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

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

Issue 1904753002: MenuButton: support Mac look & feel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cache arrow images Created 4 years, 8 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_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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 enum Style { 47 enum Style {
48 STYLE_NORMAL, 48 STYLE_NORMAL,
49 STYLE_ACTION, 49 STYLE_ACTION,
50 }; 50 };
51 51
52 // The combobox's class name. 52 // The combobox's class name.
53 static const char kViewClassName[]; 53 static const char kViewClassName[];
54 54
55 // |model| is not owned by the combobox. 55 // |model| is not owned by the combobox.
56 explicit Combobox(ui::ComboboxModel* model); 56 explicit Combobox(ui::ComboboxModel* model);
57 Combobox(ui::ComboboxModel* model, Style style);
tapted 2016/04/26 05:05:58 nit: move before the `explicit` constructor? Or re
Elly Fong-Jones 2016/04/26 17:41:25 Done.
57 ~Combobox() override; 58 ~Combobox() override;
58 59
59 static const gfx::FontList& GetFontList(); 60 static const gfx::FontList& GetFontList();
60 61
61 // Sets the listener which will be called when a selection has been made. 62 // Sets the listener which will be called when a selection has been made.
62 void set_listener(ComboboxListener* listener) { listener_ = listener; } 63 void set_listener(ComboboxListener* listener) { listener_ = listener; }
63 64
64 void SetStyle(Style style);
65
66 // Informs the combobox that its model changed. 65 // Informs the combobox that its model changed.
67 void ModelChanged(); 66 void ModelChanged();
68 67
69 // Gets/Sets the selected index. 68 // Gets/Sets the selected index.
70 int selected_index() const { return selected_index_; } 69 int selected_index() const { return selected_index_; }
71 void SetSelectedIndex(int index); 70 void SetSelectedIndex(int index);
72 71
73 // Looks for the first occurrence of |value| in |model()|. If found, selects 72 // Looks for the first occurrence of |value| in |model()|. If found, selects
74 // the found index and returns true. Otherwise simply noops and returns false. 73 // the found index and returns true. Otherwise simply noops and returns false.
75 bool SelectValue(const base::string16& value); 74 bool SelectValue(const base::string16& value);
76 75
77 ui::ComboboxModel* model() const { return model_; } 76 ui::ComboboxModel* model() const { return model_; }
78 77
79 // Set the accessible name of the combobox. 78 // Set the accessible name of the combobox.
80 void SetAccessibleName(const base::string16& name); 79 void SetAccessibleName(const base::string16& name);
81 80
82 // Visually marks the combobox as having an invalid value selected. 81 // Visually marks the combobox as having an invalid value selected.
83 // When invalid, it paints with white text on a red background. 82 // When invalid, it paints with white text on a red background.
84 // Callers are responsible for restoring validity with selection changes. 83 // Callers are responsible for restoring validity with selection changes.
85 void SetInvalid(bool invalid); 84 void SetInvalid(bool invalid);
86 bool invalid() const { return invalid_; } 85 bool invalid() const { return invalid_; }
87 86
88 // Returns the width of the arrow button component of the combobox: the arrow 87 // Returns the width of the combobox's "shoulder", which is the part
89 // button itself, and the padding on either side of it. 88 // containing the arrow, including any padding space around it.
tapted 2016/04/26 05:05:57 nit: remove "space"
Elly Fong-Jones 2016/04/26 17:41:26 Done.
90 int GetArrowButtonWidth() const; 89 int GetShoulderWidth() const;
tapted 2016/04/26 05:05:57 Can these be in the private: section? Also make su
Elly Fong-Jones 2016/04/26 17:41:26 Done.
91 90
92 // Overridden from View: 91 // Overridden from View:
93 gfx::Size GetPreferredSize() const override; 92 gfx::Size GetPreferredSize() const override;
94 const char* GetClassName() const override; 93 const char* GetClassName() const override;
95 bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) override; 94 bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) override;
96 bool OnKeyPressed(const ui::KeyEvent& e) override; 95 bool OnKeyPressed(const ui::KeyEvent& e) override;
97 bool OnKeyReleased(const ui::KeyEvent& e) override; 96 bool OnKeyReleased(const ui::KeyEvent& e) override;
98 void OnPaint(gfx::Canvas* canvas) override; 97 void OnPaint(gfx::Canvas* canvas) override;
99 void OnFocus() override; 98 void OnFocus() override;
100 void OnBlur() override; 99 void OnBlur() override;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 144
146 // Handles the clicking event. 145 // Handles the clicking event.
147 void HandleClickEvent(); 146 void HandleClickEvent();
148 147
149 PrefixSelector* GetPrefixSelector(); 148 PrefixSelector* GetPrefixSelector();
150 149
151 // Our model. Not owned. 150 // Our model. Not owned.
152 ui::ComboboxModel* model_; 151 ui::ComboboxModel* model_;
153 152
154 // The visual style of this combobox. 153 // The visual style of this combobox.
155 Style style_; 154 const Style style_;
tapted 2016/04/26 05:05:57 nice - I like this :)
Elly Fong-Jones 2016/04/26 17:41:26 Done.
156 155
157 // Our listener. Not owned. Notified when the selected index change. 156 // Our listener. Not owned. Notified when the selected index change.
158 ComboboxListener* listener_; 157 ComboboxListener* listener_;
159 158
160 // The current selected index; -1 and means no selection. 159 // The current selected index; -1 and means no selection.
161 int selected_index_; 160 int selected_index_;
162 161
163 // True when the selection is visually denoted as invalid. 162 // True when the selection is visually denoted as invalid.
164 bool invalid_; 163 bool invalid_;
165 164
(...skipping 30 matching lines...) Expand all
196 // STYLE_NOTIFY_ON_CLICK, a Combobox renders the button images according to 195 // STYLE_NOTIFY_ON_CLICK, a Combobox renders the button images according to
197 // these button states. 196 // these button states.
198 // The base View takes the ownerships of these as child views. 197 // The base View takes the ownerships of these as child views.
199 CustomButton* text_button_; 198 CustomButton* text_button_;
200 CustomButton* arrow_button_; 199 CustomButton* arrow_button_;
201 200
202 // Set while the dropdown is showing. Ensures the menu is closed if |this| is 201 // Set while the dropdown is showing. Ensures the menu is closed if |this| is
203 // destroyed. 202 // destroyed.
204 std::unique_ptr<views::MenuRunner> menu_runner_; 203 std::unique_ptr<views::MenuRunner> menu_runner_;
205 204
205 // The image to be drawn for this combobox's arrow.
206 gfx::ImageSkia enabled_arrow_image_;
207 gfx::ImageSkia disabled_arrow_image_;
tapted 2016/04/26 05:05:57 (per prior comment, just one image)
Elly Fong-Jones 2016/04/26 17:41:26 Done.
208
206 // Used for making calbacks. 209 // Used for making calbacks.
207 base::WeakPtrFactory<Combobox> weak_ptr_factory_; 210 base::WeakPtrFactory<Combobox> weak_ptr_factory_;
208 211
209 DISALLOW_COPY_AND_ASSIGN(Combobox); 212 DISALLOW_COPY_AND_ASSIGN(Combobox);
210 }; 213 };
211 214
212 } // namespace views 215 } // namespace views
213 216
214 #endif // UI_VIEWS_CONTROLS_COMBOBOX_COMBOBOX_H_ 217 #endif // UI_VIEWS_CONTROLS_COMBOBOX_COMBOBOX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698