Bug 1610775 [wpt PR 21336] - Update urllib3 to 1.25.8, a=testonly
[gecko.git] / dom / canvas / CanvasGradient.h
blob0e86048795c001be8e86873c42b29910aafa2e49
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/. */
5 #ifndef mozilla_dom_CanvasGradient_h
6 #define mozilla_dom_CanvasGradient_h
8 #include "mozilla/Attributes.h"
9 #include "nsTArray.h"
10 #include "mozilla/RefPtr.h"
11 #include "mozilla/dom/CanvasRenderingContext2DBinding.h"
12 #include "mozilla/dom/CanvasRenderingContext2D.h"
13 #include "mozilla/gfx/2D.h"
14 #include "nsWrapperCache.h"
15 #include "gfxGradientCache.h"
17 namespace mozilla {
18 namespace dom {
20 class CanvasGradient : public nsWrapperCache {
21 public:
22 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(CanvasGradient)
23 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(CanvasGradient)
25 enum class Type : uint8_t { LINEAR = 0, RADIAL };
27 Type GetType() { return mType; }
29 mozilla::gfx::GradientStops* GetGradientStopsForTarget(
30 mozilla::gfx::DrawTarget* aRT) {
31 if (mStops && mStops->GetBackendType() == aRT->GetBackendType()) {
32 return mStops;
35 mStops = gfx::gfxGradientCache::GetOrCreateGradientStops(
36 aRT, mRawStops, gfx::ExtendMode::CLAMP);
38 return mStops;
41 // WebIDL
42 void AddColorStop(float offset, const nsACString& colorstr, ErrorResult& rv);
44 JSObject* WrapObject(JSContext* aCx,
45 JS::Handle<JSObject*> aGivenProto) override {
46 return CanvasGradient_Binding::Wrap(aCx, this, aGivenProto);
49 CanvasRenderingContext2D* GetParentObject() { return mContext; }
51 protected:
52 friend struct CanvasBidiProcessor;
54 CanvasGradient(CanvasRenderingContext2D* aContext, Type aType)
55 : mContext(aContext), mType(aType) {}
57 RefPtr<CanvasRenderingContext2D> mContext;
58 nsTArray<mozilla::gfx::GradientStop> mRawStops;
59 RefPtr<mozilla::gfx::GradientStops> mStops;
60 Type mType;
61 virtual ~CanvasGradient() {}
64 } // namespace dom
65 } // namespace mozilla
67 #endif // mozilla_dom_CanvasGradient_h