layout/generic/nsHTMLReflowMetrics.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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 /* struct containing the output from nsIFrame::Reflow */
michael@0 7
michael@0 8 #ifndef nsHTMLReflowMetrics_h___
michael@0 9 #define nsHTMLReflowMetrics_h___
michael@0 10
michael@0 11 #include "nsRect.h"
michael@0 12 #include "nsBoundingMetrics.h"
michael@0 13 #include "WritingModes.h"
michael@0 14
michael@0 15 //----------------------------------------------------------------------
michael@0 16
michael@0 17 class nsHTMLReflowState;
michael@0 18
michael@0 19 // Option flags
michael@0 20 #define NS_REFLOW_CALC_BOUNDING_METRICS 0x0001
michael@0 21
michael@0 22 /**
michael@0 23 * When we store overflow areas as an array of scrollable and visual
michael@0 24 * overflow, we use these indices.
michael@0 25 *
michael@0 26 * eOverflowType_LENGTH is needed (for gcc 4.5.*, at least) to ensure
michael@0 27 * that 2 is a valid value of nsOverflowType for use in
michael@0 28 * NS_FOR_FRAME_OVERFLOW_TYPES.
michael@0 29 */
michael@0 30 enum nsOverflowType { eVisualOverflow, eScrollableOverflow,
michael@0 31 eOverflowType_LENGTH };
michael@0 32
michael@0 33 #define NS_FOR_FRAME_OVERFLOW_TYPES(var_) \
michael@0 34 for (nsOverflowType var_ = nsOverflowType(0); var_ < 2; \
michael@0 35 var_ = nsOverflowType(var_ + 1))
michael@0 36
michael@0 37 struct nsOverflowAreas {
michael@0 38 private:
michael@0 39 nsRect mRects[2];
michael@0 40 public:
michael@0 41 nsRect& Overflow(size_t aIndex) {
michael@0 42 NS_ASSERTION(aIndex < 2, "index out of range");
michael@0 43 return mRects[aIndex];
michael@0 44 }
michael@0 45 const nsRect& Overflow(size_t aIndex) const {
michael@0 46 NS_ASSERTION(aIndex < 2, "index out of range");
michael@0 47 return mRects[aIndex];
michael@0 48 }
michael@0 49
michael@0 50 nsRect& VisualOverflow() { return mRects[eVisualOverflow]; }
michael@0 51 const nsRect& VisualOverflow() const { return mRects[eVisualOverflow]; }
michael@0 52
michael@0 53 nsRect& ScrollableOverflow() { return mRects[eScrollableOverflow]; }
michael@0 54 const nsRect& ScrollableOverflow() const { return mRects[eScrollableOverflow]; }
michael@0 55
michael@0 56 nsOverflowAreas() {
michael@0 57 // default-initializes to zero due to nsRect's default constructor
michael@0 58 }
michael@0 59
michael@0 60 nsOverflowAreas(const nsRect& aVisualOverflow,
michael@0 61 const nsRect& aScrollableOverflow)
michael@0 62 {
michael@0 63 mRects[eVisualOverflow] = aVisualOverflow;
michael@0 64 mRects[eScrollableOverflow] = aScrollableOverflow;
michael@0 65 }
michael@0 66
michael@0 67 nsOverflowAreas(const nsOverflowAreas& aOther) {
michael@0 68 *this = aOther;
michael@0 69 }
michael@0 70
michael@0 71 nsOverflowAreas& operator=(const nsOverflowAreas& aOther) {
michael@0 72 mRects[0] = aOther.mRects[0];
michael@0 73 mRects[1] = aOther.mRects[1];
michael@0 74 return *this;
michael@0 75 }
michael@0 76
michael@0 77 bool operator==(const nsOverflowAreas& aOther) const {
michael@0 78 // Scrollable overflow is a point-set rectangle and visual overflow
michael@0 79 // is a pixel-set rectangle.
michael@0 80 return VisualOverflow().IsEqualInterior(aOther.VisualOverflow()) &&
michael@0 81 ScrollableOverflow().IsEqualEdges(aOther.ScrollableOverflow());
michael@0 82 }
michael@0 83
michael@0 84 bool operator!=(const nsOverflowAreas& aOther) const {
michael@0 85 return !(*this == aOther);
michael@0 86 }
michael@0 87
michael@0 88 nsOverflowAreas operator+(const nsPoint& aPoint) const {
michael@0 89 nsOverflowAreas result(*this);
michael@0 90 result += aPoint;
michael@0 91 return result;
michael@0 92 }
michael@0 93
michael@0 94 nsOverflowAreas& operator+=(const nsPoint& aPoint) {
michael@0 95 mRects[0] += aPoint;
michael@0 96 mRects[1] += aPoint;
michael@0 97 return *this;
michael@0 98 }
michael@0 99
michael@0 100 void Clear() {
michael@0 101 mRects[0].SetRect(0, 0, 0, 0);
michael@0 102 mRects[1].SetRect(0, 0, 0, 0);
michael@0 103 }
michael@0 104
michael@0 105 // Mutates |this| by unioning both overflow areas with |aOther|.
michael@0 106 void UnionWith(const nsOverflowAreas& aOther);
michael@0 107
michael@0 108 // Mutates |this| by unioning both overflow areas with |aRect|.
michael@0 109 void UnionAllWith(const nsRect& aRect);
michael@0 110
michael@0 111 // Mutates |this| by setting both overflow areas to |aRect|.
michael@0 112 void SetAllTo(const nsRect& aRect);
michael@0 113 };
michael@0 114
michael@0 115 /**
michael@0 116 * An nsCollapsingMargin represents a vertical collapsing margin between
michael@0 117 * blocks as described in section 8.3.1 of CSS2,
michael@0 118 * <URL: http://www.w3.org/TR/REC-CSS2/box.html#collapsing-margins >.
michael@0 119 *
michael@0 120 * All adjacent vertical margins collapse, and the resulting margin is
michael@0 121 * the sum of the largest positive margin included and the smallest (most
michael@0 122 * negative) negative margin included.
michael@0 123 */
michael@0 124 struct nsCollapsingMargin {
michael@0 125 private:
michael@0 126 nscoord mMostPos; // the largest positive margin included
michael@0 127 nscoord mMostNeg; // the smallest negative margin included
michael@0 128
michael@0 129 public:
michael@0 130 nsCollapsingMargin()
michael@0 131 : mMostPos(0),
michael@0 132 mMostNeg(0)
michael@0 133 {
michael@0 134 }
michael@0 135
michael@0 136 nsCollapsingMargin(const nsCollapsingMargin& aOther)
michael@0 137 : mMostPos(aOther.mMostPos),
michael@0 138 mMostNeg(aOther.mMostNeg)
michael@0 139 {
michael@0 140 }
michael@0 141
michael@0 142 bool operator==(const nsCollapsingMargin& aOther)
michael@0 143 {
michael@0 144 return mMostPos == aOther.mMostPos &&
michael@0 145 mMostNeg == aOther.mMostNeg;
michael@0 146 }
michael@0 147
michael@0 148 bool operator!=(const nsCollapsingMargin& aOther)
michael@0 149 {
michael@0 150 return !(*this == aOther);
michael@0 151 }
michael@0 152
michael@0 153 nsCollapsingMargin& operator=(const nsCollapsingMargin& aOther)
michael@0 154 {
michael@0 155 mMostPos = aOther.mMostPos;
michael@0 156 mMostNeg = aOther.mMostNeg;
michael@0 157 return *this;
michael@0 158 }
michael@0 159
michael@0 160 void Include(nscoord aCoord)
michael@0 161 {
michael@0 162 if (aCoord > mMostPos)
michael@0 163 mMostPos = aCoord;
michael@0 164 else if (aCoord < mMostNeg)
michael@0 165 mMostNeg = aCoord;
michael@0 166 }
michael@0 167
michael@0 168 void Include(const nsCollapsingMargin& aOther)
michael@0 169 {
michael@0 170 if (aOther.mMostPos > mMostPos)
michael@0 171 mMostPos = aOther.mMostPos;
michael@0 172 if (aOther.mMostNeg < mMostNeg)
michael@0 173 mMostNeg = aOther.mMostNeg;
michael@0 174 }
michael@0 175
michael@0 176 void Zero()
michael@0 177 {
michael@0 178 mMostPos = 0;
michael@0 179 mMostNeg = 0;
michael@0 180 }
michael@0 181
michael@0 182 bool IsZero() const
michael@0 183 {
michael@0 184 return (mMostPos == 0) && (mMostNeg == 0);
michael@0 185 }
michael@0 186
michael@0 187 nscoord get() const
michael@0 188 {
michael@0 189 return mMostPos + mMostNeg;
michael@0 190 }
michael@0 191 };
michael@0 192
michael@0 193 /**
michael@0 194 * Reflow metrics used to return the frame's desired size and alignment
michael@0 195 * information.
michael@0 196 *
michael@0 197 * @see #Reflow()
michael@0 198 */
michael@0 199 class nsHTMLReflowMetrics {
michael@0 200 public:
michael@0 201 // XXXldb Should |aFlags| generally be passed from parent to child?
michael@0 202 // Some places do it, and some don't. |aFlags| should perhaps go away
michael@0 203 // entirely.
michael@0 204 // XXX width/height/ascent are OUT parameters and so they shouldn't
michael@0 205 // have to be initialized, but there are some bad frame classes that
michael@0 206 // aren't properly setting them when returning from Reflow()...
michael@0 207 nsHTMLReflowMetrics(mozilla::WritingMode aWritingMode, uint32_t aFlags = 0)
michael@0 208 : mISize(0)
michael@0 209 , mBSize(0)
michael@0 210 , mBlockStartAscent(ASK_FOR_BASELINE)
michael@0 211 , mFlags(aFlags)
michael@0 212 , mWritingMode(aWritingMode)
michael@0 213 {}
michael@0 214
michael@0 215 nsHTMLReflowMetrics(const nsHTMLReflowState& aState, uint32_t aFlags = 0);
michael@0 216
michael@0 217 // ISize and BSize are logical-coordinate dimensions:
michael@0 218 // ISize is the size in the writing mode's inline direction (which equates to
michael@0 219 // width in horizontal writing modes, height in vertical ones), and BSize is
michael@0 220 // the size in the block-progression direction.
michael@0 221 nscoord ISize() const { return mISize; }
michael@0 222 nscoord BSize() const { return mBSize; }
michael@0 223
michael@0 224 nscoord& ISize() { return mISize; }
michael@0 225 nscoord& BSize() { return mBSize; }
michael@0 226
michael@0 227 // Width and Height are physical dimensions, independent of writing mode.
michael@0 228 // Accessing these is slightly more expensive than accessing the logical
michael@0 229 // dimensions (once vertical writing mode support is enabled); as far as
michael@0 230 // possible, client code should work purely with logical dimensions.
michael@0 231 nscoord Width() const { return mWritingMode.IsVertical() ? mBSize : mISize; }
michael@0 232 nscoord Height() const { return mWritingMode.IsVertical() ? mISize : mBSize; }
michael@0 233
michael@0 234 // It's only meaningful to consider "ascent" on the block-start side of the
michael@0 235 // frame; asking for the "ascent" on any other side will just return zero.
michael@0 236 nscoord TopAscent() const
michael@0 237 {
michael@0 238 return mWritingMode.IsVertical() ? 0 : mBlockStartAscent;
michael@0 239 }
michael@0 240 nscoord LeftAscent() const
michael@0 241 {
michael@0 242 return mWritingMode.IsVertical() && mWritingMode.IsVerticalLR() ?
michael@0 243 mBlockStartAscent : 0;
michael@0 244 }
michael@0 245 nscoord RightAscent() const
michael@0 246 {
michael@0 247 return mWritingMode.IsVertical() && !mWritingMode.IsVerticalLR() ?
michael@0 248 mBlockStartAscent : 0;
michael@0 249 }
michael@0 250
michael@0 251 nscoord& Width() { return mWritingMode.IsVertical() ? mBSize : mISize; }
michael@0 252 nscoord& Height() { return mWritingMode.IsVertical() ? mISize : mBSize; }
michael@0 253
michael@0 254 // To set the ascent value, we must be sure we're working with the correct
michael@0 255 // writing mode, so either pass it to the logical setter...
michael@0 256 void SetBlockStartAscent(mozilla::WritingMode aWritingMode, nscoord aAscent)
michael@0 257 {
michael@0 258 NS_ASSERTION(aWritingMode == mWritingMode, "writing mode mismatch");
michael@0 259 mBlockStartAscent = aAscent;
michael@0 260 }
michael@0 261 // ...or call the appropriate physical setter (these will probably be removed
michael@0 262 // eventually).
michael@0 263 void SetTopAscent(nscoord aAscent)
michael@0 264 {
michael@0 265 NS_ASSERTION(!mWritingMode.IsVertical(), "writing mode mismatch");
michael@0 266 mBlockStartAscent = aAscent;
michael@0 267 }
michael@0 268 void SetLeftAscent(nscoord aAscent)
michael@0 269 {
michael@0 270 NS_ASSERTION(mWritingMode.IsVertical() && mWritingMode.IsVerticalLR(),
michael@0 271 "writing mode mismatch");
michael@0 272 mBlockStartAscent = aAscent;
michael@0 273 }
michael@0 274 void SetRightAscent(nscoord aAscent)
michael@0 275 {
michael@0 276 NS_ASSERTION(mWritingMode.IsVertical() && !mWritingMode.IsVerticalLR(),
michael@0 277 "writing mode mismatch");
michael@0 278 mBlockStartAscent = aAscent;
michael@0 279 }
michael@0 280
michael@0 281 enum { ASK_FOR_BASELINE = nscoord_MAX };
michael@0 282
michael@0 283 // Metrics that _exactly_ enclose the text to allow precise MathML placements.
michael@0 284 // If the NS_REFLOW_CALC_BOUNDING_METRICS flag is set, then the caller is
michael@0 285 // requesting that you also compute additional details about your inner
michael@0 286 // bounding box and italic correction. For example, the bounding box of
michael@0 287 // msup is the smallest rectangle that _exactly_ encloses both the text
michael@0 288 // of the base and the text of the superscript.
michael@0 289 nsBoundingMetrics mBoundingMetrics; // [OUT]
michael@0 290
michael@0 291 // Carried out bottom margin values. This is the collapsed
michael@0 292 // (generational) bottom margin value.
michael@0 293 nsCollapsingMargin mCarriedOutBottomMargin;
michael@0 294
michael@0 295 // For frames that have content that overflow their content area
michael@0 296 // (HasOverflowAreas() is true) these rectangles represent the total
michael@0 297 // area of the frame including visible overflow, i.e., don't include
michael@0 298 // overflowing content that is hidden. The rects are in the local
michael@0 299 // coordinate space of the frame, and should be at least as big as the
michael@0 300 // desired size. If there is no content that overflows, then the
michael@0 301 // overflow area is identical to the desired size and should be {0, 0,
michael@0 302 // width, height}.
michael@0 303 nsOverflowAreas mOverflowAreas;
michael@0 304
michael@0 305 nsRect& VisualOverflow()
michael@0 306 { return mOverflowAreas.VisualOverflow(); }
michael@0 307 const nsRect& VisualOverflow() const
michael@0 308 { return mOverflowAreas.VisualOverflow(); }
michael@0 309 nsRect& ScrollableOverflow()
michael@0 310 { return mOverflowAreas.ScrollableOverflow(); }
michael@0 311 const nsRect& ScrollableOverflow() const
michael@0 312 { return mOverflowAreas.ScrollableOverflow(); }
michael@0 313
michael@0 314 // Set all of mOverflowAreas to (0, 0, width, height).
michael@0 315 void SetOverflowAreasToDesiredBounds();
michael@0 316
michael@0 317 // Union all of mOverflowAreas with (0, 0, width, height).
michael@0 318 void UnionOverflowAreasWithDesiredBounds();
michael@0 319
michael@0 320 mozilla::WritingMode GetWritingMode() const { return mWritingMode; }
michael@0 321
michael@0 322 private:
michael@0 323 nscoord mISize, mBSize; // [OUT] desired width and height (border-box)
michael@0 324 nscoord mBlockStartAscent; // [OUT] baseline (in Block direction), or ASK_FOR_BASELINE
michael@0 325
michael@0 326 public:
michael@0 327 uint32_t mFlags;
michael@0 328
michael@0 329 private:
michael@0 330 mozilla::WritingMode mWritingMode;
michael@0 331 };
michael@0 332
michael@0 333 #endif /* nsHTMLReflowMetrics_h___ */

mercurial