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