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
9 #include "mozilla/RefPtr.h"
10 #include "mozilla/dom/CanvasRenderingContext2DBinding.h"
11 #include "mozilla/gfx/2D.h"
12 #include "nsWrapperCache.h"
13 #include "gfxGradientCache.h"
18 class CanvasRenderingContext2D
;
20 class CanvasGradient
: public nsWrapperCache
{
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
, CONIC
};
27 Type
GetType() { return mType
; }
29 already_AddRefed
<mozilla::gfx::GradientStops
> GetGradientStopsForTarget(
30 mozilla::gfx::DrawTarget
* aRT
) {
31 return gfx::gfxGradientCache::GetOrCreateGradientStops(
32 aRT
, mRawStops
, gfx::ExtendMode::CLAMP
);
36 void AddColorStop(float offset
, const nsACString
& colorstr
, ErrorResult
& rv
);
38 JSObject
* WrapObject(JSContext
* aCx
,
39 JS::Handle
<JSObject
*> aGivenProto
) override
{
40 return CanvasGradient_Binding::Wrap(aCx
, this, aGivenProto
);
43 CanvasRenderingContext2D
* GetParentObject() { return mContext
; }
46 friend struct CanvasBidiProcessor
;
48 CanvasGradient(CanvasRenderingContext2D
* aContext
, Type aType
);
50 virtual ~CanvasGradient();
52 RefPtr
<CanvasRenderingContext2D
> mContext
;
53 nsTArray
<mozilla::gfx::GradientStop
> mRawStops
;
58 } // namespace mozilla
60 #endif // mozilla_dom_CanvasGradient_h