Commit b1fe0528 authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

Bug 1834487 - Simplify border snapping. r=Oriol

Make the computed value of border-like properties app units (which is
effectively what happens in Gecko already), and clamp at computed value
time.

Differential Revision: https://phabricator.services.mozilla.com/D179481
parent 878a345f
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -181,36 +181,39 @@ void nsColumnSetFrame::CreateBorderRenderers(
  StyleBorderStyle ruleStyle;

  // Per spec, inset => ridge and outset => groove
  if (colStyle->mColumnRuleStyle == StyleBorderStyle::Inset)
  if (colStyle->mColumnRuleStyle == StyleBorderStyle::Inset) {
    ruleStyle = StyleBorderStyle::Ridge;
  else if (colStyle->mColumnRuleStyle == StyleBorderStyle::Outset)
  } else if (colStyle->mColumnRuleStyle == StyleBorderStyle::Outset) {
    ruleStyle = StyleBorderStyle::Groove;
  else
  } else {
    ruleStyle = colStyle->mColumnRuleStyle;
  }

  nscoord ruleWidth = colStyle->GetColumnRuleWidth();
  if (!ruleWidth) return;
  if (!ruleWidth) {
    return;
  }

  aBorderRenderers.Clear();
  nscolor ruleColor =
      GetVisitedDependentColor(&nsStyleColumn::mColumnRuleColor);

  nsPresContext* presContext = PresContext();
  nsPresContext* pc = PresContext();
  // In order to re-use a large amount of code, we treat the column rule as a
  // border. We create a new border style object and fill in all the details of
  // the column rule as the left border. PaintBorder() does all the rendering
  // for us, so we not only save an enormous amount of code but we'll support
  // all the line styles that we support on borders!
  nsStyleBorder border(*presContext->Document());
  nsStyleBorder border(*pc->Document());
  Sides skipSides;
  if (isVertical) {
    border.SetBorderWidth(eSideTop, ruleWidth);
    border.SetBorderWidth(eSideTop, ruleWidth, pc->AppUnitsPerDevPixel());
    border.SetBorderStyle(eSideTop, ruleStyle);
    border.mBorderTopColor = StyleColor::FromColor(ruleColor);
    skipSides |= mozilla::SideBits::eLeftRight;
    skipSides |= mozilla::SideBits::eBottom;
  } else {
    border.SetBorderWidth(eSideLeft, ruleWidth);
    border.SetBorderWidth(eSideLeft, ruleWidth, pc->AppUnitsPerDevPixel());
    border.SetBorderStyle(eSideLeft, ruleStyle);
    border.mBorderLeftColor = StyleColor::FromColor(ruleColor);
    skipSides |= mozilla::SideBits::eTopBottom;
@@ -235,7 +238,7 @@ void nsColumnSetFrame::CreateBorderRenderers(
        bool borderIsEmpty = false;
        Maybe<nsCSSBorderRenderer> br =
            nsCSSRendering::CreateBorderRendererWithStyleBorder(
                presContext, dt, this, aDirtyRect, aLineRect, border, Style(),
                pc, dt, this, aDirtyRect, aLineRect, border, Style(),
                &borderIsEmpty, skipSides);
        if (br.isSome()) {
          MOZ_ASSERT(!borderIsEmpty);
+4 −2
Original line number Diff line number Diff line
@@ -189,6 +189,8 @@ static void ApplyBorderToStyle(const nsMathMLmtdFrame* aFrame,
  nsTArray<int8_t>* columnLinesList =
      FindCellProperty(aFrame, ColumnLinesProperty());

  const auto a2d = aFrame->PresContext()->AppUnitsPerDevPixel();

  // We don't place a row line on top of the first row
  if (rowIndex > 0 && rowLinesList) {
    // If the row number is greater than the number of provided rowline
@@ -203,7 +205,7 @@ static void ApplyBorderToStyle(const nsMathMLmtdFrame* aFrame,
                                  static_cast<StyleBorderStyle>(
                                      rowLinesList->ElementAt(listLength - 1)));
    }
    aStyleBorder.SetBorderWidth(eSideTop, borderWidth);
    aStyleBorder.SetBorderWidth(eSideTop, borderWidth, a2d);
  }

  // We don't place a column line on the left of the first column.
@@ -220,7 +222,7 @@ static void ApplyBorderToStyle(const nsMathMLmtdFrame* aFrame,
          eSideLeft, static_cast<StyleBorderStyle>(
                         columnLinesList->ElementAt(listLength - 1)));
    }
    aStyleBorder.SetBorderWidth(eSideLeft, borderWidth);
    aStyleBorder.SetBorderWidth(eSideLeft, borderWidth, a2d);
  }
}

+9 −25
Original line number Diff line number Diff line
@@ -381,11 +381,6 @@ nsChangeHint nsStylePadding::CalcDifference(
  return hint;
}

static nscoord TwipsPerPixel(const Document& aDocument) {
  auto* pc = aDocument.GetPresContext();
  return pc ? pc->AppUnitsPerDevPixel() : mozilla::AppUnitsPerCSSPixel();
}

static inline BorderRadius ZeroBorderRadius() {
  auto zero = LengthPercentage::Zero();
  return {{{zero, zero}}, {{zero, zero}}, {{zero, zero}}, {{zero, zero}}};
@@ -409,8 +404,7 @@ nsStyleBorder::nsStyleBorder(const Document& aDocument)
      mBorderRightColor(StyleColor::CurrentColor()),
      mBorderBottomColor(StyleColor::CurrentColor()),
      mBorderLeftColor(StyleColor::CurrentColor()),
      mComputedBorder(0, 0, 0, 0),
      mTwipsPerPixel(TwipsPerPixel(aDocument)) {
      mComputedBorder(0, 0, 0, 0) {
  MOZ_COUNT_CTOR(nsStyleBorder);

  nscoord medium = kMediumBorderWidth;
@@ -435,8 +429,7 @@ nsStyleBorder::nsStyleBorder(const nsStyleBorder& aSrc)
      mBorderBottomColor(aSrc.mBorderBottomColor),
      mBorderLeftColor(aSrc.mBorderLeftColor),
      mComputedBorder(aSrc.mComputedBorder),
      mBorder(aSrc.mBorder),
      mTwipsPerPixel(aSrc.mTwipsPerPixel) {
      mBorder(aSrc.mBorder) {
  MOZ_COUNT_CTOR(nsStyleBorder);
  for (const auto side : mozilla::AllPhysicalSides()) {
    mBorderStyle[side] = aSrc.mBorderStyle[side];
@@ -481,8 +474,7 @@ nsChangeHint nsStyleBorder::CalcDifference(
  // force reflow of all descendants, but the hint would need to force
  // reflow of the frame's children (see how
  // ReflowInput::InitResizeFlags initializes the inline-resize flag).
  if (mTwipsPerPixel != aNewData.mTwipsPerPixel ||
      GetComputedBorder() != aNewData.GetComputedBorder() ||
  if (GetComputedBorder() != aNewData.GetComputedBorder() ||
      mFloatEdge != aNewData.mFloatEdge ||
      mBorderImageOutset != aNewData.mBorderImageOutset ||
      mBoxDecorationBreak != aNewData.mBoxDecorationBreak) {
@@ -557,8 +549,7 @@ nsStyleOutline::nsStyleOutline(const Document& aDocument)
      mOutlineOffset({0.0f}),
      mOutlineColor(StyleColor::CurrentColor()),
      mOutlineStyle(StyleOutlineStyle::BorderStyle(StyleBorderStyle::None)),
      mActualOutlineWidth(0),
      mTwipsPerPixel(TwipsPerPixel(aDocument)) {
      mActualOutlineWidth(0) {
  MOZ_COUNT_CTOR(nsStyleOutline);
}

@@ -567,8 +558,7 @@ nsStyleOutline::nsStyleOutline(const nsStyleOutline& aSrc)
      mOutlineOffset(aSrc.mOutlineOffset),
      mOutlineColor(aSrc.mOutlineColor),
      mOutlineStyle(aSrc.mOutlineStyle),
      mActualOutlineWidth(aSrc.mActualOutlineWidth),
      mTwipsPerPixel(aSrc.mTwipsPerPixel) {
      mActualOutlineWidth(aSrc.mActualOutlineWidth) {
  MOZ_COUNT_CTOR(nsStyleOutline);
}

@@ -592,8 +582,7 @@ nsChangeHint nsStyleOutline::CalcDifference(
  }

  if (mOutlineWidth != aNewData.mOutlineWidth ||
      mOutlineOffset != aNewData.mOutlineOffset ||
      mTwipsPerPixel != aNewData.mTwipsPerPixel) {
      mOutlineOffset != aNewData.mOutlineOffset) {
    return nsChangeHint_NeutralChange;
  }

@@ -719,8 +708,7 @@ nsStyleColumn::nsStyleColumn(const Document& aDocument)
      mColumnRuleColor(StyleColor::CurrentColor()),
      mColumnRuleStyle(StyleBorderStyle::None),
      mColumnRuleWidth(kMediumBorderWidth),
      mActualColumnRuleWidth(0),
      mTwipsPerPixel(TwipsPerPixel(aDocument)) {
      mActualColumnRuleWidth(0) {
  MOZ_COUNT_CTOR(nsStyleColumn);
}

@@ -734,8 +722,7 @@ nsStyleColumn::nsStyleColumn(const nsStyleColumn& aSource)
      mColumnFill(aSource.mColumnFill),
      mColumnSpan(aSource.mColumnSpan),
      mColumnRuleWidth(aSource.mColumnRuleWidth),
      mActualColumnRuleWidth(aSource.mActualColumnRuleWidth),
      mTwipsPerPixel(aSource.mTwipsPerPixel) {
      mActualColumnRuleWidth(aSource.mActualColumnRuleWidth) {
  MOZ_COUNT_CTOR(nsStyleColumn);
}

@@ -762,10 +749,7 @@ nsChangeHint nsStyleColumn::CalcDifference(
    return NS_STYLE_HINT_VISUAL;
  }

  // XXX Is it right that we never check mTwipsPerPixel to return a
  // non-nsChangeHint_NeutralChange hint?
  if (mColumnRuleWidth != aNewData.mColumnRuleWidth ||
      mTwipsPerPixel != aNewData.mTwipsPerPixel) {
  if (mColumnRuleWidth != aNewData.mColumnRuleWidth) {
    return nsChangeHint_NeutralChange;
  }

+4 −7
Original line number Diff line number Diff line
@@ -469,9 +469,10 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleBorder {
  }

  // aBorderWidth is in twips
  void SetBorderWidth(mozilla::Side aSide, nscoord aBorderWidth) {
  void SetBorderWidth(mozilla::Side aSide, nscoord aBorderWidth,
                      nscoord aAppUnitsPerDevPixel) {
    nscoord roundedWidth =
        NS_ROUND_BORDER_TO_PIXELS(aBorderWidth, mTwipsPerPixel);
        NS_ROUND_BORDER_TO_PIXELS(aBorderWidth, aAppUnitsPerDevPixel);
    mBorder.Side(aSide) = roundedWidth;
    if (HasVisibleStyle(aSide)) {
      mComputedBorder.Side(aSide) = roundedWidth;
@@ -609,8 +610,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleBorder {
  nsMargin mBorder;

 private:
  nscoord mTwipsPerPixel;

  nsStyleBorder& operator=(const nsStyleBorder& aOther) = delete;
};

@@ -652,7 +651,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleOutline {
  // length, forced to zero when outline-style is none) rounded to device
  // pixels.  This is the value used by layout.
  nscoord mActualOutlineWidth;
  nscoord mTwipsPerPixel;
};

struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleList {
@@ -928,7 +926,7 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleText {
  mozilla::StyleTextDecorationSkipInk mTextDecorationSkipInk;
  mozilla::StyleTextUnderlinePosition mTextUnderlinePosition;

  nscoord mWebkitTextStrokeWidth;  // coord
  mozilla::StyleAu mWebkitTextStrokeWidth;

  mozilla::StyleArcSlice<mozilla::StyleSimpleShadow> mTextShadow;
  mozilla::StyleTextEmphasisStyle mTextEmphasisStyle;
@@ -2010,7 +2008,6 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleColumn {
  // length, forced to zero when column-rule-style is none) rounded to device
  // pixels.  This is the value used by layout.
  nscoord mActualColumnRuleWidth;
  nscoord mTwipsPerPixel;
};

struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleSVG {
+2 −1
Original line number Diff line number Diff line
@@ -988,8 +988,9 @@ ImgDrawResult nsBCTableCellFrame::PaintBackground(gfxContext& aRenderingContext,

  nsStyleBorder myBorder(*StyleBorder());

  const auto a2d = PresContext()->AppUnitsPerDevPixel();
  for (const auto side : mozilla::AllPhysicalSides()) {
    myBorder.SetBorderWidth(side, borderWidth.Side(side));
    myBorder.SetBorderWidth(side, borderWidth.Side(side), a2d);
  }

  // bypassing nsCSSRendering::PaintBackground is safe because this kind
Loading