Source code

Revision control

Copy as Markdown

Other Tools

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* interface for all rendering objects */
#ifndef nsIFrame_h___
#define nsIFrame_h___
#ifndef MOZILLA_INTERNAL_API
#error This header/class should only be used within Mozilla code. It should not be used by extensions.
#endif
#if (defined(XP_WIN) && !defined(HAVE_64BIT_BUILD)) || defined(ANDROID)
// Blink's magic depth limit from its HTML parser (513) plus as much as fits in
// the default run-time stack on armv7 Android on Dalvik when using display:
// block minus a bit just to be sure. The Dalvik default stack crashes at 588.
// ART can do a few frames more. Using the same number for 32-bit Windows for
// consistency. Over there, Blink's magic depth of 513 doesn't fit in the
// default stack of 1 MB, but this magic depth fits when the default is grown by
// mere 192 KB (tested in 64 KB increments).
//
// 32-bit Windows has a different limit compared to 64-bit desktop, because the
// default stack size affects all threads and consumes address space. Fixing
// that is bug 1257522.
//
// 32-bit Android on ARM already happens to have defaults that are close enough
// to what makes sense as a temporary measure on Windows, so adjusting the
// Android stack can be a follow-up. The stack on 64-bit ARM needs adjusting in
// any case before 64-bit ARM can become tier-1. See bug 1400811.
//
// Ideally, we'd get rid of this smaller limit and make 32-bit Windows and
// Android capable of working with the Linux/Mac/Win64 number below.
# define MAX_REFLOW_DEPTH 585
#else
// Blink's magic depth limit from its HTML parser times two. Also just about
// fits within the system default runtime stack limit of 8 MB on 64-bit Mac and
// Linux with display: table-cell.
# define MAX_REFLOW_DEPTH 1026
#endif
/* nsIFrame is in the process of being deCOMtaminated, i.e., this file is
eventually going to be eliminated, and all callers will use nsFrame instead.
At the moment we're midway through this process, so you will see inlined
functions and member variables in this file. -dwh */
#include <algorithm>
#include <stdio.h>
#include "FrameProperties.h"
#include "LayoutConstants.h"
#include "mozilla/AspectRatio.h"
#include "mozilla/Attributes.h"
#include "mozilla/Baseline.h"
#include "mozilla/EnumSet.h"
#include "mozilla/EventForwards.h"
#include "mozilla/Maybe.h"
#include "mozilla/RelativeTo.h"
#include "mozilla/Result.h"
#include "mozilla/SmallPointerArray.h"
#include "mozilla/ToString.h"
#include "mozilla/WritingModes.h"
#include "nsDirection.h"
#include "nsFrameList.h"
#include "nsFrameState.h"
#include "mozilla/ReflowInput.h"
#include "nsIContent.h"
#include "nsITheme.h"
#include "nsQueryFrame.h"
#include "mozilla/ComputedStyle.h"
#include "nsStyleStruct.h"
#include "Visibility.h"
#include "nsChangeHint.h"
#include "mozilla/EnumSet.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/CompositorHitTestInfo.h"
#include "mozilla/gfx/MatrixFwd.h"
#include "mozilla/intl/BidiEmbeddingLevel.h"
#include "nsDisplayItemTypes.h"
#include "nsPresContext.h"
#include "nsTHashSet.h"
#ifdef ACCESSIBILITY
# include "mozilla/a11y/AccTypes.h"
#endif
/**
* New rules of reflow:
* 1. you get a WillReflow() followed by a Reflow() followed by a DidReflow() in
* order (no separate pass over the tree)
* 2. it's the parent frame's responsibility to size/position the child's view
* (not the child frame's responsibility as it is today) during reflow (and
* before sending the DidReflow() notification)
* 3. positioning of child frames (and their views) is done on the way down the
* tree, and sizing of child frames (and their views) on the way back up
* 4. if you move a frame (outside of the reflow process, or after reflowing
* it), then you must make sure that its view (or its child frame's views)
* are re-positioned as well. It's reasonable to not position the view until
* after all reflowing the entire line, for example, but the frame should
* still be positioned and sized (and the view sized) during the reflow
* (i.e., before sending the DidReflow() notification)
* 5. the view system handles moving of widgets, i.e., it's not our problem
*/
class nsAtom;
class nsView;
class nsFrameSelection;
class nsIWidget;
class nsISelectionController;
class nsILineIterator;
class gfxSkipChars;
class gfxSkipCharsIterator;
class gfxContext;
class nsLineLink;
template <typename Link, bool>
class GenericLineListIterator;
using LineListIterator = GenericLineListIterator<nsLineLink, false>;
class nsAbsoluteContainingBlock;
class nsContainerFrame;
class nsPlaceholderFrame;
class nsStyleChangeList;
class nsViewManager;
class nsWindowSizes;
struct CharacterDataChangeInfo;
namespace mozilla {
enum class CaretAssociationHint;
enum class IsFocusableFlags : uint8_t;
enum class PeekOffsetOption : uint16_t;
enum class PseudoStyleType : uint8_t;
enum class TableSelectionMode : uint32_t;
class EffectSet;
class LazyLogModule;
class nsDisplayItem;
class nsDisplayList;
class nsDisplayListBuilder;
class nsDisplayListSet;
class PresShell;
class ScrollContainerFrame;
class ServoRestyleState;
class WidgetGUIEvent;
class WidgetMouseEvent;
struct PeekOffsetStruct;
namespace layers {
class Layer;
class LayerManager;
} // namespace layers
namespace layout {
class ScrollAnchorContainer;
} // namespace layout
} // namespace mozilla
//----------------------------------------------------------------------
// 1 million CSS pixels less than our max app unit measure.
// For reflowing with an "infinite" available inline space per [css-sizing].
// (reflowing with an NS_UNCONSTRAINEDSIZE available inline size isn't allowed
// and leads to assertions)
#define INFINITE_ISIZE_COORD nscoord(NS_MAXSIZE - (1000000 * 60))
//----------------------------------------------------------------------
namespace mozilla {
enum class LayoutFrameType : uint8_t {
#define FRAME_TYPE(ty_, ...) ty_,
#include "mozilla/FrameTypeList.h"
#undef FRAME_TYPE
};
} // namespace mozilla
enum nsSelectionAmount {
eSelectCharacter = 0, // a single Unicode character;
// do not use this (prefer Cluster) unless you
// are really sure it's what you want
eSelectCluster = 1, // a grapheme cluster: this is usually the right
// choice for movement or selection by "character"
// as perceived by the user
eSelectWord = 2,
eSelectWordNoSpace = 3, // select a "word" without selecting the following
// space, no matter what the default platform
// behavior is
eSelectLine = 4, // previous drawn line in flow.
// NOTE that selection code depends on the ordering of the above values,
// allowing simple <= tests to check categories of caret movement.
// Don't rearrange without checking the usage in nsSelection.cpp!
eSelectBeginLine = 5,
eSelectEndLine = 6,
eSelectNoAmount = 7, // just bounce back current offset.
eSelectParagraph = 8 // select a "paragraph"
};
//----------------------------------------------------------------------
// Reflow status returned by the Reflow() methods.
class nsReflowStatus final {
public:
nsReflowStatus()
: mFloatClearType(mozilla::UsedClear::None),
mInlineBreak(InlineBreak::None),
mCompletion(Completion::FullyComplete),
mNextInFlowNeedsReflow(false),
mFirstLetterComplete(false) {}
// Reset all the member variables.
void Reset() {
mFloatClearType = mozilla::UsedClear::None;
mInlineBreak = InlineBreak::None;
mCompletion = Completion::FullyComplete;
mNextInFlowNeedsReflow = false;
mFirstLetterComplete = false;
}
// Return true if all member variables have their default values.
bool IsEmpty() const {
return (IsFullyComplete() && !IsInlineBreak() && !mNextInFlowNeedsReflow &&
!mFirstLetterComplete);
}
// There are three possible completion statuses, represented by
// mCompletion.
//
// Incomplete means the frame does *not* map all its content, and the
// parent frame should create a continuing frame.
//
// OverflowIncomplete means that the frame has an overflow that is not
// complete, but its own box is complete. (This happens when the content
// overflows a fixed-height box.) The reflower should place and size the
// frame and continue its reflow, but it needs to create an overflow
// container as a continuation for this frame. See "Overflow containers"
// documentation in nsContainerFrame.h for more information.
//
// FullyComplete means the frame is neither Incomplete nor
// OverflowIncomplete. This is the default state for a nsReflowStatus.
//
enum class Completion : uint8_t {
// The order of the enum values is important, which represents the
// precedence when merging.
FullyComplete,
OverflowIncomplete,
Incomplete,
};
bool IsIncomplete() const { return mCompletion == Completion::Incomplete; }
bool IsOverflowIncomplete() const {
return mCompletion == Completion::OverflowIncomplete;
}
bool IsFullyComplete() const {
return mCompletion == Completion::FullyComplete;
}
// Just for convenience; not a distinct state.
bool IsComplete() const { return !IsIncomplete(); }
void SetIncomplete() { mCompletion = Completion::Incomplete; }
void SetOverflowIncomplete() { mCompletion = Completion::OverflowIncomplete; }
// mNextInFlowNeedsReflow bit flag means that the next-in-flow is dirty,
// and also needs to be reflowed. This status only makes sense for a frame
// that is not complete, i.e. you wouldn't set mNextInFlowNeedsReflow when
// IsComplete() is true.
bool NextInFlowNeedsReflow() const { return mNextInFlowNeedsReflow; }
void SetNextInFlowNeedsReflow() { mNextInFlowNeedsReflow = true; }
// Merge the frame completion status bits from aStatus into this.
void MergeCompletionStatusFrom(const nsReflowStatus& aStatus) {
if (mCompletion < aStatus.mCompletion) {
mCompletion = aStatus.mCompletion;
}
// These asserts ensure that the mCompletion merging works as we expect.
// (Incomplete beats OverflowIncomplete, which beats FullyComplete.)
static_assert(
Completion::Incomplete > Completion::OverflowIncomplete &&
Completion::OverflowIncomplete > Completion::FullyComplete,
"mCompletion merging won't work without this!");
mNextInFlowNeedsReflow |= aStatus.mNextInFlowNeedsReflow;
}
// There are three possible inline-break statuses, represented by
// mInlineBreak.
//
// "None" means no break is requested.
// "Before" means the break should occur before the frame.
// "After" means the break should occur after the frame.
// (Here, "the frame" is the frame whose reflow results are being reported by
// this nsReflowStatus.)
//
enum class InlineBreak : uint8_t {
None,
Before,
After,
};
bool IsInlineBreak() const { return mInlineBreak != InlineBreak::None; }
bool IsInlineBreakBefore() const {
return mInlineBreak == InlineBreak::Before;
}
bool IsInlineBreakAfter() const { return mInlineBreak == InlineBreak::After; }
mozilla::UsedClear FloatClearType() const { return mFloatClearType; }
// Set the inline line-break-before status, and reset other bit flags. Note
// that other frame completion status isn't expected to matter after calling
// this method.
//
// Here's one scenario where a child frame would report this status. Suppose
// the child has "break-inside:avoid" in its style, and the child (and its
// content) won't fit in the available block-size. This child would want to
// report this status so that it gets pushed (in its entirety) to the next
// column/page where it will hopefully fit.
void SetInlineLineBreakBeforeAndReset() {
Reset();
mFloatClearType = mozilla::UsedClear::None;
mInlineBreak = InlineBreak::Before;
}
// Set the inline line-break-after status. The clear type can be changed
// via the optional aClearType param.
void SetInlineLineBreakAfter(
mozilla::UsedClear aClearType = mozilla::UsedClear::None) {
mFloatClearType = aClearType;
mInlineBreak = InlineBreak::After;
}
// mFirstLetterComplete bit flag means the break was induced by
// completion of a first-letter.
bool FirstLetterComplete() const { return mFirstLetterComplete; }
void SetFirstLetterComplete() { mFirstLetterComplete = true; }
private:
mozilla::UsedClear mFloatClearType;
InlineBreak mInlineBreak;
Completion mCompletion;
bool mNextInFlowNeedsReflow : 1;
bool mFirstLetterComplete : 1;
};
// Convert nsReflowStatus to a human-readable string.
std::ostream& operator<<(std::ostream& aStream, const nsReflowStatus& aStatus);
namespace mozilla {
enum class AlignmentContext {
Inline,
Table,
Flexbox,
Grid,
};
/*
* For replaced elements only. Gets the intrinsic dimensions of this element,
* which can be specified on a per-axis basis.
*/
struct IntrinsicSize {
Maybe<nscoord> width;
Maybe<nscoord> height;
IntrinsicSize() = default;
IntrinsicSize(nscoord aWidth, nscoord aHeight)
: width(Some(aWidth)), height(Some(aHeight)) {}
explicit IntrinsicSize(const nsSize& aSize)
: IntrinsicSize(aSize.Width(), aSize.Height()) {}
Maybe<nsSize> ToSize() const {
return width && height ? Some(nsSize(*width, *height)) : Nothing();
}
Maybe<nscoord>& ISize(WritingMode aWM) {
return aWM.IsVertical() ? height : width;
}
const Maybe<nscoord>& ISize(WritingMode aWM) const {
return aWM.IsVertical() ? height : width;
}
Maybe<nscoord>& BSize(WritingMode aWM) {
return aWM.IsVertical() ? width : height;
}
const Maybe<nscoord>& BSize(WritingMode aWM) const {
return aWM.IsVertical() ? width : height;
}
void Zoom(const StyleZoom& aZoom) {
if (width) {
*width = aZoom.ZoomCoord(*width);
}
if (height) {
*height = aZoom.ZoomCoord(*height);
}
}
bool operator==(const IntrinsicSize& rhs) const {
return width == rhs.width && height == rhs.height;
}
bool operator!=(const IntrinsicSize& rhs) const { return !(*this == rhs); }
};
// Pseudo bidi embedding level indicating nonexistence.
constexpr mozilla::intl::BidiEmbeddingLevel kBidiLevelNone(0xff);
struct FrameBidiData {
mozilla::intl::BidiEmbeddingLevel baseLevel;
mozilla::intl::BidiEmbeddingLevel embeddingLevel;
// The embedding level of virtual bidi formatting character before
// this frame if any. kBidiLevelNone is used to indicate nonexistence
// or unnecessity of such virtual character.
mozilla::intl::BidiEmbeddingLevel precedingControl;
};
// A struct aggregates necessary data to compute the intrinsic sizes for a
// frame, typically the frame whose intrinsic size contribution is being
// requested. This struct is used as an input for GetMinISize(), GetPrefISize(),
// IntrinsicISize(), and others.
struct MOZ_STACK_CLASS IntrinsicSizeInput final {
gfxContext* const mContext;
// The content-box size of a frame's containing block (in the frame's own
// writing mode), used as a percentage basis for percentage-based sizes on the
// frame itself that contribute to its intrinsic size. For example, in grid
// layout, a percentage value of min-height be can transferred through the
// aspect-ratio to determine auto repeat columns specified in
// grid-template-columns.
//
// Note: it is acceptable for mContainingBlockSize to be Nothing() as long as
// the frame doesn't have percentage-based value for properties that need to
// be resolved in order to compute its intrinsic size.
Maybe<LogicalSize> mContainingBlockSize;
// The content-box size of a frame (in the frame's own writing mode), served
// as a percentage basis when computing the children's intrinsic
// contributions. If the basis is indefinite in a given axis, use
// NS_UNCONSTRAINEDSIZE for that component. If the value is Nothing, it is
// semantically equivalent to NS_UNCONSTRAINEDSIZE in both axes.
//
// In most scenarios, this struct is used when computing the inline size
// contribution, so the inline component of the percentage basis should be set
// to NS_UNCONSTRAINEDSIZE.
Maybe<LogicalSize> mPercentageBasisForChildren;
bool HasSomePercentageBasisForChildren() const {
return mPercentageBasisForChildren &&
!mPercentageBasisForChildren->IsAllValues(NS_UNCONSTRAINEDSIZE);
}
IntrinsicSizeInput(gfxContext* aContext,
const Maybe<LogicalSize>& aContainingBlockSize,
const Maybe<LogicalSize>& aPercentageBasisForChildren)
: mContext(aContext),
mContainingBlockSize(aContainingBlockSize),
mPercentageBasisForChildren(aPercentageBasisForChildren) {
MOZ_ASSERT(mContext);
}
// Construct a new IntrinsicSizeInput for children by copying from
// aParentInput.
//
// Note: since this constructor creates an IntrinsicSizeInput for the
// children, it does not copy mContainingBlockSize from aParentInput.
//
// This constructor converts mPercentageBasisForChildren's writing mode, if it
// exists. The original mPercentageBasis in aSource is expected to be in the
// writing mode aFromWM, and it will be converted to the writing mode aToWM.
IntrinsicSizeInput(const IntrinsicSizeInput& aParentInput,
mozilla::WritingMode aToWM, mozilla::WritingMode aFromWM)
: IntrinsicSizeInput(
aParentInput.mContext, Nothing(),
aParentInput.mPercentageBasisForChildren.map([&](const auto& aPB) {
return aPB.ConvertTo(aToWM, aFromWM);
})) {}
};
} // namespace mozilla
/// Generic destructor for frame properties. Calls delete.
template <typename T>
static void DeleteValue(T* aPropertyValue) {
delete aPropertyValue;
}
/// Generic destructor for frame properties. Calls Release().
template <typename T>
static void ReleaseValue(T* aPropertyValue) {
aPropertyValue->Release();
}
//----------------------------------------------------------------------
/**
* nsIFrame logging constants. We redefine the nspr
* PRLogModuleInfo.level field to be a bitfield. Each bit controls a
* specific type of logging. Each logging operation has associated
* inline methods defined below.
*
* Due to the redefinition of the level field we cannot use MOZ_LOG directly
* as that will cause assertions due to invalid log levels.
*/
#define NS_FRAME_TRACE_CALLS 0x1
#define NS_FRAME_TRACE_PUSH_PULL 0x2
#define NS_FRAME_TRACE_CHILD_REFLOW 0x4
#define NS_FRAME_TRACE_NEW_FRAMES 0x8
#define NS_FRAME_LOG_TEST(_lm, _bit) \
(int(((mozilla::LogModule*)(_lm))->Level()) & (_bit))
#ifdef DEBUG
# define NS_FRAME_LOG(_bit, _args) \
PR_BEGIN_MACRO \
if (NS_FRAME_LOG_TEST(nsIFrame::sFrameLogModule, _bit)) { \
printf_stderr _args; \
} \
PR_END_MACRO
#else
# define NS_FRAME_LOG(_bit, _args)
#endif
// XXX Need to rework this so that logging is free when it's off
#ifdef DEBUG
# define NS_FRAME_TRACE_IN(_method) Trace(_method, true)
# define NS_FRAME_TRACE_OUT(_method) Trace(_method, false)
# define NS_FRAME_TRACE(_bit, _args) \
PR_BEGIN_MACRO \
if (NS_FRAME_LOG_TEST(nsIFrame::sFrameLogModule, _bit)) { \
TraceMsg _args; \
} \
PR_END_MACRO
# define NS_FRAME_TRACE_REFLOW_IN(_method) Trace(_method, true)
# define NS_FRAME_TRACE_REFLOW_OUT(_method, _status) \
Trace(_method, false, _status)
#else
# define NS_FRAME_TRACE(_bits, _args)
# define NS_FRAME_TRACE_IN(_method)
# define NS_FRAME_TRACE_OUT(_method)
# define NS_FRAME_TRACE_REFLOW_IN(_method)
# define NS_FRAME_TRACE_REFLOW_OUT(_method, _status)
#endif
//----------------------------------------------------------------------
// Frame allocation boilerplate macros. Every subclass of nsFrame must
// either use NS_{DECL,IMPL}_FRAMEARENA_HELPERS pair for allocating
// memory correctly, or use NS_DECL_ABSTRACT_FRAME to declare a frame
// class abstract and stop it from being instantiated. If a frame class
// without its own operator new and GetFrameId gets instantiated, the
// per-frame recycler lists in nsPresArena will not work correctly,
// with potentially catastrophic consequences (not enough memory is
// allocated for a frame object).
#define NS_DECL_FRAMEARENA_HELPERS(class) \
NS_DECL_QUERYFRAME_TARGET(class) \
static constexpr nsIFrame::ClassID kClassID = nsIFrame::ClassID::class##_id; \
void* operator new(size_t, mozilla::PresShell*) MOZ_MUST_OVERRIDE; \
nsQueryFrame::FrameIID GetFrameId() const override MOZ_MUST_OVERRIDE { \
return nsQueryFrame::class##_id; \
}
#define NS_IMPL_FRAMEARENA_HELPERS(class) \
void* class ::operator new(size_t sz, mozilla::PresShell * aShell) { \
return aShell->AllocateFrame(nsQueryFrame::class##_id, sz); \
}
#define NS_DECL_ABSTRACT_FRAME(class) \
void* operator new(size_t, mozilla::PresShell*) MOZ_MUST_OVERRIDE = delete; \
nsQueryFrame::FrameIID GetFrameId() const override MOZ_MUST_OVERRIDE = 0;
//----------------------------------------------------------------------
namespace mozilla {
// A simple class to group stuff that we need to keep around when tearing down
// a frame tree.
//
// Native anonymous content created by the frames need to get unbound _after_
// the frame has been destroyed, see bug 1400618.
//
// We destroy the anonymous content bottom-up (so, in reverse order), because
// it's a bit simpler, though we generally don't have that much nested anonymous
// content (except for scrollbars).
struct MOZ_RAII FrameDestroyContext {
explicit FrameDestroyContext(PresShell* aPs) : mPresShell(aPs) {}
void AddAnonymousContent(already_AddRefed<nsIContent>&& aContent) {
if (RefPtr<nsIContent> content = aContent) {
mAnonymousContent.AppendElement(std::move(content));
}
}
~FrameDestroyContext();
private:
PresShell* const mPresShell;
AutoTArray<RefPtr<nsIContent>, 100> mAnonymousContent;
};
/**
* Bit-flags specific to a given layout class id.
*/
enum class LayoutFrameClassFlags : uint16_t {
None = 0,
Leaf = 1 << 0,
LeafDynamic = 1 << 1,
MathML = 1 << 2,
SVG = 1 << 3,
SVGContainer = 1 << 4,
BidiInlineContainer = 1 << 5,
// The frame is for a replaced element, such as an image
Replaced = 1 << 6,
// A replaced element that has replaced-element sizing characteristics (i.e.,
// like images or iframes), as opposed to inline-block sizing characteristics
// (like form controls).
ReplacedSizing = 1 << 7,
// A frame that participates in inline reflow, i.e., one that requires
// ReflowInput::mLineLayout.
LineParticipant = 1 << 8,
// Whether this frame is a table part (but not a table or table wrapper).
TablePart = 1 << 9,
CanContainOverflowContainers = 1 << 10,
// Whether the frame supports CSS transforms.
SupportsCSSTransforms = 1 << 11,
// Whether this frame class supports 'contain: layout' and 'contain: paint'
// (supporting one is equivalent to supporting the other).
SupportsContainLayoutAndPaint = 1 << 12,
// Whether this frame class supports the `aspect-ratio` property.
SupportsAspectRatio = 1 << 13,
// Whether this frame class is always a BFC.
BlockFormattingContext = 1 << 14,
// Whether we're a SVG rendering observer container.
SVGRenderingObserverContainer = 1 << 15,
};
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(LayoutFrameClassFlags)
} // namespace mozilla
/**
* A frame in the layout model. This interface is supported by all frame
* objects.
*
* Frames can have multiple child lists: the default child list
* (referred to as the <i>principal</i> child list, and additional named
* child lists. There is an ordering of frames within a child list, but
* there is no order defined between frames in different child lists of
* the same parent frame.
*
* Frames are NOT reference counted. Use the Destroy() member function
* to destroy a frame. The lifetime of the frame hierarchy is bounded by the
* lifetime of the presentation shell which owns the frames.
*
* nsIFrame is a private Gecko interface. If you are not Gecko then you
* should not use it. If you're not in layout, then you won't be able to
* link to many of the functions defined here. Too bad.
*
* If you're not in layout but you must call functions in here, at least
* restrict yourself to calling virtual methods, which won't hurt you as badly.
*/
class nsIFrame : public nsQueryFrame {
public:
using AlignmentContext = mozilla::AlignmentContext;
using BaselineSharingGroup = mozilla::BaselineSharingGroup;
using BaselineExportContext = mozilla::BaselineExportContext;
template <typename T>
using Maybe = mozilla::Maybe<T>;
template <typename T, typename E>
using Result = mozilla::Result<T, E>;
using Nothing = mozilla::Nothing;
using OnNonvisible = mozilla::OnNonvisible;
using ReflowInput = mozilla::ReflowInput;
using ReflowOutput = mozilla::ReflowOutput;
using Visibility = mozilla::Visibility;
using ContentRelevancy = mozilla::ContentRelevancy;
using nsDisplayItem = mozilla::nsDisplayItem;
using nsDisplayList = mozilla::nsDisplayList;
using nsDisplayListSet = mozilla::nsDisplayListSet;
using nsDisplayListBuilder = mozilla::nsDisplayListBuilder;
typedef mozilla::ComputedStyle ComputedStyle;
typedef mozilla::FrameProperties FrameProperties;
typedef mozilla::layers::LayerManager LayerManager;
typedef mozilla::gfx::DrawTarget DrawTarget;
typedef mozilla::gfx::Matrix Matrix;
typedef mozilla::gfx::Matrix4x4 Matrix4x4;
typedef mozilla::gfx::Matrix4x4Flagged Matrix4x4Flagged;
typedef mozilla::Sides Sides;
typedef mozilla::LogicalSides LogicalSides;
typedef mozilla::SmallPointerArray<nsDisplayItem> DisplayItemArray;
typedef nsQueryFrame::ClassID ClassID;
using ClassFlags = mozilla::LayoutFrameClassFlags;
protected:
using ChildList = mozilla::FrameChildList;
using ChildListID = mozilla::FrameChildListID;
using ChildListIDs = mozilla::FrameChildListIDs;
public:
// nsQueryFrame
NS_DECL_QUERYFRAME
NS_DECL_QUERYFRAME_TARGET(nsIFrame)
explicit nsIFrame(ComputedStyle* aStyle, nsPresContext* aPresContext,
ClassID aID)
: mContent(nullptr),
mComputedStyle(aStyle),
mPresContext(aPresContext),
mParent(nullptr),
mNextSibling(nullptr),
mPrevSibling(nullptr),
mState(NS_FRAME_FIRST_REFLOW | NS_FRAME_IS_DIRTY),
mWritingMode(aStyle),
mClass(aID),
mMayHaveRoundedCorners(false),
mHasImageRequest(false),
mHasFirstLetterChild(false),
mParentIsWrapperAnonBox(false),
mIsWrapperBoxNeedingRestyle(false),
mReflowRequestedForCharDataChange(false),
mForceDescendIntoIfVisible(false),
mBuiltDisplayList(false),
mFrameIsModified(false),
mHasModifiedDescendants(false),
mHasOverrideDirtyRegion(false),
mMayHaveWillChangeBudget(false),
#ifdef DEBUG
mWasVisitedByAutoFrameConstructionPageName(false),
#endif
mIsPrimaryFrame(false),
mMayHaveTransformAnimation(false),
mMayHaveOpacityAnimation(false),
mAllDescendantsAreInvisible(false),
mHasBSizeChange(false),
mHasPaddingChange(false),
mInScrollAnchorChain(false),
mHasColumnSpanSiblings(false),
mDescendantMayDependOnItsStaticPosition(false) {
MOZ_ASSERT(mComputedStyle);
MOZ_ASSERT(mPresContext);
mozilla::PodZero(&mOverflow);
MOZ_COUNT_CTOR(nsIFrame);
}
explicit nsIFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
: nsIFrame(aStyle, aPresContext, ClassID::nsIFrame_id) {}
nsPresContext* PresContext() const { return mPresContext; }
mozilla::PresShell* PresShell() const { return PresContext()->PresShell(); }
virtual nsQueryFrame::FrameIID GetFrameId() const MOZ_MUST_OVERRIDE {
return kFrameIID;
}
/**
* Called to initialize the frame. This is called immediately after creating
* the frame.
*
* If the frame is a continuing frame, then aPrevInFlow indicates the previous
* frame (the frame that was split).
*
* @param aContent the content object associated with the frame
* @param aParent the parent frame
* @param aPrevInFlow the prev-in-flow frame
*/
virtual void Init(nsIContent* aContent, nsContainerFrame* aParent,
nsIFrame* aPrevInFlow);
void* operator new(size_t, mozilla::PresShell*) MOZ_MUST_OVERRIDE;
using DestroyContext = mozilla::FrameDestroyContext;
/**
* Flags for PeekOffsetCharacter, PeekOffsetNoAmount, PeekOffsetWord return
* values.
*/
enum FrameSearchResult {
// Peek found a appropriate offset within frame.
FOUND = 0x00,
// try next frame for offset.
CONTINUE = 0x1,
// offset not found because the frame was empty of text.
CONTINUE_EMPTY = 0x2 | CONTINUE,
// offset not found because the frame didn't contain any text that could be
// selected.
CONTINUE_UNSELECTABLE = 0x4 | CONTINUE,
};
/**
* Options for PeekOffsetCharacter().
*/
struct MOZ_STACK_CLASS PeekOffsetCharacterOptions {
// Whether to restrict result to valid cursor locations (between grapheme
// clusters) - if this is included, maintains "normal" behavior, otherwise,
// used for selection by "code unit" (instead of "character")
bool mRespectClusters;
// Whether to check user-select style value - if this is included, checks
// if user-select is all, then, it may return CONTINUE_UNSELECTABLE.
bool mIgnoreUserStyleAll;
PeekOffsetCharacterOptions()
: mRespectClusters(true), mIgnoreUserStyleAll(false) {}
};
virtual void Destroy(DestroyContext&);
protected:
/**
* Return true if the frame is part of a Selection.
* Helper method to implement the public IsSelected() API.
*/
virtual bool IsFrameSelected() const;
template <class Source>
friend class do_QueryFrameHelper; // to read mClass
friend class nsBlockFrame; // for GetCaretBaseline
friend class nsContainerFrame; // for ReparentFrameViewTo
virtual ~nsIFrame();
// Overridden to prevent the global delete from being called, since
// the memory came out of an arena instead of the heap.
//
// Ideally this would be private and undefined, like the normal
// operator new. Unfortunately, the C++ standard requires an
// overridden operator delete to be accessible to any subclass that
// defines a virtual destructor, so we can only make it protected;
// worse, some C++ compilers will synthesize calls to this function
// from the "deleting destructors" that they emit in case of
// delete-expressions, so it can't even be undefined.
void operator delete(void* aPtr, size_t sz);
private:
// Left undefined; nsFrame objects are never allocated from the heap.
void* operator new(size_t sz) noexcept(true);
// Returns true if this frame has any kind of CSS animations.
bool HasCSSAnimations();
// Returns true if this frame has any kind of CSS transitions.
bool HasCSSTransitions();
public:
/**
* Get the content object associated with this frame. Does not add a
* reference.
*/
[[nodiscard]] nsIContent* GetContent() const { return mContent; }
[[nodiscard]] bool ContentIsRootOfNativeAnonymousSubtree() const {
return mContent && mContent->IsRootOfNativeAnonymousSubtree();
}
[[nodiscard]] inline bool ContentIsEditable() const;
/**
* @brief Get the closest native anonymous subtree root if the content is in a
* native anonymous subtree.
*
* @return The root of native anonymous subtree which the content belongs to.
* Otherwise, nullptr.
*/
nsIContent* GetClosestNativeAnonymousSubtreeRoot() const {
return mContent ? mContent->GetClosestNativeAnonymousSubtreeRoot()
: nullptr;
}
/**
* Get the frame that should be the parent for the frames of child elements
* May return nullptr during reflow
*/
virtual nsContainerFrame* GetContentInsertionFrame() { return nullptr; }
/**
* Move any frames on our overflow list to the end of our principal list.
* @return true if there were any overflow frames
*/
virtual bool DrainSelfOverflowList() { return false; }
/**
* Get the frame that should be scrolled if the content associated with this
* frame is targeted for scrolling. For a scroll container frame, this will
* just return the frame itself. For frames like nsTextControlFrame that
* contain a scroll container frame, will return that scroll container frame.
*/
virtual mozilla::ScrollContainerFrame* GetScrollTargetFrame() const {
return nullptr;
}
/**
* Get the offsets of the frame. most will be 0,0
*
*/
virtual std::pair<int32_t, int32_t> GetOffsets() const;
/**
* Reset the offsets when splitting frames during Bidi reordering
*
*/
virtual void AdjustOffsetsForBidi(int32_t aStart, int32_t aEnd) {}
/**
* Get the style associated with this frame.
*/
ComputedStyle* Style() const { return mComputedStyle; }
void AssertNewStyleIsSane(ComputedStyle&)
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
;
#else
{
}
#endif
void SetComputedStyle(ComputedStyle* aStyle) {
if (aStyle != mComputedStyle) {
AssertNewStyleIsSane(*aStyle);
RefPtr<ComputedStyle> oldComputedStyle = std::move(mComputedStyle);
mComputedStyle = aStyle;
DidSetComputedStyle(oldComputedStyle);
}
}
/**
* SetComputedStyleWithoutNotification is for changes to the style
* context that should suppress style change processing, in other
* words, those that aren't really changes. This generally means only
* changes that happen during frame construction.
*/
void SetComputedStyleWithoutNotification(ComputedStyle* aStyle) {
if (aStyle != mComputedStyle) {
mComputedStyle = aStyle;
}
}
protected:
// Style post processing hook
// Attention: the old style is the one we're forgetting,
// and hence possibly completely bogus for GetStyle* purposes.
// Use PeekStyleData instead.
virtual void DidSetComputedStyle(ComputedStyle* aOldComputedStyle);
public:
/**
* Define typesafe getter functions for each style struct by
* preprocessing the list of style structs. These functions are the
* preferred way to get style data. The macro creates functions like:
* const nsStyleBorder* StyleBorder();
* const nsStyleColor* StyleColor();
*
* Callers outside of libxul should use nsIDOMWindow::GetComputedStyle()
* instead of these accessors.
*
* Callers can use Style*WithOptionalParam if they're in a function that
* accepts an *optional* pointer the style struct.
*/
#define STYLE_STRUCT(name_) \
const nsStyle##name_* Style##name_() const MOZ_NONNULL_RETURN { \
NS_ASSERTION(mComputedStyle, "No style found!"); \
return mComputedStyle->Style##name_(); \
} \
const nsStyle##name_* Style##name_##WithOptionalParam( \
const nsStyle##name_* aStyleStruct) const MOZ_NONNULL_RETURN { \
if (aStyleStruct) { \
MOZ_ASSERT(aStyleStruct == Style##name_()); \
return aStyleStruct; \
} \
return Style##name_(); \
}
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
/** Also forward GetVisitedDependentColor to the style */
template <typename T, typename S>
nscolor GetVisitedDependentColor(T S::* aField) {
return mComputedStyle->GetVisitedDependentColor(aField);
}
/**
* These methods are to access any additional ComputedStyles that
* the frame may be holding.
*
* These are styles that are children of the frame's primary style and are NOT
* used as styles for any child frames.
*
* These contexts also MUST NOT have any child styles whatsoever. If you need
* to insert styles into the style tree, then you should create pseudo element
* frames to own them.
*
* The indicies must be consecutive and implementations MUST return null if
* asked for an index that is out of range.
*/
virtual ComputedStyle* GetAdditionalComputedStyle(int32_t aIndex) const;
virtual void SetAdditionalComputedStyle(int32_t aIndex,
ComputedStyle* aComputedStyle);
/**
* @param aSelectionStatus nsISelectionController::getDisplaySelection.
*/
already_AddRefed<ComputedStyle> ComputeSelectionStyle(
int16_t aSelectionStatus) const;
already_AddRefed<ComputedStyle> ComputeHighlightSelectionStyle(
nsAtom* aHighlightName);
already_AddRefed<ComputedStyle> ComputeTargetTextStyle() const;
/**
* Accessor functions for geometric parent.
*/
nsContainerFrame* GetParent() const { return mParent; }
bool CanBeDynamicReflowRoot() const;
/**
* Gets the parent of a frame, using the parent of the placeholder for
* out-of-flow frames.
*/
inline nsContainerFrame* GetInFlowParent() const;
/**
* Gets the primary frame of the closest flattened tree ancestor that has a
* frame (flattened tree ancestors may not have frames in presence of display:
* contents).
*/
inline nsIFrame* GetClosestFlattenedTreeAncestorPrimaryFrame() const;
/**
* Return the placeholder for this frame (which must be out-of-flow).
* @note this will only return non-null if |this| is the first-in-flow
* although we don't assert that here for legacy reasons.
*/
inline nsPlaceholderFrame* GetPlaceholderFrame() const {
MOZ_ASSERT(HasAnyStateBits(NS_FRAME_OUT_OF_FLOW));
return GetProperty(PlaceholderFrameProperty());
}
/**
* Set this frame's parent to aParent.
*/
void SetParent(nsContainerFrame* aParent);
/**
* The frame's writing-mode, used for logical layout computations.
* It's usually the 'writing-mode' computed value, but there are exceptions:
* * inner table frames copy the value from the table frame
* (@see nsTableRowGroupFrame::Init, nsTableRowFrame::Init etc)
* * the root element frame propagates its value to its ancestors.
* The value may obtain from the principal <body> element.
* (@see nsCSSFrameConstructor::ConstructDocElementFrame)
* * the internal anonymous frames of the root element copy their value
* from the parent.
* (@see nsIFrame::Init)
* * a scrolled frame propagates its value to its ancestor scroll frame
* (@see ScrollContainerFrame::ReloadChildFrames)
*/
mozilla::WritingMode GetWritingMode() const { return mWritingMode; }
/**
* Construct a writing mode for line layout in this frame. This is
* the writing mode of this frame, except that if this frame is styled with
* unicode-bidi:plaintext, we reset the direction to the resolved paragraph
* level of the given subframe (typically the first frame on the line),
* because the container frame could be split by hard line breaks into
* multiple paragraphs with different base direction.
* @param aSelfWM the WM of 'this'
*/
mozilla::WritingMode WritingModeForLine(mozilla::WritingMode aSelfWM,
nsIFrame* aSubFrame) const;
/**
* Bounding rect of the frame.
*
* For frames that are laid out according to CSS box model rules the values
* are in app units, and the origin is relative to the upper-left of the
* geometric parent. The size includes the content area, borders, and
* padding.
*
* Frames that are laid out according to SVG's coordinate space based rules
* (frames with the NS_FRAME_SVG_LAYOUT bit set, which *excludes*
* SVGOuterSVGFrame) are different. Many frames of this type do not set or
* use mRect, in which case the frame rect is undefined. The exceptions are:
*
* - SVGInnerSVGFrame
* - SVGGeometryFrame (used for <path>, <circle>, etc.)
* - SVGImageFrame
* - SVGForeignObjectFrame
*
* For these frames the frame rect contains the frame's element's userspace
* bounds including fill, stroke and markers, but converted to app units
* rather than being in user units (CSS px). In the SVG code "userspace" is
* defined to be the coordinate system for the attributes that define an
* element's geometry (such as the 'cx' attribute for <circle>). For more
* precise details see these frames' implementations of the ReflowSVG method
* where mRect is set.
*
* Note: moving or sizing the frame does not affect the view's size or
* position.
*/
nsRect GetRect() const { return mRect; }
nsPoint GetPosition() const { return mRect.TopLeft(); }
nsSize GetSize() const { return mRect.Size(); }
nsRect GetRectRelativeToSelf() const {
return nsRect(nsPoint(0, 0), mRect.Size());
}
/**
* Like the frame's rect (see |GetRect|), which is the border rect,
* other rectangles of the frame, in app units, relative to the parent.
*/
nsRect GetPaddingRect() const;
nsRect GetPaddingRectRelativeToSelf() const;
nsRect GetContentRect() const;
nsRect GetContentRectRelativeToSelf() const;
nsRect GetMarginRect() const;
nsRect GetMarginRectRelativeToSelf() const;
/**
* Dimensions and position in logical coordinates in the frame's writing mode
* or another writing mode
*/
mozilla::LogicalRect GetLogicalRect(const nsSize& aContainerSize) const {
return GetLogicalRect(GetWritingMode(), aContainerSize);
}
mozilla::LogicalPoint GetLogicalPosition(const nsSize& aContainerSize) const {
return GetLogicalPosition(GetWritingMode(), aContainerSize);
}
mozilla::LogicalSize GetLogicalSize() const {
return GetLogicalSize(GetWritingMode());
}
mozilla::LogicalRect GetLogicalRect(mozilla::WritingMode aWritingMode,
const nsSize& aContainerSize) const {
return mozilla::LogicalRect(aWritingMode, GetRect(), aContainerSize);
}
mozilla::LogicalPoint GetLogicalPosition(mozilla::WritingMode aWritingMode,
const nsSize& aContainerSize) const {
return GetLogicalRect(aWritingMode, aContainerSize).Origin(aWritingMode);
}
mozilla::LogicalSize GetLogicalSize(mozilla::WritingMode aWritingMode) const {
return mozilla::LogicalSize(aWritingMode, GetSize());
}
nscoord IStart(const nsSize& aContainerSize) const {
return IStart(GetWritingMode(), aContainerSize);
}
nscoord IStart(mozilla::WritingMode aWritingMode,
const nsSize& aContainerSize) const {
return GetLogicalPosition(aWritingMode, aContainerSize).I(aWritingMode);
}
nscoord BStart(const nsSize& aContainerSize) const {
return BStart(GetWritingMode(), aContainerSize);
}
nscoord BStart(mozilla::WritingMode aWritingMode,
const nsSize& aContainerSize) const {
return GetLogicalPosition(aWritingMode, aContainerSize).B(aWritingMode);
}
nscoord ISize() const { return ISize(GetWritingMode()); }
nscoord ISize(mozilla::WritingMode aWritingMode) const {
return GetLogicalSize(aWritingMode).ISize(aWritingMode);
}
nscoord BSize() const { return BSize(GetWritingMode()); }
nscoord BSize(mozilla::WritingMode aWritingMode) const {
return GetLogicalSize(aWritingMode).BSize(aWritingMode);
}
mozilla::LogicalSize ContentSize() const {
return ContentSize(GetWritingMode());
}
mozilla::LogicalSize ContentSize(mozilla::WritingMode aWritingMode) const {
mozilla::WritingMode wm = GetWritingMode();
const auto bp = GetLogicalUsedBorderAndPadding(wm)
.ApplySkipSides(GetLogicalSkipSides())
.ConvertTo(aWritingMode, wm);
const auto size = GetLogicalSize(aWritingMode);
return mozilla::LogicalSize(
aWritingMode,
std::max(0, size.ISize(aWritingMode) - bp.IStartEnd(aWritingMode)),
std::max(0, size.BSize(aWritingMode) - bp.BStartEnd(aWritingMode)));
}
nscoord ContentISize(mozilla::WritingMode aWritingMode) const {
return ContentSize(aWritingMode).ISize(aWritingMode);
}
nscoord ContentBSize(mozilla::WritingMode aWritingMode) const {
return ContentSize(aWritingMode).BSize(aWritingMode);
}
/**
* When we change the size of the frame's border-box rect, we may need to
* reset the overflow rect if it was previously stored as deltas.
* (If it is currently a "large" overflow and could be re-packed as deltas,
* we don't bother as the cost of the allocation has already been paid.)
* @param aRebuildDisplayItems If true, then adds this frame to the
* list of modified frames for display list building if the rect has changed.
* Only pass false if you're sure that the relevant display items will be
* rebuilt already (possibly by an ancestor being in the modified list), or if
* this is a temporary change.
*/
void SetRect(const nsRect& aRect, bool aRebuildDisplayItems = true) {
if (aRect == mRect) {
return;
}
if (mOverflow.mType != OverflowStorageType::Large &&
mOverflow.mType != OverflowStorageType::None) {
mozilla::OverflowAreas overflow = GetOverflowAreas();
mRect = aRect;
SetOverflowAreas(overflow);
} else {
mRect = aRect;
}
if (aRebuildDisplayItems) {
MarkNeedsDisplayItemRebuild();
}
}
/**
* Set this frame's rect from a logical rect in its own writing direction
*/
void SetRect(const mozilla::LogicalRect& aRect,
const nsSize& aContainerSize) {
SetRect(GetWritingMode(), aRect, aContainerSize);
}
/**
* Set this frame's rect from a logical rect in a different writing direction
* (GetPhysicalRect will assert if the writing mode doesn't match)
*/
void SetRect(mozilla::WritingMode aWritingMode,
const mozilla::LogicalRect& aRect,
const nsSize& aContainerSize) {
SetRect(aRect.GetPhysicalRect(aWritingMode, aContainerSize));
}
/**
* Set this frame's size from a logical size in its own writing direction.
* This leaves the frame's logical position unchanged, which means its
* physical position may change (for right-to-left modes).
*/
void SetSize(const mozilla::LogicalSize& aSize) {
SetSize(GetWritingMode(), aSize);
}
/*
* Set this frame's size from a logical size in a different writing direction.
* This leaves the frame's logical position in the given mode unchanged,
* which means its physical position may change (for right-to-left modes).
*/
void SetSize(mozilla::WritingMode aWritingMode,
const mozilla::LogicalSize& aSize) {
if (aWritingMode.IsPhysicalRTL()) {
nscoord oldWidth = mRect.Width();
SetSize(aSize.GetPhysicalSize(aWritingMode));
mRect.x -= mRect.Width() - oldWidth;
} else {
SetSize(aSize.GetPhysicalSize(aWritingMode));
}
}
/**
* Set this frame's physical size. This leaves the frame's physical position
* (topLeft) unchanged.
* @param aRebuildDisplayItems If true, then adds this frame to the
* list of modified frames for display list building if the size has changed.
* Only pass false if you're sure that the relevant display items will be
* rebuilt already (possibly by an ancestor being in the modified list), or if
* this is a temporary change.
*/
void SetSize(const nsSize& aSize, bool aRebuildDisplayItems = true) {
SetRect(nsRect(mRect.TopLeft(), aSize), aRebuildDisplayItems);
}
void SetPosition(const nsPoint& aPt);
void SetPosition(mozilla::WritingMode aWritingMode,
const mozilla::LogicalPoint& aPt,
const nsSize& aContainerSize) {
// We subtract mRect.Size() from the container size to account for
// the fact that logical origins in RTL coordinate systems are at
// the top right of the frame instead of the top left.
SetPosition(
aPt.GetPhysicalPoint(aWritingMode, aContainerSize - mRect.Size()));
}
/**
* Move the frame, accounting for relative positioning. Use this when
* adjusting the frame's position by a known amount, to properly update its
* saved normal position (see GetNormalPosition below).
*
* This must be used only when moving a frame *after*
* ReflowInput::ApplyRelativePositioning is called. When moving
* a frame during the reflow process prior to calling
* ReflowInput::ApplyRelativePositioning, the position should
* simply be adjusted directly (e.g., using SetPosition()).
*/
void MovePositionBy(const nsPoint& aTranslation);
/**
* As above, using a logical-point delta in a given writing mode.
*/
void MovePositionBy(mozilla::WritingMode aWritingMode,
const mozilla::LogicalPoint& aTranslation) {
// The LogicalPoint represents a vector rather than a point within a
// rectangular coordinate space, so we use a null containerSize when
// converting logical to physical.
const nsSize nullContainerSize;
MovePositionBy(
aTranslation.GetPhysicalPoint(aWritingMode, nullContainerSize));
}
/**
* Return frame's rect without relative positioning
*/
nsRect GetNormalRect() const;
mozilla::LogicalRect GetLogicalNormalRect(
mozilla::WritingMode aWritingMode, const nsSize& aContainerSize) const {
return mozilla::LogicalRect(aWritingMode, GetNormalRect(), aContainerSize);
}
/**
* Returns frame's rect as required by the GetBoundingClientRect() DOM API.
*/
nsRect GetBoundingClientRect();
/**
* Return frame's position without relative positioning.
* If aHasProperty is provided, returns whether the normal position
* was stored in a frame property.
*/
inline nsPoint GetNormalPosition(bool* aHasProperty = nullptr) const;
inline mozilla::LogicalPoint GetLogicalNormalPosition(
mozilla::WritingMode aWritingMode, const nsSize& aContainerSize) const;
virtual nsPoint GetPositionOfChildIgnoringScrolling(const nsIFrame* aChild) {
return aChild->GetPosition();
}
nsPoint GetPositionIgnoringScrolling() const;
#define NS_DECLARE_FRAME_PROPERTY_WITH_DTOR(prop, type, dtor) \
static const mozilla::FramePropertyDescriptor<type>* prop() { \
/* Use of constexpr caused startup crashes with MSVC2015u1 PGO. */ \
static const auto descriptor = \
mozilla::FramePropertyDescriptor<type>::NewWithDestructor<dtor>(); \
return &descriptor; \
}
// Don't use this unless you really know what you're doing!
#define NS_DECLARE_FRAME_PROPERTY_WITH_FRAME_IN_DTOR(prop, type, dtor) \
static const mozilla::FramePropertyDescriptor<type>* prop() { \
/* Use of constexpr caused startup crashes with MSVC2015u1 PGO. */ \
static const auto descriptor = mozilla::FramePropertyDescriptor< \
type>::NewWithDestructorWithFrame<dtor>(); \
return &descriptor; \
}
#define NS_DECLARE_FRAME_PROPERTY_WITHOUT_DTOR(prop, type) \
static const mozilla::FramePropertyDescriptor<type>* prop() { \
/* Use of constexpr caused startup crashes with MSVC2015u1 PGO. */ \
static const auto descriptor = \
mozilla::FramePropertyDescriptor<type>::NewWithoutDestructor(); \
return &descriptor; \
}
#define NS_DECLARE_FRAME_PROPERTY_DELETABLE(prop, type) \
NS_DECLARE_FRAME_PROPERTY_WITH_DTOR(prop, type, DeleteValue)
#define NS_DECLARE_FRAME_PROPERTY_RELEASABLE(prop, type) \
NS_DECLARE_FRAME_PROPERTY_WITH_DTOR(prop, type, ReleaseValue)
#define NS_DECLARE_FRAME_PROPERTY_WITH_DTOR_NEVER_CALLED(prop, type) \
static void AssertOnDestroyingProperty##prop(type*) { \
MOZ_ASSERT_UNREACHABLE( \
"Frame property " #prop \
" should never be destroyed by the FrameProperties class"); \
} \
NS_DECLARE_FRAME_PROPERTY_WITH_DTOR(prop, type, \
AssertOnDestroyingProperty##prop)
#define NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(prop, type) \
NS_DECLARE_FRAME_PROPERTY_WITHOUT_DTOR(prop, mozilla::SmallValueHolder<type>)
NS_DECLARE_FRAME_PROPERTY_WITHOUT_DTOR(IBSplitSibling, nsContainerFrame)
NS_DECLARE_FRAME_PROPERTY_WITHOUT_DTOR(IBSplitPrevSibling, nsContainerFrame)
NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(NormalPositionProperty, nsPoint)
NS_DECLARE_FRAME_PROPERTY_DELETABLE(ComputedOffsetProperty, nsMargin)
NS_DECLARE_FRAME_PROPERTY_DELETABLE(OutlineInnerRectProperty, nsRect)
NS_DECLARE_FRAME_PROPERTY_DELETABLE(PreEffectsBBoxProperty, nsRect)
NS_DECLARE_FRAME_PROPERTY_DELETABLE(PreTransformOverflowAreasProperty,
mozilla::OverflowAreas)
NS_DECLARE_FRAME_PROPERTY_DELETABLE(OverflowAreasProperty,
mozilla::OverflowAreas)
// The initial overflow area passed to FinishAndStoreOverflow. This is only
// set on frames that Preserve3D() or HasPerspective() or IsTransformed(), and
// when at least one of the overflow areas differs from the frame bound rect.
NS_DECLARE_FRAME_PROPERTY_DELETABLE(InitialOverflowProperty,
mozilla::OverflowAreas)
#ifdef DEBUG
// InitialOverflowPropertyDebug is added to the frame to indicate that either
// the InitialOverflowProperty has been stored or the InitialOverflowProperty
// has been suppressed due to being set to the default value (frame bounds)
NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(DebugInitialOverflowPropertyApplied,
bool)
#endif
NS_DECLARE_FRAME_PROPERTY_DELETABLE(UsedMarginProperty, nsMargin)
NS_DECLARE_FRAME_PROPERTY_DELETABLE(UsedPaddingProperty, nsMargin)
// This tracks the start and end page value for a frame.
//
//
// This is only tracked during paginated frame construction.
// This is used to implement fragmentation based on CSS page names. During
// frame construction, we insert page breaks when we begin a new page box and
// the previous page box had a different name.
struct PageValues {
// A value of null indicates that the value is equal to what auto resolves
// to for this frame.
RefPtr<const nsAtom> mStartPageValue = nullptr;
RefPtr<const nsAtom> mEndPageValue = nullptr;
};
NS_DECLARE_FRAME_PROPERTY_DELETABLE(PageValuesProperty, PageValues)
const nsAtom* GetStartPageValue() const {
if (const PageValues* const values =
FirstInFlow()->GetProperty(PageValuesProperty())) {
return values->mStartPageValue;
}
return nullptr;
}
const nsAtom* GetEndPageValue() const {
if (const PageValues* const values =
FirstInFlow()->GetProperty(PageValuesProperty())) {
<