blob: 070ccd3b29ac433742585364b37f48ffee1f338f [file] [log] [blame]
[email protected]24d2b172012-05-26 00:54:121// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]caf706f2010-10-26 17:54:082// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]55722152011-03-22 01:33:535#include "content/renderer/external_popup_menu.h"
[email protected]caf706f2010-10-26 17:54:086
[email protected]55722152011-03-22 01:33:537#include "content/common/view_messages.h"
[email protected]54bf9952013-07-17 06:43:208#include "content/renderer/menu_item_builder.h"
[email protected]310ebd6302011-10-10 19:06:289#include "content/renderer/render_view_impl.h"
[email protected]5c30b5e02013-05-30 03:46:0810#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]2255a9332013-06-17 05:12:3111#include "third_party/WebKit/public/web/WebExternalPopupMenuClient.h"
[email protected]caf706f2010-10-26 17:54:0812
[email protected]e9ff79c2012-10-19 21:31:2613namespace content {
14
[email protected]caf706f2010-10-26 17:54:0815ExternalPopupMenu::ExternalPopupMenu(
[email protected]310ebd6302011-10-10 19:06:2816 RenderViewImpl* render_view,
[email protected]caf706f2010-10-26 17:54:0817 const WebKit::WebPopupMenuInfo& popup_menu_info,
18 WebKit::WebExternalPopupMenuClient* popup_menu_client)
19 : render_view_(render_view),
20 popup_menu_info_(popup_menu_info),
[email protected]b2e4c70132013-10-03 02:07:5121 popup_menu_client_(popup_menu_client),
22 origin_scale_for_emulation_(0) {
23}
24
25void ExternalPopupMenu::SetOriginScaleForEmulation(float scale) {
26 origin_scale_for_emulation_ = scale;
[email protected]caf706f2010-10-26 17:54:0827}
28
29void ExternalPopupMenu::show(const WebKit::WebRect& bounds) {
[email protected]b2e4c70132013-10-03 02:07:5130 WebKit::WebRect rect = bounds;
31 if (origin_scale_for_emulation_) {
32 rect.x *= origin_scale_for_emulation_;
33 rect.y *= origin_scale_for_emulation_;
34 }
35
[email protected]caf706f2010-10-26 17:54:0836 ViewHostMsg_ShowPopup_Params popup_params;
[email protected]b2e4c70132013-10-03 02:07:5137 popup_params.bounds = rect;
[email protected]caf706f2010-10-26 17:54:0838 popup_params.item_height = popup_menu_info_.itemHeight;
39 popup_params.item_font_size = popup_menu_info_.itemFontSize;
40 popup_params.selected_item = popup_menu_info_.selectedIndex;
[email protected]54bf9952013-07-17 06:43:2041 for (size_t i = 0; i < popup_menu_info_.items.size(); ++i) {
42 popup_params.popup_items.push_back(
43 MenuItemBuilder::Build(popup_menu_info_.items[i]));
44 }
[email protected]caf706f2010-10-26 17:54:0845 popup_params.right_aligned = popup_menu_info_.rightAligned;
[email protected]24d2b172012-05-26 00:54:1246 popup_params.allow_multiple_selection =
47 popup_menu_info_.allowMultipleSelection;
[email protected]caf706f2010-10-26 17:54:0848 render_view_->Send(
49 new ViewHostMsg_ShowPopup(render_view_->routing_id(), popup_params));
50}
51
52void ExternalPopupMenu::close() {
53 popup_menu_client_ = NULL;
54 render_view_ = NULL;
55}
56
[email protected]24d2b172012-05-26 00:54:1257#if defined(OS_MACOSX)
[email protected]caf706f2010-10-26 17:54:0858void ExternalPopupMenu::DidSelectItem(int index) {
59 if (!popup_menu_client_)
60 return;
61 if (index == -1)
62 popup_menu_client_->didCancel();
63 else
64 popup_menu_client_->didAcceptIndex(index);
65}
[email protected]24d2b172012-05-26 00:54:1266#endif
67
68#if defined(OS_ANDROID)
69void ExternalPopupMenu::DidSelectItems(bool canceled,
70 const std::vector<int>& indices) {
71 if (!popup_menu_client_)
72 return;
73 if (canceled)
74 popup_menu_client_->didCancel();
75 else
76 popup_menu_client_->didAcceptIndices(indices);
77}
78#endif
79
[email protected]e9ff79c2012-10-19 21:31:2680} // namespace content