tor-browser

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

CanvasGradient.h (1722B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #ifndef mozilla_dom_CanvasGradient_h
      6 #define mozilla_dom_CanvasGradient_h
      7 
      8 #include "gfxGradientCache.h"
      9 #include "mozilla/RefPtr.h"
     10 #include "mozilla/dom/CanvasRenderingContext2DBinding.h"
     11 #include "mozilla/gfx/2D.h"
     12 #include "nsTArray.h"
     13 #include "nsWrapperCache.h"
     14 
     15 namespace mozilla::dom {
     16 
     17 class CanvasRenderingContext2D;
     18 
     19 class CanvasGradient : public nsWrapperCache {
     20 public:
     21  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(CanvasGradient)
     22  NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(CanvasGradient)
     23 
     24  enum class Type : uint8_t { LINEAR = 0, RADIAL, CONIC };
     25 
     26  Type GetType() { return mType; }
     27 
     28  already_AddRefed<mozilla::gfx::GradientStops> GetGradientStopsForTarget(
     29      mozilla::gfx::DrawTarget* aRT) {
     30    return gfx::gfxGradientCache::GetOrCreateGradientStops(
     31        aRT, mRawStops, gfx::ExtendMode::CLAMP);
     32  }
     33 
     34  // WebIDL
     35  void AddColorStop(float offset, const nsACString& colorstr, ErrorResult& rv);
     36 
     37  JSObject* WrapObject(JSContext* aCx,
     38                       JS::Handle<JSObject*> aGivenProto) override {
     39    return CanvasGradient_Binding::Wrap(aCx, this, aGivenProto);
     40  }
     41 
     42  CanvasRenderingContext2D* GetParentObject() { return mContext; }
     43 
     44 protected:
     45  friend struct CanvasBidiProcessor;
     46 
     47  CanvasGradient(CanvasRenderingContext2D* aContext, Type aType);
     48 
     49  virtual ~CanvasGradient();
     50 
     51  RefPtr<CanvasRenderingContext2D> mContext;
     52  nsTArray<mozilla::gfx::GradientStop> mRawStops;
     53  Type mType;
     54 };
     55 
     56 }  // namespace mozilla::dom
     57 
     58 #endif  // mozilla_dom_CanvasGradient_h