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#ifndef VTTRegion_h 33#define VTTRegion_h 34 35#if ENABLE(VIDEO_TRACK) && ENABLE(WEBVTT_REGIONS) 36 37#include "ContextDestructionObserver.h" 38#include "Document.h" 39#include "FloatPoint.h" 40#include "TextTrack.h" 41#include <wtf/RefCounted.h> 42 43namespace WebCore { 44 45class HTMLDivElement; 46class VTTCueBox; 47class VTTScanner; 48 49class VTTRegion : public RefCounted<VTTRegion>, public ContextDestructionObserver { 50public: 51 static PassRefPtr<VTTRegion> create(ScriptExecutionContext& context) 52 { 53 return adoptRef(new VTTRegion(context)); 54 } 55 56 virtual ~VTTRegion(); 57 58 TextTrack* track() const { return m_track; } 59 void setTrack(TextTrack*); 60 61 const String& id() const { return m_id; } 62 void setId(const String&); 63 64 double width() const { return m_width; } 65 void setWidth(double, ExceptionCode&); 66 67 long height() const { return m_heightInLines; } 68 void setHeight(long, ExceptionCode&); 69 70 double regionAnchorX() const { return m_regionAnchor.x(); } 71 void setRegionAnchorX(double, ExceptionCode&); 72 73 double regionAnchorY() const { return m_regionAnchor.y(); } 74 void setRegionAnchorY(double, ExceptionCode&); 75 76 double viewportAnchorX() const { return m_viewportAnchor.x(); } 77 void setViewportAnchorX(double, ExceptionCode&); 78 79 double viewportAnchorY() const { return m_viewportAnchor.y(); } 80 void setViewportAnchorY(double, ExceptionCode&); 81 82 const AtomicString scroll() const; 83 void setScroll(const AtomicString&, ExceptionCode&); 84 85 void updateParametersFromRegion(VTTRegion*); 86 87 const String& regionSettings() const { return m_settings; } 88 void setRegionSettings(const String&); 89 90 bool isScrollingRegion() { return m_scroll; } 91 92 PassRefPtr<HTMLDivElement> getDisplayTree(); 93 94 void appendTextTrackCueBox(PassRefPtr<VTTCueBox>); 95 void displayLastTextTrackCueBox(); 96 void willRemoveTextTrackCueBox(VTTCueBox*); 97 98private: 99 VTTRegion(ScriptExecutionContext&); 100 101 Document* ownerDocument() { return toDocument(m_scriptExecutionContext); } 102 103 void prepareRegionDisplayTree(); 104 105 // The timer is needed to continue processing when cue scrolling ended. 106 void startTimer(); 107 void stopTimer(); 108 void scrollTimerFired(Timer<VTTRegion>*); 109 110 enum RegionSetting { 111 None, 112 Id, 113 Width, 114 Height, 115 RegionAnchor, 116 ViewportAnchor, 117 Scroll 118 }; 119 120 RegionSetting scanSettingName(VTTScanner&); 121 122 void parseSettingValue(RegionSetting, VTTScanner&); 123 124 static const AtomicString& textTrackCueContainerShadowPseudoId(); 125 static const AtomicString& textTrackCueContainerScrollingClass(); 126 static const AtomicString& textTrackRegionShadowPseudoId(); 127 128 String m_id; 129 String m_settings; 130 131 double m_width; 132 unsigned m_heightInLines; 133 134 FloatPoint m_regionAnchor; 135 FloatPoint m_viewportAnchor; 136 137 bool m_scroll; 138 139 // The cue container is the container that is scrolled up to obtain the 140 // effect of scrolling cues when this is enabled for the regions. 141 RefPtr<HTMLDivElement> m_cueContainer; 142 RefPtr<HTMLDivElement> m_regionDisplayTree; 143 144 // The member variable track can be a raw pointer as it will never 145 // reference a destroyed TextTrack, as this member variable 146 // is cleared in the TextTrack destructor and it is generally 147 // set/reset within the addRegion and removeRegion methods. 148 TextTrack* m_track; 149 150 // Keep track of the current numeric value of the css "top" property. 151 double m_currentTop; 152 153 // The timer is used to display the next cue line after the current one has 154 // been displayed. It's main use is for scrolling regions and it triggers as 155 // soon as the animation for rolling out one line has finished, but 156 // currently it is used also for non-scrolling regions to use a single 157 // code path. 158 Timer<VTTRegion> m_scrollTimer; 159}; 160 161} // namespace WebCore 162 163#endif 164#endif 165