michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_CanvasGradient_h michael@0: #define mozilla_dom_CanvasGradient_h michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsTArray.h" michael@0: #include "mozilla/RefPtr.h" michael@0: #include "mozilla/dom/CanvasRenderingContext2DBinding.h" michael@0: #include "mozilla/dom/CanvasRenderingContext2D.h" michael@0: #include "mozilla/gfx/2D.h" michael@0: #include "nsWrapperCache.h" michael@0: #include "gfxGradientCache.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class CanvasGradient : public nsWrapperCache michael@0: { michael@0: public: michael@0: NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(CanvasGradient) michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(CanvasGradient) michael@0: michael@0: MOZ_BEGIN_NESTED_ENUM_CLASS(Type, uint8_t) michael@0: LINEAR = 0, michael@0: RADIAL michael@0: MOZ_END_NESTED_ENUM_CLASS(Type) michael@0: michael@0: Type GetType() michael@0: { michael@0: return mType; michael@0: } michael@0: michael@0: mozilla::gfx::GradientStops * michael@0: GetGradientStopsForTarget(mozilla::gfx::DrawTarget *aRT) michael@0: { michael@0: if (mStops && mStops->GetBackendType() == aRT->GetType()) { michael@0: return mStops; michael@0: } michael@0: michael@0: mStops = michael@0: gfx::gfxGradientCache::GetOrCreateGradientStops(aRT, michael@0: mRawStops, michael@0: gfx::ExtendMode::CLAMP); michael@0: michael@0: return mStops; michael@0: } michael@0: michael@0: // WebIDL michael@0: void AddColorStop(float offset, const nsAString& colorstr, ErrorResult& rv); michael@0: michael@0: JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE michael@0: { michael@0: return CanvasGradientBinding::Wrap(aCx, this); michael@0: } michael@0: michael@0: CanvasRenderingContext2D* GetParentObject() michael@0: { michael@0: return mContext; michael@0: } michael@0: michael@0: protected: michael@0: CanvasGradient(CanvasRenderingContext2D* aContext, mozilla::css::Loader *aLoader, Type aType) michael@0: : mContext(aContext) michael@0: , mCSSLoader(aLoader) michael@0: , mType(aType) michael@0: { michael@0: SetIsDOMBinding(); michael@0: } michael@0: michael@0: nsRefPtr mContext; michael@0: nsTArray mRawStops; michael@0: mozilla::RefPtr mStops; michael@0: mozilla::css::Loader* mCSSLoader; // not ref counted, it owns us michael@0: Type mType; michael@0: virtual ~CanvasGradient() {} michael@0: }; michael@0: michael@0: MOZ_FINISH_NESTED_ENUM_CLASS(CanvasGradient::Type) michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_dom_CanvasGradient_h