Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / canvas / CanvasGradient.h
blob9455f7b14b36c90cff1b367b07ca67e8d2a63e4d
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 "nsTArray.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"
15 namespace mozilla::dom {
17 class CanvasRenderingContext2D;
19 class CanvasGradient : public nsWrapperCache {
20 public:
21 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(CanvasGradient)
22 NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(CanvasGradient)
24 enum class Type : uint8_t { LINEAR = 0, RADIAL, CONIC };
26 Type GetType() { return mType; }
28 already_AddRefed<mozilla::gfx::GradientStops> GetGradientStopsForTarget(
29 mozilla::gfx::DrawTarget* aRT) {
30 return gfx::gfxGradientCache::GetOrCreateGradientStops(
31 aRT, mRawStops, gfx::ExtendMode::CLAMP);
34 // WebIDL
35 void AddColorStop(float offset, const nsACString& colorstr, ErrorResult& rv);
37 JSObject* WrapObject(JSContext* aCx,
38 JS::Handle<JSObject*> aGivenProto) override {
39 return CanvasGradient_Binding::Wrap(aCx, this, aGivenProto);
42 CanvasRenderingContext2D* GetParentObject() { return mContext; }
44 protected:
45 friend struct CanvasBidiProcessor;
47 CanvasGradient(CanvasRenderingContext2D* aContext, Type aType);
49 virtual ~CanvasGradient();
51 RefPtr<CanvasRenderingContext2D> mContext;
52 nsTArray<mozilla::gfx::GradientStop> mRawStops;
53 Type mType;
56 } // namespace mozilla::dom
58 #endif // mozilla_dom_CanvasGradient_h