RenderPart.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. #include "config.h"
  25. #include "RenderPart.h"
  26. #include "Frame.h"
  27. #include "FrameView.h"
  28. #include "HTMLFrameElementBase.h"
  29. #include "HitTestResult.h"
  30. #include "PluginViewBase.h"
  31. #include "RenderLayer.h"
  32. #include "RenderSVGRoot.h"
  33. #include "RenderView.h"
  34. using namespace std;
  35. namespace WebCore {
  36. RenderPart::RenderPart(Element* node)
  37. : RenderWidget(node)
  38. {
  39. setInline(false);
  40. }
  41. RenderPart::~RenderPart()
  42. {
  43. clearWidget();
  44. }
  45. void RenderPart::setWidget(PassRefPtr<Widget> widget)
  46. {
  47. if (widget == this->widget())
  48. return;
  49. RenderWidget::setWidget(widget);
  50. // make sure the scrollbars are set correctly for restore
  51. // ### find better fix
  52. viewCleared();
  53. }
  54. void RenderPart::viewCleared()
  55. {
  56. }
  57. #if USE(ACCELERATED_COMPOSITING)
  58. bool RenderPart::requiresLayer() const
  59. {
  60. if (RenderWidget::requiresLayer())
  61. return true;
  62. return requiresAcceleratedCompositing();
  63. }
  64. bool RenderPart::requiresAcceleratedCompositing() const
  65. {
  66. // There are two general cases in which we can return true. First, if this is a plugin
  67. // renderer and the plugin has a layer, then we need a layer. Second, if this is
  68. // a renderer with a contentDocument and that document needs a layer, then we need
  69. // a layer.
  70. if (widget() && widget()->isPluginViewBase() && toPluginViewBase(widget())->platformLayer())
  71. return true;
  72. if (!node() || !node()->isFrameOwnerElement())
  73. return false;
  74. HTMLFrameOwnerElement* element = toFrameOwnerElement(node());
  75. if (Document* contentDocument = element->contentDocument()) {
  76. if (RenderView* view = contentDocument->renderView())
  77. return view->usesCompositing();
  78. }
  79. return false;
  80. }
  81. #endif
  82. bool RenderPart::needsPreferredWidthsRecalculation() const
  83. {
  84. if (RenderWidget::needsPreferredWidthsRecalculation())
  85. return true;
  86. return embeddedContentBox();
  87. }
  88. RenderBox* RenderPart::embeddedContentBox() const
  89. {
  90. if (!node() || !widget() || !widget()->isFrameView())
  91. return 0;
  92. return toFrameView(widget())->embeddedContentBox();
  93. }
  94. bool RenderPart::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction action)
  95. {
  96. if (!widget() || !widget()->isFrameView() || !request.allowsChildFrameContent())
  97. return RenderWidget::nodeAtPoint(request, result, locationInContainer, accumulatedOffset, action);
  98. FrameView* childFrameView = toFrameView(widget());
  99. RenderView* childRoot = childFrameView->renderView();
  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. bool isInsideChildFrame = childRoot->hitTest(newHitTestRequest, newHitTestLocation, childFrameResult);
  107. if (newHitTestLocation.isRectBasedTest())
  108. result.append(childFrameResult);
  109. else if (isInsideChildFrame)
  110. result = childFrameResult;
  111. if (isInsideChildFrame)
  112. return true;
  113. }
  114. return RenderWidget::nodeAtPoint(request, result, locationInContainer, accumulatedOffset, action);
  115. }
  116. }