diff options
author | saintlou@chromium.org <saintlou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-05 16:07:32 +0000 |
---|---|---|
committer | saintlou@chromium.org <saintlou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-05 16:07:32 +0000 |
commit | dc1948711c3e8471ab563a280dc0486dbc384b2a (patch) | |
tree | bab2a88122e9b2c9fc503936209bacea0d24b223 /views/controls/combobox | |
parent | ef2a0da696decfdb7eb2e275f8816b69ca12687b (diff) | |
download | chromium_src-dc1948711c3e8471ab563a280dc0486dbc384b2a.zip chromium_src-dc1948711c3e8471ab563a280dc0486dbc384b2a.tar.gz chromium_src-dc1948711c3e8471ab563a280dc0486dbc384b2a.tar.bz2 |
Removing Menu2 (size is not settable, waiting on another CL)
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6927038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84253 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls/combobox')
-rw-r--r-- | views/controls/combobox/native_combobox_views.cc | 94 | ||||
-rw-r--r-- | views/controls/combobox/native_combobox_views.h | 21 |
2 files changed, 56 insertions, 59 deletions
diff --git a/views/controls/combobox/native_combobox_views.cc b/views/controls/combobox/native_combobox_views.cc index 0de6b5fe9..9d46687 100644 --- a/views/controls/combobox/native_combobox_views.cc +++ b/views/controls/combobox/native_combobox_views.cc @@ -17,8 +17,8 @@ #include "views/border.h" #include "views/controls/combobox/combobox.h" #include "views/controls/focusable_border.h" -#include "views/controls/menu/menu_2.h" #include "views/widget/root_view.h" +#include "views/window/window.h" #if defined(OS_LINUX) #include "ui/gfx/gtk_util.h" @@ -29,7 +29,7 @@ namespace { // A global flag to switch the Combobox wrapper to NativeComboboxViews. bool combobox_view_enabled = false; -// Define the size of the insets +// Define the size of the insets. const int kTopInsetSize = 4; const int kLeftInsetSize = 4; const int kBottomInsetSize = 4; @@ -38,7 +38,7 @@ const int kRightInsetSize = 4; // Limit how small a combobox can be. const int kMinComboboxWidth = 148; -// Size of the combobox arrow +// Size of the combobox arrow. const int kComboboxArrowSize = 9; const int kComboboxArrowOffset = 7; const int kComboboxArrowMargin = 12; @@ -49,6 +49,9 @@ const int kComboboxArrowMargin = 12; const SkColor kDefaultBorderColor = SK_ColorGRAY; const SkColor kTextColor = SK_ColorBLACK; +// Define the id of the first item in the menu (since it needs to be > 0) +const int kFirstMenuItemId = 1000; + } // namespace namespace views { @@ -120,17 +123,21 @@ void NativeComboboxViews::UpdateFromModel() { int max_width = 0; const gfx::Font &font = GetFont(); - // retrieve the items from the model and add them to our own menu - dropdown_list_model_.reset(new ui::SimpleMenuModel(this)); + dropdown_list_menu_.reset(new MenuItemView(this)); + int num_items = combobox_->model()->GetItemCount(); for (int i = 0; i < num_items; ++i) { - // TODO(saintlou): figure out RTL issues string16 text = combobox_->model()->GetItemAt(i); - dropdown_list_model_->AddItem(i, text); - max_width = std::max(max_width, font.GetStringWidth(text)); - } - dropdown_list_menu_.reset(new Menu2(dropdown_list_model_.get())); + // Inserting the Unicode formatting characters if necessary so that the + // text is displayed correctly in right-to-left UIs. + base::i18n::AdjustStringForLocaleDirection(&text); + + dropdown_list_menu_->AppendMenuItem(i + kFirstMenuItemId, UTF16ToWide(text), + MenuItemView::NORMAL); + max_width = std::max(max_width, font.GetStringWidth(text)); + } + content_width_ = max_width; content_height_ = font.GetFontSize(); } @@ -177,31 +184,30 @@ gfx::NativeView NativeComboboxViews::GetTestingHandle() const { } ///////////////////////////////////////////////////////////////// -// NativeComboboxViews, ui::SimpleMenuModel::Delegate overrides: +// NativeComboboxViews, views::MenuDelegate overrides: +// (note that the id received is offset by kFirstMenuItemId) -bool NativeComboboxViews::IsCommandIdChecked(int command_id) const { - return true; +bool NativeComboboxViews::IsItemChecked(int id) const { + return false; } -bool NativeComboboxViews::IsCommandIdEnabled(int command_id) const { +bool NativeComboboxViews::IsCommandEnabled(int id) const { return true; } -bool NativeComboboxViews::GetAcceleratorForCommandId(int command_id, - ui::Accelerator* accelerator) { - return false; +void NativeComboboxViews::ExecuteCommand(int id) { + // revert menu offset to map back to combobox model + id -= kFirstMenuItemId; + DCHECK_LT(id, combobox_->model()->GetItemCount()); + selected_item_ = id; + combobox_->SelectionChanged(); + SchedulePaint(); } -void NativeComboboxViews::ExecuteCommand(int command_id) { - if (command_id >= 0 && command_id < combobox_->model()->GetItemCount()) { - selected_item_ = command_id; - combobox_->SelectionChanged(); - } - else - NOTREACHED() << "unknown command: " << command_id; +bool NativeComboboxViews::GetAccelerator(int id, views::Accelerator* accel) { + return false; } - // static bool NativeComboboxViews::IsComboboxViewsEnabled() { #if defined(TOUCH_UI) @@ -298,33 +304,27 @@ void NativeComboboxViews::PaintText(gfx::Canvas* canvas) { } void NativeComboboxViews::ShowDropDownMenu() { - if (dropdown_list_model_.get()) { - gfx::Rect lb = GetLocalBounds(); - // Both the menu position and the menu anchor type change if the UI layout - // is right-to-left. - gfx::Point menu_position(lb.origin()); + if (!dropdown_list_menu_.get()) + UpdateFromModel(); - if (base::i18n::IsRTL()) - menu_position.Offset(lb.width() - 1, 0); + gfx::Rect lb = GetLocalBounds(); + gfx::Point menu_position(lb.origin()); + View::ConvertPointToScreen(this, &menu_position); + if (menu_position.x() < 0) + menu_position.set_x(0); - View::ConvertPointToScreen(this, &menu_position); + gfx::Rect bounds(menu_position, lb.size()); - if (menu_position.x() < 0) - menu_position.set_x(0); + dropdown_open_ = true; + dropdown_list_menu_->RunMenuAt(NULL, NULL, bounds, MenuItemView::TOPLEFT, + true); + dropdown_open_ = false; - // Open the menu - dropdown_list_menu_.reset(new Menu2(dropdown_list_model_.get())); - dropdown_list_menu_->SetMinimumWidth(lb.width()); - dropdown_open_ = true; - dropdown_list_menu_->RunMenuAt(menu_position, Menu2::ALIGN_TOPLEFT); - dropdown_open_ = false; - - // Need to explicitly clear mouse handler so that events get sent - // properly after the menu finishes running. If we don't do this, then - // the first click to other parts of the UI is eaten. - SetMouseHandler(NULL); - } + // Need to explicitly clear mouse handler so that events get sent + // properly after the menu finishes running. If we don't do this, then + // the first click to other parts of the UI is eaten. + SetMouseHandler(NULL); } } // namespace views diff --git a/views/controls/combobox/native_combobox_views.h b/views/controls/combobox/native_combobox_views.h index 7891731..18d4023 100644 --- a/views/controls/combobox/native_combobox_views.h +++ b/views/controls/combobox/native_combobox_views.h @@ -6,8 +6,8 @@ #define VIEWS_CONTROLS_COMBOBOX_NATIVE_COMBOBOX_VIEWS_H_ #pragma once -#include "ui/base/models/simple_menu_model.h" #include "views/controls/combobox/native_combobox_wrapper.h" +#include "views/controls/menu/menu_delegate.h" #include "views/view.h" namespace gfx { @@ -25,7 +25,7 @@ class FocusableBorder; // No platform specific code is used. class NativeComboboxViews : public views::View, public NativeComboboxWrapper, - public ui::SimpleMenuModel::Delegate { + public views::MenuDelegate { public: explicit NativeComboboxViews(Combobox* parent); virtual ~NativeComboboxViews(); @@ -50,13 +50,11 @@ class NativeComboboxViews : public views::View, virtual void SetFocus() OVERRIDE; virtual gfx::NativeView GetTestingHandle() const OVERRIDE; - // ui::SimpleMenuModel::Delegate overrides - virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; - virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; - virtual bool GetAcceleratorForCommandId( - int command_id, - ui::Accelerator* accelerator) OVERRIDE; - virtual void ExecuteCommand(int command_id) OVERRIDE; + // MenuDelegate overrides: + 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, views::Accelerator* accelerator) OVERRIDE; // class name of internal static const char kViewClassName[]; @@ -64,7 +62,7 @@ class NativeComboboxViews : public views::View, // Returns true when // 1) built with GYP_DEFINES="touchui=1" // 2) enabled by SetEnableComboboxViews(true) - // 3) enabled by the command line flag "--enable-combobox-view") + // 3) enabled by the command line flag "--use-pure-views") static bool IsComboboxViewsEnabled(); // Enable/Disable NativeComboboxViews implementation for Combobox. static void SetEnableComboboxViews(bool enabled); @@ -90,8 +88,7 @@ class NativeComboboxViews : public views::View, FocusableBorder* text_border_; // Context menu and its content list for the combobox. - scoped_ptr<ui::SimpleMenuModel> dropdown_list_model_; - scoped_ptr<Menu2> dropdown_list_menu_; + scoped_ptr<views::MenuItemView> dropdown_list_menu_; // Is the drop down list showing bool dropdown_open_; |