1 /* 2 * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org) 3 * (C) 2000 Simon Hausmann <hausmann (at) kde.org> 4 * (C) 2000 Stefan Schimanski (1Stein (at) 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 return ForcedLayer; 57 } 58 59 bool RenderPart::requiresAcceleratedCompositing() const 60 { 61 // There are two general cases in which we can return true. First, if this is a plugin 62 // renderer and the plugin has a layer, then we need a layer. Second, if this is 63 // a renderer with a contentDocument and that document needs a layer, then we need 64 // a layer. 65 if (widget() && widget()->isPluginView() && toPluginView(widget())->platformLayer()) 66 return true; 67 68 if (!node() || !node()->isFrameOwnerElement()) 69 return false; 70 71 HTMLFrameOwnerElement* element = toHTMLFrameOwnerElement(node()); 72 if (element->contentFrame() && element->contentFrame()->remotePlatformLayer()) 73 return true; 74 75 if (Document* contentDocument = element->contentDocument()) { 76 if (RenderView* view = contentDocument->renderView()) 77 return view->usesCompositing(); 78 } 79 80 return false; 81 } 82 83 bool RenderPart::needsPreferredWidthsRecalculation() const 84 { 85 if (RenderWidget::needsPreferredWidthsRecalculation()) 86 return true; 87 return embeddedContentBox(); 88 } 89 90 bool RenderPart::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction action) 91 { 92 if (!widget() || !widget()->isFrameView() || !request.allowsChildFrameContent()) 93 return RenderWidget::nodeAtPoint(request, result, locationInContainer, accumulatedOffset, action); 94 95 // FIXME: Until RemoteFrames use RemoteFrameViews, we need an explicit check here. 96 if (toFrameView(widget())->frame().isRemoteFrameTemporary()) 97 return RenderWidget::nodeAtPoint(request, result, locationInContainer, accumulatedOffset, action); 98 99 FrameView* childFrameView = toFrameView(widget()); 100 RenderView* childRoot = childFrameView->renderView(); 101 102 if (childRoot) { 103 LayoutPoint adjustedLocation = accumulatedOffset + location(); 104 LayoutPoint contentOffset = LayoutPoint(borderLeft() + paddingLeft(), borderTop() + paddingTop()) - childFrameView->scrollOffset(); 105 HitTestLocation newHitTestLocation(locationInContainer, -adjustedLocation - contentOffset); 106 HitTestRequest newHitTestRequest(request.type() | HitTestRequest::ChildFrameHitTest); 107 HitTestResult childFrameResult(newHitTestLocation); 108 109 bool isInsideChildFrame = childRoot->hitTest(newHitTestRequest, newHitTestLocation, childFrameResult); 110 111 if (newHitTestLocation.isRectBasedTest()) 112 result.append(childFrameResult); 113 else if (isInsideChildFrame) 114 result = childFrameResult; 115 116 if (isInsideChildFrame) 117 return true; 118 119 if (request.allowsFrameScrollbars()) { 120 // ScrollView scrollbars are not the same as RenderLayer scrollbars tested by RenderLayer::hitTestOverflowControls, 121 // so we need to test ScrollView scrollbars separately here. 122 // FIXME: Consider if this test could be done unconditionally. 123 Scrollbar* frameScrollbar = childFrameView->scrollbarAtPoint(newHitTestLocation.roundedPoint()); 124 if (frameScrollbar) 125 result.setScrollbar(frameScrollbar); 126 } 127 } 128 129 return RenderWidget::nodeAtPoint(request, result, locationInContainer, accumulatedOffset, action); 130 } 131 132 CompositingReasons RenderPart::additionalCompositingReasons(CompositingTriggerFlags) const 133 { 134 if (requiresAcceleratedCompositing()) 135 return CompositingReasonIFrame; 136 return CompositingReasonNone; 137 } 138 139 } 140