• 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 
36 namespace WebCore {
37 
38 class Document;
39 class ExecutionContext;
40 class VTTCue;
41 
42 class VTTCueBox FINAL : public HTMLDivElement {
43 public:
create(Document & document,VTTCue * cue)44     static PassRefPtr<VTTCueBox> create(Document& document, VTTCue* cue)
45     {
46         return adoptRef(new VTTCueBox(document, cue));
47     }
48 
getCue()49     VTTCue* getCue() const { return m_cue; }
50     void applyCSSProperties(const IntSize& videoSize);
51 
52 private:
53     VTTCueBox(Document&, VTTCue*);
54 
55     virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
56 
57     VTTCue* m_cue;
58 };
59 
60 class VTTCue FINAL : public TextTrackCue, public ScriptWrappable {
61 public:
create(Document & document,double startTime,double endTime,const String & text)62     static PassRefPtr<VTTCue> create(Document& document, double startTime, double endTime, const String& text)
63     {
64         return adoptRef(new VTTCue(document, startTime, endTime, text));
65     }
66 
67     virtual ~VTTCue();
68 
69     const String& vertical() const;
70     void setVertical(const String&, ExceptionState&);
71 
snapToLines()72     bool snapToLines() const { return m_snapToLines; }
73     void setSnapToLines(bool);
74 
line()75     int line() const { return m_linePosition; }
76     void setLine(int, ExceptionState&);
77 
position()78     int position() const { return m_textPosition; }
79     void setPosition(int, ExceptionState&);
80 
size()81     int size() const { return m_cueSize; }
82     void setSize(int, ExceptionState&);
83 
84     const String& align() const;
85     void setAlign(const String&, ExceptionState&);
86 
text()87     const String& text() const { return m_text; }
88     void setText(const String&);
89 
90     void parseSettings(const String&);
91 
92     PassRefPtr<DocumentFragment> getCueAsHTML();
93     PassRefPtr<DocumentFragment> createCueRenderingTree();
94 
regionId()95     const String& regionId() const { return m_regionId; }
96     void setRegionId(const String&);
97 
98     virtual void updateDisplay(const IntSize& videoSize, HTMLDivElement& container) OVERRIDE;
99 
100     virtual void updateDisplayTree(double movieTime) OVERRIDE;
101     virtual void removeDisplayTree() OVERRIDE;
102     virtual void notifyRegionWhenRemovingDisplayTree(bool notifyRegion) OVERRIDE;
103 
104     void markFutureAndPastNodes(ContainerNode*, double previousTimestamp, double movieTime);
105 
106     int calculateComputedLinePosition();
107 
108     std::pair<double, double> getCSSPosition() const;
109 
110     CSSValueID getCSSAlignment() const;
111     int getCSSSize() const;
112     CSSValueID getCSSWritingDirection() const;
113     CSSValueID getCSSWritingMode() const;
114 
115     enum WritingDirection {
116         Horizontal = 0,
117         VerticalGrowingLeft,
118         VerticalGrowingRight,
119         NumberOfWritingDirections
120     };
getWritingDirection()121     WritingDirection getWritingDirection() const { return m_writingDirection; }
122 
123     enum CueAlignment {
124         Start = 0,
125         Middle,
126         End,
127         Left,
128         Right,
129         NumberOfAlignments
130     };
getAlignment()131     CueAlignment getAlignment() const { return m_cueAlignment; }
132 
133     virtual ExecutionContext* executionContext() const OVERRIDE;
134 
135 #ifndef NDEBUG
136     virtual String toString() const OVERRIDE;
137 #endif
138 
139 private:
140     VTTCue(Document&, double startTime, double endTime, const String& text);
141 
142     Document& document() const;
143 
144     PassRefPtr<VTTCueBox> displayTreeInternal();
145     PassRefPtr<VTTCueBox> getDisplayTree(const IntSize& videoSize);
146 
147     virtual void cueDidChange() OVERRIDE;
148 
149     void createVTTNodeTree();
150     void copyVTTNodeToDOMTree(ContainerNode* vttNode, ContainerNode* root);
151 
152     std::pair<double, double> getPositionCoordinates() const;
153 
154     void calculateDisplayParameters();
155 
156     enum CueSetting {
157         None,
158         Vertical,
159         Line,
160         Position,
161         Size,
162         Align,
163         RegionId
164     };
165     CueSetting settingName(const String&);
166 
167     String m_text;
168     int m_linePosition;
169     int m_computedLinePosition;
170     int m_textPosition;
171     int m_cueSize;
172     WritingDirection m_writingDirection;
173     CueAlignment m_cueAlignment;
174     String m_regionId;
175 
176     RefPtr<DocumentFragment> m_vttNodeTree;
177     RefPtr<HTMLDivElement> m_cueBackgroundBox;
178     RefPtr<VTTCueBox> m_displayTree;
179 
180     CSSValueID m_displayDirection;
181     int m_displaySize;
182     std::pair<float, float> m_displayPosition;
183 
184     bool m_snapToLines : 1;
185     bool m_displayTreeShouldChange : 1;
186     bool m_notifyRegion : 1;
187 };
188 
toVTTCue(TextTrackCue * cue)189 inline VTTCue* toVTTCue(TextTrackCue* cue)
190 {
191     // VTTCue is currently the only TextTrackCue subclass.
192     return static_cast<VTTCue*>(cue);
193 }
194 
195 } // namespace WebCore
196 
197 #endif
198