1 // Copyright (c) 2012 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 UI_VIEWS_CONTROLS_BUTTON_BUTTON_DROPDOWN_H_
6 #define UI_VIEWS_CONTROLS_BUTTON_BUTTON_DROPDOWN_H_
8 #include "base/memory/weak_ptr.h"
9 #include "ui/views/context_menu_controller.h"
10 #include "ui/views/controls/button/image_button.h"
20 ////////////////////////////////////////////////////////////////////////////////
24 // A button class that when pressed (and held) or pressed (and drag down) will
27 ////////////////////////////////////////////////////////////////////////////////
28 class VIEWS_EXPORT ButtonDropDown : public ImageButton,
29 public ContextMenuController {
31 // The button's class name.
32 static const char kViewClassName[];
34 // Takes ownership of the |model|.
35 ButtonDropDown(ButtonListener* listener, ui::MenuModel* model);
36 virtual ~ButtonDropDown();
38 // If menu is currently pending for long press - stop it.
39 void ClearPendingMenu();
41 // Indicates if menu is currently showing.
42 bool IsMenuShowing() const;
44 // Overridden from views::View
45 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
46 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE;
47 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
48 virtual const char* GetClassName() const OVERRIDE;
49 // Showing the drop down results in a MouseCaptureLost, we need to ignore it.
50 virtual void OnMouseCaptureLost() OVERRIDE {}
51 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
52 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
53 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
55 // Overridden from views::ContextMenuController
56 virtual void ShowContextMenuForView(View* source,
57 const gfx::Point& point,
58 ui::MenuSourceType source_type) OVERRIDE;
61 // Overridden from CustomButton. Returns true if the button should become
62 // pressed when a user holds the mouse down over the button. For this
63 // implementation, both left and right mouse buttons can trigger a change
64 // to the PUSHED state.
65 virtual bool ShouldEnterPushedState(const ui::Event& event) OVERRIDE;
67 // Returns if menu should be shown. Override this to change default behavior.
68 virtual bool ShouldShowMenu();
70 // Function to show the dropdown menu.
71 virtual void ShowDropDownMenu(ui::MenuSourceType source_type);
74 // The model that populates the attached menu.
75 scoped_ptr<ui::MenuModel> model_;
77 // Indicates if menu is currently showing.
80 // Y position of mouse when left mouse button is pressed
81 int y_position_on_lbuttondown_;
83 // Menu runner to display drop down menu.
84 scoped_ptr<MenuRunner> menu_runner_;
86 // A factory for tasks that show the dropdown context menu for the button.
87 base::WeakPtrFactory<ButtonDropDown> show_menu_factory_;
89 DISALLOW_COPY_AND_ASSIGN(ButtonDropDown);
94 #endif // UI_VIEWS_CONTROLS_BUTTON_BUTTON_DROPDOWN_H_