1 /* 2 * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org) 3 * Copyright (C) 2003, 2006, 2009 Apple Inc. All rights reserved. 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public License 16 * along with this library; see the file COPYING.LIB. If not, write to 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 * 20 */ 21 22 #include "config.h" 23 #include "RenderApplet.h" 24 25 #include "Frame.h" 26 #include "HTMLAppletElement.h" 27 #include "HTMLNames.h" 28 #include "HTMLParamElement.h" 29 #include "Widget.h" 30 31 namespace WebCore { 32 33 using namespace HTMLNames; 34 35 RenderApplet::RenderApplet(HTMLAppletElement* applet, const HashMap<String, String>& args) 36 : RenderWidget(applet) 37 , m_args(args) 38 { 39 setInline(true); 40 } 41 42 IntSize RenderApplet::intrinsicSize() const 43 { 44 // FIXME: This doesn't make sense. We can't just start returning 45 // a different size once we've created the widget and expect 46 // layout and sizing to be correct. We should remove this and 47 // pass the appropriate intrinsic size in the constructor. 48 return widget() ? IntSize(50, 50) : IntSize(150, 150); 49 } 50 51 void RenderApplet::createWidgetIfNecessary() 52 { 53 HTMLAppletElement* element = static_cast<HTMLAppletElement*>(node()); 54 if (widget() || !element->isFinishedParsingChildren()) 55 return; 56 57 // FIXME: Java applets can't be resized (this is a bug in Apple's Java implementation). 58 // In order to work around this problem and have a correct size from the start, we will 59 // use fixed widths/heights from the style system when we can, since the widget might 60 // not have an accurate m_width/m_height. 61 int contentWidth = style()->width().isFixed() ? style()->width().value() : 62 width() - borderLeft() - borderRight() - paddingLeft() - paddingRight(); 63 int contentHeight = style()->height().isFixed() ? style()->height().value() : 64 height() - borderTop() - borderBottom() - paddingTop() - paddingBottom(); 65 for (Node* child = element->firstChild(); child; child = child->nextSibling()) { 66 if (child->hasTagName(paramTag)) { 67 HTMLParamElement* p = static_cast<HTMLParamElement*>(child); 68 if (!p->name().isEmpty()) 69 m_args.set(p->name(), p->value()); 70 } 71 } 72 73 Frame* frame = document()->frame(); 74 ASSERT(frame); 75 setWidget(frame->loader()->createJavaAppletWidget(IntSize(contentWidth, contentHeight), element, m_args)); 76 } 77 78 void RenderApplet::layout() 79 { 80 ASSERT(needsLayout()); 81 82 calcWidth(); 83 calcHeight(); 84 85 // The applet's widget gets created lazily upon first layout. 86 createWidgetIfNecessary(); 87 setNeedsLayout(false); 88 } 89 90 } // namespace WebCore 91