Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifndef mozilla_dom_CanvasGradient_h |
michael@0 | 6 | #define mozilla_dom_CanvasGradient_h |
michael@0 | 7 | |
michael@0 | 8 | #include "mozilla/Attributes.h" |
michael@0 | 9 | #include "nsTArray.h" |
michael@0 | 10 | #include "mozilla/RefPtr.h" |
michael@0 | 11 | #include "mozilla/dom/CanvasRenderingContext2DBinding.h" |
michael@0 | 12 | #include "mozilla/dom/CanvasRenderingContext2D.h" |
michael@0 | 13 | #include "mozilla/gfx/2D.h" |
michael@0 | 14 | #include "nsWrapperCache.h" |
michael@0 | 15 | #include "gfxGradientCache.h" |
michael@0 | 16 | |
michael@0 | 17 | namespace mozilla { |
michael@0 | 18 | namespace dom { |
michael@0 | 19 | |
michael@0 | 20 | class CanvasGradient : public nsWrapperCache |
michael@0 | 21 | { |
michael@0 | 22 | public: |
michael@0 | 23 | NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(CanvasGradient) |
michael@0 | 24 | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(CanvasGradient) |
michael@0 | 25 | |
michael@0 | 26 | MOZ_BEGIN_NESTED_ENUM_CLASS(Type, uint8_t) |
michael@0 | 27 | LINEAR = 0, |
michael@0 | 28 | RADIAL |
michael@0 | 29 | MOZ_END_NESTED_ENUM_CLASS(Type) |
michael@0 | 30 | |
michael@0 | 31 | Type GetType() |
michael@0 | 32 | { |
michael@0 | 33 | return mType; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | mozilla::gfx::GradientStops * |
michael@0 | 37 | GetGradientStopsForTarget(mozilla::gfx::DrawTarget *aRT) |
michael@0 | 38 | { |
michael@0 | 39 | if (mStops && mStops->GetBackendType() == aRT->GetType()) { |
michael@0 | 40 | return mStops; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | mStops = |
michael@0 | 44 | gfx::gfxGradientCache::GetOrCreateGradientStops(aRT, |
michael@0 | 45 | mRawStops, |
michael@0 | 46 | gfx::ExtendMode::CLAMP); |
michael@0 | 47 | |
michael@0 | 48 | return mStops; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | // WebIDL |
michael@0 | 52 | void AddColorStop(float offset, const nsAString& colorstr, ErrorResult& rv); |
michael@0 | 53 | |
michael@0 | 54 | JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE |
michael@0 | 55 | { |
michael@0 | 56 | return CanvasGradientBinding::Wrap(aCx, this); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | CanvasRenderingContext2D* GetParentObject() |
michael@0 | 60 | { |
michael@0 | 61 | return mContext; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | protected: |
michael@0 | 65 | CanvasGradient(CanvasRenderingContext2D* aContext, mozilla::css::Loader *aLoader, Type aType) |
michael@0 | 66 | : mContext(aContext) |
michael@0 | 67 | , mCSSLoader(aLoader) |
michael@0 | 68 | , mType(aType) |
michael@0 | 69 | { |
michael@0 | 70 | SetIsDOMBinding(); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | nsRefPtr<CanvasRenderingContext2D> mContext; |
michael@0 | 74 | nsTArray<mozilla::gfx::GradientStop> mRawStops; |
michael@0 | 75 | mozilla::RefPtr<mozilla::gfx::GradientStops> mStops; |
michael@0 | 76 | mozilla::css::Loader* mCSSLoader; // not ref counted, it owns us |
michael@0 | 77 | Type mType; |
michael@0 | 78 | virtual ~CanvasGradient() {} |
michael@0 | 79 | }; |
michael@0 | 80 | |
michael@0 | 81 | MOZ_FINISH_NESTED_ENUM_CLASS(CanvasGradient::Type) |
michael@0 | 82 | |
michael@0 | 83 | } // namespace dom |
michael@0 | 84 | } // namespace mozilla |
michael@0 | 85 | |
michael@0 | 86 | #endif // mozilla_dom_CanvasGradient_h |