layout/mathml/nsMathMLFrame.h

Wed, 31 Dec 2014 07:53:36 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:53:36 +0100
branch
TOR_BUG_3246
changeset 5
4ab42b5ab56c
permissions
-rw-r--r--

Correct small whitespace inconsistency, lost while renaming variables.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef nsMathMLFrame_h___
michael@0 7 #define nsMathMLFrame_h___
michael@0 8
michael@0 9 #include "mozilla/Attributes.h"
michael@0 10 #include "nsFontMetrics.h"
michael@0 11 #include "nsMathMLOperators.h"
michael@0 12 #include "nsIMathMLFrame.h"
michael@0 13 #include "nsLayoutUtils.h"
michael@0 14 #include "nsBoundingMetrics.h"
michael@0 15 #include "nsIFrame.h"
michael@0 16
michael@0 17 class nsMathMLChar;
michael@0 18 class nsCSSValue;
michael@0 19 class nsDisplayListSet;
michael@0 20
michael@0 21 // Concrete base class with default methods that derived MathML frames can override
michael@0 22 class nsMathMLFrame : public nsIMathMLFrame {
michael@0 23 public:
michael@0 24
michael@0 25 // nsIMathMLFrame ---
michael@0 26
michael@0 27 virtual bool
michael@0 28 IsSpaceLike() MOZ_OVERRIDE {
michael@0 29 return NS_MATHML_IS_SPACE_LIKE(mPresentationData.flags);
michael@0 30 }
michael@0 31
michael@0 32 NS_IMETHOD
michael@0 33 GetBoundingMetrics(nsBoundingMetrics& aBoundingMetrics) MOZ_OVERRIDE {
michael@0 34 aBoundingMetrics = mBoundingMetrics;
michael@0 35 return NS_OK;
michael@0 36 }
michael@0 37
michael@0 38 NS_IMETHOD
michael@0 39 SetBoundingMetrics(const nsBoundingMetrics& aBoundingMetrics) MOZ_OVERRIDE {
michael@0 40 mBoundingMetrics = aBoundingMetrics;
michael@0 41 return NS_OK;
michael@0 42 }
michael@0 43
michael@0 44 NS_IMETHOD
michael@0 45 SetReference(const nsPoint& aReference) MOZ_OVERRIDE {
michael@0 46 mReference = aReference;
michael@0 47 return NS_OK;
michael@0 48 }
michael@0 49
michael@0 50 virtual eMathMLFrameType GetMathMLFrameType() MOZ_OVERRIDE;
michael@0 51
michael@0 52 NS_IMETHOD
michael@0 53 Stretch(nsRenderingContext& aRenderingContext,
michael@0 54 nsStretchDirection aStretchDirection,
michael@0 55 nsBoundingMetrics& aContainerSize,
michael@0 56 nsHTMLReflowMetrics& aDesiredStretchSize) MOZ_OVERRIDE
michael@0 57 {
michael@0 58 return NS_OK;
michael@0 59 }
michael@0 60
michael@0 61 NS_IMETHOD
michael@0 62 GetEmbellishData(nsEmbellishData& aEmbellishData) MOZ_OVERRIDE {
michael@0 63 aEmbellishData = mEmbellishData;
michael@0 64 return NS_OK;
michael@0 65 }
michael@0 66
michael@0 67 NS_IMETHOD
michael@0 68 GetPresentationData(nsPresentationData& aPresentationData) MOZ_OVERRIDE {
michael@0 69 aPresentationData = mPresentationData;
michael@0 70 return NS_OK;
michael@0 71 }
michael@0 72
michael@0 73 NS_IMETHOD
michael@0 74 InheritAutomaticData(nsIFrame* aParent) MOZ_OVERRIDE;
michael@0 75
michael@0 76 NS_IMETHOD
michael@0 77 TransmitAutomaticData() MOZ_OVERRIDE
michael@0 78 {
michael@0 79 return NS_OK;
michael@0 80 }
michael@0 81
michael@0 82 NS_IMETHOD
michael@0 83 UpdatePresentationData(uint32_t aFlagsValues,
michael@0 84 uint32_t aFlagsToUpdate) MOZ_OVERRIDE;
michael@0 85
michael@0 86 NS_IMETHOD
michael@0 87 UpdatePresentationDataFromChildAt(int32_t aFirstIndex,
michael@0 88 int32_t aLastIndex,
michael@0 89 uint32_t aFlagsValues,
michael@0 90 uint32_t aFlagsToUpdate) MOZ_OVERRIDE
michael@0 91 {
michael@0 92 return NS_OK;
michael@0 93 }
michael@0 94
michael@0 95 uint8_t
michael@0 96 ScriptIncrement(nsIFrame* aFrame) MOZ_OVERRIDE
michael@0 97 {
michael@0 98 return 0;
michael@0 99 }
michael@0 100
michael@0 101 bool
michael@0 102 IsMrowLike() MOZ_OVERRIDE
michael@0 103 {
michael@0 104 return false;
michael@0 105 }
michael@0 106
michael@0 107 // helper to give a style context suitable for doing the stretching to the
michael@0 108 // MathMLChar. Frame classes that use this should make the extra style contexts
michael@0 109 // accessible to the Style System via Get/Set AdditionalStyleContext.
michael@0 110 static void
michael@0 111 ResolveMathMLCharStyle(nsPresContext* aPresContext,
michael@0 112 nsIContent* aContent,
michael@0 113 nsStyleContext* aParenStyleContext,
michael@0 114 nsMathMLChar* aMathMLChar);
michael@0 115
michael@0 116 // helper to get the mEmbellishData of a frame
michael@0 117 // The MathML REC precisely defines an "embellished operator" as:
michael@0 118 // - an <mo> element;
michael@0 119 // - or one of the elements <msub>, <msup>, <msubsup>, <munder>, <mover>,
michael@0 120 // <munderover>, <mmultiscripts>, <mfrac>, or <semantics>, whose first
michael@0 121 // argument exists and is an embellished operator;
michael@0 122 //- or one of the elements <mstyle>, <mphantom>, or <mpadded>, such that
michael@0 123 // an <mrow> containing the same arguments would be an embellished
michael@0 124 // operator;
michael@0 125 // - or an <maction> element whose selected subexpression exists and is an
michael@0 126 // embellished operator;
michael@0 127 // - or an <mrow> whose arguments consist (in any order) of one embellished
michael@0 128 // operator and zero or more spacelike elements.
michael@0 129 static void
michael@0 130 GetEmbellishDataFrom(nsIFrame* aFrame,
michael@0 131 nsEmbellishData& aEmbellishData);
michael@0 132
michael@0 133 // helper to get the presentation data of a frame. If aClimbTree is
michael@0 134 // set to true and the frame happens to be surrounded by non-MathML
michael@0 135 // helper frames needed for its support, we walk up the frame hierarchy
michael@0 136 // until we reach a MathML ancestor or the <root> math element.
michael@0 137 static void
michael@0 138 GetPresentationDataFrom(nsIFrame* aFrame,
michael@0 139 nsPresentationData& aPresentationData,
michael@0 140 bool aClimbTree = true);
michael@0 141
michael@0 142 // utilities to parse and retrieve numeric values in CSS units
michael@0 143 // All values are stored in twips.
michael@0 144 // @pre aLengthValue is the default length value of the attribute.
michael@0 145 // @post aLengthValue is the length value computed from the attribute.
michael@0 146 static void ParseNumericValue(const nsString& aString,
michael@0 147 nscoord* aLengthValue,
michael@0 148 uint32_t aFlags,
michael@0 149 nsPresContext* aPresContext,
michael@0 150 nsStyleContext* aStyleContext);
michael@0 151
michael@0 152 static nscoord
michael@0 153 CalcLength(nsPresContext* aPresContext,
michael@0 154 nsStyleContext* aStyleContext,
michael@0 155 const nsCSSValue& aCSSValue);
michael@0 156
michael@0 157 static eMathMLFrameType
michael@0 158 GetMathMLFrameTypeFor(nsIFrame* aFrame)
michael@0 159 {
michael@0 160 if (aFrame->IsFrameOfType(nsIFrame::eMathML)) {
michael@0 161 nsIMathMLFrame* mathMLFrame = do_QueryFrame(aFrame);
michael@0 162 if (mathMLFrame)
michael@0 163 return mathMLFrame->GetMathMLFrameType();
michael@0 164 }
michael@0 165 return eMathMLFrameType_UNKNOWN;
michael@0 166 }
michael@0 167
michael@0 168 // estimate of the italic correction
michael@0 169 static void
michael@0 170 GetItalicCorrection(nsBoundingMetrics& aBoundingMetrics,
michael@0 171 nscoord& aItalicCorrection)
michael@0 172 {
michael@0 173 aItalicCorrection = aBoundingMetrics.rightBearing - aBoundingMetrics.width;
michael@0 174 if (0 > aItalicCorrection) {
michael@0 175 aItalicCorrection = 0;
michael@0 176 }
michael@0 177 }
michael@0 178
michael@0 179 static void
michael@0 180 GetItalicCorrection(nsBoundingMetrics& aBoundingMetrics,
michael@0 181 nscoord& aLeftItalicCorrection,
michael@0 182 nscoord& aRightItalicCorrection)
michael@0 183 {
michael@0 184 aRightItalicCorrection = aBoundingMetrics.rightBearing - aBoundingMetrics.width;
michael@0 185 if (0 > aRightItalicCorrection) {
michael@0 186 aRightItalicCorrection = 0;
michael@0 187 }
michael@0 188 aLeftItalicCorrection = -aBoundingMetrics.leftBearing;
michael@0 189 if (0 > aLeftItalicCorrection) {
michael@0 190 aLeftItalicCorrection = 0;
michael@0 191 }
michael@0 192 }
michael@0 193
michael@0 194 // helper methods for getting sup/subdrop's from a child
michael@0 195 static void
michael@0 196 GetSubDropFromChild(nsIFrame* aChild,
michael@0 197 nscoord& aSubDrop)
michael@0 198 {
michael@0 199 nsRefPtr<nsFontMetrics> fm;
michael@0 200 nsLayoutUtils::GetFontMetricsForFrame(aChild, getter_AddRefs(fm));
michael@0 201 GetSubDrop(fm, aSubDrop);
michael@0 202 }
michael@0 203
michael@0 204 static void
michael@0 205 GetSupDropFromChild(nsIFrame* aChild,
michael@0 206 nscoord& aSupDrop)
michael@0 207 {
michael@0 208 nsRefPtr<nsFontMetrics> fm;
michael@0 209 nsLayoutUtils::GetFontMetricsForFrame(aChild, getter_AddRefs(fm));
michael@0 210 GetSupDrop(fm, aSupDrop);
michael@0 211 }
michael@0 212
michael@0 213 static void
michael@0 214 GetSkewCorrectionFromChild(nsIFrame* aChild,
michael@0 215 nscoord& aSkewCorrection)
michael@0 216 {
michael@0 217 // default is 0
michael@0 218 // individual classes should over-ride this method if necessary
michael@0 219 aSkewCorrection = 0;
michael@0 220 }
michael@0 221
michael@0 222 // 2 levels of subscript shifts
michael@0 223 static void
michael@0 224 GetSubScriptShifts(nsFontMetrics* fm,
michael@0 225 nscoord& aSubScriptShift1,
michael@0 226 nscoord& aSubScriptShift2)
michael@0 227 {
michael@0 228 nscoord xHeight = fm->XHeight();
michael@0 229 aSubScriptShift1 = NSToCoordRound(150.000f/430.556f * xHeight);
michael@0 230 aSubScriptShift2 = NSToCoordRound(247.217f/430.556f * xHeight);
michael@0 231 }
michael@0 232
michael@0 233 // 3 levels of superscript shifts
michael@0 234 static void
michael@0 235 GetSupScriptShifts(nsFontMetrics* fm,
michael@0 236 nscoord& aSupScriptShift1,
michael@0 237 nscoord& aSupScriptShift2,
michael@0 238 nscoord& aSupScriptShift3)
michael@0 239 {
michael@0 240 nscoord xHeight = fm->XHeight();
michael@0 241 aSupScriptShift1 = NSToCoordRound(412.892f/430.556f * xHeight);
michael@0 242 aSupScriptShift2 = NSToCoordRound(362.892f/430.556f * xHeight);
michael@0 243 aSupScriptShift3 = NSToCoordRound(288.889f/430.556f * xHeight);
michael@0 244 }
michael@0 245
michael@0 246 // these are TeX specific params not found in ordinary fonts
michael@0 247
michael@0 248 static void
michael@0 249 GetSubDrop(nsFontMetrics* fm,
michael@0 250 nscoord& aSubDrop)
michael@0 251 {
michael@0 252 nscoord xHeight = fm->XHeight();
michael@0 253 aSubDrop = NSToCoordRound(50.000f/430.556f * xHeight);
michael@0 254 }
michael@0 255
michael@0 256 static void
michael@0 257 GetSupDrop(nsFontMetrics* fm,
michael@0 258 nscoord& aSupDrop)
michael@0 259 {
michael@0 260 nscoord xHeight = fm->XHeight();
michael@0 261 aSupDrop = NSToCoordRound(386.108f/430.556f * xHeight);
michael@0 262 }
michael@0 263
michael@0 264 static void
michael@0 265 GetNumeratorShifts(nsFontMetrics* fm,
michael@0 266 nscoord& numShift1,
michael@0 267 nscoord& numShift2,
michael@0 268 nscoord& numShift3)
michael@0 269 {
michael@0 270 nscoord xHeight = fm->XHeight();
michael@0 271 numShift1 = NSToCoordRound(676.508f/430.556f * xHeight);
michael@0 272 numShift2 = NSToCoordRound(393.732f/430.556f * xHeight);
michael@0 273 numShift3 = NSToCoordRound(443.731f/430.556f * xHeight);
michael@0 274 }
michael@0 275
michael@0 276 static void
michael@0 277 GetDenominatorShifts(nsFontMetrics* fm,
michael@0 278 nscoord& denShift1,
michael@0 279 nscoord& denShift2)
michael@0 280 {
michael@0 281 nscoord xHeight = fm->XHeight();
michael@0 282 denShift1 = NSToCoordRound(685.951f/430.556f * xHeight);
michael@0 283 denShift2 = NSToCoordRound(344.841f/430.556f * xHeight);
michael@0 284 }
michael@0 285
michael@0 286 static void
michael@0 287 GetEmHeight(nsFontMetrics* fm,
michael@0 288 nscoord& emHeight)
michael@0 289 {
michael@0 290 #if 0
michael@0 291 // should switch to this API in order to scale with changes of TextZoom
michael@0 292 emHeight = fm->EmHeight();
michael@0 293 #else
michael@0 294 emHeight = NSToCoordRound(float(fm->Font().size));
michael@0 295 #endif
michael@0 296 }
michael@0 297
michael@0 298 static void
michael@0 299 GetAxisHeight (nsFontMetrics* fm,
michael@0 300 nscoord& axisHeight)
michael@0 301 {
michael@0 302 axisHeight = NSToCoordRound(250.000f/430.556f * fm->XHeight());
michael@0 303 }
michael@0 304
michael@0 305 static void
michael@0 306 GetBigOpSpacings(nsFontMetrics* fm,
michael@0 307 nscoord& bigOpSpacing1,
michael@0 308 nscoord& bigOpSpacing2,
michael@0 309 nscoord& bigOpSpacing3,
michael@0 310 nscoord& bigOpSpacing4,
michael@0 311 nscoord& bigOpSpacing5)
michael@0 312 {
michael@0 313 nscoord xHeight = fm->XHeight();
michael@0 314 bigOpSpacing1 = NSToCoordRound(111.111f/430.556f * xHeight);
michael@0 315 bigOpSpacing2 = NSToCoordRound(166.667f/430.556f * xHeight);
michael@0 316 bigOpSpacing3 = NSToCoordRound(200.000f/430.556f * xHeight);
michael@0 317 bigOpSpacing4 = NSToCoordRound(600.000f/430.556f * xHeight);
michael@0 318 bigOpSpacing5 = NSToCoordRound(100.000f/430.556f * xHeight);
michael@0 319 }
michael@0 320
michael@0 321 static void
michael@0 322 GetRuleThickness(nsFontMetrics* fm,
michael@0 323 nscoord& ruleThickness)
michael@0 324 {
michael@0 325 nscoord xHeight = fm->XHeight();
michael@0 326 ruleThickness = NSToCoordRound(40.000f/430.556f * xHeight);
michael@0 327 }
michael@0 328
michael@0 329 // Some parameters are not accurately obtained using the x-height.
michael@0 330 // Here are some slower variants to obtain the desired metrics
michael@0 331 // by actually measuring some characters
michael@0 332 static void
michael@0 333 GetRuleThickness(nsRenderingContext& aRenderingContext,
michael@0 334 nsFontMetrics* aFontMetrics,
michael@0 335 nscoord& aRuleThickness);
michael@0 336
michael@0 337 static void
michael@0 338 GetAxisHeight(nsRenderingContext& aRenderingContext,
michael@0 339 nsFontMetrics* aFontMetrics,
michael@0 340 nscoord& aAxisHeight);
michael@0 341
michael@0 342 protected:
michael@0 343 #if defined(DEBUG) && defined(SHOW_BOUNDING_BOX)
michael@0 344 nsresult DisplayBoundingMetrics(nsDisplayListBuilder* aBuilder,
michael@0 345 nsIFrame* aFrame, const nsPoint& aPt,
michael@0 346 const nsBoundingMetrics& aMetrics,
michael@0 347 const nsDisplayListSet& aLists);
michael@0 348 #endif
michael@0 349
michael@0 350 /**
michael@0 351 * Display a solid rectangle in the frame's text color. Used for drawing
michael@0 352 * fraction separators and root/sqrt overbars.
michael@0 353 */
michael@0 354 void DisplayBar(nsDisplayListBuilder* aBuilder,
michael@0 355 nsIFrame* aFrame, const nsRect& aRect,
michael@0 356 const nsDisplayListSet& aLists);
michael@0 357
michael@0 358 // information about the presentation policy of the frame
michael@0 359 nsPresentationData mPresentationData;
michael@0 360
michael@0 361 // information about a container that is an embellished operator
michael@0 362 nsEmbellishData mEmbellishData;
michael@0 363
michael@0 364 // Metrics that _exactly_ enclose the text of the frame
michael@0 365 nsBoundingMetrics mBoundingMetrics;
michael@0 366
michael@0 367 // Reference point of the frame: mReference.y is the baseline
michael@0 368 nsPoint mReference;
michael@0 369 };
michael@0 370
michael@0 371 #endif /* nsMathMLFrame_h___ */

mercurial