ComputedStyleInlines.h (4338B)
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/. */ 6 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. 12 */ 13 14 #ifndef ComputedStyleInlines_h 15 #define ComputedStyleInlines_h 16 17 #include "MainThreadUtils.h" 18 #include "mozilla/Assertions.h" 19 #include "mozilla/ComputedStyle.h" 20 #include "nsStyleStructInlines.h" 21 #include "nsStyleStructList.h" 22 23 namespace mozilla { 24 25 namespace detail { 26 27 template <typename T, typename Enable = void> 28 struct HasTriggerImageLoads : public std::false_type {}; 29 30 template <typename T> 31 struct HasTriggerImageLoads<T, decltype(std::declval<T&>().TriggerImageLoads( 32 std::declval<dom::Document&>(), nullptr))> 33 : public std::true_type {}; 34 35 template <typename T, const T* (ComputedStyle::*Method)() const> 36 void TriggerImageLoads(dom::Document& aDocument, const ComputedStyle* aOldStyle, 37 ComputedStyle* aStyle) { 38 if constexpr (HasTriggerImageLoads<T>::value) { 39 auto* old = aOldStyle ? (aOldStyle->*Method)() : nullptr; 40 auto* current = const_cast<T*>((aStyle->*Method)()); 41 current->TriggerImageLoads(aDocument, old); 42 } else { 43 (void)aOldStyle; 44 (void)aStyle; 45 } 46 } 47 48 } // namespace detail 49 50 void ComputedStyle::StartImageLoads(dom::Document& aDocument, 51 const ComputedStyle* aOldStyle) { 52 MOZ_ASSERT(NS_IsMainThread()); 53 54 #define TRIGGER_IMAGE_LOADS(name_) \ 55 detail::TriggerImageLoads<nsStyle##name_, &ComputedStyle::Style##name_>( \ 56 aDocument, aOldStyle, this); 57 FOR_EACH_STYLE_STRUCT(TRIGGER_IMAGE_LOADS, TRIGGER_IMAGE_LOADS) 58 #undef TRIGGER_IMAGE_LOADS 59 } 60 61 StylePointerEvents ComputedStyle::PointerEvents() const { 62 if (IsRootElementStyle()) { 63 // The root frame is not allowed to have pointer-events: none, or else no 64 // frames could be hit test against and scrolling the viewport would not 65 // work. 66 return StylePointerEvents::Auto; 67 } 68 const auto& ui = *StyleUI(); 69 if (ui.IsInert()) { 70 return StylePointerEvents::None; 71 } 72 return ui.ComputedPointerEvents(); 73 } 74 75 StyleUserSelect ComputedStyle::UserSelect() const { 76 return StyleUI()->IsInert() ? StyleUserSelect::None 77 : StyleUIReset()->ComputedUserSelect(); 78 } 79 80 bool ComputedStyle::IsFixedPosContainingBlockForNonSVGTextFrames() const { 81 // NOTE: Any CSS properties that influence the output of this function 82 // should return FIXPOS_CB_NON_SVG for will-change. 83 if (IsRootElementStyle()) { 84 return false; 85 } 86 87 const auto& disp = *StyleDisplay(); 88 if (disp.mWillChange.bits & mozilla::StyleWillChangeBits::FIXPOS_CB_NON_SVG) { 89 return true; 90 } 91 92 const auto& effects = *StyleEffects(); 93 return effects.HasFilters() || effects.HasBackdropFilters(); 94 } 95 96 bool ComputedStyle::IsFixedPosContainingBlock( 97 const nsIFrame* aContextFrame) const { 98 // NOTE: Any CSS properties that influence the output of this function 99 // should also handle will-change appropriately. 100 if (aContextFrame->IsInSVGTextSubtree()) { 101 return false; 102 } 103 if (IsFixedPosContainingBlockForNonSVGTextFrames()) { 104 return true; 105 } 106 const auto& disp = *StyleDisplay(); 107 if (disp.IsFixedPosContainingBlockForContainLayoutAndPaintSupportingFrames() && 108 aContextFrame->SupportsContainLayoutAndPaint()) { 109 return true; 110 } 111 if (disp.IsFixedPosContainingBlockForTransformSupportingFrames() && 112 aContextFrame->SupportsCSSTransforms()) { 113 return true; 114 } 115 return false; 116 } 117 118 bool ComputedStyle::IsAbsPosContainingBlock( 119 const nsIFrame* aContextFrame) const { 120 if (IsFixedPosContainingBlock(aContextFrame)) { 121 return true; 122 } 123 // NOTE: Any CSS properties that influence the output of this function 124 // should also handle will-change appropriately. 125 return StyleDisplay()->IsPositionedStyle() && 126 !aContextFrame->IsInSVGTextSubtree(); 127 } 128 129 } // namespace mozilla 130 131 #endif // ComputedStyleInlines_h