1/*
2 * Copyright (C) 2010 Apple Computer, 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 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.
24 */
25
26#include "config.h"
27#include "RenderIFrame.h"
28
29#include "FrameView.h"
30#include "HTMLIFrameElement.h"
31#include "RenderView.h"
32#include "Settings.h"
33
34namespace WebCore {
35
36using namespace HTMLNames;
37
38RenderIFrame::RenderIFrame(Element* element)
39 : RenderFrameBase(element)
40{
41}
42
43RenderIFrame::~RenderIFrame()
44{
45}
46
47void RenderIFrame::calcHeight()
48{
49 RenderPart::calcHeight();
50 if (!flattenFrame())
51 return;
52
53 HTMLIFrameElement* frame = static_cast<HTMLIFrameElement*>(node());
54 bool isScrollable = frame->scrollingMode() != ScrollbarAlwaysOff;
55
56 if (isScrollable || !style()->height().isFixed()) {
57 FrameView* view = static_cast<FrameView*>(widget());
58 int border = borderTop() + borderBottom();
59 setHeight(max(height(), view->contentsHeight() + border));
60 }
61}
62
63void RenderIFrame::calcWidth()
64{
65 RenderPart::calcWidth();
66 if (!flattenFrame())
67 return;
68
69 HTMLIFrameElement* frame = static_cast<HTMLIFrameElement*>(node());
70 bool isScrollable = frame->scrollingMode() != ScrollbarAlwaysOff;
71
72 if (isScrollable || !style()->width().isFixed()) {
73 FrameView* view = static_cast<FrameView*>(widget());
74 int border = borderLeft() + borderRight();
75 setWidth(max(width(), view->contentsWidth() + border));
76 }
77}
78
79bool RenderIFrame::flattenFrame()
80{
81 if (!node() || !node()->hasTagName(iframeTag))
82 return false;
83
84 HTMLIFrameElement* element = static_cast<HTMLIFrameElement*>(node());
85 bool isScrollable = element->scrollingMode() != ScrollbarAlwaysOff;
86
87 if (!isScrollable && style()->width().isFixed()
88 && style()->height().isFixed())
89 return false;
90
91 Frame* frame = element->document()->frame();
92 bool enabled = frame && frame->settings()->frameFlatteningEnabled();
93
94 if (!enabled || !frame->page())
95 return false;
96
97 FrameView* view = frame->page()->mainFrame()->view();
98 if (!view)
99 return false;
100
101 // Do not flatten offscreen inner frames during frame flattening.
102 return absoluteBoundingBoxRect().intersects(IntRect(IntPoint(0, 0), view->contentsSize()));
103}
104
105void RenderIFrame::layout()
106{
107 ASSERT(needsLayout());
108
109 RenderPart::calcWidth();
110 RenderPart::calcHeight();
111
112 if (flattenFrame()) {
113 layoutWithFlattening(style()->width().isFixed(), style()->height().isFixed());
114 return;
115 }
116
117 RenderPart::layout();
118
119 m_overflow.clear();
120 addShadowOverflow();
121
122 setNeedsLayout(false);
123}
124
125}