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/view_messages.h"
8 #include "content/renderer/render_view_impl.h"
9 #include "third_party/WebKit/public/platform/WebRect.h"
10 #include "third_party/WebKit/public/web/WebExternalPopupMenuClient.h"
14 ExternalPopupMenu::ExternalPopupMenu(
15 RenderViewImpl
* render_view
,
16 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
) {
23 void 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
;
32 popup_params
.allow_multiple_selection
=
33 popup_menu_info_
.allowMultipleSelection
;
35 new ViewHostMsg_ShowPopup(render_view_
->routing_id(), popup_params
));
38 void ExternalPopupMenu::close() {
39 popup_menu_client_
= NULL
;
43 #if defined(OS_MACOSX)
44 void ExternalPopupMenu::DidSelectItem(int index
) {
45 if (!popup_menu_client_
)
48 popup_menu_client_
->didCancel();
50 popup_menu_client_
->didAcceptIndex(index
);
54 #if defined(OS_ANDROID)
55 void ExternalPopupMenu::DidSelectItems(bool canceled
,
56 const std::vector
<int>& indices
) {
57 if (!popup_menu_client_
)
60 popup_menu_client_
->didCancel();
62 popup_menu_client_
->didAcceptIndices(indices
);
66 } // namespace content