summaryrefslogtreecommitdiffstats
path: root/ui/views/controls/combobox/combobox.h
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-14 04:53:08 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-14 04:53:08 +0000
commitf6445da986734610bee921979d10c76cea0f7e23 (patch)
tree0a81f747585e0512c8732018b514b2e39b6a99e1 /ui/views/controls/combobox/combobox.h
parent992558368941b95d0c8f08b7d3887bd4ac2098a9 (diff)
downloadchromium_src-f6445da986734610bee921979d10c76cea0f7e23.zip
chromium_src-f6445da986734610bee921979d10c76cea0f7e23.tar.gz
chromium_src-f6445da986734610bee921979d10c76cea0f7e23.tar.bz2
Remove NativeComboboxWin; consolidate Views Combobox code.
The Views Combobox is used by default on Win M30 (stable). This removes the deprecated native Windows control impl. The NativeComboboxViews impl is promoted to Combobox. Perform additional cleanup (remove wrapper, etc.). BUG=175843 TEST=Views Comboboxes (e.g. in the bookmark bubble) work as expected. R=sky@chromium.org Review URL: https://chromiumcodereview.appspot.com/22889018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223213 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views/controls/combobox/combobox.h')
-rw-r--r--ui/views/controls/combobox/combobox.h97
1 files changed, 61 insertions, 36 deletions
diff --git a/ui/views/controls/combobox/combobox.h b/ui/views/controls/combobox/combobox.h
index e71604e..09188e8 100644
--- a/ui/views/controls/combobox/combobox.h
+++ b/ui/views/controls/combobox/combobox.h
@@ -7,10 +7,10 @@
#include <string>
+#include "base/time/time.h"
#include "ui/gfx/native_widget_types.h"
-#include "ui/views/controls/combobox/native_combobox_wrapper.h"
+#include "ui/views/controls/menu/menu_delegate.h"
#include "ui/views/controls/prefix_delegate.h"
-#include "ui/views/view.h"
namespace gfx {
class Font;
@@ -23,10 +23,12 @@ class ComboboxModel;
namespace views {
class ComboboxListener;
+class FocusableBorder;
+class MenuRunner;
class PrefixSelector;
-// A non-editable combobox (aka a drop-down list).
-class VIEWS_EXPORT Combobox : public PrefixDelegate {
+// A non-editable combobox (aka a drop-down list or selector).
+class VIEWS_EXPORT Combobox : public MenuDelegate, public PrefixDelegate {
public:
// The combobox's class name.
static const char kViewClassName[];
@@ -38,9 +40,7 @@ class VIEWS_EXPORT Combobox : public PrefixDelegate {
static const gfx::Font& GetFont();
// Sets the listener which will be called when a selection has been made.
- void set_listener(ComboboxListener* listener) {
- listener_ = listener;
- }
+ void set_listener(ComboboxListener* listener) { listener_ = listener; }
// Informs the combobox that its model changed.
void ModelChanged();
@@ -49,66 +49,67 @@ class VIEWS_EXPORT Combobox : public PrefixDelegate {
int selected_index() const { return selected_index_; }
void SetSelectedIndex(int index);
- // Called when the combobox's selection is changed by the user.
- void SelectionChanged();
-
ui::ComboboxModel* model() const { return model_; }
// Set the accessible name of the combobox.
void SetAccessibleName(const string16& name);
- // Provided only for testing:
- gfx::NativeView GetTestingHandle() const {
- return native_wrapper_ ? native_wrapper_->GetTestingHandle() : NULL;
- }
- NativeComboboxWrapper* GetNativeWrapperForTesting() const {
- return native_wrapper_;
- }
-
- // Visually marks the combobox as having an invalid value selected. The caller
- // is responsible for flipping it back to valid if the selection changes.
+ // Visually marks the combobox as having an invalid value selected.
+ // When invalid, it paints with white text on a red background.
+ // Callers are responsible for restoring validity with selection changes.
void SetInvalid(bool invalid);
-
- bool invalid() const {
- return invalid_;
- }
+ bool invalid() const { return invalid_; }
// Overridden from View:
virtual gfx::Size GetPreferredSize() OVERRIDE;
- virtual void Layout() OVERRIDE;
- virtual void OnEnabledChanged() OVERRIDE;
+ virtual const char* GetClassName() const OVERRIDE;
virtual bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) OVERRIDE;
- virtual void OnPaintFocusBorder(gfx::Canvas* canvas) 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;
+ // Overridden from MenuDelegate:
+ virtual bool IsItemChecked(int id) const OVERRIDE;
+ virtual bool IsCommandEnabled(int id) const OVERRIDE;
+ virtual void ExecuteCommand(int id) OVERRIDE;
+ virtual bool GetAccelerator(int id, ui::Accelerator* accelerator) OVERRIDE;
+
// Overridden from PrefixDelegate:
virtual int GetRowCount() OVERRIDE;
virtual int GetSelectedRow() OVERRIDE;
virtual void SetSelectedRow(int row) OVERRIDE;
virtual string16 GetTextForRow(int row) OVERRIDE;
- protected:
- // Overridden from View:
- virtual void ViewHierarchyChanged(
- const ViewHierarchyChangedDetails& details) OVERRIDE;
- virtual const char* GetClassName() const OVERRIDE;
+ private:
+ // Updates the combobox's content from its model.
+ void UpdateFromModel();
- // The object that actually implements the native combobox.
- NativeComboboxWrapper* native_wrapper_;
+ // 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
+ void PaintText(gfx::Canvas* canvas);
+
+ // Show the drop down list
+ void ShowDropDownMenu(ui::MenuSourceType source_type);
+
+ // Called when the selection is changed by the user.
+ void OnSelectionChanged();
- private:
// Our model. Not owned.
ui::ComboboxModel* model_;
// Our listener. Not owned. Notified when the selected index change.
ComboboxListener* listener_;
- // The current selected index.
+ // The current selected index; -1 and means no selection.
int selected_index_;
// True when the selection is visually denoted as invalid.
@@ -117,8 +118,32 @@ class VIEWS_EXPORT Combobox : public PrefixDelegate {
// The accessible name of this combobox.
string16 accessible_name_;
+ // A helper used to select entries by keyboard input.
scoped_ptr<PrefixSelector> selector_;
+ // The reference to the border class. The object is owned by View::border_.
+ FocusableBorder* text_border_;
+
+ // The disclosure arrow next to the currently selected item from the list.
+ const gfx::ImageSkia* disclosure_arrow_;
+
+ // Responsible for showing the context menu.
+ scoped_ptr<MenuRunner> dropdown_list_menu_runner_;
+
+ // Is the drop down list showing
+ bool dropdown_open_;
+
+ // Like MenuButton, we use a time object in order to keep track of when the
+ // combobox was closed. The time is used for simulating menu behavior; that
+ // is, if the menu is shown and the button is pressed, we need to close the
+ // menu. There is no clean way to get the second click event because the
+ // menu is displayed using a modal loop and, unlike regular menus in Windows,
+ // the button is not part of the displayed menu.
+ base::Time closed_time_;
+
+ // The maximum dimensions of the content in the dropdown
+ gfx::Size content_size_;
+
DISALLOW_COPY_AND_ASSIGN(Combobox);
};