Skip to content

Commit

Permalink
blink::Color: Make constant colors be be Color instead of RGBA32
Browse files Browse the repository at this point in the history
The types blink::Color and RGBA32 and SkColor are used somewhat
interchangeably, because of a non-explicit constructor of blink::Color
from RGBA32.  This is towards making this constructor be explicit.

Most uses of this constructor are for color constants. Change the
constants to be of type blink::Color, so that their use does not
require the non-explicit constructor. Where an RGBA32 is desired, use
the Rgb method.

Bug: 1351544
Change-Id: I275c2181834af4db8d46ff8f2d45a098505eb3de
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3819711
Commit-Queue: ccameron chromium <ccameron@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Reviewed-by: Aaron Krajeski <aaronhk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1033495}
  • Loading branch information
ccameron-chromium authored and Chromium LUCI CQ committed Aug 10, 2022
1 parent 7768436 commit 2c40e70
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1741,7 +1741,7 @@ CSSValue* ConsumeColor(CSSParserTokenRange& range,
CSSIdentifierValue* color = ConsumeIdent(range);
return color;
}
RGBA32 color = Color::kTransparent;
RGBA32 color = Color::kTransparent.Rgb();
if (!ParseHexColor(range, color, accept_quirky_colors) &&
!ParseColorFunction(range, context, color)) {
return ConsumeInternalLightDark(ConsumeColor, range, context,
Expand Down
2 changes: 1 addition & 1 deletion third_party/blink/renderer/core/frame/local_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2294,7 +2294,7 @@ void LocalFrame::UpdateAdHighlight() {
if (IsAdRoot() && GetPage()->GetSettings().GetHighlightAds())
SetSubframeColorOverlay(SkColorSetARGB(128, 255, 0, 0));
else
SetSubframeColorOverlay(Color::kTransparent);
SetSubframeColorOverlay(SK_ColorTRANSPARENT);
}

void LocalFrame::PauseSubresourceLoading(
Expand Down
2 changes: 1 addition & 1 deletion third_party/blink/renderer/core/html/html_element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,7 @@ static RGBA32 ParseColorStringWithCrazyLegacyRules(const String& color_string) {
}

if (!digit_buffer.size())
return Color::kBlack;
return Color::kBlack.Rgb();

// Pad the buffer out to at least the next multiple of three in size.
digit_buffer.push_back('0');
Expand Down
2 changes: 1 addition & 1 deletion third_party/blink/renderer/core/html/html_hr_element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void HTMLHRElement::CollectStyleForPresentationAttribute(
style, CSSPropertyID::kBorderStyle, CSSValueID::kSolid);

const cssvalue::CSSColor& dark_gray_value =
*cssvalue::CSSColor::Create(Color::kDarkGray);
*cssvalue::CSSColor::Create(Color::kDarkGray.Rgb());
style->SetProperty(CSSPropertyID::kBorderColor, dark_gray_value);
style->SetProperty(CSSPropertyID::kBackgroundColor, dark_gray_value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static const float kMinCancelButtonSize = 5;
static const float kMaxCancelButtonSize = 21;

Color LayoutThemeDefault::active_selection_background_color_ = 0xFF1E90FF;
Color LayoutThemeDefault::active_selection_foreground_color_ = Color::kBlack;
Color LayoutThemeDefault::active_selection_foreground_color_ = 0xFF000000;
Color LayoutThemeDefault::inactive_selection_background_color_ = 0xFFC8C8C8;
Color LayoutThemeDefault::inactive_selection_foreground_color_ = 0xFF323232;
Color
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void EmbeddedObjectPainter::PaintReplaced(const PaintInfo& paint_info,
FloatRoundedRect rounded_background_rect(
gfx::RectF(ToPixelSnappedRect(background_rect)),
kReplacementTextRoundedRectRadius);
Color color = ScaleAlpha(Color::kWhite, kReplacementTextRoundedRectOpacity);
Color color = ScaleAlpha(SK_ColorWHITE, kReplacementTextRoundedRectOpacity);
AutoDarkMode auto_dark_mode(
PaintAutoDarkMode(layout_embedded_object_.StyleRef(),
DarkModeFilter::ElementRole::kBackground));
Expand All @@ -86,7 +86,7 @@ void EmbeddedObjectPainter::PaintReplaced(const PaintInfo& paint_info,
text_rect.Offset(gfx::PointF(content_rect.Center()) -
text_rect.CenterPoint());
TextRunPaintInfo run_info(text_run);
context.SetFillColor(ScaleAlpha(Color::kBlack, kReplacementTextTextOpacity));
context.SetFillColor(ScaleAlpha(SK_ColorBLACK, kReplacementTextTextOpacity));
context.DrawBidiText(
font, run_info,
text_rect.origin() +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ bool ThemePainterDefault::PaintMenuListButton(const Element& element,
WebThemeEngine::ExtraParams extra_params;
extra_params.menu_list.has_border = false;
extra_params.menu_list.has_border_radius = style.HasBorderRadius();
extra_params.menu_list.background_color = Color::kTransparent;
extra_params.menu_list.background_color = SK_ColorTRANSPARENT;
extra_params.menu_list.fill_content_area = false;
SetupMenuListArrow(document, style, rect, extra_params);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class AXInlineTextBox final : public AXObject {
AXInlineTextBox& operator=(const AXInlineTextBox&) = delete;

// AXObject overrides.
RGBA32 GetColor() const override { return Color::kTransparent; }
RGBA32 GetColor() const override { return Color::kTransparent.Rgb(); }
String GetName(ax::mojom::blink::NameFrom&,
AXObject::AXObjectVector* name_objects) const override;
void TextCharacterOffsets(Vector<int>&) const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2522,19 +2522,19 @@ RGBA32 AXNodeObject::ColorValue() const {
RGBA32 AXNodeObject::BackgroundColor() const {
LayoutObject* layout_object = GetLayoutObject();
if (!layout_object)
return Color::kTransparent;
return Color::kTransparent.Rgb();

if (IsWebArea()) {
LocalFrameView* view = DocumentFrameView();
if (view)
return view->BaseBackgroundColor().Rgb();
else
return Color::kWhite;
return Color::kWhite.Rgb();
}

const ComputedStyle* style = layout_object->Style();
if (!style || !style->HasBackground())
return Color::kTransparent;
return Color::kTransparent.Rgb();

return style->VisitedDependentColor(GetCSSPropertyBackgroundColor()).Rgb();
}
Expand Down
6 changes: 3 additions & 3 deletions third_party/blink/renderer/modules/accessibility/ax_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,10 @@ class MODULES_EXPORT AXObject : public GarbageCollected<AXObject> {
//

virtual const AtomicString& AccessKey() const { return g_null_atom; }
virtual RGBA32 BackgroundColor() const { return Color::kTransparent; }
virtual RGBA32 GetColor() const { return Color::kBlack; }
virtual RGBA32 BackgroundColor() const { return Color::kTransparent.Rgb(); }
virtual RGBA32 GetColor() const { return Color::kBlack.Rgb(); }
// Used by objects of role ColorWellRole.
virtual RGBA32 ColorValue() const { return Color::kTransparent; }
virtual RGBA32 ColorValue() const { return Color::kTransparent.Rgb(); }
virtual bool CanvasHasFallbackContent() const { return false; }
// Returns the font family that was cascaded onto ComputedStyle. This may
// contain non-user-friendly internal names.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void BaseRenderingContext2D::beginLayer() {
setShadowOffsetX(0);
setShadowOffsetY(0);
setShadowBlur(0);
GetState().SetShadowColor(Color::kTransparent);
GetState().SetShadowColor(SK_ColorTRANSPARENT);
DCHECK(!GetState().ShouldDrawShadows());
setGlobalAlpha(1.0);
setGlobalCompositeOperation("source-over");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ RGBA32 CanvasStyle::PaintColor() const {
if (type_ == kColorRGBA)
return rgba_;
DCHECK(type_ == kGradient || type_ == kImagePattern);
return Color::kBlack;
return Color::kBlack.Rgb();
}

void CanvasStyle::Trace(Visitor* visitor) const {
Expand Down
17 changes: 6 additions & 11 deletions third_party/blink/renderer/platform/graphics/color.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,12 @@

namespace blink {

// VS 2015 and above allow these definitions and in this case require them
#if !defined(COMPILER_MSVC) || _MSC_VER >= 1900
// FIXME: Use C++11 enum classes to avoid static data member initializer
// definition problems.
const RGBA32 Color::kBlack;
const RGBA32 Color::kWhite;
const RGBA32 Color::kDarkGray;
const RGBA32 Color::kGray;
const RGBA32 Color::kLightGray;
const RGBA32 Color::kTransparent;
#endif
const Color Color::kBlack = Color(0xFF000000);
const Color Color::kWhite = Color(0xFFFFFFFF);
const Color Color::kDarkGray = Color(0xFF808080);
const Color Color::kGray = Color(0xFFA0A0A0);
const Color Color::kLightGray = Color(0xFFC0C0C0);
const Color Color::kTransparent = Color(0x00000000);

namespace {

Expand Down
14 changes: 7 additions & 7 deletions third_party/blink/renderer/platform/graphics/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class PLATFORM_EXPORT Color {
DISALLOW_NEW();

public:
constexpr Color() : color_(Color::kTransparent) {}
constexpr Color() : color_(0) {}
constexpr Color(RGBA32 color) : color_(color) {}
Color(int r, int g, int b) : color_(MakeRGB(r, g, b)) {}
Color(int r, int g, int b, int a) : color_(MakeRGBA(r, g, b, a)) {}
Expand Down Expand Up @@ -146,12 +146,12 @@ class PLATFORM_EXPORT Color {
static bool ParseHexColor(const LChar*, unsigned, RGBA32&);
static bool ParseHexColor(const UChar*, unsigned, RGBA32&);

static const RGBA32 kBlack = 0xFF000000;
static const RGBA32 kWhite = 0xFFFFFFFF;
static const RGBA32 kDarkGray = 0xFF808080;
static const RGBA32 kGray = 0xFFA0A0A0;
static const RGBA32 kLightGray = 0xFFC0C0C0;
static const RGBA32 kTransparent = 0x00000000;
static const Color kBlack;
static const Color kWhite;
static const Color kDarkGray;
static const Color kGray;
static const Color kLightGray;
static const Color kTransparent;

private:
void GetHueMaxMin(double&, double&, double&) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void PaintChunker::ResetChunks(Vector<PaintChunk>* chunks) {
bool PaintChunker::IsInInitialState() const {
if (current_properties_ != PropertyTreeState::Uninitialized())
return false;
DCHECK_EQ(candidate_background_color_.Rgb(), Color::kTransparent);
DCHECK(candidate_background_color_ == Color::kTransparent);
DCHECK_EQ(candidate_background_area_, 0u);
DCHECK(will_force_new_chunk_);
DCHECK(!chunks_ || chunks_->IsEmpty());
Expand Down
85 changes: 37 additions & 48 deletions third_party/blink/renderer/platform/mac/color_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -37,57 +37,46 @@

NSColor* NsColor(const Color& color) {
RGBA32 c = color.Rgb();
switch (c) {
case 0: {
// Need this to avoid returning nil because cachedRGBAValues will default
// to 0.
DEFINE_STATIC_LOCAL(base::scoped_nsobject<NSColor>, clear_color,
([[NSColor colorWithDeviceRed:0
green:0
blue:0
alpha:0] retain]));
return clear_color;
}
case Color::kBlack: {
DEFINE_STATIC_LOCAL(base::scoped_nsobject<NSColor>, black_color,
([[NSColor colorWithDeviceRed:0
green:0
blue:0
alpha:1] retain]));
return black_color;
}
case Color::kWhite: {
DEFINE_STATIC_LOCAL(base::scoped_nsobject<NSColor>, white_color,
([[NSColor colorWithDeviceRed:1
green:1
blue:1
alpha:1] retain]));
return white_color;
}
default: {
const int kCacheSize = 32;
static unsigned cached_rgba_values[kCacheSize];
static base::scoped_nsobject<NSColor>* cached_colors(
new base::scoped_nsobject<NSColor>[kCacheSize]);
if (c == Color::kTransparent) {
// Need this to avoid returning nil because cachedRGBAValues will default
// to 0.
DEFINE_STATIC_LOCAL(base::scoped_nsobject<NSColor>, clear_color,
([[NSColor colorWithDeviceRed:0 green:0 blue:0
alpha:0] retain]));
return clear_color;
} else if (c == Color::kBlack) {
DEFINE_STATIC_LOCAL(base::scoped_nsobject<NSColor>, black_color,
([[NSColor colorWithDeviceRed:0 green:0 blue:0
alpha:1] retain]));
return black_color;
} else if (c == Color::kWhite) {
DEFINE_STATIC_LOCAL(base::scoped_nsobject<NSColor>, white_color,
([[NSColor colorWithDeviceRed:1 green:1 blue:1
alpha:1] retain]));
return white_color;
} else {
const int kCacheSize = 32;
static unsigned cached_rgba_values[kCacheSize];
static base::scoped_nsobject<NSColor>* cached_colors(
new base::scoped_nsobject<NSColor>[kCacheSize]);

for (int i = 0; i != kCacheSize; ++i) {
if (cached_rgba_values[i] == c)
return cached_colors[i];
}
for (int i = 0; i != kCacheSize; ++i) {
if (cached_rgba_values[i] == c)
return cached_colors[i];
}

NSColor* result = [NSColor
colorWithDeviceRed:static_cast<CGFloat>(color.Red()) / 255
green:static_cast<CGFloat>(color.Green()) / 255
blue:static_cast<CGFloat>(color.Blue()) / 255
alpha:static_cast<CGFloat>(color.Alpha()) / 255];
NSColor* result =
[NSColor colorWithDeviceRed:static_cast<CGFloat>(color.Red()) / 255
green:static_cast<CGFloat>(color.Green()) / 255
blue:static_cast<CGFloat>(color.Blue()) / 255
alpha:static_cast<CGFloat>(color.Alpha()) / 255];

static int cursor;
cached_rgba_values[cursor] = c;
cached_colors[cursor].reset([result retain]);
if (++cursor == kCacheSize)
cursor = 0;
return result;
}
static int cursor;
cached_rgba_values[cursor] = c;
cached_colors[cursor].reset([result retain]);
if (++cursor == kCacheSize)
cursor = 0;
return result;
}
}

Expand Down

0 comments on commit 2c40e70

Please sign in to comment.