| 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 "RenderFrameBase.h" |
| 28 | |
| 29 | #include "Frame.h" |
| 30 | #include "FrameView.h" |
| 31 | #include "HTMLFrameElementBase.h" |
| 32 | #include "RenderView.h" |
| 33 | #include "ScriptDisallowedScope.h" |
| 34 | #include <wtf/IsoMallocInlines.h> |
| 35 | |
| 36 | namespace WebCore { |
| 37 | |
| 38 | WTF_MAKE_ISO_ALLOCATED_IMPL(RenderFrameBase); |
| 39 | |
| 40 | RenderFrameBase::RenderFrameBase(HTMLFrameElementBase& element, RenderStyle&& style) |
| 41 | : RenderWidget(element, WTFMove(style)) |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | inline bool shouldExpandFrame(LayoutUnit width, LayoutUnit height, bool hasFixedWidth, bool hasFixedHeight) |
| 46 | { |
| 47 | // If the size computed to zero never expand. |
| 48 | if (!width || !height) |
| 49 | return false; |
| 50 | // Really small fixed size frames can't be meant to be scrolled and are there probably by mistake. Avoid expanding. |
| 51 | static const unsigned smallestUsefullyScrollableDimension = 8; |
| 52 | if (hasFixedWidth && width < LayoutUnit(smallestUsefullyScrollableDimension)) |
| 53 | return false; |
| 54 | if (hasFixedHeight && height < LayoutUnit(smallestUsefullyScrollableDimension)) |
| 55 | return false; |
| 56 | return true; |
| 57 | } |
| 58 | |
| 59 | void RenderFrameBase::layoutWithFlattening(bool hasFixedWidth, bool hasFixedHeight) |
| 60 | { |
| 61 | view().protectRenderWidgetUntilLayoutIsDone(*this); |
| 62 | |
| 63 | performLayoutWithFlattening(hasFixedWidth, hasFixedHeight); |
| 64 | |
| 65 | clearNeedsLayout(); |
| 66 | } |
| 67 | |
| 68 | RenderView* RenderFrameBase::childRenderView() const |
| 69 | { |
| 70 | if (!childView()) |
| 71 | return nullptr; |
| 72 | return childView()->renderView(); |
| 73 | } |
| 74 | |
| 75 | void RenderFrameBase::performLayoutWithFlattening(bool hasFixedWidth, bool hasFixedHeight) |
| 76 | { |
| 77 | // FIXME: Refactor frame flattening code so that we don't need to disable assertions here. |
| 78 | ScriptDisallowedScope::DisableAssertionsInScope scope; |
| 79 | if (!childRenderView()) |
| 80 | return; |
| 81 | |
| 82 | if (!shouldExpandFrame(width(), height(), hasFixedWidth, hasFixedHeight)) { |
| 83 | if (updateWidgetPosition() == ChildWidgetState::Destroyed) |
| 84 | return; |
| 85 | childView()->layoutContext().layout(); |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | // need to update to calculate min/max correctly |
| 90 | if (updateWidgetPosition() == ChildWidgetState::Destroyed) |
| 91 | return; |
| 92 | |
| 93 | // if scrollbars are off, and the width or height are fixed |
| 94 | // we obey them and do not expand. With frame flattening |
| 95 | // no subframe much ever become scrollable. |
| 96 | bool isScrollable = frameOwnerElement().scrollingMode() != ScrollbarAlwaysOff; |
| 97 | |
| 98 | // consider iframe inset border |
| 99 | int hBorder = borderLeft() + borderRight(); |
| 100 | int vBorder = borderTop() + borderBottom(); |
| 101 | |
| 102 | // make sure minimum preferred width is enforced |
| 103 | if (isScrollable || !hasFixedWidth) { |
| 104 | ASSERT(childRenderView()); |
| 105 | setWidth(std::max(width(), childRenderView()->minPreferredLogicalWidth() + hBorder)); |
| 106 | // update again to pass the new width to the child frame |
| 107 | if (updateWidgetPosition() == ChildWidgetState::Destroyed) |
| 108 | return; |
| 109 | childView()->layoutContext().layout(); |
| 110 | } |
| 111 | |
| 112 | ASSERT(childView()); |
| 113 | // expand the frame by setting frame height = content height |
| 114 | if (isScrollable || !hasFixedHeight || childRenderView()->isFrameSet()) |
| 115 | setHeight(std::max<LayoutUnit>(height(), childView()->contentsHeight() + vBorder)); |
| 116 | if (isScrollable || !hasFixedWidth || childRenderView()->isFrameSet()) |
| 117 | setWidth(std::max<LayoutUnit>(width(), childView()->contentsWidth() + hBorder)); |
| 118 | |
| 119 | if (updateWidgetPosition() == ChildWidgetState::Destroyed) |
| 120 | return; |
| 121 | |
| 122 | ASSERT(!childView()->layoutContext().isLayoutPending()); |
| 123 | ASSERT(!childRenderView()->needsLayout()); |
| 124 | ASSERT(!childRenderView()->firstChild() || !childRenderView()->firstChild()->firstChildSlow() || !childRenderView()->firstChild()->firstChildSlow()->needsLayout()); |
| 125 | } |
| 126 | |
| 127 | } |
| 128 | |