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) { ...@@ -866,10 +866,6 @@ void LayoutTheme::SetCustomFocusRingColor(const Color& c) {
has_custom_focus_ring_color_ = true; has_custom_focus_ring_color_ = true;
} }
bool LayoutTheme::IsFocusRingOutset() const {
return false;
}
Color LayoutTheme::FocusRingColor() const { Color LayoutTheme::FocusRingColor() const {
return has_custom_focus_ring_color_ ? custom_focus_ring_color_ return has_custom_focus_ring_color_ ? custom_focus_ring_color_
: GetTheme().PlatformFocusRingColor(); : GetTheme().PlatformFocusRingColor();
......
...@@ -169,7 +169,6 @@ class CORE_EXPORT LayoutTheme : public RefCounted<LayoutTheme> { ...@@ -169,7 +169,6 @@ class CORE_EXPORT LayoutTheme : public RefCounted<LayoutTheme> {
bool in_forced_colors_mode, bool in_forced_colors_mode,
WebColorScheme color_scheme) const; WebColorScheme color_scheme) const;
virtual bool IsFocusRingOutset() const;
virtual Color FocusRingColor() const; virtual Color FocusRingColor() const;
virtual Color PlatformFocusRingColor() const { return Color(0, 0, 0); } virtual Color PlatformFocusRingColor() const { return Color(0, 0, 0); }
void SetCustomFocusRingColor(const Color&); void SetCustomFocusRingColor(const Color&);
......
...@@ -551,8 +551,7 @@ void ObjectPainterBase::PaintOutlineRects( ...@@ -551,8 +551,7 @@ void ObjectPainterBase::PaintOutlineRects(
paint_info.context.DrawFocusRing( paint_info.context.DrawFocusRing(
pixel_snapped_outline_rects, style.GetOutlineStrokeWidthForFocusRing(), pixel_snapped_outline_rects, style.GetOutlineStrokeWidthForFocusRing(),
style.OutlineOffset(), style.GetDefaultOffsetForFocusRing(), style.OutlineOffset(), style.GetDefaultOffsetForFocusRing(),
border_radius, min_border_width, color, border_radius, min_border_width, color);
LayoutTheme::GetTheme().IsFocusRingOutset());
return; return;
} }
......
...@@ -2235,8 +2235,7 @@ int ComputedStyle::OutlineOutsetExtent() const { ...@@ -2235,8 +2235,7 @@ int ComputedStyle::OutlineOutsetExtent() const {
if (OutlineStyleIsAuto()) { if (OutlineStyleIsAuto()) {
return GraphicsContext::FocusRingOutsetExtent( return GraphicsContext::FocusRingOutsetExtent(
OutlineOffset(), GetDefaultOffsetForFocusRing(), OutlineOffset(), GetDefaultOffsetForFocusRing(),
std::ceil(GetOutlineStrokeWidthForFocusRing()), std::ceil(GetOutlineStrokeWidthForFocusRing()));
LayoutTheme::GetTheme().IsFocusRingOutset());
} }
return base::ClampAdd(OutlineWidth(), OutlineOffset()).Max(0); return base::ClampAdd(OutlineWidth(), OutlineOffset()).Max(0);
} }
...@@ -2249,9 +2248,6 @@ float ComputedStyle::GetOutlineStrokeWidthForFocusRing() const { ...@@ -2249,9 +2248,6 @@ float ComputedStyle::GetOutlineStrokeWidthForFocusRing() const {
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
return OutlineWidth(); return OutlineWidth();
#else #else
if (LayoutTheme::GetTheme().IsFocusRingOutset()) {
return OutlineWidth();
}
// Draw an outline with thickness in proportion to the zoom level, but never // Draw an outline with thickness in proportion to the zoom level, but never
// so narrow that it becomes invisible. // so narrow that it becomes invisible.
return std::max(EffectiveZoom(), 1.f); return std::max(EffectiveZoom(), 1.f);
......
...@@ -88,12 +88,10 @@ TEST(ComputedStyleTest, FocusRingWidth) { ...@@ -88,12 +88,10 @@ TEST(ComputedStyleTest, FocusRingWidth) {
static uint16_t outline_width = 4; static uint16_t outline_width = 4;
style->SetOutlineWidth(outline_width); style->SetOutlineWidth(outline_width);
double expected_width = double expected_width = 3.5;
LayoutTheme::GetTheme().IsFocusRingOutset() ? outline_width : 3.5;
EXPECT_EQ(expected_width, style->GetOutlineStrokeWidthForFocusRing()); EXPECT_EQ(expected_width, style->GetOutlineStrokeWidthForFocusRing());
expected_width = expected_width = 1.0;
LayoutTheme::GetTheme().IsFocusRingOutset() ? outline_width : 1.0;
style->SetEffectiveZoom(0.5); style->SetEffectiveZoom(0.5);
EXPECT_EQ(expected_width, style->GetOutlineStrokeWidthForFocusRing()); EXPECT_EQ(expected_width, style->GetOutlineStrokeWidthForFocusRing());
#endif #endif
......
...@@ -322,10 +322,7 @@ void GraphicsContext::CompositeRecord(sk_sp<PaintRecord> record, ...@@ -322,10 +322,7 @@ void GraphicsContext::CompositeRecord(sk_sp<PaintRecord> record,
namespace { namespace {
int AdjustedFocusRingOffset(int offset, int AdjustedFocusRingOffset(int offset, int default_offset, int width) {
int default_offset,
int width,
bool is_outset) {
if (::features::IsFormControlsRefreshEnabled()) { if (::features::IsFormControlsRefreshEnabled()) {
// For FormControlsRefresh the focus ring has a default offset that // For FormControlsRefresh the focus ring has a default offset that
// depends on the element type. // depends on the element type.
...@@ -335,8 +332,6 @@ int AdjustedFocusRingOffset(int offset, ...@@ -335,8 +332,6 @@ int AdjustedFocusRingOffset(int offset,
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
return offset + 2; return offset + 2;
#else #else
if (is_outset)
return offset + width - (width + 1) / 2;
return 0; return 0;
#endif #endif
} }
...@@ -345,19 +340,17 @@ int AdjustedFocusRingOffset(int offset, ...@@ -345,19 +340,17 @@ int AdjustedFocusRingOffset(int offset,
int GraphicsContext::FocusRingOutsetExtent(int offset, int GraphicsContext::FocusRingOutsetExtent(int offset,
int default_offset, int default_offset,
int width, int width) {
bool is_outset) {
// Unlike normal outlines (whole width is outside of the offset), focus // 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 // 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. // only half of the width is outside of the offset.
if (::features::IsFormControlsRefreshEnabled()) { if (::features::IsFormControlsRefreshEnabled()) {
// For FormControlsRefresh 2/3 of the width is outside of the offset. // 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; std::ceil(width / 3.f) * 2;
} }
return AdjustedFocusRingOffset(offset, /*default_offset=*/0, width, return AdjustedFocusRingOffset(offset, /*default_offset=*/0, width) +
is_outset) +
(width + 1) / 2; (width + 1) / 2;
} }
...@@ -398,8 +391,7 @@ void GraphicsContext::DrawFocusRingInternal(const Vector<IntRect>& rects, ...@@ -398,8 +391,7 @@ void GraphicsContext::DrawFocusRingInternal(const Vector<IntRect>& rects,
float width, float width,
int offset, int offset,
float border_radius, float border_radius,
const Color& color, const Color& color) {
bool is_outset) {
unsigned rect_count = rects.size(); unsigned rect_count = rects.size();
if (!rect_count) if (!rect_count)
return; return;
...@@ -408,8 +400,8 @@ void GraphicsContext::DrawFocusRingInternal(const Vector<IntRect>& rects, ...@@ -408,8 +400,8 @@ void GraphicsContext::DrawFocusRingInternal(const Vector<IntRect>& rects,
if (!::features::IsFormControlsRefreshEnabled()) { if (!::features::IsFormControlsRefreshEnabled()) {
// For FormControlsRefresh the offset is already adjusted by // For FormControlsRefresh the offset is already adjusted by
// GraphicsContext::DrawFocusRing. // GraphicsContext::DrawFocusRing.
offset = AdjustedFocusRingOffset(offset, /*default_offset=*/0, offset =
std::ceil(width), is_outset); AdjustedFocusRingOffset(offset, /*default_offset=*/0, std::ceil(width));
} }
for (unsigned i = 0; i < rect_count; i++) { for (unsigned i = 0; i < rect_count; i++) {
SkIRect r = rects[i]; SkIRect r = rects[i];
...@@ -432,38 +424,19 @@ void GraphicsContext::DrawFocusRingInternal(const Vector<IntRect>& rects, ...@@ -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, void GraphicsContext::DrawFocusRing(const Vector<IntRect>& rects,
float width, float width,
int offset, int offset,
int default_offset, int default_offset,
float border_radius, float border_radius,
float min_border_width, float min_border_width,
const Color& color, const Color& color) {
bool is_outset) {
if (::features::IsFormControlsRefreshEnabled()) { if (::features::IsFormControlsRefreshEnabled()) {
// The focus ring is made of two borders which have a 2:1 ratio. // The focus ring is made of two borders which have a 2:1 ratio.
const float first_border_width = (width / 3) * 2; const float first_border_width = (width / 3) * 2;
const float second_border_width = width - first_border_width; const float second_border_width = width - first_border_width;
offset = AdjustedFocusRingOffset(offset, default_offset, std::ceil(width), offset = AdjustedFocusRingOffset(offset, default_offset, std::ceil(width));
is_outset);
// How much space the focus ring would like to take from the actual border. // How much space the focus ring would like to take from the actual border.
const float inside_border_width = 1; const float inside_border_width = 1;
if (min_border_width >= inside_border_width) { if (min_border_width >= inside_border_width) {
...@@ -473,27 +446,11 @@ void GraphicsContext::DrawFocusRing(const Vector<IntRect>& rects, ...@@ -473,27 +446,11 @@ void GraphicsContext::DrawFocusRing(const Vector<IntRect>& rects,
// artifacts. // artifacts.
DrawFocusRingInternal(rects, first_border_width, DrawFocusRingInternal(rects, first_border_width,
offset + std::ceil(second_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, DrawFocusRingInternal(rects, first_border_width, offset, border_radius,
color, is_outset); color);
} else { } else {
// If a focus ring is outset and the color is dark, it may be hard to see on DrawFocusRingInternal(rects, width, offset, border_radius, color);
// 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);
}
} }
} }
......
...@@ -365,8 +365,7 @@ class PLATFORM_EXPORT GraphicsContext { ...@@ -365,8 +365,7 @@ class PLATFORM_EXPORT GraphicsContext {
int default_offset, int default_offset,
float border_radius, float border_radius,
float min_border_width, float min_border_width,
const Color&, const Color&);
bool is_outset);
void DrawFocusRing(const Path&, float width, int offset, const Color&); void DrawFocusRing(const Path&, float width, int offset, const Color&);
enum Edge { enum Edge {
...@@ -422,10 +421,7 @@ class PLATFORM_EXPORT GraphicsContext { ...@@ -422,10 +421,7 @@ class PLATFORM_EXPORT GraphicsContext {
FloatPoint& p2, FloatPoint& p2,
float stroke_width); float stroke_width);
static int FocusRingOutsetExtent(int offset, static int FocusRingOutsetExtent(int offset, int default_offset, int width);
int default_offset,
int width,
bool is_outset);
void SetInDrawingRecorder(bool); void SetInDrawingRecorder(bool);
bool InDrawingRecorder() const { return in_drawing_recorder_; } bool InDrawingRecorder() const { return in_drawing_recorder_; }
...@@ -480,8 +476,7 @@ class PLATFORM_EXPORT GraphicsContext { ...@@ -480,8 +476,7 @@ class PLATFORM_EXPORT GraphicsContext {
float width, float width,
int offset, int offset,
float border_radius, float border_radius,
const Color&, const Color&);
bool is_outset);
// SkCanvas wrappers. // SkCanvas wrappers.
void ClipRRect(const SkRRect&, 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