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

Side by Side Diff: ui/views/controls/combobox/combobox.h

Issue 2264403006: Update ui/views menus to use async (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review Updates Created 4 years, 3 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
« no previous file with comments | « no previous file | ui/views/controls/combobox/combobox.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_COMBOBOX_COMBOBOX_H_ 5 #ifndef UI_VIEWS_CONTROLS_COMBOBOX_COMBOBOX_H_
6 #define UI_VIEWS_CONTROLS_COMBOBOX_COMBOBOX_H_ 6 #define UI_VIEWS_CONTROLS_COMBOBOX_COMBOBOX_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 10 matching lines...) Expand all
21 class MenuModel; 21 class MenuModel;
22 } 22 }
23 23
24 namespace views { 24 namespace views {
25 namespace test { 25 namespace test {
26 class ComboboxTestApi; 26 class ComboboxTestApi;
27 } 27 }
28 28
29 class ComboboxListener; 29 class ComboboxListener;
30 class CustomButton; 30 class CustomButton;
31 class MenuModelAdapter;
31 class MenuRunner; 32 class MenuRunner;
32 class Painter; 33 class Painter;
33 class PrefixSelector; 34 class PrefixSelector;
34 35
35 // A non-editable combobox (aka a drop-down list or selector). 36 // A non-editable combobox (aka a drop-down list or selector).
36 // Combobox has two distinct parts, the drop down arrow and the text. Combobox 37 // Combobox has two distinct parts, the drop down arrow and the text. Combobox
37 // offers two distinct behaviors: 38 // offers two distinct behaviors:
38 // * STYLE_NORMAL: typical combobox, clicking on the text and/or button shows 39 // * STYLE_NORMAL: typical combobox, clicking on the text and/or button shows
39 // the drop down, arrow keys change selection, selected index can be changed by 40 // the drop down, arrow keys change selection, selected index can be changed by
40 // the user to something other than the first item. 41 // the user to something other than the first item.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 void ButtonPressed(Button* sender, const ui::Event& event) override; 107 void ButtonPressed(Button* sender, const ui::Event& event) override;
107 108
108 protected: 109 protected:
109 void set_size_to_largest_label(bool size_to_largest_label) { 110 void set_size_to_largest_label(bool size_to_largest_label) {
110 size_to_largest_label_ = size_to_largest_label; 111 size_to_largest_label_ = size_to_largest_label;
111 } 112 }
112 113
113 private: 114 private:
114 friend class test::ComboboxTestApi; 115 friend class test::ComboboxTestApi;
115 116
116 class ComboboxMenuModelAdapter; 117 class ComboboxMenuModel;
117 118
118 // Updates the border according to the current state. 119 // Updates the border according to the current state.
119 void UpdateBorder(); 120 void UpdateBorder();
120 121
121 // Given bounds within our View, this helper mirrors the bounds if necessary. 122 // Given bounds within our View, this helper mirrors the bounds if necessary.
122 void AdjustBoundsForRTLUI(gfx::Rect* rect) const; 123 void AdjustBoundsForRTLUI(gfx::Rect* rect) const;
123 124
124 // Draws the selected value of the drop down list 125 // Draws the selected value of the drop down list
125 void PaintText(gfx::Canvas* canvas); 126 void PaintText(gfx::Canvas* canvas);
126 127
127 // Draws the button images. 128 // Draws the button images.
128 void PaintButtons(gfx::Canvas* canvas); 129 void PaintButtons(gfx::Canvas* canvas);
129 130
130 // Show the drop down list 131 // Show the drop down list
131 void ShowDropDownMenu(ui::MenuSourceType source_type); 132 void ShowDropDownMenu(ui::MenuSourceType source_type);
132 133
134 // Cleans up after the menu as closed
135 void OnMenuClosed(Button::ButtonState original_button_state);
136
133 // Called when the selection is changed by the user. 137 // Called when the selection is changed by the user.
134 void OnPerformAction(); 138 void OnPerformAction();
135 139
136 int GetDisclosureArrowLeftPadding() const; 140 int GetDisclosureArrowLeftPadding() const;
137 int GetDisclosureArrowRightPadding() const; 141 int GetDisclosureArrowRightPadding() const;
138 142
139 // Returns the size of the disclosure arrow. 143 // Returns the size of the disclosure arrow.
140 gfx::Size ArrowSize() const; 144 gfx::Size ArrowSize() const;
141 145
142 // Finds the size of the largest menu label or, for STYLE_ACTION, the size of 146 // Finds the size of the largest menu label or, for STYLE_ACTION, the size of
(...skipping 22 matching lines...) Expand all
165 169
166 // True when the selection is visually denoted as invalid. 170 // True when the selection is visually denoted as invalid.
167 bool invalid_; 171 bool invalid_;
168 172
169 // The accessible name of this combobox. 173 // The accessible name of this combobox.
170 base::string16 accessible_name_; 174 base::string16 accessible_name_;
171 175
172 // A helper used to select entries by keyboard input. 176 // A helper used to select entries by keyboard input.
173 std::unique_ptr<PrefixSelector> selector_; 177 std::unique_ptr<PrefixSelector> selector_;
174 178
175 // Adapts a ComboboxModel for use by a views MenuRunner. 179 // The ComboboxModel for use by |menu_runner_|.
176 std::unique_ptr<ui::MenuModel> menu_model_adapter_; 180 std::unique_ptr<ui::MenuModel> menu_model_;
177 181
178 // Like MenuButton, we use a time object in order to keep track of when the 182 // Like MenuButton, we use a time object in order to keep track of when the
179 // combobox was closed. The time is used for simulating menu behavior; that 183 // combobox was closed. The time is used for simulating menu behavior; that
180 // is, if the menu is shown and the button is pressed, we need to close the 184 // is, if the menu is shown and the button is pressed, we need to close the
181 // menu. There is no clean way to get the second click event because the 185 // menu. There is no clean way to get the second click event because the
182 // menu is displayed using a modal loop and, unlike regular menus in Windows, 186 // menu is displayed using a modal loop and, unlike regular menus in Windows,
183 // the button is not part of the displayed menu. 187 // the button is not part of the displayed menu.
184 base::Time closed_time_; 188 base::Time closed_time_;
185 189
186 // The maximum dimensions of the content in the dropdown. 190 // The maximum dimensions of the content in the dropdown.
(...skipping 10 matching lines...) Expand all
197 // placed on top of this combobox as child views, accept event and manage the 201 // placed on top of this combobox as child views, accept event and manage the
198 // button states. These are not rendered but when |style_| is 202 // button states. These are not rendered but when |style_| is
199 // STYLE_NOTIFY_ON_CLICK, a Combobox renders the button images according to 203 // STYLE_NOTIFY_ON_CLICK, a Combobox renders the button images according to
200 // these button states. 204 // these button states.
201 // The base View takes the ownerships of these as child views. 205 // The base View takes the ownerships of these as child views.
202 CustomButton* text_button_; 206 CustomButton* text_button_;
203 CustomButton* arrow_button_; 207 CustomButton* arrow_button_;
204 208
205 // Set while the dropdown is showing. Ensures the menu is closed if |this| is 209 // Set while the dropdown is showing. Ensures the menu is closed if |this| is
206 // destroyed. 210 // destroyed.
207 std::unique_ptr<views::MenuRunner> menu_runner_; 211 std::unique_ptr<MenuModelAdapter> menu_model_adapter_;
212 std::unique_ptr<MenuRunner> menu_runner_;
208 213
209 // The image to be drawn for this combobox's arrow. 214 // The image to be drawn for this combobox's arrow.
210 gfx::ImageSkia arrow_image_; 215 gfx::ImageSkia arrow_image_;
211 216
212 // When true, the size of contents is defined by the selected label. 217 // When true, the size of contents is defined by the selected label.
213 // Otherwise, it's defined by the widest label in the menu. If this is set to 218 // Otherwise, it's defined by the widest label in the menu. If this is set to
214 // true, the parent view must relayout in ChildPreferredSizeChanged(). 219 // true, the parent view must relayout in ChildPreferredSizeChanged().
215 bool size_to_largest_label_; 220 bool size_to_largest_label_;
216 221
217 // Used for making calbacks. 222 // Used for making calbacks.
218 base::WeakPtrFactory<Combobox> weak_ptr_factory_; 223 base::WeakPtrFactory<Combobox> weak_ptr_factory_;
219 224
220 DISALLOW_COPY_AND_ASSIGN(Combobox); 225 DISALLOW_COPY_AND_ASSIGN(Combobox);
221 }; 226 };
222 227
223 } // namespace views 228 } // namespace views
224 229
225 #endif // UI_VIEWS_CONTROLS_COMBOBOX_COMBOBOX_H_ 230 #endif // UI_VIEWS_CONTROLS_COMBOBOX_COMBOBOX_H_
OLDNEW
« no previous file with comments | « no previous file | ui/views/controls/combobox/combobox.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698