1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 et tw=78: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_TextTrackRegion_h
8 #define mozilla_dom_TextTrackRegion_h
10 #include "nsCycleCollectionParticipant.h"
12 #include "nsWrapperCache.h"
13 #include "mozilla/ErrorResult.h"
14 #include "mozilla/dom/TextTrack.h"
15 #include "mozilla/dom/VTTRegionBinding.h"
16 #include "mozilla/Preferences.h"
18 namespace mozilla::dom
{
23 class TextTrackRegion final
: public nsISupports
, public nsWrapperCache
{
25 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
26 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(TextTrackRegion
)
28 JSObject
* WrapObject(JSContext
* aCx
,
29 JS::Handle
<JSObject
*> aGivenProto
) override
;
31 nsISupports
* GetParentObject() const { return mParent
; }
33 explicit TextTrackRegion(nsISupports
* aGlobal
);
35 /** WebIDL Methods. */
37 static already_AddRefed
<TextTrackRegion
> Constructor(
38 const GlobalObject
& aGlobal
, ErrorResult
& aRv
);
40 double Lines() const { return mLines
; }
42 void SetLines(double aLines
, ErrorResult
& aRv
) {
44 aRv
.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR
);
50 double Width() const { return mWidth
; }
52 void SetWidth(double aWidth
, ErrorResult
& aRv
) {
53 if (!InvalidValue(aWidth
, aRv
)) {
58 double RegionAnchorX() const { return mRegionAnchorX
; }
60 void SetRegionAnchorX(double aVal
, ErrorResult
& aRv
) {
61 if (!InvalidValue(aVal
, aRv
)) {
62 mRegionAnchorX
= aVal
;
66 double RegionAnchorY() const { return mRegionAnchorY
; }
68 void SetRegionAnchorY(double aVal
, ErrorResult
& aRv
) {
69 if (!InvalidValue(aVal
, aRv
)) {
70 mRegionAnchorY
= aVal
;
74 double ViewportAnchorX() const { return mViewportAnchorX
; }
76 void SetViewportAnchorX(double aVal
, ErrorResult
& aRv
) {
77 if (!InvalidValue(aVal
, aRv
)) {
78 mViewportAnchorX
= aVal
;
82 double ViewportAnchorY() const { return mViewportAnchorY
; }
84 void SetViewportAnchorY(double aVal
, ErrorResult
& aRv
) {
85 if (!InvalidValue(aVal
, aRv
)) {
86 mViewportAnchorY
= aVal
;
90 ScrollSetting
Scroll() const { return mScroll
; }
92 void SetScroll(const ScrollSetting
& aScroll
) {
93 if (aScroll
== ScrollSetting::_empty
|| aScroll
== ScrollSetting::Up
) {
98 void GetId(nsAString
& aId
) const { aId
= mId
; }
100 void SetId(const nsAString
& aId
) { mId
= aId
; }
102 /** end WebIDL Methods. */
104 // Helper to aid copying of a given TextTrackRegion's width, lines,
105 // anchor, viewport and scroll values.
106 void CopyValues(TextTrackRegion
& aRegion
);
108 // -----helpers-------
109 const nsAString
& Id() const { return mId
; }
112 ~TextTrackRegion() = default;
114 nsCOMPtr
<nsISupports
> mParent
;
118 double mRegionAnchorX
;
119 double mRegionAnchorY
;
120 double mViewportAnchorX
;
121 double mViewportAnchorY
;
122 ScrollSetting mScroll
;
124 // Helper to ensure new value is in the range: 0.0% - 100.0%; throws
125 // an IndexSizeError otherwise.
126 inline bool InvalidValue(double aValue
, ErrorResult
& aRv
) {
127 if (aValue
< 0.0 || aValue
> 100.0) {
128 aRv
.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR
);
136 } // namespace mozilla::dom
138 #endif // mozilla_dom_TextTrackRegion_h