• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 1999 Lars Knoll (knoll@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 "PluginViewBase.h"
30 #include "Widget.h"
31 
32 namespace WebCore {
33 
34 using namespace HTMLNames;
35 
RenderApplet(HTMLAppletElement * applet,const HashMap<String,String> & args)36 RenderApplet::RenderApplet(HTMLAppletElement* applet, const HashMap<String, String>& args)
37     : RenderWidget(applet)
38     , m_args(args)
39 {
40     setInline(true);
41 }
42 
~RenderApplet()43 RenderApplet::~RenderApplet()
44 {
45 }
46 
intrinsicSize() const47 IntSize RenderApplet::intrinsicSize() const
48 {
49     // FIXME: This doesn't make sense. We can't just start returning
50     // a different size once we've created the widget and expect
51     // layout and sizing to be correct. We should remove this and
52     // pass the appropriate intrinsic size in the constructor.
53     return widget() ? IntSize(50, 50) : IntSize(150, 150);
54 }
55 
createWidgetIfNecessary()56 void RenderApplet::createWidgetIfNecessary()
57 {
58     HTMLAppletElement* element = static_cast<HTMLAppletElement*>(node());
59     if (widget() || !element->isFinishedParsingChildren())
60         return;
61 
62     // FIXME: Java applets can't be resized (this is a bug in Apple's Java implementation).
63     // In order to work around this problem and have a correct size from the start, we will
64     // use fixed widths/heights from the style system when we can, since the widget might
65     // not have an accurate m_width/m_height.
66     int contentWidth = style()->width().isFixed() ? style()->width().value() :
67         width() - borderAndPaddingWidth();
68     int contentHeight = style()->height().isFixed() ? style()->height().value() :
69         height() - borderAndPaddingHeight();
70     for (Node* child = element->firstChild(); child; child = child->nextSibling()) {
71         if (child->hasTagName(paramTag)) {
72             HTMLParamElement* p = static_cast<HTMLParamElement*>(child);
73             if (!p->name().isEmpty())
74                 m_args.set(p->name(), p->value());
75         }
76     }
77 
78     Frame* frame = this->frame();
79     ASSERT(frame);
80     setWidget(frame->loader()->subframeLoader()->createJavaAppletWidget(IntSize(contentWidth, contentHeight), element, m_args));
81 }
82 
layout()83 void RenderApplet::layout()
84 {
85     ASSERT(needsLayout());
86 
87     computeLogicalWidth();
88     computeLogicalHeight();
89 
90     // The applet's widget gets created lazily upon first layout.
91     createWidgetIfNecessary();
92     setNeedsLayout(false);
93 }
94 
95 #if USE(ACCELERATED_COMPOSITING)
requiresLayer() const96 bool RenderApplet::requiresLayer() const
97 {
98     if (RenderWidget::requiresLayer())
99         return true;
100 
101     return allowsAcceleratedCompositing();
102 }
103 
allowsAcceleratedCompositing() const104 bool RenderApplet::allowsAcceleratedCompositing() const
105 {
106     return widget() && widget()->isPluginViewBase() && static_cast<PluginViewBase*>(widget())->platformLayer();
107 }
108 #endif
109 
110 } // namespace WebCore
111