OLD | NEW |
(Empty) | |
| 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 AN
Y |
| 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 AN
Y |
| 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 O
N |
| 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 #include "core/rendering/RenderFullScreen.h" |
| 27 |
| 28 #include "core/dom/FullscreenElementStack.h" |
| 29 #include "core/rendering/RenderBlockFlow.h" |
| 30 |
| 31 using namespace WebCore; |
| 32 |
| 33 class RenderFullScreenPlaceholder FINAL : public RenderBlockFlow { |
| 34 public: |
| 35 RenderFullScreenPlaceholder(RenderFullScreen* owner) |
| 36 : RenderBlockFlow(0) |
| 37 , m_owner(owner) |
| 38 { |
| 39 setDocumentForAnonymous(&owner->document()); |
| 40 } |
| 41 private: |
| 42 virtual bool isRenderFullScreenPlaceholder() const OVERRIDE { return true; } |
| 43 virtual bool supportsPartialLayout() const OVERRIDE { return false; } |
| 44 virtual void willBeDestroyed() OVERRIDE; |
| 45 RenderFullScreen* m_owner; |
| 46 }; |
| 47 |
| 48 void RenderFullScreenPlaceholder::willBeDestroyed() |
| 49 { |
| 50 m_owner->setPlaceholder(0); |
| 51 RenderBlock::willBeDestroyed(); |
| 52 } |
| 53 |
| 54 RenderFullScreen::RenderFullScreen() |
| 55 : RenderFlexibleBox(0) |
| 56 , m_placeholder(0) |
| 57 { |
| 58 setReplaced(false); |
| 59 } |
| 60 |
| 61 RenderFullScreen* RenderFullScreen::createAnonymous(Document* document) |
| 62 { |
| 63 RenderFullScreen* renderer = new RenderFullScreen(); |
| 64 renderer->setDocumentForAnonymous(document); |
| 65 return renderer; |
| 66 } |
| 67 |
| 68 void RenderFullScreen::willBeDestroyed() |
| 69 { |
| 70 if (m_placeholder) { |
| 71 remove(); |
| 72 if (!m_placeholder->beingDestroyed()) |
| 73 m_placeholder->destroy(); |
| 74 ASSERT(!m_placeholder); |
| 75 } |
| 76 |
| 77 // RenderObjects are unretained, so notify the document (which holds a point
er to a RenderFullScreen) |
| 78 // if it's RenderFullScreen is destroyed. |
| 79 FullscreenElementStack* controller = FullscreenElementStack::from(&document(
)); |
| 80 if (controller->fullScreenRenderer() == this) |
| 81 controller->fullScreenRendererDestroyed(); |
| 82 |
| 83 RenderFlexibleBox::willBeDestroyed(); |
| 84 } |
| 85 |
| 86 static PassRefPtr<RenderStyle> createFullScreenStyle() |
| 87 { |
| 88 RefPtr<RenderStyle> fullscreenStyle = RenderStyle::createDefaultStyle(); |
| 89 |
| 90 // Create a stacking context: |
| 91 fullscreenStyle->setZIndex(INT_MAX); |
| 92 |
| 93 fullscreenStyle->setFontDescription(FontDescription()); |
| 94 fullscreenStyle->font().update(0); |
| 95 |
| 96 fullscreenStyle->setDisplay(FLEX); |
| 97 fullscreenStyle->setJustifyContent(JustifyCenter); |
| 98 fullscreenStyle->setAlignItems(ItemPositionCenter); |
| 99 fullscreenStyle->setFlexDirection(FlowColumn); |
| 100 |
| 101 fullscreenStyle->setPosition(FixedPosition); |
| 102 fullscreenStyle->setWidth(Length(100.0, Percent)); |
| 103 fullscreenStyle->setHeight(Length(100.0, Percent)); |
| 104 fullscreenStyle->setLeft(Length(0, WebCore::Fixed)); |
| 105 fullscreenStyle->setTop(Length(0, WebCore::Fixed)); |
| 106 |
| 107 fullscreenStyle->setBackgroundColor(StyleColor(Color::black)); |
| 108 |
| 109 return fullscreenStyle.release(); |
| 110 } |
| 111 |
| 112 RenderObject* RenderFullScreen::wrapRenderer(RenderObject* object, RenderObject*
parent, Document* document) |
| 113 { |
| 114 RenderFullScreen* fullscreenRenderer = RenderFullScreen::createAnonymous(doc
ument); |
| 115 fullscreenRenderer->setStyle(createFullScreenStyle()); |
| 116 if (parent && !parent->isChildAllowed(fullscreenRenderer, fullscreenRenderer
->style())) { |
| 117 fullscreenRenderer->destroy(); |
| 118 return 0; |
| 119 } |
| 120 if (object) { |
| 121 // |object->parent()| can be null if the object is not yet attached |
| 122 // to |parent|. |
| 123 if (RenderObject* parent = object->parent()) { |
| 124 RenderBlock* containingBlock = object->containingBlock(); |
| 125 ASSERT(containingBlock); |
| 126 // Since we are moving the |object| to a new parent |fullscreenRende
rer|, |
| 127 // the line box tree underneath our |containingBlock| is not longer
valid. |
| 128 containingBlock->deleteLineBoxTree(); |
| 129 |
| 130 parent->addChild(fullscreenRenderer, object); |
| 131 object->remove(); |
| 132 |
| 133 // Always just do a full layout to ensure that line boxes get delete
d properly. |
| 134 // Because objects moved from |parent| to |fullscreenRenderer|, we w
ant to |
| 135 // make new line boxes instead of leaving the old ones around. |
| 136 parent->setNeedsLayoutAndPrefWidthsRecalc(); |
| 137 containingBlock->setNeedsLayoutAndPrefWidthsRecalc(); |
| 138 } |
| 139 fullscreenRenderer->addChild(object); |
| 140 fullscreenRenderer->setNeedsLayoutAndPrefWidthsRecalc(); |
| 141 } |
| 142 |
| 143 FullscreenElementStack::from(document)->setFullScreenRenderer(fullscreenRend
erer); |
| 144 return fullscreenRenderer; |
| 145 } |
| 146 |
| 147 void RenderFullScreen::unwrapRenderer() |
| 148 { |
| 149 if (parent()) { |
| 150 RenderObject* child; |
| 151 while ((child = firstChild())) { |
| 152 // We have to clear the override size, because as a flexbox, we |
| 153 // may have set one on the child, and we don't want to leave that |
| 154 // lying around on the child. |
| 155 if (child->isBox()) |
| 156 toRenderBox(child)->clearOverrideSize(); |
| 157 child->remove(); |
| 158 parent()->addChild(child, this); |
| 159 parent()->setNeedsLayoutAndPrefWidthsRecalc(); |
| 160 } |
| 161 } |
| 162 if (placeholder()) |
| 163 placeholder()->remove(); |
| 164 remove(); |
| 165 FullscreenElementStack::from(&document())->setFullScreenRenderer(0); |
| 166 } |
| 167 |
| 168 void RenderFullScreen::setPlaceholder(RenderBlock* placeholder) |
| 169 { |
| 170 m_placeholder = placeholder; |
| 171 } |
| 172 |
| 173 void RenderFullScreen::createPlaceholder(PassRefPtr<RenderStyle> style, const La
youtRect& frameRect) |
| 174 { |
| 175 if (style->width().isAuto()) |
| 176 style->setWidth(Length(frameRect.width(), Fixed)); |
| 177 if (style->height().isAuto()) |
| 178 style->setHeight(Length(frameRect.height(), Fixed)); |
| 179 |
| 180 if (!m_placeholder) { |
| 181 m_placeholder = new RenderFullScreenPlaceholder(this); |
| 182 m_placeholder->setStyle(style); |
| 183 if (parent()) { |
| 184 parent()->addChild(m_placeholder, this); |
| 185 parent()->setNeedsLayoutAndPrefWidthsRecalc(); |
| 186 } |
| 187 } else |
| 188 m_placeholder->setStyle(style); |
| 189 } |
OLD | NEW |