Commit 3dc4c27e authored by Jay Harris's avatar Jay Harris Committed by Commit Bot

Fixes a bug in the LocationIconView InkDrop

This stops the LocationIconView InkDrop from getting reset if
LocationIconView::Update is called while the InkDrop is animating.

Note: This issue doesn't seem to affect the LocationBarView, only the
CustomTabBar being introduced in CL: 1328084

Bug: 853593
Change-Id: I3ab4045c7a8d0db88a069f1d35d9763c9c8594f1
Reviewed-on: https://chromium-review.googlesource.com/c/1338579Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Commit-Queue: Jay Harris <harrisjay@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611893}
parent ae938e03
...@@ -123,6 +123,10 @@ bool LocationIconView::ShouldShowText() const { ...@@ -123,6 +123,10 @@ bool LocationIconView::ShouldShowText() const {
return !location_bar_model->GetSecureDisplayText().empty(); return !location_bar_model->GetSecureDisplayText().empty();
} }
const views::InkDrop* LocationIconView::get_ink_drop_for_testing() {
return GetInkDrop();
}
base::string16 LocationIconView::GetText() const { base::string16 LocationIconView::GetText() const {
if (delegate_->GetLocationBarModel()->GetURL().SchemeIs( if (delegate_->GetLocationBarModel()->GetURL().SchemeIs(
content::kChromeUIScheme)) content::kChromeUIScheme))
...@@ -201,26 +205,31 @@ void LocationIconView::Update(bool suppress_animations) { ...@@ -201,26 +205,31 @@ void LocationIconView::Update(bool suppress_animations) {
? base::string16() ? base::string16()
: l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON)); : l10n_util::GetStringUTF16(IDS_TOOLTIP_LOCATION_ICON));
// If the omnibox is empty or editing, the user should not be able to left // We should only enable/disable the InkDrop if the editing state has changed,
// click on the icon. As such, the icon should not show a highlight or be // as the drop gets recreated when SetInkDropMode is called. This can result
// focusable. Note: using the middle mouse to copy-and-paste should still // in strange behaviour, like the the InkDrop disappearing mid animation.
// work on the icon. if (is_editing_or_empty != was_editing_or_empty_) {
if (is_editing_or_empty) { // If the omnibox is empty or editing, the user should not be able to left
SetInkDropMode(InkDropMode::OFF); // click on the icon. As such, the icon should not show a highlight or be
SetFocusBehavior(FocusBehavior::NEVER); // focusable. Note: using the middle mouse to copy-and-paste should still
return; // work on the icon.
} if (is_editing_or_empty) {
SetInkDropMode(InkDropMode::OFF);
SetInkDropMode(InkDropMode::ON); SetFocusBehavior(FocusBehavior::NEVER);
} else {
SetInkDropMode(InkDropMode::ON);
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
#else #else
SetFocusBehavior(FocusBehavior::ALWAYS); SetFocusBehavior(FocusBehavior::ALWAYS);
#endif #endif
}
}
last_update_security_level_ = last_update_security_level_ =
delegate_->GetLocationBarModel()->GetSecurityLevel(false); delegate_->GetLocationBarModel()->GetSecurityLevel(false);
was_editing_or_empty_ = is_editing_or_empty;
} }
bool LocationIconView::IsTriggerableEvent(const ui::Event& event) { bool LocationIconView::IsTriggerableEvent(const ui::Event& event) {
......
...@@ -100,6 +100,8 @@ class LocationIconView : public IconLabelBubbleView { ...@@ -100,6 +100,8 @@ class LocationIconView : public IconLabelBubbleView {
// - the current page URL is a chrome-extension:// URL. // - the current page URL is a chrome-extension:// URL.
bool ShouldShowText() const; bool ShouldShowText() const;
const views::InkDrop* get_ink_drop_for_testing();
protected: protected:
// IconLabelBubbleView: // IconLabelBubbleView:
bool IsTriggerableEvent(const ui::Event& event) override; bool IsTriggerableEvent(const ui::Event& event) override;
...@@ -111,6 +113,10 @@ class LocationIconView : public IconLabelBubbleView { ...@@ -111,6 +113,10 @@ class LocationIconView : public IconLabelBubbleView {
security_state::SecurityLevel last_update_security_level_ = security_state::SecurityLevel last_update_security_level_ =
security_state::NONE; security_state::NONE;
// Whether the delegate's editing or empty flag was set the last time the
// location icon was updated.
bool was_editing_or_empty_ = false;
// Returns what the minimum size would be if the preferred size were |size|. // Returns what the minimum size would be if the preferred size were |size|.
gfx::Size GetMinimumSizeForPreferredSize(gfx::Size size) const; gfx::Size GetMinimumSizeForPreferredSize(gfx::Size size) const;
......
...@@ -18,7 +18,10 @@ class TestLocationIconDelegate : public LocationIconView::Delegate { ...@@ -18,7 +18,10 @@ class TestLocationIconDelegate : public LocationIconView::Delegate {
content::WebContents* GetWebContents() override { return nullptr; } content::WebContents* GetWebContents() override { return nullptr; }
bool IsEditingOrEmpty() override { return false; } bool IsEditingOrEmpty() override { return is_editing_or_empty_; }
void set_is_editing_or_empty(bool is_editing_or_empty) {
is_editing_or_empty_ = is_editing_or_empty;
}
SkColor GetSecurityChipColor( SkColor GetSecurityChipColor(
security_state::SecurityLevel security_level) const override { security_state::SecurityLevel security_level) const override {
...@@ -43,6 +46,7 @@ class TestLocationIconDelegate : public LocationIconView::Delegate { ...@@ -43,6 +46,7 @@ class TestLocationIconDelegate : public LocationIconView::Delegate {
private: private:
LocationBarModel* location_bar_model_; LocationBarModel* location_bar_model_;
bool is_editing_or_empty_ = false;
}; };
} // namespace } // namespace
...@@ -149,3 +153,39 @@ TEST_F(LocationIconViewTest, ShouldNotAnimateWarningToDangerous) { ...@@ -149,3 +153,39 @@ TEST_F(LocationIconViewTest, ShouldNotAnimateWarningToDangerous) {
view()->Update(/*suppress_animations=*/false); view()->Update(/*suppress_animations=*/false);
EXPECT_FALSE(view()->is_animating_label()); EXPECT_FALSE(view()->is_animating_label());
} }
// Whenever InkDropMode is set a new InkDrop is created, which will reset any
// animations on the drop, so we should only set the InkDropMode when it has
// actually changed.
TEST_F(LocationIconViewTest, ShouldNotRecreateInkDropNeedlessly) {
delegate()->set_is_editing_or_empty(false);
view()->Update(false);
const views::InkDrop* drop = view()->get_ink_drop_for_testing();
view()->Update(/*suppress_animations=*/false);
// The InkDropMode has not changed (is ON), so our InkDrop should remain the
// same.
EXPECT_EQ(drop, view()->get_ink_drop_for_testing());
delegate()->set_is_editing_or_empty(true);
view()->Update(/*suppress_animations=*/false);
// The InkDropMode has changed (ON --> OFF), so a new InkDrop will have been
// created.
EXPECT_NE(drop, view()->get_ink_drop_for_testing());
drop = view()->get_ink_drop_for_testing();
view()->Update(/*suppress_animations=*/false);
// The InkDropMode has not changed (is OFF), so the InkDrop should remain the
// same.
EXPECT_EQ(drop, view()->get_ink_drop_for_testing());
delegate()->set_is_editing_or_empty(false);
view()->Update(/*suppress_animations=*/false);
// The InkDrop mode has changed (OFF --> ON), so a new InkDrop will have been
// created.
EXPECT_NE(drop, view()->get_ink_drop_for_testing());
}
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