| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/weak_ptr.h" |
| 10 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 11 #include "ui/base/models/combobox_model_observer.h" | 12 #include "ui/base/models/combobox_model_observer.h" |
| 12 #include "ui/gfx/animation/animation_delegate.h" | 13 #include "ui/gfx/animation/animation_delegate.h" |
| 13 #include "ui/gfx/native_widget_types.h" | 14 #include "ui/gfx/native_widget_types.h" |
| 14 #include "ui/views/controls/button/button.h" | 15 #include "ui/views/controls/button/button.h" |
| 15 #include "ui/views/controls/menu/menu_delegate.h" | 16 #include "ui/views/controls/menu/menu_delegate.h" |
| 16 #include "ui/views/controls/prefix_delegate.h" | 17 #include "ui/views/controls/prefix_delegate.h" |
| 17 | 18 |
| 18 namespace gfx { | 19 namespace gfx { |
| 19 class FontList; | 20 class FontList; |
| 20 class SlideAnimation; | 21 class SlideAnimation; |
| 21 } | 22 } |
| 22 | 23 |
| 23 namespace ui { | 24 namespace ui { |
| 24 class ComboboxModel; | 25 class ComboboxModel; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace views { | 28 namespace views { |
| 28 | 29 |
| 29 class ComboboxListener; | 30 class ComboboxListener; |
| 30 class ComboboxMenuRunner; | 31 class ComboboxMenuRunner; |
| 31 class CustomButton; | 32 class CustomButton; |
| 32 class FocusableBorder; | 33 class FocusableBorder; |
| 33 class MenuRunner; | 34 class MenuRunner; |
| 34 class MenuRunnerHandler; | 35 class MenuRunnerHandler; |
| 35 class Painter; | 36 class Painter; |
| 36 class PrefixSelector; | 37 class PrefixSelector; |
| 37 | 38 |
| 38 // A non-editable combobox (aka a drop-down list or selector). | 39 // A non-editable combobox (aka a drop-down list or selector). |
| 39 // Combobox has two distinct parts, the drop down arrow and the text. When the | 40 // Combobox has two distinct parts, the drop down arrow and the text. Combobox |
| 40 // user clicks on the text the drop down is either shown | 41 // offers two distinct behaviors: |
| 41 // (STYLE_SHOW_DROP_DOWN_ON_CLICK) or the listener is notified | 42 // * STYLE_NORMAL: typical combobox, clicking on the text and/or button shows |
| 42 // (STYLE_NOTIFY_ON_CLICK). | 43 // the drop down, arrow keys change selection, selected index can be changed by |
| 44 // the user to something other than the first item. |
| 45 // * STYLE_ACTION: clicking on the text notifies the listener. The menu can be |
| 46 // shown only by clicking on the arrow. The selected index is always reverted to |
| 47 // 0 after the listener is notified. |
| 43 class VIEWS_EXPORT Combobox : public MenuDelegate, | 48 class VIEWS_EXPORT Combobox : public MenuDelegate, |
| 44 public PrefixDelegate, | 49 public PrefixDelegate, |
| 45 public ui::ComboboxModelObserver, | 50 public ui::ComboboxModelObserver, |
| 46 public ButtonListener { | 51 public ButtonListener { |
| 47 public: | 52 public: |
| 48 // The style of the combobox. | 53 // The style of the combobox. |
| 49 enum Style { | 54 enum Style { |
| 50 STYLE_SHOW_DROP_DOWN_ON_CLICK, | 55 STYLE_NORMAL, |
| 51 STYLE_NOTIFY_ON_CLICK, | 56 STYLE_ACTION, |
| 52 }; | 57 }; |
| 53 | 58 |
| 54 // The combobox's class name. | 59 // The combobox's class name. |
| 55 static const char kViewClassName[]; | 60 static const char kViewClassName[]; |
| 56 | 61 |
| 57 // |model| is not owned by the combobox. | 62 // |model| is not owned by the combobox. |
| 58 explicit Combobox(ui::ComboboxModel* model); | 63 explicit Combobox(ui::ComboboxModel* model); |
| 59 virtual ~Combobox(); | 64 virtual ~Combobox(); |
| 60 | 65 |
| 61 static const gfx::FontList& GetFontList(); | 66 static const gfx::FontList& GetFontList(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 119 |
| 115 // Overriden from ComboboxModelObserver: | 120 // Overriden from ComboboxModelObserver: |
| 116 virtual void OnComboboxModelChanged(ui::ComboboxModel* model) OVERRIDE; | 121 virtual void OnComboboxModelChanged(ui::ComboboxModel* model) OVERRIDE; |
| 117 | 122 |
| 118 // Overriden from ButtonListener: | 123 // Overriden from ButtonListener: |
| 119 virtual void ButtonPressed(Button* sender, const ui::Event& event) OVERRIDE; | 124 virtual void ButtonPressed(Button* sender, const ui::Event& event) OVERRIDE; |
| 120 | 125 |
| 121 private: | 126 private: |
| 122 FRIEND_TEST_ALL_PREFIXES(ComboboxTest, Click); | 127 FRIEND_TEST_ALL_PREFIXES(ComboboxTest, Click); |
| 123 FRIEND_TEST_ALL_PREFIXES(ComboboxTest, NotifyOnClickWithMouse); | 128 FRIEND_TEST_ALL_PREFIXES(ComboboxTest, NotifyOnClickWithMouse); |
| 129 FRIEND_TEST_ALL_PREFIXES(ComboboxTest, ContentWidth); |
| 124 | 130 |
| 125 // Updates the combobox's content from its model. | 131 // Updates the combobox's content from its model. |
| 126 void UpdateFromModel(); | 132 void UpdateFromModel(); |
| 127 | 133 |
| 128 // Updates the border according to the current state. | 134 // Updates the border according to the current state. |
| 129 void UpdateBorder(); | 135 void UpdateBorder(); |
| 130 | 136 |
| 131 // Given bounds within our View, this helper mirrors the bounds if necessary. | 137 // Given bounds within our View, this helper mirrors the bounds if necessary. |
| 132 void AdjustBoundsForRTLUI(gfx::Rect* rect) const; | 138 void AdjustBoundsForRTLUI(gfx::Rect* rect) const; |
| 133 | 139 |
| 134 // Draws the selected value of the drop down list | 140 // Draws the selected value of the drop down list |
| 135 void PaintText(gfx::Canvas* canvas); | 141 void PaintText(gfx::Canvas* canvas); |
| 136 | 142 |
| 137 // Draws the button images. | 143 // Draws the button images. |
| 138 void PaintButtons(gfx::Canvas* canvas); | 144 void PaintButtons(gfx::Canvas* canvas); |
| 139 | 145 |
| 140 // Show the drop down list | 146 // Show the drop down list |
| 141 void ShowDropDownMenu(ui::MenuSourceType source_type); | 147 void ShowDropDownMenu(ui::MenuSourceType source_type); |
| 142 | 148 |
| 143 // Called when the selection is changed by the user. | 149 // Called when the selection is changed by the user. |
| 144 void OnSelectionChanged(); | 150 void OnPerformAction(); |
| 151 void NotifyPerformAction(); |
| 152 void AfterPerformAction(); |
| 145 | 153 |
| 146 // Converts a menu command ID to a menu item index. | 154 // Converts a menu command ID to a menu item index. |
| 147 int MenuCommandToIndex(int menu_command_id) const; | 155 int MenuCommandToIndex(int menu_command_id) const; |
| 148 | 156 |
| 149 int GetDisclosureArrowLeftPadding() const; | 157 int GetDisclosureArrowLeftPadding() const; |
| 150 int GetDisclosureArrowRightPadding() const; | 158 int GetDisclosureArrowRightPadding() const; |
| 151 | 159 |
| 152 // Handles the clicking event. | 160 // Handles the clicking event. |
| 153 void HandleClickEvent(); | 161 void HandleClickEvent(); |
| 154 | 162 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 | 210 |
| 203 // The transparent buttons to handle events and render buttons. These are | 211 // The transparent buttons to handle events and render buttons. These are |
| 204 // placed on top of this combobox as child views, accept event and manage the | 212 // placed on top of this combobox as child views, accept event and manage the |
| 205 // button states. These are not rendered but when |style_| is | 213 // button states. These are not rendered but when |style_| is |
| 206 // STYLE_NOTIFY_ON_CLICK, a Combobox renders the button images according to | 214 // STYLE_NOTIFY_ON_CLICK, a Combobox renders the button images according to |
| 207 // these button states. | 215 // these button states. |
| 208 // The base View takes the ownerships of these as child views. | 216 // The base View takes the ownerships of these as child views. |
| 209 CustomButton* text_button_; | 217 CustomButton* text_button_; |
| 210 CustomButton* arrow_button_; | 218 CustomButton* arrow_button_; |
| 211 | 219 |
| 220 // Used for making calbacks. |
| 221 base::WeakPtrFactory<Combobox> weak_ptr_factory_; |
| 222 |
| 212 DISALLOW_COPY_AND_ASSIGN(Combobox); | 223 DISALLOW_COPY_AND_ASSIGN(Combobox); |
| 213 }; | 224 }; |
| 214 | 225 |
| 215 } // namespace views | 226 } // namespace views |
| 216 | 227 |
| 217 #endif // UI_VIEWS_CONTROLS_COMBOBOX_COMBOBOX_H_ | 228 #endif // UI_VIEWS_CONTROLS_COMBOBOX_COMBOBOX_H_ |
| OLD | NEW |