Home | History | Annotate | Download | only in rendering
      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/Frame.h"
     29 #include "core/frame/FrameView.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     clearWidget();
     50 }
     51 
     52 void RenderPart::setWidget(PassRefPtr<Widget> widget)
     53 {
     54     if (widget == this->widget())
     55         return;
     56 
     57     RenderWidget::setWidget(widget);
     58 
     59     // make sure the scrollbars are set correctly for restore
     60     // ### find better fix
     61     viewCleared();
     62 }
     63 
     64 void RenderPart::viewCleared()
     65 {
     66 }
     67 
     68 bool RenderPart::requiresLayer() const
     69 {
     70     if (RenderWidget::requiresLayer())
     71         return true;
     72 
     73     return requiresAcceleratedCompositing();
     74 }
     75 
     76 bool RenderPart::requiresAcceleratedCompositing() const
     77 {
     78     // There are two general cases in which we can return true. First, if this is a plugin
     79     // renderer and the plugin has a layer, then we need a layer. Second, if this is
     80     // a renderer with a contentDocument and that document needs a layer, then we need
     81     // a layer.
     82     if (widget() && widget()->isPluginView() && toPluginView(widget())->platformLayer())
     83         return true;
     84 
     85     if (!node() || !node()->isFrameOwnerElement())
     86         return false;
     87 
     88     HTMLFrameOwnerElement* element = toHTMLFrameOwnerElement(node());
     89     if (element->contentFrame() && element->contentFrame()->remotePlatformLayer())
     90         return true;
     91 
     92     if (Document* contentDocument = element->contentDocument()) {
     93         if (RenderView* view = contentDocument->renderView())
     94             return view->usesCompositing();
     95     }
     96 
     97     return false;
     98 }
     99 
    100 bool RenderPart::needsPreferredWidthsRecalculation() const
    101 {
    102     if (RenderWidget::needsPreferredWidthsRecalculation())
    103         return true;
    104     return embeddedContentBox();
    105 }
    106 
    107 RenderBox* RenderPart::embeddedContentBox() const
    108 {
    109     if (!node() || !widget() || !widget()->isFrameView())
    110         return 0;
    111     return toFrameView(widget())->embeddedContentBox();
    112 }
    113 
    114 bool RenderPart::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction action)
    115 {
    116     if (!widget() || !widget()->isFrameView() || !request.allowsChildFrameContent())
    117         return RenderWidget::nodeAtPoint(request, result, locationInContainer, accumulatedOffset, action);
    118 
    119     FrameView* childFrameView = toFrameView(widget());
    120     RenderView* childRoot = childFrameView->renderView();
    121 
    122     if (childRoot) {
    123         LayoutPoint adjustedLocation = accumulatedOffset + location();
    124         LayoutPoint contentOffset = LayoutPoint(borderLeft() + paddingLeft(), borderTop() + paddingTop()) - childFrameView->scrollOffset();
    125         HitTestLocation newHitTestLocation(locationInContainer, -adjustedLocation - contentOffset);
    126         HitTestRequest newHitTestRequest(request.type() | HitTestRequest::ChildFrameHitTest);
    127         HitTestResult childFrameResult(newHitTestLocation);
    128 
    129         bool isInsideChildFrame = childRoot->hitTest(newHitTestRequest, newHitTestLocation, childFrameResult);
    130 
    131         if (newHitTestLocation.isRectBasedTest())
    132             result.append(childFrameResult);
    133         else if (isInsideChildFrame)
    134             result = childFrameResult;
    135 
    136         if (isInsideChildFrame)
    137             return true;
    138 
    139         if (request.allowsFrameScrollbars()) {
    140             // ScrollView scrollbars are not the same as RenderLayer scrollbars tested by RenderLayer::hitTestOverflowControls,
    141             // so we need to test ScrollView scrollbars separately here.
    142             // FIXME: Consider if this test could be done unconditionally.
    143             Scrollbar* frameScrollbar = childFrameView->scrollbarAtPoint(newHitTestLocation.roundedPoint());
    144             if (frameScrollbar)
    145                 result.setScrollbar(frameScrollbar);
    146         }
    147     }
    148 
    149     return RenderWidget::nodeAtPoint(request, result, locationInContainer, accumulatedOffset, action);
    150 }
    151 
    152 }
    153