initial import
[vuplus_webkit] / Source / WebCore / rendering / RenderIFrame.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 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 "Frame.h"
30 #include "FrameView.h"
31 #include "HTMLIFrameElement.h"
32 #include "HTMLNames.h"
33 #include "Page.h"
34 #include "RenderView.h"
35 #include "Settings.h"
36
37 namespace WebCore {
38
39 using namespace HTMLNames;
40     
41 RenderIFrame::RenderIFrame(Element* element)
42     : RenderFrameBase(element)
43 {
44 }
45
46 void RenderIFrame::computeLogicalHeight()
47 {
48     RenderPart::computeLogicalHeight();
49     if (!flattenFrame())
50          return;
51
52     HTMLIFrameElement* frame = static_cast<HTMLIFrameElement*>(node());
53     bool isScrollable = frame->scrollingMode() != ScrollbarAlwaysOff;
54
55     if (isScrollable || !style()->height().isFixed()) {
56         FrameView* view = static_cast<FrameView*>(widget());
57         if (!view)
58             return;
59         int border = borderTop() + borderBottom();
60         setHeight(max(height(), view->contentsHeight() + border));
61     }
62 }
63
64 void RenderIFrame::computeLogicalWidth()
65 {
66     RenderPart::computeLogicalWidth();
67     if (!flattenFrame())
68         return;
69
70     HTMLIFrameElement* frame = static_cast<HTMLIFrameElement*>(node());
71     bool isScrollable = frame->scrollingMode() != ScrollbarAlwaysOff;
72
73     if (isScrollable || !style()->width().isFixed()) {
74         FrameView* view = static_cast<FrameView*>(widget());
75         if (!view)
76             return;
77         LayoutUnit border = borderLeft() + borderRight();
78         setWidth(max(width(), view->contentsWidth() + border));
79     }
80 }
81
82 bool RenderIFrame::flattenFrame()
83 {
84     if (!node() || !node()->hasTagName(iframeTag))
85         return false;
86
87     HTMLIFrameElement* element = static_cast<HTMLIFrameElement*>(node());
88     bool isScrollable = element->scrollingMode() != ScrollbarAlwaysOff;
89
90     if (style()->width().isFixed() && style()->height().isFixed()) {
91         if (!isScrollable)
92             return false;
93         if (style()->width().value() <= 0 || style()->height().value() <= 0)
94             return false;
95     }
96
97     Frame* frame = element->document()->frame();
98     bool enabled = frame && frame->settings()->frameFlatteningEnabled();
99
100     if (!enabled || !frame->page())
101         return false;
102
103     FrameView* view = frame->page()->mainFrame()->view();
104     if (!view)
105         return false;
106
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;
110 }
111
112 void RenderIFrame::layout()
113 {
114     ASSERT(needsLayout());
115
116     RenderPart::computeLogicalWidth();
117     RenderPart::computeLogicalHeight();
118
119     if (flattenFrame()) {
120         layoutWithFlattening(style()->width().isFixed(), style()->height().isFixed());
121         return;
122     }
123
124     RenderPart::layout();
125
126     m_overflow.clear();
127     addBoxShadowAndBorderOverflow();
128     updateLayerTransform();
129
130     setNeedsLayout(false);
131 }
132
133 }