Chromium Code Reviews| Index: ui/views/controls/combobox/combobox.h |
| diff --git a/ui/views/controls/combobox/combobox.h b/ui/views/controls/combobox/combobox.h |
| index 91469d8073e021cab6c41925d6cbca4f36c868b8..b554d2f0cff2cd0770f7b9c11abdff1217ce23e4 100644 |
| --- a/ui/views/controls/combobox/combobox.h |
| +++ b/ui/views/controls/combobox/combobox.h |
| @@ -9,12 +9,15 @@ |
| #include "base/time/time.h" |
| #include "ui/base/models/combobox_model_observer.h" |
| +#include "ui/gfx/animation/animation_delegate.h" |
| #include "ui/gfx/native_widget_types.h" |
| +#include "ui/views/controls/button/button.h" |
| #include "ui/views/controls/menu/menu_delegate.h" |
| #include "ui/views/controls/prefix_delegate.h" |
| namespace gfx { |
| class Font; |
| +class SlideAnimation; |
| } |
| namespace ui { |
| @@ -29,11 +32,18 @@ class MenuRunner; |
| class PrefixSelector; |
| // A non-editable combobox (aka a drop-down list or selector). |
|
sky
2013/12/02 21:28:55
Add description here of different behaviors. Maybe
hajimehoshi
2013/12/03 10:30:52
Done. (also changed enum Style).
|
| -class VIEWS_EXPORT Combobox |
| - : public MenuDelegate, |
| - public PrefixDelegate, |
| - public ui::ComboboxModelObserver { |
| +class VIEWS_EXPORT Combobox : public MenuDelegate, |
| + public PrefixDelegate, |
| + public ui::ComboboxModelObserver, |
| + public gfx::AnimationDelegate { |
| public: |
| + // The visual style of the combobox. When the style is STYLE_BUTTONS, this |
| + // combobox becames a clickable buttons. |
| + enum Style { |
| + STYLE_NORMAL, |
| + STYLE_BUTTONS, |
| + }; |
| + |
| // The combobox's class name. |
| static const char kViewClassName[]; |
| @@ -46,6 +56,8 @@ class VIEWS_EXPORT Combobox |
| // Sets the listener which will be called when a selection has been made. |
| void set_listener(ComboboxListener* listener) { listener_ = listener; } |
| + void SetStyle(Style style); |
| + |
| // Informs the combobox that its model changed. |
| void ModelChanged(); |
| @@ -74,6 +86,11 @@ class VIEWS_EXPORT Combobox |
| virtual bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) OVERRIDE; |
| virtual bool OnMousePressed(const ui::MouseEvent& mouse_event) OVERRIDE; |
| virtual bool OnMouseDragged(const ui::MouseEvent& mouse_event) OVERRIDE; |
| + virtual void OnMouseReleased(const ui::MouseEvent& mouse_event) OVERRIDE; |
| + virtual void OnMouseCaptureLost() OVERRIDE; |
| + virtual void OnMouseEntered(const ui::MouseEvent& mouse_event) OVERRIDE; |
| + virtual void OnMouseExited(const ui::MouseEvent& mouse_event) OVERRIDE; |
| + virtual void OnMouseMoved(const ui::MouseEvent& mouse_event) OVERRIDE; |
| virtual bool OnKeyPressed(const ui::KeyEvent& e) OVERRIDE; |
| virtual bool OnKeyReleased(const ui::KeyEvent& e) OVERRIDE; |
| virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE; |
| @@ -98,6 +115,9 @@ class VIEWS_EXPORT Combobox |
| // Overriden from ComboboxModelObserver: |
| virtual void OnModelChanged() OVERRIDE; |
| + // Overriden from AnimationDelegate: |
| + virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; |
| + |
| private: |
| // Updates the combobox's content from its model. |
| void UpdateFromModel(); |
| @@ -105,9 +125,12 @@ class VIEWS_EXPORT Combobox |
| // Given bounds within our View, this helper mirrors the bounds if necessary. |
| void AdjustBoundsForRTLUI(gfx::Rect* rect) const; |
| - // Draw the selected value of the drop down list |
| + // Draws the selected value of the drop down list |
| void PaintText(gfx::Canvas* canvas); |
| + // Draws the button images. |
| + void PaintButtons(gfx::Canvas* canvas); |
| + |
| // Show the drop down list |
| void ShowDropDownMenu(ui::MenuSourceType source_type); |
| @@ -117,9 +140,35 @@ class VIEWS_EXPORT Combobox |
| // Converts a menu command ID to a menu item index. |
| int MenuCommandToIndex(int menu_command_id) const; |
| + int GetDisclosureArrowLeftPadding() const; |
| + int GetDisclosureArrowRightPadding() const; |
| + |
| + // Handles the clicking event. |
| + void HandleClickEvent(); |
| + |
| + // Sets the button states. |
| + void SetButtonStates(Button::ButtonState text_button_state, |
| + Button::ButtonState arrow_button_state); |
| + |
| + // Manipulate |animation| according to the button states. |
| + void AnimateStateTransition(gfx::SlideAnimation* animation, |
| + Button::ButtonState from, |
| + Button::ButtonState to); |
| + |
| + // Returns true if the point is in the text button when using the button |
| + // sytle. Returns false if the style is not the button style. |
| + bool InTextButton(const gfx::Point& point); |
| + |
| + // Return true if the point is in the text button when using the button |
| + // sytle. Returns true if the style is not the button style. |
| + bool InArrowButton(const gfx::Point& point); |
| + |
| // Our model. Not owned. |
| ui::ComboboxModel* model_; |
| + // The visual style of this combobox. |
| + Style style_; |
| + |
| // Our listener. Not owned. Notified when the selected index change. |
| ComboboxListener* listener_; |
| @@ -158,6 +207,27 @@ class VIEWS_EXPORT Combobox |
| // The maximum dimensions of the content in the dropdown |
| gfx::Size content_size_; |
| + // The images that are used when |style_| is STYLE_BUTTONS. The first index |
| + // means the state of unfocused or focused. |
| + std::vector<const gfx::ImageSkia*> |
| + body_button_images_[2][Button::STATE_COUNT]; |
| + std::vector<const gfx::ImageSkia*> |
| + menu_button_images_[2][Button::STATE_COUNT]; |
| + |
| + // True if dragging started. |
| + bool drag_started_; |
| + |
| + // The location where dragging started. |
| + gfx::Point drag_start_point_; |
| + |
| + // The states of buttons like pressed or hovered. |
| + Button::ButtonState text_button_state_; |
| + Button::ButtonState arrow_button_state_; |
| + |
| + // The animations to render the hovered buttons. |
| + scoped_ptr<gfx::SlideAnimation> text_button_hover_animation_; |
| + scoped_ptr<gfx::SlideAnimation> arrow_button_hover_animation_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(Combobox); |
| }; |