tor-browser

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

SMILValue.h (2537B)


      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 #ifndef DOM_SMIL_SMILVALUE_H_
      8 #define DOM_SMIL_SMILVALUE_H_
      9 
     10 #include "mozilla/SMILNullType.h"
     11 #include "mozilla/SMILType.h"
     12 
     13 namespace mozilla {
     14 
     15 /**
     16 * Although objects of this type are generally only created on the stack and
     17 * only exist during the taking of a new time sample, that's not always the
     18 * case. The SMILValue objects obtained from attributes' base values are
     19 * cached so that the SMIL engine can make certain optimizations during a
     20 * sample if the base value has not changed since the last sample (potentially
     21 * avoiding recomposing). These SMILValue objects typically live much longer
     22 * than a single sample.
     23 */
     24 class SMILValue {
     25 public:
     26  SMILValue() : mU(), mType(SMILNullType::Singleton()) {}
     27  explicit SMILValue(const SMILType* aType);
     28  SMILValue(const SMILValue& aVal);
     29 
     30  ~SMILValue() { mType->DestroyValue(*this); }
     31 
     32  const SMILValue& operator=(const SMILValue& aVal);
     33 
     34  // Move constructor / reassignment operator:
     35  SMILValue(SMILValue&& aVal) noexcept;
     36  SMILValue& operator=(SMILValue&& aVal) noexcept;
     37 
     38  // Equality operators. These are allowed to be conservative (return false
     39  // more than you'd expect) - see comment above SMILType::IsEqual.
     40  bool operator==(const SMILValue& aVal) const;
     41  bool operator!=(const SMILValue& aVal) const { return !(*this == aVal); }
     42 
     43  bool IsNull() const { return (mType == SMILNullType::Singleton()); }
     44 
     45  nsresult Add(const SMILValue& aValueToAdd, uint32_t aCount = 1);
     46  nsresult SandwichAdd(const SMILValue& aValueToAdd);
     47  nsresult ComputeDistance(const SMILValue& aTo, double& aDistance) const;
     48  nsresult Interpolate(const SMILValue& aEndVal, double aUnitDistance,
     49                       SMILValue& aResult) const;
     50 
     51  union {
     52    bool mBool;
     53    uint64_t mUint;
     54    int64_t mInt;
     55    double mDouble;
     56    struct {
     57      float mAngle;
     58      uint16_t mUnit;
     59      uint16_t mOrientType;
     60    } mOrient;
     61    int32_t mIntPair[2];
     62    float mNumberPair[2];
     63    void* mPtr;
     64  } mU;
     65  const SMILType* mType;
     66 
     67 protected:
     68  void InitAndCheckPostcondition(const SMILType* aNewType);
     69  void DestroyAndCheckPostcondition();
     70  void DestroyAndReinit(const SMILType* aNewType);
     71 };
     72 
     73 }  // namespace mozilla
     74 
     75 #endif  // DOM_SMIL_SMILVALUE_H_