1 | /* |
2 | * Copyright (C) 2013, 2014 Apple Inc. 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 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if ENABLE(VIDEO_TRACK) |
29 | |
30 | #include "Color.h" |
31 | #include "VTTCue.h" |
32 | |
33 | namespace WebCore { |
34 | |
35 | class GenericCueData; |
36 | |
37 | // A "generic" cue is a non-WebVTT cue, so it is not positioned/sized with the WebVTT logic. |
38 | class TextTrackCueGeneric final : public VTTCue { |
39 | WTF_MAKE_ISO_ALLOCATED_EXPORT(TextTrackCueGeneric, WEBCORE_EXPORT); |
40 | public: |
41 | static Ref<TextTrackCueGeneric> create(ScriptExecutionContext& context, const MediaTime& start, const MediaTime& end, const String& content) |
42 | { |
43 | return adoptRef(*new TextTrackCueGeneric(context, start, end, content)); |
44 | } |
45 | |
46 | ExceptionOr<void> setLine(double) final; |
47 | ExceptionOr<void> setPosition(const LineAndPositionSetting&) final; |
48 | |
49 | bool useDefaultPosition() const { return m_useDefaultPosition; } |
50 | |
51 | double baseFontSizeRelativeToVideoHeight() const { return m_baseFontSizeRelativeToVideoHeight; } |
52 | void setBaseFontSizeRelativeToVideoHeight(double size) { m_baseFontSizeRelativeToVideoHeight = size; } |
53 | |
54 | double fontSizeMultiplier() const { return m_fontSizeMultiplier; } |
55 | void setFontSizeMultiplier(double size) { m_fontSizeMultiplier = size; } |
56 | |
57 | const String& fontName() const { return m_fontName; } |
58 | void setFontName(const String& name) { m_fontName = name; } |
59 | |
60 | const Color& foregroundColor() const { return m_foregroundColor; } |
61 | void setForegroundColor(const Color& color) { m_foregroundColor = color; } |
62 | |
63 | const Color& backgroundColor() const { return m_backgroundColor; } |
64 | void setBackgroundColor(const Color& color) { m_backgroundColor = color; } |
65 | |
66 | const Color& highlightColor() const { return m_highlightColor; } |
67 | void setHighlightColor(const Color& color) { m_highlightColor = color; } |
68 | |
69 | void setFontSize(int, const IntSize&, bool important) final; |
70 | |
71 | String toJSONString() const; |
72 | |
73 | private: |
74 | WEBCORE_EXPORT TextTrackCueGeneric(ScriptExecutionContext&, const MediaTime& start, const MediaTime& end, const String&); |
75 | |
76 | bool isOrderedBefore(const TextTrackCue*) const final; |
77 | bool isPositionedAbove(const TextTrackCue*) const final; |
78 | |
79 | Ref<VTTCueBox> createDisplayTree() final; |
80 | |
81 | bool isEqual(const TextTrackCue&, CueMatchRules) const final; |
82 | bool cueContentsMatch(const TextTrackCue&) const final; |
83 | bool doesExtendCue(const TextTrackCue&) const final; |
84 | |
85 | CueType cueType() const final { return Generic; } |
86 | |
87 | Color m_foregroundColor; |
88 | Color m_backgroundColor; |
89 | Color m_highlightColor; |
90 | double m_baseFontSizeRelativeToVideoHeight { 0 }; |
91 | double m_fontSizeMultiplier { 0 }; |
92 | String m_fontName; |
93 | bool m_useDefaultPosition { true }; |
94 | }; |
95 | |
96 | } // namespace WebCore |
97 | |
98 | namespace WTF { |
99 | |
100 | template<typename Type> |
101 | struct LogArgument; |
102 | |
103 | template <> |
104 | struct LogArgument<WebCore::TextTrackCueGeneric> { |
105 | static String toString(const WebCore::TextTrackCueGeneric& cue) |
106 | { |
107 | return cue.toJSONString(); |
108 | } |
109 | }; |
110 | |
111 | } |
112 | |
113 | SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::TextTrackCueGeneric) |
114 | static bool isType(const WebCore::TextTrackCue& cue) { return cue.cueType() == WebCore::TextTrackCue::Generic; } |
115 | SPECIALIZE_TYPE_TRAITS_END() |
116 | |
117 | #endif |
118 | |