Bug 1885565 - Part 1: Add mozac_ic_avatar_circle_24 to ui-icons r=android-reviewers...
[gecko.git] / layout / style / ComputedStyleInlines.h
blobf9e87c808fc2c78ed8d7cb26c33bf44c88272261
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 /*
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)
11 * in stylo mode.
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"
24 namespace mozilla {
26 namespace detail {
28 template <typename T, typename Enable = void>
29 struct HasTriggerImageLoads : public std::false_type {};
31 template <typename T>
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);
43 } else {
44 Unused << aOldStyle;
45 Unused << aStyle;
49 } // namespace detail
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"
59 #undef STYLE_STRUCT
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
66 // work.
67 return StylePointerEvents::Auto;
69 const auto& ui = *StyleUI();
70 if (ui.IsInert()) {
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()) {
85 return false;
88 const auto& disp = *StyleDisplay();
89 if (disp.mWillChange.bits & mozilla::StyleWillChangeBits::FIXPOS_CB_NON_SVG) {
90 return true;
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()) {
102 return false;
104 if (IsFixedPosContainingBlockForNonSVGTextFrames()) {
105 return true;
107 const auto& disp = *StyleDisplay();
108 if (disp.IsFixedPosContainingBlockForContainLayoutAndPaintSupportingFrames() &&
109 aContextFrame->SupportsContainLayoutAndPaint()) {
110 return true;
112 if (disp.IsFixedPosContainingBlockForTransformSupportingFrames() &&
113 aContextFrame->SupportsCSSTransforms()) {
114 return true;
116 return false;
119 bool ComputedStyle::IsAbsPosContainingBlock(
120 const nsIFrame* aContextFrame) const {
121 if (IsFixedPosContainingBlock(aContextFrame)) {
122 return true;
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