• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013, Opera Software ASA. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  * 3. Neither the name of Opera Software ASA nor the names of its
13  *    contributors may be used to endorse or promote products derived
14  *    from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27  * OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef VTTCue_h
31 #define VTTCue_h
32 
33 #include "bindings/v8/ScriptWrappable.h"
34 #include "core/html/track/TextTrackCue.h"
35 #include "platform/heap/Handle.h"
36 
37 namespace WebCore {
38 
39 class Document;
40 class ExecutionContext;
41 class VTTCue;
42 class VTTScanner;
43 
44 class VTTCueBox FINAL : public HTMLDivElement {
45 public:
create(Document & document,VTTCue * cue)46     static PassRefPtrWillBeRawPtr<VTTCueBox> create(Document& document, VTTCue* cue)
47     {
48         return adoptRefWillBeNoop(new VTTCueBox(document, cue));
49     }
50 
getCue()51     VTTCue* getCue() const { return m_cue; }
52     void applyCSSProperties(const IntSize& videoSize);
53 
54     virtual void trace(Visitor*) OVERRIDE;
55 
56 private:
57     VTTCueBox(Document&, VTTCue*);
58 
59     virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
60 
61     RawPtrWillBeMember<VTTCue> m_cue;
62 };
63 
64 class VTTCue FINAL : public TextTrackCue, public ScriptWrappable {
65 public:
create(Document & document,double startTime,double endTime,const String & text)66     static PassRefPtrWillBeRawPtr<VTTCue> create(Document& document, double startTime, double endTime, const String& text)
67     {
68         return adoptRefWillBeRefCountedGarbageCollected(new VTTCue(document, startTime, endTime, text));
69     }
70 
71     virtual ~VTTCue();
72 
73     const String& vertical() const;
74     void setVertical(const String&);
75 
snapToLines()76     bool snapToLines() const { return m_snapToLines; }
77     void setSnapToLines(bool);
78 
line()79     int line() const { return m_linePosition; }
80     void setLine(int, ExceptionState&);
81 
position()82     int position() const { return m_textPosition; }
83     void setPosition(int, ExceptionState&);
84 
size()85     int size() const { return m_cueSize; }
86     void setSize(int, ExceptionState&);
87 
88     const String& align() const;
89     void setAlign(const String&);
90 
text()91     const String& text() const { return m_text; }
92     void setText(const String&);
93 
94     void parseSettings(const String&);
95 
96     PassRefPtrWillBeRawPtr<DocumentFragment> getCueAsHTML();
97     PassRefPtrWillBeRawPtr<DocumentFragment> createCueRenderingTree();
98 
regionId()99     const String& regionId() const { return m_regionId; }
100     void setRegionId(const String&);
101 
102     virtual void updateDisplay(const IntSize& videoSize, HTMLDivElement& container) OVERRIDE;
103 
104     virtual void updateDisplayTree(double movieTime) OVERRIDE;
105     virtual void removeDisplayTree() OVERRIDE;
106     virtual void notifyRegionWhenRemovingDisplayTree(bool notifyRegion) OVERRIDE;
107 
108     void markFutureAndPastNodes(ContainerNode*, double previousTimestamp, double movieTime);
109 
110     int calculateComputedLinePosition();
111 
112     std::pair<double, double> getCSSPosition() const;
113 
114     CSSValueID getCSSAlignment() const;
115     int getCSSSize() const;
116     CSSValueID getCSSWritingDirection() const;
117     CSSValueID getCSSWritingMode() const;
118 
119     enum WritingDirection {
120         Horizontal = 0,
121         VerticalGrowingLeft,
122         VerticalGrowingRight,
123         NumberOfWritingDirections
124     };
getWritingDirection()125     WritingDirection getWritingDirection() const { return m_writingDirection; }
126 
127     enum CueAlignment {
128         Start = 0,
129         Middle,
130         End,
131         Left,
132         Right,
133         NumberOfAlignments
134     };
getAlignment()135     CueAlignment getAlignment() const { return m_cueAlignment; }
136 
137     virtual ExecutionContext* executionContext() const OVERRIDE;
138 
139 #ifndef NDEBUG
140     virtual String toString() const OVERRIDE;
141 #endif
142 
143     virtual void trace(Visitor*) OVERRIDE;
144 
145 private:
146     VTTCue(Document&, double startTime, double endTime, const String& text);
147 
148     Document& document() const;
149 
150     VTTCueBox& ensureDisplayTree();
151     PassRefPtrWillBeRawPtr<VTTCueBox> getDisplayTree(const IntSize& videoSize);
152 
153     virtual void cueDidChange() OVERRIDE;
154 
155     void createVTTNodeTree();
156     void copyVTTNodeToDOMTree(ContainerNode* vttNode, ContainerNode* root);
157 
158     std::pair<double, double> getPositionCoordinates() const;
159 
160     void calculateDisplayParameters();
161 
162     enum CueSetting {
163         None,
164         Vertical,
165         Line,
166         Position,
167         Size,
168         Align,
169         RegionId
170     };
171     CueSetting settingName(VTTScanner&);
172 
173     String m_text;
174     int m_linePosition;
175     int m_computedLinePosition;
176     int m_textPosition;
177     int m_cueSize;
178     WritingDirection m_writingDirection;
179     CueAlignment m_cueAlignment;
180     String m_regionId;
181 
182     RefPtrWillBeMember<DocumentFragment> m_vttNodeTree;
183     RefPtrWillBeMember<HTMLDivElement> m_cueBackgroundBox;
184     RefPtrWillBeMember<VTTCueBox> m_displayTree;
185 
186     CSSValueID m_displayDirection;
187     int m_displaySize;
188     std::pair<float, float> m_displayPosition;
189 
190     bool m_snapToLines : 1;
191     bool m_displayTreeShouldChange : 1;
192     bool m_notifyRegion : 1;
193 };
194 
195 // VTTCue is currently the only TextTrackCue subclass.
196 DEFINE_TYPE_CASTS(VTTCue, TextTrackCue, cue, true, true);
197 
198 } // namespace WebCore
199 
200 #endif
201