summaryrefslogtreecommitdiff
path: root/chromium/ui/views/controls/editable_combobox
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/ui/views/controls/editable_combobox')
-rw-r--r--chromium/ui/views/controls/editable_combobox/editable_combobox.cc78
-rw-r--r--chromium/ui/views/controls/editable_combobox/editable_combobox.h18
2 files changed, 39 insertions, 57 deletions
diff --git a/chromium/ui/views/controls/editable_combobox/editable_combobox.cc b/chromium/ui/views/controls/editable_combobox/editable_combobox.cc
index 5f76ed0db20..b4c14a33505 100644
--- a/chromium/ui/views/controls/editable_combobox/editable_combobox.cc
+++ b/chromium/ui/views/controls/editable_combobox/editable_combobox.cc
@@ -37,7 +37,6 @@
#include "ui/gfx/range/range.h"
#include "ui/gfx/render_text.h"
#include "ui/gfx/scoped_canvas.h"
-#include "ui/native_theme/native_theme.h"
#include "ui/views/animation/flood_fill_ink_drop_ripple.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/animation/ink_drop_host_view.h"
@@ -65,8 +64,7 @@ namespace {
class Arrow : public Button {
public:
- Arrow(const SkColor color, ButtonListener* listener)
- : Button(listener), color_(color) {
+ explicit Arrow(ButtonListener* listener) : Button(listener) {
// Similar to Combobox's TransparentButton.
SetFocusBehavior(FocusBehavior::NEVER);
button_controller()->set_notify_action(
@@ -93,8 +91,7 @@ class Arrow : public Button {
std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override {
return std::make_unique<views::FloodFillInkDropRipple>(
size(), GetInkDropCenterBasedOnLastEvent(),
- GetNativeTheme()->GetSystemColor(
- ui::NativeTheme::kColorId_LabelEnabledColor),
+ style::GetColor(*this, style::CONTEXT_TEXTFIELD, style::STYLE_PRIMARY),
ink_drop_visible_opacity());
}
@@ -104,7 +101,11 @@ class Arrow : public Button {
canvas->ClipRect(GetContentsBounds());
gfx::Rect arrow_bounds = GetLocalBounds();
arrow_bounds.ClampToCenteredSize(ComboboxArrowSize());
- PaintComboboxArrow(color_, arrow_bounds, canvas);
+ // Make sure the arrow use the same color as the text in the combobox.
+ PaintComboboxArrow(style::GetColor(*this, style::CONTEXT_TEXTFIELD,
+ GetEnabled() ? style::STYLE_PRIMARY
+ : style::STYLE_DISABLED),
+ arrow_bounds, canvas);
}
void GetAccessibleNodeData(ui::AXNodeData* node_data) override {
@@ -115,8 +116,6 @@ class Arrow : public Button {
node_data->SetDefaultActionVerb(ax::mojom::DefaultActionVerb::kOpen);
}
- const SkColor color_;
-
DISALLOW_COPY_AND_ASSIGN(Arrow);
};
@@ -176,15 +175,10 @@ class EditableCombobox::EditableComboboxMenuModel
gfx::RenderText::kPasswordReplacementChar);
}
- //////////////////////////////////////////////////////////////////////////////
- // Overridden from ComboboxModelObserver:
void OnComboboxModelChanged(ui::ComboboxModel* model) override {
UpdateItemsShown();
}
- //////////////////////////////////////////////////////////////////////////////
- // Overridden from MenuModel:
-
int GetItemCount() const override { return items_shown_.size(); }
private:
@@ -309,8 +303,6 @@ class EditableCombobox::EditableComboboxPreTargetHandler
DISALLOW_COPY_AND_ASSIGN(EditableComboboxPreTargetHandler);
};
-////////////////////////////////////////////////////////////////////////////////
-// EditableCombobox, public, non-overridden methods:
EditableCombobox::EditableCombobox(
std::unique_ptr<ui::ComboboxModel> combobox_model,
const bool filter_on_edit,
@@ -341,8 +333,7 @@ EditableCombobox::EditableCombobox(
textfield_->SetExtraInsets(gfx::Insets(
/*top=*/0, /*left=*/0, /*bottom=*/0,
/*right=*/kComboboxArrowContainerWidth - kComboboxArrowPaddingWidth));
- arrow_ = new Arrow(textfield_->GetTextColor(), this);
- AddChildView(arrow_);
+ arrow_ = AddChildView(std::make_unique<Arrow>(this));
}
SetLayoutManager(std::make_unique<views::FillLayout>());
}
@@ -399,9 +390,6 @@ base::string16 EditableCombobox::GetItemForTest(int index) {
return menu_model_->GetItemTextAt(index, showing_password_text_);
}
-////////////////////////////////////////////////////////////////////////////////
-// EditableCombobox, View overrides:
-
void EditableCombobox::Layout() {
View::Layout();
if (arrow_) {
@@ -411,11 +399,6 @@ void EditableCombobox::Layout() {
}
}
-void EditableCombobox::OnThemeChanged() {
- View::OnThemeChanged();
- textfield_->OnThemeChanged();
-}
-
void EditableCombobox::GetAccessibleNodeData(ui::AXNodeData* node_data) {
node_data->role = ax::mojom::Role::kComboBoxGrouping;
@@ -435,9 +418,6 @@ void EditableCombobox::OnVisibleBoundsChanged() {
CloseMenu();
}
-////////////////////////////////////////////////////////////////////////////////
-// EditableCombobox, TextfieldController overrides:
-
void EditableCombobox::ContentsChanged(Textfield* sender,
const base::string16& new_contents) {
HandleNewContent(new_contents);
@@ -455,32 +435,25 @@ bool EditableCombobox::HandleKeyEvent(Textfield* sender,
return false;
}
-////////////////////////////////////////////////////////////////////////////////
-// EditableCombobox, View overrides:
-
void EditableCombobox::OnViewBlurred(View* observed_view) {
CloseMenu();
}
-////////////////////////////////////////////////////////////////////////////////
-// EditableCombobox, ButtonListener overrides:
-
void EditableCombobox::ButtonPressed(Button* sender, const ui::Event& event) {
textfield_->RequestFocus();
- if (menu_runner_ && menu_runner_->IsRunning()) {
+ if (menu_runner_ && menu_runner_->IsRunning())
CloseMenu();
- 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);
+ else
+ ShowDropDownMenu(ui::GetMenuSourceTypeForEvent(event));
}
-////////////////////////////////////////////////////////////////////////////////
-// EditableCombobox, Private methods:
+void EditableCombobox::OnLayoutIsAnimatingChanged(
+ views::AnimatingLayoutManager* source,
+ bool is_animating) {
+ dropdown_blocked_for_animation_ = is_animating;
+ if (dropdown_blocked_for_animation_)
+ CloseMenu();
+}
void EditableCombobox::CloseMenu() {
menu_runner_.reset();
@@ -517,9 +490,10 @@ void EditableCombobox::HandleNewContent(const base::string16& new_content) {
}
void EditableCombobox::ShowDropDownMenu(ui::MenuSourceType source_type) {
- constexpr int kMenuBorderWidthLeft = 1;
constexpr int kMenuBorderWidthTop = 1;
- constexpr int kMenuBorderWidthRight = 1;
+
+ if (dropdown_blocked_for_animation_)
+ return;
if (!menu_model_->GetItemCount()) {
CloseMenu();
@@ -540,13 +514,13 @@ void EditableCombobox::ShowDropDownMenu(ui::MenuSourceType source_type) {
this, GetWidget()->GetRootView());
gfx::Rect local_bounds = textfield_->GetLocalBounds();
+
+ // Menu's requested position's width should be the same as local bounds so the
+ // border of the menu lines up with the border of the combobox. The y
+ // coordinate however should be shifted to the bottom with the border width
+ // not to overlap with the combobox border.
gfx::Point menu_position(local_bounds.origin());
- // Inset the menu's requested position so the border of the menu lines up
- // with the border of the textfield.
- menu_position.set_x(menu_position.x() + kMenuBorderWidthLeft);
menu_position.set_y(menu_position.y() + kMenuBorderWidthTop);
- local_bounds.set_width(local_bounds.width() -
- (kMenuBorderWidthLeft + kMenuBorderWidthRight));
View::ConvertPointToScreen(this, &menu_position);
gfx::Rect bounds(menu_position, local_bounds.size());
diff --git a/chromium/ui/views/controls/editable_combobox/editable_combobox.h b/chromium/ui/views/controls/editable_combobox/editable_combobox.h
index c0f6b26fad8..e4a0d3c3698 100644
--- a/chromium/ui/views/controls/editable_combobox/editable_combobox.h
+++ b/chromium/ui/views/controls/editable_combobox/editable_combobox.h
@@ -14,6 +14,7 @@
#include "ui/base/ui_base_types.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/textfield/textfield_controller.h"
+#include "ui/views/layout/animating_layout_manager.h"
#include "ui/views/style/typography.h"
#include "ui/views/view.h"
#include "ui/views/view_observer.h"
@@ -37,10 +38,12 @@ class MenuRunner;
class Textfield;
// Textfield that also shows a drop-down list with suggestions.
-class VIEWS_EXPORT EditableCombobox : public View,
- public TextfieldController,
- public ViewObserver,
- public ButtonListener {
+class VIEWS_EXPORT EditableCombobox
+ : public View,
+ public TextfieldController,
+ public ViewObserver,
+ public ButtonListener,
+ public views::AnimatingLayoutManager::Observer {
public:
METADATA_HEADER(EditableCombobox);
@@ -121,7 +124,6 @@ class VIEWS_EXPORT EditableCombobox : public View,
// Overridden from View:
void Layout() override;
- void OnThemeChanged() override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
void RequestFocus() override;
bool GetNeedsNotificationWhenVisibleBoundsChange() const override;
@@ -139,6 +141,10 @@ class VIEWS_EXPORT EditableCombobox : public View,
// Overridden from ButtonListener:
void ButtonPressed(Button* sender, const ui::Event& event) override;
+ // Overridden from views::AnimatingLayoutManager::Observer:
+ void OnLayoutIsAnimatingChanged(views::AnimatingLayoutManager* source,
+ bool is_animating) override;
+
Textfield* textfield_;
Button* arrow_ = nullptr;
std::unique_ptr<ui::ComboboxModel> combobox_model_;
@@ -171,6 +177,8 @@ class VIEWS_EXPORT EditableCombobox : public View,
// Type::kPassword.
bool showing_password_text_;
+ bool dropdown_blocked_for_animation_ = false;
+
ScopedObserver<View, ViewObserver> observer_{this};
DISALLOW_COPY_AND_ASSIGN(EditableCombobox);