OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_H_ | 5 #ifndef UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_H_ |
6 #define UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_H_ | 6 #define UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "ui/views/background.h" | 12 #include "ui/views/background.h" |
13 #include "ui/views/controls/button/text_button.h" | 13 #include "ui/views/controls/button/label_button.h" |
14 | 14 |
15 namespace views { | 15 namespace views { |
16 | 16 |
17 class MenuButtonListener; | 17 class MenuButtonListener; |
18 | 18 |
19 //////////////////////////////////////////////////////////////////////////////// | 19 //////////////////////////////////////////////////////////////////////////////// |
20 // | 20 // |
21 // MenuButton | 21 // MenuButton |
22 // | 22 // |
23 // A button that shows a menu when the left mouse button is pushed | 23 // A button that shows a menu when the left mouse button is pushed |
24 // | 24 // |
25 //////////////////////////////////////////////////////////////////////////////// | 25 //////////////////////////////////////////////////////////////////////////////// |
26 class VIEWS_EXPORT MenuButton : public TextButton { | 26 class VIEWS_EXPORT MenuButton : public LabelButton { |
27 public: | 27 public: |
28 static const char kViewClassName[]; | 28 static const char kViewClassName[]; |
29 | 29 |
30 // How much padding to put on the left and right of the menu marker. | 30 // How much padding to put on the left and right of the menu marker. |
31 static const int kMenuMarkerPaddingLeft; | 31 static const int kMenuMarkerPaddingLeft; |
32 static const int kMenuMarkerPaddingRight; | 32 static const int kMenuMarkerPaddingRight; |
33 | 33 |
34 // Create a Button. | 34 // Create a Button. |
35 MenuButton(ButtonListener* listener, | 35 MenuButton(ButtonListener* listener, |
36 const base::string16& text, | 36 const base::string16& text, |
37 MenuButtonListener* menu_button_listener, | 37 MenuButtonListener* menu_button_listener, |
38 bool show_menu_marker); | 38 bool show_menu_marker); |
39 virtual ~MenuButton(); | 39 virtual ~MenuButton(); |
40 | 40 |
41 bool show_menu_marker() const { return show_menu_marker_; } | 41 bool show_menu_marker() const { return show_menu_marker_; } |
42 void set_menu_marker(const gfx::ImageSkia* menu_marker) { | 42 void set_menu_marker(const gfx::ImageSkia* menu_marker) { |
43 menu_marker_ = menu_marker; | 43 menu_marker_ = menu_marker; |
44 } | 44 } |
45 const gfx::ImageSkia* menu_marker() const { return menu_marker_; } | 45 const gfx::ImageSkia* menu_marker() const { return menu_marker_; } |
46 | 46 |
47 const gfx::Point& menu_offset() const { return menu_offset_; } | 47 const gfx::Point& menu_offset() const { return menu_offset_; } |
48 void set_menu_offset(int x, int y) { menu_offset_.SetPoint(x, y); } | 48 void set_menu_offset(int x, int y) { menu_offset_.SetPoint(x, y); } |
49 | 49 |
50 // Activate the button (called when the button is pressed). | 50 // Activate the button (called when the button is pressed). |
51 virtual bool Activate(); | 51 virtual bool Activate(); |
52 | 52 |
53 // Overridden from TextButton for the potential use of a drop marker. | |
54 virtual void PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) OVERRIDE; | |
55 | |
56 // Overridden from View: | 53 // Overridden from View: |
57 virtual gfx::Size GetPreferredSize() const OVERRIDE; | 54 virtual gfx::Size GetPreferredSize() const OVERRIDE; |
58 virtual const char* GetClassName() const OVERRIDE; | 55 virtual const char* GetClassName() const OVERRIDE; |
| 56 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
59 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; | 57 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; |
60 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; | 58 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; |
61 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; | 59 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; |
62 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 60 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
63 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; | 61 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; |
64 virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE; | 62 virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE; |
65 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE; | 63 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE; |
66 | 64 |
67 protected: | 65 protected: |
68 // Paint the menu marker image. | 66 // Paint the menu marker image. |
69 void PaintMenuMarker(gfx::Canvas* canvas); | 67 void PaintMenuMarker(gfx::Canvas* canvas); |
70 | 68 |
| 69 // Overridden from LabelButton: |
| 70 virtual gfx::Rect GetChildAreaBounds() OVERRIDE; |
| 71 |
71 // True if the menu is currently visible. | 72 // True if the menu is currently visible. |
72 bool menu_visible_; | 73 bool menu_visible_; |
73 | 74 |
74 // Offset of the associated menu position. | 75 // Offset of the associated menu position. |
75 gfx::Point menu_offset_; | 76 gfx::Point menu_offset_; |
76 | 77 |
77 private: | 78 private: |
78 friend class TextButtonBackground; | 79 friend class TextButtonBackground; |
79 | 80 |
80 // Compute the maximum X coordinate for the current screen. MenuButtons | 81 // Compute the maximum X coordinate for the current screen. MenuButtons |
(...skipping 21 matching lines...) Expand all Loading... |
102 // If non-null the destuctor sets this to true. This is set while the menu is | 103 // If non-null the destuctor sets this to true. This is set while the menu is |
103 // showing and used to detect if the menu was deleted while running. | 104 // showing and used to detect if the menu was deleted while running. |
104 bool* destroyed_flag_; | 105 bool* destroyed_flag_; |
105 | 106 |
106 DISALLOW_COPY_AND_ASSIGN(MenuButton); | 107 DISALLOW_COPY_AND_ASSIGN(MenuButton); |
107 }; | 108 }; |
108 | 109 |
109 } // namespace views | 110 } // namespace views |
110 | 111 |
111 #endif // UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_H_ | 112 #endif // UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_H_ |
OLD | NEW |