michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 et tw=78: */ 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 michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_TextTrackRegion_h michael@0: #define mozilla_dom_TextTrackRegion_h michael@0: michael@0: #include "nsAutoPtr.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "nsString.h" michael@0: #include "nsWrapperCache.h" michael@0: #include "mozilla/ErrorResult.h" michael@0: #include "mozilla/dom/TextTrack.h" michael@0: #include "mozilla/Preferences.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class GlobalObject; michael@0: class TextTrack; michael@0: michael@0: class TextTrackRegion MOZ_FINAL : public nsISupports, michael@0: public nsWrapperCache michael@0: { michael@0: public: michael@0: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TextTrackRegion) michael@0: michael@0: static bool RegionsEnabled(JSContext* cx, JSObject* obj) michael@0: { michael@0: return Preferences::GetBool("media.webvtt.enabled") && michael@0: Preferences::GetBool("media.webvtt.regions.enabled"); michael@0: } michael@0: michael@0: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: nsISupports* GetParentObject() const michael@0: { michael@0: return mParent; michael@0: } michael@0: michael@0: TextTrackRegion(nsISupports* aGlobal); michael@0: michael@0: /** WebIDL Methods. */ michael@0: michael@0: static already_AddRefed michael@0: Constructor(const GlobalObject& aGlobal, ErrorResult& aRv); michael@0: michael@0: double Lines() const michael@0: { michael@0: return mLines; michael@0: } michael@0: michael@0: void SetLines(double aLines) michael@0: { michael@0: mLines = aLines; michael@0: } michael@0: michael@0: double Width() const michael@0: { michael@0: return mWidth; michael@0: } michael@0: michael@0: void SetWidth(double aWidth, ErrorResult& aRv) michael@0: { michael@0: if (!InvalidValue(aWidth, aRv)) { michael@0: mWidth = aWidth; michael@0: } michael@0: } michael@0: michael@0: double RegionAnchorX() const michael@0: { michael@0: return mRegionAnchorX; michael@0: } michael@0: michael@0: void SetRegionAnchorX(double aVal, ErrorResult& aRv) michael@0: { michael@0: if (!InvalidValue(aVal, aRv)) { michael@0: mRegionAnchorX = aVal; michael@0: } michael@0: } michael@0: michael@0: double RegionAnchorY() const michael@0: { michael@0: return mRegionAnchorY; michael@0: } michael@0: michael@0: void SetRegionAnchorY(double aVal, ErrorResult& aRv) michael@0: { michael@0: if (!InvalidValue(aVal, aRv)) { michael@0: mRegionAnchorY = aVal; michael@0: } michael@0: } michael@0: michael@0: double ViewportAnchorX() const michael@0: { michael@0: return mViewportAnchorX; michael@0: } michael@0: michael@0: void SetViewportAnchorX(double aVal, ErrorResult& aRv) michael@0: { michael@0: if (!InvalidValue(aVal, aRv)) { michael@0: mViewportAnchorX = aVal; michael@0: } michael@0: } michael@0: michael@0: double ViewportAnchorY() const michael@0: { michael@0: return mViewportAnchorY; michael@0: } michael@0: michael@0: void SetViewportAnchorY(double aVal, ErrorResult& aRv) michael@0: { michael@0: if (!InvalidValue(aVal, aRv)) { michael@0: mViewportAnchorY = aVal; michael@0: } michael@0: } michael@0: michael@0: void GetScroll(nsAString& aScroll) const michael@0: { michael@0: aScroll = mScroll; michael@0: } michael@0: michael@0: void SetScroll(const nsAString& aScroll, ErrorResult& aRv) michael@0: { michael@0: if (!aScroll.EqualsLiteral("") && !aScroll.EqualsLiteral("up")) { michael@0: aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR); michael@0: return; michael@0: } michael@0: michael@0: mScroll = aScroll; michael@0: } michael@0: michael@0: /** end WebIDL Methods. */ michael@0: michael@0: michael@0: // Helper to aid copying of a given TextTrackRegion's width, lines, michael@0: // anchor, viewport and scroll values. michael@0: void CopyValues(TextTrackRegion& aRegion); michael@0: michael@0: // -----helpers------- michael@0: const nsAString& Scroll() const michael@0: { michael@0: return mScroll; michael@0: } michael@0: michael@0: private: michael@0: nsCOMPtr mParent; michael@0: double mWidth; michael@0: long mLines; michael@0: double mRegionAnchorX; michael@0: double mRegionAnchorY; michael@0: double mViewportAnchorX; michael@0: double mViewportAnchorY; michael@0: nsString mScroll; michael@0: michael@0: // Helper to ensure new value is in the range: 0.0% - 100.0%; throws michael@0: // an IndexSizeError otherwise. michael@0: inline bool InvalidValue(double aValue, ErrorResult& aRv) michael@0: { michael@0: if(aValue < 0.0 || aValue > 100.0) { michael@0: aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); michael@0: return true; michael@0: } michael@0: michael@0: return false; michael@0: } michael@0: michael@0: }; michael@0: michael@0: } //namespace dom michael@0: } //namespace mozilla michael@0: michael@0: #endif //mozilla_dom_TextTrackRegion_h