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 #ifndef CEF_LIBCEF_BROWSER_VIEWS_MENU_BUTTON_VIEW_H_ 6 #define CEF_LIBCEF_BROWSER_VIEWS_MENU_BUTTON_VIEW_H_ 7 #pragma once 8 9 #include "include/views/cef_menu_button.h" 10 #include "include/views/cef_menu_button_delegate.h" 11 12 #include "libcef/browser/views/label_button_view.h" 13 14 #include "ui/views/controls/button/menu_button.h" 15 16 // Extend views::LabelButton with a no-argument constructor as required by the 17 // CefViewView template and extend views::ButtonListener as required by the 18 // CefButtonView template. 19 class MenuButtonEx : public views::MenuButton { 20 public: MenuButtonEx()21 MenuButtonEx() 22 : views::MenuButton(base::BindRepeating( 23 [](MenuButtonEx* self, const ui::Event& event) { 24 self->ButtonPressed(event); 25 }, 26 base::Unretained(this))) {} 27 28 virtual void ButtonPressed(const ui::Event& event) = 0; 29 }; 30 31 class CefMenuButtonView 32 : public CefLabelButtonView<MenuButtonEx, CefMenuButtonDelegate> { 33 public: 34 using ParentClass = CefLabelButtonView<MenuButtonEx, CefMenuButtonDelegate>; 35 36 // |cef_delegate| must not be nullptr. 37 explicit CefMenuButtonView(CefMenuButtonDelegate* cef_delegate); 38 39 CefMenuButtonView(const CefMenuButtonView&) = delete; 40 CefMenuButtonView& operator=(const CefMenuButtonView&) = delete; 41 42 void Initialize() override; 43 44 // Returns the CefMenuButton associated with this view. See comments on 45 // CefViewView::GetCefView. 46 CefRefPtr<CefMenuButton> GetCefMenuButton() const; 47 48 // Set the flags that control display of accelerator characters. 49 void SetDrawStringsFlags(int flags); 50 51 // MenuButtonEx methods: 52 void ButtonPressed(const ui::Event& event) override; 53 }; 54 55 #endif // CEF_LIBCEF_BROWSER_VIEWS_MENU_BUTTON_VIEW_H_ 56