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 {
64 DEFINE_WRAPPERTYPEINFO();
66 static PassRefPtrWillBeRawPtr<VTTCue> create(Document& document, double startTime, double endTime, const String& text)
68 return adoptRefWillBeNoop(new VTTCue(document, startTime, endTime, text));
73 const String& vertical() const;
74 void setVertical(const String&);
76 bool snapToLines() const { return m_snapToLines; }
77 void setSnapToLines(bool);
79 int line() const { return m_linePosition; }
80 void setLine(int, ExceptionState&);
82 int position() const { return m_textPosition; }
83 void setPosition(int, ExceptionState&);
85 int size() const { return m_cueSize; }
86 void setSize(int, ExceptionState&);
88 const String& align() const;
89 void setAlign(const String&);
91 const String& text() const { return m_text; }
92 void setText(const String&);
94 void parseSettings(const String&);
96 PassRefPtrWillBeRawPtr<DocumentFragment> getCueAsHTML();
97 PassRefPtrWillBeRawPtr<DocumentFragment> createCueRenderingTree();
99 const String& regionId() const { return m_regionId; }
100 void setRegionId(const String&);
102 virtual void updateDisplay(const IntSize& videoSize, HTMLDivElement& container) override;
104 virtual void updateDisplayTree(double movieTime) override;
105 virtual void removeDisplayTree() override;
106 virtual void notifyRegionWhenRemovingDisplayTree(bool notifyRegion) override;
108 void markFutureAndPastNodes(ContainerNode*, double previousTimestamp, double movieTime);
110 int calculateComputedLinePosition();
112 std::pair<double, double> getCSSPosition() const;
114 CSSValueID getCSSAlignment() const;
115 int getCSSSize() const;
116 CSSValueID getCSSWritingDirection() const;
117 CSSValueID getCSSWritingMode() const;
119 enum WritingDirection {
122 VerticalGrowingRight,
123 NumberOfWritingDirections
125 WritingDirection getWritingDirection() const { return m_writingDirection; }
135 CueAlignment getAlignment() const { return m_cueAlignment; }
137 virtual ExecutionContext* executionContext() const override;
140 virtual String toString() const override;
143 virtual void trace(Visitor*) override;
146 VTTCue(Document&, double startTime, double endTime, const String& text);
148 Document& document() const;
150 VTTCueBox& ensureDisplayTree();
151 PassRefPtrWillBeRawPtr<VTTCueBox> getDisplayTree(const IntSize& videoSize);
153 virtual void cueDidChange() override;
155 void createVTTNodeTree();
156 void copyVTTNodeToDOMTree(ContainerNode* vttNode, ContainerNode* root);
158 std::pair<double, double> getPositionCoordinates() const;
160 void calculateDisplayParameters();
171 CueSetting settingName(VTTScanner&);
175 int m_computedLinePosition;
178 WritingDirection m_writingDirection;
179 CueAlignment m_cueAlignment;
182 RefPtrWillBeMember<DocumentFragment> m_vttNodeTree;
183 RefPtrWillBeMember<HTMLDivElement> m_cueBackgroundBox;
184 RefPtrWillBeMember<VTTCueBox> m_displayTree;
186 CSSValueID m_displayDirection;
188 std::pair<float, float> m_displayPosition;
190 bool m_snapToLines : 1;
191 bool m_displayTreeShouldChange : 1;
192 bool m_notifyRegion : 1;
195 // VTTCue is currently the only TextTrackCue subclass.
196 DEFINE_TYPE_CASTS(VTTCue, TextTrackCue, cue, true, true);