151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)/*
251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * Copyright (c) 2013, Opera Software ASA. All rights reserved.
351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) *
451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * Redistribution and use in source and binary forms, with or without
551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * modification, are permitted provided that the following conditions
651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * are met:
751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * 1. Redistributions of source code must retain the above copyright
851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) *    notice, this list of conditions and the following disclaimer.
951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright
1051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) *    notice, this list of conditions and the following disclaimer in the
1151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) *    documentation and/or other materials provided with the distribution.
1251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * 3. Neither the name of Opera Software ASA nor the names of its
1351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) *    contributors may be used to endorse or promote products derived
1451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) *    from this software without specific prior written permission.
1551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) *
1651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
1951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
2051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
2151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
2551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
2751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * OF THE POSSIBILITY OF SUCH DAMAGE.
2851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) */
2951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
3051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#ifndef VTTCue_h
3151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#define VTTCue_h
3251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
3351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "core/html/track/TextTrackCue.h"
34f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "platform/heap/Handle.h"
3551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
36c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
3751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
3851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)class Document;
3951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)class ExecutionContext;
4051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)class VTTCue;
4109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)class VTTScanner;
4251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
43a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)class VTTCueBox FINAL : public HTMLDivElement {
4451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)public:
45323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    static PassRefPtrWillBeRawPtr<VTTCueBox> create(Document& document, VTTCue* cue)
4651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    {
475d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)        return adoptRefWillBeNoop(new VTTCueBox(document, cue));
4851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    }
4951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
5051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    VTTCue* getCue() const { return m_cue; }
5151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    void applyCSSProperties(const IntSize& videoSize);
5251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
53323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    virtual void trace(Visitor*) OVERRIDE;
54323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)
55a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)private:
5651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    VTTCueBox(Document&, VTTCue*);
5751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
5851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    virtual RenderObject* createRenderer(RenderStyle*) OVERRIDE;
5951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
60323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    RawPtrWillBeMember<VTTCue> m_cue;
6151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)};
6251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
63197021e6b966cfb06891637935ef33fff06433d1Ben Murdochclass VTTCue FINAL : public TextTrackCue {
647242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    DEFINE_WRAPPERTYPEINFO();
6551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)public:
66f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    static PassRefPtrWillBeRawPtr<VTTCue> create(Document& document, double startTime, double endTime, const String& text)
6751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    {
689e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)        return adoptRefWillBeNoop(new VTTCue(document, startTime, endTime, text));
6951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    }
7051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
7151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    virtual ~VTTCue();
7251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
7351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    const String& vertical() const;
74f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    void setVertical(const String&);
7551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
7651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    bool snapToLines() const { return m_snapToLines; }
7751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    void setSnapToLines(bool);
7851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
7951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int line() const { return m_linePosition; }
8051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    void setLine(int, ExceptionState&);
8151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
8251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int position() const { return m_textPosition; }
8351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    void setPosition(int, ExceptionState&);
8451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
8551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int size() const { return m_cueSize; }
8651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    void setSize(int, ExceptionState&);
8751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
8851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    const String& align() const;
89f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    void setAlign(const String&);
9051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
9151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    const String& text() const { return m_text; }
9251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    void setText(const String&);
9351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
9451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    void parseSettings(const String&);
9551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
96d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    PassRefPtrWillBeRawPtr<DocumentFragment> getCueAsHTML();
97d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    PassRefPtrWillBeRawPtr<DocumentFragment> createCueRenderingTree();
9851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
9951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    const String& regionId() const { return m_regionId; }
10051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    void setRegionId(const String&);
10151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
10251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    virtual void updateDisplay(const IntSize& videoSize, HTMLDivElement& container) OVERRIDE;
10351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
10451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    virtual void updateDisplayTree(double movieTime) OVERRIDE;
10551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    virtual void removeDisplayTree() OVERRIDE;
10651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    virtual void notifyRegionWhenRemovingDisplayTree(bool notifyRegion) OVERRIDE;
10751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
10851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    void markFutureAndPastNodes(ContainerNode*, double previousTimestamp, double movieTime);
10951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
11051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int calculateComputedLinePosition();
11151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
11251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    std::pair<double, double> getCSSPosition() const;
11351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
11451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    CSSValueID getCSSAlignment() const;
11551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int getCSSSize() const;
11651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    CSSValueID getCSSWritingDirection() const;
11751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    CSSValueID getCSSWritingMode() const;
11851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
11951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    enum WritingDirection {
12051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        Horizontal = 0,
12151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        VerticalGrowingLeft,
12251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        VerticalGrowingRight,
12351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        NumberOfWritingDirections
12451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    };
12551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    WritingDirection getWritingDirection() const { return m_writingDirection; }
12651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
12751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    enum CueAlignment {
12851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        Start = 0,
12951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        Middle,
13051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        End,
13151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        Left,
13251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        Right,
13351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        NumberOfAlignments
13451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    };
13551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    CueAlignment getAlignment() const { return m_cueAlignment; }
13651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
13751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    virtual ExecutionContext* executionContext() const OVERRIDE;
13851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
139a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#ifndef NDEBUG
140a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    virtual String toString() const OVERRIDE;
141a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#endif
14251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
143f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    virtual void trace(Visitor*) OVERRIDE;
144f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu
14551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)private:
14651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    VTTCue(Document&, double startTime, double endTime, const String& text);
14751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
14851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    Document& document() const;
14951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
1506f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch    VTTCueBox& ensureDisplayTree();
151323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    PassRefPtrWillBeRawPtr<VTTCueBox> getDisplayTree(const IntSize& videoSize);
15251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
15351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    virtual void cueDidChange() OVERRIDE;
15451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
15551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    void createVTTNodeTree();
15651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    void copyVTTNodeToDOMTree(ContainerNode* vttNode, ContainerNode* root);
15751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
15851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    std::pair<double, double> getPositionCoordinates() const;
15951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
16051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    void calculateDisplayParameters();
16151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
16251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    enum CueSetting {
16351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        None,
16451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        Vertical,
16551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        Line,
16651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        Position,
16751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        Size,
16851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        Align,
16951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        RegionId
17051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    };
17109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    CueSetting settingName(VTTScanner&);
17251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
17351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    String m_text;
17451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int m_linePosition;
17551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int m_computedLinePosition;
17651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int m_textPosition;
17751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int m_cueSize;
17851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    WritingDirection m_writingDirection;
17951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    CueAlignment m_cueAlignment;
180a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    String m_regionId;
18151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
182323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    RefPtrWillBeMember<DocumentFragment> m_vttNodeTree;
183323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    RefPtrWillBeMember<HTMLDivElement> m_cueBackgroundBox;
184323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)    RefPtrWillBeMember<VTTCueBox> m_displayTree;
18551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
18651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    CSSValueID m_displayDirection;
18751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    int m_displaySize;
18851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    std::pair<float, float> m_displayPosition;
189a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)
190a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    bool m_snapToLines : 1;
191a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    bool m_displayTreeShouldChange : 1;
192a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    bool m_notifyRegion : 1;
19351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)};
19451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
19509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)// VTTCue is currently the only TextTrackCue subclass.
19609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)DEFINE_TYPE_CASTS(VTTCue, TextTrackCue, cue, true, true);
19751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
198c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink
19951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
2007242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci#endif // VTTCue_h
201