Chromium Code Reviews| Index: Source/core/rendering/RenderWidget.cpp |
| diff --git a/Source/core/rendering/RenderWidget.cpp b/Source/core/rendering/RenderWidget.cpp |
| index 93c4daced00f2ee26e8265924711a9a8a32d8c1c..853f424cc46f57b0c289727b095207e46477ffb1 100644 |
| --- a/Source/core/rendering/RenderWidget.cpp |
| +++ b/Source/core/rendering/RenderWidget.cpp |
| @@ -26,6 +26,7 @@ |
| #include "core/accessibility/AXObjectCache.h" |
| #include "core/frame/Frame.h" |
| +#include "core/html/HTMLFrameOwnerElement.h" |
| #include "core/platform/graphics/GraphicsContext.h" |
| #include "core/rendering/CompositedLayerMapping.h" |
| #include "core/rendering/GraphicsContextAnnotator.h" |
| @@ -89,7 +90,6 @@ static void moveWidgetToParentSoon(Widget* child, FrameView* parent) |
| RenderWidget::RenderWidget(Element* element) |
| : RenderReplaced(element) |
| - , m_widget(0) |
| , m_frameView(element->document().view()) |
| // Reference counting is used to prevent the widget from being |
| // destroyed while inside the Widget code, which might not be |
| @@ -109,7 +109,9 @@ void RenderWidget::willBeDestroyed() |
| cache->remove(this); |
| } |
| - setWidget(0); |
| + Element* element = toElement(node()); |
| + if (element && element->isFrameOwnerElement()) |
| + toHTMLFrameOwnerElement(element)->setWidget(0); |
| RenderReplaced::willBeDestroyed(); |
| } |
| @@ -124,7 +126,17 @@ void RenderWidget::destroy() |
| RenderWidget::~RenderWidget() |
| { |
| ASSERT(m_refCount <= 0); |
| - clearWidget(); |
| +} |
| + |
| +Widget* RenderWidget::widget() const |
| +{ |
| + // Plugin widgets are stored in their DOM node. This includes HTMLAppletElement. |
| + Element* element = toElement(node()); |
| + |
| + if (element && element->isFrameOwnerElement()) |
| + return toHTMLFrameOwnerElement(element)->widget(); |
| + |
| + return 0; |
| } |
| // Widgets are always placed on integer boundaries, so rounding the size is actually |
| @@ -140,10 +152,13 @@ bool RenderWidget::setWidgetGeometry(const LayoutRect& frame) |
| if (!node()) |
| return false; |
| + Widget* widget = this->widget(); |
| + ASSERT(widget); |
| + |
| IntRect clipRect = roundedIntRect(enclosingLayer()->childrenClipRect()); |
| IntRect newFrame = roundedIntRect(frame); |
| bool clipChanged = m_clipRect != clipRect; |
| - bool frameRectChanged = m_widget->frameRect() != newFrame; |
| + bool frameRectChanged = widget->frameRect() != newFrame; |
| if (!frameRectChanged && !clipChanged) |
| return false; |
| @@ -152,23 +167,25 @@ bool RenderWidget::setWidgetGeometry(const LayoutRect& frame) |
| RefPtr<RenderWidget> protector(this); |
| RefPtr<Node> protectedNode(node()); |
| - m_widget->setFrameRect(newFrame); |
| + widget->setFrameRect(newFrame); |
| if (clipChanged && !frameRectChanged) |
| - m_widget->clipRectChanged(); |
| + widget->clipRectChanged(); |
| if (hasLayer() && layer()->compositingState() == PaintsIntoOwnBacking) |
| layer()->compositedLayerMapping()->updateAfterWidgetResize(); |
| - bool boundsChanged = m_widget->frameRect().size() != newFrame.size(); |
| + bool boundsChanged = widget->frameRect().size() != newFrame.size(); |
| return boundsChanged; |
| } |
| bool RenderWidget::updateWidgetGeometry() |
| { |
| + Widget* widget = this->widget(); |
| + |
| LayoutRect contentBox = contentBoxRect(); |
| LayoutRect absoluteContentBox(localToAbsoluteQuad(FloatQuad(contentBox)).boundingBox()); |
| - if (m_widget->isFrameView()) { |
| + if (widget->isFrameView()) { |
| contentBox.setLocation(absoluteContentBox.location()); |
| return setWidgetGeometry(contentBox); |
| } |
| @@ -176,33 +193,33 @@ bool RenderWidget::updateWidgetGeometry() |
| return setWidgetGeometry(absoluteContentBox); |
| } |
| -void RenderWidget::setWidget(PassRefPtr<Widget> widget) |
| +void RenderWidget::attachWidget(Widget* widget) |
| { |
| - if (widget == m_widget) |
| - return; |
| - |
| - if (m_widget) { |
| - moveWidgetToParentSoon(m_widget.get(), 0); |
| - clearWidget(); |
| - } |
| - m_widget = widget; |
| - if (m_widget) { |
| - // If we've already received a layout, apply the calculated space to the |
| - // widget immediately, but we have to have really been fully constructed (with a non-null |
| - // style pointer). |
| + if (widget) { |
| if (style()) { |
| if (!needsLayout()) |
| updateWidgetGeometry(); |
| - if (style()->visibility() != VISIBLE) |
| - m_widget->hide(); |
| - else { |
| - m_widget->show(); |
| + if (style()->visibility() != VISIBLE) { |
| + widget->hide(); |
| + } else { |
| + widget->show(); |
| repaint(); |
| } |
| } |
| - moveWidgetToParentSoon(m_widget.get(), m_frameView); |
| + moveWidgetToParentSoon(widget, m_frameView); |
| } |
| + if (AXObjectCache* cache = document().existingAXObjectCache()) |
| + cache->childrenChanged(this); |
| +} |
| + |
| +void RenderWidget::detachWidget(Widget* widget) |
| +{ |
| + // If the widget has no parent, it means it's already detached. |
|
eseidel
2013/12/02 16:28:34
Detach can be called twice?
wjmaclean
2013/12/02 21:51:55
That was a bug I was trying to resolve in this CL.
|
| + if (!widget || !widget->parent()) |
| + return; |
| + |
| + moveWidgetToParentSoon(widget, 0); |
| if (AXObjectCache* cache = document().existingAXObjectCache()) |
| cache->childrenChanged(this); |
| @@ -219,11 +236,13 @@ void RenderWidget::layout() |
| void RenderWidget::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) |
| { |
| RenderReplaced::styleDidChange(diff, oldStyle); |
| - if (m_widget) { |
| + Widget* widget = this->widget(); |
| + |
| + if (widget) { |
| if (style()->visibility() != VISIBLE) |
| - m_widget->hide(); |
| + widget->hide(); |
| else |
| - m_widget->show(); |
| + widget->show(); |
| } |
| } |
| @@ -231,9 +250,12 @@ void RenderWidget::paintContents(PaintInfo& paintInfo, const LayoutPoint& paintO |
| { |
| LayoutPoint adjustedPaintOffset = paintOffset + location(); |
| + Widget* widget = this->widget(); |
| + ASSERT(widget); |
| + |
| // Tell the widget to paint now. This is the only time the widget is allowed |
| // to paint itself. That way it will composite properly with z-indexed layers. |
| - IntPoint widgetLocation = m_widget->frameRect().location(); |
| + IntPoint widgetLocation = widget->frameRect().location(); |
| IntPoint paintLocation(roundToInt(adjustedPaintOffset.x() + borderLeft() + paddingLeft()), |
| roundToInt(adjustedPaintOffset.y() + borderTop() + paddingTop())); |
| IntRect paintRect = paintInfo.rect; |
| @@ -245,17 +267,17 @@ void RenderWidget::paintContents(PaintInfo& paintInfo, const LayoutPoint& paintO |
| paintInfo.context->translate(widgetPaintOffset); |
| paintRect.move(-widgetPaintOffset); |
| } |
| - m_widget->paint(paintInfo.context, paintRect); |
| + widget->paint(paintInfo.context, paintRect); |
| if (!widgetPaintOffset.isZero()) |
| paintInfo.context->translate(-widgetPaintOffset); |
| - if (m_widget->isFrameView()) { |
| - FrameView* frameView = toFrameView(m_widget.get()); |
| + if (widget->isFrameView()) { |
| + FrameView* frameView = toFrameView(widget); |
| bool runOverlapTests = !frameView->useSlowRepaintsIfNotOverlapped() || frameView->hasCompositedContent(); |
| if (paintInfo.overlapTestRequests && runOverlapTests) { |
| ASSERT(!paintInfo.overlapTestRequests->contains(this)); |
| - paintInfo.overlapTestRequests->set(this, m_widget->frameRect()); |
| + paintInfo.overlapTestRequests->set(this, widget->frameRect()); |
| } |
| } |
| } |
| @@ -296,7 +318,8 @@ void RenderWidget::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
| clipRoundedInnerRect(paintInfo.context, borderRect, roundedInnerRect); |
| } |
| - if (m_widget) |
| + Widget* widget = this->widget(); |
| + if (widget) |
| paintContents(paintInfo, paintOffset); |
| if (style()->hasBorderRadius()) |
| @@ -314,9 +337,10 @@ void RenderWidget::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
| void RenderWidget::setIsOverlapped(bool isOverlapped) |
| { |
| - ASSERT(m_widget); |
| - ASSERT(m_widget->isFrameView()); |
| - toFrameView(m_widget.get())->setIsOverlapped(isOverlapped); |
| + Widget* widget = this->widget(); |
| + ASSERT(widget); |
| + ASSERT(widget->isFrameView()); |
| + toFrameView(widget)->setIsOverlapped(isOverlapped); |
| } |
| void RenderWidget::deref() |
| @@ -327,15 +351,16 @@ void RenderWidget::deref() |
| void RenderWidget::updateWidgetPosition() |
| { |
| - if (!m_widget || !node()) // Check the node in case destroy() has been called. |
| + Widget* widget = this->widget(); |
| + if (!widget || !node()) // Check the node in case destroy() has been called. |
| return; |
| bool boundsChanged = updateWidgetGeometry(); |
| // if the frame bounds got changed, or if view needs layout (possibly indicating |
| // content size is wrong) we have to do a layout to set the right widget size |
| - if (m_widget && m_widget->isFrameView()) { |
| - FrameView* frameView = toFrameView(m_widget.get()); |
| + if (widget && widget->isFrameView()) { |
| + FrameView* frameView = toFrameView(widget); |
| // Check the frame's page to make sure that the frame isn't in the process of being destroyed. |
| if ((boundsChanged || frameView->needsLayout()) && frameView->frame().page()) |
| frameView->layout(); |
| @@ -344,9 +369,10 @@ void RenderWidget::updateWidgetPosition() |
| void RenderWidget::widgetPositionsUpdated() |
| { |
| - if (!m_widget) |
| + Widget* widget = this->widget(); |
| + if (!widget) |
| return; |
| - m_widget->widgetPositionsUpdated(); |
| + widget->widgetPositionsUpdated(); |
| } |
| IntRect RenderWidget::windowClipRect() const |
| @@ -357,11 +383,6 @@ IntRect RenderWidget::windowClipRect() const |
| return intersection(m_frameView->contentsToWindow(m_clipRect), m_frameView->windowClipRect()); |
| } |
| -void RenderWidget::clearWidget() |
| -{ |
| - m_widget = 0; |
| -} |
| - |
| bool RenderWidget::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction action) |
| { |
| bool hadResult = result.innerNode(); |