• 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_view.h"
6 
7 #include "libcef/browser/thread_util.h"
8 
9 #include "ui/gfx/canvas.h"
10 #include "ui/views/controls/button/menu_button_controller.h"
11 #include "ui/views/controls/menu/menu_config.h"
12 
13 namespace {
14 
15 class ButtonPressedLock : public CefMenuButtonPressedLock {
16  public:
ButtonPressedLock(views::MenuButton * menu_button)17   explicit ButtonPressedLock(views::MenuButton* menu_button)
18       : pressed_lock_(menu_button->button_controller()) {}
19 
20   ButtonPressedLock(const ButtonPressedLock&) = delete;
21   ButtonPressedLock& operator=(const ButtonPressedLock&) = delete;
22 
23  private:
24   views::MenuButtonController::PressedLock pressed_lock_;
25 
26   IMPLEMENT_REFCOUNTING_DELETE_ON_UIT(ButtonPressedLock);
27 };
28 
29 }  // namespace
30 
CefMenuButtonView(CefMenuButtonDelegate * cef_delegate)31 CefMenuButtonView::CefMenuButtonView(CefMenuButtonDelegate* cef_delegate)
32     : ParentClass(cef_delegate) {
33   DCHECK(cef_delegate);
34 }
35 
Initialize()36 void CefMenuButtonView::Initialize() {
37   ParentClass::Initialize();
38 
39   SetDrawStringsFlags(IsFocusable() ? gfx::Canvas::SHOW_PREFIX
40                                     : gfx::Canvas::HIDE_PREFIX);
41 
42   // Use the same default font as MenuItemView.
43   SetFontList(views::MenuConfig::instance().font_list);
44 }
45 
GetCefMenuButton() const46 CefRefPtr<CefMenuButton> CefMenuButtonView::GetCefMenuButton() const {
47   CefRefPtr<CefMenuButton> menu_button = GetCefLabelButton()->AsMenuButton();
48   DCHECK(menu_button);
49   return menu_button;
50 }
51 
SetDrawStringsFlags(int flags)52 void CefMenuButtonView::SetDrawStringsFlags(int flags) {
53   label()->SetDrawStringsFlags(flags);
54 }
55 
ButtonPressed(const ui::Event & event)56 void CefMenuButtonView::ButtonPressed(const ui::Event& event) {
57   auto position = GetMenuPosition();
58   cef_delegate()->OnMenuButtonPressed(GetCefMenuButton(),
59                                       CefPoint(position.x(), position.y()),
60                                       new ButtonPressedLock(this));
61 }
62