2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, 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 COMPUTER, 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.
27 #include "RenderIFrame.h"
30 #include "FrameView.h"
31 #include "HTMLIFrameElement.h"
32 #include "HTMLNames.h"
34 #include "RenderView.h"
39 using namespace HTMLNames;
41 RenderIFrame::RenderIFrame(Element* element)
42 : RenderFrameBase(element)
46 void RenderIFrame::computeLogicalHeight()
48 RenderPart::computeLogicalHeight();
52 HTMLIFrameElement* frame = static_cast<HTMLIFrameElement*>(node());
53 bool isScrollable = frame->scrollingMode() != ScrollbarAlwaysOff;
55 if (isScrollable || !style()->height().isFixed()) {
56 FrameView* view = static_cast<FrameView*>(widget());
59 int border = borderTop() + borderBottom();
60 setHeight(max(height(), view->contentsHeight() + border));
64 void RenderIFrame::computeLogicalWidth()
66 RenderPart::computeLogicalWidth();
70 HTMLIFrameElement* frame = static_cast<HTMLIFrameElement*>(node());
71 bool isScrollable = frame->scrollingMode() != ScrollbarAlwaysOff;
73 if (isScrollable || !style()->width().isFixed()) {
74 FrameView* view = static_cast<FrameView*>(widget());
77 LayoutUnit border = borderLeft() + borderRight();
78 setWidth(max(width(), view->contentsWidth() + border));
82 bool RenderIFrame::flattenFrame()
84 if (!node() || !node()->hasTagName(iframeTag))
87 HTMLIFrameElement* element = static_cast<HTMLIFrameElement*>(node());
88 bool isScrollable = element->scrollingMode() != ScrollbarAlwaysOff;
90 if (style()->width().isFixed() && style()->height().isFixed()) {
93 if (style()->width().value() <= 0 || style()->height().value() <= 0)
97 Frame* frame = element->document()->frame();
98 bool enabled = frame && frame->settings()->frameFlatteningEnabled();
100 if (!enabled || !frame->page())
103 FrameView* view = frame->page()->mainFrame()->view();
107 // Do not flatten offscreen inner frames during frame flattening, as flattening might make them visible.
108 IntRect boundingRect = absoluteBoundingBoxRect();
109 return boundingRect.maxX() > 0 && boundingRect.maxY() > 0;
112 void RenderIFrame::layout()
114 ASSERT(needsLayout());
116 RenderPart::computeLogicalWidth();
117 RenderPart::computeLogicalHeight();
119 if (flattenFrame()) {
120 layoutWithFlattening(style()->width().isFixed(), style()->height().isFixed());
124 RenderPart::layout();
127 addBoxShadowAndBorderOverflow();
128 updateLayerTransform();
130 setNeedsLayout(false);