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_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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 // The style of the combobox. | 46 // The style of the combobox. |
| 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, Style style = STYLE_NORMAL); |
| 57 ~Combobox() override; | 57 ~Combobox() override; |
| 58 | 58 |
| 59 static const gfx::FontList& GetFontList(); | 59 static const gfx::FontList& GetFontList(); |
| 60 | 60 |
| 61 // Sets the listener which will be called when a selection has been made. | 61 // Sets the listener which will be called when a selection has been made. |
| 62 void set_listener(ComboboxListener* listener) { listener_ = listener; } | 62 void set_listener(ComboboxListener* listener) { listener_ = listener; } |
| 63 | 63 |
| 64 void SetStyle(Style style); | |
| 65 | |
| 66 // Informs the combobox that its model changed. | 64 // Informs the combobox that its model changed. |
| 67 void ModelChanged(); | 65 void ModelChanged(); |
| 68 | 66 |
| 69 // Gets/Sets the selected index. | 67 // Gets/Sets the selected index. |
| 70 int selected_index() const { return selected_index_; } | 68 int selected_index() const { return selected_index_; } |
| 71 void SetSelectedIndex(int index); | 69 void SetSelectedIndex(int index); |
| 72 | 70 |
| 73 // Looks for the first occurrence of |value| in |model()|. If found, selects | 71 // 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. | 72 // the found index and returns true. Otherwise simply noops and returns false. |
| 75 bool SelectValue(const base::string16& value); | 73 bool SelectValue(const base::string16& value); |
| 76 | 74 |
| 77 ui::ComboboxModel* model() const { return model_; } | 75 ui::ComboboxModel* model() const { return model_; } |
| 78 | 76 |
| 79 // Set the accessible name of the combobox. | 77 // Set the accessible name of the combobox. |
| 80 void SetAccessibleName(const base::string16& name); | 78 void SetAccessibleName(const base::string16& name); |
| 81 | 79 |
| 82 // Visually marks the combobox as having an invalid value selected. | 80 // Visually marks the combobox as having an invalid value selected. |
| 83 // When invalid, it paints with white text on a red background. | 81 // When invalid, it paints with white text on a red background. |
| 84 // Callers are responsible for restoring validity with selection changes. | 82 // Callers are responsible for restoring validity with selection changes. |
| 85 void SetInvalid(bool invalid); | 83 void SetInvalid(bool invalid); |
| 86 bool invalid() const { return invalid_; } | 84 bool invalid() const { return invalid_; } |
| 87 | 85 |
| 88 // Returns the width of the arrow button component of the combobox: the arrow | |
| 89 // button itself, and the padding on either side of it. | |
| 90 int GetArrowButtonWidth() const; | |
| 91 | |
| 92 // Overridden from View: | 86 // Overridden from View: |
| 93 gfx::Size GetPreferredSize() const override; | 87 gfx::Size GetPreferredSize() const override; |
| 94 const char* GetClassName() const override; | 88 const char* GetClassName() const override; |
| 95 bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) override; | 89 bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) override; |
| 96 bool OnKeyPressed(const ui::KeyEvent& e) override; | 90 bool OnKeyPressed(const ui::KeyEvent& e) override; |
| 97 bool OnKeyReleased(const ui::KeyEvent& e) override; | 91 bool OnKeyReleased(const ui::KeyEvent& e) override; |
| 98 void OnPaint(gfx::Canvas* canvas) override; | 92 void OnPaint(gfx::Canvas* canvas) override; |
| 99 void OnFocus() override; | 93 void OnFocus() override; |
| 100 void OnBlur() override; | 94 void OnBlur() override; |
| 101 void GetAccessibleState(ui::AXViewState* state) override; | 95 void GetAccessibleState(ui::AXViewState* state) override; |
| 102 void Layout() override; | 96 void Layout() override; |
| 97 void OnEnabledChanged() override; | |
| 103 | 98 |
| 104 // Overridden from PrefixDelegate: | 99 // Overridden from PrefixDelegate: |
| 105 int GetRowCount() override; | 100 int GetRowCount() override; |
| 106 int GetSelectedRow() override; | 101 int GetSelectedRow() override; |
| 107 void SetSelectedRow(int row) override; | 102 void SetSelectedRow(int row) override; |
| 108 base::string16 GetTextForRow(int row) override; | 103 base::string16 GetTextForRow(int row) override; |
| 109 | 104 |
| 110 // Overriden from ButtonListener: | 105 // Overriden from ButtonListener: |
| 111 void ButtonPressed(Button* sender, const ui::Event& event) override; | 106 void ButtonPressed(Button* sender, const ui::Event& event) override; |
| 112 | 107 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 141 | 136 |
| 142 // Finds the size of the largest menu label or, for STYLE_ACTION, the size of | 137 // Finds the size of the largest menu label or, for STYLE_ACTION, the size of |
| 143 // the selected label. | 138 // the selected label. |
| 144 gfx::Size GetContentSize() const; | 139 gfx::Size GetContentSize() const; |
| 145 | 140 |
| 146 // Handles the clicking event. | 141 // Handles the clicking event. |
| 147 void HandleClickEvent(); | 142 void HandleClickEvent(); |
| 148 | 143 |
| 149 PrefixSelector* GetPrefixSelector(); | 144 PrefixSelector* GetPrefixSelector(); |
| 150 | 145 |
| 146 // Returns the width of the combobox's "shoulder", which is the part | |
| 147 // containing the arrow, including any padding around it. | |
| 148 int GetShoulderWidth() const; | |
|
sky
2016/05/17 16:49:21
Shoulder? Why not ArrowWidth? Or ArrowContainerWid
Elly Fong-Jones
2016/05/17 17:35:05
tapted and I just liked "shoulder" more than "arro
| |
| 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_; |
| 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 Loading... | |
| 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 arrow_image_; | |
| 207 | |
| 206 // Used for making calbacks. | 208 // Used for making calbacks. |
| 207 base::WeakPtrFactory<Combobox> weak_ptr_factory_; | 209 base::WeakPtrFactory<Combobox> weak_ptr_factory_; |
| 208 | 210 |
| 209 DISALLOW_COPY_AND_ASSIGN(Combobox); | 211 DISALLOW_COPY_AND_ASSIGN(Combobox); |
| 210 }; | 212 }; |
| 211 | 213 |
| 212 } // namespace views | 214 } // namespace views |
| 213 | 215 |
| 214 #endif // UI_VIEWS_CONTROLS_COMBOBOX_COMBOBOX_H_ | 216 #endif // UI_VIEWS_CONTROLS_COMBOBOX_COMBOBOX_H_ |
| OLD | NEW |