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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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; |
| 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 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 95 | 89 |
| 96 // Overridden from CustomButton: | 90 // Overridden from CustomButton: |
| 97 bool IsTriggerableEvent(const ui::Event& event) override; | 91 bool IsTriggerableEvent(const ui::Event& event) override; |
| 98 bool ShouldEnterPushedState(const ui::Event& event) override; | 92 bool ShouldEnterPushedState(const ui::Event& event) override; |
| 99 void StateChanged() override; | 93 void StateChanged() override; |
| 100 void NotifyClick(const ui::Event& event) override; | 94 void NotifyClick(const ui::Event& event) override; |
| 101 | 95 |
| 102 // Offset of the associated menu position. | 96 // Offset of the associated menu position. |
| 103 gfx::Point menu_offset_; | 97 gfx::Point menu_offset_; |
| 104 | 98 |
| 99 // Returns the width of the "shoulder" of the menubutton, which is the area | |
| 100 // containing the menu marker, and any padding surrounding it. | |
| 101 int GetShoulderWidth() const; | |
|
tapted
2016/04/26 05:05:57
can this be made private:?
Elly Fong-Jones
2016/04/26 17:41:25
Done.
| |
| 102 | |
| 105 private: | 103 private: |
| 106 friend class PressedLock; | 104 friend class PressedLock; |
| 107 | 105 |
| 108 // Increment/decrement the number of "pressed" locks this button has, and | 106 // Increment/decrement the number of "pressed" locks this button has, and |
| 109 // set the state accordingly. The ink drop is snapped to the final ACTIVATED | 107 // 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 | 108 // state if |snap_ink_drop_to_activated| is true, otherwise the ink drop will |
| 111 // be animated to the ACTIVATED state. | 109 // be animated to the ACTIVATED state. |
| 112 void IncrementPressedLocked(bool snap_ink_drop_to_activated); | 110 void IncrementPressedLocked(bool snap_ink_drop_to_activated); |
| 113 void DecrementPressedLocked(); | 111 void DecrementPressedLocked(); |
| 114 | 112 |
| 115 // Compute the maximum X coordinate for the current screen. MenuButtons | 113 // Compute the maximum X coordinate for the current screen. MenuButtons |
| 116 // use this to make sure a menu is never shown off screen. | 114 // use this to make sure a menu is never shown off screen. |
| 117 int GetMaximumScreenXCoordinate(); | 115 int GetMaximumScreenXCoordinate(); |
| 118 | 116 |
| 119 // We use a time object in order to keep track of when the menu was closed. | 117 // 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 | 118 // 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 | 119 // 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 | 120 // 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, | 121 // menu is displayed using a modal loop and, unlike regular menus in Windows, |
| 124 // the button is not part of the displayed menu. | 122 // the button is not part of the displayed menu. |
| 125 base::TimeTicks menu_closed_time_; | 123 base::TimeTicks menu_closed_time_; |
| 126 | 124 |
| 127 // Our listener. Not owned. | 125 // Our listener. Not owned. |
| 128 MenuButtonListener* listener_; | 126 MenuButtonListener* listener_; |
| 129 | 127 |
| 130 // Whether or not we're showing a drop marker. | 128 // Whether or not we're showing a drop marker. |
| 131 bool show_menu_marker_; | 129 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 | 130 |
| 136 // If non-null the destructor sets this to true. This is set while the menu is | 131 // 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. | 132 // showing and used to detect if the menu was deleted while running. |
| 138 bool* destroyed_flag_; | 133 bool* destroyed_flag_; |
| 139 | 134 |
| 140 // The current number of "pressed" locks this button has. | 135 // The current number of "pressed" locks this button has. |
| 141 int pressed_lock_count_; | 136 int pressed_lock_count_; |
| 142 | 137 |
| 143 // Used to let Activate() know if IncrementPressedLocked() was called. | 138 // Used to let Activate() know if IncrementPressedLocked() was called. |
| 144 bool* increment_pressed_lock_called_; | 139 bool* increment_pressed_lock_called_; |
| 145 | 140 |
| 146 // True if the button was in a disabled state when a menu was run, and should | 141 // 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 | 142 // return to it once the press is complete. This can happen if, e.g., we |
| 148 // programmatically show a menu on a disabled button. | 143 // programmatically show a menu on a disabled button. |
| 149 bool should_disable_after_press_; | 144 bool should_disable_after_press_; |
| 150 | 145 |
| 146 // The images to draw for the menu marker, if |show_menu_marker_| is true. | |
| 147 gfx::ImageSkia enabled_marker_image_; | |
| 148 gfx::ImageSkia disabled_marker_image_; | |
|
tapted
2016/04/26 05:05:57
Since the default PlatformStyle ignores the `enabl
Elly Fong-Jones
2016/04/26 17:41:25
Done.
| |
| 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 |