MediaFeatureChange.h (3185B)
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 /* A struct defining a media feature change. */ 8 9 #ifndef mozilla_MediaFeatureChange_h__ 10 #define mozilla_MediaFeatureChange_h__ 11 12 #include "mozilla/Attributes.h" 13 #include "mozilla/ServoStyleConsts.h" 14 #include "mozilla/TypedEnumBits.h" 15 #include "nsChangeHint.h" 16 17 namespace mozilla { 18 19 enum class MediaFeatureChangeReason : uint8_t { 20 // The viewport size the document has used has changed. 21 // 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. 26 ZoomChange = 1 << 1, 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 38 // may have changed. 39 DisplayModeChange = 1 << 6, 40 // A preference that affects media query results has changed. For 41 // example, changes to document_color_use will affect 42 // prefers-contrast. 43 PreferenceChange = 1 << 7, 44 }; 45 46 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(MediaFeatureChangeReason) 47 48 enum class MediaFeatureChangePropagation : uint8_t { 49 JustThisDocument = 0, 50 SubDocuments = 1 << 0, 51 Images = 1 << 1, 52 All = Images | SubDocuments, 53 }; 54 55 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(MediaFeatureChangePropagation) 56 57 struct MediaFeatureChange { 58 static const auto kAllChanges = static_cast<MediaFeatureChangeReason>(~0); 59 60 RestyleHint mRestyleHint; 61 nsChangeHint mChangeHint; 62 MediaFeatureChangeReason mReason; 63 64 MOZ_IMPLICIT MediaFeatureChange(MediaFeatureChangeReason aReason) 65 : MediaFeatureChange(RestyleHint{0}, nsChangeHint(0), aReason) {} 66 67 MediaFeatureChange(RestyleHint aRestyleHint, nsChangeHint aChangeHint, 68 MediaFeatureChangeReason aReason) 69 : mRestyleHint(aRestyleHint), 70 mChangeHint(aChangeHint), 71 mReason(aReason) {} 72 73 inline MediaFeatureChange& operator|=(const MediaFeatureChange& aOther) { 74 mRestyleHint |= aOther.mRestyleHint; 75 mChangeHint |= aOther.mChangeHint; 76 mReason |= aOther.mReason; 77 return *this; 78 } 79 80 static MediaFeatureChange ForPreferredColorSchemeOrForcedColorsChange() { 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}; 86 } 87 }; 88 89 } // namespace mozilla 90 91 #endif