content/canvas/src/CanvasGradient.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

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.)

     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 "mozilla/Attributes.h"
     9 #include "nsTArray.h"
    10 #include "mozilla/RefPtr.h"
    11 #include "mozilla/dom/CanvasRenderingContext2DBinding.h"
    12 #include "mozilla/dom/CanvasRenderingContext2D.h"
    13 #include "mozilla/gfx/2D.h"
    14 #include "nsWrapperCache.h"
    15 #include "gfxGradientCache.h"
    17 namespace mozilla {
    18 namespace dom {
    20 class CanvasGradient : public nsWrapperCache
    21 {
    22 public:
    23   NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(CanvasGradient)
    24   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(CanvasGradient)
    26   MOZ_BEGIN_NESTED_ENUM_CLASS(Type, uint8_t)
    27     LINEAR = 0,
    28     RADIAL
    29   MOZ_END_NESTED_ENUM_CLASS(Type)
    31   Type GetType()
    32   {
    33     return mType;
    34   }
    36   mozilla::gfx::GradientStops *
    37   GetGradientStopsForTarget(mozilla::gfx::DrawTarget *aRT)
    38   {
    39     if (mStops && mStops->GetBackendType() == aRT->GetType()) {
    40       return mStops;
    41     }
    43     mStops =
    44       gfx::gfxGradientCache::GetOrCreateGradientStops(aRT,
    45                                                       mRawStops,
    46                                                       gfx::ExtendMode::CLAMP);
    48     return mStops;
    49   }
    51   // WebIDL
    52   void AddColorStop(float offset, const nsAString& colorstr, ErrorResult& rv);
    54   JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE
    55   {
    56     return CanvasGradientBinding::Wrap(aCx, this);
    57   }
    59   CanvasRenderingContext2D* GetParentObject()
    60   {
    61     return mContext;
    62   }
    64 protected:
    65   CanvasGradient(CanvasRenderingContext2D* aContext, mozilla::css::Loader *aLoader, Type aType)
    66     : mContext(aContext)
    67     , mCSSLoader(aLoader)
    68     , mType(aType)
    69   {
    70     SetIsDOMBinding();
    71   }
    73   nsRefPtr<CanvasRenderingContext2D> mContext;
    74   nsTArray<mozilla::gfx::GradientStop> mRawStops;
    75   mozilla::RefPtr<mozilla::gfx::GradientStops> mStops;
    76   mozilla::css::Loader* mCSSLoader; // not ref counted, it owns us
    77   Type mType;
    78   virtual ~CanvasGradient() {}
    79 };
    81 MOZ_FINISH_NESTED_ENUM_CLASS(CanvasGradient::Type)
    83 } // namespace dom
    84 } // namespace mozilla
    86 #endif // mozilla_dom_CanvasGradient_h

mercurial