Commit df0f5fb4 authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[UI] Editable combobox observes animation to block dropdown menu

screencast:
https://screencast.googleplex.com/cast/NTE3OTA5NzIxMjc4MDU0NHw3YjdhZDQ1OC05MQ

Bug: 1044038
Change-Id: If729650f517848014cb7bd406af2a77c67edba70
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2210980
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772323}
parent eb8cf737
......@@ -413,6 +413,14 @@ PasswordSaveUpdateWithAccountStoreView::PasswordSaveUpdateWithAccountStoreView(
std::move(password_dropdown),
std::move(password_view_button));
// The |username_dropdown_| should observe the animating layout manager to
// close the dropdown menu when the animation starts.
observed_animating_layout_ = std::make_unique<
ScopedObserver<views::AnimatingLayoutManager,
views::AnimatingLayoutManager::Observer>>(
username_dropdown_);
observed_animating_layout_->Add(animating_layout);
// The account picker is only visible in Save bubbble, not Update bubble.
if (destination_dropdown_)
destination_dropdown_->SetVisible(!controller_.IsCurrentStateUpdate());
......
......@@ -14,6 +14,7 @@
#include "ui/views/view.h"
namespace views {
class AnimatingLayoutManager;
class Combobox;
class EditableCombobox;
class ToggleImageButton;
......@@ -88,6 +89,13 @@ class PasswordSaveUpdateWithAccountStoreView
// The view for the password value.
views::EditableCombobox* password_dropdown_;
bool are_passwords_revealed_;
// Used to add |username_dropdown_| as an observer to the
// AnimatingLayoutManager. This is needed such that the |username_dropdown_|
// keeps the dropdown menu closed while the layout is animating.
std::unique_ptr<ScopedObserver<views::AnimatingLayoutManager,
views::AnimatingLayoutManager::Observer>>
observed_animating_layout_;
};
#endif // CHROME_BROWSER_UI_VIEWS_PASSWORDS_PASSWORD_SAVE_UPDATE_WITH_ACCOUNT_STORE_VIEW_H_
......@@ -176,15 +176,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 +304,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,
......@@ -399,9 +392,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_) {
......@@ -435,9 +425,6 @@ void EditableCombobox::OnVisibleBoundsChanged() {
CloseMenu();
}
////////////////////////////////////////////////////////////////////////////////
// EditableCombobox, TextfieldController overrides:
void EditableCombobox::ContentsChanged(Textfield* sender,
const base::string16& new_contents) {
HandleNewContent(new_contents);
......@@ -455,16 +442,10 @@ 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()) {
......@@ -479,8 +460,13 @@ void EditableCombobox::ButtonPressed(Button* sender, const ui::Event& event) {
ShowDropDownMenu(source_type);
}
////////////////////////////////////////////////////////////////////////////////
// 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();
......@@ -521,6 +507,9 @@ void EditableCombobox::ShowDropDownMenu(ui::MenuSourceType source_type) {
constexpr int kMenuBorderWidthTop = 1;
constexpr int kMenuBorderWidthRight = 1;
if (dropdown_blocked_for_animation_)
return;
if (!menu_model_->GetItemCount()) {
CloseMenu();
return;
......
......@@ -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);
......@@ -139,6 +142,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 +178,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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment