2 * Copyright (c) 2013, Opera Software ASA. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
33 #include "core/html/track/TextTrackCue.h"
34 #include "platform/heap/Handle.h"
39 class ExecutionContext;
43 class VTTCueBox FINAL : public HTMLDivElement {
45 static PassRefPtrWillBeRawPtr<VTTCueBox> create(Document& document, VTTCue* cue)
47 return adoptRefWillBeNoop(new VTTCueBox(document, cue));
50 VTTCue* getCue() const { return m_cue; }
51 void applyCSSProperties(const IntSize& videoSize);
53 virtual void trace(Visitor*) OVERRIDE;
56 VTTCueBox(Document&, VTTCue*);
58 virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
60 RawPtrWillBeMember<VTTCue> m_cue;
63 class VTTCue FINAL : public TextTrackCue {
65 static PassRefPtrWillBeRawPtr<VTTCue> create(Document& document, double startTime, double endTime, const String& text)
67 return adoptRefWillBeRefCountedGarbageCollected(new VTTCue(document, startTime, endTime, text));
72 const String& vertical() const;
73 void setVertical(const String&);
75 bool snapToLines() const { return m_snapToLines; }
76 void setSnapToLines(bool);
78 int line() const { return m_linePosition; }
79 void setLine(int, ExceptionState&);
81 int position() const { return m_textPosition; }
82 void setPosition(int, ExceptionState&);
84 int size() const { return m_cueSize; }
85 void setSize(int, ExceptionState&);
87 const String& align() const;
88 void setAlign(const String&);
90 const String& text() const { return m_text; }
91 void setText(const String&);
93 void parseSettings(const String&);
95 PassRefPtrWillBeRawPtr<DocumentFragment> getCueAsHTML();
96 PassRefPtrWillBeRawPtr<DocumentFragment> createCueRenderingTree();
98 const String& regionId() const { return m_regionId; }
99 void setRegionId(const String&);
101 virtual void updateDisplay(const IntSize& videoSize, HTMLDivElement& container) OVERRIDE;
103 virtual void updateDisplayTree(double movieTime) OVERRIDE;
104 virtual void removeDisplayTree() OVERRIDE;
105 virtual void notifyRegionWhenRemovingDisplayTree(bool notifyRegion) OVERRIDE;
107 void markFutureAndPastNodes(ContainerNode*, double previousTimestamp, double movieTime);
109 int calculateComputedLinePosition();
111 std::pair<double, double> getCSSPosition() const;
113 CSSValueID getCSSAlignment() const;
114 int getCSSSize() const;
115 CSSValueID getCSSWritingDirection() const;
116 CSSValueID getCSSWritingMode() const;
118 enum WritingDirection {
121 VerticalGrowingRight,
122 NumberOfWritingDirections
124 WritingDirection getWritingDirection() const { return m_writingDirection; }
134 CueAlignment getAlignment() const { return m_cueAlignment; }
136 virtual ExecutionContext* executionContext() const OVERRIDE;
139 virtual String toString() const OVERRIDE;
142 virtual void trace(Visitor*) OVERRIDE;
145 VTTCue(Document&, double startTime, double endTime, const String& text);
147 Document& document() const;
149 VTTCueBox& ensureDisplayTree();
150 PassRefPtrWillBeRawPtr<VTTCueBox> getDisplayTree(const IntSize& videoSize);
152 virtual void cueDidChange() OVERRIDE;
154 void createVTTNodeTree();
155 void copyVTTNodeToDOMTree(ContainerNode* vttNode, ContainerNode* root);
157 std::pair<double, double> getPositionCoordinates() const;
159 void calculateDisplayParameters();
170 CueSetting settingName(VTTScanner&);
174 int m_computedLinePosition;
177 WritingDirection m_writingDirection;
178 CueAlignment m_cueAlignment;
181 RefPtrWillBeMember<DocumentFragment> m_vttNodeTree;
182 RefPtrWillBeMember<HTMLDivElement> m_cueBackgroundBox;
183 RefPtrWillBeMember<VTTCueBox> m_displayTree;
185 CSSValueID m_displayDirection;
187 std::pair<float, float> m_displayPosition;
189 bool m_snapToLines : 1;
190 bool m_displayTreeShouldChange : 1;
191 bool m_notifyRegion : 1;
194 // VTTCue is currently the only TextTrackCue subclass.
195 DEFINE_TYPE_CASTS(VTTCue, TextTrackCue, cue, true, true);