Source code

Revision control

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 "CaretAssociationHint.h"
#include "FrameProperties.h"
#include "LayoutConstants.h"
#include "mozilla/layout/FrameChildList.h"
#include "mozilla/AspectRatio.h"
#include "mozilla/Attributes.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/ComputedStyleInlines.h"
#include "mozilla/EnumSet.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/CompositorHitTestInfo.h"
#include "mozilla/gfx/MatrixFwd.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 nsIScrollableFrame;
class nsISelectionController;
class nsBoxLayoutState;
class nsBoxLayout;
class nsILineIterator;
class nsDisplayItem;
class nsDisplayItemBase;
class nsDisplayListBuilder;
class nsDisplayListSet;
class nsDisplayList;
class gfxSkipChars;
class gfxSkipCharsIterator;
class gfxContext;
class nsLineList_iterator;
class nsAbsoluteContainingBlock;
class nsContainerFrame;
class nsPlaceholderFrame;
class nsStyleChangeList;
class nsViewManager;
class nsWindowSizes;
struct nsBoxLayoutMetrics;
struct nsPeekOffsetStruct;
struct CharacterDataChangeInfo;
namespace mozilla {
enum class PseudoStyleType : uint8_t;
enum class TableSelectionMode : uint32_t;
class EventStates;
class ServoRestyleState;
class DisplayItemData;
class EffectSet;
class LazyLogModule;
class PresShell;
class WidgetGUIEvent;
class WidgetMouseEvent;
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 {
using StyleClear = mozilla::StyleClear;
public:
nsReflowStatus()
: mBreakType(StyleClear::None),
mInlineBreak(InlineBreak::None),
mCompletion(Completion::FullyComplete),
mNextInFlowNeedsReflow(false),
mTruncated(false),
mFirstLetterComplete(false) {}
// Reset all the member variables.
void Reset() {
mBreakType = StyleClear::None;
mInlineBreak = InlineBreak::None;
mCompletion = Completion::FullyComplete;
mNextInFlowNeedsReflow = false;
mTruncated = false;
mFirstLetterComplete = false;
}
// Return true if all member variables have their default values.
bool IsEmpty() const {
return (IsFullyComplete() && !IsInlineBreak() && !mNextInFlowNeedsReflow &&
!mTruncated && !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; }
// mTruncated bit flag means that the part of the frame before the first
// possible break point was unable to fit in the available space.
// Therefore, the entire frame should be moved to the next continuation of
// the parent frame. A frame that begins at the top of the page must never
// be truncated. Doing so would likely cause an infinite loop.
bool IsTruncated() const { return mTruncated; }
void UpdateTruncated(const mozilla::ReflowInput& aReflowInput,
const mozilla::ReflowOutput& aMetrics);
// 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;
mTruncated |= aStatus.mTruncated;
}
// 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; }
StyleClear BreakType() const { return mBreakType; }
// Set the inline line-break-before status, and reset other bit flags. The
// break type is StyleClear::Line. Note that other frame completion status
// isn't expected to matter after calling this method.
void SetInlineLineBreakBeforeAndReset() {
Reset();
mBreakType = StyleClear::Line;
mInlineBreak = InlineBreak::Before;
}
// Set the inline line-break-after status. The break type can be changed
// via the optional aBreakType param.
void SetInlineLineBreakAfter(StyleClear aBreakType = StyleClear::Line) {
MOZ_ASSERT(aBreakType != StyleClear::None,
"Break-after with StyleClear::None is meaningless!");
mBreakType = aBreakType;
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:
StyleClear mBreakType;
InlineBreak mInlineBreak;
Completion mCompletion;
bool mNextInFlowNeedsReflow : 1;
bool mTruncated : 1;
bool mFirstLetterComplete : 1;
};
#define NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aMetrics) \
aStatus.UpdateTruncated(aReflowInput, aMetrics);
// Convert nsReflowStatus to a human-readable string.
std::ostream& operator<<(std::ostream& aStream, const nsReflowStatus& aStatus);
/**
* nsBidiLevel is the type of the level values in our Unicode Bidi
* implementation.
* It holds an embedding level and indicates the visual direction
* by its bit 0 (even/odd value).<p>
*
* <li><code>aParaLevel</code> can be set to the
* pseudo-level values <code>NSBIDI_DEFAULT_LTR</code>
* and <code>NSBIDI_DEFAULT_RTL</code>.</li></ul>
*
* @see nsBidi::SetPara
*
* <p>The related constants are not real, valid level values.
* <code>NSBIDI_DEFAULT_XXX</code> can be used to specify
* a default for the paragraph level for
* when the <code>SetPara</code> function
* shall determine it but there is no
* strongly typed character in the input.<p>
*
* Note that the value for <code>NSBIDI_DEFAULT_LTR</code> is even
* and the one for <code>NSBIDI_DEFAULT_RTL</code> is odd,
* just like with normal LTR and RTL level values -
* these special values are designed that way. Also, the implementation
* assumes that NSBIDI_MAX_EXPLICIT_LEVEL is odd.
*
* @see NSBIDI_DEFAULT_LTR
* @see NSBIDI_DEFAULT_RTL
* @see NSBIDI_LEVEL_OVERRIDE
* @see NSBIDI_MAX_EXPLICIT_LEVEL
*/
typedef uint8_t nsBidiLevel;
/**
* Paragraph level setting.
* If there is no strong character, then set the paragraph level to 0
* (left-to-right).
*/
#define NSBIDI_DEFAULT_LTR 0xfe
/**
* Paragraph level setting.
* If there is no strong character, then set the paragraph level to 1
* (right-to-left).
*/
#define NSBIDI_DEFAULT_RTL 0xff
/**
* Maximum explicit embedding level.
* (The maximum resolved level can be up to
* <code>NSBIDI_MAX_EXPLICIT_LEVEL+1</code>).
*/
#define NSBIDI_MAX_EXPLICIT_LEVEL 125
/** Bit flag for level input.
* Overrides directional properties.
*/
#define NSBIDI_LEVEL_OVERRIDE 0x80
/**
* <code>nsBidiDirection</code> values indicate the text direction.
*/
enum nsBidiDirection {
/** All left-to-right text This is a 0 value. */
NSBIDI_LTR,
/** All right-to-left text This is a 1 value. */
NSBIDI_RTL,
/** Mixed-directional text. */
NSBIDI_MIXED
};
namespace mozilla {
enum class BaselineSharingGroup {
// NOTE Used as an array index so must be 0 and 1.
First = 0,
Last = 1,
};
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();
}
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.
static const nsBidiLevel kBidiLevelNone = 0xff;
struct FrameBidiData {
nsBidiLevel baseLevel;
nsBidiLevel 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.
nsBidiLevel precedingControl;
};
} // 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;
//----------------------------------------------------------------------
/**
* 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;
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 LengthPercentage = mozilla::LengthPercentage;
typedef mozilla::ComputedStyle ComputedStyle;
typedef mozilla::FrameProperties FrameProperties;
typedef mozilla::layers::Layer Layer;
typedef mozilla::layers::LayerManager LayerManager;
typedef mozilla::layout::FrameChildList ChildList;
typedef mozilla::layout::FrameChildListID ChildListID;
typedef mozilla::layout::FrameChildListIDs ChildListIDs;
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<mozilla::DisplayItemData>
DisplayItemDataArray;
typedef mozilla::SmallPointerArray<nsDisplayItemBase> DisplayItemArray;
typedef nsQueryFrame::ClassID ClassID;
// nsQueryFrame
NS_DECL_QUERYFRAME
NS_DECL_QUERYFRAME_TARGET(nsIFrame)
explicit nsIFrame(ComputedStyle* aStyle, nsPresContext* aPresContext,
ClassID aID)
: mRect(),
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),
mHasOverrideDirtyRegion(false),
mMayHaveWillChangeBudget(false),
mIsPrimaryFrame(false),
mMayHaveTransformAnimation(false),
mMayHaveOpacityAnimation(false),
mAllDescendantsAreInvisible(false),
mHasBSizeChange(false),
mInScrollAnchorChain(false),
mHasColumnSpanSiblings(false),
mDescendantMayDependOnItsStaticPosition(false),
mShouldGenerateComputedInfo(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).
*
* Each subclass that need a view should override this method and call
* CreateView() after calling its base class Init().
*
* @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 PostDestroyData = mozilla::layout::PostFrameDestroyData;
struct MOZ_RAII AutoPostDestroyData {
explicit AutoPostDestroyData(nsPresContext* aPresContext)
: mPresContext(aPresContext) {}
~AutoPostDestroyData() {
for (auto& content : mozilla::Reversed(mData.mAnonymousContent)) {
nsIFrame::DestroyAnonymousContent(mPresContext, content.forget());
}
}
nsPresContext* mPresContext;
PostDestroyData mData;
};
/**
* Destroys this frame and each of its child frames (recursively calls
* Destroy() for each child). If this frame is a first-continuation, this
* also removes the frame from the primary frame map and clears undisplayed
* content for its content node.
* If the frame is a placeholder, it also ensures the out-of-flow frame's
* removal and destruction.
*/
void Destroy() {
AutoPostDestroyData data(PresContext());
DestroyFrom(this, data.mData);
// Note that |this| is deleted at this point.
}
/**
* 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) {}
};
protected:
friend class nsBlockFrame; // for access to DestroyFrom
/**
* Return true if the frame is part of a Selection.
* Helper method to implement the public IsSelected() API.
*/
virtual bool IsFrameSelected() const;
/**
* Implements Destroy(). Do not call this directly except from within a
* DestroyFrom() implementation.
*
* @note This will always be called, so it is not necessary to override
* Destroy() in subclasses of nsFrame, just DestroyFrom().
*
* @param aDestructRoot is the root of the subtree being destroyed
*/
virtual void DestroyFrom(nsIFrame* aDestructRoot,
PostDestroyData& aPostDestroyData);
friend class nsFrameList; // needed to pass aDestructRoot through to children
friend class nsLineBox; // needed to pass aDestructRoot through to children
friend class nsContainerFrame; // needed to pass aDestructRoot through to
// children
template <class Source>
friend class do_QueryFrameHelper; // to read mClass
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.
*/
nsIContent* GetContent() const { return mContent; }
/**
* 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 frames implementing
* nsIScrollableFrame this will return the frame itself. For frames
* like nsTextControlFrame that contain a scrollframe, will return
* that scrollframe.
*/
virtual nsIScrollableFrame* GetScrollTargetFrame() const { return nullptr; }
/**
* Get the offsets of the frame. most will be 0,0
*
*/
virtual nsresult GetOffsets(int32_t& start, int32_t& end) 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;
/**
* 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.
* If the frame may have moved into or out of a scrollframe's
* frame subtree,
* StickyScrollContainer::NotifyReparentedFrameAcrossScrollFrameBoundary must
* also be called.
*/
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 nsHTMLScrollFrame::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)));
}
/**
* 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) {
if (mRect.TopLeft() == aPt) {
return;
}
mRect.MoveTo(aPt);
MarkNeedsDisplayItemRebuild();
}
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;
/**
* 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_DELETABLE(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(CachedBorderImageDataProperty,
CachedBorderImageData)
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)
NS_DECLARE_FRAME_PROPERTY_DELETABLE(UsedBorderProperty, nsMargin)
NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(LineBaselineOffset, nscoord)
NS_DECLARE_FRAME_PROPERTY_DELETABLE(InvalidationRect, nsRect)
NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(RefusedAsyncAnimationProperty, bool)
NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(FragStretchBSizeProperty, nscoord)
// The block-axis margin-box size associated with eBClampMarginBoxMinSize.
NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(BClampMarginBoxMinSizeProperty, nscoord)
NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(IBaselinePadProperty, nscoord)
NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(BBaselinePadProperty, nscoord)
NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(BidiDataProperty,
mozilla::FrameBidiData)
NS_DECLARE_FRAME_PROPERTY_WITHOUT_DTOR(PlaceholderFrameProperty,
nsPlaceholderFrame)
NS_DECLARE_FRAME_PROPERTY_RELEASABLE(OffsetPathCache, mozilla::gfx::Path)
NS_DECLARE_FRAME_PROPERTY_DELETABLE(DisplayItemDataProperty,
DisplayItemDataArray)
mozilla::FrameBidiData GetBidiData() const {
bool exists;
mozilla::FrameBidiData bidiData = GetProperty(BidiDataProperty(), &exists);
if (!exists) {
bidiData.precedingControl = mozilla::kBidiLevelNone;
}
return bidiData;
}
nsBidiLevel GetBaseLevel() const { return GetBidiData().baseLevel; }
nsBidiLevel GetEmbeddingLevel() const { return GetBidiData().embeddingLevel; }
/**
* Return the distance between the border edge of the frame and the
* margin edge of the frame. Like GetRect(), returns the dimensions
* as of the most recent reflow.
*
* This doesn't include any margin collapsing that may have occurred.
* It also doesn't consider GetSkipSides()/GetLogicalSkipSides(), so
* may report nonzero values on sides that are actually skipped for
* this fragment.
*
* It also treats 'auto' margins as zero, and treats any margins that
* should have been turned into 'auto' because of overconstraint as
* having their original values.
*/
virtual nsMargin GetUsedMargin() const;
virtual mozilla::LogicalMargin GetLogicalUsedMargin(
mozilla::WritingMode aWritingMode) const {
return mozilla::LogicalMargin(aWritingMode, GetUsedMargin());
}
/**
* Return the distance between the border edge of the frame (which is
* its rect) and the padding edge of the frame. Like GetRect(), returns
* the dimensions as of the most recent reflow.
*
* This doesn't consider GetSkipSides()/GetLogicalSkipSides(), so
* may report nonzero values on sides that are actually skipped for
* this fragment.
*
* Note that this differs from StyleBorder()->GetComputedBorder() in
* that this describes a region of the frame's box, and
* StyleBorder()->GetComputedBorder() describes a border. They differ
* for tables (particularly border-collapse tables) and themed
* elements.
*/
virtual nsMargin GetUsedBorder() const;
virtual mozilla::LogicalMargin GetLogicalUsedBorder(
mozilla::WritingMode aWritingMode) const {
return mozilla::LogicalMargin(aWritingMode, GetUsedBorder());
}
/**
* Return the distance between the padding edge of the frame and the
* content edge of the frame. Like GetRect(), returns the dimensions
* as of the most recent reflow.
*
* This doesn't consider GetSkipSides()/GetLogicalSkipSides(), so
* may report nonzero values on sides that are actually skipped for
* this fragment.
*/
virtual nsMargin GetUsedPadding() const;
virtual mozilla::LogicalMargin GetLogicalUsedPadding(
mozilla::WritingMode aWritingMode) const {
return mozilla::LogicalMargin(aWritingMode, GetUsedPadding());
}
nsMargin GetUsedBorderAndPadding() const {
return GetUsedBorder() + GetUsedPadding();
}
mozilla::LogicalMargin GetLogicalUsedBorderAndPadding(
mozilla::WritingMode aWritingMode) const {
return mozilla::LogicalMargin(aWritingMode, GetUsedBorderAndPadding());
}
/**
* The area to paint box-shadows around. The default is the border rect.
* (nsFieldSetFrame overrides this).
*/
virtual nsRect VisualBorderRectRelativeToSelf() const {
return nsRect(0, 0, mRect.Width(), mRect.Height());
}
/**
* Get the size, in app units, of the border radii. It returns FALSE iff all
* returned radii == 0 (so no border radii), TRUE otherwise.
* For the aRadii indexes, use the enum HalfCorner constants in gfx/2d/Types.h
* If a side is skipped via aSkipSides, its corners are forced to 0.
*
* All corner radii are then adjusted so they do not require more
* space than aBorderArea, according to the algorithm in css3-background.
*
* aFrameSize is used as the basis for percentage widths and heights.
* aBorderArea is used for the adjustment of radii that might be too
* large.
* FIXME: In the long run, we can probably get away with only one of
* these, especially if we change the way we handle outline-radius (by
* removing it and inflating the border radius)
*
* Return whether any radii are nonzero.
*/
static bool ComputeBorderRadii(const mozilla::BorderRadius&,
const nsSize& aFrameSize,
const nsSize& aBorderArea, Sides aSkipSides,
nscoord aRadii[8]);
/*
* Given a set of border radii for one box (e.g., border box), convert
* it to the equivalent set of radii for another box (e.g., in to
* padding box, out to outline box) by reducing radii or increasing
* nonzero radii as appropriate.
*
* Indices into aRadii are the enum HalfCorner constants in gfx/2d/Types.h
*
* Note that InsetBorderRadii is lossy, since it can turn nonzero
* radii into zero, and OutsetBorderRadii does not inflate zero radii.
* Therefore, callers should always inset or outset directly from the
* original value coming from style.
*/
static void InsetBorderRadii(nscoord aRadii[8], const nsMargin& aOffsets);
static void OutsetBorderRadii(nscoord aRadii[8], const nsMargin& aOffsets);
/**
* Fill in border radii for this frame. Return whether any are nonzero.
* Indices into aRadii are the enum HalfCorner constants in gfx/2d/Types.h
* aSkipSides is a union of SideBits::eLeft/Right/Top/Bottom bits that says
* which side(s) to skip.
*
* Note: GetMarginBoxBorderRadii() and GetShapeBoxBorderRadii() work only
* on frames that establish block formatting contexts since they don't
* participate in margin-collapsing.
*/
virtual bool GetBorderRadii(const nsSize& aFrameSize,
const nsSize& aBorderArea, Sides aSkipSides,
nscoord aRadii[8]) const;
bool GetBorderRadii(nscoord aRadii[8]) const;
bool GetMarginBoxBorderRadii(nscoord aRadii[8]) const;
bool GetPaddingBoxBorderRadii(nscoord aRadii[8]) const;
bool GetContentBoxBorderRadii(nscoord aRadii[8]) const;
bool GetBoxBorderRadii(nscoord aRadii[8], nsMargin aOffset,
bool aIsOutset) const;
bool GetShapeBoxBorderRadii(nscoord aRadii[8]) const;
/**
* XXX: this method will likely be replaced by GetVerticalAlignBaseline
* Get the position of the frame's baseline, relative to the top of
* the frame (its top border edge). Only valid when Reflow is not
* needed.
* @note You should only call this on frames with a WM that's parallel to
* aWritingMode.
* @param aWritingMode the writing-mode of the alignment context, with the
* ltr/rtl direction tweak done by nsIFrame::GetWritingMode(nsIFrame*) in
* inline contexts (see that method).
*/
virtual nscoord GetLogicalBaseline(mozilla::WritingMode aWritingMode) const;
/**
* Synthesize a first(last) inline-axis baseline based on our margin-box.
* An alphabetical baseline is at the start(end) edge and a central baseline
* is at the center of our block-axis margin-box (aWM tells which to use).
* @note You should only call this on frames with a WM that's parallel to aWM.
* @param aWM the writing-mode of the alignment context
* @return an offset from our border-box block-axis start(end) edge for
* a first(last) baseline respectively
* (implemented in nsIFrameInlines.h)
*/
inline nscoord SynthesizeBaselineBOffsetFromMarginBox(
mozilla::WritingMode aWM, BaselineSharingGroup aGroup) const;
/**
* Synthesize a first(last) inline-axis baseline based on our border-box.
* An alphabetical baseline is at the start(end) edge and a central baseline
* is at the center of our block-axis border-box (aWM tells which to use).
* @note The returned value is only valid when reflow is not needed.
* @note You should only call this on frames with a WM that's parallel to aWM.
* @param aWM the writing-mode of the alignment context
* @return an offset from our border-box block-axis start(end) edge for
* a first(last) baseline respectively
* (implemented in nsIFrameInlines.h)
*/
inline nscoord SynthesizeBaselineBOffsetFromBorderBox(
mozilla::WritingMode aWM, BaselineSharingGroup aGroup) const;
/**
* Synthesize a first(last) inline-axis baseline based on our content-box.
* An alphabetical baseline is at the start(end) edge and a central baseline
* is at the center of our block-axis content-box (aWM tells which to use).
* @note The returned value is only valid when reflow is not needed.
* @note You should only call this on frames with a WM that's parallel to aWM.
* @param aWM the writing-mode of the alignment context
* @return an offset from our border-box block-axis start(end) edge for
* a first(last) baseline respectively
* (implemented in nsIFrameInlines.h)
*/
inline nscoord SynthesizeBaselineBOffsetFromContentBox(
mozilla::WritingMode aWM, BaselineSharingGroup aGroup) const;
/**
* Return the position of the frame's inline-axis baseline, or synthesize one
* for the given alignment context. The returned baseline is the distance from
* the block-axis border-box start(end) edge for aBaselineGroup ::First(Last).
* @note The returned value is only valid when reflow is not needed.
* @note You should only call this on frames with a WM that's parallel to aWM.
* @param aWM the writing-mode of the alignment context
* @param aBaselineOffset out-param, only valid if the method returns true
* (implemented in nsIFrameInlines.h)
*/
inline nscoord BaselineBOffset(mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
AlignmentContext aAlignmentContext) const;
/**
* XXX: this method is taking over the role that GetLogicalBaseline has.
* Return true if the frame has a CSS2 'vertical-align' baseline.
* If it has, then the returned baseline is the distance from the block-
* axis border-box start edge.
* @note This method should only be used in AlignmentContext::Inline
* contexts.
* @note The returned value is only valid when reflow is not needed.
* @note You should only call this on frames with a WM that's parallel to aWM.
* @param aWM the writing-mode of the alignment context
* @param aBaseline the baseline offset, only valid if the method returns true
*/
virtual bool GetVerticalAlignBaseline(mozilla::WritingMode aWM,
nscoord* aBaseline) const {
return false;
}
/**
* Return true if the frame has a first(last) inline-axis natural baseline per
* CSS Box Alignment. If so, then the returned baseline is the distance from
* the block-axis border-box start(end) edge for aBaselineGroup ::First(Last).
* @note The returned value is only valid when reflow is not needed.
* @note You should only call this on frames with a WM that's parallel to aWM.
* @param aWM the writing-mode of the alignment context
* @param aBaseline the baseline offset, only valid if the method returns true
*/
virtual bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
nscoord* aBaseline) const {
return false;
}