Commit d0616ceb authored by Tommy C. Li's avatar Tommy C. Li Committed by Commit Bot

Reland "Match security chip visibility with focus ring"

This is a reland of 26399bca

It simplifies the layer creation-and-destruction lifecycle, because
that aspect seemed the most suspicious for causing crashes.

Original change's description:
> Match security chip visibility with focus ring
>
> Instantly hides or shows the IconLabelBubbleView separator when focus
> rings are available to prevent showing the separator when a focus ring
> overlaps it.
>
> Bug: chromium:865029
> Change-Id: I21a4c296c1da06b81dc91d66101d46e8ad52ad99
> Reviewed-on: https://chromium-review.googlesource.com/1142442
> Commit-Queue: Peter Boström <pbos@chromium.org>
> Reviewed-by: Bret Sepulveda <bsep@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#576358}

Bug: chromium:865029
Change-Id: I7b5b597a6e6ec114faf4888b62da1f8751e64646
Reviewed-on: https://chromium-review.googlesource.com/1147361Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Commit-Queue: Tommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577587}
parent 2232eb7e
...@@ -50,6 +50,9 @@ constexpr int kIconLabelBubbleFadeOutDurationMs = 175; ...@@ -50,6 +50,9 @@ constexpr int kIconLabelBubbleFadeOutDurationMs = 175;
IconLabelBubbleView::SeparatorView::SeparatorView(IconLabelBubbleView* owner) { IconLabelBubbleView::SeparatorView::SeparatorView(IconLabelBubbleView* owner) {
DCHECK(owner); DCHECK(owner);
owner_ = owner; owner_ = owner;
SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false);
} }
void IconLabelBubbleView::SeparatorView::OnPaint(gfx::Canvas* canvas) { void IconLabelBubbleView::SeparatorView::OnPaint(gfx::Canvas* canvas) {
...@@ -63,15 +66,18 @@ void IconLabelBubbleView::SeparatorView::OnPaint(gfx::Canvas* canvas) { ...@@ -63,15 +66,18 @@ void IconLabelBubbleView::SeparatorView::OnPaint(gfx::Canvas* canvas) {
gfx::PointF(x, GetLocalBounds().bottom()), separator_color); gfx::PointF(x, GetLocalBounds().bottom()), separator_color);
} }
void IconLabelBubbleView::SeparatorView::OnImplicitAnimationsCompleted() {
if (layer() && layer()->opacity() == 1.0f)
DestroyLayer();
}
void IconLabelBubbleView::SeparatorView::UpdateOpacity() { void IconLabelBubbleView::SeparatorView::UpdateOpacity() {
if (!visible()) if (!visible())
return; return;
// When using focus rings are visible we should hide the separator instantly
// when the IconLabelBubbleView is focused. Otherwise we should follow the
// inkdrop.
if (views::PlatformStyle::kPreferFocusRings && owner_->HasFocus()) {
layer()->SetOpacity(0.0f);
return;
}
views::InkDrop* ink_drop = owner_->GetInkDrop(); views::InkDrop* ink_drop = owner_->GetInkDrop();
DCHECK(ink_drop); DCHECK(ink_drop);
...@@ -88,10 +94,6 @@ void IconLabelBubbleView::SeparatorView::UpdateOpacity() { ...@@ -88,10 +94,6 @@ void IconLabelBubbleView::SeparatorView::UpdateOpacity() {
duration = kIconLabelBubbleFadeInDurationMs; duration = kIconLabelBubbleFadeInDurationMs;
} }
if (!layer())
SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false);
if (disable_animation_for_test_) { if (disable_animation_for_test_) {
layer()->SetOpacity(opacity); layer()->SetOpacity(opacity);
} else { } else {
...@@ -99,7 +101,6 @@ void IconLabelBubbleView::SeparatorView::UpdateOpacity() { ...@@ -99,7 +101,6 @@ void IconLabelBubbleView::SeparatorView::UpdateOpacity() {
animation.SetTransitionDuration( animation.SetTransitionDuration(
base::TimeDelta::FromMilliseconds(duration)); base::TimeDelta::FromMilliseconds(duration));
animation.SetTweenType(gfx::Tween::Type::EASE_IN); animation.SetTweenType(gfx::Tween::Type::EASE_IN);
animation.AddObserver(this);
layer()->SetOpacity(opacity); layer()->SetOpacity(opacity);
} }
} }
...@@ -377,6 +378,16 @@ void IconLabelBubbleView::NotifyClick(const ui::Event& event) { ...@@ -377,6 +378,16 @@ void IconLabelBubbleView::NotifyClick(const ui::Event& event) {
OnActivate(event); OnActivate(event);
} }
void IconLabelBubbleView::OnFocus() {
separator_view_->UpdateOpacity();
Button::OnFocus();
}
void IconLabelBubbleView::OnBlur() {
separator_view_->UpdateOpacity();
Button::OnBlur();
}
void IconLabelBubbleView::OnWidgetDestroying(views::Widget* widget) { void IconLabelBubbleView::OnWidgetDestroying(views::Widget* widget) {
widget->RemoveObserver(this); widget->RemoveObserver(this);
} }
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "ui/compositor/layer_animation_observer.h"
#include "ui/gfx/geometry/insets.h" #include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/views/animation/ink_drop_host_view.h" #include "ui/views/animation/ink_drop_host_view.h"
...@@ -38,17 +37,13 @@ class IconLabelBubbleView : public views::InkDropObserver, ...@@ -38,17 +37,13 @@ class IconLabelBubbleView : public views::InkDropObserver,
static constexpr int kTrailingPaddingPreMd = 2; static constexpr int kTrailingPaddingPreMd = 2;
// A view that draws the separator. // A view that draws the separator.
class SeparatorView : public views::View, class SeparatorView : public views::View {
public ui::ImplicitAnimationObserver {
public: public:
explicit SeparatorView(IconLabelBubbleView* owner); explicit SeparatorView(IconLabelBubbleView* owner);
// views::View: // views::View:
void OnPaint(gfx::Canvas* canvas) override; void OnPaint(gfx::Canvas* canvas) override;
// ui::ImplicitAnimationObserver:
void OnImplicitAnimationsCompleted() override;
// Updates the opacity based on the ink drop's state. // Updates the opacity based on the ink drop's state.
void UpdateOpacity(); void UpdateOpacity();
...@@ -154,6 +149,8 @@ class IconLabelBubbleView : public views::InkDropObserver, ...@@ -154,6 +149,8 @@ class IconLabelBubbleView : public views::InkDropObserver,
bool IsTriggerableEvent(const ui::Event& event) override; bool IsTriggerableEvent(const ui::Event& event) override;
bool ShouldUpdateInkDropOnClickCanceled() const override; bool ShouldUpdateInkDropOnClickCanceled() const override;
void NotifyClick(const ui::Event& event) override; void NotifyClick(const ui::Event& event) override;
void OnFocus() override;
void OnBlur() override;
// views::WidgetObserver: // views::WidgetObserver:
void OnWidgetDestroying(views::Widget* widget) override; void OnWidgetDestroying(views::Widget* widget) override;
......
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