layout/mathml/nsMathMLFrame.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/mathml/nsMathMLFrame.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,371 @@
     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 +#ifndef nsMathMLFrame_h___
    1.10 +#define nsMathMLFrame_h___
    1.11 +
    1.12 +#include "mozilla/Attributes.h"
    1.13 +#include "nsFontMetrics.h"
    1.14 +#include "nsMathMLOperators.h"
    1.15 +#include "nsIMathMLFrame.h"
    1.16 +#include "nsLayoutUtils.h"
    1.17 +#include "nsBoundingMetrics.h"
    1.18 +#include "nsIFrame.h"
    1.19 +
    1.20 +class nsMathMLChar;
    1.21 +class nsCSSValue;
    1.22 +class nsDisplayListSet;
    1.23 +
    1.24 +// Concrete base class with default methods that derived MathML frames can override
    1.25 +class nsMathMLFrame : public nsIMathMLFrame {
    1.26 +public:
    1.27 +
    1.28 +  // nsIMathMLFrame ---
    1.29 +
    1.30 +  virtual bool
    1.31 +  IsSpaceLike() MOZ_OVERRIDE {
    1.32 +    return NS_MATHML_IS_SPACE_LIKE(mPresentationData.flags);
    1.33 +  }
    1.34 +
    1.35 +  NS_IMETHOD
    1.36 +  GetBoundingMetrics(nsBoundingMetrics& aBoundingMetrics) MOZ_OVERRIDE {
    1.37 +    aBoundingMetrics = mBoundingMetrics;
    1.38 +    return NS_OK;
    1.39 +  }
    1.40 +
    1.41 +  NS_IMETHOD
    1.42 +  SetBoundingMetrics(const nsBoundingMetrics& aBoundingMetrics) MOZ_OVERRIDE {
    1.43 +    mBoundingMetrics = aBoundingMetrics;
    1.44 +    return NS_OK;
    1.45 +  }
    1.46 +
    1.47 +  NS_IMETHOD
    1.48 +  SetReference(const nsPoint& aReference) MOZ_OVERRIDE {
    1.49 +    mReference = aReference;
    1.50 +    return NS_OK;
    1.51 +  }
    1.52 +
    1.53 +  virtual eMathMLFrameType GetMathMLFrameType() MOZ_OVERRIDE;
    1.54 +
    1.55 +  NS_IMETHOD
    1.56 +  Stretch(nsRenderingContext& aRenderingContext,
    1.57 +          nsStretchDirection   aStretchDirection,
    1.58 +          nsBoundingMetrics&   aContainerSize,
    1.59 +          nsHTMLReflowMetrics& aDesiredStretchSize) MOZ_OVERRIDE
    1.60 +  {
    1.61 +    return NS_OK;
    1.62 +  }
    1.63 +
    1.64 +  NS_IMETHOD
    1.65 +  GetEmbellishData(nsEmbellishData& aEmbellishData) MOZ_OVERRIDE {
    1.66 +    aEmbellishData = mEmbellishData;
    1.67 +    return NS_OK;
    1.68 +  }
    1.69 +
    1.70 +  NS_IMETHOD
    1.71 +  GetPresentationData(nsPresentationData& aPresentationData) MOZ_OVERRIDE {
    1.72 +    aPresentationData = mPresentationData;
    1.73 +    return NS_OK;
    1.74 +  }
    1.75 +
    1.76 +  NS_IMETHOD
    1.77 +  InheritAutomaticData(nsIFrame* aParent) MOZ_OVERRIDE;
    1.78 +
    1.79 +  NS_IMETHOD
    1.80 +  TransmitAutomaticData() MOZ_OVERRIDE
    1.81 +  {
    1.82 +    return NS_OK;
    1.83 +  }
    1.84 +
    1.85 +  NS_IMETHOD
    1.86 +  UpdatePresentationData(uint32_t        aFlagsValues,
    1.87 +                         uint32_t        aFlagsToUpdate) MOZ_OVERRIDE;
    1.88 +
    1.89 +  NS_IMETHOD
    1.90 +  UpdatePresentationDataFromChildAt(int32_t         aFirstIndex,
    1.91 +                                    int32_t         aLastIndex,
    1.92 +                                    uint32_t        aFlagsValues,
    1.93 +                                    uint32_t        aFlagsToUpdate) MOZ_OVERRIDE
    1.94 +  {
    1.95 +    return NS_OK;
    1.96 +  }
    1.97 +
    1.98 +  uint8_t
    1.99 +  ScriptIncrement(nsIFrame* aFrame) MOZ_OVERRIDE
   1.100 +  {
   1.101 +    return 0;
   1.102 +  }
   1.103 +
   1.104 +  bool
   1.105 +  IsMrowLike() MOZ_OVERRIDE
   1.106 +  {
   1.107 +    return false;
   1.108 +  }
   1.109 +
   1.110 +  // helper to give a style context suitable for doing the stretching to the
   1.111 +  // MathMLChar. Frame classes that use this should make the extra style contexts
   1.112 +  // accessible to the Style System via Get/Set AdditionalStyleContext.
   1.113 +  static void
   1.114 +  ResolveMathMLCharStyle(nsPresContext*  aPresContext,
   1.115 +                         nsIContent*      aContent,
   1.116 +                         nsStyleContext*  aParenStyleContext,
   1.117 +                         nsMathMLChar*    aMathMLChar);
   1.118 +
   1.119 +  // helper to get the mEmbellishData of a frame
   1.120 +  // The MathML REC precisely defines an "embellished operator" as:
   1.121 +  // - an <mo> element;
   1.122 +  // - or one of the elements <msub>, <msup>, <msubsup>, <munder>, <mover>,
   1.123 +  //   <munderover>, <mmultiscripts>, <mfrac>, or <semantics>, whose first 
   1.124 +  //   argument exists and is an embellished operator;
   1.125 +  //- or one of the elements <mstyle>, <mphantom>, or <mpadded>, such that
   1.126 +  //   an <mrow> containing the same arguments would be an embellished
   1.127 +  //   operator;
   1.128 +  // - or an <maction> element whose selected subexpression exists and is an
   1.129 +  //   embellished operator;
   1.130 +  // - or an <mrow> whose arguments consist (in any order) of one embellished
   1.131 +  //   operator and zero or more spacelike elements.
   1.132 +  static void
   1.133 +  GetEmbellishDataFrom(nsIFrame*        aFrame,
   1.134 +                       nsEmbellishData& aEmbellishData);
   1.135 +
   1.136 +  // helper to get the presentation data of a frame. If aClimbTree is
   1.137 +  // set to true and the frame happens to be surrounded by non-MathML
   1.138 +  // helper frames needed for its support, we walk up the frame hierarchy
   1.139 +  // until we reach a MathML ancestor or the <root> math element.
   1.140 +  static void
   1.141 +  GetPresentationDataFrom(nsIFrame*           aFrame,
   1.142 +                          nsPresentationData& aPresentationData,
   1.143 +                          bool                aClimbTree = true);
   1.144 +
   1.145 +  // utilities to parse and retrieve numeric values in CSS units
   1.146 +  // All values are stored in twips.
   1.147 +  // @pre  aLengthValue is the default length value of the attribute.
   1.148 +  // @post aLengthValue is the length value computed from the attribute.
   1.149 +  static void ParseNumericValue(const nsString&   aString,
   1.150 +                                nscoord*          aLengthValue,
   1.151 +                                uint32_t          aFlags,
   1.152 +                                nsPresContext*    aPresContext,
   1.153 +                                nsStyleContext*   aStyleContext);
   1.154 +
   1.155 +  static nscoord 
   1.156 +  CalcLength(nsPresContext*   aPresContext,
   1.157 +             nsStyleContext*   aStyleContext,
   1.158 +             const nsCSSValue& aCSSValue);
   1.159 +
   1.160 +  static eMathMLFrameType
   1.161 +  GetMathMLFrameTypeFor(nsIFrame* aFrame)
   1.162 +  {
   1.163 +    if (aFrame->IsFrameOfType(nsIFrame::eMathML)) {
   1.164 +      nsIMathMLFrame* mathMLFrame = do_QueryFrame(aFrame);
   1.165 +      if (mathMLFrame)
   1.166 +        return mathMLFrame->GetMathMLFrameType();
   1.167 +    }
   1.168 +    return eMathMLFrameType_UNKNOWN;
   1.169 +  }
   1.170 +
   1.171 +  // estimate of the italic correction
   1.172 +  static void
   1.173 +  GetItalicCorrection(nsBoundingMetrics& aBoundingMetrics,
   1.174 +                      nscoord&           aItalicCorrection)
   1.175 +  {
   1.176 +    aItalicCorrection = aBoundingMetrics.rightBearing - aBoundingMetrics.width;
   1.177 +    if (0 > aItalicCorrection) {
   1.178 +      aItalicCorrection = 0;
   1.179 +    }
   1.180 +  }
   1.181 +
   1.182 +  static void
   1.183 +  GetItalicCorrection(nsBoundingMetrics& aBoundingMetrics,
   1.184 +                      nscoord&           aLeftItalicCorrection,
   1.185 +                      nscoord&           aRightItalicCorrection)
   1.186 +  {
   1.187 +    aRightItalicCorrection = aBoundingMetrics.rightBearing - aBoundingMetrics.width;
   1.188 +    if (0 > aRightItalicCorrection) {
   1.189 +      aRightItalicCorrection = 0;
   1.190 +    }
   1.191 +    aLeftItalicCorrection = -aBoundingMetrics.leftBearing;
   1.192 +    if (0 > aLeftItalicCorrection) {
   1.193 +      aLeftItalicCorrection = 0;
   1.194 +    }
   1.195 +  }
   1.196 +
   1.197 +  // helper methods for getting sup/subdrop's from a child
   1.198 +  static void 
   1.199 +  GetSubDropFromChild(nsIFrame*       aChild,
   1.200 +                      nscoord&        aSubDrop) 
   1.201 +  {
   1.202 +    nsRefPtr<nsFontMetrics> fm;
   1.203 +    nsLayoutUtils::GetFontMetricsForFrame(aChild, getter_AddRefs(fm));
   1.204 +    GetSubDrop(fm, aSubDrop);
   1.205 +  }
   1.206 +
   1.207 +  static void 
   1.208 +  GetSupDropFromChild(nsIFrame*       aChild,
   1.209 +                      nscoord&        aSupDrop) 
   1.210 +  {
   1.211 +    nsRefPtr<nsFontMetrics> fm;
   1.212 +    nsLayoutUtils::GetFontMetricsForFrame(aChild, getter_AddRefs(fm));
   1.213 +    GetSupDrop(fm, aSupDrop);
   1.214 +  }
   1.215 +
   1.216 +  static void
   1.217 +  GetSkewCorrectionFromChild(nsIFrame*       aChild,
   1.218 +                             nscoord&        aSkewCorrection) 
   1.219 +  {
   1.220 +    // default is 0
   1.221 +    // individual classes should over-ride this method if necessary
   1.222 +    aSkewCorrection = 0;
   1.223 +  }
   1.224 +
   1.225 +  // 2 levels of subscript shifts
   1.226 +  static void
   1.227 +  GetSubScriptShifts(nsFontMetrics* fm, 
   1.228 +                     nscoord&        aSubScriptShift1, 
   1.229 +                     nscoord&        aSubScriptShift2)
   1.230 +  {
   1.231 +    nscoord xHeight = fm->XHeight();
   1.232 +    aSubScriptShift1 = NSToCoordRound(150.000f/430.556f * xHeight);
   1.233 +    aSubScriptShift2 = NSToCoordRound(247.217f/430.556f * xHeight);
   1.234 +  }
   1.235 +
   1.236 +  // 3 levels of superscript shifts
   1.237 +  static void
   1.238 +  GetSupScriptShifts(nsFontMetrics* fm, 
   1.239 +                     nscoord&        aSupScriptShift1, 
   1.240 +                     nscoord&        aSupScriptShift2, 
   1.241 +                     nscoord&        aSupScriptShift3)
   1.242 +  {
   1.243 +    nscoord xHeight = fm->XHeight();
   1.244 +    aSupScriptShift1 = NSToCoordRound(412.892f/430.556f * xHeight);
   1.245 +    aSupScriptShift2 = NSToCoordRound(362.892f/430.556f * xHeight);
   1.246 +    aSupScriptShift3 = NSToCoordRound(288.889f/430.556f * xHeight);
   1.247 +  }
   1.248 +
   1.249 +  // these are TeX specific params not found in ordinary fonts
   1.250 +
   1.251 +  static void
   1.252 +  GetSubDrop(nsFontMetrics* fm,
   1.253 +             nscoord&        aSubDrop)
   1.254 +  {
   1.255 +    nscoord xHeight = fm->XHeight();
   1.256 +    aSubDrop = NSToCoordRound(50.000f/430.556f * xHeight);
   1.257 +  }
   1.258 +
   1.259 +  static void
   1.260 +  GetSupDrop(nsFontMetrics* fm,
   1.261 +             nscoord&        aSupDrop)
   1.262 +  {
   1.263 +    nscoord xHeight = fm->XHeight();
   1.264 +    aSupDrop = NSToCoordRound(386.108f/430.556f * xHeight);
   1.265 +  }
   1.266 +
   1.267 +  static void
   1.268 +  GetNumeratorShifts(nsFontMetrics* fm, 
   1.269 +                     nscoord&        numShift1, 
   1.270 +                     nscoord&        numShift2, 
   1.271 +                     nscoord&        numShift3)
   1.272 +  {
   1.273 +    nscoord xHeight = fm->XHeight();
   1.274 +    numShift1 = NSToCoordRound(676.508f/430.556f * xHeight);
   1.275 +    numShift2 = NSToCoordRound(393.732f/430.556f * xHeight);
   1.276 +    numShift3 = NSToCoordRound(443.731f/430.556f * xHeight);
   1.277 +  }
   1.278 +
   1.279 +  static void
   1.280 +  GetDenominatorShifts(nsFontMetrics* fm, 
   1.281 +                       nscoord&        denShift1, 
   1.282 +                       nscoord&        denShift2)
   1.283 +  {
   1.284 +    nscoord xHeight = fm->XHeight();
   1.285 +    denShift1 = NSToCoordRound(685.951f/430.556f * xHeight);
   1.286 +    denShift2 = NSToCoordRound(344.841f/430.556f * xHeight);
   1.287 +  }
   1.288 +
   1.289 +  static void
   1.290 +  GetEmHeight(nsFontMetrics* fm,
   1.291 +              nscoord&        emHeight)
   1.292 +  {
   1.293 +#if 0
   1.294 +    // should switch to this API in order to scale with changes of TextZoom
   1.295 +    emHeight = fm->EmHeight();
   1.296 +#else
   1.297 +    emHeight = NSToCoordRound(float(fm->Font().size));
   1.298 +#endif
   1.299 +  }
   1.300 +
   1.301 +  static void
   1.302 +  GetAxisHeight (nsFontMetrics* fm,
   1.303 +                 nscoord&        axisHeight)
   1.304 +  {
   1.305 +    axisHeight = NSToCoordRound(250.000f/430.556f * fm->XHeight());
   1.306 +  }
   1.307 +
   1.308 +  static void
   1.309 +  GetBigOpSpacings(nsFontMetrics* fm, 
   1.310 +                   nscoord&        bigOpSpacing1,
   1.311 +                   nscoord&        bigOpSpacing2,
   1.312 +                   nscoord&        bigOpSpacing3,
   1.313 +                   nscoord&        bigOpSpacing4,
   1.314 +                   nscoord&        bigOpSpacing5)
   1.315 +  {
   1.316 +    nscoord xHeight = fm->XHeight();
   1.317 +    bigOpSpacing1 = NSToCoordRound(111.111f/430.556f * xHeight);
   1.318 +    bigOpSpacing2 = NSToCoordRound(166.667f/430.556f * xHeight);
   1.319 +    bigOpSpacing3 = NSToCoordRound(200.000f/430.556f * xHeight);
   1.320 +    bigOpSpacing4 = NSToCoordRound(600.000f/430.556f * xHeight);
   1.321 +    bigOpSpacing5 = NSToCoordRound(100.000f/430.556f * xHeight);
   1.322 +  }
   1.323 +
   1.324 +  static void
   1.325 +  GetRuleThickness(nsFontMetrics* fm,
   1.326 +                   nscoord&        ruleThickness)
   1.327 +  {
   1.328 +    nscoord xHeight = fm->XHeight();
   1.329 +    ruleThickness = NSToCoordRound(40.000f/430.556f * xHeight);
   1.330 +  }
   1.331 +
   1.332 +  // Some parameters are not accurately obtained using the x-height.
   1.333 +  // Here are some slower variants to obtain the desired metrics
   1.334 +  // by actually measuring some characters
   1.335 +  static void
   1.336 +  GetRuleThickness(nsRenderingContext& aRenderingContext, 
   1.337 +                   nsFontMetrics*      aFontMetrics,
   1.338 +                   nscoord&             aRuleThickness);
   1.339 +
   1.340 +  static void
   1.341 +  GetAxisHeight(nsRenderingContext& aRenderingContext, 
   1.342 +                nsFontMetrics*      aFontMetrics,
   1.343 +                nscoord&             aAxisHeight);
   1.344 +
   1.345 +protected:
   1.346 +#if defined(DEBUG) && defined(SHOW_BOUNDING_BOX)
   1.347 +  nsresult DisplayBoundingMetrics(nsDisplayListBuilder* aBuilder,
   1.348 +                                  nsIFrame* aFrame, const nsPoint& aPt,
   1.349 +                                  const nsBoundingMetrics& aMetrics,
   1.350 +                                  const nsDisplayListSet& aLists);
   1.351 +#endif
   1.352 +
   1.353 +  /**
   1.354 +   * Display a solid rectangle in the frame's text color. Used for drawing
   1.355 +   * fraction separators and root/sqrt overbars.
   1.356 +   */
   1.357 +  void DisplayBar(nsDisplayListBuilder* aBuilder,
   1.358 +                  nsIFrame* aFrame, const nsRect& aRect,
   1.359 +                  const nsDisplayListSet& aLists);
   1.360 +
   1.361 +  // information about the presentation policy of the frame
   1.362 +  nsPresentationData mPresentationData;
   1.363 +
   1.364 +  // information about a container that is an embellished operator
   1.365 +  nsEmbellishData mEmbellishData;
   1.366 +  
   1.367 +  // Metrics that _exactly_ enclose the text of the frame
   1.368 +  nsBoundingMetrics mBoundingMetrics;
   1.369 +  
   1.370 +  // Reference point of the frame: mReference.y is the baseline
   1.371 +  nsPoint mReference; 
   1.372 +};
   1.373 +
   1.374 +#endif /* nsMathMLFrame_h___ */

mercurial