content/canvas/src/CanvasGradient.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/canvas/src/CanvasGradient.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,86 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef mozilla_dom_CanvasGradient_h
     1.9 +#define mozilla_dom_CanvasGradient_h
    1.10 +
    1.11 +#include "mozilla/Attributes.h"
    1.12 +#include "nsTArray.h"
    1.13 +#include "mozilla/RefPtr.h"
    1.14 +#include "mozilla/dom/CanvasRenderingContext2DBinding.h"
    1.15 +#include "mozilla/dom/CanvasRenderingContext2D.h"
    1.16 +#include "mozilla/gfx/2D.h"
    1.17 +#include "nsWrapperCache.h"
    1.18 +#include "gfxGradientCache.h"
    1.19 +
    1.20 +namespace mozilla {
    1.21 +namespace dom {
    1.22 +
    1.23 +class CanvasGradient : public nsWrapperCache
    1.24 +{
    1.25 +public:
    1.26 +  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(CanvasGradient)
    1.27 +  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(CanvasGradient)
    1.28 +
    1.29 +  MOZ_BEGIN_NESTED_ENUM_CLASS(Type, uint8_t)
    1.30 +    LINEAR = 0,
    1.31 +    RADIAL
    1.32 +  MOZ_END_NESTED_ENUM_CLASS(Type)
    1.33 +
    1.34 +  Type GetType()
    1.35 +  {
    1.36 +    return mType;
    1.37 +  }
    1.38 +
    1.39 +  mozilla::gfx::GradientStops *
    1.40 +  GetGradientStopsForTarget(mozilla::gfx::DrawTarget *aRT)
    1.41 +  {
    1.42 +    if (mStops && mStops->GetBackendType() == aRT->GetType()) {
    1.43 +      return mStops;
    1.44 +    }
    1.45 +
    1.46 +    mStops =
    1.47 +      gfx::gfxGradientCache::GetOrCreateGradientStops(aRT,
    1.48 +                                                      mRawStops,
    1.49 +                                                      gfx::ExtendMode::CLAMP);
    1.50 +
    1.51 +    return mStops;
    1.52 +  }
    1.53 +
    1.54 +  // WebIDL
    1.55 +  void AddColorStop(float offset, const nsAString& colorstr, ErrorResult& rv);
    1.56 +
    1.57 +  JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE
    1.58 +  {
    1.59 +    return CanvasGradientBinding::Wrap(aCx, this);
    1.60 +  }
    1.61 +
    1.62 +  CanvasRenderingContext2D* GetParentObject()
    1.63 +  {
    1.64 +    return mContext;
    1.65 +  }
    1.66 +
    1.67 +protected:
    1.68 +  CanvasGradient(CanvasRenderingContext2D* aContext, mozilla::css::Loader *aLoader, Type aType)
    1.69 +    : mContext(aContext)
    1.70 +    , mCSSLoader(aLoader)
    1.71 +    , mType(aType)
    1.72 +  {
    1.73 +    SetIsDOMBinding();
    1.74 +  }
    1.75 +
    1.76 +  nsRefPtr<CanvasRenderingContext2D> mContext;
    1.77 +  nsTArray<mozilla::gfx::GradientStop> mRawStops;
    1.78 +  mozilla::RefPtr<mozilla::gfx::GradientStops> mStops;
    1.79 +  mozilla::css::Loader* mCSSLoader; // not ref counted, it owns us
    1.80 +  Type mType;
    1.81 +  virtual ~CanvasGradient() {}
    1.82 +};
    1.83 +
    1.84 +MOZ_FINISH_NESTED_ENUM_CLASS(CanvasGradient::Type)
    1.85 +
    1.86 +} // namespace dom
    1.87 +} // namespace mozilla
    1.88 +
    1.89 +#endif // mozilla_dom_CanvasGradient_h

mercurial