Commit f060d1dd authored by David Black's avatar David Black Committed by Chromium LUCI CQ

Fix focus ring for downloads section header.

Though the entire downloads section header is focusable and behaves as
a single button, the focus ring is drawn as a circle around just the
chevron.

Screenshot: http://shortn/_yNqR9nC2Pk

Bug: 1160011
Change-Id: Ie58083966e5bf1d01b09472cc7271b978741b91f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2628747
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843687}
parent 0e949152
......@@ -19,6 +19,7 @@
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
......@@ -27,6 +28,26 @@ namespace ash {
namespace {
// CallbackPathGenerator -------------------------------------------------------
class CallbackPathGenerator : public views::HighlightPathGenerator {
public:
using Callback = base::RepeatingCallback<gfx::RRectF()>;
explicit CallbackPathGenerator(Callback callback) : callback_(callback) {}
CallbackPathGenerator(const CallbackPathGenerator&) = delete;
CallbackPathGenerator& operator=(const CallbackPathGenerator&) = delete;
~CallbackPathGenerator() override = default;
private:
// views::HighlightPathGenerator:
base::Optional<gfx::RRectF> GetRoundRect(const gfx::RectF& rect) override {
return callback_.Run();
}
Callback callback_;
};
// Header ----------------------------------------------------------------------
class Header : public views::Button {
......@@ -37,11 +58,6 @@ class Header : public views::Button {
SetCallback(
base::BindRepeating(&Header::OnPressed, base::Unretained(this)));
// Focus ring.
AshColorProvider* const ash_color_provider = AshColorProvider::Get();
focus_ring()->SetColor(ash_color_provider->GetControlsLayerColor(
AshColorProvider::ControlsLayerType::kFocusRingColor));
auto* layout = SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal, gfx::Insets(),
kHoldingSpaceDownloadsHeaderSpacing));
......@@ -54,12 +70,33 @@ class Header : public views::Button {
layout->SetFlexForView(label, 1);
// Chevron.
AshColorProvider* const ash_color_provider = AshColorProvider::Get();
auto* chevron = AddChildView(std::make_unique<views::ImageView>());
chevron->SetFlipCanvasOnPaintForRTLUI(true);
chevron->SetImage(gfx::CreateVectorIcon(
kChevronRightIcon, kHoldingSpaceDownloadsChevronIconSize,
ash_color_provider->GetContentLayerColor(
AshColorProvider::ContentLayerType::kIconColorPrimary)));
// Focus ring.
focus_ring()->SetColor(ash_color_provider->GetControlsLayerColor(
AshColorProvider::ControlsLayerType::kFocusRingColor));
// Though the entirety of the header is focusable and behaves as a single
// button, the focus ring is drawn as a circle around just the `chevron`.
focus_ring()->SetPathGenerator(
std::make_unique<CallbackPathGenerator>(base::BindRepeating(
[](const views::View* chevron) {
const float radius = chevron->width() / 2.f;
gfx::RRectF path(gfx::RectF(chevron->bounds()), radius);
if (base::i18n::IsRTL()) {
// Manually adjust for flipped canvas in RTL.
path.Offset(-chevron->parent()->width(), 0.f);
path.Scale(-1.f, 1.f);
}
return path;
},
base::Unretained(chevron))));
}
private:
......
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