Commit 38410b62 authored by Peter Boström's avatar Peter Boström Committed by Commit Bot

Use FocusRing RoundRects to match toolbar inkdrops

Creates a SkPath that matches the inkdrop shape and use that as the
focus ring.

In the future, hopefully the inkdrop shape can be generated from the
same path so that they are forced to stay in sync. For now though they
are less separate as the focus ring shape is generated using the same
insets as the inkdrop.

This focus ring is installed for ToolbarButton, BrowserAppMenuButton and
ToolbarActionView (all are visibly toolbar buttons).

Bug: chromium:862925
Change-Id: I898d2d9c6a9e058e9f84aff37615ebf3ab41cee7
Reviewed-on: https://chromium-review.googlesource.com/1139221Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: Peter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575653}
parent 55388b6f
...@@ -280,6 +280,15 @@ BrowserAppMenuButton::CreateDefaultBorder() const { ...@@ -280,6 +280,15 @@ BrowserAppMenuButton::CreateDefaultBorder() const {
return border; return border;
} }
void BrowserAppMenuButton::OnBoundsChanged(const gfx::Rect& previous_bounds) {
// TODO(pbos): Consolidate with ToolbarButton::OnBoundsChanged.
if (focus_ring()) {
focus_ring()->SetPath(CreateToolbarFocusRingPath(
this, gfx::Insets(0, 0, 0, margin_trailing_)));
}
AppMenuButton::OnBoundsChanged(previous_bounds);
}
gfx::Rect BrowserAppMenuButton::GetThemePaintRect() const { gfx::Rect BrowserAppMenuButton::GetThemePaintRect() const {
gfx::Rect rect(MenuButton::GetThemePaintRect()); gfx::Rect rect(MenuButton::GetThemePaintRect());
rect.Inset(0, 0, margin_trailing_, 0); rect.Inset(0, 0, margin_trailing_, 0);
......
...@@ -46,6 +46,7 @@ class BrowserAppMenuButton : public AppMenuButton, ...@@ -46,6 +46,7 @@ class BrowserAppMenuButton : public AppMenuButton,
void SetIsProminent(bool is_prominent); void SetIsProminent(bool is_prominent);
// views::MenuButton: // views::MenuButton:
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
void Layout() override; void Layout() override;
void OnThemeChanged() override; void OnThemeChanged() override;
......
...@@ -91,6 +91,14 @@ ToolbarActionView::~ToolbarActionView() { ...@@ -91,6 +91,14 @@ ToolbarActionView::~ToolbarActionView() {
view_controller_->SetDelegate(nullptr); view_controller_->SetDelegate(nullptr);
} }
void ToolbarActionView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
// TODO(pbos): Consolidate with ToolbarButton::OnBoundsChanged.
if (focus_ring()) {
focus_ring()->SetPath(CreateToolbarFocusRingPath(this, gfx::Insets()));
}
MenuButton::OnBoundsChanged(previous_bounds);
}
void ToolbarActionView::GetAccessibleNodeData(ui::AXNodeData* node_data) { void ToolbarActionView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
views::MenuButton::GetAccessibleNodeData(node_data); views::MenuButton::GetAccessibleNodeData(node_data);
node_data->role = ax::mojom::Role::kButton; node_data->role = ax::mojom::Role::kButton;
......
...@@ -62,6 +62,7 @@ class ToolbarActionView : public views::MenuButton, ...@@ -62,6 +62,7 @@ class ToolbarActionView : public views::MenuButton,
~ToolbarActionView() override; ~ToolbarActionView() override;
// views::MenuButton: // views::MenuButton:
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override; void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
std::unique_ptr<views::LabelButtonBorder> CreateDefaultBorder() std::unique_ptr<views::LabelButtonBorder> CreateDefaultBorder()
const override; const override;
......
...@@ -119,9 +119,8 @@ bool ToolbarButton::IsMenuShowing() const { ...@@ -119,9 +119,8 @@ bool ToolbarButton::IsMenuShowing() const {
void ToolbarButton::OnBoundsChanged(const gfx::Rect& previous_bounds) { void ToolbarButton::OnBoundsChanged(const gfx::Rect& previous_bounds) {
if (focus_ring()) { if (focus_ring()) {
SkPath path; focus_ring()->SetPath(CreateToolbarFocusRingPath(
path.addOval(gfx::RectToSkRect(GetLocalBounds())); this, gfx::Insets(0, leading_margin_, 0, 0)));
focus_ring()->SetPath(path);
} }
UpdateHighlightBackgroundAndInsets(); UpdateHighlightBackgroundAndInsets();
LabelButton::OnBoundsChanged(previous_bounds); LabelButton::OnBoundsChanged(previous_bounds);
......
...@@ -54,6 +54,24 @@ gfx::Insets GetInkDropInsets(BaseInkDropHostView* host_view, ...@@ -54,6 +54,24 @@ gfx::Insets GetInkDropInsets(BaseInkDropHostView* host_view,
return inkdrop_insets; return inkdrop_insets;
} }
// Create a SkPath matching the toolbar inkdrops to be used for the focus ring.
// TODO(pbos): Consolidate inkdrop effects, highlights and ripples along with
// focus rings so that they are derived from the same actual SkPath or other
// shared primitive. That way they would be significantly easier to keep in
// sync. This method at least reuses GetInkDropInsets.
template <class BaseInkDropHostView>
SkPath CreateToolbarFocusRingPath(BaseInkDropHostView* host_view,
const gfx::Insets& margin_insets) {
gfx::Rect rect(host_view->size());
rect.Inset(GetInkDropInsets(host_view, margin_insets));
SkPath path;
path.addRoundRect(gfx::RectToSkRect(rect),
host_view->ink_drop_large_corner_radius(),
host_view->ink_drop_large_corner_radius());
return path;
}
// Creates the appropriate ink drop for the calling button. When the newer // Creates the appropriate ink drop for the calling button. When the newer
// material UI is not enabled, it uses the default implementation of the // material UI is not enabled, it uses the default implementation of the
// calling button's base class (the template argument BaseInkDropHostView). // calling button's base class (the template argument BaseInkDropHostView).
......
...@@ -600,9 +600,11 @@ void ToolbarView::Layout() { ...@@ -600,9 +600,11 @@ void ToolbarView::Layout() {
if (maximized) if (maximized)
app_menu_width += end_padding; app_menu_width += end_padding;
// Set trailing margin before updating the bounds so OnBoundsChange can use
// the trailing margin.
app_menu_button_->SetTrailingMargin(maximized ? end_padding : 0);
app_menu_button_->SetBounds(next_element_x, toolbar_button_y, app_menu_width, app_menu_button_->SetBounds(next_element_x, toolbar_button_y, app_menu_width,
toolbar_button_height); toolbar_button_height);
app_menu_button_->SetTrailingMargin(maximized ? end_padding : 0);
} }
void ToolbarView::OnPaintBackground(gfx::Canvas* canvas) { void ToolbarView::OnPaintBackground(gfx::Canvas* canvas) {
......
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