1 | /* |
2 | * Copyright (C) 2013 Google Inc. All rights reserved. |
3 | * Copyright (C) 2014 Apple Inc. All rights reserved. |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are |
7 | * met: |
8 | * |
9 | * * Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * * Redistributions in binary form must reproduce the above |
12 | * copyright notice, this list of conditions and the following disclaimer |
13 | * in the documentation and/or other materials provided with the |
14 | * distribution. |
15 | * * Neither the name of Google Inc. nor the names of its |
16 | * contributors may be used to endorse or promote products derived from |
17 | * this software without specific prior written permission. |
18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
23 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | */ |
31 | |
32 | #pragma once |
33 | |
34 | #if ENABLE(VIDEO_TRACK) |
35 | |
36 | #include "ContextDestructionObserver.h" |
37 | #include "FloatPoint.h" |
38 | #include "TextTrack.h" |
39 | |
40 | namespace WebCore { |
41 | |
42 | class HTMLDivElement; |
43 | class VTTCueBox; |
44 | class VTTScanner; |
45 | |
46 | class VTTRegion final : public RefCounted<VTTRegion>, public ContextDestructionObserver { |
47 | public: |
48 | static Ref<VTTRegion> create(ScriptExecutionContext& context) |
49 | { |
50 | return adoptRef(*new VTTRegion(context)); |
51 | } |
52 | |
53 | virtual ~VTTRegion(); |
54 | |
55 | TextTrack* track() const { return m_track; } |
56 | void setTrack(TextTrack*); |
57 | |
58 | const String& id() const { return m_id; } |
59 | void setId(const String&); |
60 | |
61 | double width() const { return m_width; } |
62 | ExceptionOr<void> setWidth(double); |
63 | |
64 | int lines() const { return m_lines; } |
65 | ExceptionOr<void> setLines(int); |
66 | |
67 | double regionAnchorX() const { return m_regionAnchor.x(); } |
68 | ExceptionOr<void> setRegionAnchorX(double); |
69 | |
70 | double regionAnchorY() const { return m_regionAnchor.y(); } |
71 | ExceptionOr<void> setRegionAnchorY(double); |
72 | |
73 | double viewportAnchorX() const { return m_viewportAnchor.x(); } |
74 | ExceptionOr<void> setViewportAnchorX(double); |
75 | |
76 | double viewportAnchorY() const { return m_viewportAnchor.y(); } |
77 | ExceptionOr<void> setViewportAnchorY(double); |
78 | |
79 | const AtomicString& scroll() const; |
80 | ExceptionOr<void> setScroll(const AtomicString&); |
81 | |
82 | void updateParametersFromRegion(const VTTRegion&); |
83 | |
84 | const String& regionSettings() const { return m_settings; } |
85 | void setRegionSettings(const String&); |
86 | |
87 | bool isScrollingRegion() { return m_scroll; } |
88 | |
89 | HTMLDivElement& getDisplayTree(); |
90 | |
91 | void appendTextTrackCueBox(Ref<VTTCueBox>&&); |
92 | void displayLastTextTrackCueBox(); |
93 | void willRemoveTextTrackCueBox(VTTCueBox*); |
94 | |
95 | private: |
96 | VTTRegion(ScriptExecutionContext&); |
97 | |
98 | void prepareRegionDisplayTree(); |
99 | |
100 | // The timer is needed to continue processing when cue scrolling ended. |
101 | void startTimer(); |
102 | void stopTimer(); |
103 | void scrollTimerFired(); |
104 | |
105 | enum RegionSetting { |
106 | None, |
107 | Id, |
108 | Width, |
109 | Lines, |
110 | RegionAnchor, |
111 | ViewportAnchor, |
112 | Scroll |
113 | }; |
114 | |
115 | RegionSetting scanSettingName(VTTScanner&); |
116 | |
117 | void parseSettingValue(RegionSetting, VTTScanner&); |
118 | |
119 | static const AtomicString& textTrackCueContainerShadowPseudoId(); |
120 | static const AtomicString& textTrackCueContainerScrollingClass(); |
121 | static const AtomicString& textTrackRegionShadowPseudoId(); |
122 | |
123 | String m_id; |
124 | String m_settings; |
125 | |
126 | double m_width { 100 }; |
127 | unsigned m_lines { 3 }; |
128 | |
129 | FloatPoint m_regionAnchor { 0, 100 }; |
130 | FloatPoint m_viewportAnchor { 0, 100 }; |
131 | |
132 | bool m_scroll { false }; |
133 | |
134 | // The cue container is the container that is scrolled up to obtain the |
135 | // effect of scrolling cues when this is enabled for the regions. |
136 | RefPtr<HTMLDivElement> m_cueContainer; |
137 | RefPtr<HTMLDivElement> m_regionDisplayTree; |
138 | |
139 | // The member variable track can be a raw pointer as it will never |
140 | // reference a destroyed TextTrack, as this member variable |
141 | // is cleared in the TextTrack destructor and it is generally |
142 | // set/reset within the addRegion and removeRegion methods. |
143 | TextTrack* m_track { nullptr }; |
144 | |
145 | // Keep track of the current numeric value of the css "top" property. |
146 | double m_currentTop { 0 }; |
147 | |
148 | // The timer is used to display the next cue line after the current one has |
149 | // been displayed. It's main use is for scrolling regions and it triggers as |
150 | // soon as the animation for rolling out one line has finished, but |
151 | // currently it is used also for non-scrolling regions to use a single |
152 | // code path. |
153 | Timer m_scrollTimer; |
154 | }; |
155 | |
156 | } // namespace WebCore |
157 | |
158 | #endif |
159 | |