layout/mathml/nsIMathMLFrame.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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 //#define SHOW_BOUNDING_BOX 1
michael@0 6 #ifndef nsIMathMLFrame_h___
michael@0 7 #define nsIMathMLFrame_h___
michael@0 8
michael@0 9 #include "nsQueryFrame.h"
michael@0 10 #include "nsMathMLOperators.h"
michael@0 11
michael@0 12 struct nsPresentationData;
michael@0 13 struct nsEmbellishData;
michael@0 14 struct nsHTMLReflowMetrics;
michael@0 15 class nsRenderingContext;
michael@0 16 class nsIFrame;
michael@0 17
michael@0 18 // For MathML, this 'type' will be used to determine the spacing between frames
michael@0 19 // Subclasses can return a 'type' that will give them a particular spacing
michael@0 20 enum eMathMLFrameType {
michael@0 21 eMathMLFrameType_UNKNOWN = -1,
michael@0 22 eMathMLFrameType_Ordinary,
michael@0 23 eMathMLFrameType_OperatorOrdinary,
michael@0 24 eMathMLFrameType_OperatorInvisible,
michael@0 25 eMathMLFrameType_OperatorUserDefined,
michael@0 26 eMathMLFrameType_Inner,
michael@0 27 eMathMLFrameType_ItalicIdentifier,
michael@0 28 eMathMLFrameType_UprightIdentifier,
michael@0 29 eMathMLFrameType_COUNT
michael@0 30 };
michael@0 31
michael@0 32 // Abstract base class that provides additional methods for MathML frames
michael@0 33 class nsIMathMLFrame
michael@0 34 {
michael@0 35 public:
michael@0 36 NS_DECL_QUERYFRAME_TARGET(nsIMathMLFrame)
michael@0 37
michael@0 38 // helper to check whether the frame is "space-like", as defined by the spec.
michael@0 39 virtual bool IsSpaceLike() = 0;
michael@0 40
michael@0 41 /* SUPPORT FOR PRECISE POSITIONING */
michael@0 42 /*====================================================================*/
michael@0 43
michael@0 44 /* Metrics that _exactly_ enclose the text of the frame.
michael@0 45 * The frame *must* have *already* being reflowed, before you can call
michael@0 46 * the GetBoundingMetrics() method.
michael@0 47 * Note that for a frame with nested children, the bounding metrics
michael@0 48 * will exactly enclose its children. For example, the bounding metrics
michael@0 49 * of msub is the smallest rectangle that exactly encloses both the
michael@0 50 * base and the subscript.
michael@0 51 */
michael@0 52 NS_IMETHOD
michael@0 53 GetBoundingMetrics(nsBoundingMetrics& aBoundingMetrics) = 0;
michael@0 54
michael@0 55 NS_IMETHOD
michael@0 56 SetBoundingMetrics(const nsBoundingMetrics& aBoundingMetrics) = 0;
michael@0 57
michael@0 58 NS_IMETHOD
michael@0 59 SetReference(const nsPoint& aReference) = 0;
michael@0 60
michael@0 61 virtual eMathMLFrameType GetMathMLFrameType() = 0;
michael@0 62
michael@0 63 /* SUPPORT FOR STRETCHY ELEMENTS */
michael@0 64 /*====================================================================*/
michael@0 65
michael@0 66 /* Stretch :
michael@0 67 * Called to ask a stretchy MathML frame to stretch itself depending
michael@0 68 * on its context.
michael@0 69 *
michael@0 70 * An embellished frame is treated in a special way. When it receives a
michael@0 71 * Stretch() command, it passes the command to its embellished child and
michael@0 72 * the stretched size is bubbled up from the inner-most <mo> frame. In other
michael@0 73 * words, the stretch command descend through the embellished hierarchy.
michael@0 74 *
michael@0 75 * @param aStretchDirection [in] the direction where to attempt to
michael@0 76 * stretch.
michael@0 77 * @param aContainerSize [in] struct that suggests the maximumn size for
michael@0 78 * the stretched frame. Only member data of the struct that are
michael@0 79 * relevant to the direction are used (the rest is ignored).
michael@0 80 * @param aDesiredStretchSize [in/out] On input the current size
michael@0 81 * of the frame, on output the size after stretching.
michael@0 82 */
michael@0 83 NS_IMETHOD
michael@0 84 Stretch(nsRenderingContext& aRenderingContext,
michael@0 85 nsStretchDirection aStretchDirection,
michael@0 86 nsBoundingMetrics& aContainerSize,
michael@0 87 nsHTMLReflowMetrics& aDesiredStretchSize) = 0;
michael@0 88
michael@0 89 /* Get the mEmbellishData member variable. */
michael@0 90
michael@0 91 NS_IMETHOD
michael@0 92 GetEmbellishData(nsEmbellishData& aEmbellishData) = 0;
michael@0 93
michael@0 94
michael@0 95 /* SUPPORT FOR SCRIPTING ELEMENTS */
michael@0 96 /*====================================================================*/
michael@0 97
michael@0 98 /* Get the mPresentationData member variable. */
michael@0 99
michael@0 100 NS_IMETHOD
michael@0 101 GetPresentationData(nsPresentationData& aPresentationData) = 0;
michael@0 102
michael@0 103 /* InheritAutomaticData() / TransmitAutomaticData() :
michael@0 104 * There are precise rules governing each MathML frame and its children.
michael@0 105 * Properties such as the scriptlevel or the embellished nature of a frame
michael@0 106 * depend on those rules. Also, certain properties that we use to emulate
michael@0 107 * TeX rendering rules are frame-dependent too. These two methods are meant
michael@0 108 * to be implemented by frame classes that need to assert specific properties
michael@0 109 * within their subtrees.
michael@0 110 *
michael@0 111 * InheritAutomaticData() is called in a top-down manner [like nsIFrame::Init],
michael@0 112 * as we descend the frame tree, whereas TransmitAutomaticData() is called in a
michael@0 113 * bottom-up manner, as we ascend the tree [like nsIFrame::SetInitialChildList].
michael@0 114 * However, unlike Init() and SetInitialChildList() which are called only once
michael@0 115 * during the life-time of a frame (when initially constructing the frame tree),
michael@0 116 * these two methods are called to build automatic data after the <math>...</math>
michael@0 117 * subtree has been constructed fully, and are called again as we walk a child's
michael@0 118 * subtree to handle dynamic changes that happen in the content model.
michael@0 119 *
michael@0 120 * As a rule of thumb:
michael@0 121 *
michael@0 122 * 1. Use InheritAutomaticData() to set properties related to your ancestors:
michael@0 123 * - set properties that are intrinsic to yourself
michael@0 124 * - set properties that depend on the state that you expect your ancestors
michael@0 125 * to have already reached in their own InheritAutomaticData().
michael@0 126 * - set properties that your descendants assume that you would have set in
michael@0 127 * your InheritAutomaticData() -- this way, they can safely query them and
michael@0 128 * the process will feed upon itself.
michael@0 129 *
michael@0 130 * 2. Use TransmitAutomaticData() to set properties related to your descendants:
michael@0 131 * - set properties that depend on the state that you expect your descendants
michael@0 132 * to have reached upon processing their own TransmitAutomaticData().
michael@0 133 * - transmit properties that your descendants expect that you will transmit to
michael@0 134 * them in your TransmitAutomaticData() -- this way, they remain up-to-date.
michael@0 135 * - set properties that your ancestors expect that you would set in your
michael@0 136 * TransmitAutomaticData() -- this way, they can safely query them and the
michael@0 137 * process will feed upon itself.
michael@0 138 */
michael@0 139
michael@0 140 NS_IMETHOD
michael@0 141 InheritAutomaticData(nsIFrame* aParent) = 0;
michael@0 142
michael@0 143 NS_IMETHOD
michael@0 144 TransmitAutomaticData() = 0;
michael@0 145
michael@0 146 /* UpdatePresentationData:
michael@0 147 * Updates the frame's compression flag.
michael@0 148 * A frame becomes "compressed" (or "cramped") according to TeX rendering
michael@0 149 * rules (TeXBook, Ch.17, p.140-141).
michael@0 150 *
michael@0 151 * @param aFlagsValues [in]
michael@0 152 * The new values (e.g., compress) that are going to be
michael@0 153 * updated.
michael@0 154 *
michael@0 155 * @param aWhichFlags [in]
michael@0 156 * The flags that are relevant to this call. Since not all calls
michael@0 157 * are meant to update all flags at once, aWhichFlags is used
michael@0 158 * to distinguish flags that need to retain their existing values
michael@0 159 * from flags that need to be turned on (or turned off). If a bit
michael@0 160 * is set in aWhichFlags, then the corresponding value (which
michael@0 161 * can be 0 or 1) is taken from aFlagsValues and applied to the
michael@0 162 * frame. Therefore, by setting their bits in aWhichFlags, and
michael@0 163 * setting their desired values in aFlagsValues, it is possible to
michael@0 164 * update some flags in the frame, leaving the other flags unchanged.
michael@0 165 */
michael@0 166 NS_IMETHOD
michael@0 167 UpdatePresentationData(uint32_t aFlagsValues,
michael@0 168 uint32_t aWhichFlags) = 0;
michael@0 169
michael@0 170 /* UpdatePresentationDataFromChildAt :
michael@0 171 * Sets compression flag on the whole tree. For child frames
michael@0 172 * at aFirstIndex up to aLastIndex, this method sets their
michael@0 173 * compression flags. The update is propagated down the subtrees of each of
michael@0 174 * these child frames.
michael@0 175 *
michael@0 176 * @param aFirstIndex [in]
michael@0 177 * Index of the first child from where the update is propagated.
michael@0 178 *
michael@0 179 * @param aLastIndex [in]
michael@0 180 * Index of the last child where to stop the update.
michael@0 181 * A value of -1 means up to last existing child.
michael@0 182 *
michael@0 183 * @param aFlagsValues [in]
michael@0 184 * The new values (e.g., compress) that are going to be
michael@0 185 * assigned in the whole sub-trees.
michael@0 186 *
michael@0 187 * @param aWhichFlags [in]
michael@0 188 * The flags that are relevant to this call. See UpdatePresentationData()
michael@0 189 * for more details about this parameter.
michael@0 190 */
michael@0 191 NS_IMETHOD
michael@0 192 UpdatePresentationDataFromChildAt(int32_t aFirstIndex,
michael@0 193 int32_t aLastIndex,
michael@0 194 uint32_t aFlagsValues,
michael@0 195 uint32_t aWhichFlags) = 0;
michael@0 196
michael@0 197 // If aFrame is a child frame, returns the script increment which this frame
michael@0 198 // imposes on the specified frame, ignoring any artificial adjustments to
michael@0 199 // scriptlevel.
michael@0 200 // Returns 0 if the specified frame isn't a child frame.
michael@0 201 virtual uint8_t
michael@0 202 ScriptIncrement(nsIFrame* aFrame) = 0;
michael@0 203
michael@0 204 // Returns true if the frame is considered to be an mrow for layout purposes.
michael@0 205 // This includes inferred mrows, but excludes <mrow> elements with a single
michael@0 206 // child. In the latter case, the child is to be treated as if it wasn't
michael@0 207 // within an mrow, so we pretend the mrow isn't mrow-like.
michael@0 208 virtual bool
michael@0 209 IsMrowLike() = 0;
michael@0 210 };
michael@0 211
michael@0 212 // struct used by a container frame to keep track of its embellishments.
michael@0 213 // By convention, the data that we keep here is bubbled from the embellished
michael@0 214 // hierarchy, and it remains unchanged unless we have to recover from a change
michael@0 215 // that occurs in the embellished hierarchy. The struct remains in its nil
michael@0 216 // state in those frames that are not part of the embellished hierarchy.
michael@0 217 struct nsEmbellishData {
michael@0 218 // bits used to mark certain properties of our embellishments
michael@0 219 uint32_t flags;
michael@0 220
michael@0 221 // pointer on the <mo> frame at the core of the embellished hierarchy
michael@0 222 nsIFrame* coreFrame;
michael@0 223
michael@0 224 // stretchy direction that the nsMathMLChar owned by the core <mo> supports
michael@0 225 nsStretchDirection direction;
michael@0 226
michael@0 227 // spacing that may come from <mo> depending on its 'form'. Since
michael@0 228 // the 'form' may also depend on the position of the outermost
michael@0 229 // embellished ancestor, the set up of these values may require
michael@0 230 // looking up the position of our ancestors.
michael@0 231 nscoord leadingSpace;
michael@0 232 nscoord trailingSpace;
michael@0 233
michael@0 234 nsEmbellishData() {
michael@0 235 flags = 0;
michael@0 236 coreFrame = nullptr;
michael@0 237 direction = NS_STRETCH_DIRECTION_UNSUPPORTED;
michael@0 238 leadingSpace = 0;
michael@0 239 trailingSpace = 0;
michael@0 240 }
michael@0 241 };
michael@0 242
michael@0 243 // struct used by a container frame to modulate its presentation.
michael@0 244 // By convention, the data that we keep in this struct can change depending
michael@0 245 // on any of our ancestors and/or descendants. If a data can be resolved
michael@0 246 // solely from the embellished hierarchy, and it remains immutable once
michael@0 247 // resolved, we put it in |nsEmbellishData|. If it can be affected by other
michael@0 248 // things, it comes here. This struct is updated as we receive information
michael@0 249 // transmitted by our ancestors and is kept in sync with changes in our
michael@0 250 // descendants that affects us.
michael@0 251 struct nsPresentationData {
michael@0 252 // bits for: compressed, etc
michael@0 253 uint32_t flags;
michael@0 254
michael@0 255 // handy pointer on our base child (the 'nucleus' in TeX), but it may be
michael@0 256 // null here (e.g., tags like <mrow>, <mfrac>, <mtable>, etc, won't
michael@0 257 // pick a particular child in their child list to be the base)
michael@0 258 nsIFrame* baseFrame;
michael@0 259
michael@0 260 nsPresentationData() {
michael@0 261 flags = 0;
michael@0 262 baseFrame = nullptr;
michael@0 263 }
michael@0 264 };
michael@0 265
michael@0 266 // ==========================================================================
michael@0 267 // Bits used for the presentation flags -- these bits are set
michael@0 268 // in their relevant situation as they become available
michael@0 269
michael@0 270 // This bit is used to emulate TeX rendering.
michael@0 271 // Internal use only, cannot be set by the user with an attribute.
michael@0 272 #define NS_MATHML_COMPRESSED 0x00000002U
michael@0 273
michael@0 274 // This bit is set if the frame will fire a vertical stretch
michael@0 275 // command on all its (non-empty) children.
michael@0 276 // Tags like <mrow> (or an inferred mrow), mpadded, etc, will fire a
michael@0 277 // vertical stretch command on all their non-empty children
michael@0 278 #define NS_MATHML_STRETCH_ALL_CHILDREN_VERTICALLY 0x00000004U
michael@0 279
michael@0 280 // This bit is set if the frame will fire a horizontal stretch
michael@0 281 // command on all its (non-empty) children.
michael@0 282 // Tags like munder, mover, munderover, will fire a
michael@0 283 // horizontal stretch command on all their non-empty children
michael@0 284 #define NS_MATHML_STRETCH_ALL_CHILDREN_HORIZONTALLY 0x00000008U
michael@0 285
michael@0 286 // This bit is set if the frame is "space-like", as defined by the spec.
michael@0 287 #define NS_MATHML_SPACE_LIKE 0x00000040U
michael@0 288
michael@0 289 // This bit is set when the frame cannot be formatted due to an
michael@0 290 // error (e.g., invalid markup such as a <msup> without an overscript).
michael@0 291 // When set, a visual feedback will be provided to the user.
michael@0 292 #define NS_MATHML_ERROR 0x80000000U
michael@0 293
michael@0 294 // a bit used for debug
michael@0 295 #define NS_MATHML_STRETCH_DONE 0x20000000U
michael@0 296
michael@0 297 // This bit is used for visual debug. When set, the bounding box
michael@0 298 // of your frame is painted. This visual debug enable to ensure that
michael@0 299 // you have properly filled your mReference and mBoundingMetrics in
michael@0 300 // Place().
michael@0 301 #define NS_MATHML_SHOW_BOUNDING_METRICS 0x10000000U
michael@0 302
michael@0 303 // Macros that retrieve those bits
michael@0 304
michael@0 305 #define NS_MATHML_IS_COMPRESSED(_flags) \
michael@0 306 (NS_MATHML_COMPRESSED == ((_flags) & NS_MATHML_COMPRESSED))
michael@0 307
michael@0 308 #define NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(_flags) \
michael@0 309 (NS_MATHML_STRETCH_ALL_CHILDREN_VERTICALLY == ((_flags) & NS_MATHML_STRETCH_ALL_CHILDREN_VERTICALLY))
michael@0 310
michael@0 311 #define NS_MATHML_WILL_STRETCH_ALL_CHILDREN_HORIZONTALLY(_flags) \
michael@0 312 (NS_MATHML_STRETCH_ALL_CHILDREN_HORIZONTALLY == ((_flags) & NS_MATHML_STRETCH_ALL_CHILDREN_HORIZONTALLY))
michael@0 313
michael@0 314 #define NS_MATHML_IS_SPACE_LIKE(_flags) \
michael@0 315 (NS_MATHML_SPACE_LIKE == ((_flags) & NS_MATHML_SPACE_LIKE))
michael@0 316
michael@0 317 #define NS_MATHML_HAS_ERROR(_flags) \
michael@0 318 (NS_MATHML_ERROR == ((_flags) & NS_MATHML_ERROR))
michael@0 319
michael@0 320 #define NS_MATHML_STRETCH_WAS_DONE(_flags) \
michael@0 321 (NS_MATHML_STRETCH_DONE == ((_flags) & NS_MATHML_STRETCH_DONE))
michael@0 322
michael@0 323 #define NS_MATHML_PAINT_BOUNDING_METRICS(_flags) \
michael@0 324 (NS_MATHML_SHOW_BOUNDING_METRICS == ((_flags) & NS_MATHML_SHOW_BOUNDING_METRICS))
michael@0 325
michael@0 326 // ==========================================================================
michael@0 327 // Bits used for the embellish flags -- these bits are set
michael@0 328 // in their relevant situation as they become available
michael@0 329
michael@0 330 // This bit is set if the frame is an embellished operator.
michael@0 331 #define NS_MATHML_EMBELLISH_OPERATOR 0x00000001
michael@0 332
michael@0 333 // This bit is set if the frame is an <mo> frame or an embellihsed
michael@0 334 // operator for which the core <mo> has movablelimits="true"
michael@0 335 #define NS_MATHML_EMBELLISH_MOVABLELIMITS 0x00000002
michael@0 336
michael@0 337 // This bit is set if the frame is an <mo> frame or an embellihsed
michael@0 338 // operator for which the core <mo> has accent="true"
michael@0 339 #define NS_MATHML_EMBELLISH_ACCENT 0x00000004
michael@0 340
michael@0 341 // This bit is set if the frame is an <mover> or <munderover> with
michael@0 342 // an accent frame
michael@0 343 #define NS_MATHML_EMBELLISH_ACCENTOVER 0x00000008
michael@0 344
michael@0 345 // This bit is set if the frame is an <munder> or <munderover> with
michael@0 346 // an accentunder frame
michael@0 347 #define NS_MATHML_EMBELLISH_ACCENTUNDER 0x00000010
michael@0 348
michael@0 349 // Macros that retrieve those bits
michael@0 350
michael@0 351 #define NS_MATHML_IS_EMBELLISH_OPERATOR(_flags) \
michael@0 352 (NS_MATHML_EMBELLISH_OPERATOR == ((_flags) & NS_MATHML_EMBELLISH_OPERATOR))
michael@0 353
michael@0 354 #define NS_MATHML_EMBELLISH_IS_MOVABLELIMITS(_flags) \
michael@0 355 (NS_MATHML_EMBELLISH_MOVABLELIMITS == ((_flags) & NS_MATHML_EMBELLISH_MOVABLELIMITS))
michael@0 356
michael@0 357 #define NS_MATHML_EMBELLISH_IS_ACCENT(_flags) \
michael@0 358 (NS_MATHML_EMBELLISH_ACCENT == ((_flags) & NS_MATHML_EMBELLISH_ACCENT))
michael@0 359
michael@0 360 #define NS_MATHML_EMBELLISH_IS_ACCENTOVER(_flags) \
michael@0 361 (NS_MATHML_EMBELLISH_ACCENTOVER == ((_flags) & NS_MATHML_EMBELLISH_ACCENTOVER))
michael@0 362
michael@0 363 #define NS_MATHML_EMBELLISH_IS_ACCENTUNDER(_flags) \
michael@0 364 (NS_MATHML_EMBELLISH_ACCENTUNDER == ((_flags) & NS_MATHML_EMBELLISH_ACCENTUNDER))
michael@0 365
michael@0 366 #endif /* nsIMathMLFrame_h___ */

mercurial