blob: c61530a96d49b6fd8a095d9ed18baafb75334860 [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
avi1023d012015-12-25 02:39:147#include <stddef.h>
8
9#include "build/build_config.h"
avi485e5fd62014-08-25 23:26:1410#include "content/common/frame_messages.h"
[email protected]54bf9952013-07-17 06:43:2011#include "content/renderer/menu_item_builder.h"
avi485e5fd62014-08-25 23:26:1412#include "content/renderer/render_frame_impl.h"
Blink Reformata30d4232018-04-07 15:31:0613#include "third_party/blink/public/platform/web_rect.h"
14#include "third_party/blink/public/web/web_external_popup_menu_client.h"
[email protected]caf706f2010-10-26 17:54:0815
[email protected]e9ff79c2012-10-19 21:31:2616namespace content {
17
[email protected]caf706f2010-10-26 17:54:0818ExternalPopupMenu::ExternalPopupMenu(
avi485e5fd62014-08-25 23:26:1419 RenderFrameImpl* render_frame,
[email protected]180ef242013-11-07 06:50:4620 const blink::WebPopupMenuInfo& popup_menu_info,
21 blink::WebExternalPopupMenuClient* popup_menu_client)
avi485e5fd62014-08-25 23:26:1422 : render_frame_(render_frame),
[email protected]caf706f2010-10-26 17:54:0823 popup_menu_info_(popup_menu_info),
[email protected]b2e4c70132013-10-03 02:07:5124 popup_menu_client_(popup_menu_client),
25 origin_scale_for_emulation_(0) {
26}
27
Pavel Feldmancc099f72017-07-20 23:09:0028void ExternalPopupMenu::SetOriginScaleForEmulation(float scale) {
[email protected]b2e4c70132013-10-03 02:07:5129 origin_scale_for_emulation_ = scale;
[email protected]caf706f2010-10-26 17:54:0830}
31
Blink Reformat1c4d759e2017-04-09 16:34:5432void ExternalPopupMenu::Show(const blink::WebRect& bounds) {
[email protected]180ef242013-11-07 06:50:4633 blink::WebRect rect = bounds;
[email protected]b2e4c70132013-10-03 02:07:5134 if (origin_scale_for_emulation_) {
35 rect.x *= origin_scale_for_emulation_;
36 rect.y *= origin_scale_for_emulation_;
37 }
38
avi485e5fd62014-08-25 23:26:1439 FrameHostMsg_ShowPopup_Params popup_params;
[email protected]b2e4c70132013-10-03 02:07:5140 popup_params.bounds = rect;
Blink Reformat1c4d759e2017-04-09 16:34:5441 popup_params.item_height = popup_menu_info_.item_height;
42 popup_params.item_font_size = popup_menu_info_.item_font_size;
43 popup_params.selected_item = popup_menu_info_.selected_index;
[email protected]54bf9952013-07-17 06:43:2044 for (size_t i = 0; i < popup_menu_info_.items.size(); ++i) {
45 popup_params.popup_items.push_back(
46 MenuItemBuilder::Build(popup_menu_info_.items[i]));
47 }
Blink Reformat1c4d759e2017-04-09 16:34:5448 popup_params.right_aligned = popup_menu_info_.right_aligned;
[email protected]24d2b172012-05-26 00:54:1249 popup_params.allow_multiple_selection =
Blink Reformat1c4d759e2017-04-09 16:34:5450 popup_menu_info_.allow_multiple_selection;
avi485e5fd62014-08-25 23:26:1451 render_frame_->Send(
52 new FrameHostMsg_ShowPopup(render_frame_->GetRoutingID(), popup_params));
[email protected]caf706f2010-10-26 17:54:0853}
54
Blink Reformat1c4d759e2017-04-09 16:34:5455void ExternalPopupMenu::Close() {
avi485e5fd62014-08-25 23:26:1456 render_frame_->Send(
57 new FrameHostMsg_HidePopup(render_frame_->GetRoutingID()));
58 render_frame_->DidHideExternalPopupMenu();
[email protected]8ff26a8c2014-03-24 02:59:4059 // |this| was deleted.
[email protected]caf706f2010-10-26 17:54:0860}
61
thakis18e426412017-03-15 12:06:3762#if BUILDFLAG(USE_EXTERNAL_POPUP_MENU)
[email protected]24d2b172012-05-26 00:54:1263#if defined(OS_MACOSX)
[email protected]caf706f2010-10-26 17:54:0864void ExternalPopupMenu::DidSelectItem(int index) {
65 if (!popup_menu_client_)
66 return;
67 if (index == -1)
Blink Reformat1c4d759e2017-04-09 16:34:5468 popup_menu_client_->DidCancel();
[email protected]caf706f2010-10-26 17:54:0869 else
Blink Reformat1c4d759e2017-04-09 16:34:5470 popup_menu_client_->DidAcceptIndex(index);
[email protected]caf706f2010-10-26 17:54:0871}
haibinluc643d33c2016-06-03 02:22:3472#else
[email protected]24d2b172012-05-26 00:54:1273void ExternalPopupMenu::DidSelectItems(bool canceled,
74 const std::vector<int>& indices) {
75 if (!popup_menu_client_)
76 return;
77 if (canceled)
Blink Reformat1c4d759e2017-04-09 16:34:5478 popup_menu_client_->DidCancel();
[email protected]24d2b172012-05-26 00:54:1279 else
Blink Reformat1c4d759e2017-04-09 16:34:5480 popup_menu_client_->DidAcceptIndices(indices);
[email protected]24d2b172012-05-26 00:54:1281}
82#endif
haibinluc643d33c2016-06-03 02:22:3483#endif
[email protected]24d2b172012-05-26 00:54:1284
[email protected]e9ff79c2012-10-19 21:31:2685} // namespace content