layout/style/nsStyleStruct.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/style/nsStyleStruct.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,3308 @@
     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 + * structs that contain the data provided by nsStyleContext, the
    1.11 + * internal API for computed style data for an element
    1.12 + */
    1.13 +
    1.14 +#include "nsStyleStruct.h"
    1.15 +#include "nsStyleStructInlines.h"
    1.16 +#include "nsStyleConsts.h"
    1.17 +#include "nsThemeConstants.h"
    1.18 +#include "nsString.h"
    1.19 +#include "nsPresContext.h"
    1.20 +#include "nsIWidget.h"
    1.21 +#include "nsCRTGlue.h"
    1.22 +#include "nsCSSProps.h"
    1.23 +
    1.24 +#include "nsCOMPtr.h"
    1.25 +
    1.26 +#include "nsBidiUtils.h"
    1.27 +#include "nsLayoutUtils.h"
    1.28 +
    1.29 +#include "imgIRequest.h"
    1.30 +#include "imgIContainer.h"
    1.31 +
    1.32 +#include "mozilla/Likely.h"
    1.33 +#include "nsIURI.h"
    1.34 +#include "nsIDocument.h"
    1.35 +#include <algorithm>
    1.36 +
    1.37 +static_assert((((1 << nsStyleStructID_Length) - 1) &
    1.38 +               ~(NS_STYLE_INHERIT_MASK)) == 0,
    1.39 +              "Not enough bits in NS_STYLE_INHERIT_MASK");
    1.40 +
    1.41 +inline bool IsFixedUnit(const nsStyleCoord& aCoord, bool aEnumOK)
    1.42 +{
    1.43 +  return aCoord.ConvertsToLength() || 
    1.44 +         (aEnumOK && aCoord.GetUnit() == eStyleUnit_Enumerated);
    1.45 +}
    1.46 +
    1.47 +static bool EqualURIs(nsIURI *aURI1, nsIURI *aURI2)
    1.48 +{
    1.49 +  bool eq;
    1.50 +  return aURI1 == aURI2 ||    // handle null==null, and optimize
    1.51 +         (aURI1 && aURI2 &&
    1.52 +          NS_SUCCEEDED(aURI1->Equals(aURI2, &eq)) && // not equal on fail
    1.53 +          eq);
    1.54 +}
    1.55 +
    1.56 +static bool EqualURIs(mozilla::css::URLValue *aURI1, mozilla::css::URLValue *aURI2)
    1.57 +{
    1.58 +  return aURI1 == aURI2 ||    // handle null==null, and optimize
    1.59 +         (aURI1 && aURI2 && aURI1->URIEquals(*aURI2));
    1.60 +}
    1.61 +
    1.62 +static bool EqualImages(imgIRequest *aImage1, imgIRequest* aImage2)
    1.63 +{
    1.64 +  if (aImage1 == aImage2) {
    1.65 +    return true;
    1.66 +  }
    1.67 +
    1.68 +  if (!aImage1 || !aImage2) {
    1.69 +    return false;
    1.70 +  }
    1.71 +
    1.72 +  nsCOMPtr<nsIURI> uri1, uri2;
    1.73 +  aImage1->GetURI(getter_AddRefs(uri1));
    1.74 +  aImage2->GetURI(getter_AddRefs(uri2));
    1.75 +  return EqualURIs(uri1, uri2);
    1.76 +}
    1.77 +
    1.78 +// A nullsafe wrapper for strcmp. We depend on null-safety.
    1.79 +static int safe_strcmp(const char16_t* a, const char16_t* b)
    1.80 +{
    1.81 +  if (!a || !b) {
    1.82 +    return (int)(a - b);
    1.83 +  }
    1.84 +  return NS_strcmp(a, b);
    1.85 +}
    1.86 +
    1.87 +static nsChangeHint CalcShadowDifference(nsCSSShadowArray* lhs,
    1.88 +                                         nsCSSShadowArray* rhs);
    1.89 +
    1.90 +// --------------------
    1.91 +// nsStyleFont
    1.92 +//
    1.93 +nsStyleFont::nsStyleFont(const nsFont& aFont, nsPresContext *aPresContext)
    1.94 +  : mFont(aFont)
    1.95 +  , mGenericID(kGenericFont_NONE)
    1.96 +  , mExplicitLanguage(false)
    1.97 +{
    1.98 +  MOZ_COUNT_CTOR(nsStyleFont);
    1.99 +  Init(aPresContext);
   1.100 +}
   1.101 +
   1.102 +nsStyleFont::nsStyleFont(const nsStyleFont& aSrc)
   1.103 +  : mFont(aSrc.mFont)
   1.104 +  , mSize(aSrc.mSize)
   1.105 +  , mGenericID(aSrc.mGenericID)
   1.106 +  , mScriptLevel(aSrc.mScriptLevel)
   1.107 +  , mMathVariant(aSrc.mMathVariant)
   1.108 +  , mMathDisplay(aSrc.mMathDisplay)
   1.109 +  , mExplicitLanguage(aSrc.mExplicitLanguage)
   1.110 +  , mAllowZoom(aSrc.mAllowZoom)
   1.111 +  , mScriptUnconstrainedSize(aSrc.mScriptUnconstrainedSize)
   1.112 +  , mScriptMinSize(aSrc.mScriptMinSize)
   1.113 +  , mScriptSizeMultiplier(aSrc.mScriptSizeMultiplier)
   1.114 +  , mLanguage(aSrc.mLanguage)
   1.115 +{
   1.116 +  MOZ_COUNT_CTOR(nsStyleFont);
   1.117 +}
   1.118 +
   1.119 +nsStyleFont::nsStyleFont(nsPresContext* aPresContext)
   1.120 +  // passing nullptr to GetDefaultFont make it use the doc language
   1.121 +  : mFont(*(aPresContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID,
   1.122 +                                         nullptr)))
   1.123 +  , mGenericID(kGenericFont_NONE)
   1.124 +  , mExplicitLanguage(false)
   1.125 +{
   1.126 +  MOZ_COUNT_CTOR(nsStyleFont);
   1.127 +  Init(aPresContext);
   1.128 +}
   1.129 +
   1.130 +void
   1.131 +nsStyleFont::Init(nsPresContext* aPresContext)
   1.132 +{
   1.133 +  mSize = mFont.size = nsStyleFont::ZoomText(aPresContext, mFont.size);
   1.134 +  mScriptUnconstrainedSize = mSize;
   1.135 +  mScriptMinSize = aPresContext->CSSTwipsToAppUnits(
   1.136 +      NS_POINTS_TO_TWIPS(NS_MATHML_DEFAULT_SCRIPT_MIN_SIZE_PT));
   1.137 +  mScriptLevel = 0;
   1.138 +  mScriptSizeMultiplier = NS_MATHML_DEFAULT_SCRIPT_SIZE_MULTIPLIER;
   1.139 +  mMathVariant = NS_MATHML_MATHVARIANT_NONE;
   1.140 +  mMathDisplay = NS_MATHML_DISPLAYSTYLE_INLINE;
   1.141 +  mAllowZoom = true;
   1.142 +
   1.143 +  nsAutoString language;
   1.144 +  aPresContext->Document()->GetContentLanguage(language);
   1.145 +  language.StripWhitespace();
   1.146 +
   1.147 +  // Content-Language may be a comma-separated list of language codes,
   1.148 +  // in which case the HTML5 spec says to treat it as unknown
   1.149 +  if (!language.IsEmpty() &&
   1.150 +      language.FindChar(char16_t(',')) == kNotFound) {
   1.151 +    mLanguage = do_GetAtom(language);
   1.152 +    // NOTE:  This does *not* count as an explicit language; in other
   1.153 +    // words, it doesn't trigger language-specific hyphenation.
   1.154 +  } else {
   1.155 +    // we didn't find a (usable) Content-Language, so we fall back
   1.156 +    // to whatever the presContext guessed from the charset
   1.157 +    mLanguage = aPresContext->GetLanguageFromCharset();
   1.158 +  }
   1.159 +}
   1.160 +
   1.161 +void* 
   1.162 +nsStyleFont::operator new(size_t sz, nsPresContext* aContext) CPP_THROW_NEW {
   1.163 +  void* result = aContext->AllocateFromShell(sz);
   1.164 +  if (result)
   1.165 +    memset(result, 0, sz);
   1.166 +  return result;
   1.167 +}
   1.168 +  
   1.169 +void 
   1.170 +nsStyleFont::Destroy(nsPresContext* aContext) {
   1.171 +  this->~nsStyleFont();
   1.172 +  aContext->FreeToShell(sizeof(nsStyleFont), this);
   1.173 +}
   1.174 +
   1.175 +void
   1.176 +nsStyleFont::EnableZoom(nsPresContext* aContext, bool aEnable)
   1.177 +{
   1.178 +  if (mAllowZoom == aEnable) {
   1.179 +    return;
   1.180 +  }
   1.181 +  mAllowZoom = aEnable;
   1.182 +  if (mAllowZoom) {
   1.183 +    mSize = nsStyleFont::ZoomText(aContext, mSize);
   1.184 +    mFont.size = nsStyleFont::ZoomText(aContext, mFont.size);
   1.185 +    mScriptUnconstrainedSize =
   1.186 +      nsStyleFont::ZoomText(aContext, mScriptUnconstrainedSize);
   1.187 +  } else {
   1.188 +    mSize = nsStyleFont::UnZoomText(aContext, mSize);
   1.189 +    mFont.size = nsStyleFont::UnZoomText(aContext, mFont.size);
   1.190 +    mScriptUnconstrainedSize =
   1.191 +      nsStyleFont::UnZoomText(aContext, mScriptUnconstrainedSize);
   1.192 +  }
   1.193 +}
   1.194 +
   1.195 +nsChangeHint nsStyleFont::CalcDifference(const nsStyleFont& aOther) const
   1.196 +{
   1.197 +  MOZ_ASSERT(mAllowZoom == aOther.mAllowZoom,
   1.198 +             "expected mAllowZoom to be the same on both nsStyleFonts");
   1.199 +  if (mSize != aOther.mSize ||
   1.200 +      mLanguage != aOther.mLanguage ||
   1.201 +      mExplicitLanguage != aOther.mExplicitLanguage ||
   1.202 +      mMathVariant != aOther.mMathVariant ||
   1.203 +      mMathDisplay != aOther.mMathDisplay) {
   1.204 +    return NS_STYLE_HINT_REFLOW;
   1.205 +  }
   1.206 +  return CalcFontDifference(mFont, aOther.mFont);
   1.207 +}
   1.208 +
   1.209 +/* static */ nscoord
   1.210 +nsStyleFont::ZoomText(nsPresContext *aPresContext, nscoord aSize)
   1.211 +{
   1.212 +  return nscoord(float(aSize) * aPresContext->TextZoom());
   1.213 +}
   1.214 +
   1.215 +/* static */ nscoord
   1.216 +nsStyleFont::UnZoomText(nsPresContext *aPresContext, nscoord aSize)
   1.217 +{
   1.218 +  return nscoord(float(aSize) / aPresContext->TextZoom());
   1.219 +}
   1.220 +
   1.221 +nsChangeHint nsStyleFont::CalcFontDifference(const nsFont& aFont1, const nsFont& aFont2)
   1.222 +{
   1.223 +  if ((aFont1.size == aFont2.size) && 
   1.224 +      (aFont1.sizeAdjust == aFont2.sizeAdjust) && 
   1.225 +      (aFont1.style == aFont2.style) &&
   1.226 +      (aFont1.variant == aFont2.variant) &&
   1.227 +      (aFont1.weight == aFont2.weight) &&
   1.228 +      (aFont1.stretch == aFont2.stretch) &&
   1.229 +      (aFont1.smoothing == aFont2.smoothing) &&
   1.230 +      (aFont1.name == aFont2.name) &&
   1.231 +      (aFont1.kerning == aFont2.kerning) &&
   1.232 +      (aFont1.synthesis == aFont2.synthesis) &&
   1.233 +      (aFont1.variantAlternates == aFont2.variantAlternates) &&
   1.234 +      (aFont1.alternateValues == aFont2.alternateValues) &&
   1.235 +      (aFont1.featureValueLookup == aFont2.featureValueLookup) &&
   1.236 +      (aFont1.variantCaps == aFont2.variantCaps) &&
   1.237 +      (aFont1.variantEastAsian == aFont2.variantEastAsian) &&
   1.238 +      (aFont1.variantLigatures == aFont2.variantLigatures) &&
   1.239 +      (aFont1.variantNumeric == aFont2.variantNumeric) &&
   1.240 +      (aFont1.variantPosition == aFont2.variantPosition) &&
   1.241 +      (aFont1.fontFeatureSettings == aFont2.fontFeatureSettings) &&
   1.242 +      (aFont1.languageOverride == aFont2.languageOverride) &&
   1.243 +      (aFont1.systemFont == aFont2.systemFont)) {
   1.244 +    if ((aFont1.decorations == aFont2.decorations)) {
   1.245 +      return NS_STYLE_HINT_NONE;
   1.246 +    }
   1.247 +    return NS_STYLE_HINT_VISUAL;
   1.248 +  }
   1.249 +  return NS_STYLE_HINT_REFLOW;
   1.250 +}
   1.251 +
   1.252 +static bool IsFixedData(const nsStyleSides& aSides, bool aEnumOK)
   1.253 +{
   1.254 +  NS_FOR_CSS_SIDES(side) {
   1.255 +    if (!IsFixedUnit(aSides.Get(side), aEnumOK))
   1.256 +      return false;
   1.257 +  }
   1.258 +  return true;
   1.259 +}
   1.260 +
   1.261 +static nscoord CalcCoord(const nsStyleCoord& aCoord, 
   1.262 +                         const nscoord* aEnumTable, 
   1.263 +                         int32_t aNumEnums)
   1.264 +{
   1.265 +  if (aCoord.GetUnit() == eStyleUnit_Enumerated) {
   1.266 +    NS_ABORT_IF_FALSE(aEnumTable, "must have enum table");
   1.267 +    int32_t value = aCoord.GetIntValue();
   1.268 +    if (0 <= value && value < aNumEnums) {
   1.269 +      return aEnumTable[aCoord.GetIntValue()];
   1.270 +    }
   1.271 +    NS_NOTREACHED("unexpected enum value");
   1.272 +    return 0;
   1.273 +  }
   1.274 +  NS_ABORT_IF_FALSE(aCoord.ConvertsToLength(), "unexpected unit");
   1.275 +  return nsRuleNode::ComputeCoordPercentCalc(aCoord, 0);
   1.276 +}
   1.277 +
   1.278 +nsStyleMargin::nsStyleMargin() {
   1.279 +  MOZ_COUNT_CTOR(nsStyleMargin);
   1.280 +  nsStyleCoord zero(0, nsStyleCoord::CoordConstructor);
   1.281 +  NS_FOR_CSS_SIDES(side) {
   1.282 +    mMargin.Set(side, zero);
   1.283 +  }
   1.284 +  mHasCachedMargin = false;
   1.285 +}
   1.286 +
   1.287 +nsStyleMargin::nsStyleMargin(const nsStyleMargin& aSrc) {
   1.288 +  MOZ_COUNT_CTOR(nsStyleMargin);
   1.289 +  mMargin = aSrc.mMargin;
   1.290 +  mHasCachedMargin = false;
   1.291 +}
   1.292 +
   1.293 +void* 
   1.294 +nsStyleMargin::operator new(size_t sz, nsPresContext* aContext) CPP_THROW_NEW {
   1.295 +  void* result = aContext->AllocateFromShell(sz);
   1.296 +  if (result)
   1.297 +    memset(result, 0, sz);
   1.298 +  return result;
   1.299 +}
   1.300 +  
   1.301 +void 
   1.302 +nsStyleMargin::Destroy(nsPresContext* aContext) {
   1.303 +  this->~nsStyleMargin();
   1.304 +  aContext->FreeToShell(sizeof(nsStyleMargin), this);
   1.305 +}
   1.306 +
   1.307 +
   1.308 +void nsStyleMargin::RecalcData()
   1.309 +{
   1.310 +  if (IsFixedData(mMargin, false)) {
   1.311 +    NS_FOR_CSS_SIDES(side) {
   1.312 +      mCachedMargin.Side(side) = CalcCoord(mMargin.Get(side), nullptr, 0);
   1.313 +    }
   1.314 +    mHasCachedMargin = true;
   1.315 +  }
   1.316 +  else
   1.317 +    mHasCachedMargin = false;
   1.318 +}
   1.319 +
   1.320 +nsChangeHint nsStyleMargin::CalcDifference(const nsStyleMargin& aOther) const
   1.321 +{
   1.322 +  if (mMargin == aOther.mMargin) {
   1.323 +    return NS_STYLE_HINT_NONE;
   1.324 +  }
   1.325 +  // Margin differences can't affect descendant intrinsic sizes and
   1.326 +  // don't need to force children to reflow.
   1.327 +  return NS_CombineHint(nsChangeHint_NeedReflow,
   1.328 +                        nsChangeHint_ClearAncestorIntrinsics);
   1.329 +}
   1.330 +
   1.331 +nsStylePadding::nsStylePadding() {
   1.332 +  MOZ_COUNT_CTOR(nsStylePadding);
   1.333 +  nsStyleCoord zero(0, nsStyleCoord::CoordConstructor);
   1.334 +  NS_FOR_CSS_SIDES(side) {
   1.335 +    mPadding.Set(side, zero);
   1.336 +  }
   1.337 +  mHasCachedPadding = false;
   1.338 +}
   1.339 +
   1.340 +nsStylePadding::nsStylePadding(const nsStylePadding& aSrc) {
   1.341 +  MOZ_COUNT_CTOR(nsStylePadding);
   1.342 +  mPadding = aSrc.mPadding;
   1.343 +  mHasCachedPadding = false;
   1.344 +}
   1.345 +
   1.346 +void* 
   1.347 +nsStylePadding::operator new(size_t sz, nsPresContext* aContext) CPP_THROW_NEW {
   1.348 +  void* result = aContext->AllocateFromShell(sz);
   1.349 +  if (result)
   1.350 +    memset(result, 0, sz);
   1.351 +  return result;
   1.352 +}
   1.353 +  
   1.354 +void 
   1.355 +nsStylePadding::Destroy(nsPresContext* aContext) {
   1.356 +  this->~nsStylePadding();
   1.357 +  aContext->FreeToShell(sizeof(nsStylePadding), this);
   1.358 +}
   1.359 +
   1.360 +void nsStylePadding::RecalcData()
   1.361 +{
   1.362 +  if (IsFixedData(mPadding, false)) {
   1.363 +    NS_FOR_CSS_SIDES(side) {
   1.364 +      // Clamp negative calc() to 0.
   1.365 +      mCachedPadding.Side(side) =
   1.366 +        std::max(CalcCoord(mPadding.Get(side), nullptr, 0), 0);
   1.367 +    }
   1.368 +    mHasCachedPadding = true;
   1.369 +  }
   1.370 +  else
   1.371 +    mHasCachedPadding = false;
   1.372 +}
   1.373 +
   1.374 +nsChangeHint nsStylePadding::CalcDifference(const nsStylePadding& aOther) const
   1.375 +{
   1.376 +  if (mPadding == aOther.mPadding) {
   1.377 +    return NS_STYLE_HINT_NONE;
   1.378 +  }
   1.379 +  // Padding differences can't affect descendant intrinsic sizes, but do need
   1.380 +  // to force children to reflow so that we can reposition them, since their
   1.381 +  // offsets are from our frame bounds but our content rect's position within
   1.382 +  // those bounds is moving.
   1.383 +  return NS_SubtractHint(NS_STYLE_HINT_REFLOW,
   1.384 +                         nsChangeHint_ClearDescendantIntrinsics);
   1.385 +}
   1.386 +
   1.387 +nsStyleBorder::nsStyleBorder(nsPresContext* aPresContext)
   1.388 +  : mBorderColors(nullptr),
   1.389 +    mBoxShadow(nullptr),
   1.390 +    mBorderImageFill(NS_STYLE_BORDER_IMAGE_SLICE_NOFILL),
   1.391 +    mBorderImageRepeatH(NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH),
   1.392 +    mBorderImageRepeatV(NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH),
   1.393 +    mFloatEdge(NS_STYLE_FLOAT_EDGE_CONTENT),
   1.394 +    mComputedBorder(0, 0, 0, 0)
   1.395 +{
   1.396 +  MOZ_COUNT_CTOR(nsStyleBorder);
   1.397 +
   1.398 +  NS_FOR_CSS_HALF_CORNERS (corner) {
   1.399 +    mBorderRadius.Set(corner, nsStyleCoord(0, nsStyleCoord::CoordConstructor));
   1.400 +  }
   1.401 +
   1.402 +  nscoord medium =
   1.403 +    (aPresContext->GetBorderWidthTable())[NS_STYLE_BORDER_WIDTH_MEDIUM];
   1.404 +  NS_FOR_CSS_SIDES(side) {
   1.405 +    mBorderImageSlice.Set(side, nsStyleCoord(1.0f, eStyleUnit_Percent));
   1.406 +    mBorderImageWidth.Set(side, nsStyleCoord(1.0f, eStyleUnit_Factor));
   1.407 +    mBorderImageOutset.Set(side, nsStyleCoord(0.0f, eStyleUnit_Factor));
   1.408 +
   1.409 +    mBorder.Side(side) = medium;
   1.410 +    mBorderStyle[side] = NS_STYLE_BORDER_STYLE_NONE | BORDER_COLOR_FOREGROUND;
   1.411 +    mBorderColor[side] = NS_RGB(0, 0, 0);
   1.412 +  }
   1.413 +
   1.414 +  mTwipsPerPixel = aPresContext->DevPixelsToAppUnits(1);
   1.415 +}
   1.416 +
   1.417 +nsBorderColors::~nsBorderColors()
   1.418 +{
   1.419 +  NS_CSS_DELETE_LIST_MEMBER(nsBorderColors, this, mNext);
   1.420 +}
   1.421 +
   1.422 +nsBorderColors*
   1.423 +nsBorderColors::Clone(bool aDeep) const
   1.424 +{
   1.425 +  nsBorderColors* result = new nsBorderColors(mColor);
   1.426 +  if (MOZ_UNLIKELY(!result))
   1.427 +    return result;
   1.428 +  if (aDeep)
   1.429 +    NS_CSS_CLONE_LIST_MEMBER(nsBorderColors, this, mNext, result, (false));
   1.430 +  return result;
   1.431 +}
   1.432 +
   1.433 +nsStyleBorder::nsStyleBorder(const nsStyleBorder& aSrc)
   1.434 +  : mBorderColors(nullptr),
   1.435 +    mBoxShadow(aSrc.mBoxShadow),
   1.436 +    mBorderRadius(aSrc.mBorderRadius),
   1.437 +    mBorderImageSource(aSrc.mBorderImageSource),
   1.438 +    mBorderImageSlice(aSrc.mBorderImageSlice),
   1.439 +    mBorderImageWidth(aSrc.mBorderImageWidth),
   1.440 +    mBorderImageOutset(aSrc.mBorderImageOutset),
   1.441 +    mBorderImageFill(aSrc.mBorderImageFill),
   1.442 +    mBorderImageRepeatH(aSrc.mBorderImageRepeatH),
   1.443 +    mBorderImageRepeatV(aSrc.mBorderImageRepeatV),
   1.444 +    mFloatEdge(aSrc.mFloatEdge),
   1.445 +    mComputedBorder(aSrc.mComputedBorder),
   1.446 +    mBorder(aSrc.mBorder),
   1.447 +    mTwipsPerPixel(aSrc.mTwipsPerPixel)
   1.448 +{
   1.449 +  MOZ_COUNT_CTOR(nsStyleBorder);
   1.450 +  if (aSrc.mBorderColors) {
   1.451 +    EnsureBorderColors();
   1.452 +    for (int32_t i = 0; i < 4; i++)
   1.453 +      if (aSrc.mBorderColors[i])
   1.454 +        mBorderColors[i] = aSrc.mBorderColors[i]->Clone();
   1.455 +      else
   1.456 +        mBorderColors[i] = nullptr;
   1.457 +  }
   1.458 +
   1.459 +  NS_FOR_CSS_SIDES(side) {
   1.460 +    mBorderStyle[side] = aSrc.mBorderStyle[side];
   1.461 +    mBorderColor[side] = aSrc.mBorderColor[side];
   1.462 +  }
   1.463 +}
   1.464 +
   1.465 +nsStyleBorder::~nsStyleBorder()
   1.466 +{
   1.467 +  MOZ_COUNT_DTOR(nsStyleBorder);
   1.468 +  if (mBorderColors) {
   1.469 +    for (int32_t i = 0; i < 4; i++)
   1.470 +      delete mBorderColors[i];
   1.471 +    delete [] mBorderColors;
   1.472 +  }
   1.473 +}
   1.474 +
   1.475 +void*
   1.476 +nsStyleBorder::operator new(size_t sz, nsPresContext* aContext) CPP_THROW_NEW {
   1.477 +  void* result = aContext->AllocateFromShell(sz);
   1.478 +  if (result)
   1.479 +    memset(result, 0, sz);
   1.480 +  return result;
   1.481 +}
   1.482 +
   1.483 +nsMargin
   1.484 +nsStyleBorder::GetImageOutset() const
   1.485 +{
   1.486 +  // We don't check whether there is a border-image (which is OK since
   1.487 +  // the initial values yields 0 outset) so that we don't have to
   1.488 +  // reflow to update overflow areas when an image loads.
   1.489 +  nsMargin outset;
   1.490 +  NS_FOR_CSS_SIDES(s) {
   1.491 +    nsStyleCoord coord = mBorderImageOutset.Get(s);
   1.492 +    nscoord value;
   1.493 +    switch (coord.GetUnit()) {
   1.494 +      case eStyleUnit_Coord:
   1.495 +        value = coord.GetCoordValue();
   1.496 +        break;
   1.497 +      case eStyleUnit_Factor:
   1.498 +        value = coord.GetFactorValue() * mComputedBorder.Side(s);
   1.499 +        break;
   1.500 +      default:
   1.501 +        NS_NOTREACHED("unexpected CSS unit for image outset");
   1.502 +        value = 0;
   1.503 +        break;
   1.504 +    }
   1.505 +    outset.Side(s) = value;
   1.506 +  }
   1.507 +  return outset;
   1.508 +}
   1.509 +
   1.510 +void
   1.511 +nsStyleBorder::Destroy(nsPresContext* aContext) {
   1.512 +  UntrackImage(aContext);
   1.513 +  this->~nsStyleBorder();
   1.514 +  aContext->FreeToShell(sizeof(nsStyleBorder), this);
   1.515 +}
   1.516 +
   1.517 +nsChangeHint nsStyleBorder::CalcDifference(const nsStyleBorder& aOther) const
   1.518 +{
   1.519 +  nsChangeHint shadowDifference =
   1.520 +    CalcShadowDifference(mBoxShadow, aOther.mBoxShadow);
   1.521 +  NS_ABORT_IF_FALSE(shadowDifference == unsigned(NS_STYLE_HINT_REFLOW) ||
   1.522 +                    shadowDifference == unsigned(NS_STYLE_HINT_VISUAL) ||
   1.523 +                    shadowDifference == unsigned(NS_STYLE_HINT_NONE),
   1.524 +                    "should do more with shadowDifference");
   1.525 +
   1.526 +  // Note that differences in mBorder don't affect rendering (which should only
   1.527 +  // use mComputedBorder), so don't need to be tested for here.
   1.528 +  // XXXbz we should be able to return a more specific change hint for
   1.529 +  // at least GetComputedBorder() differences...
   1.530 +  if (mTwipsPerPixel != aOther.mTwipsPerPixel ||
   1.531 +      GetComputedBorder() != aOther.GetComputedBorder() ||
   1.532 +      mFloatEdge != aOther.mFloatEdge ||
   1.533 +      mBorderImageOutset != aOther.mBorderImageOutset ||
   1.534 +      (shadowDifference & nsChangeHint_NeedReflow))
   1.535 +    return NS_STYLE_HINT_REFLOW;
   1.536 +
   1.537 +  NS_FOR_CSS_SIDES(ix) {
   1.538 +    // See the explanation in nsChangeHint.h of
   1.539 +    // nsChangeHint_BorderStyleNoneChange .
   1.540 +    // Furthermore, even though we know *this* side is 0 width, just
   1.541 +    // assume a visual hint for some other change rather than bother
   1.542 +    // tracking this result through the rest of the function.
   1.543 +    if (HasVisibleStyle(ix) != aOther.HasVisibleStyle(ix)) {
   1.544 +      return NS_CombineHint(NS_STYLE_HINT_VISUAL,
   1.545 +                            nsChangeHint_BorderStyleNoneChange);
   1.546 +    }
   1.547 +  }
   1.548 +
   1.549 +  // Note that mBorderStyle stores not only the border style but also
   1.550 +  // color-related flags.  Given that we've already done an mComputedBorder
   1.551 +  // comparison, border-style differences can only lead to a VISUAL hint.  So
   1.552 +  // it's OK to just compare the values directly -- if either the actual
   1.553 +  // style or the color flags differ we want to repaint.
   1.554 +  NS_FOR_CSS_SIDES(ix) {
   1.555 +    if (mBorderStyle[ix] != aOther.mBorderStyle[ix] || 
   1.556 +        mBorderColor[ix] != aOther.mBorderColor[ix])
   1.557 +      return NS_STYLE_HINT_VISUAL;
   1.558 +  }
   1.559 +
   1.560 +  if (mBorderRadius != aOther.mBorderRadius ||
   1.561 +      !mBorderColors != !aOther.mBorderColors)
   1.562 +    return NS_STYLE_HINT_VISUAL;
   1.563 +
   1.564 +  if (IsBorderImageLoaded() || aOther.IsBorderImageLoaded()) {
   1.565 +    if (mBorderImageSource  != aOther.mBorderImageSource  ||
   1.566 +        mBorderImageRepeatH != aOther.mBorderImageRepeatH ||
   1.567 +        mBorderImageRepeatV != aOther.mBorderImageRepeatV ||
   1.568 +        mBorderImageSlice   != aOther.mBorderImageSlice   ||
   1.569 +        mBorderImageFill    != aOther.mBorderImageFill    ||
   1.570 +        mBorderImageWidth   != aOther.mBorderImageWidth   ||
   1.571 +        mBorderImageOutset  != aOther.mBorderImageOutset)
   1.572 +      return NS_STYLE_HINT_VISUAL;
   1.573 +  }
   1.574 +
   1.575 +  // Note that at this point if mBorderColors is non-null so is
   1.576 +  // aOther.mBorderColors
   1.577 +  if (mBorderColors) {
   1.578 +    NS_FOR_CSS_SIDES(ix) {
   1.579 +      if (!nsBorderColors::Equal(mBorderColors[ix],
   1.580 +                                 aOther.mBorderColors[ix]))
   1.581 +        return NS_STYLE_HINT_VISUAL;
   1.582 +    }
   1.583 +  }
   1.584 +
   1.585 +  return shadowDifference;
   1.586 +}
   1.587 +
   1.588 +nsStyleOutline::nsStyleOutline(nsPresContext* aPresContext)
   1.589 +{
   1.590 +  MOZ_COUNT_CTOR(nsStyleOutline);
   1.591 +  // spacing values not inherited
   1.592 +  nsStyleCoord zero(0, nsStyleCoord::CoordConstructor);
   1.593 +  NS_FOR_CSS_HALF_CORNERS(corner) {
   1.594 +    mOutlineRadius.Set(corner, zero);
   1.595 +  }
   1.596 +
   1.597 +  mOutlineOffset = 0;
   1.598 +
   1.599 +  mOutlineWidth = nsStyleCoord(NS_STYLE_BORDER_WIDTH_MEDIUM, eStyleUnit_Enumerated);
   1.600 +  mOutlineStyle = NS_STYLE_BORDER_STYLE_NONE;
   1.601 +  mOutlineColor = NS_RGB(0, 0, 0);
   1.602 +
   1.603 +  mHasCachedOutline = false;
   1.604 +  mTwipsPerPixel = aPresContext->DevPixelsToAppUnits(1);
   1.605 +}
   1.606 +
   1.607 +nsStyleOutline::nsStyleOutline(const nsStyleOutline& aSrc) {
   1.608 +  MOZ_COUNT_CTOR(nsStyleOutline);
   1.609 +  memcpy((nsStyleOutline*)this, &aSrc, sizeof(nsStyleOutline));
   1.610 +}
   1.611 +
   1.612 +void 
   1.613 +nsStyleOutline::RecalcData(nsPresContext* aContext)
   1.614 +{
   1.615 +  if (NS_STYLE_BORDER_STYLE_NONE == GetOutlineStyle()) {
   1.616 +    mCachedOutlineWidth = 0;
   1.617 +    mHasCachedOutline = true;
   1.618 +  } else if (IsFixedUnit(mOutlineWidth, true)) {
   1.619 +    // Clamp negative calc() to 0.
   1.620 +    mCachedOutlineWidth =
   1.621 +      std::max(CalcCoord(mOutlineWidth, aContext->GetBorderWidthTable(), 3), 0);
   1.622 +    mCachedOutlineWidth =
   1.623 +      NS_ROUND_BORDER_TO_PIXELS(mCachedOutlineWidth, mTwipsPerPixel);
   1.624 +    mHasCachedOutline = true;
   1.625 +  }
   1.626 +  else
   1.627 +    mHasCachedOutline = false;
   1.628 +}
   1.629 +
   1.630 +nsChangeHint nsStyleOutline::CalcDifference(const nsStyleOutline& aOther) const
   1.631 +{
   1.632 +  bool outlineWasVisible =
   1.633 +    mCachedOutlineWidth > 0 && mOutlineStyle != NS_STYLE_BORDER_STYLE_NONE;
   1.634 +  bool outlineIsVisible = 
   1.635 +    aOther.mCachedOutlineWidth > 0 && aOther.mOutlineStyle != NS_STYLE_BORDER_STYLE_NONE;
   1.636 +  if (outlineWasVisible != outlineIsVisible ||
   1.637 +      (outlineIsVisible && (mOutlineOffset != aOther.mOutlineOffset ||
   1.638 +                            mOutlineWidth != aOther.mOutlineWidth ||
   1.639 +                            mTwipsPerPixel != aOther.mTwipsPerPixel))) {
   1.640 +    return NS_CombineHint(nsChangeHint_AllReflowHints,
   1.641 +                          nsChangeHint_RepaintFrame);
   1.642 +  }
   1.643 +  if ((mOutlineStyle != aOther.mOutlineStyle) ||
   1.644 +      (mOutlineColor != aOther.mOutlineColor) ||
   1.645 +      (mOutlineRadius != aOther.mOutlineRadius)) {
   1.646 +    return nsChangeHint_RepaintFrame;
   1.647 +  }
   1.648 +  return NS_STYLE_HINT_NONE;
   1.649 +}
   1.650 +
   1.651 +// --------------------
   1.652 +// nsStyleList
   1.653 +//
   1.654 +nsStyleList::nsStyleList() 
   1.655 +  : mListStyleType(NS_STYLE_LIST_STYLE_DISC),
   1.656 +    mListStylePosition(NS_STYLE_LIST_STYLE_POSITION_OUTSIDE)
   1.657 +{
   1.658 +  MOZ_COUNT_CTOR(nsStyleList);
   1.659 +}
   1.660 +
   1.661 +nsStyleList::~nsStyleList() 
   1.662 +{
   1.663 +  MOZ_COUNT_DTOR(nsStyleList);
   1.664 +}
   1.665 +
   1.666 +nsStyleList::nsStyleList(const nsStyleList& aSource)
   1.667 +  : mListStyleType(aSource.mListStyleType),
   1.668 +    mListStylePosition(aSource.mListStylePosition),
   1.669 +    mImageRegion(aSource.mImageRegion)
   1.670 +{
   1.671 +  SetListStyleImage(aSource.GetListStyleImage());
   1.672 +  MOZ_COUNT_CTOR(nsStyleList);
   1.673 +}
   1.674 +
   1.675 +nsChangeHint nsStyleList::CalcDifference(const nsStyleList& aOther) const
   1.676 +{
   1.677 +  if (mListStylePosition != aOther.mListStylePosition)
   1.678 +    return NS_STYLE_HINT_FRAMECHANGE;
   1.679 +  if (EqualImages(mListStyleImage, aOther.mListStyleImage) &&
   1.680 +      mListStyleType == aOther.mListStyleType) {
   1.681 +    if (mImageRegion.IsEqualInterior(aOther.mImageRegion))
   1.682 +      return NS_STYLE_HINT_NONE;
   1.683 +    if (mImageRegion.width == aOther.mImageRegion.width &&
   1.684 +        mImageRegion.height == aOther.mImageRegion.height)
   1.685 +      return NS_STYLE_HINT_VISUAL;
   1.686 +  }
   1.687 +  return NS_STYLE_HINT_REFLOW;
   1.688 +}
   1.689 +
   1.690 +// --------------------
   1.691 +// nsStyleXUL
   1.692 +//
   1.693 +nsStyleXUL::nsStyleXUL() 
   1.694 +{ 
   1.695 +  MOZ_COUNT_CTOR(nsStyleXUL);
   1.696 +  mBoxAlign  = NS_STYLE_BOX_ALIGN_STRETCH;
   1.697 +  mBoxDirection = NS_STYLE_BOX_DIRECTION_NORMAL;
   1.698 +  mBoxFlex = 0.0f;
   1.699 +  mBoxOrient = NS_STYLE_BOX_ORIENT_HORIZONTAL;
   1.700 +  mBoxPack   = NS_STYLE_BOX_PACK_START;
   1.701 +  mBoxOrdinal = 1;
   1.702 +  mStretchStack = true;
   1.703 +}
   1.704 +
   1.705 +nsStyleXUL::~nsStyleXUL() 
   1.706 +{
   1.707 +  MOZ_COUNT_DTOR(nsStyleXUL);
   1.708 +}
   1.709 +
   1.710 +nsStyleXUL::nsStyleXUL(const nsStyleXUL& aSource)
   1.711 +{
   1.712 +  MOZ_COUNT_CTOR(nsStyleXUL);
   1.713 +  memcpy((nsStyleXUL*)this, &aSource, sizeof(nsStyleXUL));
   1.714 +}
   1.715 +
   1.716 +nsChangeHint nsStyleXUL::CalcDifference(const nsStyleXUL& aOther) const
   1.717 +{
   1.718 +  if (mBoxAlign == aOther.mBoxAlign &&
   1.719 +      mBoxDirection == aOther.mBoxDirection &&
   1.720 +      mBoxFlex == aOther.mBoxFlex &&
   1.721 +      mBoxOrient == aOther.mBoxOrient &&
   1.722 +      mBoxPack == aOther.mBoxPack &&
   1.723 +      mBoxOrdinal == aOther.mBoxOrdinal &&
   1.724 +      mStretchStack == aOther.mStretchStack)
   1.725 +    return NS_STYLE_HINT_NONE;
   1.726 +  if (mBoxOrdinal != aOther.mBoxOrdinal)
   1.727 +    return NS_STYLE_HINT_FRAMECHANGE;
   1.728 +  return NS_STYLE_HINT_REFLOW;
   1.729 +}
   1.730 +
   1.731 +// --------------------
   1.732 +// nsStyleColumn
   1.733 +//
   1.734 +/* static */ const uint32_t nsStyleColumn::kMaxColumnCount = 1000;
   1.735 +
   1.736 +nsStyleColumn::nsStyleColumn(nsPresContext* aPresContext)
   1.737 +{
   1.738 +  MOZ_COUNT_CTOR(nsStyleColumn);
   1.739 +  mColumnCount = NS_STYLE_COLUMN_COUNT_AUTO;
   1.740 +  mColumnWidth.SetAutoValue();
   1.741 +  mColumnGap.SetNormalValue();
   1.742 +  mColumnFill = NS_STYLE_COLUMN_FILL_BALANCE;
   1.743 +
   1.744 +  mColumnRuleWidth = (aPresContext->GetBorderWidthTable())[NS_STYLE_BORDER_WIDTH_MEDIUM];
   1.745 +  mColumnRuleStyle = NS_STYLE_BORDER_STYLE_NONE;
   1.746 +  mColumnRuleColor = NS_RGB(0, 0, 0);
   1.747 +  mColumnRuleColorIsForeground = true;
   1.748 +
   1.749 +  mTwipsPerPixel = aPresContext->AppUnitsPerDevPixel();
   1.750 +}
   1.751 +
   1.752 +nsStyleColumn::~nsStyleColumn() 
   1.753 +{
   1.754 +  MOZ_COUNT_DTOR(nsStyleColumn);
   1.755 +}
   1.756 +
   1.757 +nsStyleColumn::nsStyleColumn(const nsStyleColumn& aSource)
   1.758 +{
   1.759 +  MOZ_COUNT_CTOR(nsStyleColumn);
   1.760 +  memcpy((nsStyleColumn*)this, &aSource, sizeof(nsStyleColumn));
   1.761 +}
   1.762 +
   1.763 +nsChangeHint nsStyleColumn::CalcDifference(const nsStyleColumn& aOther) const
   1.764 +{
   1.765 +  if ((mColumnWidth.GetUnit() == eStyleUnit_Auto)
   1.766 +      != (aOther.mColumnWidth.GetUnit() == eStyleUnit_Auto) ||
   1.767 +      mColumnCount != aOther.mColumnCount)
   1.768 +    // We force column count changes to do a reframe, because it's tricky to handle
   1.769 +    // some edge cases where the column count gets smaller and content overflows.
   1.770 +    // XXX not ideal
   1.771 +    return NS_STYLE_HINT_FRAMECHANGE;
   1.772 +
   1.773 +  if (mColumnWidth != aOther.mColumnWidth ||
   1.774 +      mColumnGap != aOther.mColumnGap ||
   1.775 +      mColumnFill != aOther.mColumnFill)
   1.776 +    return NS_STYLE_HINT_REFLOW;
   1.777 +
   1.778 +  if (GetComputedColumnRuleWidth() != aOther.GetComputedColumnRuleWidth() ||
   1.779 +      mColumnRuleStyle != aOther.mColumnRuleStyle ||
   1.780 +      mColumnRuleColor != aOther.mColumnRuleColor ||
   1.781 +      mColumnRuleColorIsForeground != aOther.mColumnRuleColorIsForeground)
   1.782 +    return NS_STYLE_HINT_VISUAL;
   1.783 +
   1.784 +  return NS_STYLE_HINT_NONE;
   1.785 +}
   1.786 +
   1.787 +// --------------------
   1.788 +// nsStyleSVG
   1.789 +//
   1.790 +nsStyleSVG::nsStyleSVG() 
   1.791 +{
   1.792 +    MOZ_COUNT_CTOR(nsStyleSVG);
   1.793 +    mFill.mType              = eStyleSVGPaintType_Color;
   1.794 +    mFill.mPaint.mColor      = NS_RGB(0,0,0);
   1.795 +    mFill.mFallbackColor     = NS_RGB(0,0,0);
   1.796 +    mStroke.mType            = eStyleSVGPaintType_None;
   1.797 +    mStroke.mPaint.mColor    = NS_RGB(0,0,0);
   1.798 +    mStroke.mFallbackColor   = NS_RGB(0,0,0);
   1.799 +    mStrokeDasharray         = nullptr;
   1.800 +
   1.801 +    mStrokeDashoffset.SetCoordValue(0);
   1.802 +    mStrokeWidth.SetCoordValue(nsPresContext::CSSPixelsToAppUnits(1));
   1.803 +
   1.804 +    mFillOpacity             = 1.0f;
   1.805 +    mStrokeMiterlimit        = 4.0f;
   1.806 +    mStrokeOpacity           = 1.0f;
   1.807 +
   1.808 +    mStrokeDasharrayLength   = 0;
   1.809 +    mClipRule                = NS_STYLE_FILL_RULE_NONZERO;
   1.810 +    mColorInterpolation      = NS_STYLE_COLOR_INTERPOLATION_SRGB;
   1.811 +    mColorInterpolationFilters = NS_STYLE_COLOR_INTERPOLATION_LINEARRGB;
   1.812 +    mFillRule                = NS_STYLE_FILL_RULE_NONZERO;
   1.813 +    mImageRendering          = NS_STYLE_IMAGE_RENDERING_AUTO;
   1.814 +    mPaintOrder              = NS_STYLE_PAINT_ORDER_NORMAL;
   1.815 +    mShapeRendering          = NS_STYLE_SHAPE_RENDERING_AUTO;
   1.816 +    mStrokeLinecap           = NS_STYLE_STROKE_LINECAP_BUTT;
   1.817 +    mStrokeLinejoin          = NS_STYLE_STROKE_LINEJOIN_MITER;
   1.818 +    mTextAnchor              = NS_STYLE_TEXT_ANCHOR_START;
   1.819 +    mTextRendering           = NS_STYLE_TEXT_RENDERING_AUTO;
   1.820 +    mFillOpacitySource       = eStyleSVGOpacitySource_Normal;
   1.821 +    mStrokeOpacitySource     = eStyleSVGOpacitySource_Normal;
   1.822 +    mStrokeDasharrayFromObject = false;
   1.823 +    mStrokeDashoffsetFromObject = false;
   1.824 +    mStrokeWidthFromObject   = false;
   1.825 +}
   1.826 +
   1.827 +nsStyleSVG::~nsStyleSVG() 
   1.828 +{
   1.829 +  MOZ_COUNT_DTOR(nsStyleSVG);
   1.830 +  delete [] mStrokeDasharray;
   1.831 +}
   1.832 +
   1.833 +nsStyleSVG::nsStyleSVG(const nsStyleSVG& aSource)
   1.834 +{
   1.835 +  MOZ_COUNT_CTOR(nsStyleSVG);
   1.836 +  mFill = aSource.mFill;
   1.837 +  mStroke = aSource.mStroke;
   1.838 +
   1.839 +  mMarkerEnd = aSource.mMarkerEnd;
   1.840 +  mMarkerMid = aSource.mMarkerMid;
   1.841 +  mMarkerStart = aSource.mMarkerStart;
   1.842 +
   1.843 +  mStrokeDasharrayLength = aSource.mStrokeDasharrayLength;
   1.844 +  if (aSource.mStrokeDasharray) {
   1.845 +    mStrokeDasharray = new nsStyleCoord[mStrokeDasharrayLength];
   1.846 +    if (mStrokeDasharray)
   1.847 +      memcpy(mStrokeDasharray,
   1.848 +             aSource.mStrokeDasharray,
   1.849 +             mStrokeDasharrayLength * sizeof(nsStyleCoord));
   1.850 +    else
   1.851 +      mStrokeDasharrayLength = 0;
   1.852 +  } else {
   1.853 +    mStrokeDasharray = nullptr;
   1.854 +  }
   1.855 +
   1.856 +  mStrokeDashoffset = aSource.mStrokeDashoffset;
   1.857 +  mStrokeWidth = aSource.mStrokeWidth;
   1.858 +
   1.859 +  mFillOpacity = aSource.mFillOpacity;
   1.860 +  mStrokeMiterlimit = aSource.mStrokeMiterlimit;
   1.861 +  mStrokeOpacity = aSource.mStrokeOpacity;
   1.862 +
   1.863 +  mClipRule = aSource.mClipRule;
   1.864 +  mColorInterpolation = aSource.mColorInterpolation;
   1.865 +  mColorInterpolationFilters = aSource.mColorInterpolationFilters;
   1.866 +  mFillRule = aSource.mFillRule;
   1.867 +  mImageRendering = aSource.mImageRendering;
   1.868 +  mPaintOrder = aSource.mPaintOrder;
   1.869 +  mShapeRendering = aSource.mShapeRendering;
   1.870 +  mStrokeLinecap = aSource.mStrokeLinecap;
   1.871 +  mStrokeLinejoin = aSource.mStrokeLinejoin;
   1.872 +  mTextAnchor = aSource.mTextAnchor;
   1.873 +  mTextRendering = aSource.mTextRendering;
   1.874 +  mFillOpacitySource = aSource.mFillOpacitySource;
   1.875 +  mStrokeOpacitySource = aSource.mStrokeOpacitySource;
   1.876 +  mStrokeDasharrayFromObject = aSource.mStrokeDasharrayFromObject;
   1.877 +  mStrokeDashoffsetFromObject = aSource.mStrokeDashoffsetFromObject;
   1.878 +  mStrokeWidthFromObject = aSource.mStrokeWidthFromObject;
   1.879 +}
   1.880 +
   1.881 +static bool PaintURIChanged(const nsStyleSVGPaint& aPaint1,
   1.882 +                              const nsStyleSVGPaint& aPaint2)
   1.883 +{
   1.884 +  if (aPaint1.mType != aPaint2.mType) {
   1.885 +    return aPaint1.mType == eStyleSVGPaintType_Server ||
   1.886 +           aPaint2.mType == eStyleSVGPaintType_Server;
   1.887 +  }
   1.888 +  return aPaint1.mType == eStyleSVGPaintType_Server &&
   1.889 +    !EqualURIs(aPaint1.mPaint.mPaintServer, aPaint2.mPaint.mPaintServer);
   1.890 +}
   1.891 +
   1.892 +nsChangeHint nsStyleSVG::CalcDifference(const nsStyleSVG& aOther) const
   1.893 +{
   1.894 +  nsChangeHint hint = nsChangeHint(0);
   1.895 +
   1.896 +  if (!EqualURIs(mMarkerEnd, aOther.mMarkerEnd) ||
   1.897 +      !EqualURIs(mMarkerMid, aOther.mMarkerMid) ||
   1.898 +      !EqualURIs(mMarkerStart, aOther.mMarkerStart)) {
   1.899 +    // Markers currently contribute to nsSVGPathGeometryFrame::mRect,
   1.900 +    // so we need a reflow as well as a repaint. No intrinsic sizes need
   1.901 +    // to change, so nsChangeHint_NeedReflow is sufficient.
   1.902 +    NS_UpdateHint(hint, nsChangeHint_UpdateEffects);
   1.903 +    NS_UpdateHint(hint, nsChangeHint_NeedReflow);
   1.904 +    NS_UpdateHint(hint, nsChangeHint_NeedDirtyReflow); // XXX remove me: bug 876085
   1.905 +    NS_UpdateHint(hint, nsChangeHint_RepaintFrame);
   1.906 +    return hint;
   1.907 +  }
   1.908 +
   1.909 +  if (mFill != aOther.mFill ||
   1.910 +      mStroke != aOther.mStroke ||
   1.911 +      mFillOpacity != aOther.mFillOpacity ||
   1.912 +      mStrokeOpacity != aOther.mStrokeOpacity) {
   1.913 +    NS_UpdateHint(hint, nsChangeHint_RepaintFrame);
   1.914 +    if (HasStroke() != aOther.HasStroke() ||
   1.915 +        (!HasStroke() && HasFill() != aOther.HasFill())) {
   1.916 +      // Frame bounds and overflow rects depend on whether we "have" fill or
   1.917 +      // stroke. Whether we have stroke or not just changed, or else we have no
   1.918 +      // stroke (in which case whether we have fill or not is significant to frame
   1.919 +      // bounds) and whether we have fill or not just changed. In either case we
   1.920 +      // need to reflow so the frame rect is updated.
   1.921 +      // XXXperf this is a waste on non nsSVGPathGeometryFrames.
   1.922 +      NS_UpdateHint(hint, nsChangeHint_NeedReflow);
   1.923 +      NS_UpdateHint(hint, nsChangeHint_NeedDirtyReflow); // XXX remove me: bug 876085
   1.924 +    }
   1.925 +    if (PaintURIChanged(mFill, aOther.mFill) ||
   1.926 +        PaintURIChanged(mStroke, aOther.mStroke)) {
   1.927 +      NS_UpdateHint(hint, nsChangeHint_UpdateEffects);
   1.928 +    }
   1.929 +  }
   1.930 +
   1.931 +  // Stroke currently contributes to nsSVGPathGeometryFrame::mRect, so
   1.932 +  // we need a reflow here. No intrinsic sizes need to change, so
   1.933 +  // nsChangeHint_NeedReflow is sufficient.
   1.934 +  // Note that stroke-dashoffset does not affect nsSVGPathGeometryFrame::mRect.
   1.935 +  // text-anchor and text-rendering changes also require a reflow since they
   1.936 +  // change frames' rects.
   1.937 +  if (mStrokeWidth           != aOther.mStrokeWidth           ||
   1.938 +      mStrokeMiterlimit      != aOther.mStrokeMiterlimit      ||
   1.939 +      mStrokeLinecap         != aOther.mStrokeLinecap         ||
   1.940 +      mStrokeLinejoin        != aOther.mStrokeLinejoin        ||
   1.941 +      mTextAnchor            != aOther.mTextAnchor            ||
   1.942 +      mTextRendering         != aOther.mTextRendering) {
   1.943 +    NS_UpdateHint(hint, nsChangeHint_NeedReflow);
   1.944 +    NS_UpdateHint(hint, nsChangeHint_NeedDirtyReflow); // XXX remove me: bug 876085
   1.945 +    NS_UpdateHint(hint, nsChangeHint_RepaintFrame);
   1.946 +    return hint;
   1.947 +  }
   1.948 +
   1.949 +  if (hint & nsChangeHint_RepaintFrame) {
   1.950 +    return hint; // we don't add anything else below
   1.951 +  }
   1.952 +
   1.953 +  if ( mStrokeDashoffset      != aOther.mStrokeDashoffset      ||
   1.954 +       mClipRule              != aOther.mClipRule              ||
   1.955 +       mColorInterpolation    != aOther.mColorInterpolation    ||
   1.956 +       mColorInterpolationFilters != aOther.mColorInterpolationFilters ||
   1.957 +       mFillRule              != aOther.mFillRule              ||
   1.958 +       mImageRendering        != aOther.mImageRendering        ||
   1.959 +       mPaintOrder            != aOther.mPaintOrder            ||
   1.960 +       mShapeRendering        != aOther.mShapeRendering        ||
   1.961 +       mStrokeDasharrayLength != aOther.mStrokeDasharrayLength ||
   1.962 +       mFillOpacitySource     != aOther.mFillOpacitySource     ||
   1.963 +       mStrokeOpacitySource   != aOther.mStrokeOpacitySource   ||
   1.964 +       mStrokeDasharrayFromObject != aOther.mStrokeDasharrayFromObject ||
   1.965 +       mStrokeDashoffsetFromObject != aOther.mStrokeDashoffsetFromObject ||
   1.966 +       mStrokeWidthFromObject != aOther.mStrokeWidthFromObject) {
   1.967 +    NS_UpdateHint(hint, nsChangeHint_RepaintFrame);
   1.968 +    return hint;
   1.969 +  }
   1.970 +
   1.971 +  // length of stroke dasharrays are the same (tested above) - check entries
   1.972 +  for (uint32_t i=0; i<mStrokeDasharrayLength; i++)
   1.973 +    if (mStrokeDasharray[i] != aOther.mStrokeDasharray[i]) {
   1.974 +      NS_UpdateHint(hint, nsChangeHint_RepaintFrame);
   1.975 +      return hint;
   1.976 +    }
   1.977 +
   1.978 +  return hint;
   1.979 +}
   1.980 +
   1.981 +// --------------------
   1.982 +// nsStyleFilter
   1.983 +//
   1.984 +nsStyleFilter::nsStyleFilter()
   1.985 +  : mType(NS_STYLE_FILTER_NONE)
   1.986 +  , mDropShadow(nullptr)
   1.987 +{
   1.988 +  MOZ_COUNT_CTOR(nsStyleFilter);
   1.989 +}
   1.990 +
   1.991 +nsStyleFilter::nsStyleFilter(const nsStyleFilter& aSource)
   1.992 +  : mType(NS_STYLE_FILTER_NONE)
   1.993 +  , mDropShadow(nullptr)
   1.994 +{
   1.995 +  MOZ_COUNT_CTOR(nsStyleFilter);
   1.996 +  if (aSource.mType == NS_STYLE_FILTER_URL) {
   1.997 +    SetURL(aSource.mURL);
   1.998 +  } else if (aSource.mType == NS_STYLE_FILTER_DROP_SHADOW) {
   1.999 +    SetDropShadow(aSource.mDropShadow);
  1.1000 +  } else if (aSource.mType != NS_STYLE_FILTER_NONE) {
  1.1001 +    SetFilterParameter(aSource.mFilterParameter, aSource.mType);
  1.1002 +  }
  1.1003 +}
  1.1004 +
  1.1005 +nsStyleFilter::~nsStyleFilter()
  1.1006 +{
  1.1007 +  ReleaseRef();
  1.1008 +  MOZ_COUNT_DTOR(nsStyleFilter);
  1.1009 +}
  1.1010 +
  1.1011 +nsStyleFilter&
  1.1012 +nsStyleFilter::operator=(const nsStyleFilter& aOther)
  1.1013 +{
  1.1014 +  if (this == &aOther)
  1.1015 +    return *this;
  1.1016 +
  1.1017 +  if (aOther.mType == NS_STYLE_FILTER_URL) {
  1.1018 +    SetURL(aOther.mURL);
  1.1019 +  } else if (aOther.mType == NS_STYLE_FILTER_DROP_SHADOW) {
  1.1020 +    SetDropShadow(aOther.mDropShadow);
  1.1021 +  } else if (aOther.mType != NS_STYLE_FILTER_NONE) {
  1.1022 +    SetFilterParameter(aOther.mFilterParameter, aOther.mType);
  1.1023 +  }
  1.1024 +  return *this;
  1.1025 +}
  1.1026 +
  1.1027 +
  1.1028 +bool
  1.1029 +nsStyleFilter::operator==(const nsStyleFilter& aOther) const
  1.1030 +{
  1.1031 +  if (mType != aOther.mType) {
  1.1032 +      return false;
  1.1033 +  }
  1.1034 +
  1.1035 +  if (mType == NS_STYLE_FILTER_URL) {
  1.1036 +    return EqualURIs(mURL, aOther.mURL);
  1.1037 +  } else if (mType == NS_STYLE_FILTER_DROP_SHADOW) {
  1.1038 +    return *mDropShadow == *aOther.mDropShadow;
  1.1039 +  } else if (mType != NS_STYLE_FILTER_NONE) {
  1.1040 +    return mFilterParameter == aOther.mFilterParameter;
  1.1041 +  }
  1.1042 +
  1.1043 +  return true;
  1.1044 +}
  1.1045 +
  1.1046 +void
  1.1047 +nsStyleFilter::ReleaseRef()
  1.1048 +{
  1.1049 +  if (mType == NS_STYLE_FILTER_DROP_SHADOW) {
  1.1050 +    NS_ASSERTION(mDropShadow, "expected pointer");
  1.1051 +    mDropShadow->Release();
  1.1052 +  } else if (mType == NS_STYLE_FILTER_URL) {
  1.1053 +    NS_ASSERTION(mURL, "expected pointer");
  1.1054 +    mURL->Release();
  1.1055 +  }
  1.1056 +}
  1.1057 +
  1.1058 +void
  1.1059 +nsStyleFilter::SetFilterParameter(const nsStyleCoord& aFilterParameter,
  1.1060 +                                  int32_t aType)
  1.1061 +{
  1.1062 +  ReleaseRef();
  1.1063 +  mFilterParameter = aFilterParameter;
  1.1064 +  mType = aType;
  1.1065 +}
  1.1066 +
  1.1067 +void
  1.1068 +nsStyleFilter::SetURL(nsIURI* aURL)
  1.1069 +{
  1.1070 +  NS_ASSERTION(aURL, "expected pointer");
  1.1071 +  ReleaseRef();
  1.1072 +  mURL = aURL;
  1.1073 +  mURL->AddRef();
  1.1074 +  mType = NS_STYLE_FILTER_URL;
  1.1075 +}
  1.1076 +
  1.1077 +void
  1.1078 +nsStyleFilter::SetDropShadow(nsCSSShadowArray* aDropShadow)
  1.1079 +{
  1.1080 +  NS_ASSERTION(aDropShadow, "expected pointer");
  1.1081 +  ReleaseRef();
  1.1082 +  mDropShadow = aDropShadow;
  1.1083 +  mDropShadow->AddRef();
  1.1084 +  mType = NS_STYLE_FILTER_DROP_SHADOW;
  1.1085 +}
  1.1086 +
  1.1087 +// --------------------
  1.1088 +// nsStyleSVGReset
  1.1089 +//
  1.1090 +nsStyleSVGReset::nsStyleSVGReset() 
  1.1091 +{
  1.1092 +    MOZ_COUNT_CTOR(nsStyleSVGReset);
  1.1093 +    mStopColor               = NS_RGB(0,0,0);
  1.1094 +    mFloodColor              = NS_RGB(0,0,0);
  1.1095 +    mLightingColor           = NS_RGB(255,255,255);
  1.1096 +    mClipPath                = nullptr;
  1.1097 +    mMask                    = nullptr;
  1.1098 +    mStopOpacity             = 1.0f;
  1.1099 +    mFloodOpacity            = 1.0f;
  1.1100 +    mDominantBaseline        = NS_STYLE_DOMINANT_BASELINE_AUTO;
  1.1101 +    mVectorEffect            = NS_STYLE_VECTOR_EFFECT_NONE;
  1.1102 +    mMaskType                = NS_STYLE_MASK_TYPE_LUMINANCE;
  1.1103 +}
  1.1104 +
  1.1105 +nsStyleSVGReset::~nsStyleSVGReset() 
  1.1106 +{
  1.1107 +  MOZ_COUNT_DTOR(nsStyleSVGReset);
  1.1108 +}
  1.1109 +
  1.1110 +nsStyleSVGReset::nsStyleSVGReset(const nsStyleSVGReset& aSource)
  1.1111 +{
  1.1112 +  MOZ_COUNT_CTOR(nsStyleSVGReset);
  1.1113 +  mStopColor = aSource.mStopColor;
  1.1114 +  mFloodColor = aSource.mFloodColor;
  1.1115 +  mLightingColor = aSource.mLightingColor;
  1.1116 +  mClipPath = aSource.mClipPath;
  1.1117 +  mFilters = aSource.mFilters;
  1.1118 +  mMask = aSource.mMask;
  1.1119 +  mStopOpacity = aSource.mStopOpacity;
  1.1120 +  mFloodOpacity = aSource.mFloodOpacity;
  1.1121 +  mDominantBaseline = aSource.mDominantBaseline;
  1.1122 +  mVectorEffect = aSource.mVectorEffect;
  1.1123 +  mMaskType = aSource.mMaskType;
  1.1124 +}
  1.1125 +
  1.1126 +nsChangeHint nsStyleSVGReset::CalcDifference(const nsStyleSVGReset& aOther) const
  1.1127 +{
  1.1128 +  nsChangeHint hint = nsChangeHint(0);
  1.1129 +
  1.1130 +  bool equalFilters = (mFilters == aOther.mFilters);
  1.1131 +
  1.1132 +  if (!equalFilters) {
  1.1133 +    NS_UpdateHint(hint, nsChangeHint_UpdateOverflow);
  1.1134 +  }
  1.1135 +
  1.1136 +  if (!EqualURIs(mClipPath, aOther.mClipPath) ||
  1.1137 +      !EqualURIs(mMask, aOther.mMask) ||
  1.1138 +      !equalFilters) {
  1.1139 +    NS_UpdateHint(hint, nsChangeHint_UpdateEffects);
  1.1140 +    NS_UpdateHint(hint, nsChangeHint_RepaintFrame);
  1.1141 +  }
  1.1142 +
  1.1143 +  if (mDominantBaseline != aOther.mDominantBaseline) {
  1.1144 +    // XXXjwatt: why NS_STYLE_HINT_REFLOW? Isn't that excessive?
  1.1145 +    NS_UpdateHint(hint, NS_STYLE_HINT_REFLOW);
  1.1146 +  } else if (mVectorEffect  != aOther.mVectorEffect) {
  1.1147 +    // Stroke currently affects nsSVGPathGeometryFrame::mRect, and
  1.1148 +    // vector-effect affect stroke. As a result we need to reflow if
  1.1149 +    // vector-effect changes in order to have nsSVGPathGeometryFrame::
  1.1150 +    // ReflowSVG called to update its mRect. No intrinsic sizes need
  1.1151 +    // to change so nsChangeHint_NeedReflow is sufficient.
  1.1152 +    NS_UpdateHint(hint, nsChangeHint_NeedReflow);
  1.1153 +    NS_UpdateHint(hint, nsChangeHint_NeedDirtyReflow); // XXX remove me: bug 876085
  1.1154 +    NS_UpdateHint(hint, nsChangeHint_RepaintFrame);
  1.1155 +  } else if (mStopColor     != aOther.mStopColor     ||
  1.1156 +             mFloodColor    != aOther.mFloodColor    ||
  1.1157 +             mLightingColor != aOther.mLightingColor ||
  1.1158 +             mStopOpacity   != aOther.mStopOpacity   ||
  1.1159 +             mFloodOpacity  != aOther.mFloodOpacity  ||
  1.1160 +             mMaskType      != aOther.mMaskType) {
  1.1161 +    NS_UpdateHint(hint, nsChangeHint_RepaintFrame);
  1.1162 +  }
  1.1163 +
  1.1164 +  return hint;
  1.1165 +}
  1.1166 +
  1.1167 +// nsStyleSVGPaint implementation
  1.1168 +nsStyleSVGPaint::~nsStyleSVGPaint()
  1.1169 +{
  1.1170 +  if (mType == eStyleSVGPaintType_Server) {
  1.1171 +    NS_IF_RELEASE(mPaint.mPaintServer);
  1.1172 +  }
  1.1173 +}
  1.1174 +
  1.1175 +void
  1.1176 +nsStyleSVGPaint::SetType(nsStyleSVGPaintType aType)
  1.1177 +{
  1.1178 +  if (mType == eStyleSVGPaintType_Server) {
  1.1179 +    this->~nsStyleSVGPaint();
  1.1180 +    new (this) nsStyleSVGPaint();
  1.1181 +  }
  1.1182 +  mType = aType;
  1.1183 +}
  1.1184 +
  1.1185 +nsStyleSVGPaint& nsStyleSVGPaint::operator=(const nsStyleSVGPaint& aOther) 
  1.1186 +{
  1.1187 +  if (this == &aOther)
  1.1188 +    return *this;
  1.1189 +
  1.1190 +  SetType(aOther.mType);
  1.1191 +
  1.1192 +  mFallbackColor = aOther.mFallbackColor;
  1.1193 +  if (mType == eStyleSVGPaintType_Server) {
  1.1194 +    mPaint.mPaintServer = aOther.mPaint.mPaintServer;
  1.1195 +    NS_IF_ADDREF(mPaint.mPaintServer);
  1.1196 +  } else {
  1.1197 +    mPaint.mColor = aOther.mPaint.mColor;
  1.1198 +  }
  1.1199 +  return *this;
  1.1200 +}
  1.1201 +
  1.1202 +bool nsStyleSVGPaint::operator==(const nsStyleSVGPaint& aOther) const
  1.1203 +{
  1.1204 +  if (mType != aOther.mType)
  1.1205 +    return false;
  1.1206 +  if (mType == eStyleSVGPaintType_Server)
  1.1207 +    return EqualURIs(mPaint.mPaintServer, aOther.mPaint.mPaintServer) &&
  1.1208 +           mFallbackColor == aOther.mFallbackColor;
  1.1209 +  if (mType == eStyleSVGPaintType_Color)
  1.1210 +    return mPaint.mColor == aOther.mPaint.mColor;
  1.1211 +  return true;
  1.1212 +}
  1.1213 +
  1.1214 +
  1.1215 +// --------------------
  1.1216 +// nsStylePosition
  1.1217 +//
  1.1218 +nsStylePosition::nsStylePosition(void)
  1.1219 +{
  1.1220 +  MOZ_COUNT_CTOR(nsStylePosition);
  1.1221 +  // positioning values not inherited
  1.1222 +  nsStyleCoord  autoCoord(eStyleUnit_Auto);
  1.1223 +  mOffset.SetLeft(autoCoord);
  1.1224 +  mOffset.SetTop(autoCoord);
  1.1225 +  mOffset.SetRight(autoCoord);
  1.1226 +  mOffset.SetBottom(autoCoord);
  1.1227 +  mWidth.SetAutoValue();
  1.1228 +  mMinWidth.SetCoordValue(0);
  1.1229 +  mMaxWidth.SetNoneValue();
  1.1230 +  mHeight.SetAutoValue();
  1.1231 +  mMinHeight.SetCoordValue(0);
  1.1232 +  mMaxHeight.SetNoneValue();
  1.1233 +  mFlexBasis.SetAutoValue();
  1.1234 +
  1.1235 +  // The initial value of grid-auto-columns and grid-auto-rows is 'auto',
  1.1236 +  // which computes to 'minmax(min-content, max-content)'.
  1.1237 +  mGridAutoColumnsMin.SetIntValue(NS_STYLE_GRID_TRACK_BREADTH_MIN_CONTENT,
  1.1238 +                                  eStyleUnit_Enumerated);
  1.1239 +  mGridAutoColumnsMax.SetIntValue(NS_STYLE_GRID_TRACK_BREADTH_MAX_CONTENT,
  1.1240 +                                  eStyleUnit_Enumerated);
  1.1241 +  mGridAutoRowsMin.SetIntValue(NS_STYLE_GRID_TRACK_BREADTH_MIN_CONTENT,
  1.1242 +                               eStyleUnit_Enumerated);
  1.1243 +  mGridAutoRowsMax.SetIntValue(NS_STYLE_GRID_TRACK_BREADTH_MAX_CONTENT,
  1.1244 +                               eStyleUnit_Enumerated);
  1.1245 +
  1.1246 +  mGridAutoFlow = NS_STYLE_GRID_AUTO_FLOW_NONE;
  1.1247 +  mBoxSizing = NS_STYLE_BOX_SIZING_CONTENT;
  1.1248 +  mAlignContent = NS_STYLE_ALIGN_CONTENT_STRETCH;
  1.1249 +  mAlignItems = NS_STYLE_ALIGN_ITEMS_INITIAL_VALUE;
  1.1250 +  mAlignSelf = NS_STYLE_ALIGN_SELF_AUTO;
  1.1251 +  mFlexDirection = NS_STYLE_FLEX_DIRECTION_ROW;
  1.1252 +  mFlexWrap = NS_STYLE_FLEX_WRAP_NOWRAP;
  1.1253 +  mJustifyContent = NS_STYLE_JUSTIFY_CONTENT_FLEX_START;
  1.1254 +  mOrder = NS_STYLE_ORDER_INITIAL;
  1.1255 +  mFlexGrow = 0.0f;
  1.1256 +  mFlexShrink = 1.0f;
  1.1257 +  mZIndex.SetAutoValue();
  1.1258 +  mGridAutoPositionColumn.SetToInteger(1);
  1.1259 +  mGridAutoPositionRow.SetToInteger(1);
  1.1260 +  // Other members get their default constructors
  1.1261 +  // which initialize them to representations of their respective initial value.
  1.1262 +  // mGridTemplateAreas: nullptr for 'none'
  1.1263 +  // mGridTemplate{Rows,Columns}: false and empty arrays for 'none'
  1.1264 +  // mGrid{Column,Row}{Start,End}: false/0/empty values for 'auto'
  1.1265 +}
  1.1266 +
  1.1267 +nsStylePosition::~nsStylePosition(void)
  1.1268 +{
  1.1269 +  MOZ_COUNT_DTOR(nsStylePosition);
  1.1270 +}
  1.1271 +
  1.1272 +nsStylePosition::nsStylePosition(const nsStylePosition& aSource)
  1.1273 +  : mGridTemplateColumns(aSource.mGridTemplateColumns)
  1.1274 +  , mGridTemplateRows(aSource.mGridTemplateRows)
  1.1275 +  , mGridTemplateAreas(aSource.mGridTemplateAreas)
  1.1276 +  , mGridAutoPositionColumn(aSource.mGridAutoPositionColumn)
  1.1277 +  , mGridAutoPositionRow(aSource.mGridAutoPositionRow)
  1.1278 +  , mGridColumnStart(aSource.mGridColumnStart)
  1.1279 +  , mGridColumnEnd(aSource.mGridColumnEnd)
  1.1280 +  , mGridRowStart(aSource.mGridRowStart)
  1.1281 +  , mGridRowEnd(aSource.mGridRowEnd)
  1.1282 +{
  1.1283 +  MOZ_COUNT_CTOR(nsStylePosition);
  1.1284 +  // If you add any memcpy'able member vars,
  1.1285 +  // they should be declared before mGridTemplateColumns.
  1.1286 +  // If you add any non-memcpy'able member vars,
  1.1287 +  // they should be declared after mGridTemplateColumns,
  1.1288 +  // and you should invoke their copy constructor in the init list above
  1.1289 +  // and update this static-assert to include their "sizeof()"
  1.1290 +  static_assert(sizeof(nsStylePosition) ==
  1.1291 +                offsetof(nsStylePosition, mGridTemplateColumns) +
  1.1292 +                sizeof(mGridTemplateColumns) +
  1.1293 +                sizeof(mGridTemplateRows) +
  1.1294 +                sizeof(mGridTemplateAreas) +
  1.1295 +                sizeof(mGridAutoPositionColumn) +
  1.1296 +                sizeof(mGridAutoPositionRow) +
  1.1297 +                sizeof(mGridColumnStart) +
  1.1298 +                sizeof(mGridColumnEnd) +
  1.1299 +                sizeof(mGridRowStart) +
  1.1300 +                sizeof(mGridRowEnd),
  1.1301 +                "Unexpected size or offset in nsStylePosition");
  1.1302 +  memcpy((nsStylePosition*) this,
  1.1303 +         &aSource,
  1.1304 +         offsetof(nsStylePosition, mGridTemplateColumns));
  1.1305 +}
  1.1306 +
  1.1307 +static bool
  1.1308 +IsAutonessEqual(const nsStyleSides& aSides1, const nsStyleSides& aSides2)
  1.1309 +{
  1.1310 +  NS_FOR_CSS_SIDES(side) {
  1.1311 +    if ((aSides1.GetUnit(side) == eStyleUnit_Auto) !=
  1.1312 +        (aSides2.GetUnit(side) == eStyleUnit_Auto)) {
  1.1313 +      return false;
  1.1314 +    }
  1.1315 +  }
  1.1316 +  return true;
  1.1317 +}
  1.1318 +
  1.1319 +nsChangeHint nsStylePosition::CalcDifference(const nsStylePosition& aOther) const
  1.1320 +{
  1.1321 +  nsChangeHint hint =
  1.1322 +    (mZIndex == aOther.mZIndex) ? NS_STYLE_HINT_NONE : nsChangeHint_RepaintFrame;
  1.1323 +
  1.1324 +  if (mBoxSizing != aOther.mBoxSizing) {
  1.1325 +    // Can affect both widths and heights; just a bad scene.
  1.1326 +    return NS_CombineHint(hint, nsChangeHint_AllReflowHints);
  1.1327 +  }
  1.1328 +
  1.1329 +  // Properties that apply to flex items:
  1.1330 +  // NOTE: Changes to "order" on a flex item may trigger some repositioning.
  1.1331 +  // If we're in a multi-line flex container, it also may affect our size
  1.1332 +  // (and that of our container & siblings) by shuffling items between lines.
  1.1333 +  if (mAlignSelf != aOther.mAlignSelf ||
  1.1334 +      mFlexBasis != aOther.mFlexBasis ||
  1.1335 +      mFlexGrow != aOther.mFlexGrow ||
  1.1336 +      mFlexShrink != aOther.mFlexShrink ||
  1.1337 +      mOrder != aOther.mOrder) {
  1.1338 +    return NS_CombineHint(hint, nsChangeHint_AllReflowHints);
  1.1339 +  }
  1.1340 +
  1.1341 +  // Properties that apply to flex containers:
  1.1342 +  // - flex-direction can swap a flex container between vertical & horizontal.
  1.1343 +  // - align-items can change the sizing of a flex container & the positioning
  1.1344 +  //   of its children.
  1.1345 +  // - flex-wrap changes whether a flex container's children are wrapped, which
  1.1346 +  //   impacts their sizing/positioning and hence impacts the container's size.
  1.1347 +  if (mAlignItems != aOther.mAlignItems ||
  1.1348 +      mFlexDirection != aOther.mFlexDirection ||
  1.1349 +      mFlexWrap != aOther.mFlexWrap) {
  1.1350 +    return NS_CombineHint(hint, nsChangeHint_AllReflowHints);
  1.1351 +  }
  1.1352 +
  1.1353 +  // Properties that apply to grid containers:
  1.1354 +  // FIXME: only for grid containers
  1.1355 +  // (ie. 'display: grid' or 'display: inline-grid')
  1.1356 +  if (mGridTemplateColumns != aOther.mGridTemplateColumns ||
  1.1357 +      mGridTemplateRows != aOther.mGridTemplateRows ||
  1.1358 +      mGridTemplateAreas != aOther.mGridTemplateAreas ||
  1.1359 +      mGridAutoColumnsMin != aOther.mGridAutoColumnsMin ||
  1.1360 +      mGridAutoColumnsMax != aOther.mGridAutoColumnsMax ||
  1.1361 +      mGridAutoRowsMin != aOther.mGridAutoRowsMin ||
  1.1362 +      mGridAutoRowsMax != aOther.mGridAutoRowsMax ||
  1.1363 +      mGridAutoFlow != aOther.mGridAutoFlow) {
  1.1364 +    return NS_CombineHint(hint, nsChangeHint_AllReflowHints);
  1.1365 +  }
  1.1366 +
  1.1367 +  // Properties that apply to grid items:
  1.1368 +  // FIXME: only for grid items
  1.1369 +  // (ie. parent frame is 'display: grid' or 'display: inline-grid')
  1.1370 +  if (mGridColumnStart != aOther.mGridColumnStart ||
  1.1371 +      mGridColumnEnd != aOther.mGridColumnEnd ||
  1.1372 +      mGridRowStart != aOther.mGridRowStart ||
  1.1373 +      mGridRowEnd != aOther.mGridRowEnd) {
  1.1374 +    return NS_CombineHint(hint, nsChangeHint_AllReflowHints);
  1.1375 +  }
  1.1376 +
  1.1377 +  // Changing justify-content on a flexbox might affect the positioning of its
  1.1378 +  // children, but it won't affect any sizing.
  1.1379 +  if (mJustifyContent != aOther.mJustifyContent) {
  1.1380 +    NS_UpdateHint(hint, nsChangeHint_NeedReflow);
  1.1381 +  }
  1.1382 +
  1.1383 +  // Properties that apply only to multi-line flex containers:
  1.1384 +  // 'align-content' can change the positioning & sizing of a multi-line flex
  1.1385 +  // container's children when there's extra space in the cross axis, but it
  1.1386 +  // shouldn't affect the container's own sizing.
  1.1387 +  //
  1.1388 +  // NOTE: If we get here, we know that mFlexWrap == aOther.mFlexWrap
  1.1389 +  // (otherwise, we would've returned earlier). So it doesn't matter which one
  1.1390 +  // of those we check to see if we're multi-line.
  1.1391 +  if (mFlexWrap != NS_STYLE_FLEX_WRAP_NOWRAP &&
  1.1392 +      mAlignContent != aOther.mAlignContent) {
  1.1393 +    NS_UpdateHint(hint, nsChangeHint_NeedReflow);
  1.1394 +  }
  1.1395 +
  1.1396 +  if (mHeight != aOther.mHeight ||
  1.1397 +      mMinHeight != aOther.mMinHeight ||
  1.1398 +      mMaxHeight != aOther.mMaxHeight) {
  1.1399 +    // Height changes can affect descendant intrinsic sizes due to replaced
  1.1400 +    // elements with percentage heights in descendants which also have
  1.1401 +    // percentage heights.  And due to our not-so-great computation of mVResize
  1.1402 +    // in nsHTMLReflowState, they do need to force reflow of the whole subtree.
  1.1403 +    // XXXbz due to XUL caching heights as well, height changes also need to
  1.1404 +    // clear ancestor intrinsics!
  1.1405 +    return NS_CombineHint(hint, nsChangeHint_AllReflowHints);
  1.1406 +  }
  1.1407 +
  1.1408 +  if (mWidth != aOther.mWidth ||
  1.1409 +      mMinWidth != aOther.mMinWidth ||
  1.1410 +      mMaxWidth != aOther.mMaxWidth) {
  1.1411 +    // None of our width differences can affect descendant intrinsic
  1.1412 +    // sizes and none of them need to force children to reflow.
  1.1413 +    return
  1.1414 +      NS_CombineHint(hint,
  1.1415 +                     NS_SubtractHint(nsChangeHint_AllReflowHints,
  1.1416 +                                     NS_CombineHint(nsChangeHint_ClearDescendantIntrinsics,
  1.1417 +                                                    nsChangeHint_NeedDirtyReflow)));
  1.1418 +  }
  1.1419 +
  1.1420 +  // If width and height have not changed, but any of the offsets have changed,
  1.1421 +  // then return the respective hints so that we would hopefully be able to
  1.1422 +  // avoid reflowing.
  1.1423 +  // Note that it is possible that we'll need to reflow when processing
  1.1424 +  // restyles, but we don't have enough information to make a good decision
  1.1425 +  // right now.
  1.1426 +  // Don't try to handle changes between "auto" and non-auto efficiently;
  1.1427 +  // that's tricky to do and will hardly ever be able to avoid a reflow.
  1.1428 +  if (mOffset != aOther.mOffset) {
  1.1429 +    if (IsAutonessEqual(mOffset, aOther.mOffset)) {
  1.1430 +      NS_UpdateHint(hint, nsChangeHint(nsChangeHint_RecomputePosition |
  1.1431 +                                       nsChangeHint_UpdateOverflow));
  1.1432 +    } else {
  1.1433 +      return NS_CombineHint(hint, nsChangeHint_AllReflowHints);
  1.1434 +    }
  1.1435 +  }
  1.1436 +  return hint;
  1.1437 +}
  1.1438 +
  1.1439 +/* static */ bool
  1.1440 +nsStylePosition::WidthCoordDependsOnContainer(const nsStyleCoord &aCoord)
  1.1441 +{
  1.1442 +  return aCoord.GetUnit() == eStyleUnit_Auto ||
  1.1443 +         aCoord.HasPercent() ||
  1.1444 +         (aCoord.GetUnit() == eStyleUnit_Enumerated &&
  1.1445 +          (aCoord.GetIntValue() == NS_STYLE_WIDTH_FIT_CONTENT ||
  1.1446 +           aCoord.GetIntValue() == NS_STYLE_WIDTH_AVAILABLE));
  1.1447 +}
  1.1448 +
  1.1449 +// --------------------
  1.1450 +// nsStyleTable
  1.1451 +//
  1.1452 +
  1.1453 +nsStyleTable::nsStyleTable() 
  1.1454 +{ 
  1.1455 +  MOZ_COUNT_CTOR(nsStyleTable);
  1.1456 +  // values not inherited
  1.1457 +  mLayoutStrategy = NS_STYLE_TABLE_LAYOUT_AUTO;
  1.1458 +  mFrame = NS_STYLE_TABLE_FRAME_NONE;
  1.1459 +  mRules = NS_STYLE_TABLE_RULES_NONE;
  1.1460 +  mSpan = 1;
  1.1461 +}
  1.1462 +
  1.1463 +nsStyleTable::~nsStyleTable(void) 
  1.1464 +{
  1.1465 +  MOZ_COUNT_DTOR(nsStyleTable);
  1.1466 +}
  1.1467 +
  1.1468 +nsStyleTable::nsStyleTable(const nsStyleTable& aSource)
  1.1469 +{
  1.1470 +  MOZ_COUNT_CTOR(nsStyleTable);
  1.1471 +  memcpy((nsStyleTable*)this, &aSource, sizeof(nsStyleTable));
  1.1472 +}
  1.1473 +
  1.1474 +nsChangeHint nsStyleTable::CalcDifference(const nsStyleTable& aOther) const
  1.1475 +{
  1.1476 +  // Changes in mRules may require reframing (if border-collapse stuff changes, for example).
  1.1477 +  if (mRules != aOther.mRules || mSpan != aOther.mSpan ||
  1.1478 +      mLayoutStrategy != aOther.mLayoutStrategy)
  1.1479 +    return NS_STYLE_HINT_FRAMECHANGE;
  1.1480 +  if (mFrame != aOther.mFrame)
  1.1481 +    return NS_STYLE_HINT_REFLOW;
  1.1482 +  return NS_STYLE_HINT_NONE;
  1.1483 +}
  1.1484 +
  1.1485 +// -----------------------
  1.1486 +// nsStyleTableBorder
  1.1487 +
  1.1488 +nsStyleTableBorder::nsStyleTableBorder(nsPresContext* aPresContext) 
  1.1489 +{ 
  1.1490 +  MOZ_COUNT_CTOR(nsStyleTableBorder);
  1.1491 +  mBorderCollapse = NS_STYLE_BORDER_SEPARATE;
  1.1492 +
  1.1493 +  nsCompatibility compatMode = eCompatibility_FullStandards;
  1.1494 +  if (aPresContext)
  1.1495 +    compatMode = aPresContext->CompatibilityMode();
  1.1496 +  mEmptyCells = (compatMode == eCompatibility_NavQuirks)
  1.1497 +                  ? NS_STYLE_TABLE_EMPTY_CELLS_SHOW_BACKGROUND     
  1.1498 +                  : NS_STYLE_TABLE_EMPTY_CELLS_SHOW;
  1.1499 +  mCaptionSide = NS_STYLE_CAPTION_SIDE_TOP;
  1.1500 +  mBorderSpacingX = 0;
  1.1501 +  mBorderSpacingY = 0;
  1.1502 +}
  1.1503 +
  1.1504 +nsStyleTableBorder::~nsStyleTableBorder(void) 
  1.1505 +{
  1.1506 +  MOZ_COUNT_DTOR(nsStyleTableBorder);
  1.1507 +}
  1.1508 +
  1.1509 +nsStyleTableBorder::nsStyleTableBorder(const nsStyleTableBorder& aSource)
  1.1510 +{
  1.1511 +  MOZ_COUNT_CTOR(nsStyleTableBorder);
  1.1512 +  memcpy((nsStyleTableBorder*)this, &aSource, sizeof(nsStyleTableBorder));
  1.1513 +}
  1.1514 +
  1.1515 +nsChangeHint nsStyleTableBorder::CalcDifference(const nsStyleTableBorder& aOther) const
  1.1516 +{
  1.1517 +  // Border-collapse changes need a reframe, because we use a different frame
  1.1518 +  // class for table cells in the collapsed border model.  This is used to
  1.1519 +  // conserve memory when using the separated border model (collapsed borders
  1.1520 +  // require extra state to be stored).
  1.1521 +  if (mBorderCollapse != aOther.mBorderCollapse) {
  1.1522 +    return NS_STYLE_HINT_FRAMECHANGE;
  1.1523 +  }
  1.1524 +  
  1.1525 +  if ((mCaptionSide == aOther.mCaptionSide) &&
  1.1526 +      (mBorderSpacingX == aOther.mBorderSpacingX) &&
  1.1527 +      (mBorderSpacingY == aOther.mBorderSpacingY)) {
  1.1528 +    if (mEmptyCells == aOther.mEmptyCells)
  1.1529 +      return NS_STYLE_HINT_NONE;
  1.1530 +    return NS_STYLE_HINT_VISUAL;
  1.1531 +  }
  1.1532 +  else
  1.1533 +    return NS_STYLE_HINT_REFLOW;
  1.1534 +}
  1.1535 +
  1.1536 +// --------------------
  1.1537 +// nsStyleColor
  1.1538 +//
  1.1539 +
  1.1540 +nsStyleColor::nsStyleColor(nsPresContext* aPresContext)
  1.1541 +{
  1.1542 +  MOZ_COUNT_CTOR(nsStyleColor);
  1.1543 +  mColor = aPresContext->DefaultColor();
  1.1544 +}
  1.1545 +
  1.1546 +nsStyleColor::nsStyleColor(const nsStyleColor& aSource)
  1.1547 +{
  1.1548 +  MOZ_COUNT_CTOR(nsStyleColor);
  1.1549 +  mColor = aSource.mColor;
  1.1550 +}
  1.1551 +
  1.1552 +nsChangeHint nsStyleColor::CalcDifference(const nsStyleColor& aOther) const
  1.1553 +{
  1.1554 +  if (mColor == aOther.mColor)
  1.1555 +    return NS_STYLE_HINT_NONE;
  1.1556 +  return NS_STYLE_HINT_VISUAL;
  1.1557 +}
  1.1558 +
  1.1559 +// --------------------
  1.1560 +// nsStyleGradient
  1.1561 +//
  1.1562 +bool
  1.1563 +nsStyleGradient::operator==(const nsStyleGradient& aOther) const
  1.1564 +{
  1.1565 +  NS_ABORT_IF_FALSE(mSize == NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER ||
  1.1566 +                    mShape != NS_STYLE_GRADIENT_SHAPE_LINEAR,
  1.1567 +                    "incorrect combination of shape and size");
  1.1568 +  NS_ABORT_IF_FALSE(aOther.mSize == NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER ||
  1.1569 +                    aOther.mShape != NS_STYLE_GRADIENT_SHAPE_LINEAR,
  1.1570 +                    "incorrect combination of shape and size");
  1.1571 +
  1.1572 +  if (mShape != aOther.mShape ||
  1.1573 +      mSize != aOther.mSize ||
  1.1574 +      mRepeating != aOther.mRepeating ||
  1.1575 +      mLegacySyntax != aOther.mLegacySyntax ||
  1.1576 +      mBgPosX != aOther.mBgPosX ||
  1.1577 +      mBgPosY != aOther.mBgPosY ||
  1.1578 +      mAngle != aOther.mAngle ||
  1.1579 +      mRadiusX != aOther.mRadiusX ||
  1.1580 +      mRadiusY != aOther.mRadiusY)
  1.1581 +    return false;
  1.1582 +
  1.1583 +  if (mStops.Length() != aOther.mStops.Length())
  1.1584 +    return false;
  1.1585 +
  1.1586 +  for (uint32_t i = 0; i < mStops.Length(); i++) {
  1.1587 +    if (mStops[i].mLocation != aOther.mStops[i].mLocation ||
  1.1588 +        mStops[i].mColor != aOther.mStops[i].mColor)
  1.1589 +      return false;
  1.1590 +  }
  1.1591 +
  1.1592 +  return true;
  1.1593 +}
  1.1594 +
  1.1595 +nsStyleGradient::nsStyleGradient(void)
  1.1596 +  : mShape(NS_STYLE_GRADIENT_SHAPE_LINEAR)
  1.1597 +  , mSize(NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER)
  1.1598 +  , mRepeating(false)
  1.1599 +  , mLegacySyntax(false)
  1.1600 +{
  1.1601 +}
  1.1602 +
  1.1603 +bool
  1.1604 +nsStyleGradient::IsOpaque()
  1.1605 +{
  1.1606 +  for (uint32_t i = 0; i < mStops.Length(); i++) {
  1.1607 +    if (NS_GET_A(mStops[i].mColor) < 255)
  1.1608 +      return false;
  1.1609 +  }
  1.1610 +  return true;
  1.1611 +}
  1.1612 +
  1.1613 +bool
  1.1614 +nsStyleGradient::HasCalc()
  1.1615 +{
  1.1616 +  for (uint32_t i = 0; i < mStops.Length(); i++) {
  1.1617 +    if (mStops[i].mLocation.IsCalcUnit())
  1.1618 +      return true;
  1.1619 +  }
  1.1620 +  return mBgPosX.IsCalcUnit() || mBgPosY.IsCalcUnit() || mAngle.IsCalcUnit() ||
  1.1621 +         mRadiusX.IsCalcUnit() || mRadiusY.IsCalcUnit();
  1.1622 +}
  1.1623 +
  1.1624 +// --------------------
  1.1625 +// nsStyleImage
  1.1626 +//
  1.1627 +
  1.1628 +nsStyleImage::nsStyleImage()
  1.1629 +  : mType(eStyleImageType_Null)
  1.1630 +  , mCropRect(nullptr)
  1.1631 +#ifdef DEBUG
  1.1632 +  , mImageTracked(false)
  1.1633 +#endif
  1.1634 +{
  1.1635 +  MOZ_COUNT_CTOR(nsStyleImage);
  1.1636 +}
  1.1637 +
  1.1638 +nsStyleImage::~nsStyleImage()
  1.1639 +{
  1.1640 +  MOZ_COUNT_DTOR(nsStyleImage);
  1.1641 +  if (mType != eStyleImageType_Null)
  1.1642 +    SetNull();
  1.1643 +}
  1.1644 +
  1.1645 +nsStyleImage::nsStyleImage(const nsStyleImage& aOther)
  1.1646 +  : mType(eStyleImageType_Null)
  1.1647 +  , mCropRect(nullptr)
  1.1648 +#ifdef DEBUG
  1.1649 +  , mImageTracked(false)
  1.1650 +#endif
  1.1651 +{
  1.1652 +  // We need our own copy constructor because we don't want
  1.1653 +  // to copy the reference count
  1.1654 +  MOZ_COUNT_CTOR(nsStyleImage);
  1.1655 +  DoCopy(aOther);
  1.1656 +}
  1.1657 +
  1.1658 +nsStyleImage&
  1.1659 +nsStyleImage::operator=(const nsStyleImage& aOther)
  1.1660 +{
  1.1661 +  if (this != &aOther)
  1.1662 +    DoCopy(aOther);
  1.1663 +
  1.1664 +  return *this;
  1.1665 +}
  1.1666 +
  1.1667 +void
  1.1668 +nsStyleImage::DoCopy(const nsStyleImage& aOther)
  1.1669 +{
  1.1670 +  SetNull();
  1.1671 +
  1.1672 +  if (aOther.mType == eStyleImageType_Image)
  1.1673 +    SetImageData(aOther.mImage);
  1.1674 +  else if (aOther.mType == eStyleImageType_Gradient)
  1.1675 +    SetGradientData(aOther.mGradient);
  1.1676 +  else if (aOther.mType == eStyleImageType_Element)
  1.1677 +    SetElementId(aOther.mElementId);
  1.1678 +
  1.1679 +  SetCropRect(aOther.mCropRect);
  1.1680 +}
  1.1681 +
  1.1682 +void
  1.1683 +nsStyleImage::SetNull()
  1.1684 +{
  1.1685 +  NS_ABORT_IF_FALSE(!mImageTracked,
  1.1686 +                    "Calling SetNull() with image tracked!");
  1.1687 +
  1.1688 +  if (mType == eStyleImageType_Gradient)
  1.1689 +    mGradient->Release();
  1.1690 +  else if (mType == eStyleImageType_Image)
  1.1691 +    NS_RELEASE(mImage);
  1.1692 +  else if (mType == eStyleImageType_Element)
  1.1693 +    NS_Free(mElementId);
  1.1694 +
  1.1695 +  mType = eStyleImageType_Null;
  1.1696 +  mCropRect = nullptr;
  1.1697 +}
  1.1698 +
  1.1699 +void
  1.1700 +nsStyleImage::SetImageData(imgIRequest* aImage)
  1.1701 +{
  1.1702 +  NS_ABORT_IF_FALSE(!mImageTracked,
  1.1703 +                    "Setting a new image without untracking the old one!");
  1.1704 +
  1.1705 +  NS_IF_ADDREF(aImage);
  1.1706 +
  1.1707 +  if (mType != eStyleImageType_Null)
  1.1708 +    SetNull();
  1.1709 +
  1.1710 +  if (aImage) {
  1.1711 +    mImage = aImage;
  1.1712 +    mType = eStyleImageType_Image;
  1.1713 +  }
  1.1714 +  mSubImages.Clear();
  1.1715 +}
  1.1716 +
  1.1717 +void
  1.1718 +nsStyleImage::TrackImage(nsPresContext* aContext)
  1.1719 +{
  1.1720 +  // Sanity
  1.1721 +  NS_ABORT_IF_FALSE(!mImageTracked, "Already tracking image!");
  1.1722 +  NS_ABORT_IF_FALSE(mType == eStyleImageType_Image,
  1.1723 +                    "Can't track image when there isn't one!");
  1.1724 +
  1.1725 +  // Register the image with the document
  1.1726 +  nsIDocument* doc = aContext->Document();
  1.1727 +  if (doc)
  1.1728 +    doc->AddImage(mImage);
  1.1729 +
  1.1730 +  // Mark state
  1.1731 +#ifdef DEBUG
  1.1732 +  mImageTracked = true;
  1.1733 +#endif
  1.1734 +}
  1.1735 +
  1.1736 +void
  1.1737 +nsStyleImage::UntrackImage(nsPresContext* aContext)
  1.1738 +{
  1.1739 +  // Sanity
  1.1740 +  NS_ABORT_IF_FALSE(mImageTracked, "Image not tracked!");
  1.1741 +  NS_ABORT_IF_FALSE(mType == eStyleImageType_Image,
  1.1742 +                    "Can't untrack image when there isn't one!");
  1.1743 +
  1.1744 +  // Unregister the image with the document
  1.1745 +  nsIDocument* doc = aContext->Document();
  1.1746 +  if (doc)
  1.1747 +    doc->RemoveImage(mImage, nsIDocument::REQUEST_DISCARD);
  1.1748 +
  1.1749 +  // Mark state
  1.1750 +#ifdef DEBUG
  1.1751 +  mImageTracked = false;
  1.1752 +#endif
  1.1753 +}
  1.1754 +
  1.1755 +void
  1.1756 +nsStyleImage::SetGradientData(nsStyleGradient* aGradient)
  1.1757 +{
  1.1758 +  if (aGradient)
  1.1759 +    aGradient->AddRef();
  1.1760 +
  1.1761 +  if (mType != eStyleImageType_Null)
  1.1762 +    SetNull();
  1.1763 +
  1.1764 +  if (aGradient) {
  1.1765 +    mGradient = aGradient;
  1.1766 +    mType = eStyleImageType_Gradient;
  1.1767 +  }
  1.1768 +}
  1.1769 +
  1.1770 +void
  1.1771 +nsStyleImage::SetElementId(const char16_t* aElementId)
  1.1772 +{
  1.1773 +  if (mType != eStyleImageType_Null)
  1.1774 +    SetNull();
  1.1775 +
  1.1776 +  if (aElementId) {
  1.1777 +    mElementId = NS_strdup(aElementId);
  1.1778 +    mType = eStyleImageType_Element;
  1.1779 +  }
  1.1780 +}
  1.1781 +
  1.1782 +void
  1.1783 +nsStyleImage::SetCropRect(nsStyleSides* aCropRect)
  1.1784 +{
  1.1785 +  if (aCropRect) {
  1.1786 +    mCropRect = new nsStyleSides(*aCropRect);
  1.1787 +    // There is really not much we can do if 'new' fails
  1.1788 +  } else {
  1.1789 +    mCropRect = nullptr;
  1.1790 +  }
  1.1791 +}
  1.1792 +
  1.1793 +static int32_t
  1.1794 +ConvertToPixelCoord(const nsStyleCoord& aCoord, int32_t aPercentScale)
  1.1795 +{
  1.1796 +  double pixelValue;
  1.1797 +  switch (aCoord.GetUnit()) {
  1.1798 +    case eStyleUnit_Percent:
  1.1799 +      pixelValue = aCoord.GetPercentValue() * aPercentScale;
  1.1800 +      break;
  1.1801 +    case eStyleUnit_Factor:
  1.1802 +      pixelValue = aCoord.GetFactorValue();
  1.1803 +      break;
  1.1804 +    default:
  1.1805 +      NS_NOTREACHED("unexpected unit for image crop rect");
  1.1806 +      return 0;
  1.1807 +  }
  1.1808 +  NS_ABORT_IF_FALSE(pixelValue >= 0, "we ensured non-negative while parsing");
  1.1809 +  pixelValue = std::min(pixelValue, double(INT32_MAX)); // avoid overflow
  1.1810 +  return NS_lround(pixelValue);
  1.1811 +}
  1.1812 +
  1.1813 +bool
  1.1814 +nsStyleImage::ComputeActualCropRect(nsIntRect& aActualCropRect,
  1.1815 +                                    bool* aIsEntireImage) const
  1.1816 +{
  1.1817 +  if (mType != eStyleImageType_Image)
  1.1818 +    return false;
  1.1819 +
  1.1820 +  nsCOMPtr<imgIContainer> imageContainer;
  1.1821 +  mImage->GetImage(getter_AddRefs(imageContainer));
  1.1822 +  if (!imageContainer)
  1.1823 +    return false;
  1.1824 +
  1.1825 +  nsIntSize imageSize;
  1.1826 +  imageContainer->GetWidth(&imageSize.width);
  1.1827 +  imageContainer->GetHeight(&imageSize.height);
  1.1828 +  if (imageSize.width <= 0 || imageSize.height <= 0)
  1.1829 +    return false;
  1.1830 +
  1.1831 +  int32_t left   = ConvertToPixelCoord(mCropRect->GetLeft(),   imageSize.width);
  1.1832 +  int32_t top    = ConvertToPixelCoord(mCropRect->GetTop(),    imageSize.height);
  1.1833 +  int32_t right  = ConvertToPixelCoord(mCropRect->GetRight(),  imageSize.width);
  1.1834 +  int32_t bottom = ConvertToPixelCoord(mCropRect->GetBottom(), imageSize.height);
  1.1835 +
  1.1836 +  // IntersectRect() returns an empty rect if we get negative width or height
  1.1837 +  nsIntRect cropRect(left, top, right - left, bottom - top);
  1.1838 +  nsIntRect imageRect(nsIntPoint(0, 0), imageSize);
  1.1839 +  aActualCropRect.IntersectRect(imageRect, cropRect);
  1.1840 +
  1.1841 +  if (aIsEntireImage)
  1.1842 +    *aIsEntireImage = aActualCropRect.IsEqualInterior(imageRect);
  1.1843 +  return true;
  1.1844 +}
  1.1845 +
  1.1846 +nsresult
  1.1847 +nsStyleImage::StartDecoding() const
  1.1848 +{
  1.1849 +  if ((mType == eStyleImageType_Image) && mImage)
  1.1850 +    return mImage->StartDecoding();
  1.1851 +  return NS_OK;
  1.1852 +}
  1.1853 +
  1.1854 +bool
  1.1855 +nsStyleImage::IsOpaque() const
  1.1856 +{
  1.1857 +  if (!IsComplete())
  1.1858 +    return false;
  1.1859 +
  1.1860 +  if (mType == eStyleImageType_Gradient)
  1.1861 +    return mGradient->IsOpaque();
  1.1862 +
  1.1863 +  if (mType == eStyleImageType_Element)
  1.1864 +    return false;
  1.1865 +
  1.1866 +  NS_ABORT_IF_FALSE(mType == eStyleImageType_Image, "unexpected image type");
  1.1867 +
  1.1868 +  nsCOMPtr<imgIContainer> imageContainer;
  1.1869 +  mImage->GetImage(getter_AddRefs(imageContainer));
  1.1870 +  NS_ABORT_IF_FALSE(imageContainer, "IsComplete() said image container is ready");
  1.1871 +
  1.1872 +  // Check if the crop region of the current image frame is opaque.
  1.1873 +  if (imageContainer->FrameIsOpaque(imgIContainer::FRAME_CURRENT)) {
  1.1874 +    if (!mCropRect)
  1.1875 +      return true;
  1.1876 +
  1.1877 +    // Must make sure if mCropRect contains at least a pixel.
  1.1878 +    // XXX Is this optimization worth it? Maybe I should just return false.
  1.1879 +    nsIntRect actualCropRect;
  1.1880 +    bool rv = ComputeActualCropRect(actualCropRect);
  1.1881 +    NS_ASSERTION(rv, "ComputeActualCropRect() can not fail here");
  1.1882 +    return rv && !actualCropRect.IsEmpty();
  1.1883 +  }
  1.1884 +
  1.1885 +  return false;
  1.1886 +}
  1.1887 +
  1.1888 +bool
  1.1889 +nsStyleImage::IsComplete() const
  1.1890 +{
  1.1891 +  switch (mType) {
  1.1892 +    case eStyleImageType_Null:
  1.1893 +      return false;
  1.1894 +    case eStyleImageType_Gradient:
  1.1895 +    case eStyleImageType_Element:
  1.1896 +      return true;
  1.1897 +    case eStyleImageType_Image:
  1.1898 +    {
  1.1899 +      uint32_t status = imgIRequest::STATUS_ERROR;
  1.1900 +      return NS_SUCCEEDED(mImage->GetImageStatus(&status)) &&
  1.1901 +             (status & imgIRequest::STATUS_SIZE_AVAILABLE) &&
  1.1902 +             (status & imgIRequest::STATUS_FRAME_COMPLETE);
  1.1903 +    }
  1.1904 +    default:
  1.1905 +      NS_NOTREACHED("unexpected image type");
  1.1906 +      return false;
  1.1907 +  }
  1.1908 +}
  1.1909 +
  1.1910 +bool
  1.1911 +nsStyleImage::IsLoaded() const
  1.1912 +{
  1.1913 +  switch (mType) {
  1.1914 +    case eStyleImageType_Null:
  1.1915 +      return false;
  1.1916 +    case eStyleImageType_Gradient:
  1.1917 +    case eStyleImageType_Element:
  1.1918 +      return true;
  1.1919 +    case eStyleImageType_Image:
  1.1920 +    {
  1.1921 +      uint32_t status = imgIRequest::STATUS_ERROR;
  1.1922 +      return NS_SUCCEEDED(mImage->GetImageStatus(&status)) &&
  1.1923 +             !(status & imgIRequest::STATUS_ERROR) &&
  1.1924 +             (status & imgIRequest::STATUS_LOAD_COMPLETE);
  1.1925 +    }
  1.1926 +    default:
  1.1927 +      NS_NOTREACHED("unexpected image type");
  1.1928 +      return false;
  1.1929 +  }
  1.1930 +}
  1.1931 +
  1.1932 +static inline bool
  1.1933 +EqualRects(const nsStyleSides* aRect1, const nsStyleSides* aRect2)
  1.1934 +{
  1.1935 +  return aRect1 == aRect2 || /* handles null== null, and optimize */
  1.1936 +         (aRect1 && aRect2 && *aRect1 == *aRect2);
  1.1937 +}
  1.1938 +
  1.1939 +bool
  1.1940 +nsStyleImage::operator==(const nsStyleImage& aOther) const
  1.1941 +{
  1.1942 +  if (mType != aOther.mType)
  1.1943 +    return false;
  1.1944 +
  1.1945 +  if (!EqualRects(mCropRect, aOther.mCropRect))
  1.1946 +    return false;
  1.1947 +
  1.1948 +  if (mType == eStyleImageType_Image)
  1.1949 +    return EqualImages(mImage, aOther.mImage);
  1.1950 +
  1.1951 +  if (mType == eStyleImageType_Gradient)
  1.1952 +    return *mGradient == *aOther.mGradient;
  1.1953 +
  1.1954 +  if (mType == eStyleImageType_Element)
  1.1955 +    return NS_strcmp(mElementId, aOther.mElementId) == 0;
  1.1956 +
  1.1957 +  return true;
  1.1958 +}
  1.1959 +
  1.1960 +// --------------------
  1.1961 +// nsStyleBackground
  1.1962 +//
  1.1963 +
  1.1964 +nsStyleBackground::nsStyleBackground()
  1.1965 +  : mAttachmentCount(1)
  1.1966 +  , mClipCount(1)
  1.1967 +  , mOriginCount(1)
  1.1968 +  , mRepeatCount(1)
  1.1969 +  , mPositionCount(1)
  1.1970 +  , mImageCount(1)
  1.1971 +  , mSizeCount(1)
  1.1972 +  , mBlendModeCount(1)
  1.1973 +  , mBackgroundColor(NS_RGBA(0, 0, 0, 0))
  1.1974 +  , mBackgroundInlinePolicy(NS_STYLE_BG_INLINE_POLICY_CONTINUOUS)
  1.1975 +{
  1.1976 +  MOZ_COUNT_CTOR(nsStyleBackground);
  1.1977 +  Layer *onlyLayer = mLayers.AppendElement();
  1.1978 +  NS_ASSERTION(onlyLayer, "auto array must have room for 1 element");
  1.1979 +  onlyLayer->SetInitialValues();
  1.1980 +}
  1.1981 +
  1.1982 +nsStyleBackground::nsStyleBackground(const nsStyleBackground& aSource)
  1.1983 +  : mAttachmentCount(aSource.mAttachmentCount)
  1.1984 +  , mClipCount(aSource.mClipCount)
  1.1985 +  , mOriginCount(aSource.mOriginCount)
  1.1986 +  , mRepeatCount(aSource.mRepeatCount)
  1.1987 +  , mPositionCount(aSource.mPositionCount)
  1.1988 +  , mImageCount(aSource.mImageCount)
  1.1989 +  , mSizeCount(aSource.mSizeCount)
  1.1990 +  , mBlendModeCount(aSource.mBlendModeCount)
  1.1991 +  , mLayers(aSource.mLayers) // deep copy
  1.1992 +  , mBackgroundColor(aSource.mBackgroundColor)
  1.1993 +  , mBackgroundInlinePolicy(aSource.mBackgroundInlinePolicy)
  1.1994 +{
  1.1995 +  MOZ_COUNT_CTOR(nsStyleBackground);
  1.1996 +  // If the deep copy of mLayers failed, truncate the counts.
  1.1997 +  uint32_t count = mLayers.Length();
  1.1998 +  if (count != aSource.mLayers.Length()) {
  1.1999 +    NS_WARNING("truncating counts due to out-of-memory");
  1.2000 +    mAttachmentCount = std::max(mAttachmentCount, count);
  1.2001 +    mClipCount = std::max(mClipCount, count);
  1.2002 +    mOriginCount = std::max(mOriginCount, count);
  1.2003 +    mRepeatCount = std::max(mRepeatCount, count);
  1.2004 +    mPositionCount = std::max(mPositionCount, count);
  1.2005 +    mImageCount = std::max(mImageCount, count);
  1.2006 +    mSizeCount = std::max(mSizeCount, count);
  1.2007 +    mBlendModeCount = std::max(mSizeCount, count);
  1.2008 +  }
  1.2009 +}
  1.2010 +
  1.2011 +nsStyleBackground::~nsStyleBackground()
  1.2012 +{
  1.2013 +  MOZ_COUNT_DTOR(nsStyleBackground);
  1.2014 +}
  1.2015 +
  1.2016 +void
  1.2017 +nsStyleBackground::Destroy(nsPresContext* aContext)
  1.2018 +{
  1.2019 +  // Untrack all the images stored in our layers
  1.2020 +  for (uint32_t i = 0; i < mImageCount; ++i)
  1.2021 +    mLayers[i].UntrackImages(aContext);
  1.2022 +
  1.2023 +  this->~nsStyleBackground();
  1.2024 +  aContext->FreeToShell(sizeof(nsStyleBackground), this);
  1.2025 +}
  1.2026 +
  1.2027 +nsChangeHint nsStyleBackground::CalcDifference(const nsStyleBackground& aOther) const
  1.2028 +{
  1.2029 +  const nsStyleBackground* moreLayers =
  1.2030 +    mImageCount > aOther.mImageCount ? this : &aOther;
  1.2031 +  const nsStyleBackground* lessLayers =
  1.2032 +    mImageCount > aOther.mImageCount ? &aOther : this;
  1.2033 +
  1.2034 +  bool hasVisualDifference = false;
  1.2035 +
  1.2036 +  NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(i, moreLayers) {
  1.2037 +    if (i < lessLayers->mImageCount) {
  1.2038 +      if (moreLayers->mLayers[i] != lessLayers->mLayers[i]) {
  1.2039 +        if ((moreLayers->mLayers[i].mImage.GetType() == eStyleImageType_Element) ||
  1.2040 +            (lessLayers->mLayers[i].mImage.GetType() == eStyleImageType_Element))
  1.2041 +          return NS_CombineHint(nsChangeHint_UpdateEffects, NS_STYLE_HINT_VISUAL);
  1.2042 +        hasVisualDifference = true;
  1.2043 +      }
  1.2044 +    } else {
  1.2045 +      if (moreLayers->mLayers[i].mImage.GetType() == eStyleImageType_Element)
  1.2046 +        return NS_CombineHint(nsChangeHint_UpdateEffects, NS_STYLE_HINT_VISUAL);
  1.2047 +      hasVisualDifference = true;
  1.2048 +    }
  1.2049 +  }
  1.2050 +
  1.2051 +  if (hasVisualDifference ||
  1.2052 +      mBackgroundColor != aOther.mBackgroundColor ||
  1.2053 +      mBackgroundInlinePolicy != aOther.mBackgroundInlinePolicy)
  1.2054 +    return NS_STYLE_HINT_VISUAL;
  1.2055 +
  1.2056 +  return NS_STYLE_HINT_NONE;
  1.2057 +}
  1.2058 +
  1.2059 +bool nsStyleBackground::HasFixedBackground() const
  1.2060 +{
  1.2061 +  NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(i, this) {
  1.2062 +    const Layer &layer = mLayers[i];
  1.2063 +    if (layer.mAttachment == NS_STYLE_BG_ATTACHMENT_FIXED &&
  1.2064 +        !layer.mImage.IsEmpty()) {
  1.2065 +      return true;
  1.2066 +    }
  1.2067 +  }
  1.2068 +  return false;
  1.2069 +}
  1.2070 +
  1.2071 +bool nsStyleBackground::IsTransparent() const
  1.2072 +{
  1.2073 +  return BottomLayer().mImage.IsEmpty() &&
  1.2074 +         mImageCount == 1 &&
  1.2075 +         NS_GET_A(mBackgroundColor) == 0;
  1.2076 +}
  1.2077 +
  1.2078 +void
  1.2079 +nsStyleBackground::Position::SetInitialValues()
  1.2080 +{
  1.2081 +  // Initial value is "0% 0%"
  1.2082 +  mXPosition.mPercent = 0.0f;
  1.2083 +  mXPosition.mLength = 0;
  1.2084 +  mXPosition.mHasPercent = true;
  1.2085 +  mYPosition.mPercent = 0.0f;
  1.2086 +  mYPosition.mLength = 0;
  1.2087 +  mYPosition.mHasPercent = true;
  1.2088 +}
  1.2089 +
  1.2090 +bool
  1.2091 +nsStyleBackground::Size::DependsOnPositioningAreaSize(const nsStyleImage& aImage) const
  1.2092 +{
  1.2093 +  NS_ABORT_IF_FALSE(aImage.GetType() != eStyleImageType_Null,
  1.2094 +                    "caller should have handled this");
  1.2095 +
  1.2096 +  // If either dimension contains a non-zero percentage, rendering for that
  1.2097 +  // dimension straightforwardly depends on frame size.
  1.2098 +  if ((mWidthType == eLengthPercentage && mWidth.mPercent != 0.0f) ||
  1.2099 +      (mHeightType == eLengthPercentage && mHeight.mPercent != 0.0f)) {
  1.2100 +    return true;
  1.2101 +  }
  1.2102 +
  1.2103 +  // So too for contain and cover.
  1.2104 +  if (mWidthType == eContain || mWidthType == eCover) {
  1.2105 +    return true;
  1.2106 +  }
  1.2107 +
  1.2108 +  // If both dimensions are fixed lengths, there's no dependency.
  1.2109 +  if (mWidthType == eLengthPercentage && mHeightType == eLengthPercentage) {
  1.2110 +    return false;
  1.2111 +  }
  1.2112 +
  1.2113 +  NS_ABORT_IF_FALSE((mWidthType == eLengthPercentage && mHeightType == eAuto) ||
  1.2114 +                    (mWidthType == eAuto && mHeightType == eLengthPercentage) ||
  1.2115 +                    (mWidthType == eAuto && mHeightType == eAuto),
  1.2116 +                    "logic error");
  1.2117 +
  1.2118 +  nsStyleImageType type = aImage.GetType();
  1.2119 +
  1.2120 +  // Gradient rendering depends on frame size when auto is involved because
  1.2121 +  // gradients have no intrinsic ratio or dimensions, and therefore the relevant
  1.2122 +  // dimension is "treat[ed] as 100%".
  1.2123 +  if (type == eStyleImageType_Gradient) {
  1.2124 +    return true;
  1.2125 +  }
  1.2126 +
  1.2127 +  // XXX Element rendering for auto or fixed length doesn't depend on frame size
  1.2128 +  //     according to the spec.  However, we don't implement the spec yet, so
  1.2129 +  //     for now we bail and say element() plus auto affects ultimate size.
  1.2130 +  if (type == eStyleImageType_Element) {
  1.2131 +    return true;
  1.2132 +  }
  1.2133 +
  1.2134 +  if (type == eStyleImageType_Image) {
  1.2135 +    nsCOMPtr<imgIContainer> imgContainer;
  1.2136 +    aImage.GetImageData()->GetImage(getter_AddRefs(imgContainer));
  1.2137 +    if (imgContainer) {
  1.2138 +      nsIntSize imageSize;
  1.2139 +      nsSize imageRatio;
  1.2140 +      bool hasWidth, hasHeight;
  1.2141 +      nsLayoutUtils::ComputeSizeForDrawing(imgContainer, imageSize, imageRatio,
  1.2142 +                                           hasWidth, hasHeight);
  1.2143 +
  1.2144 +      // If the image has a fixed width and height, rendering never depends on
  1.2145 +      // the frame size.
  1.2146 +      if (hasWidth && hasHeight) {
  1.2147 +        return false;
  1.2148 +      }
  1.2149 +
  1.2150 +      // If the image has an intrinsic ratio, rendering will depend on frame
  1.2151 +      // size when background-size is all auto.
  1.2152 +      if (imageRatio != nsSize(0, 0)) {
  1.2153 +        return mWidthType == mHeightType;
  1.2154 +      }
  1.2155 +
  1.2156 +      // Otherwise, rendering depends on frame size when the image dimensions
  1.2157 +      // and background-size don't complement each other.
  1.2158 +      return !(hasWidth && mHeightType == eLengthPercentage) &&
  1.2159 +             !(hasHeight && mWidthType == eLengthPercentage);
  1.2160 +    }
  1.2161 +  } else {
  1.2162 +    NS_NOTREACHED("missed an enum value");
  1.2163 +  }
  1.2164 +
  1.2165 +  // Passed the gauntlet: no dependency.
  1.2166 +  return false;
  1.2167 +}
  1.2168 +
  1.2169 +void
  1.2170 +nsStyleBackground::Size::SetInitialValues()
  1.2171 +{
  1.2172 +  mWidthType = mHeightType = eAuto;
  1.2173 +}
  1.2174 +
  1.2175 +bool
  1.2176 +nsStyleBackground::Size::operator==(const Size& aOther) const
  1.2177 +{
  1.2178 +  NS_ABORT_IF_FALSE(mWidthType < eDimensionType_COUNT,
  1.2179 +                    "bad mWidthType for this");
  1.2180 +  NS_ABORT_IF_FALSE(mHeightType < eDimensionType_COUNT,
  1.2181 +                    "bad mHeightType for this");
  1.2182 +  NS_ABORT_IF_FALSE(aOther.mWidthType < eDimensionType_COUNT,
  1.2183 +                    "bad mWidthType for aOther");
  1.2184 +  NS_ABORT_IF_FALSE(aOther.mHeightType < eDimensionType_COUNT,
  1.2185 +                    "bad mHeightType for aOther");
  1.2186 +
  1.2187 +  return mWidthType == aOther.mWidthType &&
  1.2188 +         mHeightType == aOther.mHeightType &&
  1.2189 +         (mWidthType != eLengthPercentage || mWidth == aOther.mWidth) &&
  1.2190 +         (mHeightType != eLengthPercentage || mHeight == aOther.mHeight);
  1.2191 +}
  1.2192 +
  1.2193 +void
  1.2194 +nsStyleBackground::Repeat::SetInitialValues() 
  1.2195 +{
  1.2196 +  mXRepeat = NS_STYLE_BG_REPEAT_REPEAT;
  1.2197 +  mYRepeat = NS_STYLE_BG_REPEAT_REPEAT;
  1.2198 +}
  1.2199 +
  1.2200 +nsStyleBackground::Layer::Layer()
  1.2201 +{
  1.2202 +}
  1.2203 +
  1.2204 +nsStyleBackground::Layer::~Layer()
  1.2205 +{
  1.2206 +}
  1.2207 +
  1.2208 +void
  1.2209 +nsStyleBackground::Layer::SetInitialValues()
  1.2210 +{
  1.2211 +  mAttachment = NS_STYLE_BG_ATTACHMENT_SCROLL;
  1.2212 +  mClip = NS_STYLE_BG_CLIP_BORDER;
  1.2213 +  mOrigin = NS_STYLE_BG_ORIGIN_PADDING;
  1.2214 +  mRepeat.SetInitialValues();
  1.2215 +  mBlendMode = NS_STYLE_BLEND_NORMAL;
  1.2216 +  mPosition.SetInitialValues();
  1.2217 +  mSize.SetInitialValues();
  1.2218 +  mImage.SetNull();
  1.2219 +}
  1.2220 +
  1.2221 +bool
  1.2222 +nsStyleBackground::Layer::RenderingMightDependOnPositioningAreaSizeChange() const
  1.2223 +{
  1.2224 +  // Do we even have an image?
  1.2225 +  if (mImage.IsEmpty()) {
  1.2226 +    return false;
  1.2227 +  }
  1.2228 +
  1.2229 +  return mPosition.DependsOnPositioningAreaSize() ||
  1.2230 +      mSize.DependsOnPositioningAreaSize(mImage);
  1.2231 +}
  1.2232 +
  1.2233 +bool
  1.2234 +nsStyleBackground::Layer::operator==(const Layer& aOther) const
  1.2235 +{
  1.2236 +  return mAttachment == aOther.mAttachment &&
  1.2237 +         mClip == aOther.mClip &&
  1.2238 +         mOrigin == aOther.mOrigin &&
  1.2239 +         mRepeat == aOther.mRepeat &&
  1.2240 +         mBlendMode == aOther.mBlendMode &&
  1.2241 +         mPosition == aOther.mPosition &&
  1.2242 +         mSize == aOther.mSize &&
  1.2243 +         mImage == aOther.mImage;
  1.2244 +}
  1.2245 +
  1.2246 +// --------------------
  1.2247 +// nsStyleDisplay
  1.2248 +//
  1.2249 +void nsTimingFunction::AssignFromKeyword(int32_t aTimingFunctionType)
  1.2250 +{
  1.2251 +  switch (aTimingFunctionType) {
  1.2252 +    case NS_STYLE_TRANSITION_TIMING_FUNCTION_STEP_START:
  1.2253 +      mType = StepStart;
  1.2254 +      mSteps = 1;
  1.2255 +      return;
  1.2256 +    case NS_STYLE_TRANSITION_TIMING_FUNCTION_STEP_END:
  1.2257 +      mType = StepEnd;
  1.2258 +      mSteps = 1;
  1.2259 +      return;
  1.2260 +    default:
  1.2261 +      mType = Function;
  1.2262 +      break;
  1.2263 +  }
  1.2264 +
  1.2265 +  static_assert(NS_STYLE_TRANSITION_TIMING_FUNCTION_EASE == 0 &&
  1.2266 +                NS_STYLE_TRANSITION_TIMING_FUNCTION_LINEAR == 1 &&
  1.2267 +                NS_STYLE_TRANSITION_TIMING_FUNCTION_EASE_IN == 2 &&
  1.2268 +                NS_STYLE_TRANSITION_TIMING_FUNCTION_EASE_OUT == 3 &&
  1.2269 +                NS_STYLE_TRANSITION_TIMING_FUNCTION_EASE_IN_OUT == 4,
  1.2270 +                "transition timing function constants not as expected");
  1.2271 +
  1.2272 +  static const float timingFunctionValues[5][4] = {
  1.2273 +    { 0.25f, 0.10f, 0.25f, 1.00f }, // ease
  1.2274 +    { 0.00f, 0.00f, 1.00f, 1.00f }, // linear
  1.2275 +    { 0.42f, 0.00f, 1.00f, 1.00f }, // ease-in
  1.2276 +    { 0.00f, 0.00f, 0.58f, 1.00f }, // ease-out
  1.2277 +    { 0.42f, 0.00f, 0.58f, 1.00f }  // ease-in-out
  1.2278 +  };
  1.2279 +
  1.2280 +  NS_ABORT_IF_FALSE(0 <= aTimingFunctionType && aTimingFunctionType < 5,
  1.2281 +                    "keyword out of range");
  1.2282 +  mFunc.mX1 = timingFunctionValues[aTimingFunctionType][0];
  1.2283 +  mFunc.mY1 = timingFunctionValues[aTimingFunctionType][1];
  1.2284 +  mFunc.mX2 = timingFunctionValues[aTimingFunctionType][2];
  1.2285 +  mFunc.mY2 = timingFunctionValues[aTimingFunctionType][3];
  1.2286 +}
  1.2287 +
  1.2288 +nsTransition::nsTransition(const nsTransition& aCopy)
  1.2289 +  : mTimingFunction(aCopy.mTimingFunction)
  1.2290 +  , mDuration(aCopy.mDuration)
  1.2291 +  , mDelay(aCopy.mDelay)
  1.2292 +  , mProperty(aCopy.mProperty)
  1.2293 +  , mUnknownProperty(aCopy.mUnknownProperty)
  1.2294 +{
  1.2295 +}
  1.2296 +
  1.2297 +void nsTransition::SetInitialValues()
  1.2298 +{
  1.2299 +  mTimingFunction = nsTimingFunction(NS_STYLE_TRANSITION_TIMING_FUNCTION_EASE);
  1.2300 +  mDuration = 0.0;
  1.2301 +  mDelay = 0.0;
  1.2302 +  mProperty = eCSSPropertyExtra_all_properties;
  1.2303 +}
  1.2304 +
  1.2305 +void nsTransition::SetUnknownProperty(const nsAString& aUnknownProperty)
  1.2306 +{
  1.2307 +  NS_ASSERTION(nsCSSProps::LookupProperty(aUnknownProperty,
  1.2308 +                                          nsCSSProps::eEnabledForAllContent) ==
  1.2309 +                 eCSSProperty_UNKNOWN,
  1.2310 +               "should be unknown property");
  1.2311 +  mProperty = eCSSProperty_UNKNOWN;
  1.2312 +  mUnknownProperty = do_GetAtom(aUnknownProperty);
  1.2313 +}
  1.2314 +
  1.2315 +nsAnimation::nsAnimation(const nsAnimation& aCopy)
  1.2316 +  : mTimingFunction(aCopy.mTimingFunction)
  1.2317 +  , mDuration(aCopy.mDuration)
  1.2318 +  , mDelay(aCopy.mDelay)
  1.2319 +  , mName(aCopy.mName)
  1.2320 +  , mDirection(aCopy.mDirection)
  1.2321 +  , mFillMode(aCopy.mFillMode)
  1.2322 +  , mPlayState(aCopy.mPlayState)
  1.2323 +  , mIterationCount(aCopy.mIterationCount)
  1.2324 +{
  1.2325 +}
  1.2326 +
  1.2327 +void
  1.2328 +nsAnimation::SetInitialValues()
  1.2329 +{
  1.2330 +  mTimingFunction = nsTimingFunction(NS_STYLE_TRANSITION_TIMING_FUNCTION_EASE);
  1.2331 +  mDuration = 0.0;
  1.2332 +  mDelay = 0.0;
  1.2333 +  mName = EmptyString();
  1.2334 +  mDirection = NS_STYLE_ANIMATION_DIRECTION_NORMAL;
  1.2335 +  mFillMode = NS_STYLE_ANIMATION_FILL_MODE_NONE;
  1.2336 +  mPlayState = NS_STYLE_ANIMATION_PLAY_STATE_RUNNING;
  1.2337 +  mIterationCount = 1.0f;
  1.2338 +}
  1.2339 +
  1.2340 +nsStyleDisplay::nsStyleDisplay()
  1.2341 +  : mWillChangeBitField(0)
  1.2342 +{
  1.2343 +  MOZ_COUNT_CTOR(nsStyleDisplay);
  1.2344 +  mAppearance = NS_THEME_NONE;
  1.2345 +  mDisplay = NS_STYLE_DISPLAY_INLINE;
  1.2346 +  mOriginalDisplay = mDisplay;
  1.2347 +  mPosition = NS_STYLE_POSITION_STATIC;
  1.2348 +  mFloats = NS_STYLE_FLOAT_NONE;
  1.2349 +  mOriginalFloats = mFloats;
  1.2350 +  mBreakType = NS_STYLE_CLEAR_NONE;
  1.2351 +  mBreakInside = NS_STYLE_PAGE_BREAK_AUTO;
  1.2352 +  mBreakBefore = false;
  1.2353 +  mBreakAfter = false;
  1.2354 +  mOverflowX = NS_STYLE_OVERFLOW_VISIBLE;
  1.2355 +  mOverflowY = NS_STYLE_OVERFLOW_VISIBLE;
  1.2356 +  mOverflowClipBox = NS_STYLE_OVERFLOW_CLIP_BOX_PADDING_BOX;
  1.2357 +  mResize = NS_STYLE_RESIZE_NONE;
  1.2358 +  mClipFlags = NS_STYLE_CLIP_AUTO;
  1.2359 +  mClip.SetRect(0,0,0,0);
  1.2360 +  mOpacity = 1.0f;
  1.2361 +  mSpecifiedTransform = nullptr;
  1.2362 +  mTransformOrigin[0].SetPercentValue(0.5f); // Transform is centered on origin
  1.2363 +  mTransformOrigin[1].SetPercentValue(0.5f);
  1.2364 +  mTransformOrigin[2].SetCoordValue(0);
  1.2365 +  mPerspectiveOrigin[0].SetPercentValue(0.5f);
  1.2366 +  mPerspectiveOrigin[1].SetPercentValue(0.5f);
  1.2367 +  mChildPerspective.SetNoneValue();
  1.2368 +  mBackfaceVisibility = NS_STYLE_BACKFACE_VISIBILITY_VISIBLE;
  1.2369 +  mTransformStyle = NS_STYLE_TRANSFORM_STYLE_FLAT;
  1.2370 +  mOrient = NS_STYLE_ORIENT_AUTO;
  1.2371 +  mMixBlendMode = NS_STYLE_BLEND_NORMAL;
  1.2372 +  mTouchAction = NS_STYLE_TOUCH_ACTION_AUTO;
  1.2373 +
  1.2374 +  mTransitions.AppendElement();
  1.2375 +  NS_ABORT_IF_FALSE(mTransitions.Length() == 1,
  1.2376 +                    "appending within auto buffer should never fail");
  1.2377 +  mTransitions[0].SetInitialValues();
  1.2378 +  mTransitionTimingFunctionCount = 1;
  1.2379 +  mTransitionDurationCount = 1;
  1.2380 +  mTransitionDelayCount = 1;
  1.2381 +  mTransitionPropertyCount = 1;
  1.2382 +
  1.2383 +  mAnimations.AppendElement();
  1.2384 +  NS_ABORT_IF_FALSE(mAnimations.Length() == 1,
  1.2385 +                    "appending within auto buffer should never fail");
  1.2386 +  mAnimations[0].SetInitialValues();
  1.2387 +  mAnimationTimingFunctionCount = 1;
  1.2388 +  mAnimationDurationCount = 1;
  1.2389 +  mAnimationDelayCount = 1;
  1.2390 +  mAnimationNameCount = 1;
  1.2391 +  mAnimationDirectionCount = 1;
  1.2392 +  mAnimationFillModeCount = 1;
  1.2393 +  mAnimationPlayStateCount = 1;
  1.2394 +  mAnimationIterationCountCount = 1;
  1.2395 +}
  1.2396 +
  1.2397 +nsStyleDisplay::nsStyleDisplay(const nsStyleDisplay& aSource)
  1.2398 +  : mBinding(aSource.mBinding)
  1.2399 +  , mClip(aSource.mClip)
  1.2400 +  , mOpacity(aSource.mOpacity)
  1.2401 +  , mDisplay(aSource.mDisplay)
  1.2402 +  , mOriginalDisplay(aSource.mOriginalDisplay)
  1.2403 +  , mAppearance(aSource.mAppearance)
  1.2404 +  , mPosition(aSource.mPosition)
  1.2405 +  , mFloats(aSource.mFloats)
  1.2406 +  , mOriginalFloats(aSource.mOriginalFloats)
  1.2407 +  , mBreakType(aSource.mBreakType)
  1.2408 +  , mBreakInside(aSource.mBreakInside)
  1.2409 +  , mBreakBefore(aSource.mBreakBefore)
  1.2410 +  , mBreakAfter(aSource.mBreakAfter)
  1.2411 +  , mOverflowX(aSource.mOverflowX)
  1.2412 +  , mOverflowY(aSource.mOverflowY)
  1.2413 +  , mOverflowClipBox(aSource.mOverflowClipBox)
  1.2414 +  , mResize(aSource.mResize)
  1.2415 +  , mClipFlags(aSource.mClipFlags)
  1.2416 +  , mOrient(aSource.mOrient)
  1.2417 +  , mMixBlendMode(aSource.mMixBlendMode)
  1.2418 +  , mWillChangeBitField(aSource.mWillChangeBitField)
  1.2419 +  , mWillChange(aSource.mWillChange)
  1.2420 +  , mTouchAction(aSource.mTouchAction)
  1.2421 +  , mBackfaceVisibility(aSource.mBackfaceVisibility)
  1.2422 +  , mTransformStyle(aSource.mTransformStyle)
  1.2423 +  , mSpecifiedTransform(aSource.mSpecifiedTransform)
  1.2424 +  , mChildPerspective(aSource.mChildPerspective)
  1.2425 +  , mTransitions(aSource.mTransitions)
  1.2426 +  , mTransitionTimingFunctionCount(aSource.mTransitionTimingFunctionCount)
  1.2427 +  , mTransitionDurationCount(aSource.mTransitionDurationCount)
  1.2428 +  , mTransitionDelayCount(aSource.mTransitionDelayCount)
  1.2429 +  , mTransitionPropertyCount(aSource.mTransitionPropertyCount)
  1.2430 +  , mAnimations(aSource.mAnimations)
  1.2431 +  , mAnimationTimingFunctionCount(aSource.mAnimationTimingFunctionCount)
  1.2432 +  , mAnimationDurationCount(aSource.mAnimationDurationCount)
  1.2433 +  , mAnimationDelayCount(aSource.mAnimationDelayCount)
  1.2434 +  , mAnimationNameCount(aSource.mAnimationNameCount)
  1.2435 +  , mAnimationDirectionCount(aSource.mAnimationDirectionCount)
  1.2436 +  , mAnimationFillModeCount(aSource.mAnimationFillModeCount)
  1.2437 +  , mAnimationPlayStateCount(aSource.mAnimationPlayStateCount)
  1.2438 +  , mAnimationIterationCountCount(aSource.mAnimationIterationCountCount)
  1.2439 +{
  1.2440 +  MOZ_COUNT_CTOR(nsStyleDisplay);
  1.2441 +
  1.2442 +  /* Copy over transform origin. */
  1.2443 +  mTransformOrigin[0] = aSource.mTransformOrigin[0];
  1.2444 +  mTransformOrigin[1] = aSource.mTransformOrigin[1];
  1.2445 +  mTransformOrigin[2] = aSource.mTransformOrigin[2];
  1.2446 +  mPerspectiveOrigin[0] = aSource.mPerspectiveOrigin[0];
  1.2447 +  mPerspectiveOrigin[1] = aSource.mPerspectiveOrigin[1];
  1.2448 +}
  1.2449 +
  1.2450 +nsChangeHint nsStyleDisplay::CalcDifference(const nsStyleDisplay& aOther) const
  1.2451 +{
  1.2452 +  nsChangeHint hint = nsChangeHint(0);
  1.2453 +
  1.2454 +  if (!EqualURIs(mBinding, aOther.mBinding)
  1.2455 +      || mPosition != aOther.mPosition
  1.2456 +      || mDisplay != aOther.mDisplay
  1.2457 +      || (mFloats == NS_STYLE_FLOAT_NONE) != (aOther.mFloats == NS_STYLE_FLOAT_NONE)
  1.2458 +      || mOverflowX != aOther.mOverflowX
  1.2459 +      || mOverflowY != aOther.mOverflowY
  1.2460 +      || mResize != aOther.mResize)
  1.2461 +    NS_UpdateHint(hint, nsChangeHint_ReconstructFrame);
  1.2462 +
  1.2463 +  if ((mAppearance == NS_THEME_TEXTFIELD &&
  1.2464 +       aOther.mAppearance != NS_THEME_TEXTFIELD) ||
  1.2465 +      (mAppearance != NS_THEME_TEXTFIELD &&
  1.2466 +       aOther.mAppearance == NS_THEME_TEXTFIELD)) {
  1.2467 +    // This is for <input type=number> where we allow authors to specify a
  1.2468 +    // |-moz-appearance:textfield| to get a control without a spinner. (The
  1.2469 +    // spinner is present for |-moz-appearance:number-input| but also other
  1.2470 +    // values such as 'none'.) We need to reframe since we want to use
  1.2471 +    // nsTextControlFrame instead of nsNumberControlFrame if the author
  1.2472 +    // specifies 'textfield'.
  1.2473 +    return nsChangeHint_ReconstructFrame;
  1.2474 +  }
  1.2475 +
  1.2476 +  if (mFloats != aOther.mFloats) {
  1.2477 +    // Changing which side we float on doesn't affect descendants directly
  1.2478 +    NS_UpdateHint(hint,
  1.2479 +       NS_SubtractHint(nsChangeHint_AllReflowHints,
  1.2480 +                       NS_CombineHint(nsChangeHint_ClearDescendantIntrinsics,
  1.2481 +                                      nsChangeHint_NeedDirtyReflow)));
  1.2482 +  }
  1.2483 +
  1.2484 +  // XXX the following is conservative, for now: changing float breaking shouldn't
  1.2485 +  // necessarily require a repaint, reflow should suffice.
  1.2486 +  if (mBreakType != aOther.mBreakType
  1.2487 +      || mBreakInside != aOther.mBreakInside
  1.2488 +      || mBreakBefore != aOther.mBreakBefore
  1.2489 +      || mBreakAfter != aOther.mBreakAfter
  1.2490 +      || mAppearance != aOther.mAppearance
  1.2491 +      || mOrient != aOther.mOrient
  1.2492 +      || mOverflowClipBox != aOther.mOverflowClipBox
  1.2493 +      || mClipFlags != aOther.mClipFlags || !mClip.IsEqualInterior(aOther.mClip))
  1.2494 +    NS_UpdateHint(hint, NS_CombineHint(nsChangeHint_AllReflowHints,
  1.2495 +                                       nsChangeHint_RepaintFrame));
  1.2496 +
  1.2497 +  if (mOpacity != aOther.mOpacity) {
  1.2498 +    // If we're going from the optimized >=0.99 opacity value to 1.0 or back, then
  1.2499 +    // repaint the frame because DLBI will not catch the invalidation.  Otherwise,
  1.2500 +    // just update the opacity layer.
  1.2501 +    if ((mOpacity >= 0.99f && mOpacity < 1.0f && aOther.mOpacity == 1.0f) ||
  1.2502 +        (aOther.mOpacity >= 0.99f && aOther.mOpacity < 1.0f && mOpacity == 1.0f)) {
  1.2503 +      NS_UpdateHint(hint, nsChangeHint_RepaintFrame);
  1.2504 +    } else {
  1.2505 +      NS_UpdateHint(hint, nsChangeHint_UpdateOpacityLayer);
  1.2506 +    }
  1.2507 +  }
  1.2508 +
  1.2509 +  /* If we've added or removed the transform property, we need to reconstruct the frame to add
  1.2510 +   * or remove the view object, and also to handle abs-pos and fixed-pos containers.
  1.2511 +   */
  1.2512 +  if (HasTransformStyle() != aOther.HasTransformStyle()) {
  1.2513 +    // We do not need to apply nsChangeHint_UpdateTransformLayer since
  1.2514 +    // nsChangeHint_RepaintFrame will forcibly invalidate the frame area and
  1.2515 +    // ensure layers are rebuilt (or removed).
  1.2516 +    NS_UpdateHint(hint, NS_CombineHint(nsChangeHint_AddOrRemoveTransform,
  1.2517 +                          NS_CombineHint(nsChangeHint_UpdateOverflow,
  1.2518 +                                         nsChangeHint_RepaintFrame)));
  1.2519 +  }
  1.2520 +  else if (HasTransformStyle()) {
  1.2521 +    /* Otherwise, if we've kept the property lying around and we already had a
  1.2522 +     * transform, we need to see whether or not we've changed the transform.
  1.2523 +     * If so, we need to recompute its overflow rect (which probably changed
  1.2524 +     * if the transform changed) and to redraw within the bounds of that new
  1.2525 +     * overflow rect.
  1.2526 +     */
  1.2527 +    if (!mSpecifiedTransform != !aOther.mSpecifiedTransform ||
  1.2528 +        (mSpecifiedTransform &&
  1.2529 +         *mSpecifiedTransform != *aOther.mSpecifiedTransform)) {
  1.2530 +      NS_UpdateHint(hint, NS_CombineHint(nsChangeHint_UpdatePostTransformOverflow,
  1.2531 +                                         nsChangeHint_UpdateTransformLayer));
  1.2532 +    }
  1.2533 +
  1.2534 +    const nsChangeHint kUpdateOverflowAndRepaintHint =
  1.2535 +      NS_CombineHint(nsChangeHint_UpdateOverflow, nsChangeHint_RepaintFrame);
  1.2536 +    for (uint8_t index = 0; index < 3; ++index)
  1.2537 +      if (mTransformOrigin[index] != aOther.mTransformOrigin[index]) {
  1.2538 +        NS_UpdateHint(hint, kUpdateOverflowAndRepaintHint);
  1.2539 +        break;
  1.2540 +      }
  1.2541 +    
  1.2542 +    for (uint8_t index = 0; index < 2; ++index)
  1.2543 +      if (mPerspectiveOrigin[index] != aOther.mPerspectiveOrigin[index]) {
  1.2544 +        NS_UpdateHint(hint, kUpdateOverflowAndRepaintHint);
  1.2545 +        break;
  1.2546 +      }
  1.2547 +
  1.2548 +    if (mChildPerspective != aOther.mChildPerspective ||
  1.2549 +        mTransformStyle != aOther.mTransformStyle)
  1.2550 +      NS_UpdateHint(hint, kUpdateOverflowAndRepaintHint);
  1.2551 +
  1.2552 +    if (mBackfaceVisibility != aOther.mBackfaceVisibility)
  1.2553 +      NS_UpdateHint(hint, nsChangeHint_RepaintFrame);
  1.2554 +  }
  1.2555 +
  1.2556 +  uint8_t willChangeBitsChanged =
  1.2557 +    mWillChangeBitField ^ aOther.mWillChangeBitField;
  1.2558 +  if (willChangeBitsChanged & NS_STYLE_WILL_CHANGE_STACKING_CONTEXT) {
  1.2559 +    NS_UpdateHint(hint, nsChangeHint_RepaintFrame);
  1.2560 +  }
  1.2561 +  if (willChangeBitsChanged & ~uint8_t(NS_STYLE_WILL_CHANGE_STACKING_CONTEXT)) {
  1.2562 +    // FIXME (Bug 974125): Don't reconstruct the frame
  1.2563 +    NS_UpdateHint(hint, nsChangeHint_ReconstructFrame);
  1.2564 +  }
  1.2565 +
  1.2566 +  // Note:  Our current behavior for handling changes to the
  1.2567 +  // transition-duration, transition-delay, and transition-timing-function
  1.2568 +  // properties is to do nothing.  In other words, the transition
  1.2569 +  // property that matters is what it is when the transition begins, and
  1.2570 +  // we don't stop a transition later because the transition property
  1.2571 +  // changed.
  1.2572 +  // We do handle changes to transition-property, but we don't need to
  1.2573 +  // bother with anything here, since the transition manager is notified
  1.2574 +  // of any style context change anyway.
  1.2575 +
  1.2576 +  // Note: Likewise, for animation-*, the animation manager gets
  1.2577 +  // notified about every new style context constructed, and it uses
  1.2578 +  // that opportunity to handle dynamic changes appropriately.
  1.2579 +
  1.2580 +  return hint;
  1.2581 +}
  1.2582 +
  1.2583 +// --------------------
  1.2584 +// nsStyleVisibility
  1.2585 +//
  1.2586 +
  1.2587 +nsStyleVisibility::nsStyleVisibility(nsPresContext* aPresContext)
  1.2588 +{
  1.2589 +  MOZ_COUNT_CTOR(nsStyleVisibility);
  1.2590 +  uint32_t bidiOptions = aPresContext->GetBidi();
  1.2591 +  if (GET_BIDI_OPTION_DIRECTION(bidiOptions) == IBMBIDI_TEXTDIRECTION_RTL)
  1.2592 +    mDirection = NS_STYLE_DIRECTION_RTL;
  1.2593 +  else
  1.2594 +    mDirection = NS_STYLE_DIRECTION_LTR;
  1.2595 +
  1.2596 +  mVisible = NS_STYLE_VISIBILITY_VISIBLE;
  1.2597 +  mPointerEvents = NS_STYLE_POINTER_EVENTS_AUTO;
  1.2598 +  mWritingMode = NS_STYLE_WRITING_MODE_HORIZONTAL_TB;
  1.2599 +}
  1.2600 +
  1.2601 +nsStyleVisibility::nsStyleVisibility(const nsStyleVisibility& aSource)
  1.2602 +{
  1.2603 +  MOZ_COUNT_CTOR(nsStyleVisibility);
  1.2604 +  mImageOrientation = aSource.mImageOrientation;
  1.2605 +  mDirection = aSource.mDirection;
  1.2606 +  mVisible = aSource.mVisible;
  1.2607 +  mPointerEvents = aSource.mPointerEvents;
  1.2608 +  mWritingMode = aSource.mWritingMode;
  1.2609 +} 
  1.2610 +
  1.2611 +nsChangeHint nsStyleVisibility::CalcDifference(const nsStyleVisibility& aOther) const
  1.2612 +{
  1.2613 +  nsChangeHint hint = nsChangeHint(0);
  1.2614 +
  1.2615 +  if (mDirection != aOther.mDirection || mWritingMode != aOther.mWritingMode) {
  1.2616 +    NS_UpdateHint(hint, nsChangeHint_ReconstructFrame);
  1.2617 +  } else {
  1.2618 +    if ((mImageOrientation != aOther.mImageOrientation)) {
  1.2619 +      NS_UpdateHint(hint, nsChangeHint_AllReflowHints);
  1.2620 +    }
  1.2621 +    if (mVisible != aOther.mVisible) {
  1.2622 +      if ((NS_STYLE_VISIBILITY_COLLAPSE == mVisible) ||
  1.2623 +          (NS_STYLE_VISIBILITY_COLLAPSE == aOther.mVisible)) {
  1.2624 +        NS_UpdateHint(hint, NS_STYLE_HINT_REFLOW);
  1.2625 +      } else {
  1.2626 +        NS_UpdateHint(hint, NS_STYLE_HINT_VISUAL);
  1.2627 +      }
  1.2628 +    }
  1.2629 +    if (mPointerEvents != aOther.mPointerEvents) {
  1.2630 +      // nsSVGPathGeometryFrame's mRect depends on stroke _and_ on the value
  1.2631 +      // of pointer-events. See nsSVGPathGeometryFrame::ReflowSVG's use of
  1.2632 +      // GetHitTestFlags. (Only a reflow, no visual change.)
  1.2633 +      NS_UpdateHint(hint, nsChangeHint_NeedReflow);
  1.2634 +      NS_UpdateHint(hint, nsChangeHint_NeedDirtyReflow); // XXX remove me: bug 876085
  1.2635 +    }
  1.2636 +  }
  1.2637 +  return hint;
  1.2638 +}
  1.2639 +
  1.2640 +nsStyleContentData::~nsStyleContentData()
  1.2641 +{
  1.2642 +  NS_ABORT_IF_FALSE(!mImageTracked,
  1.2643 +                    "nsStyleContentData being destroyed while still tracking image!");
  1.2644 +  if (mType == eStyleContentType_Image) {
  1.2645 +    NS_IF_RELEASE(mContent.mImage);
  1.2646 +  } else if (mType == eStyleContentType_Counter ||
  1.2647 +             mType == eStyleContentType_Counters) {
  1.2648 +    mContent.mCounters->Release();
  1.2649 +  } else if (mContent.mString) {
  1.2650 +    NS_Free(mContent.mString);
  1.2651 +  }
  1.2652 +}
  1.2653 +
  1.2654 +nsStyleContentData& nsStyleContentData::operator=(const nsStyleContentData& aOther)
  1.2655 +{
  1.2656 +  if (this == &aOther)
  1.2657 +    return *this;
  1.2658 +  this->~nsStyleContentData();
  1.2659 +  new (this) nsStyleContentData();
  1.2660 +
  1.2661 +  mType = aOther.mType;
  1.2662 +  if (mType == eStyleContentType_Image) {
  1.2663 +    mContent.mImage = aOther.mContent.mImage;
  1.2664 +    NS_IF_ADDREF(mContent.mImage);
  1.2665 +  } else if (mType == eStyleContentType_Counter ||
  1.2666 +             mType == eStyleContentType_Counters) {
  1.2667 +    mContent.mCounters = aOther.mContent.mCounters;
  1.2668 +    mContent.mCounters->AddRef();
  1.2669 +  } else if (aOther.mContent.mString) {
  1.2670 +    mContent.mString = NS_strdup(aOther.mContent.mString);
  1.2671 +  } else {
  1.2672 +    mContent.mString = nullptr;
  1.2673 +  }
  1.2674 +  return *this;
  1.2675 +}
  1.2676 +
  1.2677 +bool nsStyleContentData::operator==(const nsStyleContentData& aOther) const
  1.2678 +{
  1.2679 +  if (mType != aOther.mType)
  1.2680 +    return false;
  1.2681 +  if (mType == eStyleContentType_Image) {
  1.2682 +    if (!mContent.mImage || !aOther.mContent.mImage)
  1.2683 +      return mContent.mImage == aOther.mContent.mImage;
  1.2684 +    bool eq;
  1.2685 +    nsCOMPtr<nsIURI> thisURI, otherURI;
  1.2686 +    mContent.mImage->GetURI(getter_AddRefs(thisURI));
  1.2687 +    aOther.mContent.mImage->GetURI(getter_AddRefs(otherURI));
  1.2688 +    return thisURI == otherURI ||  // handles null==null
  1.2689 +           (thisURI && otherURI &&
  1.2690 +            NS_SUCCEEDED(thisURI->Equals(otherURI, &eq)) &&
  1.2691 +            eq);
  1.2692 +  }
  1.2693 +  if (mType == eStyleContentType_Counter ||
  1.2694 +      mType == eStyleContentType_Counters)
  1.2695 +    return *mContent.mCounters == *aOther.mContent.mCounters;
  1.2696 +  return safe_strcmp(mContent.mString, aOther.mContent.mString) == 0;
  1.2697 +}
  1.2698 +
  1.2699 +void
  1.2700 +nsStyleContentData::TrackImage(nsPresContext* aContext)
  1.2701 +{
  1.2702 +  // Sanity
  1.2703 +  NS_ABORT_IF_FALSE(!mImageTracked, "Already tracking image!");
  1.2704 +  NS_ABORT_IF_FALSE(mType == eStyleContentType_Image,
  1.2705 +                    "Trying to do image tracking on non-image!");
  1.2706 +  NS_ABORT_IF_FALSE(mContent.mImage,
  1.2707 +                    "Can't track image when there isn't one!");
  1.2708 +
  1.2709 +  // Register the image with the document
  1.2710 +  nsIDocument* doc = aContext->Document();
  1.2711 +  if (doc)
  1.2712 +    doc->AddImage(mContent.mImage);
  1.2713 +
  1.2714 +  // Mark state
  1.2715 +#ifdef DEBUG
  1.2716 +  mImageTracked = true;
  1.2717 +#endif
  1.2718 +}
  1.2719 +
  1.2720 +void
  1.2721 +nsStyleContentData::UntrackImage(nsPresContext* aContext)
  1.2722 +{
  1.2723 +  // Sanity
  1.2724 +  NS_ABORT_IF_FALSE(mImageTracked, "Image not tracked!");
  1.2725 +  NS_ABORT_IF_FALSE(mType == eStyleContentType_Image,
  1.2726 +                    "Trying to do image tracking on non-image!");
  1.2727 +  NS_ABORT_IF_FALSE(mContent.mImage,
  1.2728 +                    "Can't untrack image when there isn't one!");
  1.2729 +
  1.2730 +  // Unregister the image with the document
  1.2731 +  nsIDocument* doc = aContext->Document();
  1.2732 +  if (doc)
  1.2733 +    doc->RemoveImage(mContent.mImage, nsIDocument::REQUEST_DISCARD);
  1.2734 +
  1.2735 +  // Mark state
  1.2736 +#ifdef DEBUG
  1.2737 +  mImageTracked = false;
  1.2738 +#endif
  1.2739 +}
  1.2740 +
  1.2741 +
  1.2742 +//-----------------------
  1.2743 +// nsStyleContent
  1.2744 +//
  1.2745 +
  1.2746 +nsStyleContent::nsStyleContent(void)
  1.2747 +  : mMarkerOffset(),
  1.2748 +    mContents(nullptr),
  1.2749 +    mIncrements(nullptr),
  1.2750 +    mResets(nullptr),
  1.2751 +    mContentCount(0),
  1.2752 +    mIncrementCount(0),
  1.2753 +    mResetCount(0)
  1.2754 +{
  1.2755 +  MOZ_COUNT_CTOR(nsStyleContent);
  1.2756 +  mMarkerOffset.SetAutoValue();
  1.2757 +}
  1.2758 +
  1.2759 +nsStyleContent::~nsStyleContent(void)
  1.2760 +{
  1.2761 +  MOZ_COUNT_DTOR(nsStyleContent);
  1.2762 +  DELETE_ARRAY_IF(mContents);
  1.2763 +  DELETE_ARRAY_IF(mIncrements);
  1.2764 +  DELETE_ARRAY_IF(mResets);
  1.2765 +}
  1.2766 +
  1.2767 +void 
  1.2768 +nsStyleContent::Destroy(nsPresContext* aContext)
  1.2769 +{
  1.2770 +  // Unregister any images we might have with the document.
  1.2771 +  for (uint32_t i = 0; i < mContentCount; ++i) {
  1.2772 +    if ((mContents[i].mType == eStyleContentType_Image) &&
  1.2773 +        mContents[i].mContent.mImage) {
  1.2774 +      mContents[i].UntrackImage(aContext);
  1.2775 +    }
  1.2776 +  }
  1.2777 +
  1.2778 +  this->~nsStyleContent();
  1.2779 +  aContext->FreeToShell(sizeof(nsStyleContent), this);
  1.2780 +}
  1.2781 +
  1.2782 +nsStyleContent::nsStyleContent(const nsStyleContent& aSource)
  1.2783 +   :mMarkerOffset(),
  1.2784 +    mContents(nullptr),
  1.2785 +    mIncrements(nullptr),
  1.2786 +    mResets(nullptr),
  1.2787 +    mContentCount(0),
  1.2788 +    mIncrementCount(0),
  1.2789 +    mResetCount(0)
  1.2790 +
  1.2791 +{
  1.2792 +  MOZ_COUNT_CTOR(nsStyleContent);
  1.2793 +  mMarkerOffset = aSource.mMarkerOffset;
  1.2794 +
  1.2795 +  uint32_t index;
  1.2796 +  if (NS_SUCCEEDED(AllocateContents(aSource.ContentCount()))) {
  1.2797 +    for (index = 0; index < mContentCount; index++) {
  1.2798 +      ContentAt(index) = aSource.ContentAt(index);
  1.2799 +    }
  1.2800 +  }
  1.2801 +
  1.2802 +  if (NS_SUCCEEDED(AllocateCounterIncrements(aSource.CounterIncrementCount()))) {
  1.2803 +    for (index = 0; index < mIncrementCount; index++) {
  1.2804 +      const nsStyleCounterData *data = aSource.GetCounterIncrementAt(index);
  1.2805 +      mIncrements[index].mCounter = data->mCounter;
  1.2806 +      mIncrements[index].mValue = data->mValue;
  1.2807 +    }
  1.2808 +  }
  1.2809 +
  1.2810 +  if (NS_SUCCEEDED(AllocateCounterResets(aSource.CounterResetCount()))) {
  1.2811 +    for (index = 0; index < mResetCount; index++) {
  1.2812 +      const nsStyleCounterData *data = aSource.GetCounterResetAt(index);
  1.2813 +      mResets[index].mCounter = data->mCounter;
  1.2814 +      mResets[index].mValue = data->mValue;
  1.2815 +    }
  1.2816 +  }
  1.2817 +}
  1.2818 +
  1.2819 +nsChangeHint nsStyleContent::CalcDifference(const nsStyleContent& aOther) const
  1.2820 +{
  1.2821 +  // In ReResolveStyleContext we assume that if there's no existing
  1.2822 +  // ::before or ::after and we don't have to restyle children of the
  1.2823 +  // node then we can't end up with a ::before or ::after due to the
  1.2824 +  // restyle of the node itself.  That's not quite true, but the only
  1.2825 +  // exception to the above is when the 'content' property of the node
  1.2826 +  // changes and the pseudo-element inherits the changed value.  Since
  1.2827 +  // the code here triggers a frame change on the node in that case,
  1.2828 +  // the optimization in ReResolveStyleContext is ok.  But if we ever
  1.2829 +  // change this code to not reconstruct frames on changes to the
  1.2830 +  // 'content' property, then we will need to revisit the optimization
  1.2831 +  // in ReResolveStyleContext.
  1.2832 +
  1.2833 +  if (mContentCount != aOther.mContentCount ||
  1.2834 +      mIncrementCount != aOther.mIncrementCount || 
  1.2835 +      mResetCount != aOther.mResetCount) {
  1.2836 +    return NS_STYLE_HINT_FRAMECHANGE;
  1.2837 +  }
  1.2838 +
  1.2839 +  uint32_t ix = mContentCount;
  1.2840 +  while (0 < ix--) {
  1.2841 +    if (mContents[ix] != aOther.mContents[ix]) {
  1.2842 +      // Unfortunately we need to reframe here; a simple reflow
  1.2843 +      // will not pick up different text or different image URLs,
  1.2844 +      // since we set all that up in the CSSFrameConstructor
  1.2845 +      return NS_STYLE_HINT_FRAMECHANGE;
  1.2846 +    }
  1.2847 +  }
  1.2848 +  ix = mIncrementCount;
  1.2849 +  while (0 < ix--) {
  1.2850 +    if ((mIncrements[ix].mValue != aOther.mIncrements[ix].mValue) || 
  1.2851 +        (mIncrements[ix].mCounter != aOther.mIncrements[ix].mCounter)) {
  1.2852 +      return NS_STYLE_HINT_FRAMECHANGE;
  1.2853 +    }
  1.2854 +  }
  1.2855 +  ix = mResetCount;
  1.2856 +  while (0 < ix--) {
  1.2857 +    if ((mResets[ix].mValue != aOther.mResets[ix].mValue) || 
  1.2858 +        (mResets[ix].mCounter != aOther.mResets[ix].mCounter)) {
  1.2859 +      return NS_STYLE_HINT_FRAMECHANGE;
  1.2860 +    }
  1.2861 +  }
  1.2862 +  if (mMarkerOffset != aOther.mMarkerOffset) {
  1.2863 +    return NS_STYLE_HINT_REFLOW;
  1.2864 +  }
  1.2865 +  return NS_STYLE_HINT_NONE;
  1.2866 +}
  1.2867 +
  1.2868 +nsresult nsStyleContent::AllocateContents(uint32_t aCount)
  1.2869 +{
  1.2870 +  // We need to run the destructors of the elements of mContents, so we
  1.2871 +  // delete and reallocate even if aCount == mContentCount.  (If
  1.2872 +  // nsStyleContentData had its members private and managed their
  1.2873 +  // ownership on setting, we wouldn't need this, but that seems
  1.2874 +  // unnecessary at this point.)
  1.2875 +  DELETE_ARRAY_IF(mContents);
  1.2876 +  if (aCount) {
  1.2877 +    mContents = new nsStyleContentData[aCount];
  1.2878 +    if (! mContents) {
  1.2879 +      mContentCount = 0;
  1.2880 +      return NS_ERROR_OUT_OF_MEMORY;
  1.2881 +    }
  1.2882 +  }
  1.2883 +  mContentCount = aCount;
  1.2884 +  return NS_OK;
  1.2885 +}
  1.2886 +
  1.2887 +// ---------------------
  1.2888 +// nsStyleQuotes
  1.2889 +//
  1.2890 +
  1.2891 +nsStyleQuotes::nsStyleQuotes(void)
  1.2892 +  : mQuotesCount(0),
  1.2893 +    mQuotes(nullptr)
  1.2894 +{
  1.2895 +  MOZ_COUNT_CTOR(nsStyleQuotes);
  1.2896 +  SetInitial();
  1.2897 +}
  1.2898 +
  1.2899 +nsStyleQuotes::~nsStyleQuotes(void)
  1.2900 +{
  1.2901 +  MOZ_COUNT_DTOR(nsStyleQuotes);
  1.2902 +  DELETE_ARRAY_IF(mQuotes);
  1.2903 +}
  1.2904 +
  1.2905 +nsStyleQuotes::nsStyleQuotes(const nsStyleQuotes& aSource)
  1.2906 +  : mQuotesCount(0),
  1.2907 +    mQuotes(nullptr)
  1.2908 +{
  1.2909 +  MOZ_COUNT_CTOR(nsStyleQuotes);
  1.2910 +  CopyFrom(aSource);
  1.2911 +}
  1.2912 +
  1.2913 +void
  1.2914 +nsStyleQuotes::SetInitial()
  1.2915 +{
  1.2916 +  // The initial value for quotes is the en-US typographic convention:
  1.2917 +  // outermost are LEFT and RIGHT DOUBLE QUOTATION MARK, alternating
  1.2918 +  // with LEFT and RIGHT SINGLE QUOTATION MARK.
  1.2919 +  static const char16_t initialQuotes[8] = {
  1.2920 +    0x201C, 0, 0x201D, 0, 0x2018, 0, 0x2019, 0
  1.2921 +  };
  1.2922 +  
  1.2923 +  if (NS_SUCCEEDED(AllocateQuotes(2))) {
  1.2924 +    SetQuotesAt(0,
  1.2925 +                nsDependentString(&initialQuotes[0], 1),
  1.2926 +                nsDependentString(&initialQuotes[2], 1));
  1.2927 +    SetQuotesAt(1,
  1.2928 +                nsDependentString(&initialQuotes[4], 1),
  1.2929 +                nsDependentString(&initialQuotes[6], 1));
  1.2930 +  }
  1.2931 +}
  1.2932 +
  1.2933 +void
  1.2934 +nsStyleQuotes::CopyFrom(const nsStyleQuotes& aSource)
  1.2935 +{
  1.2936 +  if (NS_SUCCEEDED(AllocateQuotes(aSource.QuotesCount()))) {
  1.2937 +    uint32_t count = (mQuotesCount * 2);
  1.2938 +    for (uint32_t index = 0; index < count; index += 2) {
  1.2939 +      aSource.GetQuotesAt(index, mQuotes[index], mQuotes[index + 1]);
  1.2940 +    }
  1.2941 +  }
  1.2942 +}
  1.2943 +
  1.2944 +nsChangeHint nsStyleQuotes::CalcDifference(const nsStyleQuotes& aOther) const
  1.2945 +{
  1.2946 +  // If the quotes implementation is ever going to change we might not need
  1.2947 +  // a framechange here and a reflow should be sufficient.  See bug 35768.
  1.2948 +  if (mQuotesCount == aOther.mQuotesCount) {
  1.2949 +    uint32_t ix = (mQuotesCount * 2);
  1.2950 +    while (0 < ix--) {
  1.2951 +      if (mQuotes[ix] != aOther.mQuotes[ix]) {
  1.2952 +        return NS_STYLE_HINT_FRAMECHANGE;
  1.2953 +      }
  1.2954 +    }
  1.2955 +
  1.2956 +    return NS_STYLE_HINT_NONE;
  1.2957 +  }
  1.2958 +  return NS_STYLE_HINT_FRAMECHANGE;
  1.2959 +}
  1.2960 +
  1.2961 +// --------------------
  1.2962 +// nsStyleTextReset
  1.2963 +//
  1.2964 +
  1.2965 +nsStyleTextReset::nsStyleTextReset(void) 
  1.2966 +{ 
  1.2967 +  MOZ_COUNT_CTOR(nsStyleTextReset);
  1.2968 +  mVerticalAlign.SetIntValue(NS_STYLE_VERTICAL_ALIGN_BASELINE, eStyleUnit_Enumerated);
  1.2969 +  mTextDecorationLine = NS_STYLE_TEXT_DECORATION_LINE_NONE;
  1.2970 +  mTextDecorationColor = NS_RGB(0,0,0);
  1.2971 +  mTextDecorationStyle =
  1.2972 +    NS_STYLE_TEXT_DECORATION_STYLE_SOLID | BORDER_COLOR_FOREGROUND;
  1.2973 +  mUnicodeBidi = NS_STYLE_UNICODE_BIDI_NORMAL;
  1.2974 +}
  1.2975 +
  1.2976 +nsStyleTextReset::nsStyleTextReset(const nsStyleTextReset& aSource) 
  1.2977 +{ 
  1.2978 +  MOZ_COUNT_CTOR(nsStyleTextReset);
  1.2979 +  *this = aSource;
  1.2980 +}
  1.2981 +
  1.2982 +nsStyleTextReset::~nsStyleTextReset(void)
  1.2983 +{
  1.2984 +  MOZ_COUNT_DTOR(nsStyleTextReset);
  1.2985 +}
  1.2986 +
  1.2987 +nsChangeHint nsStyleTextReset::CalcDifference(const nsStyleTextReset& aOther) const
  1.2988 +{
  1.2989 +  if (mVerticalAlign == aOther.mVerticalAlign
  1.2990 +      && mUnicodeBidi == aOther.mUnicodeBidi) {
  1.2991 +    uint8_t lineStyle = GetDecorationStyle();
  1.2992 +    uint8_t otherLineStyle = aOther.GetDecorationStyle();
  1.2993 +    if (mTextDecorationLine != aOther.mTextDecorationLine ||
  1.2994 +        lineStyle != otherLineStyle) {
  1.2995 +      // Reflow for decoration line style changes only to or from double or
  1.2996 +      // wave because that may cause overflow area changes
  1.2997 +      if (lineStyle == NS_STYLE_TEXT_DECORATION_STYLE_DOUBLE ||
  1.2998 +          lineStyle == NS_STYLE_TEXT_DECORATION_STYLE_WAVY ||
  1.2999 +          otherLineStyle == NS_STYLE_TEXT_DECORATION_STYLE_DOUBLE ||
  1.3000 +          otherLineStyle == NS_STYLE_TEXT_DECORATION_STYLE_WAVY) {
  1.3001 +        return NS_STYLE_HINT_REFLOW;
  1.3002 +      }
  1.3003 +      // Repaint for other style decoration lines because they must be in
  1.3004 +      // default overflow rect
  1.3005 +      return NS_STYLE_HINT_VISUAL;
  1.3006 +    }
  1.3007 +
  1.3008 +    // Repaint for decoration color changes
  1.3009 +    nscolor decColor, otherDecColor;
  1.3010 +    bool isFG, otherIsFG;
  1.3011 +    GetDecorationColor(decColor, isFG);
  1.3012 +    aOther.GetDecorationColor(otherDecColor, otherIsFG);
  1.3013 +    if (isFG != otherIsFG || (!isFG && decColor != otherDecColor)) {
  1.3014 +      return NS_STYLE_HINT_VISUAL;
  1.3015 +    }
  1.3016 +
  1.3017 +    if (mTextOverflow != aOther.mTextOverflow) {
  1.3018 +      return NS_STYLE_HINT_VISUAL;
  1.3019 +    }
  1.3020 +    return NS_STYLE_HINT_NONE;
  1.3021 +  }
  1.3022 +  return NS_STYLE_HINT_REFLOW;
  1.3023 +}
  1.3024 +
  1.3025 +// Allowed to return one of NS_STYLE_HINT_NONE, NS_STYLE_HINT_REFLOW
  1.3026 +// or NS_STYLE_HINT_VISUAL. Currently we just return NONE or REFLOW, though.
  1.3027 +// XXXbz can this not return a more specific hint?  If that's ever
  1.3028 +// changed, nsStyleBorder::CalcDifference will need changing too.
  1.3029 +static nsChangeHint
  1.3030 +CalcShadowDifference(nsCSSShadowArray* lhs,
  1.3031 +                     nsCSSShadowArray* rhs)
  1.3032 +{
  1.3033 +  if (lhs == rhs)
  1.3034 +    return NS_STYLE_HINT_NONE;
  1.3035 +
  1.3036 +  if (!lhs || !rhs || lhs->Length() != rhs->Length())
  1.3037 +    return NS_STYLE_HINT_REFLOW;
  1.3038 +
  1.3039 +  for (uint32_t i = 0; i < lhs->Length(); ++i) {
  1.3040 +    if (*lhs->ShadowAt(i) != *rhs->ShadowAt(i))
  1.3041 +      return NS_STYLE_HINT_REFLOW;
  1.3042 +  }
  1.3043 +  return NS_STYLE_HINT_NONE;
  1.3044 +}
  1.3045 +
  1.3046 +// --------------------
  1.3047 +// nsStyleText
  1.3048 +//
  1.3049 +
  1.3050 +nsStyleText::nsStyleText(void)
  1.3051 +{ 
  1.3052 +  MOZ_COUNT_CTOR(nsStyleText);
  1.3053 +  mTextAlign = NS_STYLE_TEXT_ALIGN_DEFAULT;
  1.3054 +  mTextAlignLast = NS_STYLE_TEXT_ALIGN_AUTO;
  1.3055 +  mTextAlignTrue = false;
  1.3056 +  mTextAlignLastTrue = false;
  1.3057 +  mTextTransform = NS_STYLE_TEXT_TRANSFORM_NONE;
  1.3058 +  mWhiteSpace = NS_STYLE_WHITESPACE_NORMAL;
  1.3059 +  mWordBreak = NS_STYLE_WORDBREAK_NORMAL;
  1.3060 +  mWordWrap = NS_STYLE_WORDWRAP_NORMAL;
  1.3061 +  mHyphens = NS_STYLE_HYPHENS_MANUAL;
  1.3062 +  mTextSizeAdjust = NS_STYLE_TEXT_SIZE_ADJUST_AUTO;
  1.3063 +  mTextOrientation = NS_STYLE_TEXT_ORIENTATION_AUTO;
  1.3064 +  mTextCombineUpright = NS_STYLE_TEXT_COMBINE_UPRIGHT_NONE;
  1.3065 +  mControlCharacterVisibility = NS_STYLE_CONTROL_CHARACTER_VISIBILITY_HIDDEN;
  1.3066 +
  1.3067 +  mLetterSpacing.SetNormalValue();
  1.3068 +  mLineHeight.SetNormalValue();
  1.3069 +  mTextIndent.SetCoordValue(0);
  1.3070 +  mWordSpacing = 0;
  1.3071 +
  1.3072 +  mTextShadow = nullptr;
  1.3073 +  mTabSize = NS_STYLE_TABSIZE_INITIAL;
  1.3074 +}
  1.3075 +
  1.3076 +nsStyleText::nsStyleText(const nsStyleText& aSource)
  1.3077 +  : mTextAlign(aSource.mTextAlign),
  1.3078 +    mTextAlignLast(aSource.mTextAlignLast),
  1.3079 +    mTextAlignTrue(false),
  1.3080 +    mTextAlignLastTrue(false),
  1.3081 +    mTextTransform(aSource.mTextTransform),
  1.3082 +    mWhiteSpace(aSource.mWhiteSpace),
  1.3083 +    mWordBreak(aSource.mWordBreak),
  1.3084 +    mWordWrap(aSource.mWordWrap),
  1.3085 +    mHyphens(aSource.mHyphens),
  1.3086 +    mTextSizeAdjust(aSource.mTextSizeAdjust),
  1.3087 +    mTextOrientation(aSource.mTextOrientation),
  1.3088 +    mTextCombineUpright(aSource.mTextCombineUpright),
  1.3089 +    mControlCharacterVisibility(aSource.mControlCharacterVisibility),
  1.3090 +    mTabSize(aSource.mTabSize),
  1.3091 +    mWordSpacing(aSource.mWordSpacing),
  1.3092 +    mLetterSpacing(aSource.mLetterSpacing),
  1.3093 +    mLineHeight(aSource.mLineHeight),
  1.3094 +    mTextIndent(aSource.mTextIndent),
  1.3095 +    mTextShadow(aSource.mTextShadow)
  1.3096 +{
  1.3097 +  MOZ_COUNT_CTOR(nsStyleText);
  1.3098 +}
  1.3099 +
  1.3100 +nsStyleText::~nsStyleText(void)
  1.3101 +{
  1.3102 +  MOZ_COUNT_DTOR(nsStyleText);
  1.3103 +}
  1.3104 +
  1.3105 +nsChangeHint nsStyleText::CalcDifference(const nsStyleText& aOther) const
  1.3106 +{
  1.3107 +  if (WhiteSpaceOrNewlineIsSignificant() !=
  1.3108 +      aOther.WhiteSpaceOrNewlineIsSignificant()) {
  1.3109 +    // This may require construction of suppressed text frames
  1.3110 +    return NS_STYLE_HINT_FRAMECHANGE;
  1.3111 +  }
  1.3112 +
  1.3113 +  if (mTextCombineUpright != aOther.mTextCombineUpright ||
  1.3114 +      mControlCharacterVisibility != aOther.mControlCharacterVisibility) {
  1.3115 +    return nsChangeHint_ReconstructFrame;
  1.3116 +  }
  1.3117 +
  1.3118 +  if ((mTextAlign != aOther.mTextAlign) ||
  1.3119 +      (mTextAlignLast != aOther.mTextAlignLast) ||
  1.3120 +      (mTextAlignTrue != aOther.mTextAlignTrue) ||
  1.3121 +      (mTextAlignLastTrue != aOther.mTextAlignLastTrue) ||
  1.3122 +      (mTextTransform != aOther.mTextTransform) ||
  1.3123 +      (mWhiteSpace != aOther.mWhiteSpace) ||
  1.3124 +      (mWordBreak != aOther.mWordBreak) ||
  1.3125 +      (mWordWrap != aOther.mWordWrap) ||
  1.3126 +      (mHyphens != aOther.mHyphens) ||
  1.3127 +      (mTextSizeAdjust != aOther.mTextSizeAdjust) ||
  1.3128 +      (mTextOrientation != aOther.mTextOrientation) ||
  1.3129 +      (mLetterSpacing != aOther.mLetterSpacing) ||
  1.3130 +      (mLineHeight != aOther.mLineHeight) ||
  1.3131 +      (mTextIndent != aOther.mTextIndent) ||
  1.3132 +      (mWordSpacing != aOther.mWordSpacing) ||
  1.3133 +      (mTabSize != aOther.mTabSize))
  1.3134 +    return NS_STYLE_HINT_REFLOW;
  1.3135 +
  1.3136 +  return CalcShadowDifference(mTextShadow, aOther.mTextShadow);
  1.3137 +}
  1.3138 +
  1.3139 +//-----------------------
  1.3140 +// nsStyleUserInterface
  1.3141 +//
  1.3142 +
  1.3143 +nsCursorImage::nsCursorImage()
  1.3144 +  : mHaveHotspot(false)
  1.3145 +  , mHotspotX(0.0f)
  1.3146 +  , mHotspotY(0.0f)
  1.3147 +{
  1.3148 +}
  1.3149 +
  1.3150 +nsCursorImage::nsCursorImage(const nsCursorImage& aOther)
  1.3151 +  : mHaveHotspot(aOther.mHaveHotspot)
  1.3152 +  , mHotspotX(aOther.mHotspotX)
  1.3153 +  , mHotspotY(aOther.mHotspotY)
  1.3154 +{
  1.3155 +  SetImage(aOther.GetImage());
  1.3156 +}
  1.3157 +
  1.3158 +nsCursorImage::~nsCursorImage()
  1.3159 +{
  1.3160 +  SetImage(nullptr);
  1.3161 +}
  1.3162 +
  1.3163 +nsCursorImage&
  1.3164 +nsCursorImage::operator=(const nsCursorImage& aOther)
  1.3165 +{
  1.3166 +  if (this != &aOther) {
  1.3167 +    mHaveHotspot = aOther.mHaveHotspot;
  1.3168 +    mHotspotX = aOther.mHotspotX;
  1.3169 +    mHotspotY = aOther.mHotspotY;
  1.3170 +    SetImage(aOther.GetImage());
  1.3171 +  }
  1.3172 +
  1.3173 +  return *this;
  1.3174 +}
  1.3175 +
  1.3176 +nsStyleUserInterface::nsStyleUserInterface(void) 
  1.3177 +{ 
  1.3178 +  MOZ_COUNT_CTOR(nsStyleUserInterface);
  1.3179 +  mUserInput = NS_STYLE_USER_INPUT_AUTO;
  1.3180 +  mUserModify = NS_STYLE_USER_MODIFY_READ_ONLY;
  1.3181 +  mUserFocus = NS_STYLE_USER_FOCUS_NONE;
  1.3182 +
  1.3183 +  mCursor = NS_STYLE_CURSOR_AUTO; // fix for bugzilla bug 51113
  1.3184 +
  1.3185 +  mCursorArrayLength = 0;
  1.3186 +  mCursorArray = nullptr;
  1.3187 +}
  1.3188 +
  1.3189 +nsStyleUserInterface::nsStyleUserInterface(const nsStyleUserInterface& aSource) :
  1.3190 +  mUserInput(aSource.mUserInput),
  1.3191 +  mUserModify(aSource.mUserModify),
  1.3192 +  mUserFocus(aSource.mUserFocus),
  1.3193 +  mCursor(aSource.mCursor)
  1.3194 +{ 
  1.3195 +  MOZ_COUNT_CTOR(nsStyleUserInterface);
  1.3196 +  CopyCursorArrayFrom(aSource);
  1.3197 +}
  1.3198 +
  1.3199 +nsStyleUserInterface::~nsStyleUserInterface(void) 
  1.3200 +{ 
  1.3201 +  MOZ_COUNT_DTOR(nsStyleUserInterface);
  1.3202 +  delete [] mCursorArray;
  1.3203 +}
  1.3204 +
  1.3205 +nsChangeHint nsStyleUserInterface::CalcDifference(const nsStyleUserInterface& aOther) const
  1.3206 +{
  1.3207 +  nsChangeHint hint = nsChangeHint(0);
  1.3208 +  if (mCursor != aOther.mCursor)
  1.3209 +    NS_UpdateHint(hint, nsChangeHint_UpdateCursor);
  1.3210 +
  1.3211 +  // We could do better. But it wouldn't be worth it, URL-specified cursors are
  1.3212 +  // rare.
  1.3213 +  if (mCursorArrayLength > 0 || aOther.mCursorArrayLength > 0)
  1.3214 +    NS_UpdateHint(hint, nsChangeHint_UpdateCursor);
  1.3215 +
  1.3216 +  if (mUserModify != aOther.mUserModify)
  1.3217 +    NS_UpdateHint(hint, NS_STYLE_HINT_VISUAL);
  1.3218 +  
  1.3219 +  if ((mUserInput != aOther.mUserInput) &&
  1.3220 +      ((NS_STYLE_USER_INPUT_NONE == mUserInput) || 
  1.3221 +       (NS_STYLE_USER_INPUT_NONE == aOther.mUserInput))) {
  1.3222 +    NS_UpdateHint(hint, NS_STYLE_HINT_FRAMECHANGE);
  1.3223 +  }
  1.3224 +
  1.3225 +  // ignore mUserFocus
  1.3226 +
  1.3227 +  return hint;
  1.3228 +}
  1.3229 +
  1.3230 +void
  1.3231 +nsStyleUserInterface::CopyCursorArrayFrom(const nsStyleUserInterface& aSource)
  1.3232 +{
  1.3233 +  mCursorArray = nullptr;
  1.3234 +  mCursorArrayLength = 0;
  1.3235 +  if (aSource.mCursorArrayLength) {
  1.3236 +    mCursorArray = new nsCursorImage[aSource.mCursorArrayLength];
  1.3237 +    if (mCursorArray) {
  1.3238 +      mCursorArrayLength = aSource.mCursorArrayLength;
  1.3239 +      for (uint32_t i = 0; i < mCursorArrayLength; ++i)
  1.3240 +        mCursorArray[i] = aSource.mCursorArray[i];
  1.3241 +    }
  1.3242 +  }
  1.3243 +}
  1.3244 +
  1.3245 +//-----------------------
  1.3246 +// nsStyleUIReset
  1.3247 +//
  1.3248 +
  1.3249 +nsStyleUIReset::nsStyleUIReset(void) 
  1.3250 +{ 
  1.3251 +  MOZ_COUNT_CTOR(nsStyleUIReset);
  1.3252 +  mUserSelect = NS_STYLE_USER_SELECT_AUTO;
  1.3253 +  mForceBrokenImageIcon = 0;
  1.3254 +  mIMEMode = NS_STYLE_IME_MODE_AUTO;
  1.3255 +  mWindowShadow = NS_STYLE_WINDOW_SHADOW_DEFAULT;
  1.3256 +}
  1.3257 +
  1.3258 +nsStyleUIReset::nsStyleUIReset(const nsStyleUIReset& aSource) 
  1.3259 +{
  1.3260 +  MOZ_COUNT_CTOR(nsStyleUIReset);
  1.3261 +  mUserSelect = aSource.mUserSelect;
  1.3262 +  mForceBrokenImageIcon = aSource.mForceBrokenImageIcon;
  1.3263 +  mIMEMode = aSource.mIMEMode;
  1.3264 +  mWindowShadow = aSource.mWindowShadow;
  1.3265 +}
  1.3266 +
  1.3267 +nsStyleUIReset::~nsStyleUIReset(void) 
  1.3268 +{ 
  1.3269 +  MOZ_COUNT_DTOR(nsStyleUIReset);
  1.3270 +}
  1.3271 +
  1.3272 +nsChangeHint nsStyleUIReset::CalcDifference(const nsStyleUIReset& aOther) const
  1.3273 +{
  1.3274 +  // ignore mIMEMode
  1.3275 +  if (mForceBrokenImageIcon != aOther.mForceBrokenImageIcon)
  1.3276 +    return NS_STYLE_HINT_FRAMECHANGE;
  1.3277 +  if (mWindowShadow != aOther.mWindowShadow) {
  1.3278 +    // We really need just an nsChangeHint_SyncFrameView, except
  1.3279 +    // on an ancestor of the frame, so we get that by doing a
  1.3280 +    // reflow.
  1.3281 +    return NS_STYLE_HINT_REFLOW;
  1.3282 +  }
  1.3283 +  if (mUserSelect != aOther.mUserSelect)
  1.3284 +    return NS_STYLE_HINT_VISUAL;
  1.3285 +  return NS_STYLE_HINT_NONE;
  1.3286 +}
  1.3287 +
  1.3288 +//-----------------------
  1.3289 +// nsStyleVariables
  1.3290 +//
  1.3291 +
  1.3292 +nsStyleVariables::nsStyleVariables()
  1.3293 +{
  1.3294 +  MOZ_COUNT_CTOR(nsStyleVariables);
  1.3295 +}
  1.3296 +
  1.3297 +nsStyleVariables::nsStyleVariables(const nsStyleVariables& aSource)
  1.3298 +{
  1.3299 +  MOZ_COUNT_CTOR(nsStyleVariables);
  1.3300 +}
  1.3301 +
  1.3302 +nsStyleVariables::~nsStyleVariables(void)
  1.3303 +{
  1.3304 +  MOZ_COUNT_DTOR(nsStyleVariables);
  1.3305 +}
  1.3306 +
  1.3307 +nsChangeHint
  1.3308 +nsStyleVariables::CalcDifference(const nsStyleVariables& aOther) const
  1.3309 +{
  1.3310 +  return nsChangeHint(0);
  1.3311 +}

mercurial