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

Unified Diff: ui/views/controls/combobox/combobox.h

Issue 59383003: Add the button style for combobox (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sky's review (3) Created 7 years 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 side-by-side diff with in-line comments
Download patch
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..dc446644bc4c03044815fcd2e6199fce159a377e 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 {
@@ -24,16 +27,28 @@ class ComboboxModel;
namespace views {
class ComboboxListener;
+class CustomButton;
class FocusableBorder;
class MenuRunner;
+class Painter;
class PrefixSelector;
// A non-editable combobox (aka a drop-down list or selector).
-class VIEWS_EXPORT Combobox
- : public MenuDelegate,
- public PrefixDelegate,
- public ui::ComboboxModelObserver {
+// Combobox has two distinct parts, the drop down arrow and the text. When the
+// user clicks on the text the drop down is either shown
+// (STYLE_SHOW_DROP_DOWN_ON_CLICK) or the listener is notified
+// (STYLE_NOTIFY_ON_CLICK).
+class VIEWS_EXPORT Combobox : public MenuDelegate,
+ public PrefixDelegate,
+ public ui::ComboboxModelObserver,
+ public ButtonListener {
public:
+ // The style of the combobox.
+ enum Style {
+ STYLE_SHOW_DROP_DOWN_ON_CLICK,
+ STYLE_NOTIFY_ON_CLICK,
+ };
+
// The combobox's class name.
static const char kViewClassName[];
@@ -46,6 +61,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();
@@ -72,16 +89,14 @@ class VIEWS_EXPORT Combobox
virtual gfx::Size GetPreferredSize() OVERRIDE;
virtual const char* GetClassName() const OVERRIDE;
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 bool OnKeyPressed(const ui::KeyEvent& e) OVERRIDE;
virtual bool OnKeyReleased(const ui::KeyEvent& e) OVERRIDE;
- virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE;
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
virtual void OnFocus() OVERRIDE;
virtual void OnBlur() OVERRIDE;
virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
virtual ui::TextInputClient* GetTextInputClient() OVERRIDE;
+ virtual void Layout() OVERRIDE;
// Overridden from MenuDelegate:
virtual bool IsItemChecked(int id) const OVERRIDE;
@@ -98,6 +113,9 @@ class VIEWS_EXPORT Combobox
// Overriden from ComboboxModelObserver:
virtual void OnModelChanged() OVERRIDE;
+ // Overriden from ButtonListener:
+ virtual void ButtonPressed(Button* sender, const ui::Event& event) OVERRIDE;
+
private:
// Updates the combobox's content from its model.
void UpdateFromModel();
@@ -105,9 +123,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 +138,18 @@ 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();
+
// 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 +188,22 @@ class VIEWS_EXPORT Combobox
// The maximum dimensions of the content in the dropdown
gfx::Size content_size_;
+ // The painters or images that are used when |style_| is STYLE_BUTTONS. The
+ // first index means the state of unfocused or focused.
+ // The images are owned by ResourceBundle.
+ scoped_ptr<Painter> body_button_painters_[2][Button::STATE_COUNT];
+ std::vector<const gfx::ImageSkia*>
+ menu_button_images_[2][Button::STATE_COUNT];
+
+ // The transparent buttons to handle events and render buttons. These are
+ // placed on top of this combobox as child views, accept event and manage the
+ // button states. These are not rendered but when |style_| is
+ // STYLE_NOTIFY_ON_CLICK, a Combobox renders the button images according to
+ // these button states.
+ // The base View takes the ownerships of these as child views.
+ CustomButton* text_button_;
+ CustomButton* arrow_button_;
+
DISALLOW_COPY_AND_ASSIGN(Combobox);
};

Powered by Google App Engine
This is Rietveld 408576698