Skip to content

Commit

Permalink
Bug 1802799 - [refactor] Migrate NS_STYLE_TEXT_DECORATION_STYLE_* def…
Browse files Browse the repository at this point in the history
…ines r=emilio,geckoview-reviewers,ohall

Differential Revision: https://phabricator.services.mozilla.com/D163177
  • Loading branch information
ben-freist committed Dec 19, 2022
1 parent 2b840ea commit d34c322
Show file tree
Hide file tree
Showing 21 changed files with 122 additions and 116 deletions.
15 changes: 8 additions & 7 deletions accessible/base/StyleInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,22 @@ void StyleInfo::FormatColor(const nscolor& aValue, nsAString& aFormattedValue) {
aFormattedValue.Append(')');
}

already_AddRefed<nsAtom> StyleInfo::TextDecorationStyleToAtom(uint8_t aValue) {
already_AddRefed<nsAtom> StyleInfo::TextDecorationStyleToAtom(
StyleTextDecorationStyle aValue) {
// TODO: When these are enum classes that rust also understands we should just
// make an FFI call here.
switch (aValue) {
case NS_STYLE_TEXT_DECORATION_STYLE_NONE:
case StyleTextDecorationStyle::None:
return NS_Atomize("-moz-none");
case NS_STYLE_TEXT_DECORATION_STYLE_SOLID:
case StyleTextDecorationStyle::Solid:
return NS_Atomize("solid");
case NS_STYLE_TEXT_DECORATION_STYLE_DOUBLE:
case StyleTextDecorationStyle::Double:
return NS_Atomize("double");
case NS_STYLE_TEXT_DECORATION_STYLE_DOTTED:
case StyleTextDecorationStyle::Dotted:
return NS_Atomize("dotted");
case NS_STYLE_TEXT_DECORATION_STYLE_DASHED:
case StyleTextDecorationStyle::Dashed:
return NS_Atomize("dashed");
case NS_STYLE_TEXT_DECORATION_STYLE_WAVY:
case StyleTextDecorationStyle::Wavy:
return NS_Atomize("wavy");
default:
MOZ_ASSERT_UNREACHABLE("Unknown decoration style");
Expand Down
3 changes: 2 additions & 1 deletion accessible/base/StyleInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class StyleInfo {
CSSCoord MarginBottom() { return Margin(eSideBottom); }

static void FormatColor(const nscolor& aValue, nsAString& aFormattedValue);
static already_AddRefed<nsAtom> TextDecorationStyleToAtom(uint8_t aValue);
static already_AddRefed<nsAtom> TextDecorationStyleToAtom(
StyleTextDecorationStyle aValue);

private:
StyleInfo() = delete;
Expand Down
6 changes: 3 additions & 3 deletions accessible/base/TextAttrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,11 @@ class TextAttrsMgr {
TextDecorValue()
: mColor{0},
mLine{StyleTextDecorationLine::NONE},
mStyle{NS_STYLE_TEXT_DECORATION_STYLE_NONE} {}
mStyle{StyleTextDecorationStyle::None} {}
explicit TextDecorValue(nsIFrame* aFrame);

nscolor Color() const { return mColor; }
uint8_t Style() const { return mStyle; }
mozilla::StyleTextDecorationStyle Style() const { return mStyle; }

bool IsDefined() const { return IsUnderline() || IsLineThrough(); }
bool IsUnderline() const {
Expand All @@ -387,7 +387,7 @@ class TextAttrsMgr {
private:
nscolor mColor;
mozilla::StyleTextDecorationLine mLine;
uint8_t mStyle;
mozilla::StyleTextDecorationStyle mStyle;
};

class TextDecorTextAttr : public TTextAttr<TextDecorValue> {
Expand Down
2 changes: 1 addition & 1 deletion editor/docs/IMEHandlingGuide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ specified with following prefs. The values must be string of "#rrggbb" format.

Underline style can be specified with the following prefs. The values are
integer, 0: none, 1: dotted, 2: dashed, 3: solid, 4: double, 5: wavy (The
values same as ``NS_STYLE_TEXT_DECORATION_STYLE_*`` defined in
values same as ``mozilla::StyleTextDecorationStyle`` defined in
`nsStyleConsts.h <https://searchfox.org/mozilla-central/source/layout/style/nsStyleConsts.h>`__).

* ``ui.IMERawInputUnderlineStyle``
Expand Down
13 changes: 7 additions & 6 deletions layout/generic/TextDrawTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ class TextDrawTarget : public DrawTarget {
// as the top-left corner of the rect.
void AppendDecoration(const Point& aStart, const Point& aEnd,
const float aThickness, const bool aVertical,
const DeviceColor& aColor, const uint8_t aStyle) {
const DeviceColor& aColor,
const StyleTextDecorationStyle aStyle) {
auto pos = LayoutDevicePoint::FromUnknownPoint(aStart);
LayoutDeviceSize size;

Expand All @@ -281,19 +282,19 @@ class TextDrawTarget : public DrawTarget {
: wr::LineOrientation::Horizontal;

switch (aStyle) {
case NS_STYLE_TEXT_DECORATION_STYLE_SOLID:
case StyleTextDecorationStyle::Solid:
decoration.style = wr::LineStyle::Solid;
break;
case NS_STYLE_TEXT_DECORATION_STYLE_DOTTED:
case StyleTextDecorationStyle::Dotted:
decoration.style = wr::LineStyle::Dotted;
break;
case NS_STYLE_TEXT_DECORATION_STYLE_DASHED:
case StyleTextDecorationStyle::Dashed:
decoration.style = wr::LineStyle::Dashed;
break;
// Wavy lines should go through AppendWavyDecoration
case NS_STYLE_TEXT_DECORATION_STYLE_WAVY:
case StyleTextDecorationStyle::Wavy:
// Double lines should be lowered to two solid lines
case NS_STYLE_TEXT_DECORATION_STYLE_DOUBLE:
case StyleTextDecorationStyle::Double:
default:
MOZ_CRASH("TextDrawTarget received unsupported line style");
}
Expand Down
63 changes: 32 additions & 31 deletions layout/generic/nsTextFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,13 @@ class nsTextPaintStyle {
nscolor* aBackColor);
// if this returns false, we don't need to draw underline.
bool GetSelectionUnderlineForPaint(int32_t aIndex, nscolor* aLineColor,
float* aRelativeSize, uint8_t* aStyle);
float* aRelativeSize,
StyleTextDecorationStyle* aStyle);

// if this returns false, we don't need to draw underline.
static bool GetSelectionUnderline(nsIFrame*, int32_t aIndex,
nscolor* aLineColor, float* aRelativeSize,
uint8_t* aStyle);
StyleTextDecorationStyle* aStyle);

// if this returns false, no text-shadow was specified for the selection
// and the *aShadow parameter was not modified.
Expand Down Expand Up @@ -513,7 +514,7 @@ class nsTextPaintStyle {
nscolor mTextColor;
nscolor mBGColor;
nscolor mUnderlineColor;
uint8_t mUnderlineStyle;
StyleTextDecorationStyle mUnderlineStyle;
float mUnderlineRelativeSize;
};
nsSelectionStyle mSelectionStyle[5];
Expand Down Expand Up @@ -4170,16 +4171,15 @@ void nsTextPaintStyle::GetIMESelectionColors(int32_t aIndex,
*aBackColor = selectionStyle->mBGColor;
}

bool nsTextPaintStyle::GetSelectionUnderlineForPaint(int32_t aIndex,
nscolor* aLineColor,
float* aRelativeSize,
uint8_t* aStyle) {
bool nsTextPaintStyle::GetSelectionUnderlineForPaint(
int32_t aIndex, nscolor* aLineColor, float* aRelativeSize,
StyleTextDecorationStyle* aStyle) {
NS_ASSERTION(aLineColor, "aLineColor is null");
NS_ASSERTION(aRelativeSize, "aRelativeSize is null");
NS_ASSERTION(aIndex >= 0 && aIndex < 5, "Index out of range");

nsSelectionStyle* selectionStyle = GetSelectionStyle(aIndex);
if (selectionStyle->mUnderlineStyle == NS_STYLE_TEXT_DECORATION_STYLE_NONE ||
if (selectionStyle->mUnderlineStyle == StyleTextDecorationStyle::None ||
selectionStyle->mUnderlineColor == NS_TRANSPARENT ||
selectionStyle->mUnderlineRelativeSize <= 0.0f)
return false;
Expand Down Expand Up @@ -4375,7 +4375,7 @@ void nsTextPaintStyle::InitSelectionStyle(int32_t aIndex) {

nscolor lineColor;
float relativeSize;
uint8_t lineStyle;
StyleTextDecorationStyle lineStyle;
GetSelectionUnderline(mFrame, aIndex, &lineColor, &relativeSize, &lineStyle);

if (mResolveColors) {
Expand All @@ -4394,7 +4394,7 @@ void nsTextPaintStyle::InitSelectionStyle(int32_t aIndex) {
bool nsTextPaintStyle::GetSelectionUnderline(nsIFrame* aFrame, int32_t aIndex,
nscolor* aLineColor,
float* aRelativeSize,
uint8_t* aStyle) {
StyleTextDecorationStyle* aStyle) {
NS_ASSERTION(aFrame, "aFrame is null");
NS_ASSERTION(aRelativeSize, "aRelativeSize is null");
NS_ASSERTION(aStyle, "aStyle is null");
Expand All @@ -4403,10 +4403,11 @@ bool nsTextPaintStyle::GetSelectionUnderline(nsIFrame* aFrame, int32_t aIndex,
StyleIDs& styleID = SelectionStyleIDs[aIndex];

nscolor color = LookAndFeel::Color(styleID.mLine, aFrame);
int32_t style = LookAndFeel::GetInt(styleID.mLineStyle);
if (style > NS_STYLE_TEXT_DECORATION_STYLE_MAX) {
const int32_t lineStyle = LookAndFeel::GetInt(styleID.mLineStyle);
auto style = static_cast<StyleTextDecorationStyle>(lineStyle);
if (lineStyle > static_cast<int32_t>(StyleTextDecorationStyle::Sentinel)) {
NS_ERROR("Invalid underline style value is specified");
style = NS_STYLE_TEXT_DECORATION_STYLE_SOLID;
style = StyleTextDecorationStyle::Solid;
}
float size = LookAndFeel::GetFloat(styleID.mLineRelativeSize);

Expand All @@ -4418,8 +4419,8 @@ bool nsTextPaintStyle::GetSelectionUnderline(nsIFrame* aFrame, int32_t aIndex,
*aRelativeSize = size;
*aStyle = style;

return style != NS_STYLE_TEXT_DECORATION_STYLE_NONE &&
color != NS_TRANSPARENT && size > 0.0f;
return style != StyleTextDecorationStyle::None && color != NS_TRANSPARENT &&
size > 0.0f;
}

bool nsTextPaintStyle::GetSelectionShadow(
Expand Down Expand Up @@ -5336,7 +5337,7 @@ void nsTextFrame::GetTextDecorations(
physicalBlockStartOffset +=
vertical ? f->GetNormalPosition().x : f->GetNormalPosition().y;

const uint8_t style = styleTextReset->mTextDecorationStyle;
const auto style = styleTextReset->mTextDecorationStyle;
if (textDecorations) {
nscolor color;
if (useOverride) {
Expand Down Expand Up @@ -5675,13 +5676,13 @@ void nsTextFrame::UnionAdditionalOverflow(nsPresContext* aPresContext,
// The underline/overline drawable area must be contained in the overflow
// rect when this is in floating first letter frame at *both* modes.
// In this case, aBlock is the ::first-letter frame.
uint8_t decorationStyle =
auto decorationStyle =
aBlock->Style()->StyleTextReset()->mTextDecorationStyle;
// If the style is none, let's include decoration line rect as solid style
// since changing the style from none to solid/dotted/dashed doesn't cause
// reflow.
if (decorationStyle == NS_STYLE_TEXT_DECORATION_STYLE_NONE) {
decorationStyle = NS_STYLE_TEXT_DECORATION_STYLE_SOLID;
if (decorationStyle == StyleTextDecorationStyle::None) {
decorationStyle = StyleTextDecorationStyle::Solid;
}
nsCSSRendering::DecorationRectParams params;

Expand Down Expand Up @@ -5780,8 +5781,8 @@ void nsTextFrame::UnionAdditionalOverflow(nsPresContext* aPresContext,
// If the style is solid, let's include decoration line rect of
// solid style since changing the style from none to
// solid/dotted/dashed doesn't cause reflow.
if (params.style == NS_STYLE_TEXT_DECORATION_STYLE_NONE) {
params.style = NS_STYLE_TEXT_DECORATION_STYLE_SOLID;
if (params.style == StyleTextDecorationStyle::None) {
params.style = StyleTextDecorationStyle::Solid;
}

float inflation = GetInflationForTextDecorations(
Expand Down Expand Up @@ -5964,23 +5965,23 @@ void nsTextFrame::PaintDecorationLine(
}
}

static uint8_t ToStyleLineStyle(const TextRangeStyle& aStyle) {
static StyleTextDecorationStyle ToStyleLineStyle(const TextRangeStyle& aStyle) {
switch (aStyle.mLineStyle) {
case TextRangeStyle::LineStyle::None:
return NS_STYLE_TEXT_DECORATION_STYLE_NONE;
return StyleTextDecorationStyle::None;
case TextRangeStyle::LineStyle::Solid:
return NS_STYLE_TEXT_DECORATION_STYLE_SOLID;
return StyleTextDecorationStyle::Solid;
case TextRangeStyle::LineStyle::Dotted:
return NS_STYLE_TEXT_DECORATION_STYLE_DOTTED;
return StyleTextDecorationStyle::Dotted;
case TextRangeStyle::LineStyle::Dashed:
return NS_STYLE_TEXT_DECORATION_STYLE_DASHED;
return StyleTextDecorationStyle::Dashed;
case TextRangeStyle::LineStyle::Double:
return NS_STYLE_TEXT_DECORATION_STYLE_DOUBLE;
return StyleTextDecorationStyle::Double;
case TextRangeStyle::LineStyle::Wavy:
return NS_STYLE_TEXT_DECORATION_STYLE_WAVY;
return StyleTextDecorationStyle::Wavy;
}
MOZ_ASSERT_UNREACHABLE("Invalid line style");
return NS_STYLE_TEXT_DECORATION_STYLE_NONE;
return StyleTextDecorationStyle::None;
}

/**
Expand Down Expand Up @@ -6107,7 +6108,7 @@ void nsTextFrame::DrawSelectionDecorations(

relativeSize = 2.0f;
aTextPaintStyle.GetURLSecondaryColor(&params.color);
params.style = NS_STYLE_TEXT_DECORATION_STYLE_SOLID;
params.style = StyleTextDecorationStyle::Solid;
params.defaultLineThickness = metrics.strikeoutSize;
params.lineSize.height = ComputeDecorationLineThickness(
decThickness, params.defaultLineThickness, metrics,
Expand Down Expand Up @@ -7306,7 +7307,7 @@ void nsTextFrame::DrawTextRunAndDecorations(
auto paintDecorationLine = [&](const LineDecoration& dec,
gfxFloat Metrics::*lineSize,
StyleTextDecorationLine lineType) {
if (dec.mStyle == NS_STYLE_TEXT_DECORATION_STYLE_NONE) {
if (dec.mStyle == StyleTextDecorationStyle::None) {
return;
}

Expand Down
5 changes: 3 additions & 2 deletions layout/generic/nsTextFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ class nsTextFrame : public nsIFrame {
// thickness of the decoration line
const mozilla::StyleTextDecorationLength mTextDecorationThickness;
nscolor mColor;
uint8_t mStyle;
mozilla::StyleTextDecorationStyle mStyle;

// The text-underline-position property; affects the underline offset only
// if mTextUnderlineOffset is auto.
Expand All @@ -845,7 +845,8 @@ class nsTextFrame : public nsIFrame {
mozilla::StyleTextUnderlinePosition aUnderlinePosition,
const mozilla::LengthPercentageOrAuto& aUnderlineOffset,
const mozilla::StyleTextDecorationLength& aDecThickness,
const nscolor aColor, const uint8_t aStyle)
const nscolor aColor,
const mozilla::StyleTextDecorationStyle aStyle)
: mFrame(aFrame),
mBaselineOffset(aOff),
mTextUnderlineOffset(aUnderlineOffset),
Expand Down
Loading

0 comments on commit d34c322

Please sign in to comment.