webengine/osswebengine/WebCore/rendering/RenderApplet.cpp
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /**
       
     2  * This file is part of the HTML widget for KDE.
       
     3  *
       
     4  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
       
     5  * Copyright (C) 2003, 2006 Apple Computer, Inc.
       
     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 "RenderApplet.h"
       
    26 
       
    27 #include "Document.h"
       
    28 #include "Frame.h"
       
    29 #include "FrameLoader.h"
       
    30 #include "HTMLAppletElement.h"
       
    31 #include "HTMLNames.h"
       
    32 #include "HTMLParamElement.h"
       
    33 #include "Widget.h"
       
    34 
       
    35 namespace WebCore {
       
    36 
       
    37 using namespace HTMLNames;
       
    38 
       
    39 RenderApplet::RenderApplet(HTMLAppletElement* applet, const HashMap<String, String>& args)
       
    40     : RenderWidget(applet)
       
    41     , m_args(args)
       
    42 {
       
    43     setInline(true);
       
    44 }
       
    45 
       
    46 RenderApplet::~RenderApplet()
       
    47 {
       
    48 }
       
    49 
       
    50 IntSize RenderApplet::intrinsicSize() const
       
    51 {
       
    52     // FIXME: This doesn't make sense. We can't just start returning
       
    53     // a different size once we've created the widget and expect
       
    54     // layout and sizing to be correct. We should remove this and
       
    55     // pass the appropriate intrinsic size in the constructor.
       
    56     return m_widget ? IntSize(50, 50) : IntSize(150, 150);
       
    57 }
       
    58 
       
    59 void RenderApplet::createWidgetIfNecessary()
       
    60 {
       
    61     HTMLAppletElement* element = static_cast<HTMLAppletElement*>(node());
       
    62     if (m_widget)
       
    63         return;
       
    64     if (!element->allParamsAvailable())
       
    65         return;
       
    66 
       
    67     // FIXME: Java applets can't be resized (this is a bug in Apple's Java implementation).
       
    68     // In order to work around this problem and have a correct size from the start, we will
       
    69     // use fixed widths/heights from the style system when we can, since the widget might
       
    70     // not have an accurate m_width/m_height.
       
    71     int width = style()->width().isFixed() ? style()->width().value() : 
       
    72         m_width - borderLeft() - borderRight() - paddingLeft() - paddingRight();
       
    73     int height = style()->height().isFixed() ? style()->height().value() :
       
    74         m_height - borderTop() - borderBottom() - paddingTop() - paddingBottom();
       
    75     for (Node* child = element->firstChild(); child; child = child->nextSibling()) {
       
    76         if (child->hasTagName(paramTag)) {
       
    77             HTMLParamElement* p = static_cast<HTMLParamElement*>(child);
       
    78             if (!p->name().isEmpty())
       
    79                 m_args.set(p->name(), p->value());
       
    80         }
       
    81     }
       
    82 
       
    83     Frame* frame = document()->frame();
       
    84     ASSERT(frame);
       
    85     setWidget(frame->loader()->createJavaAppletWidget(IntSize(width, height), element, m_args));
       
    86 }
       
    87 
       
    88 void RenderApplet::layout()
       
    89 {
       
    90     ASSERT(needsLayout());
       
    91 
       
    92     calcWidth();
       
    93     calcHeight();
       
    94 
       
    95     // The applet's widget gets created lazily upon first layout.
       
    96     createWidgetIfNecessary();
       
    97     setNeedsLayout(false);
       
    98 }
       
    99 
       
   100 } // namespace WebCore