[email protected] | 24d2b17 | 2012-05-26 00:54:12 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 5572215 | 2011-03-22 01:33:53 | [diff] [blame] | 5 | #include "content/renderer/external_popup_menu.h" |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 6 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 7 | #include <stddef.h> |
8 | |||||
9 | #include "build/build_config.h" | ||||
avi | 485e5fd6 | 2014-08-25 23:26:14 | [diff] [blame] | 10 | #include "content/common/frame_messages.h" |
[email protected] | 54bf995 | 2013-07-17 06:43:20 | [diff] [blame] | 11 | #include "content/renderer/menu_item_builder.h" |
avi | 485e5fd6 | 2014-08-25 23:26:14 | [diff] [blame] | 12 | #include "content/renderer/render_frame_impl.h" |
[email protected] | 5c30b5e0 | 2013-05-30 03:46:08 | [diff] [blame] | 13 | #include "third_party/WebKit/public/platform/WebRect.h" |
[email protected] | 2255a933 | 2013-06-17 05:12:31 | [diff] [blame] | 14 | #include "third_party/WebKit/public/web/WebExternalPopupMenuClient.h" |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 15 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 16 | namespace content { |
17 | |||||
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 18 | ExternalPopupMenu::ExternalPopupMenu( |
avi | 485e5fd6 | 2014-08-25 23:26:14 | [diff] [blame] | 19 | RenderFrameImpl* render_frame, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 20 | const blink::WebPopupMenuInfo& popup_menu_info, |
21 | blink::WebExternalPopupMenuClient* popup_menu_client) | ||||
avi | 485e5fd6 | 2014-08-25 23:26:14 | [diff] [blame] | 22 | : render_frame_(render_frame), |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 23 | popup_menu_info_(popup_menu_info), |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 24 | popup_menu_client_(popup_menu_client), |
25 | origin_scale_for_emulation_(0) { | ||||
26 | } | ||||
27 | |||||
[email protected] | 9a2d7ee3 | 2013-12-05 12:15:49 | [diff] [blame] | 28 | void ExternalPopupMenu::SetOriginScaleAndOffsetForEmulation( |
dgozman | 9260b0a1 | 2015-03-16 13:45:20 | [diff] [blame] | 29 | float scale, const gfx::PointF& offset) { |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 30 | origin_scale_for_emulation_ = scale; |
[email protected] | 9a2d7ee3 | 2013-12-05 12:15:49 | [diff] [blame] | 31 | origin_offset_for_emulation_ = offset; |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 32 | } |
33 | |||||
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 34 | void ExternalPopupMenu::Show(const blink::WebRect& bounds) { |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 35 | blink::WebRect rect = bounds; |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 36 | if (origin_scale_for_emulation_) { |
37 | rect.x *= origin_scale_for_emulation_; | ||||
38 | rect.y *= origin_scale_for_emulation_; | ||||
39 | } | ||||
[email protected] | 9a2d7ee3 | 2013-12-05 12:15:49 | [diff] [blame] | 40 | rect.x += origin_offset_for_emulation_.x(); |
41 | rect.y += origin_offset_for_emulation_.y(); | ||||
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 42 | |
avi | 485e5fd6 | 2014-08-25 23:26:14 | [diff] [blame] | 43 | FrameHostMsg_ShowPopup_Params popup_params; |
[email protected] | b2e4c7013 | 2013-10-03 02:07:51 | [diff] [blame] | 44 | popup_params.bounds = rect; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 45 | 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] | 54bf995 | 2013-07-17 06:43:20 | [diff] [blame] | 48 | 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 Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 52 | popup_params.right_aligned = popup_menu_info_.right_aligned; |
[email protected] | 24d2b17 | 2012-05-26 00:54:12 | [diff] [blame] | 53 | popup_params.allow_multiple_selection = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 54 | popup_menu_info_.allow_multiple_selection; |
avi | 485e5fd6 | 2014-08-25 23:26:14 | [diff] [blame] | 55 | render_frame_->Send( |
56 | new FrameHostMsg_ShowPopup(render_frame_->GetRoutingID(), popup_params)); | ||||
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 57 | } |
58 | |||||
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 59 | void ExternalPopupMenu::Close() { |
avi | 485e5fd6 | 2014-08-25 23:26:14 | [diff] [blame] | 60 | render_frame_->Send( |
61 | new FrameHostMsg_HidePopup(render_frame_->GetRoutingID())); | ||||
62 | render_frame_->DidHideExternalPopupMenu(); | ||||
[email protected] | 8ff26a8c | 2014-03-24 02:59:40 | [diff] [blame] | 63 | // |this| was deleted. |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 64 | } |
65 | |||||
thakis | 18e42641 | 2017-03-15 12:06:37 | [diff] [blame] | 66 | #if BUILDFLAG(USE_EXTERNAL_POPUP_MENU) |
[email protected] | 24d2b17 | 2012-05-26 00:54:12 | [diff] [blame] | 67 | #if defined(OS_MACOSX) |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 68 | void ExternalPopupMenu::DidSelectItem(int index) { |
69 | if (!popup_menu_client_) | ||||
70 | return; | ||||
71 | if (index == -1) | ||||
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 72 | popup_menu_client_->DidCancel(); |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 73 | else |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 74 | popup_menu_client_->DidAcceptIndex(index); |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 75 | } |
haibinlu | c643d33c | 2016-06-03 02:22:34 | [diff] [blame] | 76 | #else |
[email protected] | 24d2b17 | 2012-05-26 00:54:12 | [diff] [blame] | 77 | void ExternalPopupMenu::DidSelectItems(bool canceled, |
78 | const std::vector<int>& indices) { | ||||
79 | if (!popup_menu_client_) | ||||
80 | return; | ||||
81 | if (canceled) | ||||
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 82 | popup_menu_client_->DidCancel(); |
[email protected] | 24d2b17 | 2012-05-26 00:54:12 | [diff] [blame] | 83 | else |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame^] | 84 | popup_menu_client_->DidAcceptIndices(indices); |
[email protected] | 24d2b17 | 2012-05-26 00:54:12 | [diff] [blame] | 85 | } |
86 | #endif | ||||
haibinlu | c643d33c | 2016-06-03 02:22:34 | [diff] [blame] | 87 | #endif |
[email protected] | 24d2b17 | 2012-05-26 00:54:12 | [diff] [blame] | 88 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 89 | } // namespace content |