1 // Copyright 2013 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 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_
6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_
8 #include "ui/views/context_menu_controller.h"
9 #include "ui/views/controls/button/button.h"
10 #include "ui/views/controls/button/label_button.h"
20 // This class provides basic drawing and mouse-over behavior for buttons
21 // appearing in the toolbar.
22 class ToolbarButton
: public views::LabelButton
,
23 public views::ContextMenuController
{
25 // Takes ownership of the |model|, which can be null if no menu
27 ToolbarButton(views::ButtonListener
* listener
, ui::MenuModel
* model
);
28 ~ToolbarButton() override
;
30 // Set up basic mouseover border behavior.
31 // Should be called before first paint.
34 // Methods for handling ButtonDropDown-style menus.
35 void ClearPendingMenu();
36 bool IsMenuShowing() const;
38 // views::LabelButton:
39 gfx::Size
GetPreferredSize() const override
;
40 bool OnMousePressed(const ui::MouseEvent
& event
) override
;
41 bool OnMouseDragged(const ui::MouseEvent
& event
) override
;
42 void OnMouseReleased(const ui::MouseEvent
& event
) override
;
43 // Showing the drop down results in a MouseCaptureLost, we need to ignore it.
44 void OnMouseCaptureLost() override
;
45 void OnMouseExited(const ui::MouseEvent
& event
) override
;
46 void OnGestureEvent(ui::GestureEvent
* event
) override
;
47 void GetAccessibleState(ui::AXViewState
* state
) override
;
48 scoped_ptr
<views::LabelButtonBorder
> CreateDefaultBorder() const override
;
50 // views::ContextMenuController:
51 void ShowContextMenuForView(View
* source
,
52 const gfx::Point
& point
,
53 ui::MenuSourceType source_type
) override
;
56 // Overridden from CustomButton. Returns true if the button should become
57 // pressed when a user holds the mouse down over the button. For this
58 // implementation, both left and right mouse buttons can trigger a change
59 // to the PUSHED state.
60 bool ShouldEnterPushedState(const ui::Event
& event
) override
;
62 // Returns if menu should be shown. Override this to change default behavior.
63 virtual bool ShouldShowMenu();
65 // Function to show the dropdown menu.
66 virtual void ShowDropDownMenu(ui::MenuSourceType source_type
);
69 // views::LabelButton:
70 const char* GetClassName() const override
;
72 // The model that populates the attached menu.
73 scoped_ptr
<ui::MenuModel
> model_
;
75 // Indicates if menu is currently showing.
78 // Y position of mouse when left mouse button is pressed
79 int y_position_on_lbuttondown_
;
81 // Menu runner to display drop down menu.
82 scoped_ptr
<views::MenuRunner
> menu_runner_
;
84 // A factory for tasks that show the dropdown context menu for the button.
85 base::WeakPtrFactory
<ToolbarButton
> show_menu_factory_
;
87 DISALLOW_COPY_AND_ASSIGN(ToolbarButton
);
90 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_