Update V8 to version 4.6.61.
[chromium-blink-merge.git] / content / renderer / external_popup_menu.cc
blobf2363e31b53cadf397be04cc0eb9e0ee3280447f
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/external_popup_menu.h"
7 #include "content/common/frame_messages.h"
8 #include "content/renderer/menu_item_builder.h"
9 #include "content/renderer/render_frame_impl.h"
10 #include "third_party/WebKit/public/platform/WebRect.h"
11 #include "third_party/WebKit/public/web/WebExternalPopupMenuClient.h"
13 namespace content {
15 ExternalPopupMenu::ExternalPopupMenu(
16 RenderFrameImpl* render_frame,
17 const blink::WebPopupMenuInfo& popup_menu_info,
18 blink::WebExternalPopupMenuClient* popup_menu_client)
19 : render_frame_(render_frame),
20 popup_menu_info_(popup_menu_info),
21 popup_menu_client_(popup_menu_client),
22 origin_scale_for_emulation_(0) {
25 void ExternalPopupMenu::SetOriginScaleAndOffsetForEmulation(
26 float scale, const gfx::PointF& offset) {
27 origin_scale_for_emulation_ = scale;
28 origin_offset_for_emulation_ = offset;
31 void ExternalPopupMenu::show(const blink::WebRect& bounds) {
32 blink::WebRect rect = bounds;
33 if (origin_scale_for_emulation_) {
34 rect.x *= origin_scale_for_emulation_;
35 rect.y *= origin_scale_for_emulation_;
37 rect.x += origin_offset_for_emulation_.x();
38 rect.y += origin_offset_for_emulation_.y();
40 FrameHostMsg_ShowPopup_Params popup_params;
41 popup_params.bounds = rect;
42 popup_params.item_height = popup_menu_info_.itemHeight;
43 popup_params.item_font_size = popup_menu_info_.itemFontSize;
44 popup_params.selected_item = popup_menu_info_.selectedIndex;
45 for (size_t i = 0; i < popup_menu_info_.items.size(); ++i) {
46 popup_params.popup_items.push_back(
47 MenuItemBuilder::Build(popup_menu_info_.items[i]));
49 popup_params.right_aligned = popup_menu_info_.rightAligned;
50 popup_params.allow_multiple_selection =
51 popup_menu_info_.allowMultipleSelection;
52 render_frame_->Send(
53 new FrameHostMsg_ShowPopup(render_frame_->GetRoutingID(), popup_params));
56 void ExternalPopupMenu::close() {
57 render_frame_->Send(
58 new FrameHostMsg_HidePopup(render_frame_->GetRoutingID()));
59 render_frame_->DidHideExternalPopupMenu();
60 // |this| was deleted.
63 #if defined(OS_MACOSX)
64 void ExternalPopupMenu::DidSelectItem(int index) {
65 if (!popup_menu_client_)
66 return;
67 if (index == -1)
68 popup_menu_client_->didCancel();
69 else
70 popup_menu_client_->didAcceptIndex(index);
72 #endif
74 #if defined(OS_ANDROID)
75 void ExternalPopupMenu::DidSelectItems(bool canceled,
76 const std::vector<int>& indices) {
77 if (!popup_menu_client_)
78 return;
79 if (canceled)
80 popup_menu_client_->didCancel();
81 else
82 popup_menu_client_->didAcceptIndices(indices);
84 #endif
86 } // namespace content