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/gfx/geometry/point.h"
10 #include "ui/views/animation/ink_drop_host.h"
11 #include "ui/views/context_menu_controller.h"
12 #include "ui/views/controls/button/button.h"
13 #include "ui/views/controls/button/label_button.h"
20 class InkDropAnimationController
;
24 // This class provides basic drawing and mouse-over behavior for buttons
25 // appearing in the toolbar.
26 class ToolbarButton
: public views::LabelButton
,
27 public views::ContextMenuController
,
28 public views::InkDropHost
{
30 // Takes ownership of the |model|, which can be null if no menu
32 ToolbarButton(views::ButtonListener
* listener
, ui::MenuModel
* model
);
33 ~ToolbarButton() override
;
35 // Set up basic mouseover border behavior.
36 // Should be called before first paint.
39 // Methods for handling ButtonDropDown-style menus.
40 void ClearPendingMenu();
41 bool IsMenuShowing() const;
43 // views::LabelButton:
44 gfx::Size
GetPreferredSize() const override
;
45 void Layout() override
;
46 bool OnMousePressed(const ui::MouseEvent
& event
) override
;
47 bool OnMouseDragged(const ui::MouseEvent
& event
) override
;
48 void OnMouseReleased(const ui::MouseEvent
& event
) override
;
49 // Showing the drop down results in a MouseCaptureLost, we need to ignore it.
50 void OnMouseCaptureLost() override
;
51 void OnMouseExited(const ui::MouseEvent
& event
) override
;
52 void OnGestureEvent(ui::GestureEvent
* event
) override
;
53 void GetAccessibleState(ui::AXViewState
* state
) override
;
54 scoped_ptr
<views::LabelButtonBorder
> CreateDefaultBorder() const override
;
56 // views::ContextMenuController:
57 void ShowContextMenuForView(View
* source
,
58 const gfx::Point
& point
,
59 ui::MenuSourceType source_type
) override
;
61 // views::InkDropHost:
62 void AddInkDropLayer(ui::Layer
* ink_drop_layer
) override
;
63 void RemoveInkDropLayer(ui::Layer
* ink_drop_layer
) override
;
66 // views::LabelButton:
67 bool ShouldEnterPushedState(const ui::Event
& event
) override
;
68 void NotifyClick(const ui::Event
& event
) override
;
70 // Returns if menu should be shown. Override this to change default behavior.
71 virtual bool ShouldShowMenu();
73 // Function to show the dropdown menu.
74 virtual void ShowDropDownMenu(ui::MenuSourceType source_type
);
76 // Returns the Point where the ink drop should be centered.
77 virtual gfx::Point
CalculateInkDropCenter() const;
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_