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 */
/* interface for all rendering objects */
#ifndef nsIFrame_h___
#define nsIFrame_h___
#error This header/class should only be used within Mozilla code. It should not be used by extensions.
#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
// 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
/* 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"
# include "mozilla/a11y/AccTypes.h"
* 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 nsILineIterator;
class gfxSkipChars;
class gfxSkipCharsIterator;
class gfxContext;
class nsLineList_iterator;
class nsAbsoluteContainingBlock;
class nsContainerFrame;
class nsPlaceholderFrame;
class nsStyleChangeList;
class nsViewManager;
class nsWindowSizes;
struct CharacterDataChangeInfo;
namespace mozilla {
enum class CaretAssociationHint;
enum class PeekOffsetOption : uint16_t;
enum class PseudoStyleType : uint8_t;
enum class TableSelectionMode : uint32_t;
class nsDisplayItem;
class nsDisplayList;
class nsDisplayListBuilder;
class nsDisplayListSet;
class ServoRestyleState;
class EffectSet;
class LazyLogModule;
class PresShell;
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"
} // 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 {
: mFloatClearType(mozilla::StyleClear::None),
mFirstLetterComplete(false) {}
// Reset all the member variables.
void Reset() {
mFloatClearType = mozilla::StyleClear::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 &&
// 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.
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.)
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 {
bool IsInlineBreak() const { return mInlineBreak != InlineBreak::None; }
bool IsInlineBreakBefore() const {
return mInlineBreak == InlineBreak::Before;
bool IsInlineBreakAfter() const { return mInlineBreak == InlineBreak::After; }
mozilla::StyleClear 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() {
mFloatClearType = mozilla::StyleClear::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::StyleClear aClearType = mozilla::StyleClear::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; }
mozilla::StyleClear 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 {
* 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();
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;
} // 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) {
* 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_LOG_TEST(_lm, _bit) \
(int(((mozilla::LogModule*)(_lm))->Level()) & (_bit))
#ifdef DEBUG
# define NS_FRAME_LOG(_bit, _args) \
if (NS_FRAME_LOG_TEST(nsIFrame::sFrameLogModule, _bit)) { \
printf_stderr _args; \
} \
# define NS_FRAME_LOG(_bit, _args)
// 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) \
if (NS_FRAME_LOG_TEST(nsIFrame::sFrameLogModule, _bit)) { \
TraceMsg _args; \
} \
# define NS_FRAME_TRACE_REFLOW_IN(_method) Trace(_method, true)
# define NS_FRAME_TRACE_REFLOW_OUT(_method, _status) \
Trace(_method, false, _status)
# 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)
// 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).
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; \
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) {
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,
// Frame that contains a block but looks like a replaced element from the
// outside.
ReplacedContainsBlock = 1 << 7,
// 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 << 8,
// A frame that participates in inline reflow, i.e., one that requires
// ReflowInput::mLineLayout.
LineParticipant = 1 << 9,
// Whether this frame is a table part (but not a table or table wrapper).
TablePart = 1 << 10,
CanContainOverflowContainers = 1 << 11,
// Whether the frame supports CSS transforms.
SupportsCSSTransforms = 1 << 12,
// Whether this frame class supports 'contain: layout' and 'contain: paint'
// (supporting one is equivalent to supporting the other).
SupportsContainLayoutAndPaint = 1 << 13,
// Whether this frame class supports the `aspect-ratio` property.
SupportsAspectRatio = 1 << 14,
// Whether this frame class is always a BFC.
BlockFormattingContext = 1 << 15,
} // 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 {
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 LengthPercentage = mozilla::LengthPercentage;
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;
using ChildList = mozilla::FrameChildList;
using ChildListID = mozilla::FrameChildListID;
using ChildListIDs = mozilla::FrameChildListIDs;
// nsQueryFrame
explicit nsIFrame(ComputedStyle* aStyle, nsPresContext* aPresContext,
ClassID aID)
: mContent(nullptr),
#ifdef DEBUG
mDescendantMayDependOnItsStaticPosition(false) {
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 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.
// offset not found because the frame was empty of text.
// offset not found because the frame didn't contain any text that could be
// selected.
* 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;
: mRespectClusters(true), mIgnoreUserStyleAll(false) {}
virtual void Destroy(DestroyContext&);
* 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);
// 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();
* Get the content object associated with this frame. Does not add a
* reference.
nsIContent* GetContent() const { return mContent; }
* @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 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 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&)
void SetComputedStyle(ComputedStyle* aStyle) {
if (aStyle != mComputedStyle) {
RefPtr<ComputedStyle> oldComputedStyle = std::move(mComputedStyle);
mComputedStyle = aStyle;
* 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;
// 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);
* 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"
/** 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 {
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)
.ConvertTo(aWritingMode, wm);
const auto size = GetLogicalSize(aWritingMode);
return mozilla::LogicalSize(
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) {
if (mOverflow.mType != OverflowStorageType::Large &&
mOverflow.mType != OverflowStorageType::None) {
mozilla::OverflowAreas overflow = GetOverflowAreas();
mRect = aRect;
} else {
mRect = aRect;
if (aRebuildDisplayItems) {
* 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();
mRect.x -= mRect.Width() - oldWidth;
} else {
* 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.
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;
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!
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; \
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; \
static void AssertOnDestroyingProperty##prop(type*) { \
"Frame property " #prop \
" should never be destroyed by the FrameProperties class"); \
} \
NS_DECLARE_FRAME_PROPERTY_WITHOUT_DTOR(prop, mozilla::SmallValueHolder<type>)
// 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.
#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)
// 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;
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())) {
return values->mEndPageValue;
return nullptr;
// Returns the page name based on style information for this frame, or null
// if the value is auto.
const nsAtom* GetStylePageName() const {
const mozilla::StylePageName& pageName = StylePage()->mPage;
if (pageName.IsPageName()) {
return pageName.AsPageName().AsAtom();
MOZ_ASSERT(pageName.IsAuto(), "Impossible page name");
return nullptr;
bool HasUnreflowedContainerQueryAncestor() const;
// The value that the CSS page-name "auto" keyword resolves to for children
// of this frame.
// A missing value for this property indicates that the auto value is the
// empty string, which is the default if no ancestors of a frame specify a
// page name. This avoids ever storing this property if the document doesn't
// use named pages.
// Ideally this would be a const atom, but that isn't possible with the
// Release() call. This isn't too bad, since it's hidden behind constness-
// preserving getter/setter.
// Get the value that the CSS page-name "auto" keyword resolves to for
// children of this frame.
// This is needed when propagating page-name values up the frame tree.
const nsAtom* GetAutoPageValue() const {
if (const nsAtom* const atom = GetProperty(AutoPageValueProperty())) {
return atom;
return nsGkAtoms::_empty;
void SetAutoPageValue(const nsAtom* aAtom) {
MOZ_ASSERT(aAtom, "Atom must not be null");
nsAtom* const atom = const_cast<nsAtom*>(aAtom);
if (atom != nsGkAtoms::_empty) {
SetProperty(AutoPageValueProperty(), do_AddRef(atom).take());
NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(RefusedAsyncAnimationProperty, bool)
// The block-axis margin-box size associated with eBClampMarginBoxMinSize.
NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(BClampMarginBoxMinSizeProperty, nscoord)
NS_DECLARE_FRAME_PROPERTY_RELEASABLE(OffsetPathCache, mozilla::gfx::Path)
mozilla::FrameBidiData GetBidiData() const {
bool exists;
mozilla::FrameBidiData bidiData = GetProperty(BidiDataProperty(), &exists);
if (!exists) {
bidiData.precedingControl = mozilla::kBidiLevelNone;
return bidiData;
mozilla::intl::BidiEmbeddingLevel GetBaseLevel() const {
return GetBidiData().baseLevel;
mozilla::intl::BidiEmbeddingLevel 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.
* 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 insetting the radii is lossy, since it can turn nonzero radii
* into zero, and re-adjusting does not inflate zero radii.
* Therefore, callers should always adjust directly from the original value
* coming from style.
static void AdjustBorderRadii(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], const nsMargin& aOffset) const;
bool GetShapeBoxBorderRadii(nscoord aRadii[8]) const;
* Returns one em unit, adjusted for font inflation if needed, in app units.
nscoord OneEmInAppUnits() const;
* `GetNaturalBaselineBOffset`, but determines the baseline sharing group
* through `GetDefaultBaselineSharingGroup` (If not specified), assuming line
* layout context, and never fails, returning a synthesized baseline through
* `SynthesizeFallbackBaseline`. Unlike `GetNaturalBaselineBOffset`, Result is
* always relative to the block start of the frame.
nscoord GetLogicalBaseline(mozilla::WritingMode aWM) const;
* Same as the above, but with baseline sharing group & export
* context specified.
nscoord GetLogicalBaseline(mozilla::WritingMode aWM,
BaselineSharingGroup aBaselineGroup,
BaselineExportContext aExportContext) const;
* Return true if the frame has a first(last) inline-axis baseline per
* CSS Box Alignment. If so, the returned baseline is the distance from
* the relevant block-axis border-box edge (Start for
* BaselineSharingGroup::First, end for BaselineSharingGroup::Last), where
* a positive value points towards the content-box.
* Some frames can export different baselines depending if it's in a line
* layout context or any other context (e.g. Flex, grid).
* @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.
* @note We're approaching `nsLayoutUtils::Get(First|Last)LineBaseline` ==
* `GetNaturalBaselineBOffset(aWM, (First|Last), Other)`. Grid relies on
* baseline synthesis behaviour in `nsLayoutUtils` implementations (bug
* 1609403), which blocks its removal.
* @param aWM the writing-mode of the alignment context.
* @return the baseline offset, if one exists
virtual Maybe<nscoord> GetNaturalBaselineBOffset(
mozilla::WritingMode aWM, BaselineSharingGroup aBaselineGroup,
BaselineExportContext aExportContext) const {
return Nothing{};
struct CaretBlockAxisMetrics {
nscoord mOffset = 0;
nscoord mExtent = 0;
* Get the offset (Block start of the caret) and extent of the caret in this
* frame. The returned offset is corrected for vertical & line-inverted
* writing modes.
CaretBlockAxisMetrics GetCaretBlockAxisMetrics(mozilla::WritingMode,
const nsFontMetrics&) const;
// Gets the page-name value to be used for the page that contains this frame
// during paginated reflow.
// This only inspects the first in-flow child of this frame, and if that
// is a container frame then its first in-flow child, until it reaches the
// deepest child of the tree.
// This will resolve auto values, including the case where no frame has a
// page-name set in which case it will return the empty atom. It will never
// return null.
// This is intended to be used either on the root frame to find the first
// page's page-name, or on a newly created continuation to find what the new
// page's page-name will be.