Backed out changeset 496886cb30a5 (bug 1867152) for bc failures on browser_user_input...
[gecko.git] / layout / generic / nsIFrameInlines.h
blobe187f0dfb0bc135169875bdad7329ce512a41cb4
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsIFrameInlines_h___
8 #define nsIFrameInlines_h___
10 #include "mozilla/dom/ElementInlines.h"
11 #include "mozilla/ComputedStyleInlines.h"
12 #include "nsContainerFrame.h"
13 #include "nsLayoutUtils.h"
14 #include "nsPlaceholderFrame.h"
15 #include "nsCSSAnonBoxes.h"
16 #include "nsFrameManager.h"
18 bool nsIFrame::IsFlexItem() const {
19 return GetParent() && GetParent()->IsFlexContainerFrame() &&
20 !HasAnyStateBits(NS_FRAME_OUT_OF_FLOW);
23 bool nsIFrame::IsGridItem() const {
24 return GetParent() && GetParent()->IsGridContainerFrame() &&
25 !HasAnyStateBits(NS_FRAME_OUT_OF_FLOW);
28 bool nsIFrame::IsFlexOrGridContainer() const {
29 return IsFlexContainerFrame() || IsGridContainerFrame();
32 bool nsIFrame::IsFlexOrGridItem() const {
33 return !HasAnyStateBits(NS_FRAME_OUT_OF_FLOW) && GetParent() &&
34 GetParent()->IsFlexOrGridContainer();
37 bool nsIFrame::IsMasonry(mozilla::LogicalAxis aAxis) const {
38 MOZ_DIAGNOSTIC_ASSERT(IsGridContainerFrame());
39 return HasAnyStateBits(aAxis == mozilla::eLogicalAxisBlock
40 ? NS_STATE_GRID_IS_ROW_MASONRY
41 : NS_STATE_GRID_IS_COL_MASONRY);
44 bool nsIFrame::IsTableCaption() const {
45 return StyleDisplay()->mDisplay == mozilla::StyleDisplay::TableCaption &&
46 GetParent()->Style()->GetPseudoType() ==
47 mozilla::PseudoStyleType::tableWrapper;
50 bool nsIFrame::IsFloating() const {
51 return HasAnyStateBits(NS_FRAME_OUT_OF_FLOW) &&
52 StyleDisplay()->IsFloating(this);
55 bool nsIFrame::IsAbsPosContainingBlock() const {
56 return Style()->IsAbsPosContainingBlock(this);
59 bool nsIFrame::IsFixedPosContainingBlock() const {
60 return Style()->IsFixedPosContainingBlock(this);
63 bool nsIFrame::IsRelativelyOrStickyPositioned() const {
64 return StyleDisplay()->IsRelativelyOrStickyPositioned(this);
67 bool nsIFrame::IsRelativelyPositioned() const {
68 return StyleDisplay()->IsRelativelyPositioned(this);
71 bool nsIFrame::IsStickyPositioned() const {
72 return StyleDisplay()->IsStickyPositioned(this);
75 bool nsIFrame::IsAbsolutelyPositioned(
76 const nsStyleDisplay* aStyleDisplay) const {
77 return HasAnyStateBits(NS_FRAME_OUT_OF_FLOW) &&
78 StyleDisplayWithOptionalParam(aStyleDisplay)
79 ->IsAbsolutelyPositioned(this);
82 inline bool nsIFrame::IsTrueOverflowContainer() const {
83 return HasAnyStateBits(NS_FRAME_IS_OVERFLOW_CONTAINER) &&
84 !IsAbsolutelyPositioned();
85 // XXXfr This check isn't quite correct, because it doesn't handle cases
86 // where the out-of-flow has overflow.. but that's rare.
87 // We'll need to revisit the way abspos continuations are handled later
88 // for various reasons, this detail is one of them. See bug 154892
91 bool nsIFrame::IsBlockOutside() const {
92 return StyleDisplay()->IsBlockOutside(this);
95 bool nsIFrame::IsInlineOutside() const {
96 return StyleDisplay()->IsInlineOutside(this);
99 bool nsIFrame::IsColumnSpan() const {
100 return IsBlockOutside() && StyleColumn()->IsColumnSpanStyle();
103 bool nsIFrame::IsColumnSpanInMulticolSubtree() const {
104 return IsColumnSpan() &&
105 (HasAnyStateBits(NS_FRAME_HAS_MULTI_COLUMN_ANCESTOR) ||
106 // A frame other than inline and block won't have
107 // NS_FRAME_HAS_MULTI_COLUMN_ANCESTOR. We instead test its parent.
108 (GetParent() && GetParent()->Style()->GetPseudoType() ==
109 mozilla::PseudoStyleType::columnSpanWrapper));
112 mozilla::StyleDisplay nsIFrame::GetDisplay() const {
113 return StyleDisplay()->GetDisplay(this);
116 void nsIFrame::PropagateWritingModeToSelfAndAncestors(
117 mozilla::WritingMode aWM) {
118 MOZ_ASSERT(IsCanvasFrame());
119 for (auto f = this; f; f = f->GetParent()) {
120 f->mWritingMode = aWM;
124 nsContainerFrame* nsIFrame::GetInFlowParent() const {
125 if (HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) {
126 nsIFrame* ph =
127 FirstContinuation()->GetProperty(nsIFrame::PlaceholderFrameProperty());
128 return ph->GetParent();
131 return GetParent();
134 // We generally want to follow the style tree for preserve-3d, jumping through
135 // display: contents.
137 // There are various fun mismatches between the flattened tree and the frame
138 // tree which makes this non-trivial to do looking at the frame tree state:
140 // - Anon boxes. You'd have to step through them, because you generally want to
141 // ignore them.
143 // - IB-splits, which produce a frame tree where frames for the block inside
144 // the inline are not children of any frame from the inline.
146 // - display: contents, which makes DOM ancestors not have frames even when a
147 // descendant does.
149 // See GetFlattenedTreeParentElementForStyle for the difference between it and
150 // plain GetFlattenedTreeParentElement.
151 nsIFrame* nsIFrame::GetClosestFlattenedTreeAncestorPrimaryFrame() const {
152 if (!mContent) {
153 return nullptr;
155 mozilla::dom::Element* parent =
156 mContent->GetFlattenedTreeParentElementForStyle();
157 while (parent) {
158 if (nsIFrame* frame = parent->GetPrimaryFrame()) {
159 return frame;
161 // NOTE(emilio): This should be an assert except we have code in tree which
162 // violates invariants like the <frameset> frame construction code.
163 if (MOZ_UNLIKELY(!parent->IsDisplayContents())) {
164 return nullptr;
166 parent = parent->GetFlattenedTreeParentElementForStyle();
168 return nullptr;
171 nsPoint nsIFrame::GetNormalPosition(bool* aHasProperty) const {
172 bool hasProperty;
173 nsPoint normalPosition = GetProperty(NormalPositionProperty(), &hasProperty);
174 if (aHasProperty) {
175 *aHasProperty = hasProperty;
177 return hasProperty ? normalPosition : GetPosition();
180 mozilla::LogicalPoint nsIFrame::GetLogicalNormalPosition(
181 mozilla::WritingMode aWritingMode, const nsSize& aContainerSize) const {
182 // Subtract the size of this frame from the container size to get
183 // the correct position in rtl frames where the origin is on the
184 // right instead of the left
185 return mozilla::LogicalPoint(aWritingMode, GetNormalPosition(),
186 aContainerSize - mRect.Size());
189 #endif