tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

StyleAnimationValue.h (4763B)


      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 /* Utilities for animation of computed style values */
      8 
      9 #ifndef mozilla_StyleAnimationValue_h_
     10 #define mozilla_StyleAnimationValue_h_
     11 
     12 #include "NonCustomCSSPropertyId.h"
     13 #include "mozilla/CSSPropertyId.h"
     14 #include "mozilla/RefPtr.h"
     15 #include "mozilla/ServoBindingTypes.h"
     16 #include "mozilla/ServoStyleConsts.h"  // Servo_AnimationValue_Dump
     17 #include "nsColor.h"
     18 #include "nsStringFwd.h"
     19 #include "nsStyleTransformMatrix.h"
     20 
     21 class nsIFrame;
     22 
     23 namespace mozilla {
     24 
     25 namespace css {
     26 class StyleRule;
     27 }  // namespace css
     28 
     29 namespace dom {
     30 class Element;
     31 }  // namespace dom
     32 
     33 namespace layers {
     34 class Animatable;
     35 }  // namespace layers
     36 
     37 enum class PseudoStyleType : uint8_t;
     38 struct PropertyStyleAnimationValuePair;
     39 
     40 struct AnimationValue {
     41  explicit AnimationValue(const RefPtr<StyleAnimationValue>& aValue)
     42      : mServo(aValue) {}
     43  AnimationValue() = default;
     44 
     45  AnimationValue(const AnimationValue& aOther) = default;
     46  AnimationValue(AnimationValue&& aOther) = default;
     47 
     48  AnimationValue& operator=(const AnimationValue& aOther) = default;
     49  AnimationValue& operator=(AnimationValue&& aOther) = default;
     50 
     51  bool operator==(const AnimationValue& aOther) const;
     52  bool operator!=(const AnimationValue& aOther) const;
     53 
     54  bool IsNull() const { return !mServo; }
     55 
     56  float GetOpacity() const;
     57 
     58  // Returns nscolor value in this AnimationValue.
     59  // Currently only background-color is supported.
     60  nscolor GetColor(nscolor aForegroundColor) const;
     61 
     62  // Returns true if this AnimationValue is current-color.
     63  // Currently only background-color is supported.
     64  bool IsCurrentColor() const;
     65 
     66  // Return a transform list for the transform property.
     67  const mozilla::StyleTransform& GetTransformProperty() const;
     68  const mozilla::StyleScale& GetScaleProperty() const;
     69  const mozilla::StyleTranslate& GetTranslateProperty() const;
     70  const mozilla::StyleRotate& GetRotateProperty() const;
     71 
     72  // Motion path properties.
     73  // Note: This clones the StyleOffsetPath object from its AnimatedValue, so
     74  // this may be expensive if the path is a complex SVG path or polygon. The
     75  // caller should be aware of this performance impact.
     76  void GetOffsetPathProperty(StyleOffsetPath& aOffsetPath) const;
     77  const mozilla::LengthPercentage& GetOffsetDistanceProperty() const;
     78  const mozilla::StyleOffsetRotate& GetOffsetRotateProperty() const;
     79  const mozilla::StylePositionOrAuto& GetOffsetAnchorProperty() const;
     80  const mozilla::StyleOffsetPosition& GetOffsetPositionProperty() const;
     81  bool IsOffsetPathUrl() const;
     82 
     83  // Return the scale for mServo, which is calculated with reference to aFrame.
     84  mozilla::gfx::MatrixScales GetScaleValue(const nsIFrame* aFrame) const;
     85 
     86  // Uncompute this AnimationValue and then serialize it.
     87  void SerializeSpecifiedValue(const CSSPropertyId& aProperty,
     88                               const StylePerDocumentStyleData* aRawData,
     89                               nsACString& aString) const;
     90 
     91  // Check if |*this| and |aToValue| can be interpolated.
     92  bool IsInterpolableWith(const CSSPropertyId& aProperty,
     93                          const AnimationValue& aToValue) const;
     94 
     95  // Compute the distance between *this and aOther.
     96  double ComputeDistance(const AnimationValue& aOther) const;
     97 
     98  // Create an AnimaitonValue from a string. This method flushes style, so we
     99  // should use this carefully. Now, it is only used by
    100  // nsDOMWindowUtils::ComputeAnimationDistance.
    101  static AnimationValue FromString(CSSPropertyId& aProperty,
    102                                   const nsACString& aValue,
    103                                   dom::Element* aElement);
    104 
    105  // Create an already_AddRefed<StyleAnimationValue> from a
    106  // layers::Animatable. Basically, this function should return AnimationValue,
    107  // but it seems the caller, AnimationHelper, only needs
    108  // StyleAnimationValue, so we return its already_AddRefed<> to avoid
    109  // adding/removing a redundant ref-count.
    110  static already_AddRefed<StyleAnimationValue> FromAnimatable(
    111      NonCustomCSSPropertyId aProperty, const layers::Animatable& aAnimatable);
    112 
    113  RefPtr<StyleAnimationValue> mServo;
    114 };
    115 
    116 inline std::ostream& operator<<(std::ostream& aOut,
    117                                const AnimationValue& aValue) {
    118  MOZ_ASSERT(aValue.mServo);
    119  nsAutoCString s;
    120  Servo_AnimationValue_Dump(aValue.mServo, &s);
    121  return aOut << s;
    122 }
    123 
    124 struct PropertyStyleAnimationValuePair {
    125  CSSPropertyId mProperty;
    126  AnimationValue mValue;
    127 };
    128 }  // namespace mozilla
    129 
    130 #endif