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"
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"
20 class CanvasGradient
: public nsWrapperCache
23 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(CanvasGradient
)
24 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(CanvasGradient
)
26 MOZ_BEGIN_NESTED_ENUM_CLASS(Type
, uint8_t)
29 MOZ_END_NESTED_ENUM_CLASS(Type
)
36 mozilla::gfx::GradientStops
*
37 GetGradientStopsForTarget(mozilla::gfx::DrawTarget
*aRT
)
39 if (mStops
&& mStops
->GetBackendType() == aRT
->GetBackendType()) {
44 gfx::gfxGradientCache::GetOrCreateGradientStops(aRT
,
46 gfx::ExtendMode::CLAMP
);
52 void AddColorStop(float offset
, const nsAString
& colorstr
, ErrorResult
& rv
);
54 JSObject
* WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
56 return CanvasGradientBinding::Wrap(aCx
, this);
59 CanvasRenderingContext2D
* GetParentObject()
65 CanvasGradient(CanvasRenderingContext2D
* aContext
, Type aType
)
72 nsRefPtr
<CanvasRenderingContext2D
> mContext
;
73 nsTArray
<mozilla::gfx::GradientStop
> mRawStops
;
74 mozilla::RefPtr
<mozilla::gfx::GradientStops
> mStops
;
76 virtual ~CanvasGradient() {}
79 MOZ_FINISH_NESTED_ENUM_CLASS(CanvasGradient::Type
)
82 } // namespace mozilla
84 #endif // mozilla_dom_CanvasGradient_h