blob: 06f83453a8b237f047cf73273dea7267f3adca2c [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]310ebd6302011-10-10 19:06:288#include "content/renderer/render_view_impl.h"
[email protected]5c30b5e02013-05-30 03:46:089#include "third_party/WebKit/public/platform/WebRect.h"
[email protected]2255a9332013-06-17 05:12:3110#include "third_party/WebKit/public/web/WebExternalPopupMenuClient.h"
[email protected]caf706f2010-10-26 17:54:0811
[email protected]e9ff79c2012-10-19 21:31:2612namespace content {
13
[email protected]caf706f2010-10-26 17:54:0814ExternalPopupMenu::ExternalPopupMenu(
[email protected]310ebd6302011-10-10 19:06:2815 RenderViewImpl* render_view,
[email protected]caf706f2010-10-26 17:54:0816 const WebKit::WebPopupMenuInfo& popup_menu_info,
17 WebKit::WebExternalPopupMenuClient* popup_menu_client)
18 : render_view_(render_view),
19 popup_menu_info_(popup_menu_info),
20 popup_menu_client_(popup_menu_client) {
21}
22
23void ExternalPopupMenu::show(const WebKit::WebRect& bounds) {
24 ViewHostMsg_ShowPopup_Params popup_params;
25 popup_params.bounds = bounds;
26 popup_params.item_height = popup_menu_info_.itemHeight;
27 popup_params.item_font_size = popup_menu_info_.itemFontSize;
28 popup_params.selected_item = popup_menu_info_.selectedIndex;
29 for (size_t i = 0; i < popup_menu_info_.items.size(); ++i)
30 popup_params.popup_items.push_back(WebMenuItem(popup_menu_info_.items[i]));
31 popup_params.right_aligned = popup_menu_info_.rightAligned;
[email protected]24d2b172012-05-26 00:54:1232 popup_params.allow_multiple_selection =
33 popup_menu_info_.allowMultipleSelection;
[email protected]caf706f2010-10-26 17:54:0834 render_view_->Send(
35 new ViewHostMsg_ShowPopup(render_view_->routing_id(), popup_params));
36}
37
38void ExternalPopupMenu::close() {
39 popup_menu_client_ = NULL;
40 render_view_ = NULL;
41}
42
[email protected]24d2b172012-05-26 00:54:1243#if defined(OS_MACOSX)
[email protected]caf706f2010-10-26 17:54:0844void ExternalPopupMenu::DidSelectItem(int index) {
45 if (!popup_menu_client_)
46 return;
47 if (index == -1)
48 popup_menu_client_->didCancel();
49 else
50 popup_menu_client_->didAcceptIndex(index);
51}
[email protected]24d2b172012-05-26 00:54:1252#endif
53
54#if defined(OS_ANDROID)
55void ExternalPopupMenu::DidSelectItems(bool canceled,
56 const std::vector<int>& indices) {
57 if (!popup_menu_client_)
58 return;
59 if (canceled)
60 popup_menu_client_->didCancel();
61 else
62 popup_menu_client_->didAcceptIndices(indices);
63}
64#endif
65
[email protected]e9ff79c2012-10-19 21:31:2666} // namespace content