Commit a0c4aeac authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

views: support focus rings on tab-close buttons

This change:
1) Adds focus rings to the tab-close button
2) Moves the new tab button to last in the TabStrip's focus order if it is not
   in LEADING position so that the keyboard focus order within the TabStrip is
   correct

Positioning the ring for the tab-close button requires some finesse: the tab
close button has its margins adjusted, but the focus ring only needs to draw
around the visible part of the button.

Bug: 848299
Change-Id: I226683d3a8829f5a88e9bf102b4c8ba4ecfae459
Reviewed-on: https://chromium-review.googlesource.com/1091131Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565673}
parent 7aebaa45
......@@ -867,6 +867,12 @@ void Tab::Layout() {
close_button_->SetBorder(
views::CreateEmptyBorder(top, left, bottom, right));
close_button_->SizeToPreferredSize();
// Re-layout the close button so it can recompute its focus ring if needed:
// SizeToPreferredSize() will not necessarily re-Layout the View if only its
// interior margins have changed (which this logic does), but the focus ring
// still needs to be updated because it doesn't want to encompass the
// interior margins.
close_button_->Layout();
}
close_button_->SetVisible(showing_close_button_);
......
......@@ -24,6 +24,7 @@
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/rect_based_targeting_utils.h"
#include "ui/views/style/platform_style.h"
#if defined(USE_AURA)
#include "ui/aura/env.h"
......@@ -40,6 +41,10 @@ TabCloseButton::TabCloseButton(views::ButtonListener* listener,
// Disable animation so that the red danger sign shows up immediately
// to help avoid mis-clicks.
SetAnimationDuration(0);
SetInstallFocusRingOnFocus(views::PlatformStyle::kPreferFocusRings);
if (focus_ring())
SetFocusPainter(nullptr);
}
TabCloseButton::~TabCloseButton() {}
......@@ -106,6 +111,16 @@ const char* TabCloseButton::GetClassName() const {
return "TabCloseButton";
}
void TabCloseButton::Layout() {
ImageButton::Layout();
if (focus_ring()) {
focus_ring()->Layout();
SkPath path;
path.addOval(gfx::RectToSkRect(GetContentsBounds()));
focus_ring()->SetPath(path);
}
}
void TabCloseButton::PaintButtonContents(gfx::Canvas* canvas) {
canvas->SaveLayerAlpha(GetOpacity());
views::ImageButton::PaintButtonContents(canvas);
......
......@@ -47,6 +47,7 @@ class TabCloseButton : public views::ImageButton,
void OnMouseReleased(const ui::MouseEvent& event) override;
void OnGestureEvent(ui::GestureEvent* event) override;
const char* GetClassName() const override;
void Layout() override;
protected:
void PaintButtonContents(gfx::Canvas* canvas) override;
......
......@@ -464,6 +464,12 @@ void TabStrip::AddTabAt(int model_index, TabRendererData data, bool is_active) {
tabs_.Add(tab, model_index);
selected_tabs_.IncrementFrom(model_index);
// If the new tab button is visually after the tabs, make sure it is logically
// afterwards as well so that the focus traversal order is correct.
NewTabButtonPosition position = controller_->GetNewTabButtonPosition();
if (position == AFTER_TABS || position == TRAILING)
ReorderChildView(new_tab_button_, -1);
if (touch_layout_) {
GenerateIdealBoundsForPinnedTabs(NULL);
int add_types = 0;
......
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