blob: 08d71e982616a0488783dce268689cd64d0b6780 [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),
21 popup_menu_client_(popup_menu_client) {
22}
23
24void ExternalPopupMenu::show(const WebKit::WebRect& bounds) {
25 ViewHostMsg_ShowPopup_Params popup_params;
26 popup_params.bounds = bounds;
27 popup_params.item_height = popup_menu_info_.itemHeight;
28 popup_params.item_font_size = popup_menu_info_.itemFontSize;
29 popup_params.selected_item = popup_menu_info_.selectedIndex;
[email protected]54bf9952013-07-17 06:43:2030 for (size_t i = 0; i < popup_menu_info_.items.size(); ++i) {
31 popup_params.popup_items.push_back(
32 MenuItemBuilder::Build(popup_menu_info_.items[i]));
33 }
[email protected]caf706f2010-10-26 17:54:0834 popup_params.right_aligned = popup_menu_info_.rightAligned;
[email protected]24d2b172012-05-26 00:54:1235 popup_params.allow_multiple_selection =
36 popup_menu_info_.allowMultipleSelection;
[email protected]caf706f2010-10-26 17:54:0837 render_view_->Send(
38 new ViewHostMsg_ShowPopup(render_view_->routing_id(), popup_params));
39}
40
41void ExternalPopupMenu::close() {
42 popup_menu_client_ = NULL;
43 render_view_ = NULL;
44}
45
[email protected]24d2b172012-05-26 00:54:1246#if defined(OS_MACOSX)
[email protected]caf706f2010-10-26 17:54:0847void ExternalPopupMenu::DidSelectItem(int index) {
48 if (!popup_menu_client_)
49 return;
50 if (index == -1)
51 popup_menu_client_->didCancel();
52 else
53 popup_menu_client_->didAcceptIndex(index);
54}
[email protected]24d2b172012-05-26 00:54:1255#endif
56
57#if defined(OS_ANDROID)
58void ExternalPopupMenu::DidSelectItems(bool canceled,
59 const std::vector<int>& indices) {
60 if (!popup_menu_client_)
61 return;
62 if (canceled)
63 popup_menu_client_->didCancel();
64 else
65 popup_menu_client_->didAcceptIndices(indices);
66}
67#endif
68
[email protected]e9ff79c2012-10-19 21:31:2669} // namespace content