Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/TextTrackRegion.h
Line
Count
Source (jump to first uncovered line)
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/. */
6
7
#ifndef mozilla_dom_TextTrackRegion_h
8
#define mozilla_dom_TextTrackRegion_h
9
10
#include "nsCycleCollectionParticipant.h"
11
#include "nsString.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"
17
18
namespace mozilla {
19
namespace dom {
20
21
class GlobalObject;
22
class TextTrack;
23
24
class TextTrackRegion final : public nsISupports,
25
                              public nsWrapperCache
26
{
27
public:
28
29
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
30
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TextTrackRegion)
31
32
  JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
33
34
  nsISupports* GetParentObject() const
35
0
  {
36
0
    return mParent;
37
0
  }
38
39
  explicit TextTrackRegion(nsISupports* aGlobal);
40
41
  /** WebIDL Methods. */
42
43
  static already_AddRefed<TextTrackRegion>
44
  Constructor(const GlobalObject& aGlobal, ErrorResult& aRv);
45
46
  double Lines() const
47
0
  {
48
0
    return mLines;
49
0
  }
50
51
  void SetLines(double aLines, ErrorResult& aRv)
52
0
  {
53
0
    if (aLines < 0) {
54
0
      aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
55
0
    } else {
56
0
      mLines = aLines;
57
0
    }
58
0
  }
59
60
  double Width() const
61
0
  {
62
0
    return mWidth;
63
0
  }
64
65
  void SetWidth(double aWidth, ErrorResult& aRv)
66
0
  {
67
0
    if (!InvalidValue(aWidth, aRv)) {
68
0
      mWidth = aWidth;
69
0
    }
70
0
  }
71
72
  double RegionAnchorX() const
73
0
  {
74
0
    return mRegionAnchorX;
75
0
  }
76
77
  void SetRegionAnchorX(double aVal, ErrorResult& aRv)
78
0
  {
79
0
    if (!InvalidValue(aVal, aRv)) {
80
0
      mRegionAnchorX = aVal;
81
0
    }
82
0
  }
83
84
  double RegionAnchorY() const
85
0
  {
86
0
    return mRegionAnchorY;
87
0
  }
88
89
  void SetRegionAnchorY(double aVal, ErrorResult& aRv)
90
0
  {
91
0
    if (!InvalidValue(aVal, aRv)) {
92
0
      mRegionAnchorY = aVal;
93
0
    }
94
0
  }
95
96
  double ViewportAnchorX() const
97
0
  {
98
0
    return mViewportAnchorX;
99
0
  }
100
101
  void SetViewportAnchorX(double aVal, ErrorResult& aRv)
102
0
  {
103
0
    if (!InvalidValue(aVal, aRv)) {
104
0
      mViewportAnchorX = aVal;
105
0
    }
106
0
  }
107
108
  double ViewportAnchorY() const
109
0
  {
110
0
    return mViewportAnchorY;
111
0
  }
112
113
  void SetViewportAnchorY(double aVal, ErrorResult& aRv)
114
0
  {
115
0
    if (!InvalidValue(aVal, aRv)) {
116
0
      mViewportAnchorY = aVal;
117
0
    }
118
0
  }
119
120
  ScrollSetting Scroll() const
121
0
  {
122
0
    return mScroll;
123
0
  }
124
125
  void SetScroll(const ScrollSetting& aScroll)
126
0
  {
127
0
    if (aScroll == ScrollSetting::_empty || aScroll == ScrollSetting::Up) {
128
0
      mScroll = aScroll;
129
0
    }
130
0
  }
131
132
  void GetId(nsAString& aId) const
133
0
  {
134
0
    aId = mId;
135
0
  }
136
137
  void SetId(const nsAString& aId)
138
0
  {
139
0
    mId = aId;
140
0
  }
141
142
  /** end WebIDL Methods. */
143
144
145
  // Helper to aid copying of a given TextTrackRegion's width, lines,
146
  // anchor, viewport and scroll values.
147
  void CopyValues(TextTrackRegion& aRegion);
148
149
  // -----helpers-------
150
  const nsAString& Id() const
151
0
  {
152
0
    return mId;
153
0
  }
154
155
private:
156
0
  ~TextTrackRegion() {}
157
158
  nsCOMPtr<nsISupports> mParent;
159
  nsString mId;
160
  double mWidth;
161
  long mLines;
162
  double mRegionAnchorX;
163
  double mRegionAnchorY;
164
  double mViewportAnchorX;
165
  double mViewportAnchorY;
166
  ScrollSetting mScroll;
167
168
  // Helper to ensure new value is in the range: 0.0% - 100.0%; throws
169
  // an IndexSizeError otherwise.
170
  inline bool InvalidValue(double aValue, ErrorResult& aRv)
171
0
  {
172
0
    if(aValue < 0.0  || aValue > 100.0) {
173
0
      aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
174
0
      return true;
175
0
    }
176
0
177
0
    return false;
178
0
  }
179
180
};
181
182
} //namespace dom
183
} //namespace mozilla
184
185
#endif //mozilla_dom_TextTrackRegion_h