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/. */
8 * Inlined methods for ComputedStyle. Will just redirect to
9 * GeckoComputedStyle methods when compiled without stylo, but will do
10 * virtual dispatch (by checking which kind of container it is)
14 #ifndef ComputedStyleInlines_h
15 #define ComputedStyleInlines_h
17 #include "mozilla/ComputedStyle.h"
19 #include "MainThreadUtils.h"
20 #include "mozilla/Assertions.h"
21 #include "mozilla/Unused.h"
22 #include "nsStyleStructInlines.h"
28 template <typename T
, typename Enable
= void>
29 struct HasTriggerImageLoads
: public std::false_type
{};
32 struct HasTriggerImageLoads
<T
, decltype(std::declval
<T
&>().TriggerImageLoads(
33 std::declval
<dom::Document
&>(), nullptr))>
34 : public std::true_type
{};
36 template <typename T
, const T
* (ComputedStyle::*Method
)() const>
37 void TriggerImageLoads(dom::Document
& aDocument
, const ComputedStyle
* aOldStyle
,
38 ComputedStyle
* aStyle
) {
39 if constexpr (HasTriggerImageLoads
<T
>::value
) {
40 auto* old
= aOldStyle
? (aOldStyle
->*Method
)() : nullptr;
41 auto* current
= const_cast<T
*>((aStyle
->*Method
)());
42 current
->TriggerImageLoads(aDocument
, old
);
51 void ComputedStyle::StartImageLoads(dom::Document
& aDocument
,
52 const ComputedStyle
* aOldStyle
) {
53 MOZ_ASSERT(NS_IsMainThread());
55 #define STYLE_STRUCT(name_) \
56 detail::TriggerImageLoads<nsStyle##name_, &ComputedStyle::Style##name_>( \
57 aDocument, aOldStyle, this);
58 #include "nsStyleStructList.h"
62 StylePointerEvents
ComputedStyle::PointerEvents() const {
63 if (IsRootElementStyle()) {
64 // The root frame is not allowed to have pointer-events: none, or else no
65 // frames could be hit test against and scrolling the viewport would not
67 return StylePointerEvents::Auto
;
69 const auto& ui
= *StyleUI();
71 return StylePointerEvents::None
;
73 return ui
.ComputedPointerEvents();
76 StyleUserSelect
ComputedStyle::UserSelect() const {
77 return StyleUI()->IsInert() ? StyleUserSelect::None
78 : StyleUIReset()->ComputedUserSelect();
81 bool ComputedStyle::IsFixedPosContainingBlockForNonSVGTextFrames() const {
82 // NOTE: Any CSS properties that influence the output of this function
83 // should return FIXPOS_CB_NON_SVG for will-change.
84 if (IsRootElementStyle()) {
88 const auto& disp
= *StyleDisplay();
89 if (disp
.mWillChange
.bits
& mozilla::StyleWillChangeBits::FIXPOS_CB_NON_SVG
) {
93 const auto& effects
= *StyleEffects();
94 return effects
.HasFilters() || effects
.HasBackdropFilters();
97 bool ComputedStyle::IsFixedPosContainingBlock(
98 const nsIFrame
* aContextFrame
) const {
99 // NOTE: Any CSS properties that influence the output of this function
100 // should also handle will-change appropriately.
101 if (aContextFrame
->IsInSVGTextSubtree()) {
104 if (IsFixedPosContainingBlockForNonSVGTextFrames()) {
107 const auto& disp
= *StyleDisplay();
108 if (disp
.IsFixedPosContainingBlockForContainLayoutAndPaintSupportingFrames() &&
109 aContextFrame
->SupportsContainLayoutAndPaint()) {
112 if (disp
.IsFixedPosContainingBlockForTransformSupportingFrames() &&
113 aContextFrame
->SupportsCSSTransforms()) {
119 bool ComputedStyle::IsAbsPosContainingBlock(
120 const nsIFrame
* aContextFrame
) const {
121 if (IsFixedPosContainingBlock(aContextFrame
)) {
124 // NOTE: Any CSS properties that influence the output of this function
125 // should also handle will-change appropriately.
126 return StyleDisplay()->IsPositionedStyle() &&
127 !aContextFrame
->IsInSVGTextSubtree();
130 } // namespace mozilla
132 #endif // ComputedStyleInlines_h