Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / 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 "core/rendering/RenderPart.h"
27
28 #include "core/frame/FrameView.h"
29 #include "core/frame/LocalFrame.h"
30 #include "core/html/HTMLFrameElementBase.h"
31 #include "core/plugins/PluginView.h"
32 #include "core/rendering/HitTestResult.h"
33 #include "core/rendering/RenderLayer.h"
34 #include "core/rendering/RenderView.h"
35 #include "core/rendering/svg/RenderSVGRoot.h"
36
37 using namespace std;
38
39 namespace WebCore {
40
41 RenderPart::RenderPart(Element* node)
42     : RenderWidget(node)
43 {
44     setInline(false);
45 }
46
47 RenderPart::~RenderPart()
48 {
49 }
50
51 LayerType RenderPart::layerTypeRequired() const
52 {
53     LayerType type = RenderWidget::layerTypeRequired();
54     if (type != NoLayer)
55         return type;
56
57     return requiresAcceleratedCompositing() ? NormalLayer : NoLayer;
58 }
59
60 bool RenderPart::requiresAcceleratedCompositing() const
61 {
62     // There are two general cases in which we can return true. First, if this is a plugin
63     // renderer and the plugin has a layer, then we need a layer. Second, if this is
64     // a renderer with a contentDocument and that document needs a layer, then we need
65     // a layer.
66     if (widget() && widget()->isPluginView() && toPluginView(widget())->platformLayer())
67         return true;
68
69     if (!node() || !node()->isFrameOwnerElement())
70         return false;
71
72     HTMLFrameOwnerElement* element = toHTMLFrameOwnerElement(node());
73     if (element->contentFrame() && element->contentFrame()->remotePlatformLayer())
74         return true;
75
76     if (Document* contentDocument = element->contentDocument()) {
77         if (RenderView* view = contentDocument->renderView())
78             return view->usesCompositing();
79     }
80
81     return false;
82 }
83
84 bool RenderPart::needsPreferredWidthsRecalculation() const
85 {
86     if (RenderWidget::needsPreferredWidthsRecalculation())
87         return true;
88     return embeddedContentBox();
89 }
90
91 bool RenderPart::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction action)
92 {
93     if (!widget() || !widget()->isFrameView() || !request.allowsChildFrameContent())
94         return RenderWidget::nodeAtPoint(request, result, locationInContainer, accumulatedOffset, action);
95
96     // FIXME: Until RemoteFrames use RemoteFrameViews, we need an explicit check here.
97     if (toFrameView(widget())->frame().isRemoteFrameTemporary())
98         return RenderWidget::nodeAtPoint(request, result, locationInContainer, accumulatedOffset, action);
99
100     FrameView* childFrameView = toFrameView(widget());
101     RenderView* childRoot = childFrameView->renderView();
102
103     if (childRoot) {
104         LayoutPoint adjustedLocation = accumulatedOffset + location();
105         LayoutPoint contentOffset = LayoutPoint(borderLeft() + paddingLeft(), borderTop() + paddingTop()) - childFrameView->scrollOffset();
106         HitTestLocation newHitTestLocation(locationInContainer, -adjustedLocation - contentOffset);
107         HitTestRequest newHitTestRequest(request.type() | HitTestRequest::ChildFrameHitTest);
108         HitTestResult childFrameResult(newHitTestLocation);
109
110         bool isInsideChildFrame = childRoot->hitTest(newHitTestRequest, newHitTestLocation, childFrameResult);
111
112         if (newHitTestLocation.isRectBasedTest())
113             result.append(childFrameResult);
114         else if (isInsideChildFrame)
115             result = childFrameResult;
116
117         if (isInsideChildFrame)
118             return true;
119
120         if (request.allowsFrameScrollbars()) {
121             // ScrollView scrollbars are not the same as RenderLayer scrollbars tested by RenderLayer::hitTestOverflowControls,
122             // so we need to test ScrollView scrollbars separately here.
123             // FIXME: Consider if this test could be done unconditionally.
124             Scrollbar* frameScrollbar = childFrameView->scrollbarAtPoint(newHitTestLocation.roundedPoint());
125             if (frameScrollbar)
126                 result.setScrollbar(frameScrollbar);
127         }
128     }
129
130     return RenderWidget::nodeAtPoint(request, result, locationInContainer, accumulatedOffset, action);
131 }
132
133 CompositingReasons RenderPart::additionalCompositingReasons(CompositingTriggerFlags) const
134 {
135     if (requiresAcceleratedCompositing())
136         return CompositingReasonIFrame;
137     return CompositingReasonNone;
138 }
139
140 }