layout/mathml/nsMathMLmfracFrame.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/mathml/nsMathMLmfracFrame.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,590 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +
    1.10 +#include "nsMathMLmfracFrame.h"
    1.11 +#include "nsPresContext.h"
    1.12 +#include "nsRenderingContext.h"
    1.13 +#include "nsDisplayList.h"
    1.14 +#include "gfxContext.h"
    1.15 +#include "nsMathMLElement.h"
    1.16 +#include <algorithm>
    1.17 +
    1.18 +//
    1.19 +// <mfrac> -- form a fraction from two subexpressions - implementation
    1.20 +//
    1.21 +
    1.22 +// various fraction line thicknesses (multiplicative values of the default rule thickness)
    1.23 +
    1.24 +#define THIN_FRACTION_LINE                   0.5f
    1.25 +#define THIN_FRACTION_LINE_MINIMUM_PIXELS    1  // minimum of 1 pixel
    1.26 +
    1.27 +#define THICK_FRACTION_LINE                  2.0f
    1.28 +#define THICK_FRACTION_LINE_MINIMUM_PIXELS   2  // minimum of 2 pixels
    1.29 +
    1.30 +nsIFrame*
    1.31 +NS_NewMathMLmfracFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
    1.32 +{
    1.33 +  return new (aPresShell) nsMathMLmfracFrame(aContext);
    1.34 +}
    1.35 +
    1.36 +NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmfracFrame)
    1.37 +
    1.38 +nsMathMLmfracFrame::~nsMathMLmfracFrame()
    1.39 +{
    1.40 +}
    1.41 +
    1.42 +eMathMLFrameType
    1.43 +nsMathMLmfracFrame::GetMathMLFrameType()
    1.44 +{
    1.45 +  // frac is "inner" in TeXBook, Appendix G, rule 15e. See also page 170.
    1.46 +  return eMathMLFrameType_Inner;
    1.47 +}
    1.48 +
    1.49 +uint8_t
    1.50 +nsMathMLmfracFrame::ScriptIncrement(nsIFrame* aFrame)
    1.51 +{
    1.52 +  if (!StyleFont()->mMathDisplay &&
    1.53 +      aFrame && (mFrames.FirstChild() == aFrame ||
    1.54 +                 mFrames.LastChild() == aFrame)) {
    1.55 +    return 1;
    1.56 +  }
    1.57 +  return 0;
    1.58 +}
    1.59 +
    1.60 +NS_IMETHODIMP
    1.61 +nsMathMLmfracFrame::TransmitAutomaticData()
    1.62 +{
    1.63 +  // The TeXbook (Ch 17. p.141) says the numerator inherits the compression
    1.64 +  //  while the denominator is compressed
    1.65 +  UpdatePresentationDataFromChildAt(1,  1,
    1.66 +     NS_MATHML_COMPRESSED,
    1.67 +     NS_MATHML_COMPRESSED);
    1.68 +
    1.69 +  // If displaystyle is false, then scriptlevel is incremented, so notify the
    1.70 +  // children of this.
    1.71 +  if (!StyleFont()->mMathDisplay) {
    1.72 +    PropagateFrameFlagFor(mFrames.FirstChild(),
    1.73 +                          NS_FRAME_MATHML_SCRIPT_DESCENDANT);
    1.74 +    PropagateFrameFlagFor(mFrames.LastChild(),
    1.75 +                          NS_FRAME_MATHML_SCRIPT_DESCENDANT);
    1.76 +  }
    1.77 +
    1.78 +  // if our numerator is an embellished operator, let its state bubble to us
    1.79 +  GetEmbellishDataFrom(mFrames.FirstChild(), mEmbellishData);
    1.80 +  if (NS_MATHML_IS_EMBELLISH_OPERATOR(mEmbellishData.flags)) {
    1.81 +    // even when embellished, we need to record that <mfrac> won't fire
    1.82 +    // Stretch() on its embellished child
    1.83 +    mEmbellishData.direction = NS_STRETCH_DIRECTION_UNSUPPORTED;
    1.84 +  }
    1.85 +
    1.86 +  return NS_OK;
    1.87 +}
    1.88 +
    1.89 +nscoord 
    1.90 +nsMathMLmfracFrame::CalcLineThickness(nsPresContext*  aPresContext,
    1.91 +                                      nsStyleContext*  aStyleContext,
    1.92 +                                      nsString&        aThicknessAttribute,
    1.93 +                                      nscoord          onePixel,
    1.94 +                                      nscoord          aDefaultRuleThickness)
    1.95 +{
    1.96 +  nscoord defaultThickness = aDefaultRuleThickness;
    1.97 +  nscoord lineThickness = aDefaultRuleThickness;
    1.98 +  nscoord minimumThickness = onePixel;
    1.99 +
   1.100 +  // linethickness
   1.101 +  //
   1.102 +  // "Specifies the thickness of the horizontal 'fraction bar', or 'rule'. The
   1.103 +  // default value is 'medium', 'thin' is thinner, but visible, 'thick' is
   1.104 +  // thicker; the exact thickness of these is left up to the rendering agent."
   1.105 +  //
   1.106 +  // values: length | "thin" | "medium" | "thick"
   1.107 +  // default: medium
   1.108 +  //
   1.109 +  if (!aThicknessAttribute.IsEmpty()) {
   1.110 +    if (aThicknessAttribute.EqualsLiteral("thin")) {
   1.111 +      lineThickness = NSToCoordFloor(defaultThickness * THIN_FRACTION_LINE);
   1.112 +      minimumThickness = onePixel * THIN_FRACTION_LINE_MINIMUM_PIXELS;
   1.113 +      // should visually decrease by at least one pixel, if default is not a pixel
   1.114 +      if (defaultThickness > onePixel && lineThickness > defaultThickness - onePixel)
   1.115 +        lineThickness = defaultThickness - onePixel;
   1.116 +    }
   1.117 +    else if (aThicknessAttribute.EqualsLiteral("medium")) {
   1.118 +      // medium is default
   1.119 +    }
   1.120 +    else if (aThicknessAttribute.EqualsLiteral("thick")) {
   1.121 +      lineThickness = NSToCoordCeil(defaultThickness * THICK_FRACTION_LINE);
   1.122 +      minimumThickness = onePixel * THICK_FRACTION_LINE_MINIMUM_PIXELS;
   1.123 +      // should visually increase by at least one pixel
   1.124 +      if (lineThickness < defaultThickness + onePixel)
   1.125 +        lineThickness = defaultThickness + onePixel;
   1.126 +    }
   1.127 +    else {
   1.128 +      // length value
   1.129 +      lineThickness = defaultThickness;
   1.130 +      ParseNumericValue(aThicknessAttribute, &lineThickness,
   1.131 +                        nsMathMLElement::PARSE_ALLOW_UNITLESS,
   1.132 +                        aPresContext, aStyleContext);
   1.133 +    }
   1.134 +  }
   1.135 +
   1.136 +  // use minimum if the lineThickness is a non-zero value less than minimun
   1.137 +  if (lineThickness && lineThickness < minimumThickness) 
   1.138 +    lineThickness = minimumThickness;
   1.139 +
   1.140 +  return lineThickness;
   1.141 +}
   1.142 +
   1.143 +void
   1.144 +nsMathMLmfracFrame::BuildDisplayList(nsDisplayListBuilder*   aBuilder,
   1.145 +                                     const nsRect&           aDirtyRect,
   1.146 +                                     const nsDisplayListSet& aLists)
   1.147 +{
   1.148 +  /////////////
   1.149 +  // paint the numerator and denominator
   1.150 +  nsMathMLContainerFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists);
   1.151 +  
   1.152 +  /////////////
   1.153 +  // paint the fraction line
   1.154 +  if (mIsBevelled) {
   1.155 +    DisplaySlash(aBuilder, this, mLineRect, mLineThickness, aLists);
   1.156 +  } else {
   1.157 +    DisplayBar(aBuilder, this, mLineRect, aLists);
   1.158 +  }
   1.159 +}
   1.160 +
   1.161 +/* virtual */ nsresult
   1.162 +nsMathMLmfracFrame::MeasureForWidth(nsRenderingContext& aRenderingContext,
   1.163 +                                    nsHTMLReflowMetrics& aDesiredSize)
   1.164 +{
   1.165 +  return PlaceInternal(aRenderingContext,
   1.166 +                       false,
   1.167 +                       aDesiredSize,
   1.168 +                       true);
   1.169 +}
   1.170 +
   1.171 +nscoord
   1.172 +nsMathMLmfracFrame::FixInterFrameSpacing(nsHTMLReflowMetrics& aDesiredSize)
   1.173 +{
   1.174 +  nscoord gap = nsMathMLContainerFrame::FixInterFrameSpacing(aDesiredSize);
   1.175 +  if (!gap) return 0;
   1.176 +
   1.177 +  mLineRect.MoveBy(gap, 0);
   1.178 +  return gap;
   1.179 +}
   1.180 +
   1.181 +/* virtual */ nsresult
   1.182 +nsMathMLmfracFrame::Place(nsRenderingContext& aRenderingContext,
   1.183 +                          bool                 aPlaceOrigin,
   1.184 +                          nsHTMLReflowMetrics& aDesiredSize)
   1.185 +{
   1.186 +  return PlaceInternal(aRenderingContext,
   1.187 +                       aPlaceOrigin,
   1.188 +                       aDesiredSize,
   1.189 +                       false);
   1.190 +}
   1.191 +
   1.192 +nsresult
   1.193 +nsMathMLmfracFrame::PlaceInternal(nsRenderingContext& aRenderingContext,
   1.194 +                                  bool                 aPlaceOrigin,
   1.195 +                                  nsHTMLReflowMetrics& aDesiredSize,
   1.196 +                                  bool                 aWidthOnly)
   1.197 +{
   1.198 +  ////////////////////////////////////
   1.199 +  // Get the children's desired sizes
   1.200 +  nsBoundingMetrics bmNum, bmDen;
   1.201 +  nsHTMLReflowMetrics sizeNum(aDesiredSize.GetWritingMode());
   1.202 +  nsHTMLReflowMetrics sizeDen(aDesiredSize.GetWritingMode());
   1.203 +  nsIFrame* frameDen = nullptr;
   1.204 +  nsIFrame* frameNum = mFrames.FirstChild();
   1.205 +  if (frameNum) 
   1.206 +    frameDen = frameNum->GetNextSibling();
   1.207 +  if (!frameNum || !frameDen || frameDen->GetNextSibling()) {
   1.208 +    // report an error, encourage people to get their markups in order
   1.209 +    if (aPlaceOrigin) {
   1.210 +      ReportChildCountError();
   1.211 +    }
   1.212 +    return ReflowError(aRenderingContext, aDesiredSize);
   1.213 +  }
   1.214 +  GetReflowAndBoundingMetricsFor(frameNum, sizeNum, bmNum);
   1.215 +  GetReflowAndBoundingMetricsFor(frameDen, sizeDen, bmDen);
   1.216 +
   1.217 +  nsPresContext* presContext = PresContext();
   1.218 +  nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
   1.219 +
   1.220 +  nsRefPtr<nsFontMetrics> fm;
   1.221 +  nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm));
   1.222 +  aRenderingContext.SetFont(fm);
   1.223 +
   1.224 +  nscoord defaultRuleThickness, axisHeight;
   1.225 +  GetRuleThickness(aRenderingContext, fm, defaultRuleThickness);
   1.226 +  GetAxisHeight(aRenderingContext, fm, axisHeight);
   1.227 +
   1.228 +  bool outermostEmbellished = false;
   1.229 +  if (mEmbellishData.coreFrame) {
   1.230 +    nsEmbellishData parentData;
   1.231 +    GetEmbellishDataFrom(mParent, parentData);
   1.232 +    outermostEmbellished = parentData.coreFrame != mEmbellishData.coreFrame;
   1.233 +  }
   1.234 +
   1.235 +  // see if the linethickness attribute is there 
   1.236 +  nsAutoString value;
   1.237 +  mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::linethickness_, value);
   1.238 +  mLineThickness = CalcLineThickness(presContext, mStyleContext, value,
   1.239 +                                     onePixel, defaultRuleThickness);
   1.240 +
   1.241 +  // bevelled attribute
   1.242 +  mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::bevelled_, value);
   1.243 +  mIsBevelled = value.EqualsLiteral("true");
   1.244 +
   1.245 +  if (!mIsBevelled) {
   1.246 +    mLineRect.height = mLineThickness;
   1.247 +
   1.248 +    // by default, leave at least one-pixel padding at either end, and add
   1.249 +    // lspace & rspace that may come from <mo> if we are an outermost
   1.250 +    // embellished container (we fetch values from the core since they may use
   1.251 +    // units that depend on style data, and style changes could have occurred
   1.252 +    // in the core since our last visit there)
   1.253 +    nscoord leftSpace = onePixel;
   1.254 +    nscoord rightSpace = onePixel;
   1.255 +    if (outermostEmbellished) {
   1.256 +      nsEmbellishData coreData;
   1.257 +      GetEmbellishDataFrom(mEmbellishData.coreFrame, coreData);
   1.258 +      leftSpace += StyleVisibility()->mDirection ?
   1.259 +                     coreData.trailingSpace : coreData.leadingSpace;
   1.260 +      rightSpace += StyleVisibility()->mDirection ?
   1.261 +                      coreData.leadingSpace : coreData.trailingSpace;
   1.262 +    }
   1.263 +
   1.264 +    //////////////////
   1.265 +    // Get shifts
   1.266 +    nscoord numShift = 0;
   1.267 +    nscoord denShift = 0;
   1.268 +
   1.269 +    // Rule 15b, App. G, TeXbook
   1.270 +    nscoord numShift1, numShift2, numShift3;
   1.271 +    nscoord denShift1, denShift2;
   1.272 +
   1.273 +    GetNumeratorShifts(fm, numShift1, numShift2, numShift3);
   1.274 +    GetDenominatorShifts(fm, denShift1, denShift2);
   1.275 +    if (StyleFont()->mMathDisplay == NS_MATHML_DISPLAYSTYLE_BLOCK) {
   1.276 +      // C > T
   1.277 +      numShift = numShift1;
   1.278 +      denShift = denShift1;
   1.279 +    }
   1.280 +    else {
   1.281 +      numShift = (0 < mLineRect.height) ? numShift2 : numShift3;
   1.282 +      denShift = denShift2;
   1.283 +    }
   1.284 +
   1.285 +    nscoord minClearance = 0;
   1.286 +    nscoord actualClearance = 0;
   1.287 +
   1.288 +    nscoord actualRuleThickness =  mLineThickness;
   1.289 +
   1.290 +    if (0 == actualRuleThickness) {
   1.291 +      // Rule 15c, App. G, TeXbook
   1.292 +
   1.293 +      // min clearance between numerator and denominator
   1.294 +      minClearance = StyleFont()->mMathDisplay == NS_MATHML_DISPLAYSTYLE_BLOCK ?
   1.295 +        7 * defaultRuleThickness : 3 * defaultRuleThickness;
   1.296 +      actualClearance =
   1.297 +        (numShift - bmNum.descent) - (bmDen.ascent - denShift);
   1.298 +      // actualClearance should be >= minClearance
   1.299 +      if (actualClearance < minClearance) {
   1.300 +        nscoord halfGap = (minClearance - actualClearance)/2;
   1.301 +        numShift += halfGap;
   1.302 +        denShift += halfGap;
   1.303 +      }
   1.304 +    }
   1.305 +    else {
   1.306 +    // Rule 15d, App. G, TeXbook
   1.307 +
   1.308 +    // min clearance between numerator or denominator and middle of bar
   1.309 +
   1.310 +    // TeX has a different interpretation of the thickness.
   1.311 +    // Try $a \above10pt b$ to see. Here is what TeX does:
   1.312 +    // minClearance = StyleFont()->mMathDisplay == NS_MATHML_DISPLAYSTYLE_BLOCK
   1.313 +    // ? 3 * actualRuleThickness : actualRuleThickness;
   1.314 + 
   1.315 +    // we slightly depart from TeX here. We use the defaultRuleThickness instead
   1.316 +    // of the value coming from the linethickness attribute, i.e., we recover what
   1.317 +    // TeX does if the user hasn't set linethickness. But when the linethickness
   1.318 +    // is set, we avoid the wide gap problem.
   1.319 +     minClearance = StyleFont()->mMathDisplay == NS_MATHML_DISPLAYSTYLE_BLOCK ?
   1.320 +      3 * defaultRuleThickness : defaultRuleThickness + onePixel;
   1.321 +
   1.322 +      // adjust numShift to maintain minClearance if needed
   1.323 +      actualClearance =
   1.324 +        (numShift - bmNum.descent) - (axisHeight + actualRuleThickness/2);
   1.325 +      if (actualClearance < minClearance) {
   1.326 +        numShift += (minClearance - actualClearance);
   1.327 +      }
   1.328 +      // adjust denShift to maintain minClearance if needed
   1.329 +      actualClearance =
   1.330 +        (axisHeight - actualRuleThickness/2) - (bmDen.ascent - denShift);
   1.331 +      if (actualClearance < minClearance) {
   1.332 +        denShift += (minClearance - actualClearance);
   1.333 +      }
   1.334 +    }
   1.335 +
   1.336 +    //////////////////
   1.337 +    // Place Children
   1.338 +
   1.339 +    // XXX Need revisiting the width. TeX uses the exact width
   1.340 +    // e.g. in $$\huge\frac{\displaystyle\int}{i}$$
   1.341 +    nscoord width = std::max(bmNum.width, bmDen.width);
   1.342 +    nscoord dxNum = leftSpace + (width - sizeNum.Width())/2;
   1.343 +    nscoord dxDen = leftSpace + (width - sizeDen.Width())/2;
   1.344 +    width += leftSpace + rightSpace;
   1.345 +
   1.346 +    // see if the numalign attribute is there 
   1.347 +    mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::numalign_, value);
   1.348 +    if (value.EqualsLiteral("left"))
   1.349 +      dxNum = leftSpace;
   1.350 +    else if (value.EqualsLiteral("right"))
   1.351 +      dxNum = width - rightSpace - sizeNum.Width();
   1.352 +
   1.353 +    // see if the denomalign attribute is there 
   1.354 +    mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::denomalign_, value);
   1.355 +    if (value.EqualsLiteral("left"))
   1.356 +      dxDen = leftSpace;
   1.357 +    else if (value.EqualsLiteral("right"))
   1.358 +      dxDen = width - rightSpace - sizeDen.Width();
   1.359 +
   1.360 +    mBoundingMetrics.rightBearing =
   1.361 +      std::max(dxNum + bmNum.rightBearing, dxDen + bmDen.rightBearing);
   1.362 +    if (mBoundingMetrics.rightBearing < width - rightSpace)
   1.363 +      mBoundingMetrics.rightBearing = width - rightSpace;
   1.364 +    mBoundingMetrics.leftBearing =
   1.365 +      std::min(dxNum + bmNum.leftBearing, dxDen + bmDen.leftBearing);
   1.366 +    if (mBoundingMetrics.leftBearing > leftSpace)
   1.367 +      mBoundingMetrics.leftBearing = leftSpace;
   1.368 +    mBoundingMetrics.ascent = bmNum.ascent + numShift;
   1.369 +    mBoundingMetrics.descent = bmDen.descent + denShift;
   1.370 +    mBoundingMetrics.width = width;
   1.371 +
   1.372 +    aDesiredSize.SetTopAscent(sizeNum.TopAscent() + numShift);
   1.373 +    aDesiredSize.Height() = aDesiredSize.TopAscent() +
   1.374 +      sizeDen.Height() - sizeDen.TopAscent() + denShift;
   1.375 +    aDesiredSize.Width() = mBoundingMetrics.width;
   1.376 +    aDesiredSize.mBoundingMetrics = mBoundingMetrics;
   1.377 +
   1.378 +    mReference.x = 0;
   1.379 +    mReference.y = aDesiredSize.TopAscent();
   1.380 +
   1.381 +    if (aPlaceOrigin) {
   1.382 +      nscoord dy;
   1.383 +      // place numerator
   1.384 +      dy = 0;
   1.385 +      FinishReflowChild(frameNum, presContext, sizeNum, nullptr, dxNum, dy, 0);
   1.386 +      // place denominator
   1.387 +      dy = aDesiredSize.Height() - sizeDen.Height();
   1.388 +      FinishReflowChild(frameDen, presContext, sizeDen, nullptr, dxDen, dy, 0);
   1.389 +      // place the fraction bar - dy is top of bar
   1.390 +      dy = aDesiredSize.TopAscent() - (axisHeight + actualRuleThickness/2);
   1.391 +      mLineRect.SetRect(leftSpace, dy, width - (leftSpace + rightSpace),
   1.392 +                        actualRuleThickness);
   1.393 +    }
   1.394 +  } else {
   1.395 +    nscoord numShift = 0.0;
   1.396 +    nscoord denShift = 0.0;
   1.397 +    nscoord padding = 3 * defaultRuleThickness;
   1.398 +    nscoord slashRatio = 3;
   1.399 +
   1.400 +    // Define the constant used in the expression of the maximum width
   1.401 +    nscoord em = fm->EmHeight();
   1.402 +    nscoord slashMaxWidthConstant = 2 * em;
   1.403 +
   1.404 +    // For large line thicknesses the minimum slash height is limited to the
   1.405 +    // largest expected height of a fraction
   1.406 +    nscoord slashMinHeight = slashRatio *
   1.407 +      std::min(2 * mLineThickness, slashMaxWidthConstant);
   1.408 +
   1.409 +    nscoord leadingSpace = padding;
   1.410 +    nscoord trailingSpace = padding;
   1.411 +    if (outermostEmbellished) {
   1.412 +      nsEmbellishData coreData;
   1.413 +      GetEmbellishDataFrom(mEmbellishData.coreFrame, coreData);
   1.414 +      leadingSpace += coreData.leadingSpace;
   1.415 +      trailingSpace += coreData.trailingSpace;
   1.416 +    }
   1.417 +    nscoord delta;
   1.418 +    
   1.419 +    //           ___________
   1.420 +    //          |           |    /
   1.421 +    //         {|-NUMERATOR-|   /
   1.422 +    //         {|___________|  S
   1.423 +    //         {               L
   1.424 +    // numShift{               A
   1.425 +    // ------------------------------------------------------- baseline
   1.426 +    //                         S   _____________ } denShift
   1.427 +    //                         H  |             |}
   1.428 +    //                        /   |-DENOMINATOR-|}
   1.429 +    //                       /    |_____________| 
   1.430 +    //
   1.431 +
   1.432 +    // first, ensure that the top of the numerator is at least as high as the
   1.433 +    // top of the denominator (and the reverse for the bottoms)
   1.434 +    delta = std::max(bmDen.ascent - bmNum.ascent,
   1.435 +                   bmNum.descent - bmDen.descent) / 2;
   1.436 +    if (delta > 0) {
   1.437 +      numShift += delta;
   1.438 +      denShift += delta;
   1.439 +    }
   1.440 +
   1.441 +    if (StyleFont()->mMathDisplay == NS_MATHML_DISPLAYSTYLE_BLOCK) {
   1.442 +      delta = std::min(bmDen.ascent + bmDen.descent,
   1.443 +                     bmNum.ascent + bmNum.descent) / 2;
   1.444 +      numShift += delta;
   1.445 +      denShift += delta;
   1.446 +    } else {
   1.447 +      nscoord xHeight = fm->XHeight();
   1.448 +      numShift += xHeight / 2;
   1.449 +      denShift += xHeight / 4;
   1.450 +    }
   1.451 +   
   1.452 +    // Set the ascent/descent of our BoundingMetrics.
   1.453 +    mBoundingMetrics.ascent = bmNum.ascent + numShift;
   1.454 +    mBoundingMetrics.descent = bmDen.descent + denShift;
   1.455 +
   1.456 +    // At this point the height of the slash is
   1.457 +    // mBoundingMetrics.ascent + mBoundingMetrics.descent
   1.458 +    // Ensure that it is greater than slashMinHeight
   1.459 +    delta = (slashMinHeight -
   1.460 +             (mBoundingMetrics.ascent + mBoundingMetrics.descent)) / 2;
   1.461 +    if (delta > 0) {
   1.462 +      mBoundingMetrics.ascent += delta;
   1.463 +      mBoundingMetrics.descent += delta;
   1.464 +    }
   1.465 +
   1.466 +    // Set the width of the slash
   1.467 +    if (aWidthOnly) {
   1.468 +      mLineRect.width = mLineThickness + slashMaxWidthConstant;
   1.469 +    } else {
   1.470 +      mLineRect.width = mLineThickness +
   1.471 +        std::min(slashMaxWidthConstant,
   1.472 +               (mBoundingMetrics.ascent + mBoundingMetrics.descent) /
   1.473 +               slashRatio);
   1.474 +    }
   1.475 +
   1.476 +    // Set horizontal bounding metrics
   1.477 +    if (StyleVisibility()->mDirection) {
   1.478 +      mBoundingMetrics.leftBearing = trailingSpace + bmDen.leftBearing;
   1.479 +      mBoundingMetrics.rightBearing = trailingSpace + bmDen.width + mLineRect.width + bmNum.rightBearing;
   1.480 +    } else {
   1.481 +      mBoundingMetrics.leftBearing = leadingSpace + bmNum.leftBearing;
   1.482 +      mBoundingMetrics.rightBearing = leadingSpace + bmNum.width + mLineRect.width + bmDen.rightBearing;
   1.483 +    }
   1.484 +    mBoundingMetrics.width =
   1.485 +      leadingSpace + bmNum.width + mLineRect.width + bmDen.width +
   1.486 +      trailingSpace;
   1.487 +
   1.488 +    // Set aDesiredSize
   1.489 +    aDesiredSize.SetTopAscent(mBoundingMetrics.ascent + padding);
   1.490 +    aDesiredSize.Height() =
   1.491 +      mBoundingMetrics.ascent + mBoundingMetrics.descent + 2 * padding;
   1.492 +    aDesiredSize.Width() = mBoundingMetrics.width;
   1.493 +    aDesiredSize.mBoundingMetrics = mBoundingMetrics;
   1.494 +
   1.495 +    mReference.x = 0;
   1.496 +    mReference.y = aDesiredSize.TopAscent();
   1.497 +    
   1.498 +    if (aPlaceOrigin) {
   1.499 +      nscoord dx, dy;
   1.500 +
   1.501 +      // place numerator
   1.502 +      dx = MirrorIfRTL(aDesiredSize.Width(), sizeNum.Width(),
   1.503 +                       leadingSpace);
   1.504 +      dy = aDesiredSize.TopAscent() - numShift - sizeNum.TopAscent();
   1.505 +      FinishReflowChild(frameNum, presContext, sizeNum, nullptr, dx, dy, 0);
   1.506 +
   1.507 +      // place the fraction bar
   1.508 +      dx = MirrorIfRTL(aDesiredSize.Width(), mLineRect.width,
   1.509 +                       leadingSpace + bmNum.width);
   1.510 +      dy = aDesiredSize.TopAscent() - mBoundingMetrics.ascent;
   1.511 +      mLineRect.SetRect(dx, dy,
   1.512 +                        mLineRect.width, aDesiredSize.Height() - 2 * padding);
   1.513 +
   1.514 +      // place denominator
   1.515 +      dx = MirrorIfRTL(aDesiredSize.Width(), sizeDen.Width(),
   1.516 +                       leadingSpace + bmNum.width + mLineRect.width);
   1.517 +      dy = aDesiredSize.TopAscent() + denShift - sizeDen.TopAscent();
   1.518 +      FinishReflowChild(frameDen, presContext, sizeDen, nullptr, dx, dy, 0);
   1.519 +    }
   1.520 +
   1.521 +  }
   1.522 +
   1.523 +  return NS_OK;
   1.524 +}
   1.525 +
   1.526 +class nsDisplayMathMLSlash : public nsDisplayItem {
   1.527 +public:
   1.528 +  nsDisplayMathMLSlash(nsDisplayListBuilder* aBuilder,
   1.529 +                       nsIFrame* aFrame, const nsRect& aRect,
   1.530 +                       nscoord aThickness, bool aRTL)
   1.531 +    : nsDisplayItem(aBuilder, aFrame), mRect(aRect), mThickness(aThickness),
   1.532 +      mRTL(aRTL) {
   1.533 +    MOZ_COUNT_CTOR(nsDisplayMathMLSlash);
   1.534 +  }
   1.535 +#ifdef NS_BUILD_REFCNT_LOGGING
   1.536 +  virtual ~nsDisplayMathMLSlash() {
   1.537 +    MOZ_COUNT_DTOR(nsDisplayMathMLSlash);
   1.538 +  }
   1.539 +#endif
   1.540 +
   1.541 +  virtual void Paint(nsDisplayListBuilder* aBuilder,
   1.542 +                     nsRenderingContext* aCtx) MOZ_OVERRIDE;
   1.543 +  NS_DISPLAY_DECL_NAME("MathMLSlash", TYPE_MATHML_SLASH)
   1.544 +
   1.545 +private:
   1.546 +  nsRect    mRect;
   1.547 +  nscoord   mThickness;
   1.548 +  bool      mRTL;
   1.549 +};
   1.550 +
   1.551 +void nsDisplayMathMLSlash::Paint(nsDisplayListBuilder* aBuilder,
   1.552 +                                 nsRenderingContext* aCtx)
   1.553 +{
   1.554 +  // get the gfxRect
   1.555 +  nsPresContext* presContext = mFrame->PresContext();
   1.556 +  gfxRect rect = presContext->AppUnitsToGfxUnits(mRect + ToReferenceFrame());
   1.557 +  
   1.558 +  // paint with the current text color
   1.559 +  aCtx->SetColor(mFrame->GetVisitedDependentColor(eCSSProperty_color));
   1.560 + 
   1.561 +  // draw the slash as a parallelogram 
   1.562 +  gfxContext *gfxCtx = aCtx->ThebesContext();
   1.563 +  gfxPoint delta = gfxPoint(presContext->AppUnitsToGfxUnits(mThickness), 0);
   1.564 +  gfxCtx->NewPath();
   1.565 +
   1.566 +  if (mRTL) {
   1.567 +    gfxCtx->MoveTo(rect.TopLeft());
   1.568 +    gfxCtx->LineTo(rect.TopLeft() + delta);
   1.569 +    gfxCtx->LineTo(rect.BottomRight());
   1.570 +    gfxCtx->LineTo(rect.BottomRight() - delta);
   1.571 +  } else {
   1.572 +    gfxCtx->MoveTo(rect.BottomLeft());
   1.573 +    gfxCtx->LineTo(rect.BottomLeft() + delta);
   1.574 +    gfxCtx->LineTo(rect.TopRight());
   1.575 +    gfxCtx->LineTo(rect.TopRight() - delta);
   1.576 +  }
   1.577 +
   1.578 +  gfxCtx->ClosePath();
   1.579 +  gfxCtx->Fill();
   1.580 +}
   1.581 +
   1.582 +void
   1.583 +nsMathMLmfracFrame::DisplaySlash(nsDisplayListBuilder* aBuilder,
   1.584 +                                 nsIFrame* aFrame, const nsRect& aRect,
   1.585 +                                 nscoord aThickness,
   1.586 +                                 const nsDisplayListSet& aLists) {
   1.587 +  if (!aFrame->StyleVisibility()->IsVisible() || aRect.IsEmpty())
   1.588 +    return;
   1.589 +
   1.590 +  aLists.Content()->AppendNewToTop(new (aBuilder)
   1.591 +    nsDisplayMathMLSlash(aBuilder, aFrame, aRect, aThickness,
   1.592 +                         StyleVisibility()->mDirection));
   1.593 +}

mercurial