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 /* constants for what needs to be recomputed in response to style changes */
8 
9 #ifndef nsChangeHint_h___
10 #define nsChangeHint_h___
11 
12 #include "mozilla/Types.h"
13 #include "nsDebug.h"
14 #include "nsTArray.h"
15 
16 struct nsCSSSelector;
17 
18 // Defines for various style related constants
19 
20 enum nsChangeHint : uint32_t {
21   nsChangeHint_Empty = 0,
22 
23   // change was visual only (e.g., COLOR=)
24   // Invalidates all descendant frames (including following
25   // placeholders to out-of-flow frames).
26   nsChangeHint_RepaintFrame = 1 << 0,
27 
28   // For reflow, we want flags to give us arbitrary FrameNeedsReflow behavior.
29   // just do a FrameNeedsReflow.
30   nsChangeHint_NeedReflow = 1 << 1,
31 
32   // Invalidate intrinsic widths on the frame's ancestors.  Must not be set
33   // without setting nsChangeHint_NeedReflow.
34   nsChangeHint_ClearAncestorIntrinsics = 1 << 2,
35 
36   // Invalidate intrinsic widths on the frame's descendants.  Must not be set
37   // without also setting nsChangeHint_ClearAncestorIntrinsics,
38   // nsChangeHint_NeedDirtyReflow and nsChangeHint_NeedReflow.
39   nsChangeHint_ClearDescendantIntrinsics = 1 << 3,
40 
41   // Force unconditional reflow of all descendants.  Must not be set without
42   // setting nsChangeHint_NeedReflow, but can be set regardless of whether the
43   // Clear*Intrinsics flags are set.
44   nsChangeHint_NeedDirtyReflow = 1 << 4,
45 
46   // change requires view to be updated, if there is one (e.g., clip:).
47   // Updates all descendants (including following placeholders to out-of-flows).
48   nsChangeHint_SyncFrameView = 1 << 5,
49 
50   // The currently shown mouse cursor needs to be updated
51   nsChangeHint_UpdateCursor = 1 << 6,
52 
53   /**
54    * Used when the computed value (a URI) of one or more of an element's
55    * filter/mask/clip/etc CSS properties changes, causing the element's frame
56    * to start/stop referencing (or reference different) SVG resource elements.
57    * (_Not_ used to handle changes to referenced resource elements.) Using this
58    * hint results in SVGObserverUtils::UpdateEffects being called on the
59    * element's frame.
60    */
61   nsChangeHint_UpdateEffects = 1 << 7,
62 
63   /**
64    * Visual change only, but the change can be handled entirely by
65    * updating the layer(s) for the frame.
66    * Updates all descendants (including following placeholders to out-of-flows).
67    */
68   nsChangeHint_UpdateOpacityLayer = 1 << 8,
69   /**
70    * Updates all descendants. Any placeholder descendants' out-of-flows
71    * are also descendants of the transformed frame, so they're updated.
72    */
73   nsChangeHint_UpdateTransformLayer = 1 << 9,
74 
75   /**
76    * Change requires frame change (e.g., display:).
77    * Reconstructs all frame descendants, including following placeholders
78    * to out-of-flows.
79    *
80    * Note that this subsumes all the other change hints. (see
81    * RestyleManager::ProcessRestyledFrames for details).
82    */
83   nsChangeHint_ReconstructFrame = 1 << 10,
84 
85   /**
86    * The frame's overflow area has changed. Does not update any descendant
87    * frames.
88    */
89   nsChangeHint_UpdateOverflow = 1 << 11,
90 
91   /**
92    * The overflow area of the frame and all of its descendants has changed. This
93    * can happen through a text-decoration change.
94    */
95   nsChangeHint_UpdateSubtreeOverflow = 1 << 12,
96 
97   /**
98    * The frame's overflow area has changed, through a change in its transform.
99    * In other words, the frame's pre-transform overflow is unchanged, but
100    * its post-transform overflow has changed, and thus its effect on its
101    * parent's overflow has changed.  If the pre-transform overflow has
102    * changed, see nsChangeHint_UpdateOverflow.
103    * Does not update any descendant frames.
104    */
105   nsChangeHint_UpdatePostTransformOverflow = 1 << 13,
106 
107   /**
108    * This frame's effect on its parent's overflow area has changed.
109    * (But neither its pre-transform nor post-transform overflow have
110    * changed; if those are the case, see
111    * nsChangeHint_UpdatePostTransformOverflow.)
112    */
113   nsChangeHint_UpdateParentOverflow = 1 << 14,
114 
115   /**
116    * The children-only transform of an SVG frame changed, requiring the
117    * overflow rects of the frame's immediate children to be updated.
118    */
119   nsChangeHint_ChildrenOnlyTransform = 1 << 15,
120 
121   /**
122    * The frame's offsets have changed, while its dimensions might have
123    * changed as well.  This hint is used for positioned frames if their
124    * offset changes.  If we decide that the dimensions are likely to
125    * change, this will trigger a reflow.
126    *
127    * Note that this should probably be used in combination with
128    * nsChangeHint_UpdateOverflow in order to get the overflow areas of
129    * the ancestors updated as well.
130    */
131   nsChangeHint_RecomputePosition = 1 << 16,
132 
133   /**
134    * Behaves like ReconstructFrame, but only if the frame has descendants
135    * that are absolutely or fixed position. Use this hint when a style change
136    * has changed whether the frame is a container for fixed-pos or abs-pos
137    * elements, but reframing is otherwise not needed.
138    *
139    * Note that nsStyleContext::CalcStyleDifference adjusts results
140    * returned by style struct CalcDifference methods to return this hint
141    * only if there was a change to whether the element's overall style
142    * indicates that it establishes a containing block.
143    */
144   nsChangeHint_UpdateContainingBlock = 1 << 17,
145 
146   /**
147    * This change hint has *no* change handling behavior.  However, it
148    * exists to be a non-inherited hint, because when the border-style
149    * changes, and it's inherited by a child, that might require a reflow
150    * due to the border-width change on the child.
151    */
152   nsChangeHint_BorderStyleNoneChange = 1 << 18,
153 
154   /**
155    * SVG textPath needs to be recomputed because the path has changed.
156    * This means that the glyph positions of the text need to be recomputed.
157    */
158   nsChangeHint_UpdateTextPath = 1 << 19,
159 
160   /**
161    * This will schedule an invalidating paint. This is useful if something
162    * has changed which will be invalidated by DLBI.
163    */
164   nsChangeHint_SchedulePaint = 1 << 20,
165 
166   /**
167    * A hint reflecting that style data changed with no change handling
168    * behavior.  We need to return this, rather than nsChangeHint(0),
169    * so that certain optimizations that manipulate the style context tree are
170    * correct.
171    *
172    * nsChangeHint_NeutralChange must be returned by CalcDifference on a given
173    * style struct if the data in the style structs are meaningfully different
174    * and if no other change hints are returned.  If any other change hints are
175    * set, then nsChangeHint_NeutralChange need not also be included, but it is
176    * safe to do so.  (An example of style structs having non-meaningfully
177    * different data would be cached information that would be re-calculated
178    * to the same values, such as nsStyleBorder::mSubImages.)
179    */
180   nsChangeHint_NeutralChange = 1 << 21,
181 
182   /**
183    * This will cause rendering observers to be invalidated.
184    */
185   nsChangeHint_InvalidateRenderingObservers = 1 << 22,
186 
187   /**
188    * Indicates that the reflow changes the size or position of the
189    * element, and thus the reflow must start from at least the frame's
190    * parent.  Must be not be set without also setting nsChangeHint_NeedReflow
191    * and nsChangeHint_ClearAncestorIntrinsics.
192    */
193   nsChangeHint_ReflowChangesSizeOrPosition = 1 << 23,
194 
195   /**
196    * Indicates that the style changes the computed BSize --- e.g. 'height'.
197    * Must not be set without also setting nsChangeHint_NeedReflow.
198    */
199   nsChangeHint_UpdateComputedBSize = 1 << 24,
200 
201   /**
202    * Indicates that the 'opacity' property changed between 1 and non-1.
203    *
204    * Used as extra data for handling UpdateOpacityLayer hints.
205    *
206    * Note that we do not send this hint if the non-1 value was 0.99 or
207    * greater, since in that case we send a RepaintFrame hint instead.
208    */
209   nsChangeHint_UpdateUsesOpacity = 1 << 25,
210 
211   /**
212    * Indicates that the 'background-position' property changed.
213    * Regular frames can invalidate these changes using DLBI, but
214    * for some frame types we need to repaint the whole frame because
215    * the frame does not build individual background image display items
216    * for each background layer.
217    */
218   nsChangeHint_UpdateBackgroundPosition = 1 << 26,
219 
220   /**
221    * Indicates that a frame has changed to or from having the CSS
222    * transform property set.
223    */
224   nsChangeHint_AddOrRemoveTransform = 1 << 27,
225 
226   /**
227    * Indicates that the overflow-x and/or overflow-y property changed.
228    *
229    * In most cases, this is equivalent to nsChangeHint_ReconstructFrame. But
230    * in some special cases where the change is really targeting the viewport's
231    * scrollframe, this is instead equivalent to nsChangeHint_AllReflowHints
232    * (because the viewport always has an associated scrollframe).
233    */
234   nsChangeHint_CSSOverflowChange = 1 << 28,
235 
236   /**
237    * Indicates that nsIFrame::UpdateWidgetProperties needs to be called.
238    * This is used for -moz-window-* properties.
239    */
240   nsChangeHint_UpdateWidgetProperties = 1 << 29,
241 
242   /**
243    *  Indicates that there has been a colspan or rowspan attribute change
244    *  on the cells of a table.
245    */
246   nsChangeHint_UpdateTableCellSpans = 1 << 30,
247 
248   /**
249    * Indicates that the visiblity property changed.
250    * This change hint is used for skip restyling for animations on
251    * visibility:hidden elements in the case where the elements have no visible
252    * descendants.
253    */
254   nsChangeHint_VisibilityChange = 1u << 31,
255 
256   // IMPORTANT NOTE: When adding a new hint, you will need to add it to
257   // one of:
258   //
259   //   * nsChangeHint_Hints_NeverHandledForDescendants
260   //   * nsChangeHint_Hints_AlwaysHandledForDescendants
261   //   * nsChangeHint_Hints_SometimesHandledForDescendants
262   //
263   // and you also may need to handle it in NS_HintsNotHandledForDescendantsIn.
264   //
265   // Please also add it to RestyleManager::ChangeHintToString and
266   // modify nsChangeHint_AllHints below accordingly.
267 
268   /**
269    * Dummy hint value for all hints. It exists for compile time check.
270    */
271   nsChangeHint_AllHints = uint32_t((1ull << 32) - 1),
272 };
273 
274 // Redefine these operators to return nothing. This will catch any use
275 // of these operators on hints. We should not be using these operators
276 // on nsChangeHints
277 inline void operator<(nsChangeHint s1, nsChangeHint s2) {}
278 inline void operator>(nsChangeHint s1, nsChangeHint s2) {}
279 inline void operator!=(nsChangeHint s1, nsChangeHint s2) {}
280 inline void operator==(nsChangeHint s1, nsChangeHint s2) {}
281 inline void operator<=(nsChangeHint s1, nsChangeHint s2) {}
282 inline void operator>=(nsChangeHint s1, nsChangeHint s2) {}
283 
284 // Operators on nsChangeHints
285 
286 // Returns true iff the second hint contains all the hints of the first hint
NS_IsHintSubset(nsChangeHint aSubset,nsChangeHint aSuperSet)287 inline bool NS_IsHintSubset(nsChangeHint aSubset, nsChangeHint aSuperSet) {
288   return (aSubset & aSuperSet) == aSubset;
289 }
290 
291 // The functions below need an integral type to cast to to avoid
292 // infinite recursion.
293 typedef decltype(nsChangeHint(0) + nsChangeHint(0)) nsChangeHint_size_t;
294 
295 inline nsChangeHint constexpr operator|(nsChangeHint aLeft,
296                                         nsChangeHint aRight) {
297   return nsChangeHint(nsChangeHint_size_t(aLeft) | nsChangeHint_size_t(aRight));
298 }
299 
300 inline nsChangeHint constexpr operator&(nsChangeHint aLeft,
301                                         nsChangeHint aRight) {
302   return nsChangeHint(nsChangeHint_size_t(aLeft) & nsChangeHint_size_t(aRight));
303 }
304 
305 inline nsChangeHint& operator|=(nsChangeHint& aLeft, nsChangeHint aRight) {
306   return aLeft = aLeft | aRight;
307 }
308 
309 inline nsChangeHint& operator&=(nsChangeHint& aLeft, nsChangeHint aRight) {
310   return aLeft = aLeft & aRight;
311 }
312 
313 inline nsChangeHint constexpr operator~(nsChangeHint aArg) {
314   return nsChangeHint(~nsChangeHint_size_t(aArg));
315 }
316 
317 inline nsChangeHint constexpr operator^(nsChangeHint aLeft,
318                                         nsChangeHint aRight) {
319   return nsChangeHint(nsChangeHint_size_t(aLeft) ^ nsChangeHint_size_t(aRight));
320 }
321 
322 inline nsChangeHint operator^=(nsChangeHint& aLeft, nsChangeHint aRight) {
323   return aLeft = aLeft ^ aRight;
324 }
325 
326 /**
327  * We have an optimization when processing change hints which prevents
328  * us from visiting the descendants of a node when a hint on that node
329  * is being processed.  This optimization does not apply in some of the
330  * cases where applying a hint to an element does not necessarily result
331  * in the same hint being handled on the descendants.
332  */
333 
334 // The change hints that are always handled for descendants.
335 #define nsChangeHint_Hints_AlwaysHandledForDescendants                     \
336   (nsChangeHint_ClearDescendantIntrinsics | nsChangeHint_NeedDirtyReflow | \
337    nsChangeHint_NeutralChange | nsChangeHint_ReconstructFrame |            \
338    nsChangeHint_RepaintFrame | nsChangeHint_SchedulePaint |                \
339    nsChangeHint_SyncFrameView | nsChangeHint_UpdateCursor |                \
340    nsChangeHint_UpdateSubtreeOverflow | nsChangeHint_UpdateTextPath |      \
341    nsChangeHint_VisibilityChange)
342 
343 // The change hints that are never handled for descendants.
344 #define nsChangeHint_Hints_NeverHandledForDescendants                        \
345   (nsChangeHint_BorderStyleNoneChange | nsChangeHint_ChildrenOnlyTransform | \
346    nsChangeHint_CSSOverflowChange |                                          \
347    nsChangeHint_InvalidateRenderingObservers |                               \
348    nsChangeHint_RecomputePosition | nsChangeHint_UpdateBackgroundPosition |  \
349    nsChangeHint_UpdateComputedBSize | nsChangeHint_UpdateContainingBlock |   \
350    nsChangeHint_UpdateEffects | nsChangeHint_UpdateOpacityLayer |            \
351    nsChangeHint_UpdateOverflow | nsChangeHint_UpdateParentOverflow |         \
352    nsChangeHint_UpdatePostTransformOverflow |                                \
353    nsChangeHint_UpdateTableCellSpans | nsChangeHint_UpdateTransformLayer |   \
354    nsChangeHint_UpdateUsesOpacity | nsChangeHint_AddOrRemoveTransform |      \
355    nsChangeHint_UpdateWidgetProperties)
356 
357 // The change hints that are sometimes considered to be handled for descendants.
358 #define nsChangeHint_Hints_SometimesHandledForDescendants           \
359   (nsChangeHint_ClearAncestorIntrinsics | nsChangeHint_NeedReflow | \
360    nsChangeHint_ReflowChangesSizeOrPosition)
361 
362 static_assert(!(nsChangeHint_Hints_AlwaysHandledForDescendants &
363                 nsChangeHint_Hints_NeverHandledForDescendants) &&
364                   !(nsChangeHint_Hints_AlwaysHandledForDescendants &
365                     nsChangeHint_Hints_SometimesHandledForDescendants) &&
366                   !(nsChangeHint_Hints_NeverHandledForDescendants &
367                     nsChangeHint_Hints_SometimesHandledForDescendants) &&
368                   !(nsChangeHint_AllHints ^
369                     nsChangeHint_Hints_AlwaysHandledForDescendants ^
370                     nsChangeHint_Hints_NeverHandledForDescendants ^
371                     nsChangeHint_Hints_SometimesHandledForDescendants),
372               "change hints must be present in exactly one of "
373               "nsChangeHint_Hints_{Always,Never,Sometimes}"
374               "HandledForDescendants");
375 
376 // The most hints that NS_HintsNotHandledForDescendantsIn could possibly return:
377 #define nsChangeHint_Hints_NotHandledForDescendants \
378   (nsChangeHint_Hints_NeverHandledForDescendants |  \
379    nsChangeHint_Hints_SometimesHandledForDescendants)
380 
381 // Redefine the old NS_STYLE_HINT constants in terms of the new hint structure
382 #define NS_STYLE_HINT_VISUAL                                            \
383   nsChangeHint(nsChangeHint_RepaintFrame | nsChangeHint_SyncFrameView | \
384                nsChangeHint_SchedulePaint)
385 #define nsChangeHint_AllReflowHints                                        \
386   nsChangeHint(                                                            \
387       nsChangeHint_NeedReflow | nsChangeHint_ReflowChangesSizeOrPosition | \
388       nsChangeHint_ClearAncestorIntrinsics |                               \
389       nsChangeHint_ClearDescendantIntrinsics | nsChangeHint_NeedDirtyReflow)
390 
391 // Below are the change hints that we send for ISize & BSize changes.
392 // Each is similar to nsChangeHint_AllReflowHints with a few changes.
393 
394 // * For an ISize change, we send nsChangeHint_AllReflowHints, with two bits
395 // excluded: nsChangeHint_ClearDescendantIntrinsics (because an ancestor's
396 // inline-size change can't affect descendant intrinsic sizes), and
397 // nsChangeHint_NeedDirtyReflow (because ISize changes don't need to *force*
398 // all descendants to reflow).
399 #define nsChangeHint_ReflowHintsForISizeChange            \
400   nsChangeHint(nsChangeHint_AllReflowHints &              \
401                ~(nsChangeHint_ClearDescendantIntrinsics | \
402                  nsChangeHint_NeedDirtyReflow))
403 
404 // * For a BSize change, we send almost the same hints as for ISize changes,
405 // with one extra: nsChangeHint_UpdateComputedBSize.  We need this hint because
406 // BSize changes CAN affect descendant intrinsic sizes, due to replaced
407 // elements with percentage BSizes in descendants which also have percentage
408 // BSizes. nsChangeHint_UpdateComputedBSize clears intrinsic sizes for frames
409 // that have such replaced elements. (We could instead send
410 // nsChangeHint_ClearDescendantIntrinsics, but that's broader than we need.)
411 //
412 // NOTE: You might think that BSize changes could exclude
413 // nsChangeHint_ClearAncestorIntrinsics (which is inline-axis specific), but we
414 // do need to send it, to clear cached results from CSS Flex measuring reflows.
415 #define nsChangeHint_ReflowHintsForBSizeChange                           \
416   nsChangeHint(                                                          \
417       (nsChangeHint_AllReflowHints | nsChangeHint_UpdateComputedBSize) & \
418       ~(nsChangeHint_ClearDescendantIntrinsics |                         \
419         nsChangeHint_NeedDirtyReflow))
420 
421 // * For changes to the float area of an already-floated element, we need all
422 // reflow hints, but not the ones that apply to descendants.
423 // Our descendants aren't impacted when our float area only changes
424 // placement but not size/shape. (e.g. if we change which side we float to).
425 // But our ancestors/siblings are potentially impacted, so we need to send
426 // the non-descendant reflow hints.
427 #define nsChangeHint_ReflowHintsForFloatAreaChange        \
428   nsChangeHint(nsChangeHint_AllReflowHints &              \
429                ~(nsChangeHint_ClearDescendantIntrinsics | \
430                  nsChangeHint_NeedDirtyReflow))
431 
432 #define NS_STYLE_HINT_REFLOW \
433   nsChangeHint(NS_STYLE_HINT_VISUAL | nsChangeHint_AllReflowHints)
434 
435 #define nsChangeHint_Hints_CanIgnoreIfNotVisible                   \
436   nsChangeHint(NS_STYLE_HINT_VISUAL | nsChangeHint_NeutralChange | \
437                nsChangeHint_UpdateOpacityLayer |                   \
438                nsChangeHint_AddOrRemoveTransform |                 \
439                nsChangeHint_UpdatePostTransformOverflow |          \
440                nsChangeHint_UpdateTransformLayer |                 \
441                nsChangeHint_UpdateUsesOpacity | nsChangeHint_VisibilityChange)
442 
443 // NB: Once we drop support for the old style system, this logic should be
444 // inlined in the Servo style system to eliminate the FFI call.
NS_HintsNotHandledForDescendantsIn(nsChangeHint aChangeHint)445 inline nsChangeHint NS_HintsNotHandledForDescendantsIn(
446     nsChangeHint aChangeHint) {
447   nsChangeHint result =
448       aChangeHint & nsChangeHint_Hints_NeverHandledForDescendants;
449 
450   if (!NS_IsHintSubset(nsChangeHint_NeedDirtyReflow, aChangeHint)) {
451     if (NS_IsHintSubset(nsChangeHint_NeedReflow, aChangeHint)) {
452       // If NeedDirtyReflow is *not* set, then NeedReflow is a
453       // non-inherited hint.
454       result |= nsChangeHint_NeedReflow;
455     }
456 
457     if (NS_IsHintSubset(nsChangeHint_ReflowChangesSizeOrPosition,
458                         aChangeHint)) {
459       // If NeedDirtyReflow is *not* set, then ReflowChangesSizeOrPosition is a
460       // non-inherited hint.
461       result |= nsChangeHint_ReflowChangesSizeOrPosition;
462     }
463   }
464 
465   if (!NS_IsHintSubset(nsChangeHint_ClearDescendantIntrinsics, aChangeHint) &&
466       NS_IsHintSubset(nsChangeHint_ClearAncestorIntrinsics, aChangeHint)) {
467     // If ClearDescendantIntrinsics is *not* set, then
468     // ClearAncestorIntrinsics is a non-inherited hint.
469     result |= nsChangeHint_ClearAncestorIntrinsics;
470   }
471 
472   MOZ_ASSERT(
473       NS_IsHintSubset(result, nsChangeHint_Hints_NotHandledForDescendants),
474       "something is inconsistent");
475 
476   return result;
477 }
478 
NS_HintsHandledForDescendantsIn(nsChangeHint aChangeHint)479 inline nsChangeHint NS_HintsHandledForDescendantsIn(nsChangeHint aChangeHint) {
480   return aChangeHint & ~NS_HintsNotHandledForDescendantsIn(aChangeHint);
481 }
482 
483 // Returns the change hints in aOurChange that are not subsumed by those
484 // in aHintsHandled (which are hints that have been handled by an ancestor).
NS_RemoveSubsumedHints(nsChangeHint aOurChange,nsChangeHint aHintsHandled)485 inline nsChangeHint NS_RemoveSubsumedHints(nsChangeHint aOurChange,
486                                            nsChangeHint aHintsHandled) {
487   nsChangeHint result =
488       aOurChange & ~NS_HintsHandledForDescendantsIn(aHintsHandled);
489 
490   if (result &
491       (nsChangeHint_ClearAncestorIntrinsics |
492        nsChangeHint_ClearDescendantIntrinsics | nsChangeHint_NeedDirtyReflow |
493        nsChangeHint_ReflowChangesSizeOrPosition |
494        nsChangeHint_UpdateComputedBSize)) {
495     result |= nsChangeHint_NeedReflow;
496   }
497 
498   if (result & (nsChangeHint_ClearDescendantIntrinsics)) {
499     MOZ_ASSERT(result & nsChangeHint_ClearAncestorIntrinsics);
500     result |=  // nsChangeHint_ClearAncestorIntrinsics |
501         nsChangeHint_NeedDirtyReflow;
502   }
503 
504   return result;
505 }
506 
507 /**
508  * |nsRestyleHint| is a bitfield for the result of
509  * |HasStateDependentStyle| and |HasAttributeDependentStyle|.  When no
510  * restyling is necessary, use |nsRestyleHint(0)|.
511  *
512  * Without eRestyle_Force or eRestyle_ForceDescendants, the restyling process
513  * can stop processing at a frame when it detects no style changes and it is
514  * known that the styles of the subtree beneath it will not change, leaving
515  * the old style context on the frame.  eRestyle_Force can be used to skip this
516  * optimization on a frame, and to force its new style context to be used.
517  *
518  * Similarly, eRestyle_ForceDescendants will cause the frame and all of its
519  * descendants to be traversed and for the new style contexts that are created
520  * to be set on the frames.
521  *
522  * NOTE: When adding new restyle hints, please also add them to
523  * RestyleManager::RestyleHintToString.
524  */
525 enum nsRestyleHint : uint32_t {
526   // Rerun selector matching on the element.  If a new style context
527   // results, update the style contexts of descendants.  (Irrelevant if
528   // eRestyle_Subtree is also set, since that implies a superset of the
529   // work.)
530   eRestyle_Self = 1 << 0,
531 
532   // Rerun selector matching on descendants of the element that match
533   // a given selector.
534   eRestyle_SomeDescendants = 1 << 1,
535 
536   // Rerun selector matching on the element and all of its descendants.
537   // (Implies eRestyle_ForceDescendants, which ensures that we continue
538   // the restyling process for all descendants, but doesn't cause
539   // selector matching.)
540   eRestyle_Subtree = 1 << 2,
541 
542   // Rerun selector matching on all later siblings of the element and
543   // all of their descendants.
544   eRestyle_LaterSiblings = 1 << 3,
545 
546   // Replace the style data coming from CSS transitions without updating
547   // any other style data.  If a new style context results, update style
548   // contexts on the descendants.  (Irrelevant if eRestyle_Self or
549   // eRestyle_Subtree is also set, since those imply a superset of the
550   // work.)
551   eRestyle_CSSTransitions = 1 << 4,
552 
553   // Replace the style data coming from CSS animations without updating
554   // any other style data.  If a new style context results, update style
555   // contexts on the descendants.  (Irrelevant if eRestyle_Self or
556   // eRestyle_Subtree is also set, since those imply a superset of the
557   // work.)
558   eRestyle_CSSAnimations = 1 << 5,
559 
560   // Replace the style data coming from inline style without updating
561   // any other style data.  If a new style context results, update style
562   // contexts on the descendants.  (Irrelevant if eRestyle_Self or
563   // eRestyle_Subtree is also set, since those imply a superset of the
564   // work.)  Supported only for element style contexts and not for
565   // pseudo-elements or anonymous boxes, on which it converts to
566   // eRestyle_Self.
567   // If the change is for the advance of a declarative animation, use
568   // the value below instead.
569   eRestyle_StyleAttribute = 1 << 6,
570 
571   // Same as eRestyle_StyleAttribute, but for when the change results
572   // from the advance of a declarative animation.
573   eRestyle_StyleAttribute_Animations = 1 << 7,
574 
575   // Continue the restyling process to the current frame's children even
576   // if this frame's restyling resulted in no style changes.
577   eRestyle_Force = 1 << 8,
578 
579   // Continue the restyling process to all of the current frame's
580   // descendants, even if any frame's restyling resulted in no style
581   // changes.  (Implies eRestyle_Force.)  Note that this is weaker than
582   // eRestyle_Subtree, which makes us rerun selector matching on all
583   // descendants rather than just continuing the restyling process.
584   eRestyle_ForceDescendants = 1 << 9,
585 
586   // Useful unions:
587   eRestyle_AllHintsWithAnimations = eRestyle_CSSTransitions |
588                                     eRestyle_CSSAnimations |
589                                     eRestyle_StyleAttribute_Animations,
590 };
591 
592 // The functions below need an integral type to cast to to avoid
593 // infinite recursion.
594 typedef decltype(nsRestyleHint(0) + nsRestyleHint(0)) nsRestyleHint_size_t;
595 
596 inline constexpr nsRestyleHint operator|(nsRestyleHint aLeft,
597                                          nsRestyleHint aRight) {
598   return nsRestyleHint(nsRestyleHint_size_t(aLeft) |
599                        nsRestyleHint_size_t(aRight));
600 }
601 
602 inline constexpr nsRestyleHint operator&(nsRestyleHint aLeft,
603                                          nsRestyleHint aRight) {
604   return nsRestyleHint(nsRestyleHint_size_t(aLeft) &
605                        nsRestyleHint_size_t(aRight));
606 }
607 
608 inline nsRestyleHint& operator|=(nsRestyleHint& aLeft, nsRestyleHint aRight) {
609   return aLeft = aLeft | aRight;
610 }
611 
612 inline nsRestyleHint& operator&=(nsRestyleHint& aLeft, nsRestyleHint aRight) {
613   return aLeft = aLeft & aRight;
614 }
615 
616 inline constexpr nsRestyleHint operator~(nsRestyleHint aArg) {
617   return nsRestyleHint(~nsRestyleHint_size_t(aArg));
618 }
619 
620 inline constexpr nsRestyleHint operator^(nsRestyleHint aLeft,
621                                          nsRestyleHint aRight) {
622   return nsRestyleHint(nsRestyleHint_size_t(aLeft) ^
623                        nsRestyleHint_size_t(aRight));
624 }
625 
626 inline nsRestyleHint operator^=(nsRestyleHint& aLeft, nsRestyleHint aRight) {
627   return aLeft = aLeft ^ aRight;
628 }
629 
630 namespace mozilla {
631 
632 /**
633  * Additional data used in conjunction with an nsRestyleHint to control the
634  * restyle process.
635  */
636 struct RestyleHintData {
637   // When eRestyle_SomeDescendants is used, this array contains the selectors
638   // that identify which descendants will be restyled.
639   nsTArray<nsCSSSelector*> mSelectorsForDescendants;
640 };
641 
642 }  // namespace mozilla
643 
644 #endif /* nsChangeHint_h___ */
645