content/media/TextTrackRegion.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/TextTrackRegion.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,177 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:set ts=2 sw=2 et tw=78: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef mozilla_dom_TextTrackRegion_h
    1.11 +#define mozilla_dom_TextTrackRegion_h
    1.12 +
    1.13 +#include "nsAutoPtr.h"
    1.14 +#include "nsCycleCollectionParticipant.h"
    1.15 +#include "nsString.h"
    1.16 +#include "nsWrapperCache.h"
    1.17 +#include "mozilla/ErrorResult.h"
    1.18 +#include "mozilla/dom/TextTrack.h"
    1.19 +#include "mozilla/Preferences.h"
    1.20 +
    1.21 +namespace mozilla {
    1.22 +namespace dom {
    1.23 +
    1.24 +class GlobalObject;
    1.25 +class TextTrack;
    1.26 +
    1.27 +class TextTrackRegion MOZ_FINAL : public nsISupports,
    1.28 +                                  public nsWrapperCache
    1.29 +{
    1.30 +public:
    1.31 +
    1.32 +  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    1.33 +  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TextTrackRegion)
    1.34 +
    1.35 +  static bool RegionsEnabled(JSContext* cx, JSObject* obj)
    1.36 +  {
    1.37 +    return Preferences::GetBool("media.webvtt.enabled") &&
    1.38 +           Preferences::GetBool("media.webvtt.regions.enabled");
    1.39 +  }
    1.40 +
    1.41 +  virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
    1.42 +
    1.43 +  nsISupports* GetParentObject() const
    1.44 +  {
    1.45 +    return mParent;
    1.46 +  }
    1.47 +
    1.48 +  TextTrackRegion(nsISupports* aGlobal);
    1.49 +
    1.50 +  /** WebIDL Methods. */
    1.51 +
    1.52 +  static already_AddRefed<TextTrackRegion>
    1.53 +  Constructor(const GlobalObject& aGlobal, ErrorResult& aRv);
    1.54 +
    1.55 +  double Lines() const
    1.56 +  {
    1.57 +    return mLines;
    1.58 +  }
    1.59 +
    1.60 +  void SetLines(double aLines)
    1.61 +  {
    1.62 +    mLines = aLines;
    1.63 +  }
    1.64 +
    1.65 +  double Width() const
    1.66 +  {
    1.67 +    return mWidth;
    1.68 +  }
    1.69 +
    1.70 +  void SetWidth(double aWidth, ErrorResult& aRv)
    1.71 +  {
    1.72 +    if (!InvalidValue(aWidth, aRv)) {
    1.73 +      mWidth = aWidth;
    1.74 +    }
    1.75 +  }
    1.76 +
    1.77 +  double RegionAnchorX() const
    1.78 +  {
    1.79 +    return mRegionAnchorX;
    1.80 +  }
    1.81 +
    1.82 +  void SetRegionAnchorX(double aVal, ErrorResult& aRv)
    1.83 +  {
    1.84 +    if (!InvalidValue(aVal, aRv)) {
    1.85 +      mRegionAnchorX = aVal;
    1.86 +    }
    1.87 +  }
    1.88 +
    1.89 +  double RegionAnchorY() const
    1.90 +  {
    1.91 +    return mRegionAnchorY;
    1.92 +  }
    1.93 +
    1.94 +  void SetRegionAnchorY(double aVal, ErrorResult& aRv)
    1.95 +  {
    1.96 +    if (!InvalidValue(aVal, aRv)) {
    1.97 +      mRegionAnchorY = aVal;
    1.98 +    }
    1.99 +  }
   1.100 +
   1.101 +  double ViewportAnchorX() const
   1.102 +  {
   1.103 +    return mViewportAnchorX;
   1.104 +  }
   1.105 +
   1.106 +  void SetViewportAnchorX(double aVal, ErrorResult& aRv)
   1.107 +  {
   1.108 +    if (!InvalidValue(aVal, aRv)) {
   1.109 +      mViewportAnchorX = aVal;
   1.110 +    }
   1.111 +  }
   1.112 +
   1.113 +  double ViewportAnchorY() const
   1.114 +  {
   1.115 +    return mViewportAnchorY;
   1.116 +  }
   1.117 +
   1.118 +  void SetViewportAnchorY(double aVal, ErrorResult& aRv)
   1.119 +  {
   1.120 +    if (!InvalidValue(aVal, aRv)) {
   1.121 +      mViewportAnchorY = aVal;
   1.122 +    }
   1.123 +  }
   1.124 +
   1.125 +  void GetScroll(nsAString& aScroll) const
   1.126 +  {
   1.127 +    aScroll = mScroll;
   1.128 +  }
   1.129 +
   1.130 +  void SetScroll(const nsAString& aScroll, ErrorResult& aRv)
   1.131 +  {
   1.132 +    if (!aScroll.EqualsLiteral("") && !aScroll.EqualsLiteral("up")) {
   1.133 +      aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
   1.134 +      return;
   1.135 +    }
   1.136 +
   1.137 +    mScroll = aScroll;
   1.138 +  }
   1.139 +
   1.140 +  /** end WebIDL Methods. */
   1.141 +
   1.142 +
   1.143 +  // Helper to aid copying of a given TextTrackRegion's width, lines,
   1.144 +  // anchor, viewport and scroll values.
   1.145 +  void CopyValues(TextTrackRegion& aRegion);
   1.146 +
   1.147 +  // -----helpers-------
   1.148 +  const nsAString& Scroll() const
   1.149 +  {
   1.150 +    return mScroll;
   1.151 +  }
   1.152 +
   1.153 +private:
   1.154 +  nsCOMPtr<nsISupports> mParent;
   1.155 +  double mWidth;
   1.156 +  long mLines;
   1.157 +  double mRegionAnchorX;
   1.158 +  double mRegionAnchorY;
   1.159 +  double mViewportAnchorX;
   1.160 +  double mViewportAnchorY;
   1.161 +  nsString mScroll;
   1.162 +
   1.163 +  // Helper to ensure new value is in the range: 0.0% - 100.0%; throws
   1.164 +  // an IndexSizeError otherwise.
   1.165 +  inline bool InvalidValue(double aValue, ErrorResult& aRv)
   1.166 +  {
   1.167 +    if(aValue < 0.0  || aValue > 100.0) {
   1.168 +      aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
   1.169 +      return true;
   1.170 +    }
   1.171 +
   1.172 +    return false;
   1.173 +  }
   1.174 +
   1.175 +};
   1.176 +
   1.177 +} //namespace dom
   1.178 +} //namespace mozilla
   1.179 +
   1.180 +#endif //mozilla_dom_TextTrackRegion_h

mercurial