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 "base/memory/scoped_ptr.h"
9 #include "ui/views/animation/ink_drop_host.h"
10 #include "ui/views/context_menu_controller.h"
11 #include "ui/views/controls/button/button.h"
12 #include "ui/views/controls/button/label_button.h"
19 class InkDropAnimationController
;
23 // This class provides basic drawing and mouse-over behavior for buttons
24 // appearing in the toolbar.
25 class ToolbarButton
: public views::LabelButton
,
26 public views::ContextMenuController
,
27 public views::InkDropHost
{
29 // Takes ownership of the |model|, which can be null if no menu
31 ToolbarButton(views::ButtonListener
* listener
, ui::MenuModel
* model
);
32 ~ToolbarButton() override
;
34 // Set up basic mouseover border behavior.
35 // Should be called before first paint.
38 // Methods for handling ButtonDropDown-style menus.
39 void ClearPendingMenu();
40 bool IsMenuShowing() const;
42 // views::LabelButton:
43 gfx::Size
GetPreferredSize() const override
;
44 void Layout() override
;
45 bool OnMousePressed(const ui::MouseEvent
& event
) override
;
46 bool OnMouseDragged(const ui::MouseEvent
& event
) override
;
47 void OnMouseReleased(const ui::MouseEvent
& event
) override
;
48 // Showing the drop down results in a MouseCaptureLost, we need to ignore it.
49 void OnMouseCaptureLost() override
;
50 void OnMouseExited(const ui::MouseEvent
& event
) override
;
51 void OnGestureEvent(ui::GestureEvent
* event
) override
;
52 void GetAccessibleState(ui::AXViewState
* state
) override
;
53 scoped_ptr
<views::LabelButtonBorder
> CreateDefaultBorder() const override
;
55 // views::ContextMenuController:
56 void ShowContextMenuForView(View
* source
,
57 const gfx::Point
& point
,
58 ui::MenuSourceType source_type
) override
;
60 // views::InkDropHost:
61 void AddInkDropLayer(ui::Layer
* ink_drop_layer
) override
;
62 void RemoveInkDropLayer(ui::Layer
* ink_drop_layer
) override
;
65 // Overridden from CustomButton. Returns true if the button should become
66 // pressed when a user holds the mouse down over the button. For this
67 // implementation, both left and right mouse buttons can trigger a change
68 // to the PUSHED state.
69 bool ShouldEnterPushedState(const ui::Event
& event
) override
;
71 // Returns if menu should be shown. Override this to change default behavior.
72 virtual bool ShouldShowMenu();
74 // Function to show the dropdown menu.
75 virtual void ShowDropDownMenu(ui::MenuSourceType source_type
);
77 virtual void LayoutInkDrop();
79 views::InkDropAnimationController
* ink_drop_animation_controller() {
80 return ink_drop_animation_controller_
.get();
84 // views::LabelButton:
85 const char* GetClassName() const override
;
87 // The model that populates the attached menu.
88 scoped_ptr
<ui::MenuModel
> model_
;
90 // Indicates if menu is currently showing.
93 // Y position of mouse when left mouse button is pressed
94 int y_position_on_lbuttondown_
;
96 // Menu runner to display drop down menu.
97 scoped_ptr
<views::MenuRunner
> menu_runner_
;
99 // Animation controller for the ink drop ripple effect.
100 scoped_ptr
<views::InkDropAnimationController
> ink_drop_animation_controller_
;
102 // A factory for tasks that show the dropdown context menu for the button.
103 base::WeakPtrFactory
<ToolbarButton
> show_menu_factory_
;
105 DISALLOW_COPY_AND_ASSIGN(ToolbarButton
);
108 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_