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
: uint16_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 // The fact of whether the device size is the page size has changed, thus
38 // resolution media queries can change.
39 DeviceSizeIsPageSizeChange
= 1 << 6,
40 // display-mode changed on the document, thus the display-mode media queries
42 DisplayModeChange
= 1 << 7,
43 // A preference that affects media query results has changed. For
44 // example, changes to document_color_use will affect
46 PreferenceChange
= 1 << 8,
49 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(MediaFeatureChangeReason
)
51 enum class MediaFeatureChangePropagation
: uint8_t {
53 SubDocuments
= 1 << 0,
55 All
= Images
| SubDocuments
,
58 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(MediaFeatureChangePropagation
)
60 struct MediaFeatureChange
{
61 static const auto kAllChanges
= static_cast<MediaFeatureChangeReason
>(~0);
63 RestyleHint mRestyleHint
;
64 nsChangeHint mChangeHint
;
65 MediaFeatureChangeReason mReason
;
67 MOZ_IMPLICIT
MediaFeatureChange(MediaFeatureChangeReason aReason
)
68 : MediaFeatureChange(RestyleHint
{0}, nsChangeHint(0), aReason
) {}
70 MediaFeatureChange(RestyleHint aRestyleHint
, nsChangeHint aChangeHint
,
71 MediaFeatureChangeReason aReason
)
72 : mRestyleHint(aRestyleHint
),
73 mChangeHint(aChangeHint
),
76 inline MediaFeatureChange
& operator|=(const MediaFeatureChange
& aOther
) {
77 mRestyleHint
|= aOther
.mRestyleHint
;
78 mChangeHint
|= aOther
.mChangeHint
;
79 mReason
|= aOther
.mReason
;
84 } // namespace mozilla