layout/base/nsLayoutUtils.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/base/nsLayoutUtils.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,2301 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsLayoutUtils_h__
    1.10 +#define nsLayoutUtils_h__
    1.11 +
    1.12 +#include "mozilla/MemoryReporting.h"
    1.13 +#include "nsChangeHint.h"
    1.14 +#include "nsAutoPtr.h"
    1.15 +#include "nsFrameList.h"
    1.16 +#include "mozilla/layout/FrameChildList.h"
    1.17 +#include "nsThreadUtils.h"
    1.18 +#include "nsIPrincipal.h"
    1.19 +#include "GraphicsFilter.h"
    1.20 +#include "nsCSSPseudoElements.h"
    1.21 +#include "FrameMetrics.h"
    1.22 +#include "gfx3DMatrix.h"
    1.23 +#include "nsIWidget.h"
    1.24 +#include "nsCSSProperty.h"
    1.25 +#include "nsStyleCoord.h"
    1.26 +#include "nsStyleConsts.h"
    1.27 +#include "nsGkAtoms.h"
    1.28 +#include "nsRuleNode.h"
    1.29 +#include "imgIContainer.h"
    1.30 +#include "mozilla/gfx/2D.h"
    1.31 +#include "Units.h"
    1.32 +
    1.33 +#include <limits>
    1.34 +#include <algorithm>
    1.35 +
    1.36 +class nsIFormControlFrame;
    1.37 +class nsPresContext;
    1.38 +class nsIContent;
    1.39 +class nsIAtom;
    1.40 +class nsIScrollableFrame;
    1.41 +class nsIDOMEvent;
    1.42 +class nsRegion;
    1.43 +class nsDisplayListBuilder;
    1.44 +class nsDisplayItem;
    1.45 +class nsFontMetrics;
    1.46 +class nsFontFaceList;
    1.47 +class nsIImageLoadingContent;
    1.48 +class nsStyleContext;
    1.49 +class nsBlockFrame;
    1.50 +class gfxASurface;
    1.51 +class gfxDrawable;
    1.52 +class nsView;
    1.53 +class nsIFrame;
    1.54 +class nsStyleCoord;
    1.55 +class nsStyleCorners;
    1.56 +class gfxContext;
    1.57 +class nsPIDOMWindow;
    1.58 +class imgIRequest;
    1.59 +class nsIDocument;
    1.60 +class gfxPoint;
    1.61 +struct nsStyleFont;
    1.62 +struct nsStyleImageOrientation;
    1.63 +struct nsOverflowAreas;
    1.64 +
    1.65 +namespace mozilla {
    1.66 +class SVGImageContext;
    1.67 +struct IntrinsicSize;
    1.68 +struct ContainerLayerParameters;
    1.69 +namespace dom {
    1.70 +class DOMRectList;
    1.71 +class Element;
    1.72 +class HTMLImageElement;
    1.73 +class HTMLCanvasElement;
    1.74 +class HTMLVideoElement;
    1.75 +} // namespace dom
    1.76 +namespace layers {
    1.77 +class Layer;
    1.78 +}
    1.79 +}
    1.80 +
    1.81 +namespace mozilla {
    1.82 +
    1.83 +struct DisplayPortPropertyData {
    1.84 +  DisplayPortPropertyData(const nsRect& aRect, uint32_t aPriority)
    1.85 +    : mRect(aRect)
    1.86 +    , mPriority(aPriority)
    1.87 +  {}
    1.88 +  nsRect mRect;
    1.89 +  uint32_t mPriority;
    1.90 +};
    1.91 +
    1.92 +struct DisplayPortMarginsPropertyData {
    1.93 +  DisplayPortMarginsPropertyData(const LayerMargin& aMargins,
    1.94 +                                 uint32_t aAlignmentX, uint32_t aAlignmentY,
    1.95 +                                 uint32_t aPriority)
    1.96 +    : mMargins(aMargins)
    1.97 +    , mAlignmentX(aAlignmentX)
    1.98 +    , mAlignmentY(aAlignmentY)
    1.99 +    , mPriority(aPriority)
   1.100 +  {}
   1.101 +  LayerMargin mMargins;
   1.102 +  uint32_t mAlignmentX;
   1.103 +  uint32_t mAlignmentY;
   1.104 +  uint32_t mPriority;
   1.105 +};
   1.106 +
   1.107 +template <class AnimationsOrTransitions>
   1.108 +extern AnimationsOrTransitions* HasAnimationOrTransition(nsIContent* aContent,
   1.109 +                                                         nsIAtom* aAnimationProperty,
   1.110 +                                                         nsCSSProperty aProperty);
   1.111 +
   1.112 +} // namespace mozilla
   1.113 +
   1.114 +/**
   1.115 + * nsLayoutUtils is a namespace class used for various helper
   1.116 + * functions that are useful in multiple places in layout.  The goal
   1.117 + * is not to define multiple copies of the same static helper.
   1.118 + */
   1.119 +class nsLayoutUtils
   1.120 +{
   1.121 +  typedef ::GraphicsFilter GraphicsFilter;
   1.122 +  typedef mozilla::dom::DOMRectList DOMRectList;
   1.123 +  typedef mozilla::layers::Layer Layer;
   1.124 +  typedef mozilla::ContainerLayerParameters ContainerLayerParameters;
   1.125 +  typedef mozilla::gfx::SourceSurface SourceSurface;
   1.126 +  typedef mozilla::gfx::DrawTarget DrawTarget;
   1.127 +  typedef mozilla::gfx::Rect Rect;
   1.128 +
   1.129 +public:
   1.130 +  typedef mozilla::layers::FrameMetrics FrameMetrics;
   1.131 +  typedef FrameMetrics::ViewID ViewID;
   1.132 +  typedef mozilla::CSSPoint CSSPoint;
   1.133 +  typedef mozilla::CSSSize CSSSize;
   1.134 +  typedef mozilla::LayerMargin LayerMargin;
   1.135 +
   1.136 +  /**
   1.137 +   * Finds previously assigned ViewID for the given content element, if any.
   1.138 +   * Returns whether a ViewID was previously assigned.
   1.139 +   */
   1.140 +  static bool FindIDFor(const nsIContent* aContent, ViewID* aOutViewId);
   1.141 +
   1.142 +  /**
   1.143 +   * Finds previously assigned or generates a unique ViewID for the given
   1.144 +   * content element.
   1.145 +   */
   1.146 +  static ViewID FindOrCreateIDFor(nsIContent* aContent);
   1.147 +
   1.148 +  /**
   1.149 +   * Find content for given ID.
   1.150 +   */
   1.151 +  static nsIContent* FindContentFor(ViewID aId);
   1.152 +
   1.153 +  /**
   1.154 +   * Find the scrollable frame for a given ID.
   1.155 +   */
   1.156 +  static nsIScrollableFrame* FindScrollableFrameFor(ViewID aId);
   1.157 +
   1.158 +  /**
   1.159 +   * Get display port for the given element.
   1.160 +   */
   1.161 +  static bool GetDisplayPort(nsIContent* aContent, nsRect *aResult = nullptr);
   1.162 +
   1.163 +  MOZ_BEGIN_NESTED_ENUM_CLASS(RepaintMode, uint8_t)
   1.164 +    Repaint,
   1.165 +    DoNotRepaint
   1.166 +  MOZ_END_NESTED_ENUM_CLASS(RepaintMode)
   1.167 +
   1.168 +  /**
   1.169 +   * Set the display port margins for a content element to be used with a
   1.170 +   * display port base (see SetDisplayPortBase()).
   1.171 +   * See also nsIDOMWindowUtils.setDisplayPortMargins.
   1.172 +   * @param aContent the content element for which to set the margins
   1.173 +   * @param aPresShell the pres shell for the document containing the element
   1.174 +   * @param aMargins the margins to set
   1.175 +   * @param aAlignmentX, alignmentY the amount of pixels to which to align the
   1.176 +   *                                displayport built by combining the base
   1.177 +   *                                rect with the margins, in either direction
   1.178 +   * @param aPriority a priority value to determine which margins take effect
   1.179 +   *                  when multiple callers specify margins
   1.180 +   * @param aRepaintMode whether to schedule a paint after setting the margins
   1.181 +   */
   1.182 +  static void SetDisplayPortMargins(nsIContent* aContent,
   1.183 +                                    nsIPresShell* aPresShell,
   1.184 +                                    const LayerMargin& aMargins,
   1.185 +                                    uint32_t aAlignmentX,
   1.186 +                                    uint32_t aAlignmentY,
   1.187 +                                    uint32_t aPriority = 0,
   1.188 +                                    RepaintMode aRepaintMode = RepaintMode::Repaint);
   1.189 +
   1.190 +  /**
   1.191 +   * Set the display port base rect for given element to be used with display
   1.192 +   * port margins.
   1.193 +   * SetDisplayPortBaseIfNotSet is like SetDisplayPortBase except it only sets
   1.194 +   * the display port base to aBase if no display port base is currently set.
   1.195 +   */
   1.196 +  static void SetDisplayPortBase(nsIContent* aContent, const nsRect& aBase);
   1.197 +  static void SetDisplayPortBaseIfNotSet(nsIContent* aContent, const nsRect& aBase);
   1.198 +
   1.199 +  /**
   1.200 +   * Get the critical display port for the given element.
   1.201 +   */
   1.202 +  static bool GetCriticalDisplayPort(nsIContent* aContent, nsRect* aResult = nullptr);
   1.203 +
   1.204 +  /**
   1.205 +   * Use heuristics to figure out the child list that
   1.206 +   * aChildFrame is currently in.
   1.207 +   */
   1.208 +  static mozilla::layout::FrameChildListID GetChildListNameFor(nsIFrame* aChildFrame);
   1.209 +
   1.210 +  /**
   1.211 +   * GetBeforeFrame returns the outermost :before frame of the given frame, if
   1.212 +   * one exists.  This is typically O(1).  The frame passed in must be
   1.213 +   * the first-in-flow.
   1.214 +   *
   1.215 +   * @param aFrame the frame whose :before is wanted
   1.216 +   * @return the :before frame or nullptr if there isn't one
   1.217 +   */
   1.218 +  static nsIFrame* GetBeforeFrame(nsIFrame* aFrame);
   1.219 +
   1.220 +  /**
   1.221 +   * GetAfterFrame returns the outermost :after frame of the given frame, if one
   1.222 +   * exists.  This will walk the in-flow chain to the last-in-flow if
   1.223 +   * needed.  This function is typically O(N) in the number of child
   1.224 +   * frames, following in-flows, etc.
   1.225 +   *
   1.226 +   * @param aFrame the frame whose :after is wanted
   1.227 +   * @return the :after frame or nullptr if there isn't one
   1.228 +   */
   1.229 +  static nsIFrame* GetAfterFrame(nsIFrame* aFrame);
   1.230 +
   1.231 +  /**
   1.232 +   * Given a frame, search up the frame tree until we find an
   1.233 +   * ancestor that (or the frame itself) is of type aFrameType, if any.
   1.234 +   *
   1.235 +   * @param aFrame the frame to start at
   1.236 +   * @param aFrameType the frame type to look for
   1.237 +   * @return a frame of the given type or nullptr if no
   1.238 +   *         such ancestor exists
   1.239 +   */
   1.240 +  static nsIFrame* GetClosestFrameOfType(nsIFrame* aFrame, nsIAtom* aFrameType);
   1.241 +
   1.242 +  /**
   1.243 +   * Given a frame, search up the frame tree until we find an
   1.244 +   * ancestor that (or the frame itself) is a "Page" frame, if any.
   1.245 +   *
   1.246 +   * @param aFrame the frame to start at
   1.247 +   * @return a frame of type nsGkAtoms::pageFrame or nullptr if no
   1.248 +   *         such ancestor exists
   1.249 +   */
   1.250 +  static nsIFrame* GetPageFrame(nsIFrame* aFrame)
   1.251 +  {
   1.252 +    return GetClosestFrameOfType(aFrame, nsGkAtoms::pageFrame);
   1.253 +  }
   1.254 +
   1.255 +  /**
   1.256 +   * Given a frame which is the primary frame for an element,
   1.257 +   * return the frame that has the non-psuedoelement style context for
   1.258 +   * the content.
   1.259 +   * This is aPrimaryFrame itself except for tableOuter frames.
   1.260 +   */
   1.261 +  static nsIFrame* GetStyleFrame(nsIFrame* aPrimaryFrame);
   1.262 +
   1.263 +  /**
   1.264 +   * Given a content node,
   1.265 +   * return the frame that has the non-psuedoelement style context for
   1.266 +   * the content.  May return null.
   1.267 +   * This is aContent->GetPrimaryFrame() except for tableOuter frames.
   1.268 +   */
   1.269 +  static nsIFrame* GetStyleFrame(const nsIContent* aContent);
   1.270 +
   1.271 +  /**
   1.272 +   * IsGeneratedContentFor returns true if aFrame is the outermost
   1.273 +   * frame for generated content of type aPseudoElement for aContent.
   1.274 +   * aFrame *might not* have the aPseudoElement pseudo-style! For example
   1.275 +   * it might be a table outer frame and the inner table frame might
   1.276 +   * have the pseudo-style.
   1.277 +   *
   1.278 +   * @param aContent the content node we're looking at.  If this is
   1.279 +   *        null, then we just assume that aFrame has the right content
   1.280 +   *        pointer.
   1.281 +   * @param aFrame the frame we're looking at
   1.282 +   * @param aPseudoElement the pseudo type we're interested in
   1.283 +   * @return whether aFrame is the generated aPseudoElement frame for aContent
   1.284 +   */
   1.285 +  static bool IsGeneratedContentFor(nsIContent* aContent, nsIFrame* aFrame,
   1.286 +                                      nsIAtom* aPseudoElement);
   1.287 +
   1.288 +#ifdef DEBUG
   1.289 +  // TODO: remove, see bug 598468.
   1.290 +  static bool gPreventAssertInCompareTreePosition;
   1.291 +#endif // DEBUG
   1.292 +
   1.293 +  /**
   1.294 +   * CompareTreePosition determines whether aContent1 comes before or
   1.295 +   * after aContent2 in a preorder traversal of the content tree.
   1.296 +   *
   1.297 +   * @param aCommonAncestor either null, or a common ancestor of
   1.298 +   *                        aContent1 and aContent2.  Actually this is
   1.299 +   *                        only a hint; if it's not an ancestor of
   1.300 +   *                        aContent1 or aContent2, this function will
   1.301 +   *                        still work, but it will be slower than
   1.302 +   *                        normal.
   1.303 +   * @return < 0 if aContent1 is before aContent2
   1.304 +   *         > 0 if aContent1 is after aContent2,
   1.305 +   *         0 otherwise (meaning they're the same, or they're in
   1.306 +   *           different documents)
   1.307 +   */
   1.308 +  static int32_t CompareTreePosition(nsIContent* aContent1,
   1.309 +                                     nsIContent* aContent2,
   1.310 +                                     const nsIContent* aCommonAncestor = nullptr)
   1.311 +  {
   1.312 +    return DoCompareTreePosition(aContent1, aContent2, -1, 1, aCommonAncestor);
   1.313 +  }
   1.314 +
   1.315 +  /*
   1.316 +   * More generic version of |CompareTreePosition|.  |aIf1Ancestor|
   1.317 +   * gives the value to return when 1 is an ancestor of 2, and likewise
   1.318 +   * for |aIf2Ancestor|.  Passing (-1, 1) gives preorder traversal
   1.319 +   * order, and (1, -1) gives postorder traversal order.
   1.320 +   */
   1.321 +  static int32_t DoCompareTreePosition(nsIContent* aContent1,
   1.322 +                                       nsIContent* aContent2,
   1.323 +                                       int32_t aIf1Ancestor,
   1.324 +                                       int32_t aIf2Ancestor,
   1.325 +                                       const nsIContent* aCommonAncestor = nullptr);
   1.326 +
   1.327 +  /**
   1.328 +   * CompareTreePosition determines whether aFrame1 comes before or
   1.329 +   * after aFrame2 in a preorder traversal of the frame tree, where out
   1.330 +   * of flow frames are treated as children of their placeholders. This is
   1.331 +   * basically the same ordering as DoCompareTreePosition(nsIContent*) except
   1.332 +   * that it handles anonymous content properly and there are subtleties with
   1.333 +   * continuations.
   1.334 +   *
   1.335 +   * @param aCommonAncestor either null, or a common ancestor of
   1.336 +   *                        aContent1 and aContent2.  Actually this is
   1.337 +   *                        only a hint; if it's not an ancestor of
   1.338 +   *                        aContent1 or aContent2, this function will
   1.339 +   *                        still work, but it will be slower than
   1.340 +   *                        normal.
   1.341 +   * @return < 0 if aContent1 is before aContent2
   1.342 +   *         > 0 if aContent1 is after aContent2,
   1.343 +   *         0 otherwise (meaning they're the same, or they're in
   1.344 +   *           different frame trees)
   1.345 +   */
   1.346 +  static int32_t CompareTreePosition(nsIFrame* aFrame1,
   1.347 +                                     nsIFrame* aFrame2,
   1.348 +                                     nsIFrame* aCommonAncestor = nullptr)
   1.349 +  {
   1.350 +    return DoCompareTreePosition(aFrame1, aFrame2, -1, 1, aCommonAncestor);
   1.351 +  }
   1.352 +
   1.353 +  static int32_t CompareTreePosition(nsIFrame* aFrame1,
   1.354 +                                     nsIFrame* aFrame2,
   1.355 +                                     nsTArray<nsIFrame*>& aFrame2Ancestors,
   1.356 +                                     nsIFrame* aCommonAncestor = nullptr)
   1.357 +  {
   1.358 +    return DoCompareTreePosition(aFrame1, aFrame2, aFrame2Ancestors,
   1.359 +                                 -1, 1, aCommonAncestor);
   1.360 +  }
   1.361 +
   1.362 +  /*
   1.363 +   * More generic version of |CompareTreePosition|.  |aIf1Ancestor|
   1.364 +   * gives the value to return when 1 is an ancestor of 2, and likewise
   1.365 +   * for |aIf2Ancestor|.  Passing (-1, 1) gives preorder traversal
   1.366 +   * order, and (1, -1) gives postorder traversal order.
   1.367 +   */
   1.368 +  static int32_t DoCompareTreePosition(nsIFrame* aFrame1,
   1.369 +                                       nsIFrame* aFrame2,
   1.370 +                                       int32_t aIf1Ancestor,
   1.371 +                                       int32_t aIf2Ancestor,
   1.372 +                                       nsIFrame* aCommonAncestor = nullptr);
   1.373 +
   1.374 +  static nsIFrame* FillAncestors(nsIFrame* aFrame,
   1.375 +                                 nsIFrame* aStopAtAncestor,
   1.376 +                                 nsTArray<nsIFrame*>* aAncestors);
   1.377 +
   1.378 +  static int32_t DoCompareTreePosition(nsIFrame* aFrame1,
   1.379 +                                       nsIFrame* aFrame2,
   1.380 +                                       nsTArray<nsIFrame*>& aFrame2Ancestors,
   1.381 +                                       int32_t aIf1Ancestor,
   1.382 +                                       int32_t aIf2Ancestor,
   1.383 +                                       nsIFrame* aCommonAncestor);
   1.384 +
   1.385 +  /**
   1.386 +   * LastContinuationWithChild gets the last continuation in aFrame's chain
   1.387 +   * that has a child, or the first continuation if the frame has no children.
   1.388 +   */
   1.389 +  static nsIFrame* LastContinuationWithChild(nsIFrame* aFrame);
   1.390 +
   1.391 +  /**
   1.392 +   * GetLastSibling simply finds the last sibling of aFrame, or returns nullptr if
   1.393 +   * aFrame is null.
   1.394 +   */
   1.395 +  static nsIFrame* GetLastSibling(nsIFrame* aFrame);
   1.396 +
   1.397 +  /**
   1.398 +   * FindSiblingViewFor locates the child of aParentView that aFrame's
   1.399 +   * view should be inserted 'above' (i.e., before in sibling view
   1.400 +   * order).  This is the first child view of aParentView whose
   1.401 +   * corresponding content is before aFrame's content (view siblings
   1.402 +   * are in reverse content order).
   1.403 +   */
   1.404 +  static nsView* FindSiblingViewFor(nsView* aParentView, nsIFrame* aFrame);
   1.405 +
   1.406 +  /**
   1.407 +   * Get the parent of aFrame. If aFrame is the root frame for a document,
   1.408 +   * and the document has a parent document in the same view hierarchy, then
   1.409 +   * we try to return the subdocumentframe in the parent document.
   1.410 +   * @param aExtraOffset [in/out] if non-null, then as we cross documents
   1.411 +   * an extra offset may be required and it will be added to aCrossDocOffset.
   1.412 +   * Be careful dealing with this extra offset as it is in app units of the
   1.413 +   * parent document, which may have a different app units per dev pixel ratio
   1.414 +   * than the child document.
   1.415 +   */
   1.416 +  static nsIFrame* GetCrossDocParentFrame(const nsIFrame* aFrame,
   1.417 +                                          nsPoint* aCrossDocOffset = nullptr);
   1.418 +
   1.419 +  /**
   1.420 +   * IsProperAncestorFrame checks whether aAncestorFrame is an ancestor
   1.421 +   * of aFrame and not equal to aFrame.
   1.422 +   * @param aCommonAncestor nullptr, or a common ancestor of aFrame and
   1.423 +   * aAncestorFrame. If non-null, this can bound the search and speed up
   1.424 +   * the function
   1.425 +   */
   1.426 +  static bool IsProperAncestorFrame(nsIFrame* aAncestorFrame, nsIFrame* aFrame,
   1.427 +                                      nsIFrame* aCommonAncestor = nullptr);
   1.428 +
   1.429 +  /**
   1.430 +   * Like IsProperAncestorFrame, but looks across document boundaries.
   1.431 +   *
   1.432 +   * Just like IsAncestorFrameCrossDoc, except that it returns false when
   1.433 +   * aFrame == aAncestorFrame.
   1.434 +   */
   1.435 +  static bool IsProperAncestorFrameCrossDoc(nsIFrame* aAncestorFrame, nsIFrame* aFrame,
   1.436 +                                              nsIFrame* aCommonAncestor = nullptr);
   1.437 +
   1.438 +  /**
   1.439 +   * IsAncestorFrameCrossDoc checks whether aAncestorFrame is an ancestor
   1.440 +   * of aFrame or equal to aFrame, looking across document boundaries.
   1.441 +   * @param aCommonAncestor nullptr, or a common ancestor of aFrame and
   1.442 +   * aAncestorFrame. If non-null, this can bound the search and speed up
   1.443 +   * the function.
   1.444 +   *
   1.445 +   * Just like IsProperAncestorFrameCrossDoc, except that it returns true when
   1.446 +   * aFrame == aAncestorFrame.
   1.447 +   */
   1.448 +  static bool IsAncestorFrameCrossDoc(const nsIFrame* aAncestorFrame, const nsIFrame* aFrame,
   1.449 +                                        const nsIFrame* aCommonAncestor = nullptr);
   1.450 +
   1.451 +  /**
   1.452 +   * Sets the fixed-pos metadata properties on aLayer.
   1.453 +   * aAnchorRect is the basic anchor rectangle. If aFixedPosFrame is not a viewport
   1.454 +   * frame, then we pick a corner of aAnchorRect to as the anchor point for the
   1.455 +   * fixed-pos layer (i.e. the point to remain stable during zooming), based
   1.456 +   * on which of the fixed-pos frame's CSS absolute positioning offset
   1.457 +   * properties (top, left, right, bottom) are auto. aAnchorRect is in the
   1.458 +   * coordinate space of aLayer's container layer (i.e. relative to the reference
   1.459 +   * frame of the display item which is building aLayer's container layer).
   1.460 +   */
   1.461 +  static void SetFixedPositionLayerData(Layer* aLayer, const nsIFrame* aViewportFrame,
   1.462 +                                        const nsRect& aAnchorRect,
   1.463 +                                        const nsIFrame* aFixedPosFrame,
   1.464 +                                        nsPresContext* aPresContext,
   1.465 +                                        const ContainerLayerParameters& aContainerParameters);
   1.466 +
   1.467 +  /**
   1.468 +   * Return true if aPresContext's viewport has a displayport.
   1.469 +   * Fills in aDisplayPort with the displayport rectangle if non-null.
   1.470 +   */
   1.471 +  static bool ViewportHasDisplayPort(nsPresContext* aPresContext,
   1.472 +                                     nsRect* aDisplayPort = nullptr);
   1.473 +
   1.474 +  /**
   1.475 +   * Return true if aFrame is a fixed-pos frame and is a child of a viewport
   1.476 +   * which has a displayport. These frames get special treatment from the compositor.
   1.477 +   * aDisplayPort, if non-null, is set to the display port rectangle (relative to
   1.478 +   * the viewport).
   1.479 +   */
   1.480 +  static bool IsFixedPosFrameInDisplayPort(const nsIFrame* aFrame,
   1.481 +                                           nsRect* aDisplayPort = nullptr);
   1.482 +
   1.483 +  /**
   1.484 +   * Finds the nearest ancestor frame to aItem that is considered to have (or
   1.485 +   * will have) "animated geometry". For example the scrolled frames of
   1.486 +   * scrollframes which are actively being scrolled fall into this category.
   1.487 +   * Frames with certain CSS properties that are being animated (e.g.
   1.488 +   * 'left'/'top' etc) are also placed in this category.
   1.489 +   * Frames with different active geometry roots are in different ThebesLayers,
   1.490 +   * so that we can animate the geometry root by changing its transform (either
   1.491 +   * on the main thread or in the compositor).
   1.492 +   * The animated geometry root is required to be a descendant (or equal to)
   1.493 +   * aItem's ReferenceFrame(), which means that we will fall back to
   1.494 +   * returning aItem->ReferenceFrame() when we can't find another animated
   1.495 +   * geometry root.
   1.496 +   */
   1.497 +  static nsIFrame* GetAnimatedGeometryRootFor(nsDisplayItem* aItem,
   1.498 +                                              nsDisplayListBuilder* aBuilder);
   1.499 +
   1.500 +  /**
   1.501 +    * GetScrollableFrameFor returns the scrollable frame for a scrolled frame
   1.502 +    */
   1.503 +  static nsIScrollableFrame* GetScrollableFrameFor(const nsIFrame *aScrolledFrame);
   1.504 +
   1.505 +  /**
   1.506 +   * GetNearestScrollableFrameForDirection locates the first ancestor of
   1.507 +   * aFrame (or aFrame itself) that is scrollable with overflow:scroll or
   1.508 +   * overflow:auto in the given direction and where either the scrollbar for
   1.509 +   * that direction is visible or the frame can be scrolled by some
   1.510 +   * positive amount in that direction.
   1.511 +   * The search extends across document boundaries.
   1.512 +   *
   1.513 +   * @param  aFrame the frame to start with
   1.514 +   * @param  aDirection Whether it's for horizontal or vertical scrolling.
   1.515 +   * @return the nearest scrollable frame or nullptr if not found
   1.516 +   */
   1.517 +  enum Direction { eHorizontal, eVertical };
   1.518 +  static nsIScrollableFrame* GetNearestScrollableFrameForDirection(nsIFrame* aFrame,
   1.519 +                                                                   Direction aDirection);
   1.520 +
   1.521 +  enum {
   1.522 +    SCROLLABLE_SAME_DOC = 0x01,
   1.523 +    SCROLLABLE_INCLUDE_HIDDEN = 0x02
   1.524 +  };
   1.525 +  /**
   1.526 +   * GetNearestScrollableFrame locates the first ancestor of aFrame
   1.527 +   * (or aFrame itself) that is scrollable with overflow:scroll or
   1.528 +   * overflow:auto in some direction.
   1.529 +   *
   1.530 +   * @param  aFrame the frame to start with
   1.531 +   * @param  aFlags if SCROLLABLE_SAME_DOC is set, do not search across
   1.532 +   * document boundaries. If SCROLLABLE_INCLUDE_HIDDEN is set, include
   1.533 +   * frames scrollable with overflow:hidden.
   1.534 +   * @return the nearest scrollable frame or nullptr if not found
   1.535 +   */
   1.536 +  static nsIScrollableFrame* GetNearestScrollableFrame(nsIFrame* aFrame,
   1.537 +                                                       uint32_t aFlags = 0);
   1.538 +
   1.539 +  /**
   1.540 +   * GetScrolledRect returns the range of allowable scroll offsets
   1.541 +   * for aScrolledFrame, assuming the scrollable overflow area is
   1.542 +   * aScrolledFrameOverflowArea and the scrollport size is aScrollPortSize.
   1.543 +   * aDirection is either NS_STYLE_DIRECTION_LTR or NS_STYLE_DIRECTION_RTL.
   1.544 +   */
   1.545 +  static nsRect GetScrolledRect(nsIFrame* aScrolledFrame,
   1.546 +                                const nsRect& aScrolledFrameOverflowArea,
   1.547 +                                const nsSize& aScrollPortSize,
   1.548 +                                uint8_t aDirection);
   1.549 +
   1.550 +  /**
   1.551 +   * HasPseudoStyle returns true if aContent (whose primary style
   1.552 +   * context is aStyleContext) has the aPseudoElement pseudo-style
   1.553 +   * attached to it; returns false otherwise.
   1.554 +   *
   1.555 +   * @param aContent the content node we're looking at
   1.556 +   * @param aStyleContext aContent's style context
   1.557 +   * @param aPseudoElement the id of the pseudo style we care about
   1.558 +   * @param aPresContext the presentation context
   1.559 +   * @return whether aContent has aPseudoElement style attached to it
   1.560 +   */
   1.561 +  static bool HasPseudoStyle(nsIContent* aContent,
   1.562 +                               nsStyleContext* aStyleContext,
   1.563 +                               nsCSSPseudoElements::Type aPseudoElement,
   1.564 +                               nsPresContext* aPresContext);
   1.565 +
   1.566 +  /**
   1.567 +   * If this frame is a placeholder for a float, then return the float,
   1.568 +   * otherwise return nullptr.  aPlaceholder must be a placeholder frame.
   1.569 +   */
   1.570 +  static nsIFrame* GetFloatFromPlaceholder(nsIFrame* aPlaceholder);
   1.571 +
   1.572 +  // Combine aNewBreakType with aOrigBreakType, but limit the break types
   1.573 +  // to NS_STYLE_CLEAR_LEFT, RIGHT, LEFT_AND_RIGHT.
   1.574 +  static uint8_t CombineBreakType(uint8_t aOrigBreakType, uint8_t aNewBreakType);
   1.575 +
   1.576 +  /**
   1.577 +   * Get the coordinates of a given DOM mouse event, relative to a given
   1.578 +   * frame. Works only for DOM events generated by WidgetGUIEvents.
   1.579 +   * @param aDOMEvent the event
   1.580 +   * @param aFrame the frame to make coordinates relative to
   1.581 +   * @return the point, or (NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE) if
   1.582 +   * for some reason the coordinates for the mouse are not known (e.g.,
   1.583 +   * the event is not a GUI event).
   1.584 +   */
   1.585 +  static nsPoint GetDOMEventCoordinatesRelativeTo(nsIDOMEvent* aDOMEvent,
   1.586 +                                                  nsIFrame* aFrame);
   1.587 +
   1.588 +  /**
   1.589 +   * Get the coordinates of a given native mouse event, relative to a given
   1.590 +   * frame.
   1.591 +   * @param aEvent the event
   1.592 +   * @param aFrame the frame to make coordinates relative to
   1.593 +   * @return the point, or (NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE) if
   1.594 +   * for some reason the coordinates for the mouse are not known (e.g.,
   1.595 +   * the event is not a GUI event).
   1.596 +   */
   1.597 +  static nsPoint GetEventCoordinatesRelativeTo(
   1.598 +                   const mozilla::WidgetEvent* aEvent,
   1.599 +                   nsIFrame* aFrame);
   1.600 +
   1.601 +  /**
   1.602 +   * Get the coordinates of a given point relative to an event and a
   1.603 +   * given frame.
   1.604 +   * @param aEvent the event
   1.605 +   * @param aPoint the point to get the coordinates relative to
   1.606 +   * @param aFrame the frame to make coordinates relative to
   1.607 +   * @return the point, or (NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE) if
   1.608 +   * for some reason the coordinates for the mouse are not known (e.g.,
   1.609 +   * the event is not a GUI event).
   1.610 +   */
   1.611 +  static nsPoint GetEventCoordinatesRelativeTo(
   1.612 +                   const mozilla::WidgetEvent* aEvent,
   1.613 +                   const nsIntPoint aPoint,
   1.614 +                   nsIFrame* aFrame);
   1.615 +
   1.616 +  /**
   1.617 +   * Get the coordinates of a given point relative to a widget and a
   1.618 +   * given frame.
   1.619 +   * @param aWidget the event src widget
   1.620 +   * @param aPoint the point to get the coordinates relative to
   1.621 +   * @param aFrame the frame to make coordinates relative to
   1.622 +   * @return the point, or (NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE) if
   1.623 +   * for some reason the coordinates for the mouse are not known (e.g.,
   1.624 +   * the event is not a GUI event).
   1.625 +   */
   1.626 +  static nsPoint GetEventCoordinatesRelativeTo(nsIWidget* aWidget,
   1.627 +                                               const nsIntPoint aPoint,
   1.628 +                                               nsIFrame* aFrame);
   1.629 +
   1.630 +  /**
   1.631 +   * Get the popup frame of a given native mouse event.
   1.632 +   * @param aPresContext only check popups within aPresContext or a descendant
   1.633 +   * @param aEvent  the event.
   1.634 +   * @return        Null, if there is no popup frame at the point, otherwise,
   1.635 +   *                returns top-most popup frame at the point.
   1.636 +   */
   1.637 +  static nsIFrame* GetPopupFrameForEventCoordinates(
   1.638 +                     nsPresContext* aPresContext,
   1.639 +                     const mozilla::WidgetEvent* aEvent);
   1.640 +
   1.641 +  /**
   1.642 +   * Translate from widget coordinates to the view's coordinates
   1.643 +   * @param aPresContext the PresContext for the view
   1.644 +   * @param aWidget the widget
   1.645 +   * @param aPt the point relative to the widget
   1.646 +   * @param aView  view to which returned coordinates are relative
   1.647 +   * @return the point in the view's coordinates
   1.648 +   */
   1.649 +  static nsPoint TranslateWidgetToView(nsPresContext* aPresContext,
   1.650 +                                       nsIWidget* aWidget, nsIntPoint aPt,
   1.651 +                                       nsView* aView);
   1.652 +
   1.653 +  /**
   1.654 +   * Given a matrix and a point, let T be the transformation matrix translating points
   1.655 +   * in the coordinate space with origin aOrigin to the coordinate space used by the
   1.656 +   * matrix.  If M is the stored matrix, this function returns (T-1)MT, the matrix
   1.657 +   * that's equivalent to aMatrix but in the coordinate space that treats aOrigin
   1.658 +   * as the origin.
   1.659 +   *
   1.660 +   * @param aOrigin The origin to translate to.
   1.661 +   * @param aMatrix The matrix to change the basis of.
   1.662 +   * @return A matrix equivalent to aMatrix, but operating in the coordinate system with
   1.663 +   *         origin aOrigin.
   1.664 +   */
   1.665 +  static gfx3DMatrix ChangeMatrixBasis(const gfxPoint3D &aOrigin, const gfx3DMatrix &aMatrix);
   1.666 +
   1.667 +  /**
   1.668 +   * Find IDs corresponding to a scrollable content element in the child process.
   1.669 +   * In correspondence with the shadow layer tree, you can use this to perform a
   1.670 +   * hit test that corresponds to a specific shadow layer that you can then perform
   1.671 +   * transformations on to do parent-side scrolling.
   1.672 +   *
   1.673 +   * @param aFrame The root frame of a stack context
   1.674 +   * @param aTarget The rect to hit test relative to the frame origin
   1.675 +   * @param aOutIDs All found IDs are added here
   1.676 +   * @param aIgnoreRootScrollFrame a boolean to control if the display list
   1.677 +   *        builder should ignore the root scroll frame
   1.678 +   */
   1.679 +  static nsresult GetRemoteContentIds(nsIFrame* aFrame,
   1.680 +                                     const nsRect& aTarget,
   1.681 +                                     nsTArray<ViewID> &aOutIDs,
   1.682 +                                     bool aIgnoreRootScrollFrame);
   1.683 +
   1.684 +  enum FrameForPointFlags {
   1.685 +    /**
   1.686 +     * When set, paint suppression is ignored, so we'll return non-root page
   1.687 +     * elements even if paint suppression is stopping them from painting.
   1.688 +     */
   1.689 +    IGNORE_PAINT_SUPPRESSION = 0x01,
   1.690 +    /**
   1.691 +     * When set, clipping due to the root scroll frame (and any other viewport-
   1.692 +     * related clipping) is ignored.
   1.693 +     */
   1.694 +    IGNORE_ROOT_SCROLL_FRAME = 0x02,
   1.695 +    /**
   1.696 +     * When set, return only content in the same document as aFrame.
   1.697 +     */
   1.698 +    IGNORE_CROSS_DOC = 0x04
   1.699 +  };
   1.700 +
   1.701 +  /**
   1.702 +   * Given aFrame, the root frame of a stacking context, find its descendant
   1.703 +   * frame under the point aPt that receives a mouse event at that location,
   1.704 +   * or nullptr if there is no such frame.
   1.705 +   * @param aPt the point, relative to the frame origin
   1.706 +   * @param aFlags some combination of FrameForPointFlags
   1.707 +   */
   1.708 +  static nsIFrame* GetFrameForPoint(nsIFrame* aFrame, nsPoint aPt,
   1.709 +                                    uint32_t aFlags = 0);
   1.710 +
   1.711 +  /**
   1.712 +   * Given aFrame, the root frame of a stacking context, find all descendant
   1.713 +   * frames under the area of a rectangle that receives a mouse event,
   1.714 +   * or nullptr if there is no such frame.
   1.715 +   * @param aRect the rect, relative to the frame origin
   1.716 +   * @param aOutFrames an array to add all the frames found
   1.717 +   * @param aFlags some combination of FrameForPointFlags
   1.718 +   */
   1.719 +  static nsresult GetFramesForArea(nsIFrame* aFrame, const nsRect& aRect,
   1.720 +                                   nsTArray<nsIFrame*> &aOutFrames,
   1.721 +                                   uint32_t aFlags = 0);
   1.722 +
   1.723 +  /**
   1.724 +   * Transform aRect relative to aFrame up to the coordinate system of
   1.725 +   * aAncestor. Computes the bounding-box of the true quadrilateral.
   1.726 +   * Pass non-null aPreservesAxisAlignedRectangles and it will be set to true if
   1.727 +   * we only need to use a 2d transform that PreservesAxisAlignedRectangles().
   1.728 +   */
   1.729 +  static nsRect TransformFrameRectToAncestor(nsIFrame* aFrame,
   1.730 +                                             const nsRect& aRect,
   1.731 +                                             const nsIFrame* aAncestor,
   1.732 +                                             bool* aPreservesAxisAlignedRectangles = nullptr);
   1.733 +
   1.734 +
   1.735 +  /**
   1.736 +   * Gets the transform for aFrame relative to aAncestor. Pass null for aAncestor
   1.737 +   * to go up to the root frame.
   1.738 +   */
   1.739 +  static gfx3DMatrix GetTransformToAncestor(nsIFrame *aFrame, const nsIFrame *aAncestor);
   1.740 +
   1.741 +  /**
   1.742 +   * Transforms a list of CSSPoints from aFromFrame to aToFrame, taking into
   1.743 +   * account all relevant transformations on the frames up to (but excluding)
   1.744 +   * their nearest common ancestor.
   1.745 +   * If we encounter a transform that we need to invert but which is
   1.746 +   * non-invertible, we return NONINVERTIBLE_TRANSFORM. If the frames have
   1.747 +   * no common ancestor, we return NO_COMMON_ANCESTOR.
   1.748 +   * If this returns TRANSFORM_SUCCEEDED, the points in aPoints are transformed
   1.749 +   * in-place, otherwise they are untouched.
   1.750 +   */
   1.751 +  enum TransformResult {
   1.752 +    TRANSFORM_SUCCEEDED,
   1.753 +    NO_COMMON_ANCESTOR,
   1.754 +    NONINVERTIBLE_TRANSFORM
   1.755 +  };
   1.756 +  static TransformResult TransformPoints(nsIFrame* aFromFrame, nsIFrame* aToFrame,
   1.757 +                                         uint32_t aPointCount, CSSPoint* aPoints);
   1.758 +
   1.759 +  /**
   1.760 +   * Return true if a "layer transform" could be computed for aFrame,
   1.761 +   * and optionally return the computed transform.  The returned
   1.762 +   * transform is what would be set on the layer currently if a layers
   1.763 +   * transaction were opened at the time this helper is called.
   1.764 +   */
   1.765 +  static bool GetLayerTransformForFrame(nsIFrame* aFrame,
   1.766 +                                        gfx3DMatrix* aTransform);
   1.767 +
   1.768 +  /**
   1.769 +   * Given a point in the global coordinate space, returns that point expressed
   1.770 +   * in the coordinate system of aFrame.  This effectively inverts all transforms
   1.771 +   * between this point and the root frame.
   1.772 +   *
   1.773 +   * @param aFrame The frame that acts as the coordinate space container.
   1.774 +   * @param aPoint The point, in the global space, to get in the frame-local space.
   1.775 +   * @return aPoint, expressed in aFrame's canonical coordinate space.
   1.776 +   */
   1.777 +  static nsPoint TransformRootPointToFrame(nsIFrame* aFrame,
   1.778 +                                           const nsPoint &aPoint)
   1.779 +  {
   1.780 +    return TransformAncestorPointToFrame(aFrame, aPoint, nullptr);
   1.781 +  }
   1.782 +
   1.783 +  /**
   1.784 +   * Transform aPoint relative to aAncestor down to the coordinate system of
   1.785 +   * aFrame.
   1.786 +   */
   1.787 +  static nsPoint TransformAncestorPointToFrame(nsIFrame* aFrame,
   1.788 +                                               const nsPoint& aPoint,
   1.789 +                                               nsIFrame* aAncestor);
   1.790 +
   1.791 +  /**
   1.792 +   * Helper function that, given a rectangle and a matrix, returns the smallest
   1.793 +   * rectangle containing the image of the source rectangle.
   1.794 +   *
   1.795 +   * @param aBounds The rectangle to transform.
   1.796 +   * @param aMatrix The matrix to transform it with.
   1.797 +   * @param aFactor The number of app units per graphics unit.
   1.798 +   * @return The smallest rect that contains the image of aBounds.
   1.799 +   */
   1.800 +  static nsRect MatrixTransformRect(const nsRect &aBounds,
   1.801 +                                    const gfx3DMatrix &aMatrix, float aFactor);
   1.802 +
   1.803 +  /**
   1.804 +   * Helper function that, given a rectangle and a matrix, returns the smallest
   1.805 +   * rectangle containing the image of the source rectangle rounded out to the nearest
   1.806 +   * pixel value.
   1.807 +   *
   1.808 +   * @param aBounds The rectangle to transform.
   1.809 +   * @param aMatrix The matrix to transform it with.
   1.810 +   * @param aFactor The number of app units per graphics unit.
   1.811 +   * @return The smallest rect that contains the image of aBounds.
   1.812 +   */
   1.813 +  static nsRect MatrixTransformRectOut(const nsRect &aBounds,
   1.814 +                                    const gfx3DMatrix &aMatrix, float aFactor);
   1.815 +  /**
   1.816 +   * Helper function that, given a point and a matrix, returns the image
   1.817 +   * of that point under the matrix transform.
   1.818 +   *
   1.819 +   * @param aPoint The point to transform.
   1.820 +   * @param aMatrix The matrix to transform it with.
   1.821 +   * @param aFactor The number of app units per graphics unit.
   1.822 +   * @return The image of the point under the transform.
   1.823 +   */
   1.824 +  static nsPoint MatrixTransformPoint(const nsPoint &aPoint,
   1.825 +                                      const gfx3DMatrix &aMatrix, float aFactor);
   1.826 +
   1.827 +  /**
   1.828 +   * Given a graphics rectangle in graphics space, return a rectangle in
   1.829 +   * app space that contains the graphics rectangle, rounding out as necessary.
   1.830 +   *
   1.831 +   * @param aRect The graphics rect to round outward.
   1.832 +   * @param aFactor The number of app units per graphics unit.
   1.833 +   * @return The smallest rectangle in app space that contains aRect.
   1.834 +   */
   1.835 +  static nsRect RoundGfxRectToAppRect(const Rect &aRect, float aFactor);
   1.836 +
   1.837 +  /**
   1.838 +   * Given a graphics rectangle in graphics space, return a rectangle in
   1.839 +   * app space that contains the graphics rectangle, rounding out as necessary.
   1.840 +   *
   1.841 +   * @param aRect The graphics rect to round outward.
   1.842 +   * @param aFactor The number of app units per graphics unit.
   1.843 +   * @return The smallest rectangle in app space that contains aRect.
   1.844 +   */
   1.845 +  static nsRect RoundGfxRectToAppRect(const gfxRect &aRect, float aFactor);
   1.846 +
   1.847 +  /**
   1.848 +   * Returns a subrectangle of aContainedRect that is entirely inside the rounded
   1.849 +   * rect. Complex cases are handled conservatively by returning a smaller
   1.850 +   * rect than necessary.
   1.851 +   */
   1.852 +  static nsRegion RoundedRectIntersectRect(const nsRect& aRoundedRect,
   1.853 +                                           const nscoord aRadii[8],
   1.854 +                                           const nsRect& aContainedRect);
   1.855 +
   1.856 +  /**
   1.857 +   * Return whether any part of aTestRect is inside of the rounded
   1.858 +   * rectangle formed by aBounds and aRadii (which are indexed by the
   1.859 +   * NS_CORNER_* constants in nsStyleConsts.h). This is precise.
   1.860 +   */
   1.861 +  static bool RoundedRectIntersectsRect(const nsRect& aRoundedRect,
   1.862 +                                        const nscoord aRadii[8],
   1.863 +                                        const nsRect& aTestRect);
   1.864 +
   1.865 +  enum {
   1.866 +    PAINT_IN_TRANSFORM = 0x01,
   1.867 +    PAINT_SYNC_DECODE_IMAGES = 0x02,
   1.868 +    PAINT_WIDGET_LAYERS = 0x04,
   1.869 +    PAINT_IGNORE_SUPPRESSION = 0x08,
   1.870 +    PAINT_DOCUMENT_RELATIVE = 0x10,
   1.871 +    PAINT_HIDE_CARET = 0x20,
   1.872 +    PAINT_ALL_CONTINUATIONS = 0x40,
   1.873 +    PAINT_TO_WINDOW = 0x80,
   1.874 +    PAINT_EXISTING_TRANSACTION = 0x100,
   1.875 +    PAINT_NO_COMPOSITE = 0x200,
   1.876 +    PAINT_COMPRESSED = 0x400
   1.877 +  };
   1.878 +
   1.879 +  /**
   1.880 +   * Given aFrame, the root frame of a stacking context, paint it and its
   1.881 +   * descendants to aRenderingContext.
   1.882 +   * @param aRenderingContext a rendering context translated so that (0,0)
   1.883 +   * is the origin of aFrame; for best results, (0,0) should transform
   1.884 +   * to pixel-aligned coordinates. This can be null, in which case
   1.885 +   * aFrame must be a "display root" (root frame for a root document,
   1.886 +   * or the root of a popup) with an associated widget and we draw using
   1.887 +   * the layer manager for the frame's widget.
   1.888 +   * @param aDirtyRegion the region that must be painted, in the coordinates
   1.889 +   * of aFrame
   1.890 +   * @param aBackstop paint the dirty area with this color before drawing
   1.891 +   * the actual content; pass NS_RGBA(0,0,0,0) to draw no background
   1.892 +   * @param aFlags if PAINT_IN_TRANSFORM is set, then we assume
   1.893 +   * this is inside a transform or SVG foreignObject. If
   1.894 +   * PAINT_SYNC_DECODE_IMAGES is set, we force synchronous decode on all
   1.895 +   * images. If PAINT_WIDGET_LAYERS is set, aFrame must be a display root,
   1.896 +   * and we will use the frame's widget's layer manager to paint
   1.897 +   * even if aRenderingContext is non-null. This is useful if you want
   1.898 +   * to force rendering to use the widget's layer manager for testing
   1.899 +   * or speed. PAINT_WIDGET_LAYERS must be set if aRenderingContext is null.
   1.900 +   * If PAINT_DOCUMENT_RELATIVE is used, the visible region is interpreted
   1.901 +   * as being relative to the document.  (Normally it's relative to the CSS
   1.902 +   * viewport.) PAINT_TO_WINDOW sets painting to window to true on the display
   1.903 +   * list builder even if we can't tell that we are painting to the window.
   1.904 +   * If PAINT_EXISTING_TRANSACTION is set, then BeginTransaction() has already
   1.905 +   * been called on aFrame's widget's layer manager and should not be
   1.906 +   * called again.
   1.907 +   * If PAINT_COMPRESSED is set, the FrameLayerBuilder should be set to compressed mode
   1.908 +   * to avoid short cut optimizations.
   1.909 +   *
   1.910 +   * So there are three possible behaviours:
   1.911 +   * 1) PAINT_WIDGET_LAYERS is set and aRenderingContext is null; we paint
   1.912 +   * by calling BeginTransaction on the widget's layer manager
   1.913 +   * 2) PAINT_WIDGET_LAYERS is set and aRenderingContext is non-null; we
   1.914 +   * paint by calling BeginTransactionWithTarget on the widget's layer
   1.915 +   * maanger
   1.916 +   * 3) PAINT_WIDGET_LAYERS is not set and aRenderingContext is non-null;
   1.917 +   * we paint by construct a BasicLayerManager and calling
   1.918 +   * BeginTransactionWithTarget on it. This is desirable if we're doing
   1.919 +   * something like drawWindow in a mode where what gets rendered doesn't
   1.920 +   * necessarily correspond to what's visible in the window; we don't
   1.921 +   * want to mess up the widget's layer tree.
   1.922 +   */
   1.923 +  static nsresult PaintFrame(nsRenderingContext* aRenderingContext, nsIFrame* aFrame,
   1.924 +                             const nsRegion& aDirtyRegion, nscolor aBackstop,
   1.925 +                             uint32_t aFlags = 0);
   1.926 +
   1.927 +  /**
   1.928 +   * Uses a binary search for find where the cursor falls in the line of text
   1.929 +   * It also keeps track of the part of the string that has already been measured
   1.930 +   * so it doesn't have to keep measuring the same text over and over
   1.931 +   *
   1.932 +   * @param "aBaseWidth" contains the width in twips of the portion
   1.933 +   * of the text that has already been measured, and aBaseInx contains
   1.934 +   * the index of the text that has already been measured.
   1.935 +   *
   1.936 +   * @param aTextWidth returns the (in twips) the length of the text that falls
   1.937 +   * before the cursor aIndex contains the index of the text where the cursor falls
   1.938 +   */
   1.939 +  static bool
   1.940 +  BinarySearchForPosition(nsRenderingContext* acx,
   1.941 +                          const char16_t* aText,
   1.942 +                          int32_t    aBaseWidth,
   1.943 +                          int32_t    aBaseInx,
   1.944 +                          int32_t    aStartInx,
   1.945 +                          int32_t    aEndInx,
   1.946 +                          int32_t    aCursorPos,
   1.947 +                          int32_t&   aIndex,
   1.948 +                          int32_t&   aTextWidth);
   1.949 +
   1.950 +  class BoxCallback {
   1.951 +  public:
   1.952 +    virtual void AddBox(nsIFrame* aFrame) = 0;
   1.953 +  };
   1.954 +  /**
   1.955 +   * Collect all CSS boxes associated with aFrame and its
   1.956 +   * continuations, "drilling down" through outer table frames and
   1.957 +   * some anonymous blocks since they're not real CSS boxes.
   1.958 +   * If aFrame is null, no boxes are returned.
   1.959 +   * SVG frames return a single box, themselves.
   1.960 +   */
   1.961 +  static void GetAllInFlowBoxes(nsIFrame* aFrame, BoxCallback* aCallback);
   1.962 +
   1.963 +  /**
   1.964 +   * Find the first frame descendant of aFrame (including aFrame) which is
   1.965 +   * not an anonymous frame that getBoxQuads/getClientRects should ignore.
   1.966 +   */
   1.967 +  static nsIFrame* GetFirstNonAnonymousFrame(nsIFrame* aFrame);
   1.968 +
   1.969 +  class RectCallback {
   1.970 +  public:
   1.971 +    virtual void AddRect(const nsRect& aRect) = 0;
   1.972 +  };
   1.973 +
   1.974 +  struct RectAccumulator : public RectCallback {
   1.975 +    nsRect mResultRect;
   1.976 +    nsRect mFirstRect;
   1.977 +    bool mSeenFirstRect;
   1.978 +
   1.979 +    RectAccumulator();
   1.980 +
   1.981 +    virtual void AddRect(const nsRect& aRect);
   1.982 +  };
   1.983 +
   1.984 +  struct RectListBuilder : public RectCallback {
   1.985 +    DOMRectList* mRectList;
   1.986 +
   1.987 +    RectListBuilder(DOMRectList* aList);
   1.988 +    virtual void AddRect(const nsRect& aRect);
   1.989 +  };
   1.990 +
   1.991 +  static nsIFrame* GetContainingBlockForClientRect(nsIFrame* aFrame);
   1.992 +
   1.993 +  enum {
   1.994 +    RECTS_ACCOUNT_FOR_TRANSFORMS = 0x01,
   1.995 +    // Two bits for specifying which box type to use.
   1.996 +    // With neither bit set (default), use the border box.
   1.997 +    RECTS_USE_CONTENT_BOX = 0x02,
   1.998 +    RECTS_USE_PADDING_BOX = 0x04,
   1.999 +    RECTS_USE_MARGIN_BOX = 0x06, // both bits set
  1.1000 +    RECTS_WHICH_BOX_MASK = 0x06 // bitmask for these two bits
  1.1001 +  };
  1.1002 +  /**
  1.1003 +   * Collect all CSS boxes (content, padding, border, or margin) associated
  1.1004 +   * with aFrame and its continuations, "drilling down" through outer table
  1.1005 +   * frames and some anonymous blocks since they're not real CSS boxes.
  1.1006 +   * The boxes are positioned relative to aRelativeTo (taking scrolling
  1.1007 +   * into account) and passed to the callback in frame-tree order.
  1.1008 +   * If aFrame is null, no boxes are returned.
  1.1009 +   * For SVG frames, returns one rectangle, the bounding box.
  1.1010 +   * If aFlags includes RECTS_ACCOUNT_FOR_TRANSFORMS, then when converting
  1.1011 +   * the boxes into aRelativeTo coordinates, transforms (including CSS
  1.1012 +   * and SVG transforms) are taken into account.
  1.1013 +   * If aFlags includes one of RECTS_USE_CONTENT_BOX, RECTS_USE_PADDING_BOX,
  1.1014 +   * or RECTS_USE_MARGIN_BOX, the corresponding type of box is used.
  1.1015 +   * Otherwise (by default), the border box is used.
  1.1016 +   */
  1.1017 +  static void GetAllInFlowRects(nsIFrame* aFrame, nsIFrame* aRelativeTo,
  1.1018 +                                RectCallback* aCallback, uint32_t aFlags = 0);
  1.1019 +
  1.1020 +  /**
  1.1021 +   * Computes the union of all rects returned by GetAllInFlowRects. If
  1.1022 +   * the union is empty, returns the first rect.
  1.1023 +   * If aFlags includes RECTS_ACCOUNT_FOR_TRANSFORMS, then when converting
  1.1024 +   * the boxes into aRelativeTo coordinates, transforms (including CSS
  1.1025 +   * and SVG transforms) are taken into account.
  1.1026 +   * If aFlags includes one of RECTS_USE_CONTENT_BOX, RECTS_USE_PADDING_BOX,
  1.1027 +   * or RECTS_USE_MARGIN_BOX, the corresponding type of box is used.
  1.1028 +   * Otherwise (by default), the border box is used.
  1.1029 +   */
  1.1030 +  static nsRect GetAllInFlowRectsUnion(nsIFrame* aFrame, nsIFrame* aRelativeTo,
  1.1031 +                                       uint32_t aFlags = 0);
  1.1032 +
  1.1033 +  enum {
  1.1034 +    EXCLUDE_BLUR_SHADOWS = 0x01
  1.1035 +  };
  1.1036 +  /**
  1.1037 +   * Takes a text-shadow array from the style properties of a given nsIFrame and
  1.1038 +   * computes the union of those shadows along with the given initial rect.
  1.1039 +   * If there are no shadows, the initial rect is returned.
  1.1040 +   */
  1.1041 +  static nsRect GetTextShadowRectsUnion(const nsRect& aTextAndDecorationsRect,
  1.1042 +                                        nsIFrame* aFrame,
  1.1043 +                                        uint32_t aFlags = 0);
  1.1044 +
  1.1045 +  /**
  1.1046 +   * Get the font metrics corresponding to the frame's style data.
  1.1047 +   * @param aFrame the frame
  1.1048 +   * @param aFontMetrics the font metrics result
  1.1049 +   * @param aSizeInflation number to multiply font size by
  1.1050 +   * @return success or failure code
  1.1051 +   */
  1.1052 +  static nsresult GetFontMetricsForFrame(const nsIFrame* aFrame,
  1.1053 +                                         nsFontMetrics** aFontMetrics,
  1.1054 +                                         float aSizeInflation = 1.0f);
  1.1055 +
  1.1056 +  /**
  1.1057 +   * Get the font metrics corresponding to the given style data.
  1.1058 +   * @param aStyleContext the style data
  1.1059 +   * @param aFontMetrics the font metrics result
  1.1060 +   * @param aSizeInflation number to multiply font size by
  1.1061 +   * @return success or failure code
  1.1062 +   */
  1.1063 +  static nsresult GetFontMetricsForStyleContext(nsStyleContext* aStyleContext,
  1.1064 +                                                nsFontMetrics** aFontMetrics,
  1.1065 +                                                float aSizeInflation = 1.0f);
  1.1066 +
  1.1067 +  /**
  1.1068 +   * Find the immediate child of aParent whose frame subtree contains
  1.1069 +   * aDescendantFrame. Returns null if aDescendantFrame is not a descendant
  1.1070 +   * of aParent.
  1.1071 +   */
  1.1072 +  static nsIFrame* FindChildContainingDescendant(nsIFrame* aParent, nsIFrame* aDescendantFrame);
  1.1073 +
  1.1074 +  /**
  1.1075 +   * Find the nearest ancestor that's a block
  1.1076 +   */
  1.1077 +  static nsBlockFrame* FindNearestBlockAncestor(nsIFrame* aFrame);
  1.1078 +
  1.1079 +  /**
  1.1080 +   * Find the nearest ancestor that's not for generated content. Will return
  1.1081 +   * aFrame if aFrame is not for generated content.
  1.1082 +   */
  1.1083 +  static nsIFrame* GetNonGeneratedAncestor(nsIFrame* aFrame);
  1.1084 +
  1.1085 +  /**
  1.1086 +   * Cast aFrame to an nsBlockFrame* or return null if it's not
  1.1087 +   * an nsBlockFrame.
  1.1088 +   */
  1.1089 +  static nsBlockFrame* GetAsBlock(nsIFrame* aFrame);
  1.1090 +
  1.1091 +  /*
  1.1092 +   * Whether the frame is an nsBlockFrame which is not a wrapper block.
  1.1093 +   */
  1.1094 +  static bool IsNonWrapperBlock(nsIFrame* aFrame);
  1.1095 +
  1.1096 +  /**
  1.1097 +   * If aFrame is an out of flow frame, return its placeholder, otherwise
  1.1098 +   * return its parent.
  1.1099 +   */
  1.1100 +  static nsIFrame* GetParentOrPlaceholderFor(nsIFrame* aFrame);
  1.1101 +
  1.1102 +  /**
  1.1103 +   * If aFrame is an out of flow frame, return its placeholder, otherwise
  1.1104 +   * return its (possibly cross-doc) parent.
  1.1105 +   */
  1.1106 +  static nsIFrame* GetParentOrPlaceholderForCrossDoc(nsIFrame* aFrame);
  1.1107 +
  1.1108 +  /**
  1.1109 +   * Get a frame's next-in-flow, or, if it doesn't have one, its
  1.1110 +   * block-in-inline-split sibling.
  1.1111 +   */
  1.1112 +  static nsIFrame*
  1.1113 +  GetNextContinuationOrIBSplitSibling(nsIFrame *aFrame);
  1.1114 +
  1.1115 +  /**
  1.1116 +   * Get the first frame in the continuation-plus-ib-split-sibling chain
  1.1117 +   * containing aFrame.
  1.1118 +   */
  1.1119 +  static nsIFrame*
  1.1120 +  FirstContinuationOrIBSplitSibling(nsIFrame *aFrame);
  1.1121 +
  1.1122 +  /**
  1.1123 +   * Is FirstContinuationOrIBSplitSibling(aFrame) going to return
  1.1124 +   * aFrame?
  1.1125 +   */
  1.1126 +  static bool
  1.1127 +  IsFirstContinuationOrIBSplitSibling(nsIFrame *aFrame);
  1.1128 +
  1.1129 +  /**
  1.1130 +   * Check whether aFrame is a part of the scrollbar or scrollcorner of
  1.1131 +   * the root content.
  1.1132 +   * @param aFrame the checking frame
  1.1133 +   * @return if TRUE, the frame is a part of the scrollbar or scrollcorner of
  1.1134 +   *         the root content.
  1.1135 +   */
  1.1136 +  static bool IsViewportScrollbarFrame(nsIFrame* aFrame);
  1.1137 +
  1.1138 +  /**
  1.1139 +   * Get the contribution of aFrame to its containing block's intrinsic
  1.1140 +   * width.  This considers the child's intrinsic width, its 'width',
  1.1141 +   * 'min-width', and 'max-width' properties, and its padding, border,
  1.1142 +   * and margin.
  1.1143 +   */
  1.1144 +  enum IntrinsicWidthType { MIN_WIDTH, PREF_WIDTH };
  1.1145 +  enum {
  1.1146 +    IGNORE_PADDING = 0x01
  1.1147 +  };
  1.1148 +  static nscoord IntrinsicForContainer(nsRenderingContext* aRenderingContext,
  1.1149 +                                       nsIFrame* aFrame,
  1.1150 +                                       IntrinsicWidthType aType,
  1.1151 +                                       uint32_t aFlags = 0);
  1.1152 +
  1.1153 +  /*
  1.1154 +   * Convert nsStyleCoord to nscoord when percentages depend on the
  1.1155 +   * containing block size.
  1.1156 +   * @param aPercentBasis The width or height of the containing block
  1.1157 +   * (whichever the client wants to use for resolving percentages).
  1.1158 +   */
  1.1159 +  static nscoord ComputeCBDependentValue(nscoord aPercentBasis,
  1.1160 +                                         const nsStyleCoord& aCoord);
  1.1161 +
  1.1162 +  /*
  1.1163 +   * Convert nsStyleCoord to nscoord when percentages depend on the
  1.1164 +   * containing block width, and enumerated values are for width,
  1.1165 +   * min-width, or max-width.  Returns the content-box width value based
  1.1166 +   * on aContentEdgeToBoxSizing and aBoxSizingToMarginEdge (which are
  1.1167 +   * also used for the enumerated values for width.  This function does
  1.1168 +   * not handle 'auto'.  It ensures that the result is nonnegative.
  1.1169 +   *
  1.1170 +   * @param aRenderingContext Rendering context for font measurement/metrics.
  1.1171 +   * @param aFrame Frame whose (min-/max-/)width is being computed
  1.1172 +   * @param aContainingBlockWidth Width of aFrame's containing block.
  1.1173 +   * @param aContentEdgeToBoxSizing The sum of any left/right padding and
  1.1174 +   *          border that goes inside the rect chosen by box-sizing.
  1.1175 +   * @param aBoxSizingToMarginEdge The sum of any left/right padding, border,
  1.1176 +   *          and margin that goes outside the rect chosen by box-sizing.
  1.1177 +   * @param aCoord The width value to compute.
  1.1178 +   */
  1.1179 +  static nscoord ComputeWidthValue(
  1.1180 +                   nsRenderingContext* aRenderingContext,
  1.1181 +                   nsIFrame*            aFrame,
  1.1182 +                   nscoord              aContainingBlockWidth,
  1.1183 +                   nscoord              aContentEdgeToBoxSizing,
  1.1184 +                   nscoord              aBoxSizingToMarginEdge,
  1.1185 +                   const nsStyleCoord&  aCoord);
  1.1186 +
  1.1187 +  /*
  1.1188 +   * Convert nsStyleCoord to nscoord when percentages depend on the
  1.1189 +   * containing block height.
  1.1190 +   */
  1.1191 +  static nscoord ComputeHeightDependentValue(
  1.1192 +                   nscoord              aContainingBlockHeight,
  1.1193 +                   const nsStyleCoord&  aCoord);
  1.1194 +
  1.1195 +  /*
  1.1196 +   * Likewise, but for 'height', 'min-height', or 'max-height'.
  1.1197 +   */
  1.1198 +  static nscoord ComputeHeightValue(nscoord aContainingBlockHeight,
  1.1199 +                                    nscoord aContentEdgeToBoxSizingBoxEdge,
  1.1200 +                                    const nsStyleCoord& aCoord)
  1.1201 +  {
  1.1202 +    MOZ_ASSERT(aContainingBlockHeight != nscoord_MAX || !aCoord.HasPercent(),
  1.1203 +               "caller must deal with %% of unconstrained height");
  1.1204 +    MOZ_ASSERT(aCoord.IsCoordPercentCalcUnit());
  1.1205 +
  1.1206 +    nscoord result =
  1.1207 +      nsRuleNode::ComputeCoordPercentCalc(aCoord, aContainingBlockHeight);
  1.1208 +    // Clamp calc(), and the subtraction for box-sizing.
  1.1209 +    return std::max(0, result - aContentEdgeToBoxSizingBoxEdge);
  1.1210 +  }
  1.1211 +
  1.1212 +  static bool IsAutoHeight(const nsStyleCoord &aCoord, nscoord aCBHeight)
  1.1213 +  {
  1.1214 +    nsStyleUnit unit = aCoord.GetUnit();
  1.1215 +    return unit == eStyleUnit_Auto ||  // only for 'height'
  1.1216 +           unit == eStyleUnit_None ||  // only for 'max-height'
  1.1217 +           (aCBHeight == nscoord_MAX && aCoord.HasPercent());
  1.1218 +  }
  1.1219 +
  1.1220 +  static bool IsPaddingZero(const nsStyleCoord &aCoord)
  1.1221 +  {
  1.1222 +    return (aCoord.GetUnit() == eStyleUnit_Coord &&
  1.1223 +            aCoord.GetCoordValue() == 0) ||
  1.1224 +           (aCoord.GetUnit() == eStyleUnit_Percent &&
  1.1225 +            aCoord.GetPercentValue() == 0.0f) ||
  1.1226 +           (aCoord.IsCalcUnit() &&
  1.1227 +            // clamp negative calc() to 0
  1.1228 +            nsRuleNode::ComputeCoordPercentCalc(aCoord, nscoord_MAX) <= 0 &&
  1.1229 +            nsRuleNode::ComputeCoordPercentCalc(aCoord, 0) <= 0);
  1.1230 +  }
  1.1231 +
  1.1232 +  static bool IsMarginZero(const nsStyleCoord &aCoord)
  1.1233 +  {
  1.1234 +    return (aCoord.GetUnit() == eStyleUnit_Coord &&
  1.1235 +            aCoord.GetCoordValue() == 0) ||
  1.1236 +           (aCoord.GetUnit() == eStyleUnit_Percent &&
  1.1237 +            aCoord.GetPercentValue() == 0.0f) ||
  1.1238 +           (aCoord.IsCalcUnit() &&
  1.1239 +            nsRuleNode::ComputeCoordPercentCalc(aCoord, nscoord_MAX) == 0 &&
  1.1240 +            nsRuleNode::ComputeCoordPercentCalc(aCoord, 0) == 0);
  1.1241 +  }
  1.1242 +
  1.1243 +  static void MarkDescendantsDirty(nsIFrame *aSubtreeRoot);
  1.1244 +
  1.1245 +  /*
  1.1246 +   * Calculate the used values for 'width' and 'height' for a replaced element.
  1.1247 +   *
  1.1248 +   *   http://www.w3.org/TR/CSS21/visudet.html#min-max-widths
  1.1249 +   */
  1.1250 +  static nsSize ComputeSizeWithIntrinsicDimensions(
  1.1251 +                    nsRenderingContext* aRenderingContext, nsIFrame* aFrame,
  1.1252 +                    const mozilla::IntrinsicSize& aIntrinsicSize,
  1.1253 +                    nsSize aIntrinsicRatio, nsSize aCBSize,
  1.1254 +                    nsSize aMargin, nsSize aBorder, nsSize aPadding);
  1.1255 +
  1.1256 +  /*
  1.1257 +   * Calculate the used values for 'width' and 'height' when width
  1.1258 +   * and height are 'auto'. The tentWidth and tentHeight arguments should be
  1.1259 +   * the result of applying the rules for computing intrinsic sizes and ratios.
  1.1260 +   * as specified by CSS 2.1 sections 10.3.2 and 10.6.2
  1.1261 +   */
  1.1262 +  static nsSize ComputeAutoSizeWithIntrinsicDimensions(nscoord minWidth, nscoord minHeight,
  1.1263 +                                                       nscoord maxWidth, nscoord maxHeight,
  1.1264 +                                                       nscoord tentWidth, nscoord tentHeight);
  1.1265 +
  1.1266 +  // Implement nsIFrame::GetPrefWidth in terms of nsIFrame::AddInlinePrefWidth
  1.1267 +  static nscoord PrefWidthFromInline(nsIFrame* aFrame,
  1.1268 +                                     nsRenderingContext* aRenderingContext);
  1.1269 +
  1.1270 +  // Implement nsIFrame::GetMinWidth in terms of nsIFrame::AddInlineMinWidth
  1.1271 +  static nscoord MinWidthFromInline(nsIFrame* aFrame,
  1.1272 +                                    nsRenderingContext* aRenderingContext);
  1.1273 +
  1.1274 +  // Get a suitable foreground color for painting aProperty for aFrame.
  1.1275 +  static nscolor GetColor(nsIFrame* aFrame, nsCSSProperty aProperty);
  1.1276 +
  1.1277 +  // Get the native text color if appropriate.  If false is returned, callers
  1.1278 +  // should fallback to the CSS color.
  1.1279 +  static bool GetNativeTextColor(nsIFrame* aFrame, nscolor& aColor);
  1.1280 +
  1.1281 +  // Get a baseline y position in app units that is snapped to device pixels.
  1.1282 +  static gfxFloat GetSnappedBaselineY(nsIFrame* aFrame, gfxContext* aContext,
  1.1283 +                                      nscoord aY, nscoord aAscent);
  1.1284 +
  1.1285 +  static void DrawString(const nsIFrame*       aFrame,
  1.1286 +                         nsRenderingContext*   aContext,
  1.1287 +                         const char16_t*      aString,
  1.1288 +                         int32_t               aLength,
  1.1289 +                         nsPoint               aPoint,
  1.1290 +                         nsStyleContext*       aStyleContext = nullptr);
  1.1291 +
  1.1292 +  static nscoord GetStringWidth(const nsIFrame*      aFrame,
  1.1293 +                                nsRenderingContext* aContext,
  1.1294 +                                const char16_t*     aString,
  1.1295 +                                int32_t              aLength);
  1.1296 +
  1.1297 +  /**
  1.1298 +   * Helper function for drawing text-shadow. The callback's job
  1.1299 +   * is to draw whatever needs to be blurred onto the given context.
  1.1300 +   */
  1.1301 +  typedef void (* TextShadowCallback)(nsRenderingContext* aCtx,
  1.1302 +                                      nsPoint aShadowOffset,
  1.1303 +                                      const nscolor& aShadowColor,
  1.1304 +                                      void* aData);
  1.1305 +
  1.1306 +  static void PaintTextShadow(const nsIFrame*     aFrame,
  1.1307 +                              nsRenderingContext* aContext,
  1.1308 +                              const nsRect&       aTextRect,
  1.1309 +                              const nsRect&       aDirtyRect,
  1.1310 +                              const nscolor&      aForegroundColor,
  1.1311 +                              TextShadowCallback  aCallback,
  1.1312 +                              void*               aCallbackData);
  1.1313 +
  1.1314 +  /**
  1.1315 +   * Gets the baseline to vertically center text from a font within a
  1.1316 +   * line of specified height.
  1.1317 +   *
  1.1318 +   * Returns the baseline position relative to the top of the line.
  1.1319 +   */
  1.1320 +  static nscoord GetCenteredFontBaseline(nsFontMetrics* aFontMetrics,
  1.1321 +                                         nscoord         aLineHeight);
  1.1322 +
  1.1323 +  /**
  1.1324 +   * Derive a baseline of |aFrame| (measured from its top border edge)
  1.1325 +   * from its first in-flow line box (not descending into anything with
  1.1326 +   * 'overflow' not 'visible', potentially including aFrame itself).
  1.1327 +   *
  1.1328 +   * Returns true if a baseline was found (and fills in aResult).
  1.1329 +   * Otherwise returns false.
  1.1330 +   */
  1.1331 +  static bool GetFirstLineBaseline(const nsIFrame* aFrame, nscoord* aResult);
  1.1332 +
  1.1333 +  /**
  1.1334 +   * Just like GetFirstLineBaseline, except also returns the top and
  1.1335 +   * bottom of the line with the baseline.
  1.1336 +   *
  1.1337 +   * Returns true if a line was found (and fills in aResult).
  1.1338 +   * Otherwise returns false.
  1.1339 +   */
  1.1340 +  struct LinePosition {
  1.1341 +    nscoord mTop, mBaseline, mBottom;
  1.1342 +
  1.1343 +    LinePosition operator+(nscoord aOffset) const {
  1.1344 +      LinePosition result;
  1.1345 +      result.mTop = mTop + aOffset;
  1.1346 +      result.mBaseline = mBaseline + aOffset;
  1.1347 +      result.mBottom = mBottom + aOffset;
  1.1348 +      return result;
  1.1349 +    }
  1.1350 +  };
  1.1351 +  static bool GetFirstLinePosition(const nsIFrame* aFrame,
  1.1352 +                                   LinePosition* aResult);
  1.1353 +
  1.1354 +
  1.1355 +  /**
  1.1356 +   * Derive a baseline of |aFrame| (measured from its top border edge)
  1.1357 +   * from its last in-flow line box (not descending into anything with
  1.1358 +   * 'overflow' not 'visible', potentially including aFrame itself).
  1.1359 +   *
  1.1360 +   * Returns true if a baseline was found (and fills in aResult).
  1.1361 +   * Otherwise returns false.
  1.1362 +   */
  1.1363 +  static bool GetLastLineBaseline(const nsIFrame* aFrame, nscoord* aResult);
  1.1364 +
  1.1365 +  /**
  1.1366 +   * Returns a y coordinate relative to this frame's origin that represents
  1.1367 +   * the logical bottom of the frame or its visible content, whichever is lower.
  1.1368 +   * Relative positioning is ignored and margins and glyph bounds are not
  1.1369 +   * considered.
  1.1370 +   * This value will be >= mRect.height() and <= overflowRect.YMost() unless
  1.1371 +   * relative positioning is applied.
  1.1372 +   */
  1.1373 +  static nscoord CalculateContentBottom(nsIFrame* aFrame);
  1.1374 +
  1.1375 +  /**
  1.1376 +   * Gets the closest frame (the frame passed in or one of its parents) that
  1.1377 +   * qualifies as a "layer"; used in DOM0 methods that depends upon that
  1.1378 +   * definition. This is the nearest frame that is either positioned or scrolled
  1.1379 +   * (the child of a scroll frame).
  1.1380 +   */
  1.1381 +  static nsIFrame* GetClosestLayer(nsIFrame* aFrame);
  1.1382 +
  1.1383 +  /**
  1.1384 +   * Gets the graphics filter for the frame
  1.1385 +   */
  1.1386 +  static GraphicsFilter GetGraphicsFilterForFrame(nsIFrame* aFrame);
  1.1387 +
  1.1388 +  /* N.B. The only difference between variants of the Draw*Image
  1.1389 +   * functions below is the type of the aImage argument.
  1.1390 +   */
  1.1391 +
  1.1392 +  /**
  1.1393 +   * Draw a background image.  The image's dimensions are as specified in aDest;
  1.1394 +   * the image itself is not consulted to determine a size.
  1.1395 +   * See https://wiki.mozilla.org/Gecko:Image_Snapping_and_Rendering
  1.1396 +   *   @param aRenderingContext Where to draw the image, set up with an
  1.1397 +   *                            appropriate scale and transform for drawing in
  1.1398 +   *                            app units.
  1.1399 +   *   @param aImage            The image.
  1.1400 +   *   @param aImageSize        The unscaled size of the image being drawn.
  1.1401 +   *                            (This might be the image's size if no scaling
  1.1402 +   *                            occurs, or it might be the image's size if
  1.1403 +   *                            the image is a vector image being rendered at
  1.1404 +   *                            that size.)
  1.1405 +   *   @param aDest             The position and scaled area where one copy of
  1.1406 +   *                            the image should be drawn.
  1.1407 +   *   @param aFill             The area to be filled with copies of the
  1.1408 +   *                            image.
  1.1409 +   *   @param aAnchor           A point in aFill which we will ensure is
  1.1410 +   *                            pixel-aligned in the output.
  1.1411 +   *   @param aDirty            Pixels outside this area may be skipped.
  1.1412 +   *   @param aImageFlags       Image flags of the imgIContainer::FLAG_* variety
  1.1413 +   */
  1.1414 +  static nsresult DrawBackgroundImage(nsRenderingContext* aRenderingContext,
  1.1415 +                                      imgIContainer*      aImage,
  1.1416 +                                      const nsIntSize&    aImageSize,
  1.1417 +                                      GraphicsFilter      aGraphicsFilter,
  1.1418 +                                      const nsRect&       aDest,
  1.1419 +                                      const nsRect&       aFill,
  1.1420 +                                      const nsPoint&      aAnchor,
  1.1421 +                                      const nsRect&       aDirty,
  1.1422 +                                      uint32_t            aImageFlags);
  1.1423 +
  1.1424 +  /**
  1.1425 +   * Draw an image.
  1.1426 +   * See https://wiki.mozilla.org/Gecko:Image_Snapping_and_Rendering
  1.1427 +   *   @param aRenderingContext Where to draw the image, set up with an
  1.1428 +   *                            appropriate scale and transform for drawing in
  1.1429 +   *                            app units.
  1.1430 +   *   @param aImage            The image.
  1.1431 +   *   @param aDest             Where one copy of the image should mapped to.
  1.1432 +   *   @param aFill             The area to be filled with copies of the
  1.1433 +   *                            image.
  1.1434 +   *   @param aAnchor           A point in aFill which we will ensure is
  1.1435 +   *                            pixel-aligned in the output.
  1.1436 +   *   @param aDirty            Pixels outside this area may be skipped.
  1.1437 +   *   @param aImageFlags       Image flags of the imgIContainer::FLAG_* variety
  1.1438 +   */
  1.1439 +  static nsresult DrawImage(nsRenderingContext* aRenderingContext,
  1.1440 +                            imgIContainer*       aImage,
  1.1441 +                            GraphicsFilter       aGraphicsFilter,
  1.1442 +                            const nsRect&        aDest,
  1.1443 +                            const nsRect&        aFill,
  1.1444 +                            const nsPoint&       aAnchor,
  1.1445 +                            const nsRect&        aDirty,
  1.1446 +                            uint32_t             aImageFlags);
  1.1447 +
  1.1448 +  /**
  1.1449 +   * Convert an nsRect to a gfxRect.
  1.1450 +   */
  1.1451 +  static gfxRect RectToGfxRect(const nsRect& aRect,
  1.1452 +                               int32_t aAppUnitsPerDevPixel);
  1.1453 +
  1.1454 +  /**
  1.1455 +   * Draw a drawable using the pixel snapping algorithm.
  1.1456 +   * See https://wiki.mozilla.org/Gecko:Image_Snapping_and_Rendering
  1.1457 +   *   @param aRenderingContext Where to draw the image, set up with an
  1.1458 +   *                            appropriate scale and transform for drawing in
  1.1459 +   *                            app units.
  1.1460 +   *   @param aDrawable         The drawable we want to draw.
  1.1461 +   *   @param aFilter           The graphics filter we should draw with.
  1.1462 +   *   @param aDest             Where one copy of the image should mapped to.
  1.1463 +   *   @param aFill             The area to be filled with copies of the
  1.1464 +   *                            image.
  1.1465 +   *   @param aAnchor           A point in aFill which we will ensure is
  1.1466 +   *                            pixel-aligned in the output.
  1.1467 +   *   @param aDirty            Pixels outside this area may be skipped.
  1.1468 +   */
  1.1469 +  static void DrawPixelSnapped(nsRenderingContext* aRenderingContext,
  1.1470 +                               gfxDrawable*         aDrawable,
  1.1471 +                               GraphicsFilter       aFilter,
  1.1472 +                               const nsRect&        aDest,
  1.1473 +                               const nsRect&        aFill,
  1.1474 +                               const nsPoint&       aAnchor,
  1.1475 +                               const nsRect&        aDirty);
  1.1476 +
  1.1477 +  /**
  1.1478 +   * Draw a whole image without scaling or tiling.
  1.1479 +   *
  1.1480 +   *   @param aRenderingContext Where to draw the image, set up with an
  1.1481 +   *                            appropriate scale and transform for drawing in
  1.1482 +   *                            app units.
  1.1483 +   *   @param aImage            The image.
  1.1484 +   *   @param aDest             The top-left where the image should be drawn
  1.1485 +   *   @param aDirty            If non-null, then pixels outside this area may
  1.1486 +   *                            be skipped.
  1.1487 +   *   @param aImageFlags       Image flags of the imgIContainer::FLAG_* variety
  1.1488 +   *   @param aSourceArea       If non-null, this area is extracted from
  1.1489 +   *                            the image and drawn at aDest. It's
  1.1490 +   *                            in appunits. For best results it should
  1.1491 +   *                            be aligned with image pixels.
  1.1492 +   */
  1.1493 +  static nsresult DrawSingleUnscaledImage(nsRenderingContext* aRenderingContext,
  1.1494 +                                          imgIContainer*       aImage,
  1.1495 +                                          GraphicsFilter       aGraphicsFilter,
  1.1496 +                                          const nsPoint&       aDest,
  1.1497 +                                          const nsRect*        aDirty,
  1.1498 +                                          uint32_t             aImageFlags,
  1.1499 +                                          const nsRect*        aSourceArea = nullptr);
  1.1500 +
  1.1501 +  /**
  1.1502 +   * Draw a whole image without tiling.
  1.1503 +   *
  1.1504 +   *   @param aRenderingContext Where to draw the image, set up with an
  1.1505 +   *                            appropriate scale and transform for drawing in
  1.1506 +   *                            app units.
  1.1507 +   *   @param aImage            The image.
  1.1508 +   *   @param aDest             The area that the image should fill
  1.1509 +   *   @param aDirty            Pixels outside this area may be skipped.
  1.1510 +   *   @param aSVGContext       If non-null, SVG-related rendering context
  1.1511 +   *                            such as overridden attributes on the image
  1.1512 +   *                            document's root <svg> node. Ignored for
  1.1513 +   *                            raster images.
  1.1514 +   *   @param aImageFlags       Image flags of the imgIContainer::FLAG_*
  1.1515 +   *                            variety.
  1.1516 +   *   @param aSourceArea       If non-null, this area is extracted from
  1.1517 +   *                            the image and drawn in aDest. It's
  1.1518 +   *                            in appunits. For best results it should
  1.1519 +   *                            be aligned with image pixels.
  1.1520 +   */
  1.1521 +  static nsresult DrawSingleImage(nsRenderingContext*    aRenderingContext,
  1.1522 +                                  imgIContainer*         aImage,
  1.1523 +                                  GraphicsFilter         aGraphicsFilter,
  1.1524 +                                  const nsRect&          aDest,
  1.1525 +                                  const nsRect&          aDirty,
  1.1526 +                                  const mozilla::SVGImageContext* aSVGContext,
  1.1527 +                                  uint32_t               aImageFlags,
  1.1528 +                                  const nsRect*          aSourceArea = nullptr);
  1.1529 +
  1.1530 +  /**
  1.1531 +   * Given an imgIContainer, this method attempts to obtain an intrinsic
  1.1532 +   * px-valued height & width for it.  If the imgIContainer has a non-pixel
  1.1533 +   * value for either height or width, this method tries to generate a pixel
  1.1534 +   * value for that dimension using the intrinsic ratio (if available).  The
  1.1535 +   * intrinsic ratio will be assigned to aIntrinsicRatio; if there's no
  1.1536 +   * intrinsic ratio then (0, 0) will be assigned.
  1.1537 +   *
  1.1538 +   * This method will always set aGotWidth and aGotHeight to indicate whether
  1.1539 +   * we were able to successfully obtain (or compute) a value for each
  1.1540 +   * dimension.
  1.1541 +   *
  1.1542 +   * NOTE: This method is similar to ComputeSizeWithIntrinsicDimensions.  The
  1.1543 +   * difference is that this one is simpler and is suited to places where we
  1.1544 +   * have less information about the frame tree.
  1.1545 +   */
  1.1546 +  static void ComputeSizeForDrawing(imgIContainer* aImage,
  1.1547 +                                    nsIntSize&     aImageSize,
  1.1548 +                                    nsSize&        aIntrinsicRatio,
  1.1549 +                                    bool&          aGotWidth,
  1.1550 +                                    bool&          aGotHeight);
  1.1551 +
  1.1552 +  /**
  1.1553 +   * Given a source area of an image (in appunits) and a destination area
  1.1554 +   * that we want to map that source area too, computes the area that
  1.1555 +   * would be covered by the whole image. This is useful for passing to
  1.1556 +   * the aDest parameter of DrawImage, when we want to draw a subimage
  1.1557 +   * of an overall image.
  1.1558 +   */
  1.1559 +  static nsRect GetWholeImageDestination(const nsIntSize& aWholeImageSize,
  1.1560 +                                         const nsRect& aImageSourceArea,
  1.1561 +                                         const nsRect& aDestArea);
  1.1562 +
  1.1563 +  /**
  1.1564 +   * Given an image container and an orientation, returns an image container
  1.1565 +   * that contains the same image, reoriented appropriately. May return the
  1.1566 +   * original image container if no changes are needed.
  1.1567 +   *
  1.1568 +   * @param aContainer   The image container to apply the orientation to.
  1.1569 +   * @param aOrientation The desired orientation.
  1.1570 +   */
  1.1571 +  static already_AddRefed<imgIContainer>
  1.1572 +  OrientImage(imgIContainer* aContainer,
  1.1573 +              const nsStyleImageOrientation& aOrientation);
  1.1574 +
  1.1575 +  /**
  1.1576 +   * Determine if any corner radius is of nonzero size
  1.1577 +   *   @param aCorners the |nsStyleCorners| object to check
  1.1578 +   *   @return true unless all the coordinates are 0%, 0 or null.
  1.1579 +   *
  1.1580 +   * A corner radius with one dimension zero and one nonzero is
  1.1581 +   * treated as a nonzero-radius corner, even though it will end up
  1.1582 +   * being rendered like a zero-radius corner.  This is because such
  1.1583 +   * corners are not expected to appear outside of test cases, and it's
  1.1584 +   * simpler to implement the test this way.
  1.1585 +   */
  1.1586 +  static bool HasNonZeroCorner(const nsStyleCorners& aCorners);
  1.1587 +
  1.1588 +  /**
  1.1589 +   * Determine if there is any corner radius on corners adjacent to the
  1.1590 +   * given side.
  1.1591 +   */
  1.1592 +  static bool HasNonZeroCornerOnSide(const nsStyleCorners& aCorners,
  1.1593 +                                       mozilla::css::Side aSide);
  1.1594 +
  1.1595 +  /**
  1.1596 +   * Determine if a widget is likely to require transparency or translucency.
  1.1597 +   *   @param aBackgroundFrame The frame that the background is set on. For
  1.1598 +   *                           <window>s, this will be the canvas frame.
  1.1599 +   *   @param aCSSRootFrame    The frame that holds CSS properties affecting
  1.1600 +   *                           the widget's transparency. For menupopups,
  1.1601 +   *                           aBackgroundFrame and aCSSRootFrame will be the
  1.1602 +   *                           same.
  1.1603 +   *   @return a value suitable for passing to SetWindowTranslucency
  1.1604 +   */
  1.1605 +  static nsTransparencyMode GetFrameTransparency(nsIFrame* aBackgroundFrame,
  1.1606 +                                                 nsIFrame* aCSSRootFrame);
  1.1607 +
  1.1608 +  /**
  1.1609 +   * A frame is a popup if it has its own floating window. Menus, panels
  1.1610 +   * and combobox dropdowns are popups.
  1.1611 +   */
  1.1612 +  static bool IsPopup(nsIFrame* aFrame);
  1.1613 +
  1.1614 +  /**
  1.1615 +   * Find the nearest "display root". This is the nearest enclosing
  1.1616 +   * popup frame or the root prescontext's root frame.
  1.1617 +   */
  1.1618 +  static nsIFrame* GetDisplayRootFrame(nsIFrame* aFrame);
  1.1619 +
  1.1620 +  /**
  1.1621 +   * Get the reference frame that would be used when constructing a
  1.1622 +   * display item for this frame.  (Note, however, that
  1.1623 +   * nsDisplayTransform use the reference frame appropriate for their
  1.1624 +   * GetTransformRootFrame(), rather than using their own frame as a
  1.1625 +   * reference frame.)
  1.1626 +   *
  1.1627 +   * This duplicates some of the logic of GetDisplayRootFrame above and
  1.1628 +   * of nsDisplayListBuilder::FindReferenceFrameFor.
  1.1629 +   *
  1.1630 +   * If you have an nsDisplayListBuilder, you should get the reference
  1.1631 +   * frame from it instead of calling this.
  1.1632 +   */
  1.1633 +  static nsIFrame* GetReferenceFrame(nsIFrame* aFrame);
  1.1634 +
  1.1635 +  /**
  1.1636 +   * Get the parent of this frame, except if that parent is part of a
  1.1637 +   * preserve-3d hierarchy, get the parent of the root of the
  1.1638 +   * preserve-3d hierarchy.
  1.1639 +   *
  1.1640 +   * (This is used as the starting point for reference frame computation
  1.1641 +   * for nsDisplayTransform display items.)
  1.1642 +   */
  1.1643 +  static nsIFrame* GetTransformRootFrame(nsIFrame* aFrame);
  1.1644 +
  1.1645 +  /**
  1.1646 +   * Get textrun construction flags determined by a given style; in particular
  1.1647 +   * some combination of:
  1.1648 +   * -- TEXT_DISABLE_OPTIONAL_LIGATURES if letter-spacing is in use
  1.1649 +   * -- TEXT_OPTIMIZE_SPEED if the text-rendering CSS property and font size
  1.1650 +   * and prefs indicate we should be optimizing for speed over quality
  1.1651 +   */
  1.1652 +  static uint32_t GetTextRunFlagsForStyle(nsStyleContext* aStyleContext,
  1.1653 +                                          const nsStyleFont* aStyleFont,
  1.1654 +                                          const nsStyleText* aStyleText,
  1.1655 +                                          nscoord aLetterSpacing);
  1.1656 +
  1.1657 +  /**
  1.1658 +   * Takes two rectangles whose origins must be the same, and computes
  1.1659 +   * the difference between their union and their intersection as two
  1.1660 +   * rectangles. (This difference is a superset of the difference
  1.1661 +   * between the two rectangles.)
  1.1662 +   */
  1.1663 +  static void GetRectDifferenceStrips(const nsRect& aR1, const nsRect& aR2,
  1.1664 +                                      nsRect* aHStrip, nsRect* aVStrip);
  1.1665 +
  1.1666 +  /**
  1.1667 +   * Get a device context that can be used to get up-to-date device
  1.1668 +   * dimensions for the given window. For some reason, this is more
  1.1669 +   * complicated than it ought to be in multi-monitor situations.
  1.1670 +   */
  1.1671 +  static nsDeviceContext*
  1.1672 +  GetDeviceContextForScreenInfo(nsPIDOMWindow* aWindow);
  1.1673 +
  1.1674 +  /**
  1.1675 +   * Some frames with 'position: fixed' (nsStylePosition::mDisplay ==
  1.1676 +   * NS_STYLE_POSITION_FIXED) are not really fixed positioned, since
  1.1677 +   * they're inside an element with -moz-transform.  This function says
  1.1678 +   * whether such an element is a real fixed-pos element.
  1.1679 +   */
  1.1680 +  static bool IsReallyFixedPos(nsIFrame* aFrame);
  1.1681 +
  1.1682 +  /**
  1.1683 +   * Obtain a gfxASurface from the given DOM element, if possible.
  1.1684 +   * This obtains the most natural surface from the element; that
  1.1685 +   * is, the one that can be obtained with the fewest conversions.
  1.1686 +   *
  1.1687 +   * The flags below can modify the behaviour of this function.  The
  1.1688 +   * result is returned as a SurfaceFromElementResult struct, also
  1.1689 +   * defined below.
  1.1690 +   *
  1.1691 +   * Currently, this will do:
  1.1692 +   *  - HTML Canvas elements: will return the underlying canvas surface
  1.1693 +   *  - HTML Video elements: will return the current video frame
  1.1694 +   *  - Image elements: will return the image
  1.1695 +   *
  1.1696 +   * The above results are modified by the below flags (copying,
  1.1697 +   * forcing image surface, etc.).
  1.1698 +   */
  1.1699 +
  1.1700 +  enum {
  1.1701 +    /* When creating a new surface, create an image surface */
  1.1702 +    SFE_WANT_IMAGE_SURFACE = 1 << 0,
  1.1703 +    /* Whether to extract the first frame (as opposed to the
  1.1704 +       current frame) in the case that the element is an image. */
  1.1705 +    SFE_WANT_FIRST_FRAME = 1 << 1,
  1.1706 +    /* Whether we should skip colorspace/gamma conversion */
  1.1707 +    SFE_NO_COLORSPACE_CONVERSION = 1 << 2,
  1.1708 +    /* Specifies that the caller wants unpremultiplied pixel data.
  1.1709 +       If this is can be done efficiently, the result will be a
  1.1710 +       DataSourceSurface and mIsPremultiplied with be set to false. */
  1.1711 +    SFE_PREFER_NO_PREMULTIPLY_ALPHA = 1 << 3,
  1.1712 +    /* Whether we should skip getting a surface for vector images and
  1.1713 +       return a DirectDrawInfo containing an imgIContainer instead. */
  1.1714 +    SFE_NO_RASTERIZING_VECTORS = 1 << 4
  1.1715 +  };
  1.1716 +
  1.1717 +  struct DirectDrawInfo {
  1.1718 +    /* imgIContainer to directly draw to a context */
  1.1719 +    nsCOMPtr<imgIContainer> mImgContainer;
  1.1720 +    /* which frame to draw */
  1.1721 +    uint32_t mWhichFrame;
  1.1722 +    /* imgIContainer flags to use when drawing */
  1.1723 +    uint32_t mDrawingFlags;
  1.1724 +  };
  1.1725 +
  1.1726 +  struct SurfaceFromElementResult {
  1.1727 +    SurfaceFromElementResult();
  1.1728 +
  1.1729 +    /* mSurface will contain the resulting surface, or will be nullptr on error */
  1.1730 +    nsRefPtr<gfxASurface> mSurface;
  1.1731 +    mozilla::RefPtr<SourceSurface> mSourceSurface;
  1.1732 +    /* Contains info for drawing when there is no mSourceSurface. */
  1.1733 +    DirectDrawInfo mDrawInfo;
  1.1734 +
  1.1735 +    /* The size of the surface */
  1.1736 +    gfxIntSize mSize;
  1.1737 +    /* The principal associated with the element whose surface was returned.
  1.1738 +       If there is a surface, this will never be null. */
  1.1739 +    nsCOMPtr<nsIPrincipal> mPrincipal;
  1.1740 +    /* The image request, if the element is an nsIImageLoadingContent */
  1.1741 +    nsCOMPtr<imgIRequest> mImageRequest;
  1.1742 +    /* Whether the element was "write only", that is, the bits should not be exposed to content */
  1.1743 +    bool mIsWriteOnly;
  1.1744 +    /* Whether the element was still loading.  Some consumers need to handle
  1.1745 +       this case specially. */
  1.1746 +    bool mIsStillLoading;
  1.1747 +    /* Whether the element used CORS when loading. */
  1.1748 +    bool mCORSUsed;
  1.1749 +    /* Whether the returned image contains premultiplied pixel data */
  1.1750 +    bool mIsPremultiplied;
  1.1751 +  };
  1.1752 +
  1.1753 +  static SurfaceFromElementResult SurfaceFromElement(mozilla::dom::Element *aElement,
  1.1754 +                                                     uint32_t aSurfaceFlags = 0,
  1.1755 +                                                     DrawTarget *aTarget = nullptr);
  1.1756 +  static SurfaceFromElementResult SurfaceFromElement(nsIImageLoadingContent *aElement,
  1.1757 +                                                     uint32_t aSurfaceFlags = 0,
  1.1758 +                                                     DrawTarget *aTarget = nullptr);
  1.1759 +  // Need an HTMLImageElement overload, because otherwise the
  1.1760 +  // nsIImageLoadingContent and mozilla::dom::Element overloads are ambiguous
  1.1761 +  // for HTMLImageElement.
  1.1762 +  static SurfaceFromElementResult SurfaceFromElement(mozilla::dom::HTMLImageElement *aElement,
  1.1763 +                                                     uint32_t aSurfaceFlags = 0,
  1.1764 +                                                     DrawTarget *aTarget = nullptr);
  1.1765 +  static SurfaceFromElementResult SurfaceFromElement(mozilla::dom::HTMLCanvasElement *aElement,
  1.1766 +                                                     uint32_t aSurfaceFlags = 0,
  1.1767 +                                                     DrawTarget *aTarget = nullptr);
  1.1768 +  static SurfaceFromElementResult SurfaceFromElement(mozilla::dom::HTMLVideoElement *aElement,
  1.1769 +                                                     uint32_t aSurfaceFlags = 0,
  1.1770 +                                                     DrawTarget *aTarget = nullptr);
  1.1771 +
  1.1772 +  /**
  1.1773 +   * When the document is editable by contenteditable attribute of its root
  1.1774 +   * content or body content.
  1.1775 +   *
  1.1776 +   * Be aware, this returns nullptr if it's in designMode.
  1.1777 +   *
  1.1778 +   * For example:
  1.1779 +   *
  1.1780 +   *  <html contenteditable="true"><body></body></html>
  1.1781 +   *    returns the <html>.
  1.1782 +   *
  1.1783 +   *  <html><body contenteditable="true"></body></html>
  1.1784 +   *  <body contenteditable="true"></body>
  1.1785 +   *    With these cases, this returns the <body>.
  1.1786 +   *    NOTE: The latter case isn't created normally, however, it can be
  1.1787 +   *          created by script with XHTML.
  1.1788 +   *
  1.1789 +   *  <body><p contenteditable="true"></p></body>
  1.1790 +   *    returns nullptr because <body> isn't editable.
  1.1791 +   */
  1.1792 +  static nsIContent*
  1.1793 +    GetEditableRootContentByContentEditable(nsIDocument* aDocument);
  1.1794 +
  1.1795 +  /**
  1.1796 +   * Returns true if the passed in prescontext needs the dark grey background
  1.1797 +   * that goes behind the page of a print preview presentation.
  1.1798 +   */
  1.1799 +  static bool NeedsPrintPreviewBackground(nsPresContext* aPresContext);
  1.1800 +
  1.1801 +  /**
  1.1802 +   * Adds all font faces used in the frame tree starting from aFrame
  1.1803 +   * to the list aFontFaceList.
  1.1804 +   */
  1.1805 +  static nsresult GetFontFacesForFrames(nsIFrame* aFrame,
  1.1806 +                                        nsFontFaceList* aFontFaceList);
  1.1807 +
  1.1808 +  /**
  1.1809 +   * Adds all font faces used within the specified range of text in aFrame,
  1.1810 +   * and optionally its continuations, to the list in aFontFaceList.
  1.1811 +   * Pass 0 and INT32_MAX for aStartOffset and aEndOffset to specify the
  1.1812 +   * entire text is to be considered.
  1.1813 +   */
  1.1814 +  static nsresult GetFontFacesForText(nsIFrame* aFrame,
  1.1815 +                                      int32_t aStartOffset,
  1.1816 +                                      int32_t aEndOffset,
  1.1817 +                                      bool aFollowContinuations,
  1.1818 +                                      nsFontFaceList* aFontFaceList);
  1.1819 +
  1.1820 +  /**
  1.1821 +   * Walks the frame tree starting at aFrame looking for textRuns.
  1.1822 +   * If |clear| is true, just clears the TEXT_RUN_MEMORY_ACCOUNTED flag
  1.1823 +   * on each textRun found (and |aMallocSizeOf| is not used).
  1.1824 +   * If |clear| is false, adds the storage used for each textRun to the
  1.1825 +   * total, and sets the TEXT_RUN_MEMORY_ACCOUNTED flag to avoid double-
  1.1826 +   * accounting. (Runs with this flag already set will be skipped.)
  1.1827 +   * Expected usage pattern is therefore to call twice:
  1.1828 +   *    (void)SizeOfTextRunsForFrames(rootFrame, nullptr, true);
  1.1829 +   *    total = SizeOfTextRunsForFrames(rootFrame, mallocSizeOf, false);
  1.1830 +   */
  1.1831 +  static size_t SizeOfTextRunsForFrames(nsIFrame* aFrame,
  1.1832 +                                        mozilla::MallocSizeOf aMallocSizeOf,
  1.1833 +                                        bool clear);
  1.1834 +
  1.1835 +  /**
  1.1836 +   * Returns true if the content node has animations or transitions that can be
  1.1837 +   * performed on the compositor.
  1.1838 +   */
  1.1839 +  static bool HasAnimationsForCompositor(nsIContent* aContent,
  1.1840 +                                         nsCSSProperty aProperty);
  1.1841 +
  1.1842 +  /**
  1.1843 +   * Returns true if the content node has animations or transitions for the
  1.1844 +   * property.
  1.1845 +   */
  1.1846 +  static bool HasAnimations(nsIContent* aContent, nsCSSProperty aProperty);
  1.1847 +
  1.1848 +  /**
  1.1849 +   * Checks if off-main-thread animations are enabled.
  1.1850 +   */
  1.1851 +  static bool AreAsyncAnimationsEnabled();
  1.1852 +
  1.1853 +  /**
  1.1854 +   * Checks if we should warn about animations that can't be async
  1.1855 +   */
  1.1856 +  static bool IsAnimationLoggingEnabled();
  1.1857 +
  1.1858 +  /**
  1.1859 +   * Find a suitable scale for an element (aContent) over the course of any
  1.1860 +   * animations and transitions on the element.
  1.1861 +   * It will check the maximum and minimum scale during the animations and
  1.1862 +   * transitions and return a suitable value for performance and quality.
  1.1863 +   * Will return scale(1,1) if there is no animated scaling.
  1.1864 +   * Always return positive value.
  1.1865 +   */
  1.1866 +  static gfxSize ComputeSuitableScaleForAnimation(nsIContent* aContent);
  1.1867 +
  1.1868 +  /**
  1.1869 +   * Checks if we should forcibly use nearest pixel filtering for the
  1.1870 +   * background.
  1.1871 +   */
  1.1872 +  static bool UseBackgroundNearestFiltering();
  1.1873 +
  1.1874 +  /**
  1.1875 +   * Checks whether we want to use the GPU to scale images when
  1.1876 +   * possible.
  1.1877 +   */
  1.1878 +  static bool GPUImageScalingEnabled();
  1.1879 +
  1.1880 +  /**
  1.1881 +   * Checks whether we want to layerize animated images whenever possible.
  1.1882 +   */
  1.1883 +  static bool AnimatedImageLayersEnabled();
  1.1884 +
  1.1885 +  /**
  1.1886 +   * Checks if we should enable parsing for CSS Filters.
  1.1887 +   */
  1.1888 +  static bool CSSFiltersEnabled();
  1.1889 +
  1.1890 +  /**
  1.1891 +   * Checks whether support for the CSS-wide "unset" value is enabled.
  1.1892 +   */
  1.1893 +  static bool UnsetValueEnabled();
  1.1894 +
  1.1895 +  /**
  1.1896 +   * Checks whether support for the CSS text-align (and -moz-text-align-last)
  1.1897 +   * 'true' value is enabled.
  1.1898 +   */
  1.1899 +  static bool IsTextAlignTrueValueEnabled();
  1.1900 +
  1.1901 +  /**
  1.1902 +   * Checks if CSS variables are currently enabled.
  1.1903 +   */
  1.1904 +  static bool CSSVariablesEnabled()
  1.1905 +  {
  1.1906 +    return sCSSVariablesEnabled;
  1.1907 +  }
  1.1908 +
  1.1909 +  static bool InterruptibleReflowEnabled()
  1.1910 +  {
  1.1911 +    return sInterruptibleReflowEnabled;
  1.1912 +  }
  1.1913 +
  1.1914 +  /**
  1.1915 +   * Unions the overflow areas of the children of aFrame with aOverflowAreas.
  1.1916 +   * aSkipChildLists specifies any child lists that should be skipped.
  1.1917 +   * kSelectPopupList and kPopupList are always skipped.
  1.1918 +   */
  1.1919 +  static void UnionChildOverflow(nsIFrame* aFrame,
  1.1920 +                                 nsOverflowAreas& aOverflowAreas,
  1.1921 +                                 mozilla::layout::FrameChildListIDs aSkipChildLists =
  1.1922 +                                     mozilla::layout::FrameChildListIDs());
  1.1923 +
  1.1924 +  /**
  1.1925 +   * Return the font size inflation *ratio* for a given frame.  This is
  1.1926 +   * the factor by which font sizes should be inflated; it is never
  1.1927 +   * smaller than 1.
  1.1928 +   */
  1.1929 +  static float FontSizeInflationFor(const nsIFrame *aFrame);
  1.1930 +
  1.1931 +  /**
  1.1932 +   * Perform the first half of the computation of FontSizeInflationFor
  1.1933 +   * (see above).
  1.1934 +   * This includes determining whether inflation should be performed
  1.1935 +   * within this container and returning 0 if it should not be.
  1.1936 +   *
  1.1937 +   * The result is guaranteed not to vary between line participants
  1.1938 +   * (inlines, text frames) within a line.
  1.1939 +   *
  1.1940 +   * The result should not be used directly since font sizes slightly
  1.1941 +   * above the minimum should always be adjusted as done by
  1.1942 +   * FontSizeInflationInner.
  1.1943 +   */
  1.1944 +  static nscoord InflationMinFontSizeFor(const nsIFrame *aFrame);
  1.1945 +
  1.1946 +  /**
  1.1947 +   * Perform the second half of the computation done by
  1.1948 +   * FontSizeInflationFor (see above).
  1.1949 +   *
  1.1950 +   * aMinFontSize must be the result of one of the
  1.1951 +   *   InflationMinFontSizeFor methods above.
  1.1952 +   */
  1.1953 +  static float FontSizeInflationInner(const nsIFrame *aFrame,
  1.1954 +                                      nscoord aMinFontSize);
  1.1955 +
  1.1956 +  static bool FontSizeInflationEnabled(nsPresContext *aPresContext);
  1.1957 +
  1.1958 +  /**
  1.1959 +   * See comment above "font.size.inflation.maxRatio" in
  1.1960 +   * modules/libpref/src/init/all.js .
  1.1961 +   */
  1.1962 +  static uint32_t FontSizeInflationMaxRatio() {
  1.1963 +    return sFontSizeInflationMaxRatio;
  1.1964 +  }
  1.1965 +
  1.1966 +  /**
  1.1967 +   * See comment above "font.size.inflation.emPerLine" in
  1.1968 +   * modules/libpref/src/init/all.js .
  1.1969 +   */
  1.1970 +  static uint32_t FontSizeInflationEmPerLine() {
  1.1971 +    return sFontSizeInflationEmPerLine;
  1.1972 +  }
  1.1973 +
  1.1974 +  /**
  1.1975 +   * See comment above "font.size.inflation.minTwips" in
  1.1976 +   * modules/libpref/src/init/all.js .
  1.1977 +   */
  1.1978 +  static uint32_t FontSizeInflationMinTwips() {
  1.1979 +    return sFontSizeInflationMinTwips;
  1.1980 +  }
  1.1981 +
  1.1982 +  /**
  1.1983 +   * See comment above "font.size.inflation.lineThreshold" in
  1.1984 +   * modules/libpref/src/init/all.js .
  1.1985 +   */
  1.1986 +  static uint32_t FontSizeInflationLineThreshold() {
  1.1987 +    return sFontSizeInflationLineThreshold;
  1.1988 +  }
  1.1989 +
  1.1990 +  static bool FontSizeInflationForceEnabled() {
  1.1991 +    return sFontSizeInflationForceEnabled;
  1.1992 +  }
  1.1993 +
  1.1994 +  static bool FontSizeInflationDisabledInMasterProcess() {
  1.1995 +    return sFontSizeInflationDisabledInMasterProcess;
  1.1996 +  }
  1.1997 +
  1.1998 +  /**
  1.1999 +   * See comment above "font.size.inflation.mappingIntercept" in
  1.2000 +   * modules/libpref/src/init/all.js .
  1.2001 +   */
  1.2002 +  static int32_t FontSizeInflationMappingIntercept() {
  1.2003 +    return sFontSizeInflationMappingIntercept;
  1.2004 +  }
  1.2005 +
  1.2006 +  /**
  1.2007 +   * Returns true if the nglayout.debug.invalidation pref is set to true.
  1.2008 +   * Note that sInvalidationDebuggingIsEnabled is declared outside this function to
  1.2009 +   * allow it to be accessed an manipulated from breakpoint conditions.
  1.2010 +   */
  1.2011 +  static bool InvalidationDebuggingIsEnabled() {
  1.2012 +    return sInvalidationDebuggingIsEnabled || getenv("MOZ_DUMP_INVALIDATION") != 0;
  1.2013 +  }
  1.2014 +
  1.2015 +  static void Initialize();
  1.2016 +  static void Shutdown();
  1.2017 +
  1.2018 +  /**
  1.2019 +   * Register an imgIRequest object with a refresh driver.
  1.2020 +   *
  1.2021 +   * @param aPresContext The nsPresContext whose refresh driver we want to
  1.2022 +   *        register with.
  1.2023 +   * @param aRequest A pointer to the imgIRequest object which the client wants
  1.2024 +   *        to register with the refresh driver.
  1.2025 +   * @param aRequestRegistered A pointer to a boolean value which indicates
  1.2026 +   *        whether the given image request is registered. If
  1.2027 +   *        *aRequestRegistered is true, then this request will not be
  1.2028 +   *        registered again. If the request is registered by this function,
  1.2029 +   *        then *aRequestRegistered will be set to true upon the completion of
  1.2030 +   *        this function.
  1.2031 +   *
  1.2032 +   */
  1.2033 +  static void RegisterImageRequest(nsPresContext* aPresContext,
  1.2034 +                                   imgIRequest* aRequest,
  1.2035 +                                   bool* aRequestRegistered);
  1.2036 +
  1.2037 +  /**
  1.2038 +   * Register an imgIRequest object with a refresh driver, but only if the
  1.2039 +   * request is for an image that is animated.
  1.2040 +   *
  1.2041 +   * @param aPresContext The nsPresContext whose refresh driver we want to
  1.2042 +   *        register with.
  1.2043 +   * @param aRequest A pointer to the imgIRequest object which the client wants
  1.2044 +   *        to register with the refresh driver.
  1.2045 +   * @param aRequestRegistered A pointer to a boolean value which indicates
  1.2046 +   *        whether the given image request is registered. If
  1.2047 +   *        *aRequestRegistered is true, then this request will not be
  1.2048 +   *        registered again. If the request is registered by this function,
  1.2049 +   *        then *aRequestRegistered will be set to true upon the completion of
  1.2050 +   *        this function.
  1.2051 +   *
  1.2052 +   */
  1.2053 +  static void RegisterImageRequestIfAnimated(nsPresContext* aPresContext,
  1.2054 +                                             imgIRequest* aRequest,
  1.2055 +                                             bool* aRequestRegistered);
  1.2056 +
  1.2057 +  /**
  1.2058 +   * Deregister an imgIRequest object from a refresh driver.
  1.2059 +   *
  1.2060 +   * @param aPresContext The nsPresContext whose refresh driver we want to
  1.2061 +   *        deregister from.
  1.2062 +   * @param aRequest A pointer to the imgIRequest object with which the client
  1.2063 +   *        previously registered and now wants to deregister from the refresh
  1.2064 +   *        driver.
  1.2065 +   * @param aRequestRegistered A pointer to a boolean value which indicates
  1.2066 +   *        whether the given image request is registered. If
  1.2067 +   *        *aRequestRegistered is false, then this request will not be
  1.2068 +   *        deregistered. If the request is deregistered by this function,
  1.2069 +   *        then *aRequestRegistered will be set to false upon the completion of
  1.2070 +   *        this function.
  1.2071 +   */
  1.2072 +  static void DeregisterImageRequest(nsPresContext* aPresContext,
  1.2073 +                                     imgIRequest* aRequest,
  1.2074 +                                     bool* aRequestRegistered);
  1.2075 +
  1.2076 +  /**
  1.2077 +   * Shim to nsCSSFrameConstructor::PostRestyleEvent. Exists so that we
  1.2078 +   * can avoid including nsCSSFrameConstructor.h and all its dependencies
  1.2079 +   * in content files.
  1.2080 +   */
  1.2081 +  static void PostRestyleEvent(mozilla::dom::Element* aElement,
  1.2082 +                               nsRestyleHint aRestyleHint,
  1.2083 +                               nsChangeHint aMinChangeHint);
  1.2084 +
  1.2085 +  /**
  1.2086 +   * Updates a pair of x and y distances if a given point is closer to a given
  1.2087 +   * rectangle than the original distance values.  If aPoint is closer to
  1.2088 +   * aRect than aClosestXDistance and aClosestYDistance indicate, then those
  1.2089 +   * two variables are updated with the distance between aPoint and aRect,
  1.2090 +   * and true is returned.  If aPoint is not closer, then aClosestXDistance
  1.2091 +   * and aClosestYDistance are left unchanged, and false is returned.
  1.2092 +   *
  1.2093 +   * Distances are measured in the two dimensions separately; a closer x
  1.2094 +   * distance beats a closer y distance.
  1.2095 +   */
  1.2096 +  template<typename PointType, typename RectType, typename CoordType>
  1.2097 +  static bool PointIsCloserToRect(PointType aPoint, const RectType& aRect,
  1.2098 +                                  CoordType& aClosestXDistance,
  1.2099 +                                  CoordType& aClosestYDistance);
  1.2100 +  /**
  1.2101 +   * Computes the box shadow rect for the frame, or returns an empty rect if
  1.2102 +   * there are no shadows.
  1.2103 +   *
  1.2104 +   * @param aFrame Frame to compute shadows for.
  1.2105 +   * @param aFrameSize Size of aFrame (in case it hasn't been set yet).
  1.2106 +   */
  1.2107 +  static nsRect GetBoxShadowRectForFrame(nsIFrame* aFrame, const nsSize& aFrameSize);
  1.2108 +
  1.2109 +#ifdef DEBUG
  1.2110 +  /**
  1.2111 +   * Assert that there are no duplicate continuations of the same frame
  1.2112 +   * within aFrameList.  Optimize the tests by assuming that all frames
  1.2113 +   * in aFrameList have parent aContainer.
  1.2114 +   */
  1.2115 +  static void
  1.2116 +  AssertNoDuplicateContinuations(nsIFrame* aContainer,
  1.2117 +                                 const nsFrameList& aFrameList);
  1.2118 +
  1.2119 +  /**
  1.2120 +   * Assert that the frame tree rooted at |aSubtreeRoot| is empty, i.e.,
  1.2121 +   * that it contains no first-in-flows.
  1.2122 +   */
  1.2123 +  static void
  1.2124 +  AssertTreeOnlyEmptyNextInFlows(nsIFrame *aSubtreeRoot);
  1.2125 +#endif
  1.2126 +
  1.2127 +  /**
  1.2128 +   * Determine if aImageFrame (which is an nsImageFrame, nsImageControlFrame, or
  1.2129 +   * nsSVGImageFrame) is visible or close to being visible via scrolling and
  1.2130 +   * update the presshell with this knowledge.
  1.2131 +   */
  1.2132 +  static void
  1.2133 +  UpdateImageVisibilityForFrame(nsIFrame* aImageFrame);
  1.2134 +
  1.2135 + /**
  1.2136 +  * Calculate the compostion size for a frame. See FrameMetrics.h for
  1.2137 +  * defintion of composition size (or bounds).
  1.2138 +  */
  1.2139 +  static nsSize
  1.2140 +  CalculateCompositionSizeForFrame(nsIFrame* aFrame);
  1.2141 +
  1.2142 + /**
  1.2143 +  * Calculate the composition size for the root scroll frame of the root
  1.2144 +  * content document.
  1.2145 +  * @param aFrame A frame in the root content document (or a descendant of it).
  1.2146 +  * @param aIsRootContentDocRootScrollFrame Whether aFrame is already the root
  1.2147 +  *          scroll frame of the root content document. In this case we just
  1.2148 +  *          use aFrame's own composition size.
  1.2149 +  * @param aMetrics A partially populated FrameMetrics for aFrame. Must have at
  1.2150 +  *          least mCompositionBounds, mCumulativeResolution, and
  1.2151 +  *          mDevPixelsPerCSSPixel set.
  1.2152 +  */
  1.2153 +  static CSSSize
  1.2154 +  CalculateRootCompositionSize(nsIFrame* aFrame,
  1.2155 +                               bool aIsRootContentDocRootScrollFrame,
  1.2156 +                               const FrameMetrics& aMetrics);
  1.2157 +
  1.2158 + /**
  1.2159 +  * Calculate the scrollable rect for a frame. See FrameMetrics.h for
  1.2160 +  * defintion of scrollable rect. aScrollableFrame is the scroll frame to calculate
  1.2161 +  * the scrollable rect for. If it's null then we calculate the scrollable rect
  1.2162 +  * as the rect of the root frame.
  1.2163 +  */
  1.2164 +  static nsRect
  1.2165 +  CalculateScrollableRectForFrame(nsIScrollableFrame* aScrollableFrame, nsIFrame* aRootFrame);
  1.2166 +
  1.2167 + /**
  1.2168 +  * Calculate the expanded scrollable rect for a frame. See FrameMetrics.h for
  1.2169 +  * defintion of expanded scrollable rect.
  1.2170 +  */
  1.2171 +  static nsRect
  1.2172 +  CalculateExpandedScrollableRect(nsIFrame* aFrame);
  1.2173 +
  1.2174 +  /**
  1.2175 +   * Return whether we want to use APZ for subframes in this process.
  1.2176 +   * Currently we don't support APZ for the parent process on B2G.
  1.2177 +   */
  1.2178 +  static bool WantSubAPZC();
  1.2179 +
  1.2180 + /**
  1.2181 +   * Get the display port for |aScrollFrame|'s content. If |aScrollFrame|
  1.2182 +   * WantsAsyncScroll() and we don't have a scrollable displayport yet (as
  1.2183 +   * tracked by |aBuilder|), calculate and set a display port. Returns true if
  1.2184 +   * there is (now) a displayport, and if so the displayport is returned in
  1.2185 +   * |aOutDisplayport|.
  1.2186 +   *
  1.2187 +   * Note that a displayport can either be stored as a rect, or as a base
  1.2188 +   * rect + margins. If it is stored as a base rect + margins, the base rect
  1.2189 +   * is updated to |aDisplayPortBase|, and the rect assembled from the
  1.2190 +   * base rect and margins is returned. If this function creates a displayport,
  1.2191 +   * it computes margins and stores |aDisplayPortBase| as the base rect.
  1.2192 +   *
  1.2193 +   * This is intended to be called during display list building.
  1.2194 +   */
  1.2195 +  static bool GetOrMaybeCreateDisplayPort(nsDisplayListBuilder& aBuilder,
  1.2196 +                                          nsIFrame* aScrollFrame,
  1.2197 +                                          nsRect aDisplayPortBase,
  1.2198 +                                          nsRect* aOutDisplayport);
  1.2199 +
  1.2200 +private:
  1.2201 +  static uint32_t sFontSizeInflationEmPerLine;
  1.2202 +  static uint32_t sFontSizeInflationMinTwips;
  1.2203 +  static uint32_t sFontSizeInflationLineThreshold;
  1.2204 +  static int32_t  sFontSizeInflationMappingIntercept;
  1.2205 +  static uint32_t sFontSizeInflationMaxRatio;
  1.2206 +  static bool sFontSizeInflationForceEnabled;
  1.2207 +  static bool sFontSizeInflationDisabledInMasterProcess;
  1.2208 +  static bool sInvalidationDebuggingIsEnabled;
  1.2209 +  static bool sCSSVariablesEnabled;
  1.2210 +  static bool sInterruptibleReflowEnabled;
  1.2211 +};
  1.2212 +
  1.2213 +MOZ_FINISH_NESTED_ENUM_CLASS(nsLayoutUtils::RepaintMode)
  1.2214 +
  1.2215 +template<typename PointType, typename RectType, typename CoordType>
  1.2216 +/* static */ bool
  1.2217 +nsLayoutUtils::PointIsCloserToRect(PointType aPoint, const RectType& aRect,
  1.2218 +                                   CoordType& aClosestXDistance,
  1.2219 +                                   CoordType& aClosestYDistance)
  1.2220 +{
  1.2221 +  CoordType fromLeft = aPoint.x - aRect.x;
  1.2222 +  CoordType fromRight = aPoint.x - aRect.XMost();
  1.2223 +
  1.2224 +  CoordType xDistance;
  1.2225 +  if (fromLeft >= 0 && fromRight <= 0) {
  1.2226 +    xDistance = 0;
  1.2227 +  } else {
  1.2228 +    xDistance = std::min(abs(fromLeft), abs(fromRight));
  1.2229 +  }
  1.2230 +
  1.2231 +  if (xDistance <= aClosestXDistance) {
  1.2232 +    if (xDistance < aClosestXDistance) {
  1.2233 +      aClosestYDistance = std::numeric_limits<CoordType>::max();
  1.2234 +    }
  1.2235 +
  1.2236 +    CoordType fromTop = aPoint.y - aRect.y;
  1.2237 +    CoordType fromBottom = aPoint.y - aRect.YMost();
  1.2238 +
  1.2239 +    CoordType yDistance;
  1.2240 +    if (fromTop >= 0 && fromBottom <= 0) {
  1.2241 +      yDistance = 0;
  1.2242 +    } else {
  1.2243 +      yDistance = std::min(abs(fromTop), abs(fromBottom));
  1.2244 +    }
  1.2245 +
  1.2246 +    if (yDistance < aClosestYDistance) {
  1.2247 +      aClosestXDistance = xDistance;
  1.2248 +      aClosestYDistance = yDistance;
  1.2249 +      return true;
  1.2250 +    }
  1.2251 +  }
  1.2252 +
  1.2253 +  return false;
  1.2254 +}
  1.2255 +
  1.2256 +namespace mozilla {
  1.2257 +  namespace layout {
  1.2258 +
  1.2259 +    /**
  1.2260 +     * An RAII class which will, for the duration of its lifetime,
  1.2261 +     * **if** the frame given is a container for font size inflation,
  1.2262 +     * set the current inflation container on the pres context to null
  1.2263 +     * (and then, in its destructor, restore the old value).
  1.2264 +     */
  1.2265 +    class AutoMaybeDisableFontInflation {
  1.2266 +    public:
  1.2267 +      AutoMaybeDisableFontInflation(nsIFrame *aFrame);
  1.2268 +
  1.2269 +      ~AutoMaybeDisableFontInflation();
  1.2270 +    private:
  1.2271 +      nsPresContext *mPresContext;
  1.2272 +      bool mOldValue;
  1.2273 +    };
  1.2274 +
  1.2275 +  }
  1.2276 +}
  1.2277 +
  1.2278 +class nsSetAttrRunnable : public nsRunnable
  1.2279 +{
  1.2280 +public:
  1.2281 +  nsSetAttrRunnable(nsIContent* aContent, nsIAtom* aAttrName,
  1.2282 +                    const nsAString& aValue);
  1.2283 +  nsSetAttrRunnable(nsIContent* aContent, nsIAtom* aAttrName,
  1.2284 +                    int32_t aValue);
  1.2285 +
  1.2286 +  NS_DECL_NSIRUNNABLE
  1.2287 +
  1.2288 +  nsCOMPtr<nsIContent> mContent;
  1.2289 +  nsCOMPtr<nsIAtom> mAttrName;
  1.2290 +  nsAutoString mValue;
  1.2291 +};
  1.2292 +
  1.2293 +class nsUnsetAttrRunnable : public nsRunnable
  1.2294 +{
  1.2295 +public:
  1.2296 +  nsUnsetAttrRunnable(nsIContent* aContent, nsIAtom* aAttrName);
  1.2297 +
  1.2298 +  NS_DECL_NSIRUNNABLE
  1.2299 +
  1.2300 +  nsCOMPtr<nsIContent> mContent;
  1.2301 +  nsCOMPtr<nsIAtom> mAttrName;
  1.2302 +};
  1.2303 +
  1.2304 +#endif // nsLayoutUtils_h__

mercurial