Commit cb26d351 authored by Manuel Rego Casasnovas's avatar Manuel Rego Casasnovas Committed by Commit Bot

Remove LayoutTheme::IsFocusRingOutset()

This patch removes LayoutTheme::IsFocusRingOutset()
as it's only implemented in one place and returns always "false".

Due to this we can also remove the method
ShouldDrawInnerFocusRingForContrast() in graphics_context.cc,
as it always return "false" too.

No new tests as it's covered by existent tests, just removing dead code.

Change-Id: Ib4715770603d2ac66b353c7d077b75385e24aa3b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2134248Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Reviewed-by: default avatarMason Freed <masonfreed@chromium.org>
Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Manuel Rego <rego@igalia.com>
Cr-Commit-Position: refs/heads/master@{#756266}
parent 5aabde78
......@@ -866,10 +866,6 @@ void LayoutTheme::SetCustomFocusRingColor(const Color& c) {
has_custom_focus_ring_color_ = true;
}
bool LayoutTheme::IsFocusRingOutset() const {
return false;
}
Color LayoutTheme::FocusRingColor() const {
return has_custom_focus_ring_color_ ? custom_focus_ring_color_
: GetTheme().PlatformFocusRingColor();
......
......@@ -169,7 +169,6 @@ class CORE_EXPORT LayoutTheme : public RefCounted<LayoutTheme> {
bool in_forced_colors_mode,
WebColorScheme color_scheme) const;
virtual bool IsFocusRingOutset() const;
virtual Color FocusRingColor() const;
virtual Color PlatformFocusRingColor() const { return Color(0, 0, 0); }
void SetCustomFocusRingColor(const Color&);
......
......@@ -551,8 +551,7 @@ void ObjectPainterBase::PaintOutlineRects(
paint_info.context.DrawFocusRing(
pixel_snapped_outline_rects, style.GetOutlineStrokeWidthForFocusRing(),
style.OutlineOffset(), style.GetDefaultOffsetForFocusRing(),
border_radius, min_border_width, color,
LayoutTheme::GetTheme().IsFocusRingOutset());
border_radius, min_border_width, color);
return;
}
......
......@@ -2235,8 +2235,7 @@ int ComputedStyle::OutlineOutsetExtent() const {
if (OutlineStyleIsAuto()) {
return GraphicsContext::FocusRingOutsetExtent(
OutlineOffset(), GetDefaultOffsetForFocusRing(),
std::ceil(GetOutlineStrokeWidthForFocusRing()),
LayoutTheme::GetTheme().IsFocusRingOutset());
std::ceil(GetOutlineStrokeWidthForFocusRing()));
}
return base::ClampAdd(OutlineWidth(), OutlineOffset()).Max(0);
}
......@@ -2249,9 +2248,6 @@ float ComputedStyle::GetOutlineStrokeWidthForFocusRing() const {
#if defined(OS_MACOSX)
return OutlineWidth();
#else
if (LayoutTheme::GetTheme().IsFocusRingOutset()) {
return OutlineWidth();
}
// Draw an outline with thickness in proportion to the zoom level, but never
// so narrow that it becomes invisible.
return std::max(EffectiveZoom(), 1.f);
......
......@@ -88,12 +88,10 @@ TEST(ComputedStyleTest, FocusRingWidth) {
static uint16_t outline_width = 4;
style->SetOutlineWidth(outline_width);
double expected_width =
LayoutTheme::GetTheme().IsFocusRingOutset() ? outline_width : 3.5;
double expected_width = 3.5;
EXPECT_EQ(expected_width, style->GetOutlineStrokeWidthForFocusRing());
expected_width =
LayoutTheme::GetTheme().IsFocusRingOutset() ? outline_width : 1.0;
expected_width = 1.0;
style->SetEffectiveZoom(0.5);
EXPECT_EQ(expected_width, style->GetOutlineStrokeWidthForFocusRing());
#endif
......
......@@ -322,10 +322,7 @@ void GraphicsContext::CompositeRecord(sk_sp<PaintRecord> record,
namespace {
int AdjustedFocusRingOffset(int offset,
int default_offset,
int width,
bool is_outset) {
int AdjustedFocusRingOffset(int offset, int default_offset, int width) {
if (::features::IsFormControlsRefreshEnabled()) {
// For FormControlsRefresh the focus ring has a default offset that
// depends on the element type.
......@@ -335,8 +332,6 @@ int AdjustedFocusRingOffset(int offset,
#if defined(OS_MACOSX)
return offset + 2;
#else
if (is_outset)
return offset + width - (width + 1) / 2;
return 0;
#endif
}
......@@ -345,19 +340,17 @@ int AdjustedFocusRingOffset(int offset,
int GraphicsContext::FocusRingOutsetExtent(int offset,
int default_offset,
int width,
bool is_outset) {
int width) {
// Unlike normal outlines (whole width is outside of the offset), focus
// rings can be drawn with the center of the path aligned with the offset, so
// only half of the width is outside of the offset.
if (::features::IsFormControlsRefreshEnabled()) {
// For FormControlsRefresh 2/3 of the width is outside of the offset.
return AdjustedFocusRingOffset(offset, default_offset, width, is_outset) +
return AdjustedFocusRingOffset(offset, default_offset, width) +
std::ceil(width / 3.f) * 2;
}
return AdjustedFocusRingOffset(offset, /*default_offset=*/0, width,
is_outset) +
return AdjustedFocusRingOffset(offset, /*default_offset=*/0, width) +
(width + 1) / 2;
}
......@@ -398,8 +391,7 @@ void GraphicsContext::DrawFocusRingInternal(const Vector<IntRect>& rects,
float width,
int offset,
float border_radius,
const Color& color,
bool is_outset) {
const Color& color) {
unsigned rect_count = rects.size();
if (!rect_count)
return;
......@@ -408,8 +400,8 @@ void GraphicsContext::DrawFocusRingInternal(const Vector<IntRect>& rects,
if (!::features::IsFormControlsRefreshEnabled()) {
// For FormControlsRefresh the offset is already adjusted by
// GraphicsContext::DrawFocusRing.
offset = AdjustedFocusRingOffset(offset, /*default_offset=*/0,
std::ceil(width), is_outset);
offset =
AdjustedFocusRingOffset(offset, /*default_offset=*/0, std::ceil(width));
}
for (unsigned i = 0; i < rect_count; i++) {
SkIRect r = rects[i];
......@@ -432,38 +424,19 @@ void GraphicsContext::DrawFocusRingInternal(const Vector<IntRect>& rects,
}
}
namespace {
static const double kFocusRingLuminanceThreshold = 0.45;
bool ShouldDrawInnerFocusRingForContrast(bool is_outset,
float width,
Color color) {
if (!is_outset || width < 3) {
return false;
}
double h = 0.0, s = 0.0, l = 0.0;
color.GetHSL(h, s, l);
return l < kFocusRingLuminanceThreshold;
}
} // namespace
void GraphicsContext::DrawFocusRing(const Vector<IntRect>& rects,
float width,
int offset,
int default_offset,
float border_radius,
float min_border_width,
const Color& color,
bool is_outset) {
const Color& color) {
if (::features::IsFormControlsRefreshEnabled()) {
// The focus ring is made of two borders which have a 2:1 ratio.
const float first_border_width = (width / 3) * 2;
const float second_border_width = width - first_border_width;
offset = AdjustedFocusRingOffset(offset, default_offset, std::ceil(width),
is_outset);
offset = AdjustedFocusRingOffset(offset, default_offset, std::ceil(width));
// How much space the focus ring would like to take from the actual border.
const float inside_border_width = 1;
if (min_border_width >= inside_border_width) {
......@@ -473,27 +446,11 @@ void GraphicsContext::DrawFocusRing(const Vector<IntRect>& rects,
// artifacts.
DrawFocusRingInternal(rects, first_border_width,
offset + std::ceil(second_border_width),
border_radius, SK_ColorWHITE, is_outset);
border_radius, SK_ColorWHITE);
DrawFocusRingInternal(rects, first_border_width, offset, border_radius,
color, is_outset);
color);
} else {
// If a focus ring is outset and the color is dark, it may be hard to see on
// dark backgrounds. In this case, we'll actually draw two focus rings, the
// outset focus ring with a white inner ring for contrast.
if (ShouldDrawInnerFocusRingForContrast(is_outset, width, color)) {
int contrast_offset = static_cast<int>(std::floor(width * 0.5));
// We create a 1px gap for the contrast ring. The contrast ring is drawn
// first, and we overdraw by a pixel to ensure no gaps or AA artifacts.
DrawFocusRingInternal(rects, contrast_offset, offset, border_radius,
SK_ColorWHITE, is_outset);
DrawFocusRingInternal(rects, width - contrast_offset,
offset + contrast_offset, border_radius, color,
is_outset);
} else {
DrawFocusRingInternal(rects, width, offset, border_radius, color,
is_outset);
}
DrawFocusRingInternal(rects, width, offset, border_radius, color);
}
}
......
......@@ -365,8 +365,7 @@ class PLATFORM_EXPORT GraphicsContext {
int default_offset,
float border_radius,
float min_border_width,
const Color&,
bool is_outset);
const Color&);
void DrawFocusRing(const Path&, float width, int offset, const Color&);
enum Edge {
......@@ -422,10 +421,7 @@ class PLATFORM_EXPORT GraphicsContext {
FloatPoint& p2,
float stroke_width);
static int FocusRingOutsetExtent(int offset,
int default_offset,
int width,
bool is_outset);
static int FocusRingOutsetExtent(int offset, int default_offset, int width);
void SetInDrawingRecorder(bool);
bool InDrawingRecorder() const { return in_drawing_recorder_; }
......@@ -480,8 +476,7 @@ class PLATFORM_EXPORT GraphicsContext {
float width,
int offset,
float border_radius,
const Color&,
bool is_outset);
const Color&);
// SkCanvas wrappers.
void ClipRRect(const SkRRect&,
......
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