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/macros.h" | 10 #include "base/macros.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 | 37 |
| 38 private: | 38 private: |
| 39 base::WeakPtr<MenuButton> menu_button_; | 39 base::WeakPtr<MenuButton> menu_button_; |
| 40 | 40 |
| 41 DISALLOW_COPY_AND_ASSIGN(PressedLock); | 41 DISALLOW_COPY_AND_ASSIGN(PressedLock); |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 static const char kViewClassName[]; | 44 static const char kViewClassName[]; |
| 45 | 45 |
| 46 // How much padding to put on the left and right of the menu marker. | 46 // How much padding to put on the left and right of the menu marker. |
| 47 static const int kMenuMarkerPaddingLeft; | 47 static const int kMenuMarkerPaddingLeft; |
|
tapted
2016/04/27 03:25:11
huh - looks like these are unused now and can be r
Elly Fong-Jones
2016/04/28 17:03:12
Done.
| |
| 48 static const int kMenuMarkerPaddingRight; | 48 static const int kMenuMarkerPaddingRight; |
| 49 | 49 |
| 50 // Create a Button. | 50 // Create a Button. |
| 51 MenuButton(const base::string16& text, | 51 MenuButton(const base::string16& text, |
| 52 MenuButtonListener* menu_button_listener, | 52 MenuButtonListener* menu_button_listener, |
| 53 bool show_menu_marker); | 53 bool show_menu_marker); |
| 54 ~MenuButton() override; | 54 ~MenuButton() override; |
| 55 | 55 |
| 56 bool show_menu_marker() const { return show_menu_marker_; } | |
| 57 void set_menu_marker(const gfx::ImageSkia* menu_marker) { | |
| 58 menu_marker_ = menu_marker; | |
| 59 } | |
| 60 const gfx::ImageSkia* menu_marker() const { return menu_marker_; } | |
| 61 | |
| 62 const gfx::Point& menu_offset() const { return menu_offset_; } | 56 const gfx::Point& menu_offset() const { return menu_offset_; } |
| 63 void set_menu_offset(int x, int y) { menu_offset_.SetPoint(x, y); } | 57 void set_menu_offset(int x, int y) { menu_offset_.SetPoint(x, y); } |
| 64 | 58 |
| 65 // Activate the button (called when the button is pressed). |event| is the | 59 // Activate the button (called when the button is pressed). |event| is the |
| 66 // event triggering the activation, if any. | 60 // event triggering the activation, if any. |
| 67 bool Activate(const ui::Event* event); | 61 bool Activate(const ui::Event* event); |
| 68 | 62 |
| 69 // Returns true if the event is of the proper type to potentially trigger an | 63 // Returns true if the event is of the proper type to potentially trigger an |
| 70 // action. Since MenuButtons have properties other than event type (like | 64 // action. Since MenuButtons have properties other than event type (like |
| 71 // last menu open time) to determine if an event is valid to activate the | 65 // last menu open time) to determine if an event is valid to activate the |
| 72 // menu, this is distinct from IsTriggerableEvent(). | 66 // menu, this is distinct from IsTriggerableEvent(). |
| 73 virtual bool IsTriggerableEventType(const ui::Event& event); | 67 virtual bool IsTriggerableEventType(const ui::Event& event); |
| 74 | 68 |
| 75 // Overridden from View: | 69 // Overridden from View: |
| 76 gfx::Size GetPreferredSize() const override; | 70 gfx::Size GetPreferredSize() const override; |
| 77 const char* GetClassName() const override; | 71 const char* GetClassName() const override; |
| 78 void OnPaint(gfx::Canvas* canvas) override; | 72 void OnPaint(gfx::Canvas* canvas) override; |
| 79 bool OnMousePressed(const ui::MouseEvent& event) override; | 73 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 80 void OnMouseReleased(const ui::MouseEvent& event) override; | 74 void OnMouseReleased(const ui::MouseEvent& event) override; |
| 81 void OnMouseEntered(const ui::MouseEvent& event) override; | 75 void OnMouseEntered(const ui::MouseEvent& event) override; |
| 82 void OnMouseExited(const ui::MouseEvent& event) override; | 76 void OnMouseExited(const ui::MouseEvent& event) override; |
| 83 void OnMouseMoved(const ui::MouseEvent& event) override; | 77 void OnMouseMoved(const ui::MouseEvent& event) override; |
| 84 void OnGestureEvent(ui::GestureEvent* event) override; | 78 void OnGestureEvent(ui::GestureEvent* event) override; |
| 85 bool OnKeyPressed(const ui::KeyEvent& event) override; | 79 bool OnKeyPressed(const ui::KeyEvent& event) override; |
| 86 bool OnKeyReleased(const ui::KeyEvent& event) override; | 80 bool OnKeyReleased(const ui::KeyEvent& event) override; |
| 87 void GetAccessibleState(ui::AXViewState* state) override; | 81 void GetAccessibleState(ui::AXViewState* state) override; |
| 82 void OnEnabledChanged() override; | |
| 88 | 83 |
| 89 protected: | 84 protected: |
| 90 // Paint the menu marker image. | 85 // Paint the menu marker image. |
| 91 void PaintMenuMarker(gfx::Canvas* canvas); | 86 void PaintMenuMarker(gfx::Canvas* canvas); |
| 92 | 87 |
| 93 // Overridden from LabelButton: | 88 // Overridden from LabelButton: |
| 94 gfx::Rect GetChildAreaBounds() override; | 89 gfx::Rect GetChildAreaBounds() override; |
| 95 | 90 |
| 96 // Overridden from CustomButton: | 91 // Overridden from CustomButton: |
| 97 bool IsTriggerableEvent(const ui::Event& event) override; | 92 bool IsTriggerableEvent(const ui::Event& event) override; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 109 // set the state accordingly. The ink drop is snapped to the final ACTIVATED | 104 // set the state accordingly. The ink drop is snapped to the final ACTIVATED |
| 110 // state if |snap_ink_drop_to_activated| is true, otherwise the ink drop will | 105 // state if |snap_ink_drop_to_activated| is true, otherwise the ink drop will |
| 111 // be animated to the ACTIVATED state. | 106 // be animated to the ACTIVATED state. |
| 112 void IncrementPressedLocked(bool snap_ink_drop_to_activated); | 107 void IncrementPressedLocked(bool snap_ink_drop_to_activated); |
| 113 void DecrementPressedLocked(); | 108 void DecrementPressedLocked(); |
| 114 | 109 |
| 115 // Compute the maximum X coordinate for the current screen. MenuButtons | 110 // Compute the maximum X coordinate for the current screen. MenuButtons |
| 116 // use this to make sure a menu is never shown off screen. | 111 // use this to make sure a menu is never shown off screen. |
| 117 int GetMaximumScreenXCoordinate(); | 112 int GetMaximumScreenXCoordinate(); |
| 118 | 113 |
| 114 // Returns the width of the "shoulder" of the menubutton, which is the area | |
|
tapted
2016/04/27 03:25:11
nit: menubutton -> MenuButton
Elly Fong-Jones
2016/04/28 17:03:12
Done.
| |
| 115 // containing the menu marker, and any padding surrounding it. | |
| 116 int GetShoulderWidth() const; | |
| 117 | |
| 119 // We use a time object in order to keep track of when the menu was closed. | 118 // We use a time object in order to keep track of when the menu was closed. |
| 120 // The time is used for simulating menu behavior for the menu button; that | 119 // The time is used for simulating menu behavior for the menu button; that |
| 121 // is, if the menu is shown and the button is pressed, we need to close the | 120 // is, if the menu is shown and the button is pressed, we need to close the |
| 122 // menu. There is no clean way to get the second click event because the | 121 // menu. There is no clean way to get the second click event because the |
| 123 // menu is displayed using a modal loop and, unlike regular menus in Windows, | 122 // menu is displayed using a modal loop and, unlike regular menus in Windows, |
| 124 // the button is not part of the displayed menu. | 123 // the button is not part of the displayed menu. |
| 125 base::TimeTicks menu_closed_time_; | 124 base::TimeTicks menu_closed_time_; |
| 126 | 125 |
| 127 // Our listener. Not owned. | 126 // Our listener. Not owned. |
| 128 MenuButtonListener* listener_; | 127 MenuButtonListener* listener_; |
| 129 | 128 |
| 129 // The images to draw for the menu marker, if |show_menu_marker_| is true. | |
|
tapted
2016/04/27 03:25:11
I think we can keep the old comment, and variable
Elly Fong-Jones
2016/04/28 17:03:12
Done.
| |
| 130 gfx::ImageSkia marker_image_; | |
| 131 | |
| 130 // Whether or not we're showing a drop marker. | 132 // Whether or not we're showing a drop marker. |
| 131 bool show_menu_marker_; | 133 const bool show_menu_marker_; |
| 132 | |
| 133 // The down arrow used to differentiate the menu button from normal buttons. | |
| 134 const gfx::ImageSkia* menu_marker_; | |
| 135 | 134 |
| 136 // If non-null the destructor sets this to true. This is set while the menu is | 135 // If non-null the destructor sets this to true. This is set while the menu is |
| 137 // showing and used to detect if the menu was deleted while running. | 136 // showing and used to detect if the menu was deleted while running. |
| 138 bool* destroyed_flag_; | 137 bool* destroyed_flag_; |
| 139 | 138 |
| 140 // The current number of "pressed" locks this button has. | 139 // The current number of "pressed" locks this button has. |
| 141 int pressed_lock_count_; | 140 int pressed_lock_count_; |
| 142 | 141 |
| 143 // Used to let Activate() know if IncrementPressedLocked() was called. | 142 // Used to let Activate() know if IncrementPressedLocked() was called. |
| 144 bool* increment_pressed_lock_called_; | 143 bool* increment_pressed_lock_called_; |
| 145 | 144 |
| 146 // True if the button was in a disabled state when a menu was run, and should | 145 // True if the button was in a disabled state when a menu was run, and should |
| 147 // return to it once the press is complete. This can happen if, e.g., we | 146 // return to it once the press is complete. This can happen if, e.g., we |
| 148 // programmatically show a menu on a disabled button. | 147 // programmatically show a menu on a disabled button. |
| 149 bool should_disable_after_press_; | 148 bool should_disable_after_press_; |
| 150 | 149 |
| 151 base::WeakPtrFactory<MenuButton> weak_factory_; | 150 base::WeakPtrFactory<MenuButton> weak_factory_; |
| 152 | 151 |
| 153 DISALLOW_COPY_AND_ASSIGN(MenuButton); | 152 DISALLOW_COPY_AND_ASSIGN(MenuButton); |
| 154 }; | 153 }; |
| 155 | 154 |
| 156 } // namespace views | 155 } // namespace views |
| 157 | 156 |
| 158 #endif // UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_H_ | 157 #endif // UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_H_ |
| OLD | NEW |