PageRenderTime 50ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/third_party/blink/renderer/core/css/resolver/cascade_resolver.h

http://github.com/chromium/chromium
C Header | 127 lines | 62 code | 25 blank | 40 comment | 1 complexity | 74b191e503ae3e31410ce64d61d4f3c6 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.0, BSD-2-Clause, LGPL-2.1, MPL-2.0, 0BSD, EPL-1.0, MPL-2.0-no-copyleft-exception, GPL-2.0, BitTorrent-1.0, CPL-1.0, LGPL-3.0, Unlicense, BSD-3-Clause, CC0-1.0, JSON, MIT, GPL-3.0, CC-BY-SA-3.0, AGPL-1.0
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_CSS_RESOLVER_CASCADE_RESOLVER_H_
  5. #define THIRD_PARTY_BLINK_RENDERER_CORE_CSS_RESOLVER_CASCADE_RESOLVER_H_
  6. #include "base/auto_reset.h"
  7. #include "third_party/blink/renderer/core/core_export.h"
  8. #include "third_party/blink/renderer/core/css/css_property_name.h"
  9. #include "third_party/blink/renderer/core/css/properties/css_property.h"
  10. #include "third_party/blink/renderer/core/css/resolver/cascade_filter.h"
  11. #include "third_party/blink/renderer/core/css/resolver/cascade_origin.h"
  12. #include "third_party/blink/renderer/core/css/rule_set.h"
  13. namespace blink {
  14. class CascadePriority;
  15. class CSSProperty;
  16. class CSSVariableData;
  17. class CSSProperty;
  18. namespace cssvalue {
  19. class CSSPendingSubstitutionValue;
  20. } // namespace cssvalue
  21. // CascadeResolver is an object passed on the stack during Apply. Its most
  22. // important job is to detect cycles during Apply (in general, keep track of
  23. // which properties we're currently applying).
  24. class CORE_EXPORT CascadeResolver {
  25. STACK_ALLOCATED();
  26. public:
  27. // TODO(crbug.com/985047): Probably use a HashMap for this.
  28. using NameStack = Vector<CSSPropertyName, 8>;
  29. // A 'locked' property is a property we are in the process of applying.
  30. // In other words, once a property is locked, locking it again would form
  31. // a cycle, and is therefore an error.
  32. bool IsLocked(const CSSProperty&) const;
  33. bool IsLocked(const CSSPropertyName&) const;
  34. // We do not allow substitution of animation-tainted values into
  35. // an animation-affecting property.
  36. //
  37. // https://drafts.csswg.org/css-variables/#animation-tainted
  38. bool AllowSubstitution(CSSVariableData*) const;
  39. // Sets the generation of the priority to zero, which has the effect of
  40. // marking it as unapplied. (I.e. this can be used to force re-application of
  41. // a declaration).
  42. void MarkUnapplied(CascadePriority*) const;
  43. // Sets the generation of the priority to the current generation,
  44. // which has the effect of marking it as already applied. (I.e. this can be
  45. // used to skip application of a declaration).
  46. void MarkApplied(CascadePriority*) const;
  47. // If the incoming origin is kAuthor, collect flags from 'property'.
  48. // AuthorFlags() can then later be used to see which flags have been observed.
  49. void CollectAuthorFlags(const CSSProperty& property, CascadeOrigin origin) {
  50. author_flags_ |=
  51. (origin == CascadeOrigin::kAuthor ? property.GetFlags() : 0);
  52. }
  53. CSSProperty::Flags AuthorFlags() const { return author_flags_; }
  54. // Automatically locks and unlocks the given property. (See
  55. // CascadeResolver::IsLocked).
  56. class CORE_EXPORT AutoLock {
  57. STACK_ALLOCATED();
  58. public:
  59. AutoLock(const CSSProperty&, CascadeResolver&);
  60. AutoLock(const CSSPropertyName&, CascadeResolver&);
  61. ~AutoLock();
  62. private:
  63. CascadeResolver& resolver_;
  64. };
  65. private:
  66. friend class AutoLock;
  67. friend class StyleCascade;
  68. friend class TestCascadeResolver;
  69. CascadeResolver(CascadeFilter filter, uint8_t generation)
  70. : filter_(filter), generation_(generation) {}
  71. // If the given property is already being applied, returns true.
  72. // The return value is the same value you would get from InCycle(), and
  73. // is just returned for convenience.
  74. //
  75. // When a cycle has been detected, the CascadeResolver will *persist the cycle
  76. // state* (i.e. InCycle() will continue to return true) until we reach
  77. // the start of the cycle.
  78. //
  79. // The cycle state is cleared by ~AutoLock, once we have moved far enough
  80. // up the stack.
  81. bool DetectCycle(const CSSProperty&);
  82. // Returns true whenever the CascadeResolver is in a cycle state.
  83. // This DOES NOT detect cycles; the caller must call DetectCycle first.
  84. bool InCycle() const;
  85. NameStack stack_;
  86. wtf_size_t cycle_depth_ = kNotFound;
  87. CascadeFilter filter_;
  88. const uint8_t generation_ = 0;
  89. CSSProperty::Flags author_flags_ = 0;
  90. // A very simple cache for CSSPendingSubstitutionValues. We cache only the
  91. // most recently parsed CSSPendingSubstitutionValue, such that consecutive
  92. // calls to ResolvePendingSubstitution with the same value don't need to
  93. // do the same parsing job all over again.
  94. struct {
  95. STACK_ALLOCATED();
  96. public:
  97. const cssvalue::CSSPendingSubstitutionValue* value = nullptr;
  98. HeapVector<CSSPropertyValue, 256> parsed_properties;
  99. } shorthand_cache_;
  100. };
  101. } // namespace blink
  102. #endif // THIRD_PARTY_BLINK_RENDERER_CORE_CSS_RESOLVER_CASCADE_RESOLVER_H_