| OLD | NEW |
| (Empty) |
| 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 "RenderFrameBase.h" | |
| 28 | |
| 29 #include "Frame.h" | |
| 30 #include "FrameView.h" | |
| 31 #include "HTMLFrameElementBase.h" | |
| 32 #include "RenderView.h" | |
| 33 | |
| 34 namespace WebCore { | |
| 35 | |
| 36 RenderFrameBase::RenderFrameBase(Element* element) | |
| 37 : RenderPart(element) | |
| 38 { | |
| 39 } | |
| 40 | |
| 41 inline bool shouldExpandFrame(LayoutUnit width, LayoutUnit height, bool hasFixed
Width, bool hasFixedHeight) | |
| 42 { | |
| 43 // If the size computed to zero never expand. | |
| 44 if (!width || !height) | |
| 45 return false; | |
| 46 // Really small fixed size frames can't be meant to be scrolled and are ther
e probably by mistake. Avoid expanding. | |
| 47 static unsigned smallestUsefullyScrollableDimension = 8; | |
| 48 if (hasFixedWidth && width < LayoutUnit(smallestUsefullyScrollableDimension)
) | |
| 49 return false; | |
| 50 if (hasFixedHeight && height < LayoutUnit(smallestUsefullyScrollableDimensio
n)) | |
| 51 return false; | |
| 52 return true; | |
| 53 } | |
| 54 | |
| 55 void RenderFrameBase::layoutWithFlattening(bool hasFixedWidth, bool hasFixedHeig
ht) | |
| 56 { | |
| 57 FrameView* childFrameView = toFrameView(widget()); | |
| 58 RenderView* childRoot = childFrameView ? childFrameView->frame()->contentRen
derer() : 0; | |
| 59 | |
| 60 if (!childRoot || !shouldExpandFrame(width(), height(), hasFixedWidth, hasFi
xedHeight)) { | |
| 61 updateWidgetPosition(); | |
| 62 if (childFrameView) | |
| 63 childFrameView->layout(); | |
| 64 setNeedsLayout(false); | |
| 65 return; | |
| 66 } | |
| 67 | |
| 68 // need to update to calculate min/max correctly | |
| 69 updateWidgetPosition(); | |
| 70 | |
| 71 // if scrollbars are off, and the width or height are fixed | |
| 72 // we obey them and do not expand. With frame flattening | |
| 73 // no subframe much ever become scrollable. | |
| 74 | |
| 75 HTMLFrameElementBase* element = static_cast<HTMLFrameElementBase*>(node()); | |
| 76 bool isScrollable = element->scrollingMode() != ScrollbarAlwaysOff; | |
| 77 | |
| 78 // consider iframe inset border | |
| 79 int hBorder = borderLeft() + borderRight(); | |
| 80 int vBorder = borderTop() + borderBottom(); | |
| 81 | |
| 82 // make sure minimum preferred width is enforced | |
| 83 if (isScrollable || !hasFixedWidth) { | |
| 84 setWidth(max(width(), childRoot->minPreferredLogicalWidth() + hBorder)); | |
| 85 // update again to pass the new width to the child frame | |
| 86 updateWidgetPosition(); | |
| 87 childFrameView->layout(); | |
| 88 } | |
| 89 | |
| 90 // expand the frame by setting frame height = content height | |
| 91 if (isScrollable || !hasFixedHeight || childRoot->isFrameSet()) | |
| 92 setHeight(max<LayoutUnit>(height(), childFrameView->contentsHeight() + v
Border)); | |
| 93 if (isScrollable || !hasFixedWidth || childRoot->isFrameSet()) | |
| 94 setWidth(max<LayoutUnit>(width(), childFrameView->contentsWidth() + hBor
der)); | |
| 95 | |
| 96 updateWidgetPosition(); | |
| 97 | |
| 98 ASSERT(!childFrameView->layoutPending()); | |
| 99 ASSERT(!childRoot->needsLayout()); | |
| 100 ASSERT(!childRoot->firstChild() || !childRoot->firstChild()->firstChild() ||
!childRoot->firstChild()->firstChild()->needsLayout()); | |
| 101 | |
| 102 setNeedsLayout(false); | |
| 103 } | |
| 104 | |
| 105 } | |
| OLD | NEW |