1/* 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 3 * (C) 2000 Simon Hausmann <hausmann@kde.org> 4 * (C) 2000 Stefan Schimanski (1Stein@gmx.de) 5 * Copyright (C) 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Library General Public 9 * License as published by the Free Software Foundation; either 10 * version 2 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Library General Public License for more details. 16 * 17 * You should have received a copy of the GNU Library General Public License 18 * along with this library; see the file COPYING.LIB. If not, write to 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * Boston, MA 02110-1301, USA. 21 * 22 */ 23 24#include "config.h" 25#include "RenderFrame.h" 26 27#include "FrameView.h" 28#include "HTMLFrameElement.h" 29#include "RenderView.h" 30 31#ifdef FLATTEN_FRAMESET 32#include "Frame.h" 33#include "Document.h" 34#include "RenderView.h" 35#endif 36 37namespace WebCore { 38 39RenderFrame::RenderFrame(HTMLFrameElement* frame) 40 : RenderPart(frame) 41{ 42 setInline(false); 43} 44 45FrameEdgeInfo RenderFrame::edgeInfo() const 46{ 47 HTMLFrameElement* element = static_cast<HTMLFrameElement*>(node()); 48 return FrameEdgeInfo(element->noResize(), element->hasFrameBorder()); 49} 50 51void RenderFrame::viewCleared() 52{ 53 HTMLFrameElement* element = static_cast<HTMLFrameElement*>(node()); 54 if (!element || !widget() || !widget()->isFrameView()) 55 return; 56 57 FrameView* view = static_cast<FrameView*>(widget()); 58 59 int marginw = element->getMarginWidth(); 60 int marginh = element->getMarginHeight(); 61 62 if (marginw != -1) 63 view->setMarginWidth(marginw); 64 if (marginh != -1) 65 view->setMarginHeight(marginh); 66} 67 68#ifdef FLATTEN_FRAMESET 69void RenderFrame::layout() 70{ 71 if (widget() && widget()->isFrameView()) { 72 FrameView* view = static_cast<FrameView*>(widget()); 73 RenderView* root = NULL; 74 if (view->frame() && view->frame()->document() && 75 view->frame()->document()->renderer() && 76 view->frame()->document()->renderer()->isRenderView()) 77 root = static_cast<RenderView*>(view->frame()->document()->renderer()); 78 if (root) { 79 // Resize the widget so that the RenderView will layout according to those dimensions. 80 view->resize(width(), height()); 81 view->layout(); 82 // We can only grow in width and height because if positionFrames gives us a width and we become smaller, 83 // then the fixup process of forcing the frame to fill extra space will fail. 84 if (width() > root->docWidth()) { 85 view->resize(root->docWidth(), 0); 86 view->layout(); 87 } 88 // Honor the height set by RenderFrameSet::positionFrames unless our document height is larger. 89 setHeight(max(root->docHeight(), height())); 90 setWidth(max(root->docWidth(), width())); 91 } 92 } 93 setNeedsLayout(false); 94} 95#endif 96void RenderFrame::layoutWithFlattening(bool fixedWidth, bool fixedHeight) 97{ 98 // NOTE: The width and height have been set at this point by 99 // RenderFrameSet::positionFramesWithFlattening() 100 101 FrameView* childFrameView = static_cast<FrameView*>(widget()); 102 RenderView* childRoot = childFrameView ? static_cast<RenderView*>(childFrameView->frame()->contentRenderer()) : 0; 103 HTMLFrameElement* element = static_cast<HTMLFrameElement*>(node()); 104 105 // Do not expand framesets which has zero width or height 106 if (!width() || !height() || !childRoot) { 107 updateWidgetPosition(); 108 if (childFrameView) 109 childFrameView->layout(); 110 setNeedsLayout(false); 111 return; 112 } 113 114 // need to update to calculate min/max correctly 115 updateWidgetPosition(); 116 if (childRoot->prefWidthsDirty()) 117 childRoot->calcPrefWidths(); 118 119 // if scrollbars are off, and the width or height are fixed 120 // we obey them and do not expand. With frame flattening 121 // no subframe much ever become scrollable. 122 123 bool isScrollable = element->scrollingMode() != ScrollbarAlwaysOff; 124 125 // make sure minimum preferred width is enforced 126 if (isScrollable || !fixedWidth || childRoot->isFrameSet()) 127 setWidth(max(width(), childRoot->minPrefWidth())); 128 129 // update again to pass the width to the child frame 130 updateWidgetPosition(); 131 childFrameView->layout(); 132 133 // expand the frame by setting frame height = content height 134 if (isScrollable || !fixedHeight || childRoot->isFrameSet()) 135 setHeight(max(height(), childFrameView->contentsHeight())); 136 if (isScrollable || !fixedWidth || childRoot->isFrameSet()) 137 setWidth(max(width(), childFrameView->contentsWidth())); 138 139 updateWidgetPosition(); 140 141 ASSERT(!childFrameView->layoutPending()); 142 ASSERT(!childRoot->needsLayout()); 143 ASSERT(!childRoot->firstChild() || !childRoot->firstChild()->firstChild() || !childRoot->firstChild()->firstChild()->needsLayout()); 144 145 setNeedsLayout(false); 146} 147 148} // namespace WebCore 149