Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: ui/views/controls/button/menu_button.h

Issue 1904753002: MenuButton: support Mac look & feel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add basic tests Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
85 // Subclasses that want to use a border can override this method.
86 virtual bool ShouldUsePlatformStyleBackground() const;
87 virtual bool ShouldUsePlatformStyleBorder() const;
tapted 2016/05/09 08:01:35 So I think there is a nicer solution that doesn't
88
93 // Overridden from LabelButton: 89 // Overridden from LabelButton:
94 gfx::Rect GetChildAreaBounds() override; 90 gfx::Rect GetChildAreaBounds() override;
95 91
96 // Overridden from CustomButton: 92 // Overridden from CustomButton:
97 bool IsTriggerableEvent(const ui::Event& event) override; 93 bool IsTriggerableEvent(const ui::Event& event) override;
98 bool ShouldEnterPushedState(const ui::Event& event) override; 94 bool ShouldEnterPushedState(const ui::Event& event) override;
99 void StateChanged() override; 95 void StateChanged() override;
100 void NotifyClick(const ui::Event& event) override; 96 void NotifyClick(const ui::Event& event) override;
101 97
102 // Offset of the associated menu position. 98 // Offset of the associated menu position.
103 gfx::Point menu_offset_; 99 gfx::Point menu_offset_;
104 100
105 private: 101 private:
106 friend class PressedLock; 102 friend class PressedLock;
107 103
108 // Increment/decrement the number of "pressed" locks this button has, and 104 // 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 105 // 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 106 // state if |snap_ink_drop_to_activated| is true, otherwise the ink drop will
111 // be animated to the ACTIVATED state. 107 // be animated to the ACTIVATED state.
112 void IncrementPressedLocked(bool snap_ink_drop_to_activated); 108 void IncrementPressedLocked(bool snap_ink_drop_to_activated);
113 void DecrementPressedLocked(); 109 void DecrementPressedLocked();
114 110
115 // Compute the maximum X coordinate for the current screen. MenuButtons 111 // Compute the maximum X coordinate for the current screen. MenuButtons
116 // use this to make sure a menu is never shown off screen. 112 // use this to make sure a menu is never shown off screen.
117 int GetMaximumScreenXCoordinate(); 113 int GetMaximumScreenXCoordinate();
118 114
115 // Returns the width of the "shoulder" of the MenuButton, which is the area
116 // containing the menu marker, and any padding surrounding it.
117 int GetShoulderWidth() const;
118
119 // We use a time object in order to keep track of when the menu was closed. 119 // 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 120 // 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 121 // 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 122 // 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, 123 // menu is displayed using a modal loop and, unlike regular menus in Windows,
124 // the button is not part of the displayed menu. 124 // the button is not part of the displayed menu.
125 base::TimeTicks menu_closed_time_; 125 base::TimeTicks menu_closed_time_;
126 126
127 // Our listener. Not owned. 127 // Our listener. Not owned.
128 MenuButtonListener* listener_; 128 MenuButtonListener* listener_;
129 129
130 // Whether or not we're showing a drop marker. 130 // Whether or not we're showing a drop marker.
131 bool show_menu_marker_; 131 const bool show_menu_marker_;
132 132
133 // The down arrow used to differentiate the menu button from normal buttons. 133 // The down arrow used to differentiate the menu button from normal buttons.
134 const gfx::ImageSkia* menu_marker_; 134 gfx::ImageSkia menu_marker_;
135 135
136 // If non-null the destructor sets this to true. This is set while the menu is 136 // 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. 137 // showing and used to detect if the menu was deleted while running.
138 bool* destroyed_flag_; 138 bool* destroyed_flag_;
139 139
140 // The current number of "pressed" locks this button has. 140 // The current number of "pressed" locks this button has.
141 int pressed_lock_count_; 141 int pressed_lock_count_;
142 142
143 // Used to let Activate() know if IncrementPressedLocked() was called. 143 // Used to let Activate() know if IncrementPressedLocked() was called.
144 bool* increment_pressed_lock_called_; 144 bool* increment_pressed_lock_called_;
145 145
146 // True if the button was in a disabled state when a menu was run, and should 146 // 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 147 // return to it once the press is complete. This can happen if, e.g., we
148 // programmatically show a menu on a disabled button. 148 // programmatically show a menu on a disabled button.
149 bool should_disable_after_press_; 149 bool should_disable_after_press_;
150 150
151 base::WeakPtrFactory<MenuButton> weak_factory_; 151 base::WeakPtrFactory<MenuButton> weak_factory_;
152 152
153 DISALLOW_COPY_AND_ASSIGN(MenuButton); 153 DISALLOW_COPY_AND_ASSIGN(MenuButton);
154 }; 154 };
155 155
156 } // namespace views 156 } // namespace views
157 157
158 #endif // UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_H_ 158 #endif // UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698