Commit 2c27da07 authored by Peter Boström's avatar Peter Boström Committed by Commit Bot

Add a TabStyleHighlightPathGenerator to Tab

Replaces probably a significant amount of path updates in
::OnBoundsChanged override (which this change also removes).

This might reduce some jank in the tab strip while opening tabs or
resizing windows, though it's unclear whether it amounts to a
significant chunk of work as a fraction of total work here.

Bug: chromium:1007546
Change-Id: I5aab0ce9cfcaeea2bec80f994d0586e588ff977e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1861044
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@{#705971}
parent 5e45d793
...@@ -72,6 +72,7 @@ ...@@ -72,6 +72,7 @@
#include "ui/resources/grit/ui_resources.h" #include "ui/resources/grit/ui_resources.h"
#include "ui/views/border.h" #include "ui/views/border.h"
#include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/rect_based_targeting_utils.h" #include "ui/views/rect_based_targeting_utils.h"
#include "ui/views/view.h" #include "ui/views/view.h"
...@@ -114,6 +115,22 @@ int Center(int size, int item_size) { ...@@ -114,6 +115,22 @@ int Center(int size, int item_size) {
return extra_space / 2; return extra_space / 2;
} }
class TabStyleHighlightPathGenerator : public views::HighlightPathGenerator {
public:
explicit TabStyleHighlightPathGenerator(TabStyle* tab_style)
: tab_style_(tab_style) {}
// views::HighlightPathGenerator:
SkPath GetHighlightPath(const views::View* view) override {
return tab_style_->GetPath(TabStyle::PathType::kHighlight, 1.0);
}
private:
TabStyle* const tab_style_;
DISALLOW_COPY_AND_ASSIGN(TabStyleHighlightPathGenerator);
};
} // namespace } // namespace
// Helper class that observes the tab's close button. // Helper class that observes the tab's close button.
...@@ -206,6 +223,8 @@ Tab::Tab(TabController* controller) ...@@ -206,6 +223,8 @@ Tab::Tab(TabController* controller)
// Enable keyboard focus. // Enable keyboard focus.
SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
focus_ring_ = views::FocusRing::Install(this); focus_ring_ = views::FocusRing::Install(this);
views::HighlightPathGenerator::Install(
this, std::make_unique<TabStyleHighlightPathGenerator>(tab_style_.get()));
} }
Tab::~Tab() { Tab::~Tab() {
...@@ -400,12 +419,6 @@ const char* Tab::GetClassName() const { ...@@ -400,12 +419,6 @@ const char* Tab::GetClassName() const {
return kViewClassName; return kViewClassName;
} }
void Tab::OnBoundsChanged(const gfx::Rect& previous_bounds) {
// Update focus ring path.
const SkPath path = tab_style_->GetPath(TabStyle::PathType::kHighlight, 1.0);
SetProperty(views::kHighlightPathKey, path);
}
bool Tab::OnKeyPressed(const ui::KeyEvent& event) { bool Tab::OnKeyPressed(const ui::KeyEvent& event) {
if (event.key_code() == ui::VKEY_SPACE && !IsSelected()) { if (event.key_code() == ui::VKEY_SPACE && !IsSelected()) {
controller_->SelectTab(this, event); controller_->SelectTab(this, event);
......
...@@ -79,7 +79,6 @@ class Tab : public gfx::AnimationDelegate, ...@@ -79,7 +79,6 @@ class Tab : public gfx::AnimationDelegate,
// TabSlotView: // TabSlotView:
void Layout() override; void Layout() override;
const char* GetClassName() const override; const char* GetClassName() const override;
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
bool OnKeyPressed(const ui::KeyEvent& event) override; bool OnKeyPressed(const ui::KeyEvent& event) override;
bool OnMousePressed(const ui::MouseEvent& event) override; bool OnMousePressed(const ui::MouseEvent& event) override;
bool OnMouseDragged(const ui::MouseEvent& event) override; bool OnMouseDragged(const ui::MouseEvent& event) 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