blob: 23c433d5eb67ded9c34739d2e94603518212a3c3 [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"
[email protected]5c30b5e02013-05-30 03:46:0813#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]2255a9332013-06-17 05:12:3114#include "third_party/WebKit/public/web/WebExternalPopupMenuClient.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
[email protected]9a2d7ee32013-12-05 12:15:4928void ExternalPopupMenu::SetOriginScaleAndOffsetForEmulation(
dgozman9260b0a12015-03-16 13:45:2029 float scale, const gfx::PointF& offset) {
[email protected]b2e4c70132013-10-03 02:07:5130 origin_scale_for_emulation_ = scale;
[email protected]9a2d7ee32013-12-05 12:15:4931 origin_offset_for_emulation_ = offset;
[email protected]caf706f2010-10-26 17:54:0832}
33
Blink Reformat1c4d759e2017-04-09 16:34:5434void ExternalPopupMenu::Show(const blink::WebRect& bounds) {
[email protected]180ef242013-11-07 06:50:4635 blink::WebRect rect = bounds;
[email protected]b2e4c70132013-10-03 02:07:5136 if (origin_scale_for_emulation_) {
37 rect.x *= origin_scale_for_emulation_;
38 rect.y *= origin_scale_for_emulation_;
39 }
[email protected]9a2d7ee32013-12-05 12:15:4940 rect.x += origin_offset_for_emulation_.x();
41 rect.y += origin_offset_for_emulation_.y();
[email protected]b2e4c70132013-10-03 02:07:5142
avi485e5fd62014-08-25 23:26:1443 FrameHostMsg_ShowPopup_Params popup_params;
[email protected]b2e4c70132013-10-03 02:07:5144 popup_params.bounds = rect;
Blink Reformat1c4d759e2017-04-09 16:34:5445 popup_params.item_height = popup_menu_info_.item_height;
46 popup_params.item_font_size = popup_menu_info_.item_font_size;
47 popup_params.selected_item = popup_menu_info_.selected_index;
[email protected]54bf9952013-07-17 06:43:2048 for (size_t i = 0; i < popup_menu_info_.items.size(); ++i) {
49 popup_params.popup_items.push_back(
50 MenuItemBuilder::Build(popup_menu_info_.items[i]));
51 }
Blink Reformat1c4d759e2017-04-09 16:34:5452 popup_params.right_aligned = popup_menu_info_.right_aligned;
[email protected]24d2b172012-05-26 00:54:1253 popup_params.allow_multiple_selection =
Blink Reformat1c4d759e2017-04-09 16:34:5454 popup_menu_info_.allow_multiple_selection;
avi485e5fd62014-08-25 23:26:1455 render_frame_->Send(
56 new FrameHostMsg_ShowPopup(render_frame_->GetRoutingID(), popup_params));
[email protected]caf706f2010-10-26 17:54:0857}
58
Blink Reformat1c4d759e2017-04-09 16:34:5459void ExternalPopupMenu::Close() {
avi485e5fd62014-08-25 23:26:1460 render_frame_->Send(
61 new FrameHostMsg_HidePopup(render_frame_->GetRoutingID()));
62 render_frame_->DidHideExternalPopupMenu();
[email protected]8ff26a8c2014-03-24 02:59:4063 // |this| was deleted.
[email protected]caf706f2010-10-26 17:54:0864}
65
thakis18e426412017-03-15 12:06:3766#if BUILDFLAG(USE_EXTERNAL_POPUP_MENU)
[email protected]24d2b172012-05-26 00:54:1267#if defined(OS_MACOSX)
[email protected]caf706f2010-10-26 17:54:0868void ExternalPopupMenu::DidSelectItem(int index) {
69 if (!popup_menu_client_)
70 return;
71 if (index == -1)
Blink Reformat1c4d759e2017-04-09 16:34:5472 popup_menu_client_->DidCancel();
[email protected]caf706f2010-10-26 17:54:0873 else
Blink Reformat1c4d759e2017-04-09 16:34:5474 popup_menu_client_->DidAcceptIndex(index);
[email protected]caf706f2010-10-26 17:54:0875}
haibinluc643d33c2016-06-03 02:22:3476#else
[email protected]24d2b172012-05-26 00:54:1277void ExternalPopupMenu::DidSelectItems(bool canceled,
78 const std::vector<int>& indices) {
79 if (!popup_menu_client_)
80 return;
81 if (canceled)
Blink Reformat1c4d759e2017-04-09 16:34:5482 popup_menu_client_->DidCancel();
[email protected]24d2b172012-05-26 00:54:1283 else
Blink Reformat1c4d759e2017-04-09 16:34:5484 popup_menu_client_->DidAcceptIndices(indices);
[email protected]24d2b172012-05-26 00:54:1285}
86#endif
haibinluc643d33c2016-06-03 02:22:3487#endif
[email protected]24d2b172012-05-26 00:54:1288
[email protected]e9ff79c2012-10-19 21:31:2689} // namespace content