initial import
[vuplus_webkit] / Source / WebCore / rendering / RenderFullScreen.cpp
1 /*
2  * Copyright (C) 2010 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. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16  * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  */
24
25 #include "config.h"
26
27 #if ENABLE(FULLSCREEN_API)
28
29 #include "RenderFullScreen.h"
30
31 #include "RenderLayer.h"
32
33 #if USE(ACCELERATED_COMPOSITING)
34 #include "RenderLayerCompositor.h"
35 #endif
36
37 using namespace WebCore;
38
39 class RenderFullScreenPlaceholder : public RenderBlock {
40 public:
41     RenderFullScreenPlaceholder(RenderFullScreen* owner) 
42         : RenderBlock(owner->document())
43         , m_owner(owner) 
44     { 
45     }
46 private:
47     virtual bool isRenderFullScreenPlaceholder() const { return true; }
48     virtual void willBeDestroyed();
49     RenderFullScreen* m_owner;
50 };
51
52 void RenderFullScreenPlaceholder::willBeDestroyed()
53 {
54     m_owner->setPlaceholder(0);
55     RenderBlock::willBeDestroyed();
56 }
57
58 RenderFullScreen::RenderFullScreen(Node* node) 
59     : RenderDeprecatedFlexibleBox(node)
60     , m_placeholder(0)
61
62     setReplaced(false); 
63 }
64
65 void RenderFullScreen::willBeDestroyed()
66 {
67     if (m_placeholder) {
68         remove();
69         if (!m_placeholder->beingDestroyed())
70             m_placeholder->destroy();
71         ASSERT(!m_placeholder);
72     }
73
74     // RenderObjects are unretained, so notify the document (which holds a pointer to a RenderFullScreen)
75     // if it's RenderFullScreen is destroyed.
76     if (document() && document()->fullScreenRenderer() == this)
77         document()->fullScreenRendererDestroyed();
78
79     RenderDeprecatedFlexibleBox::willBeDestroyed();
80 }
81
82 PassRefPtr<RenderStyle> RenderFullScreen::createFullScreenStyle()
83 {
84     RefPtr<RenderStyle> fullscreenStyle = RenderStyle::createDefaultStyle();
85
86     // Create a stacking context:
87     fullscreenStyle->setZIndex(INT_MAX);
88
89     fullscreenStyle->setFontDescription(FontDescription());
90     fullscreenStyle->font().update(0);
91
92     fullscreenStyle->setDisplay(BOX);
93     fullscreenStyle->setBoxPack(BCENTER);
94     fullscreenStyle->setBoxAlign(BCENTER);
95     fullscreenStyle->setBoxOrient(VERTICAL);
96     
97     fullscreenStyle->setPosition(FixedPosition);
98     fullscreenStyle->setWidth(Length(100.0, Percent));
99     fullscreenStyle->setHeight(Length(100.0, Percent));
100     fullscreenStyle->setLeft(Length(0, Fixed));
101     fullscreenStyle->setTop(Length(0, Fixed));
102     
103     fullscreenStyle->setBackgroundColor(Color::black);
104     
105     return fullscreenStyle.release();
106 }
107
108 void RenderFullScreen::setPlaceholder(RenderBlock* placeholder)
109 {
110     m_placeholder = placeholder;
111 }
112
113 void RenderFullScreen::createPlaceholder(PassRefPtr<RenderStyle> style, const IntRect& frameRect)
114 {
115     if (style->width().isAuto())
116         style->setWidth(Length(frameRect.width(), Fixed));
117     if (style->height().isAuto())
118         style->setHeight(Length(frameRect.height(), Fixed));
119
120     if (!m_placeholder) {
121         m_placeholder = new (document()->renderArena()) RenderFullScreenPlaceholder(this);
122         m_placeholder->setStyle(style);
123         if (parent()) {
124             parent()->addChild(m_placeholder, this);
125             remove();
126         }
127         m_placeholder->addChild(this);
128     } else
129         m_placeholder->setStyle(style);
130 }
131
132 #endif