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 "mozilla/ComputedStyle.h"
18 #include "mozilla/ServoComputedDataInlines.h"
19 #include "mozilla/ServoUtils.h"
20 #include "nsPresContext.h"
21
22 namespace mozilla {
23
24 namespace detail {
25 template <typename T, const T* (ComputedStyle::*Method)() const>
TriggerImageLoads(dom::Document & aDocument,const ComputedStyle * aOldStyle,ComputedStyle * aStyle)26 void TriggerImageLoads(dom::Document& aDocument, const ComputedStyle* aOldStyle,
27 ComputedStyle* aStyle) {
28 if constexpr (T::kHasTriggerImageLoads) {
29 auto* old = aOldStyle ? (aOldStyle->*Method)() : nullptr;
30 auto* current = const_cast<T*>((aStyle->*Method)());
31 current->TriggerImageLoads(aDocument, old);
32 } else {
33 Unused << aOldStyle;
34 Unused << aStyle;
35 }
36 }
37 } // namespace detail
38
StartImageLoads(dom::Document & aDocument,const ComputedStyle * aOldStyle)39 void ComputedStyle::StartImageLoads(dom::Document& aDocument,
40 const ComputedStyle* aOldStyle) {
41 MOZ_ASSERT(NS_IsMainThread());
42
43 #define STYLE_STRUCT(name_) \
44 detail::TriggerImageLoads<nsStyle##name_, &ComputedStyle::Style##name_>( \
45 aDocument, aOldStyle, this);
46 #include "nsStyleStructList.h"
47 #undef STYLE_STRUCT
48 }
49
50 } // namespace mozilla
51
52 #endif // ComputedStyleInlines_h
53