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. ``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 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 "RenderView.h"
34#include "Settings.h"
35#include <wtf/IsoMallocInlines.h>
36#include <wtf/StackStats.h>
37
38namespace WebCore {
39
40WTF_MAKE_ISO_ALLOCATED_IMPL(RenderIFrame);
41
42using namespace HTMLNames;
43
44RenderIFrame::RenderIFrame(HTMLIFrameElement& element, RenderStyle&& style)
45 : RenderFrameBase(element, WTFMove(style))
46{
47}
48
49HTMLIFrameElement& RenderIFrame::iframeElement() const
50{
51 return downcast<HTMLIFrameElement>(RenderFrameBase::frameOwnerElement());
52}
53
54bool RenderIFrame::shouldComputeSizeAsReplaced() const
55{
56 return true;
57}
58
59bool RenderIFrame::isInlineBlockOrInlineTable() const
60{
61 return isInline();
62}
63
64bool RenderIFrame::requiresLayer() const
65{
66 return RenderFrameBase::requiresLayer() || style().resize() != Resize::None;
67}
68
69RenderView* RenderIFrame::contentRootRenderer() const
70{
71 FrameView* childFrameView = childView();
72 return childFrameView ? childFrameView->frame().contentRenderer() : 0;
73}
74
75bool RenderIFrame::isFullScreenIFrame() const
76{
77 // Some authors implement fullscreen popups as out-of-flow iframes with size set to full viewport (using vw/vh units).
78 // The size used may not perfectly match the viewport size so the following heuristic uses a relaxed constraint.
79 return style().hasOutOfFlowPosition() && style().hasViewportUnits();
80}
81
82bool RenderIFrame::flattenFrame() const
83{
84 if (view().frameView().effectiveFrameFlattening() == FrameFlattening::Disabled)
85 return false;
86
87 if (style().width().isFixed() && style().height().isFixed()) {
88 // Do not flatten iframes with scrolling="no".
89 if (iframeElement().scrollingMode() == ScrollbarAlwaysOff)
90 return false;
91 // Do not flatten iframes that have zero size, as flattening might make them visible.
92 if (style().width().value() <= 0 || style().height().value() <= 0)
93 return false;
94 // Do not flatten "fullscreen" iframes or they could become larger than the viewport.
95 if (view().frameView().effectiveFrameFlattening() <= FrameFlattening::EnabledForNonFullScreenIFrames && isFullScreenIFrame())
96 return false;
97 }
98
99 // Do not flatten offscreen inner frames during frame flattening, as flattening might make them visible.
100 IntRect boundingRect = absoluteBoundingBoxRectIgnoringTransforms();
101 return boundingRect.maxX() > 0 && boundingRect.maxY() > 0;
102}
103
104void RenderIFrame::layout()
105{
106 StackStats::LayoutCheckPoint layoutCheckPoint;
107 ASSERT(needsLayout());
108
109 updateLogicalWidth();
110 // No kids to layout as a replaced element.
111 updateLogicalHeight();
112
113 if (flattenFrame())
114 layoutWithFlattening(style().width().isFixed(), style().height().isFixed());
115
116 clearOverflow();
117 addVisualEffectOverflow();
118 updateLayerTransform();
119
120 clearNeedsLayout();
121}
122
123}
124