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 25 matching lines...) Expand all Loading... | |
| 36 ~PressedLock(); | 36 ~PressedLock(); |
| 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. | |
| 47 static const int kMenuMarkerPaddingLeft; | |
| 48 static const int kMenuMarkerPaddingRight; | |
| 49 | |
| 50 // Create a Button. | 46 // Create a Button. |
| 51 MenuButton(const base::string16& text, | 47 MenuButton(const base::string16& text, |
| 52 MenuButtonListener* menu_button_listener, | 48 MenuButtonListener* menu_button_listener, |
| 53 bool show_menu_marker); | 49 bool show_menu_marker); |
| 54 ~MenuButton() override; | 50 ~MenuButton() override; |
| 55 | 51 |
| 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_; } | 52 const gfx::Point& menu_offset() const { return menu_offset_; } |
| 63 void set_menu_offset(int x, int y) { menu_offset_.SetPoint(x, y); } | 53 void set_menu_offset(int x, int y) { menu_offset_.SetPoint(x, y); } |
| 64 | 54 |
| 65 // Activate the button (called when the button is pressed). |event| is the | 55 // Activate the button (called when the button is pressed). |event| is the |
| 66 // event triggering the activation, if any. | 56 // event triggering the activation, if any. |
| 67 bool Activate(const ui::Event* event); | 57 bool Activate(const ui::Event* event); |
| 68 | 58 |
| 69 // Returns true if the event is of the proper type to potentially trigger an | 59 // 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 | 60 // 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 | 61 // last menu open time) to determine if an event is valid to activate the |
| 72 // menu, this is distinct from IsTriggerableEvent(). | 62 // menu, this is distinct from IsTriggerableEvent(). |
| 73 virtual bool IsTriggerableEventType(const ui::Event& event); | 63 virtual bool IsTriggerableEventType(const ui::Event& event); |
| 74 | 64 |
| 75 // Overridden from View: | 65 // Overridden from View: |
| 76 gfx::Size GetPreferredSize() const override; | 66 gfx::Size GetPreferredSize() const override; |
| 77 const char* GetClassName() const override; | 67 const char* GetClassName() const override; |
| 78 void OnPaint(gfx::Canvas* canvas) override; | 68 void OnPaint(gfx::Canvas* canvas) override; |
| 79 bool OnMousePressed(const ui::MouseEvent& event) override; | 69 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 80 void OnMouseReleased(const ui::MouseEvent& event) override; | 70 void OnMouseReleased(const ui::MouseEvent& event) override; |
| 81 void OnMouseEntered(const ui::MouseEvent& event) override; | 71 void OnMouseEntered(const ui::MouseEvent& event) override; |
| 82 void OnMouseExited(const ui::MouseEvent& event) override; | 72 void OnMouseExited(const ui::MouseEvent& event) override; |
| 83 void OnMouseMoved(const ui::MouseEvent& event) override; | 73 void OnMouseMoved(const ui::MouseEvent& event) override; |
| 84 void OnGestureEvent(ui::GestureEvent* event) override; | 74 void OnGestureEvent(ui::GestureEvent* event) override; |
| 85 bool OnKeyPressed(const ui::KeyEvent& event) override; | 75 bool OnKeyPressed(const ui::KeyEvent& event) override; |
| 86 bool OnKeyReleased(const ui::KeyEvent& event) override; | 76 bool OnKeyReleased(const ui::KeyEvent& event) override; |
| 87 void GetAccessibleState(ui::AXViewState* state) override; | 77 void GetAccessibleState(ui::AXViewState* state) override; |
| 78 void OnEnabledChanged() override; | |
| 79 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; | |
| 88 | 80 |
| 89 protected: | 81 protected: |
| 90 // Paint the menu marker image. | 82 // Paint the menu marker image. |
| 91 void PaintMenuMarker(gfx::Canvas* canvas); | 83 void PaintMenuMarker(gfx::Canvas* canvas); |
| 92 | 84 |
| 93 // Overridden from LabelButton: | 85 // Overridden from LabelButton: |
| 94 gfx::Rect GetChildAreaBounds() override; | 86 gfx::Rect GetChildAreaBounds() override; |
| 95 | 87 |
| 96 // Overridden from CustomButton: | 88 // Overridden from CustomButton: |
| 97 bool IsTriggerableEvent(const ui::Event& event) override; | 89 bool IsTriggerableEvent(const ui::Event& event) override; |
| 98 bool ShouldEnterPushedState(const ui::Event& event) override; | 90 bool ShouldEnterPushedState(const ui::Event& event) override; |
| 99 void StateChanged() override; | 91 void StateChanged() override; |
| 100 void NotifyClick(const ui::Event& event) override; | 92 void NotifyClick(const ui::Event& event) override; |
| 101 | 93 |
| 94 // Subclasses that want to use a border can override this method. | |
| 95 virtual bool ShouldUsePlatformStyleBorder() const; | |
|
tapted
2016/04/29 06:53:18
nit: usually newly introduced methods come before
Elly Fong-Jones
2016/05/06 21:30:45
Done.
| |
| 96 | |
| 102 // Offset of the associated menu position. | 97 // Offset of the associated menu position. |
| 103 gfx::Point menu_offset_; | 98 gfx::Point menu_offset_; |
| 104 | 99 |
| 105 private: | 100 private: |
| 106 friend class PressedLock; | 101 friend class PressedLock; |
| 107 | 102 |
| 108 // Increment/decrement the number of "pressed" locks this button has, and | 103 // 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 | 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 | |
| 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 |
| 130 // Whether or not we're showing a drop marker. | 129 // Whether or not we're showing a drop marker. |
| 131 bool show_menu_marker_; | 130 const bool show_menu_marker_; |
| 132 | 131 |
| 133 // The down arrow used to differentiate the menu button from normal buttons. | 132 // The down arrow used to differentiate the menu button from normal buttons. |
| 134 const gfx::ImageSkia* menu_marker_; | 133 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 |