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 /* A struct defining a media feature change. */
9 #ifndef mozilla_MediaFeatureChange_h__
10 #define mozilla_MediaFeatureChange_h__
12 #include "nsChangeHint.h"
13 #include "mozilla/Attributes.h"
14 #include "mozilla/TypedEnumBits.h"
15 #include "mozilla/ServoStyleConsts.h"
19 enum class MediaFeatureChangeReason
: uint8_t {
20 // The viewport size the document has used has changed.
22 // This affects size media queries like min-width.
23 ViewportChange
= 1 << 0,
24 // The effective text zoom has changed. This affects the meaning of em units,
25 // and thus affects any media query that uses a Length.
27 // The resolution has changed. This can affect device-pixel-ratio media
28 // queries, for example.
29 ResolutionChange
= 1 << 2,
30 // The medium has changed.
31 MediumChange
= 1 << 3,
32 // The size-mode has changed.
33 SizeModeChange
= 1 << 4,
34 // A system metric or multiple have changed. This affects all the media
35 // features that expose the presence of a system metric directly.
36 SystemMetricsChange
= 1 << 5,
37 // display-mode changed on the document, thus the display-mode media queries
39 DisplayModeChange
= 1 << 6,
40 // A preference that affects media query results has changed. For
41 // example, changes to document_color_use will affect
43 PreferenceChange
= 1 << 7,
46 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(MediaFeatureChangeReason
)
48 enum class MediaFeatureChangePropagation
: uint8_t {
50 SubDocuments
= 1 << 0,
52 All
= Images
| SubDocuments
,
55 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(MediaFeatureChangePropagation
)
57 struct MediaFeatureChange
{
58 static const auto kAllChanges
= static_cast<MediaFeatureChangeReason
>(~0);
60 RestyleHint mRestyleHint
;
61 nsChangeHint mChangeHint
;
62 MediaFeatureChangeReason mReason
;
64 MOZ_IMPLICIT
MediaFeatureChange(MediaFeatureChangeReason aReason
)
65 : MediaFeatureChange(RestyleHint
{0}, nsChangeHint(0), aReason
) {}
67 MediaFeatureChange(RestyleHint aRestyleHint
, nsChangeHint aChangeHint
,
68 MediaFeatureChangeReason aReason
)
69 : mRestyleHint(aRestyleHint
),
70 mChangeHint(aChangeHint
),
73 inline MediaFeatureChange
& operator|=(const MediaFeatureChange
& aOther
) {
74 mRestyleHint
|= aOther
.mRestyleHint
;
75 mChangeHint
|= aOther
.mChangeHint
;
76 mReason
|= aOther
.mReason
;
80 static MediaFeatureChange
ForPreferredColorSchemeChange() {
81 // We need to restyle because not only media queries have changed, system
82 // colors may as well via the prefers-color-scheme meta tag / effective
83 // color-scheme property value.
84 return {RestyleHint::RecascadeSubtree(), nsChangeHint(0),
85 MediaFeatureChangeReason::SystemMetricsChange
};
89 } // namespace mozilla