initial import
[vuplus_webkit] / Source / WebCore / rendering / RenderPart.cpp
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  * Copyright (C) Research In Motion Limited 2011. All rights reserved.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB.  If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  */
24
25 #include "config.h"
26 #include "RenderPart.h"
27
28 #include "Frame.h"
29 #include "FrameView.h"
30 #include "HTMLFrameElementBase.h"
31 #include "PluginViewBase.h"
32 #include "RenderSVGRoot.h"
33 #include "RenderView.h"
34
35 using namespace std;
36
37 namespace WebCore {
38
39 RenderPart::RenderPart(Element* node)
40     : RenderWidget(node)
41 {
42     setInline(false);
43 }
44
45 RenderPart::~RenderPart()
46 {
47     clearWidget();
48 }
49
50 void RenderPart::setWidget(PassRefPtr<Widget> widget)
51 {
52     if (widget == this->widget())
53         return;
54
55     RenderWidget::setWidget(widget);
56
57     // make sure the scrollbars are set correctly for restore
58     // ### find better fix
59     viewCleared();
60 }
61
62 void RenderPart::viewCleared()
63 {
64 }
65
66 #if USE(ACCELERATED_COMPOSITING)
67 bool RenderPart::requiresLayer() const
68 {
69     if (RenderWidget::requiresLayer())
70         return true;
71     
72     return requiresAcceleratedCompositing();
73 }
74
75 bool RenderPart::requiresAcceleratedCompositing() const
76 {
77     // There are two general cases in which we can return true. First, if this is a plugin 
78     // renderer and the plugin has a layer, then we need a layer. Second, if this is 
79     // a renderer with a contentDocument and that document needs a layer, then we need
80     // a layer.
81     if (widget() && widget()->isPluginViewBase() && static_cast<PluginViewBase*>(widget())->platformLayer())
82         return true;
83
84     if (!node() || !node()->isFrameOwnerElement())
85         return false;
86
87     HTMLFrameOwnerElement* element = static_cast<HTMLFrameOwnerElement*>(node());
88     if (Document* contentDocument = element->contentDocument()) {
89         if (RenderView* view = contentDocument->renderView())
90             return view->usesCompositing();
91     }
92
93     return false;
94 }
95 #endif
96
97 bool RenderPart::needsPreferredWidthsRecalculation() const
98 {
99     if (RenderWidget::needsPreferredWidthsRecalculation())
100         return true;
101     return embeddedContentBox();
102 }
103
104 RenderBox* RenderPart::embeddedContentBox() const
105 {
106     if (!node() || !widget() || !widget()->isFrameView())
107         return 0;
108     return static_cast<FrameView*>(widget())->embeddedContentBox();
109 }
110
111 }