Commit 804c3821 authored by Peter Boström's avatar Peter Boström Committed by Commit Bot

Add HighlightPathGenerator to IconLabelBubbleView

Removes updates to the highlight path done on every Layout() call.

Bug: chromium:1007546
Change-Id: Ia179a182c39ada394e1076eae25f374922a1d2b3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1861125
Auto-Submit: Peter Boström <pbos@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705973}
parent b25e7445
...@@ -31,8 +31,8 @@ ...@@ -31,8 +31,8 @@
#include "ui/views/animation/ink_drop_ripple.h" #include "ui/views/animation/ink_drop_ripple.h"
#include "ui/views/background.h" #include "ui/views/background.h"
#include "ui/views/border.h" #include "ui/views/border.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
#include "ui/views/view_class_properties.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
using MD = ui::MaterialDesignController; using MD = ui::MaterialDesignController;
...@@ -119,6 +119,23 @@ void IconLabelBubbleView::SeparatorView::UpdateOpacity() { ...@@ -119,6 +119,23 @@ void IconLabelBubbleView::SeparatorView::UpdateOpacity() {
} }
} }
//////////////////////////////////////////////////////////////////
// HighlightPathGenerator class
class IconLabelBubbleView::HighlightPathGenerator
: public views::HighlightPathGenerator {
public:
HighlightPathGenerator() = default;
// views::HighlightPathGenerator:
SkPath GetHighlightPath(const views::View* view) override {
return static_cast<const IconLabelBubbleView*>(view)->GetHighlightPath();
}
private:
DISALLOW_COPY_AND_ASSIGN(HighlightPathGenerator);
};
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// IconLabelBubbleView class // IconLabelBubbleView class
...@@ -136,6 +153,9 @@ IconLabelBubbleView::IconLabelBubbleView(const gfx::FontList& font_list) ...@@ -136,6 +153,9 @@ IconLabelBubbleView::IconLabelBubbleView(const gfx::FontList& font_list)
set_ink_drop_highlight_opacity( set_ink_drop_highlight_opacity(
GetOmniboxStateOpacity(OmniboxPartState::HOVERED)); GetOmniboxStateOpacity(OmniboxPartState::HOVERED));
views::HighlightPathGenerator::Install(
this, std::make_unique<HighlightPathGenerator>());
UpdateBorder(); UpdateBorder();
set_notify_enter_exit_on_child(true); set_notify_enter_exit_on_child(true);
...@@ -264,7 +284,10 @@ void IconLabelBubbleView::Layout() { ...@@ -264,7 +284,10 @@ void IconLabelBubbleView::Layout() {
separator_view_->SetBounds(separator_x, separator_bounds.y(), separator_width, separator_view_->SetBounds(separator_x, separator_bounds.y(), separator_width,
separator_height); separator_height);
UpdateHighlightPath(); if (focus_ring()) {
focus_ring()->Layout();
focus_ring()->SchedulePaint();
}
} }
bool IconLabelBubbleView::OnMousePressed(const ui::MouseEvent& event) { bool IconLabelBubbleView::OnMousePressed(const ui::MouseEvent& event) {
...@@ -522,7 +545,7 @@ void IconLabelBubbleView::HideAnimation() { ...@@ -522,7 +545,7 @@ void IconLabelBubbleView::HideAnimation() {
GetInkDrop()->SetShowHighlightOnFocus(false); GetInkDrop()->SetShowHighlightOnFocus(false);
} }
void IconLabelBubbleView::UpdateHighlightPath() { SkPath IconLabelBubbleView::GetHighlightPath() const {
gfx::Rect highlight_bounds = GetLocalBounds(); gfx::Rect highlight_bounds = GetLocalBounds();
if (ShouldShowSeparator()) if (ShouldShowSeparator())
highlight_bounds.Inset(0, 0, GetEndPaddingWithSeparator(), 0); highlight_bounds.Inset(0, 0, GetEndPaddingWithSeparator(), 0);
...@@ -531,13 +554,7 @@ void IconLabelBubbleView::UpdateHighlightPath() { ...@@ -531,13 +554,7 @@ void IconLabelBubbleView::UpdateHighlightPath() {
const float corner_radius = highlight_bounds.height() / 2.f; const float corner_radius = highlight_bounds.height() / 2.f;
const SkRect rect = RectToSkRect(highlight_bounds); const SkRect rect = RectToSkRect(highlight_bounds);
SkPath path; return SkPath().addRoundRect(rect, corner_radius, corner_radius);
path.addRoundRect(rect, corner_radius, corner_radius);
SetProperty(views::kHighlightPathKey, path);
if (focus_ring()) {
focus_ring()->Layout();
focus_ring()->SchedulePaint();
}
} }
void IconLabelBubbleView::UpdateBorder() { void IconLabelBubbleView::UpdateBorder() {
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/optional.h" #include "base/optional.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "third_party/skia/include/core/SkPath.h"
#include "ui/base/material_design/material_design_controller.h" #include "ui/base/material_design/material_design_controller.h"
#include "ui/base/material_design/material_design_controller_observer.h" #include "ui/base/material_design/material_design_controller_observer.h"
#include "ui/gfx/geometry/insets.h" #include "ui/gfx/geometry/insets.h"
...@@ -188,6 +189,8 @@ class IconLabelBubbleView : public views::InkDropObserver, ...@@ -188,6 +189,8 @@ class IconLabelBubbleView : public views::InkDropObserver,
bool is_animation_paused() const { return is_animation_paused_; } bool is_animation_paused() const { return is_animation_paused_; }
private: private:
class HighlightPathGenerator;
// Spacing between the image and the label. // Spacing between the image and the label.
int GetInternalSpacing() const; int GetInternalSpacing() const;
...@@ -216,9 +219,9 @@ class IconLabelBubbleView : public views::InkDropObserver, ...@@ -216,9 +219,9 @@ class IconLabelBubbleView : public views::InkDropObserver,
// called directly, use AnimateOut() instead, which handles label visibility. // called directly, use AnimateOut() instead, which handles label visibility.
void HideAnimation(); void HideAnimation();
// Updates the highlight path for ink drops and focus rings using the current // Gets the highlight path for ink drops and focus rings using the current
// bounds and the separator visibility. // bounds and separator visibility.
void UpdateHighlightPath(); SkPath GetHighlightPath() const;
// Sets the border padding around this view. // Sets the border padding around this view.
void UpdateBorder(); void UpdateBorder();
......
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