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 37namespace blink { 38 39RenderPart::RenderPart(Element* node) 40 : RenderWidget(node) 41{ 42 setInline(false); 43} 44 45RenderPart::~RenderPart() 46{ 47} 48 49LayerType RenderPart::layerTypeRequired() const 50{ 51 LayerType type = RenderWidget::layerTypeRequired(); 52 if (type != NoLayer) 53 return type; 54 return ForcedLayer; 55} 56 57bool RenderPart::requiresAcceleratedCompositing() const 58{ 59 // There are two general cases in which we can return true. First, if this is a plugin 60 // renderer and the plugin has a layer, then we need a layer. Second, if this is 61 // a renderer with a contentDocument and that document needs a layer, then we need 62 // a layer. 63 if (widget() && widget()->isPluginView() && toPluginView(widget())->platformLayer()) 64 return true; 65 66 if (!node() || !node()->isFrameOwnerElement()) 67 return false; 68 69 HTMLFrameOwnerElement* element = toHTMLFrameOwnerElement(node()); 70 if (element->contentFrame() && element->contentFrame()->remotePlatformLayer()) 71 return true; 72 73 if (Document* contentDocument = element->contentDocument()) { 74 if (RenderView* view = contentDocument->renderView()) 75 return view->usesCompositing(); 76 } 77 78 return false; 79} 80 81bool RenderPart::needsPreferredWidthsRecalculation() const 82{ 83 if (RenderWidget::needsPreferredWidthsRecalculation()) 84 return true; 85 return embeddedContentBox(); 86} 87 88bool RenderPart::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction action) 89{ 90 if (!widget() || !widget()->isFrameView() || !request.allowsChildFrameContent()) 91 return RenderWidget::nodeAtPoint(request, result, locationInContainer, accumulatedOffset, action); 92 93 // FIXME: Until RemoteFrames use RemoteFrameViews, we need an explicit check here. 94 if (toFrameView(widget())->frame().isRemoteFrameTemporary()) 95 return RenderWidget::nodeAtPoint(request, result, locationInContainer, accumulatedOffset, action); 96 97 FrameView* childFrameView = toFrameView(widget()); 98 RenderView* childRoot = childFrameView->renderView(); 99 100 if (childRoot) { 101 LayoutPoint adjustedLocation = accumulatedOffset + location(); 102 LayoutPoint contentOffset = LayoutPoint(borderLeft() + paddingLeft(), borderTop() + paddingTop()) - childFrameView->scrollOffset(); 103 HitTestLocation newHitTestLocation(locationInContainer, -adjustedLocation - contentOffset); 104 HitTestRequest newHitTestRequest(request.type() | HitTestRequest::ChildFrameHitTest); 105 HitTestResult childFrameResult(newHitTestLocation); 106 107 bool isInsideChildFrame = childRoot->hitTest(newHitTestRequest, newHitTestLocation, childFrameResult); 108 109 if (newHitTestLocation.isRectBasedTest()) 110 result.append(childFrameResult); 111 else if (isInsideChildFrame) 112 result = childFrameResult; 113 114 if (isInsideChildFrame) 115 return true; 116 } 117 118 return RenderWidget::nodeAtPoint(request, result, locationInContainer, accumulatedOffset, action); 119} 120 121CompositingReasons RenderPart::additionalCompositingReasons() const 122{ 123 if (requiresAcceleratedCompositing()) 124 return CompositingReasonIFrame; 125 return CompositingReasonNone; 126} 127 128} 129