• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The Chromium Embedded Framework Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be found
3 // in the LICENSE file.
4 
5 #include "libcef/browser/views/menu_button_impl.h"
6 
7 #include "libcef/browser/views/menu_button_view.h"
8 #include "libcef/browser/views/window_impl.h"
9 
10 #include "ui/gfx/canvas.h"
11 
12 // static
CreateMenuButton(CefRefPtr<CefMenuButtonDelegate> delegate,const CefString & text)13 CefRefPtr<CefMenuButton> CefMenuButton::CreateMenuButton(
14     CefRefPtr<CefMenuButtonDelegate> delegate,
15     const CefString& text) {
16   return CefMenuButtonImpl::Create(delegate, text);
17 }
18 
19 // static
Create(CefRefPtr<CefMenuButtonDelegate> delegate,const CefString & text)20 CefRefPtr<CefMenuButtonImpl> CefMenuButtonImpl::Create(
21     CefRefPtr<CefMenuButtonDelegate> delegate,
22     const CefString& text) {
23   CEF_REQUIRE_UIT_RETURN(nullptr);
24   DCHECK(delegate);
25   if (!delegate)
26     return nullptr;
27   CefRefPtr<CefMenuButtonImpl> menu_button = new CefMenuButtonImpl(delegate);
28   menu_button->Initialize();
29   if (!text.empty())
30     menu_button->SetText(text);
31   return menu_button;
32 }
33 
ShowMenu(CefRefPtr<CefMenuModel> menu_model,const CefPoint & screen_point,cef_menu_anchor_position_t anchor_position)34 void CefMenuButtonImpl::ShowMenu(CefRefPtr<CefMenuModel> menu_model,
35                                  const CefPoint& screen_point,
36                                  cef_menu_anchor_position_t anchor_position) {
37   CEF_REQUIRE_VALID_RETURN_VOID();
38   CefRefPtr<CefWindow> window =
39       view_util::GetWindowFor(root_view()->GetWidget());
40   CefWindowImpl* window_impl = static_cast<CefWindowImpl*>(window.get());
41   if (window_impl) {
42     window_impl->ShowMenu(root_view(), menu_model, screen_point,
43                           anchor_position);
44   }
45 }
46 
TriggerMenu()47 void CefMenuButtonImpl::TriggerMenu() {
48   CEF_REQUIRE_VALID_RETURN_VOID();
49   root_view()->Activate(nullptr);
50 }
51 
SetFocusable(bool focusable)52 void CefMenuButtonImpl::SetFocusable(bool focusable) {
53   CEF_REQUIRE_VALID_RETURN_VOID();
54   static_cast<CefMenuButtonView*>(root_view())
55       ->SetDrawStringsFlags(focusable ? gfx::Canvas::SHOW_PREFIX
56                                       : gfx::Canvas::HIDE_PREFIX);
57   ParentClass::SetFocusable(focusable);
58 }
59 
CefMenuButtonImpl(CefRefPtr<CefMenuButtonDelegate> delegate)60 CefMenuButtonImpl::CefMenuButtonImpl(CefRefPtr<CefMenuButtonDelegate> delegate)
61     : ParentClass(delegate) {
62   DCHECK(delegate);
63 }
64 
CreateRootView()65 views::MenuButton* CefMenuButtonImpl::CreateRootView() {
66   return new CefMenuButtonView(delegate());
67 }
68 
InitializeRootView()69 void CefMenuButtonImpl::InitializeRootView() {
70   static_cast<CefMenuButtonView*>(root_view())->Initialize();
71 }
72