2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "bindings/core/v8/ScriptWrappable.h"
35 #include "core/dom/ContextLifecycleObserver.h"
36 #include "core/html/track/TextTrack.h"
37 #include "platform/Timer.h"
38 #include "platform/geometry/FloatPoint.h"
39 #include "platform/heap/Handle.h"
40 #include "wtf/PassOwnPtr.h"
41 #include "wtf/RefCounted.h"
51 class VTTRegion final : public RefCountedWillBeGarbageCollectedFinalized<VTTRegion>, public ScriptWrappable {
52 DEFINE_WRAPPERTYPEINFO();
54 static PassRefPtrWillBeRawPtr<VTTRegion> create()
56 return adoptRefWillBeNoop(new VTTRegion());
61 TextTrack* track() const { return m_track; }
62 void setTrack(TextTrack*);
64 const String& id() const { return m_id; }
65 void setId(const String&);
67 double width() const { return m_width; }
68 void setWidth(double, ExceptionState&);
70 long height() const { return m_heightInLines; }
71 void setHeight(long, ExceptionState&);
73 double regionAnchorX() const { return m_regionAnchor.x(); }
74 void setRegionAnchorX(double, ExceptionState&);
76 double regionAnchorY() const { return m_regionAnchor.y(); }
77 void setRegionAnchorY(double, ExceptionState&);
79 double viewportAnchorX() const { return m_viewportAnchor.x(); }
80 void setViewportAnchorX(double, ExceptionState&);
82 double viewportAnchorY() const { return m_viewportAnchor.y(); }
83 void setViewportAnchorY(double, ExceptionState&);
85 const AtomicString scroll() const;
86 void setScroll(const AtomicString&, ExceptionState&);
88 void updateParametersFromRegion(VTTRegion*);
90 const String& regionSettings() const { return m_settings; }
91 void setRegionSettings(const String&);
93 bool isScrollingRegion() { return m_scroll; }
95 PassRefPtrWillBeRawPtr<HTMLDivElement> getDisplayTree(Document&);
97 void appendVTTCueBox(PassRefPtrWillBeRawPtr<VTTCueBox>);
98 void displayLastVTTCueBox();
99 void willRemoveVTTCueBox(VTTCueBox*);
101 void trace(Visitor*);
106 void prepareRegionDisplayTree();
108 // The timer is needed to continue processing when cue scrolling ended.
111 void scrollTimerFired(Timer<VTTRegion>*);
122 RegionSetting scanSettingName(VTTScanner&);
123 void parseSettingValue(RegionSetting, VTTScanner&);
125 static const AtomicString& textTrackCueContainerShadowPseudoId();
126 static const AtomicString& textTrackCueContainerScrollingClass();
127 static const AtomicString& textTrackRegionShadowPseudoId();
132 unsigned m_heightInLines;
133 FloatPoint m_regionAnchor;
134 FloatPoint m_viewportAnchor;
137 // The cue container is the container that is scrolled up to obtain the
138 // effect of scrolling cues when this is enabled for the regions.
139 RefPtrWillBeMember<HTMLDivElement> m_cueContainer;
140 RefPtrWillBeMember<HTMLDivElement> m_regionDisplayTree;
142 // The member variable track can be a raw pointer as it will never
143 // reference a destroyed TextTrack, as this member variable
144 // is cleared in the TextTrack destructor and it is generally
145 // set/reset within the addRegion and removeRegion methods.
146 RawPtrWillBeMember<TextTrack> m_track;
148 // Keep track of the current numeric value of the css "top" property.
151 // The timer is used to display the next cue line after the current one has
152 // been displayed. It's main use is for scrolling regions and it triggers as
153 // soon as the animation for rolling out one line has finished, but
154 // currently it is used also for non-scrolling regions to use a single
156 Timer<VTTRegion> m_scrollTimer;
161 #endif // VTTRegion_h