Chromium Code Reviews| 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" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 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 bool menu_visible() const { return menus_visible_ > 0; } | |
| 51 | |
| 52 // Increases the |menus_visible_| count by one and sets the state to be | |
|
sky
2014/09/18 20:02:24
This is very fragile and not something I want in t
Devlin
2014/09/18 20:53:51
The problem with isolating all the logic in the ex
| |
| 53 // pressed. | |
| 54 // This is public because some menus may "attach" themselves to a menu button, | |
| 55 // even if they aren't the main menu for that button (the one run via | |
| 56 // Activate()). | |
| 57 void AttachMenu(); | |
| 58 | |
| 59 // Decreases the |menus_visible_| count by one and sets the state to be | |
| 60 // normal if this was the last visible menu. | |
| 61 void DetachMenu(); | |
| 62 | |
| 50 // Activate the button (called when the button is pressed). | 63 // Activate the button (called when the button is pressed). |
| 51 virtual bool Activate(); | 64 virtual bool Activate(); |
| 52 | 65 |
| 53 // Overridden from View: | 66 // Overridden from View: |
| 54 virtual gfx::Size GetPreferredSize() const OVERRIDE; | 67 virtual gfx::Size GetPreferredSize() const OVERRIDE; |
| 55 virtual const char* GetClassName() const OVERRIDE; | 68 virtual const char* GetClassName() const OVERRIDE; |
| 56 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 69 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
| 57 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; | 70 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; |
| 58 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; | 71 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; |
| 59 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; | |
| 60 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 72 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
| 61 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; | 73 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; |
| 62 virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE; | 74 virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE; |
| 63 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE; | 75 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE; |
| 64 | 76 |
| 65 protected: | 77 protected: |
| 78 // MenuButton: | |
| 79 virtual bool ShouldRespondToMouseMovement() OVERRIDE; | |
| 80 | |
| 66 // Paint the menu marker image. | 81 // Paint the menu marker image. |
| 67 void PaintMenuMarker(gfx::Canvas* canvas); | 82 void PaintMenuMarker(gfx::Canvas* canvas); |
| 68 | 83 |
| 69 // Overridden from LabelButton: | 84 // Overridden from LabelButton: |
| 70 virtual gfx::Rect GetChildAreaBounds() OVERRIDE; | 85 virtual gfx::Rect GetChildAreaBounds() OVERRIDE; |
| 71 | 86 |
| 72 // True if the menu is currently visible. | 87 // True if the menu is currently visible. |
| 73 bool menu_visible_; | 88 int menus_visible_; |
| 74 | 89 |
| 75 // Offset of the associated menu position. | 90 // Offset of the associated menu position. |
| 76 gfx::Point menu_offset_; | 91 gfx::Point menu_offset_; |
| 77 | 92 |
| 78 private: | 93 private: |
| 79 // Compute the maximum X coordinate for the current screen. MenuButtons | 94 // Compute the maximum X coordinate for the current screen. MenuButtons |
| 80 // use this to make sure a menu is never shown off screen. | 95 // use this to make sure a menu is never shown off screen. |
| 81 int GetMaximumScreenXCoordinate(); | 96 int GetMaximumScreenXCoordinate(); |
| 82 | 97 |
| 83 // We use a time object in order to keep track of when the menu was closed. | 98 // We use a time object in order to keep track of when the menu was closed. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 100 // If non-null the destuctor sets this to true. This is set while the menu is | 115 // If non-null the destuctor sets this to true. This is set while the menu is |
| 101 // showing and used to detect if the menu was deleted while running. | 116 // showing and used to detect if the menu was deleted while running. |
| 102 bool* destroyed_flag_; | 117 bool* destroyed_flag_; |
| 103 | 118 |
| 104 DISALLOW_COPY_AND_ASSIGN(MenuButton); | 119 DISALLOW_COPY_AND_ASSIGN(MenuButton); |
| 105 }; | 120 }; |
| 106 | 121 |
| 107 } // namespace views | 122 } // namespace views |
| 108 | 123 |
| 109 #endif // UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_H_ | 124 #endif // UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_H_ |
| OLD | NEW |