diff options
Diffstat (limited to 'chromium/ui/views/controls/combobox/combobox.cc')
-rw-r--r-- | chromium/ui/views/controls/combobox/combobox.cc | 437 |
1 files changed, 54 insertions, 383 deletions
diff --git a/chromium/ui/views/controls/combobox/combobox.cc b/chromium/ui/views/controls/combobox/combobox.cc index f900b99d012..41a5ac2b1b3 100644 --- a/chromium/ui/views/controls/combobox/combobox.cc +++ b/chromium/ui/views/controls/combobox/combobox.cc @@ -4,93 +4,41 @@ #include "ui/views/controls/combobox/combobox.h" -#include <stddef.h> - -#include <utility> - #include "base/logging.h" -#include "base/macros.h" #include "build/build_config.h" #include "ui/accessibility/ax_action_data.h" #include "ui/accessibility/ax_node_data.h" -#include "ui/base/default_style.h" #include "ui/base/ime/input_method.h" +#include "ui/base/models/combobox_model.h" #include "ui/base/models/combobox_model_observer.h" -#include "ui/base/resource/resource_bundle.h" +#include "ui/base/models/menu_model.h" #include "ui/events/event.h" -#include "ui/gfx/animation/throb_animation.h" #include "ui/gfx/canvas.h" #include "ui/gfx/color_palette.h" #include "ui/gfx/scoped_canvas.h" #include "ui/gfx/text_utils.h" -#include "ui/native_theme/common_theme.h" #include "ui/native_theme/native_theme.h" -#include "ui/native_theme/native_theme_aura.h" -#include "ui/resources/grit/ui_resources.h" #include "ui/views/animation/flood_fill_ink_drop_ripple.h" -#include "ui/views/animation/ink_drop_highlight.h" #include "ui/views/animation/ink_drop_impl.h" #include "ui/views/background.h" -#include "ui/views/controls/button/button.h" -#include "ui/views/controls/button/label_button.h" #include "ui/views/controls/combobox/combobox_listener.h" #include "ui/views/controls/focus_ring.h" #include "ui/views/controls/focusable_border.h" #include "ui/views/controls/menu/menu_config.h" #include "ui/views/controls/menu/menu_runner.h" #include "ui/views/controls/prefix_selector.h" -#include "ui/views/controls/textfield/textfield.h" #include "ui/views/layout/layout_provider.h" #include "ui/views/mouse_constants.h" -#include "ui/views/painter.h" -#include "ui/views/resources/grit/views_resources.h" #include "ui/views/style/platform_style.h" +#include "ui/views/style/typography.h" #include "ui/views/widget/widget.h" namespace views { namespace { -// STYLE_ACTION arrow container padding widths. -const int kActionLeftPadding = 12; -const int kActionRightPadding = 11; - -// Menu border widths -const int kMenuBorderWidthLeft = 1; -const int kMenuBorderWidthTop = 1; -const int kMenuBorderWidthRight = 1; - -// Limit how small a combobox can be. -const int kMinComboboxWidth = 25; - -// Define the id of the first item in the menu (since it needs to be > 0) -const int kFirstMenuItemId = 1000; - // Used to indicate that no item is currently selected by the user. -const int kNoSelection = -1; - -const int kBodyButtonImages[] = IMAGE_GRID(IDR_COMBOBOX_BUTTON); -const int kHoveredBodyButtonImages[] = IMAGE_GRID(IDR_COMBOBOX_BUTTON_H); -const int kPressedBodyButtonImages[] = IMAGE_GRID(IDR_COMBOBOX_BUTTON_P); -const int kFocusedBodyButtonImages[] = IMAGE_GRID(IDR_COMBOBOX_BUTTON_F); -const int kFocusedHoveredBodyButtonImages[] = - IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_H); -const int kFocusedPressedBodyButtonImages[] = - IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_P); - -#define MENU_IMAGE_GRID(x) { \ - x ## _MENU_TOP, x ## _MENU_CENTER, x ## _MENU_BOTTOM, } - -const int kMenuButtonImages[] = MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON); -const int kHoveredMenuButtonImages[] = MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_H); -const int kPressedMenuButtonImages[] = MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_P); -const int kFocusedMenuButtonImages[] = MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_F); -const int kFocusedHoveredMenuButtonImages[] = - MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_H); -const int kFocusedPressedMenuButtonImages[] = - MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_P); - -#undef MENU_IMAGE_GRID +constexpr int kNoSelection = -1; SkColor GetTextColorForEnableState(const Combobox& combobox, bool enabled) { return style::GetColor( @@ -98,30 +46,10 @@ SkColor GetTextColorForEnableState(const Combobox& combobox, bool enabled) { enabled ? style::STYLE_PRIMARY : style::STYLE_DISABLED); } -gfx::Rect PositionArrowWithinContainer(const gfx::Rect& container_bounds, - const gfx::Size& arrow_size, - Combobox::Style style) { - gfx::Rect bounds(container_bounds); - if (style == Combobox::STYLE_ACTION) { - // This positions the arrow horizontally. The later call to - // ClampToCenteredSize will position it vertically without touching the - // horizontal position. - bounds.Inset(kActionLeftPadding, 0, kActionRightPadding, 0); - DCHECK_EQ(bounds.width(), arrow_size.width()); - } - - bounds.ClampToCenteredSize(arrow_size); - return bounds; -} - // The transparent button which holds a button state but is not rendered. class TransparentButton : public Button { public: - TransparentButton(ButtonListener* listener, bool animate_state_change) - : Button(listener) { - set_animate_on_state_change(animate_state_change); - if (animate_state_change) - SetAnimationDuration(LabelButton::kHoverAnimationDurationMs); + explicit TransparentButton(ButtonListener* listener) : Button(listener) { SetFocusBehavior(FocusBehavior::NEVER); set_notify_action(PlatformStyle::kMenuNotifyActivationAction); @@ -180,103 +108,6 @@ int GetAdjacentIndex(ui::ComboboxModel* model, int increment, int index) { } #endif -// Returns the image resource ids of an array for the body button. -// -// TODO(hajimehoshi): This function should return the images for the 'disabled' -// status. (crbug/270052) -const int* GetBodyButtonImageIds(bool focused, - Button::ButtonState state, - size_t* num) { - DCHECK(num); - *num = 9; - switch (state) { - case Button::STATE_DISABLED: - return focused ? kFocusedBodyButtonImages : kBodyButtonImages; - case Button::STATE_NORMAL: - return focused ? kFocusedBodyButtonImages : kBodyButtonImages; - case Button::STATE_HOVERED: - return focused ? - kFocusedHoveredBodyButtonImages : kHoveredBodyButtonImages; - case Button::STATE_PRESSED: - return focused ? - kFocusedPressedBodyButtonImages : kPressedBodyButtonImages; - default: - NOTREACHED(); - } - return NULL; -} - -// Returns the image resource ids of an array for the menu button. -const int* GetMenuButtonImageIds(bool focused, - Button::ButtonState state, - size_t* num) { - DCHECK(num); - *num = 3; - switch (state) { - case Button::STATE_DISABLED: - return focused ? kFocusedMenuButtonImages : kMenuButtonImages; - case Button::STATE_NORMAL: - return focused ? kFocusedMenuButtonImages : kMenuButtonImages; - case Button::STATE_HOVERED: - return focused ? - kFocusedHoveredMenuButtonImages : kHoveredMenuButtonImages; - case Button::STATE_PRESSED: - return focused ? - kFocusedPressedMenuButtonImages : kPressedMenuButtonImages; - default: - NOTREACHED(); - } - return NULL; -} - -// Returns the images for the menu buttons. -std::vector<const gfx::ImageSkia*> GetMenuButtonImages( - bool focused, - Button::ButtonState state) { - const int* ids; - size_t num_ids; - ids = GetMenuButtonImageIds(focused, state, &num_ids); - std::vector<const gfx::ImageSkia*> images; - images.reserve(num_ids); - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - for (size_t i = 0; i < num_ids; i++) - images.push_back(rb.GetImageSkiaNamed(ids[i])); - return images; -} - -// Paints three images in a column at the given location. The center image is -// stretched so as to fit the given height. -void PaintImagesVertically(gfx::Canvas* canvas, - const gfx::ImageSkia& top_image, - const gfx::ImageSkia& center_image, - const gfx::ImageSkia& bottom_image, - int x, int y, int width, int height) { - canvas->DrawImageInt(top_image, - 0, 0, top_image.width(), top_image.height(), - x, y, width, top_image.height(), false); - y += top_image.height(); - int center_height = height - top_image.height() - bottom_image.height(); - canvas->DrawImageInt(center_image, - 0, 0, center_image.width(), center_image.height(), - x, y, width, center_height, false); - y += center_height; - canvas->DrawImageInt(bottom_image, - 0, 0, bottom_image.width(), bottom_image.height(), - x, y, width, bottom_image.height(), false); -} - -// Paints the arrow button. -void PaintArrowButton( - gfx::Canvas* canvas, - const std::vector<const gfx::ImageSkia*>& arrow_button_images, - int x, int height) { - PaintImagesVertically(canvas, - *arrow_button_images[0], - *arrow_button_images[1], - *arrow_button_images[2], - x, 0, arrow_button_images[0]->width(), height); -} - } // namespace // static @@ -295,8 +126,7 @@ class Combobox::ComboboxMenuModel : public ui::MenuModel, private: bool UseCheckmarks() const { - return owner_->style_ != STYLE_ACTION && - MenuConfig::instance().check_selected_combobox_item; + return MenuConfig::instance().check_selected_combobox_item; } // Overridden from MenuModel: @@ -305,12 +135,8 @@ class Combobox::ComboboxMenuModel : public ui::MenuModel, int GetItemCount() const override { return model_->GetItemCount(); } ItemType GetTypeAt(int index) const override { - if (model_->IsItemSeparatorAt(index)) { - // In action menus, disallow <item>, <separator>, ... since that would put - // a separator at the top of the menu. - DCHECK(index != 1 || owner_->style_ != STYLE_ACTION); + if (model_->IsItemSeparatorAt(index)) return TYPE_SEPARATOR; - } return UseCheckmarks() ? TYPE_CHECK : TYPE_COMMAND; } @@ -319,6 +145,8 @@ class Combobox::ComboboxMenuModel : public ui::MenuModel, } int GetCommandIdAt(int index) const override { + // Define the id of the first item in the menu (since it needs to be > 0) + constexpr int kFirstMenuItemId = 1000; return index + kFirstMenuItemId; } @@ -357,13 +185,6 @@ class Combobox::ComboboxMenuModel : public ui::MenuModel, return model_->IsItemEnabledAt(index); } - bool IsVisibleAt(int index) const override { - // When STYLE_ACTION is used, the first item is not added to the menu. It is - // assumed that the first item is always selected and rendered on the top of - // the action button. - return index > 0 || owner_->style_ != STYLE_ACTION; - } - void HighlightChangedTo(int index) override {} void ActivatedAt(int index) override { @@ -396,22 +217,19 @@ class Combobox::ComboboxMenuModel : public ui::MenuModel, //////////////////////////////////////////////////////////////////////////////// // Combobox, public: -Combobox::Combobox(std::unique_ptr<ui::ComboboxModel> model, Style style) - : Combobox(model.get(), style) { +Combobox::Combobox(std::unique_ptr<ui::ComboboxModel> model) + : Combobox(model.get()) { owned_model_ = std::move(model); } -Combobox::Combobox(ui::ComboboxModel* model, Style style) +Combobox::Combobox(ui::ComboboxModel* model) : model_(model), - style_(style), listener_(nullptr), - selected_index_(style == STYLE_ACTION ? 0 : model_->GetDefaultIndex()), + selected_index_(model_->GetDefaultIndex()), invalid_(false), menu_model_(new ComboboxMenuModel(this, model)), - text_button_(new TransparentButton(this, style_ == STYLE_ACTION)), - arrow_button_(new TransparentButton(this, style_ == STYLE_ACTION)), - size_to_largest_label_(style_ == STYLE_NORMAL), - weak_ptr_factory_(this) { + arrow_button_(new TransparentButton(this)), + size_to_largest_label_(true) { ModelChanged(); #if defined(OS_MACOSX) SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); @@ -421,29 +239,7 @@ Combobox::Combobox(ui::ComboboxModel* model, Style style) UpdateBorder(); - // Initialize the button images. - Button::ButtonState button_states[] = { - Button::STATE_DISABLED, - Button::STATE_NORMAL, - Button::STATE_HOVERED, - Button::STATE_PRESSED, - }; - for (int i = 0; i < 2; i++) { - for (size_t state_index = 0; state_index < arraysize(button_states); - state_index++) { - Button::ButtonState state = button_states[state_index]; - size_t num; - bool focused = !!i; - const int* ids = GetBodyButtonImageIds(focused, state, &num); - body_button_painters_[focused][state] = - Painter::CreateImageGridPainter(ids); - menu_button_images_[focused][state] = GetMenuButtonImages(focused, state); - } - } - - text_button_->SetVisible(true); arrow_button_->SetVisible(true); - AddChildView(text_button_); AddChildView(arrow_button_); // A layer is applied to make sure that canvas bounds are snapped to pixel @@ -463,8 +259,7 @@ Combobox::~Combobox() { // static const gfx::FontList& Combobox::GetFontList() { - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - return rb.GetFontListWithDelta(ui::kLabelFontSizeDelta); + return style::GetFont(style::CONTEXT_BUTTON, style::STYLE_PRIMARY); } void Combobox::ModelChanged() { @@ -482,9 +277,6 @@ void Combobox::ModelChanged() { } void Combobox::SetSelectedIndex(int index) { - if (style_ == STYLE_ACTION) - return; - selected_index_ = index; if (size_to_largest_label_) { SchedulePaint(); @@ -495,9 +287,6 @@ void Combobox::SetSelectedIndex(int index) { } bool Combobox::SelectValue(const base::string16& value) { - if (style_ == STYLE_ACTION) - return false; - for (int i = 0; i < model()->GetItemCount(); ++i) { if (value == model()->GetItemAt(i)) { SetSelectedIndex(i); @@ -532,25 +321,7 @@ void Combobox::SetInvalid(bool invalid) { void Combobox::Layout() { View::Layout(); - - int text_button_width = 0; - int arrow_button_width = 0; - - switch (style_) { - case STYLE_NORMAL: { - arrow_button_width = width(); - break; - } - case STYLE_ACTION: { - arrow_button_width = GetArrowContainerWidth(); - text_button_width = width() - arrow_button_width; - break; - } - } - - int arrow_button_x = std::max(0, text_button_width); - text_button_->SetBounds(0, 0, std::max(0, text_button_width), height()); - arrow_button_->SetBounds(arrow_button_x, 0, arrow_button_width, height()); + arrow_button_->SetBounds(0, 0, width(), height()); } void Combobox::OnNativeThemeChanged(const ui::NativeTheme* theme) { @@ -585,6 +356,9 @@ base::string16 Combobox::GetTextForRow(int row) { // Combobox, View overrides: gfx::Size Combobox::CalculatePreferredSize() const { + // Limit how small a combobox can be. + constexpr int kMinComboboxWidth = 25; + // The preferred size will drive the local bounds which in turn is used to set // the minimum width for the dropdown list. gfx::Insets insets = GetInsets(); @@ -664,21 +438,9 @@ bool Combobox::OnKeyPressed(const ui::KeyEvent& e) { new_index = GetAdjacentIndex(model(), -1, selected_index_); break; - case ui::VKEY_SPACE: - if (style_ == STYLE_ACTION) { - // When pressing space, the click event will be raised after the key is - // released. - text_button_->SetState(Button::STATE_PRESSED); - } else { - show_menu = true; - } - break; - case ui::VKEY_RETURN: - if (style_ == STYLE_ACTION) - OnPerformAction(); - else - show_menu = true; + case ui::VKEY_SPACE: + show_menu = true; break; #endif // OS_MACOSX default: @@ -687,8 +449,7 @@ bool Combobox::OnKeyPressed(const ui::KeyEvent& e) { if (show_menu) { ShowDropDownMenu(ui::MENU_SOURCE_KEYBOARD); - } else if (new_index != selected_index_ && new_index != kNoSelection && - style_ != STYLE_ACTION) { + } else if (new_index != selected_index_ && new_index != kNoSelection) { DCHECK(!model()->IsItemSeparatorAt(new_index)); selected_index_ = new_index; OnPerformAction(); @@ -697,31 +458,10 @@ bool Combobox::OnKeyPressed(const ui::KeyEvent& e) { return true; } -bool Combobox::OnKeyReleased(const ui::KeyEvent& e) { - if (style_ != STYLE_ACTION) - return false; // crbug.com/127520 - - if (e.key_code() == ui::VKEY_SPACE && style_ == STYLE_ACTION && - text_button_->state() == Button::STATE_PRESSED) - OnPerformAction(); - - return false; -} - void Combobox::OnPaint(gfx::Canvas* canvas) { - switch (style_) { - case STYLE_NORMAL: { - OnPaintBackground(canvas); - PaintText(canvas); - OnPaintBorder(canvas); - break; - } - case STYLE_ACTION: { - PaintButtons(canvas); - PaintText(canvas); - break; - } - } + OnPaintBackground(canvas); + PaintText(canvas); + OnPaintBorder(canvas); } void Combobox::OnFocus() { @@ -779,29 +519,22 @@ void Combobox::ButtonPressed(Button* sender, const ui::Event& event) { if (!enabled()) return; - if (sender == text_button_) { - OnPerformAction(); - } else { - DCHECK_EQ(arrow_button_, sender); - // TODO(hajimehoshi): Fix the problem that the arrow button blinks when - // cliking this while the dropdown menu is opened. - const base::TimeDelta delta = base::Time::Now() - closed_time_; - if (delta.InMilliseconds() <= kMinimumMsBetweenButtonClicks) - return; + // TODO(hajimehoshi): Fix the problem that the arrow button blinks when + // cliking this while the dropdown menu is opened. + const base::TimeDelta delta = base::Time::Now() - closed_time_; + if (delta.InMilliseconds() <= kMinimumMsBetweenButtonClicks) + return; - ui::MenuSourceType source_type = ui::MENU_SOURCE_MOUSE; - if (event.IsKeyEvent()) - source_type = ui::MENU_SOURCE_KEYBOARD; - else if (event.IsGestureEvent() || event.IsTouchEvent()) - source_type = ui::MENU_SOURCE_TOUCH; - ShowDropDownMenu(source_type); - } + ui::MenuSourceType source_type = ui::MENU_SOURCE_MOUSE; + if (event.IsKeyEvent()) + source_type = ui::MENU_SOURCE_KEYBOARD; + else if (event.IsGestureEvent() || event.IsTouchEvent()) + source_type = ui::MENU_SOURCE_TOUCH; + ShowDropDownMenu(source_type); } void Combobox::UpdateBorder() { std::unique_ptr<FocusableBorder> border(new FocusableBorder()); - if (style_ == STYLE_ACTION) - border->SetInsets(5, 10, 5, 10); if (invalid_) border->SetColorId(ui::NativeTheme::kColorId_AlertSeverityHigh); SetBorder(std::move(border)); @@ -842,8 +575,7 @@ void Combobox::PaintText(gfx::Canvas* canvas) { gfx::Rect arrow_bounds(disclosure_arrow_offset, 0, GetArrowContainerWidth(), height()); - arrow_bounds = - PositionArrowWithinContainer(arrow_bounds, ArrowSize(), style_); + arrow_bounds.ClampToCenteredSize(ArrowSize()); AdjustBoundsForRTLUI(&arrow_bounds); { @@ -874,82 +606,28 @@ void Combobox::PaintText(gfx::Canvas* canvas) { } } -void Combobox::PaintButtons(gfx::Canvas* canvas) { - DCHECK(style_ == STYLE_ACTION); - - gfx::ScopedRTLFlipCanvas scoped_canvas(canvas, width()); - - bool focused = HasFocus(); - const std::vector<const gfx::ImageSkia*>& arrow_button_images = - menu_button_images_[focused][ - arrow_button_->state() == Button::STATE_HOVERED ? - Button::STATE_NORMAL : arrow_button_->state()]; - - int text_button_hover_alpha = - text_button_->state() == Button::STATE_PRESSED ? 0 : - static_cast<int>(static_cast<TransparentButton*>(text_button_)-> - GetAnimationValue() * 255); - if (text_button_hover_alpha < 255) { - canvas->SaveLayerAlpha(255 - text_button_hover_alpha); - Painter* text_button_painter = - body_button_painters_[focused][ - text_button_->state() == Button::STATE_HOVERED ? - Button::STATE_NORMAL : text_button_->state()].get(); - Painter::PaintPainterAt(canvas, text_button_painter, - gfx::Rect(0, 0, text_button_->width(), height())); - canvas->Restore(); - } - if (0 < text_button_hover_alpha) { - canvas->SaveLayerAlpha(text_button_hover_alpha); - Painter* text_button_hovered_painter = - body_button_painters_[focused][Button::STATE_HOVERED].get(); - Painter::PaintPainterAt(canvas, text_button_hovered_painter, - gfx::Rect(0, 0, text_button_->width(), height())); - canvas->Restore(); - } - - int arrow_button_hover_alpha = - arrow_button_->state() == Button::STATE_PRESSED ? 0 : - static_cast<int>(static_cast<TransparentButton*>(arrow_button_)-> - GetAnimationValue() * 255); - if (arrow_button_hover_alpha < 255) { - canvas->SaveLayerAlpha(255 - arrow_button_hover_alpha); - PaintArrowButton(canvas, arrow_button_images, arrow_button_->x(), height()); - canvas->Restore(); - } - if (0 < arrow_button_hover_alpha) { - canvas->SaveLayerAlpha(arrow_button_hover_alpha); - const std::vector<const gfx::ImageSkia*>& arrow_button_hovered_images = - menu_button_images_[focused][Button::STATE_HOVERED]; - PaintArrowButton(canvas, arrow_button_hovered_images, - arrow_button_->x(), height()); - canvas->Restore(); - } -} - void Combobox::ShowDropDownMenu(ui::MenuSourceType source_type) { + // Menu border widths. + constexpr int kMenuBorderWidthLeft = 1; + constexpr int kMenuBorderWidthTop = 1; + constexpr int kMenuBorderWidthRight = 1; + gfx::Rect lb = GetLocalBounds(); gfx::Point menu_position(lb.origin()); - if (style_ == STYLE_NORMAL) { - // Inset the menu's requested position so the border of the menu lines up - // with the border of the combobox. - menu_position.set_x(menu_position.x() + kMenuBorderWidthLeft); - menu_position.set_y(menu_position.y() + kMenuBorderWidthTop); - } + // Inset the menu's requested position so the border of the menu lines up + // with the border of the combobox. + menu_position.set_x(menu_position.x() + kMenuBorderWidthLeft); + menu_position.set_y(menu_position.y() + kMenuBorderWidthTop); + lb.set_width(lb.width() - (kMenuBorderWidthLeft + kMenuBorderWidthRight)); View::ConvertPointToScreen(this, &menu_position); gfx::Rect bounds(menu_position, lb.size()); - Button::ButtonState original_state = Button::STATE_NORMAL; - if (arrow_button_) { - original_state = arrow_button_->state(); - arrow_button_->SetState(Button::STATE_PRESSED); - } - MenuAnchorPosition anchor_position = - style_ == STYLE_ACTION ? MENU_ANCHOR_TOPRIGHT : MENU_ANCHOR_TOPLEFT; + Button::ButtonState original_state = arrow_button_->state(); + arrow_button_->SetState(Button::STATE_PRESSED); // Allow |menu_runner_| to be set by the testing API, but if this method is // ever invoked recursively, ensure the old menu is closed. @@ -959,14 +637,13 @@ void Combobox::ShowDropDownMenu(ui::MenuSourceType source_type) { base::Bind(&Combobox::OnMenuClosed, base::Unretained(this), original_state))); } - menu_runner_->RunMenuAt(GetWidget(), nullptr, bounds, anchor_position, + menu_runner_->RunMenuAt(GetWidget(), nullptr, bounds, MENU_ANCHOR_TOPLEFT, source_type); } void Combobox::OnMenuClosed(Button::ButtonState original_button_state) { menu_runner_.reset(); - if (arrow_button_) - arrow_button_->SetState(original_button_state); + arrow_button_->SetState(original_button_state); closed_time_ = base::Time::Now(); } @@ -974,13 +651,10 @@ void Combobox::OnPerformAction() { NotifyAccessibilityEvent(ax::mojom::Event::kValueChanged, true); SchedulePaint(); - // This combobox may be deleted by the listener. - base::WeakPtr<Combobox> weak_ptr = weak_ptr_factory_.GetWeakPtr(); if (listener_) listener_->OnPerformAction(this); - if (weak_ptr && style_ == STYLE_ACTION) - selected_index_ = 0; + // Note |this| may be deleted by |listener_|. } gfx::Size Combobox::ArrowSize() const { @@ -1011,10 +685,7 @@ PrefixSelector* Combobox::GetPrefixSelector() { int Combobox::GetArrowContainerWidth() const { constexpr int kPaddingWidth = 8; - int padding = style_ == STYLE_NORMAL - ? kPaddingWidth * 2 - : kActionLeftPadding + kActionRightPadding; - return ArrowSize().width() + padding; + return ArrowSize().width() + kPaddingWidth * 2; } } // namespace views |