This source file includes following definitions.
- m_refCount
- willBeDestroyed
- destroy
- widget
- roundedIntRect
- setWidgetGeometry
- updateWidgetGeometry
- layout
- styleDidChange
- paintContents
- paint
- setIsOverlapped
- deref
- updateOnWidgetChange
- updateWidgetPosition
- widgetPositionsUpdated
- nodeAtPoint
- getCursor
#include "config.h"
#include "core/rendering/RenderWidget.h"
#include "core/accessibility/AXObjectCache.h"
#include "core/frame/LocalFrame.h"
#include "core/html/HTMLFrameOwnerElement.h"
#include "core/html/HTMLPlugInElement.h"
#include "core/rendering/GraphicsContextAnnotator.h"
#include "core/rendering/HitTestResult.h"
#include "core/rendering/LayoutRectRecorder.h"
#include "core/rendering/RenderLayer.h"
#include "core/rendering/RenderView.h"
#include "core/rendering/compositing/CompositedLayerMapping.h"
#include "core/rendering/compositing/RenderLayerCompositor.h"
#include "wtf/HashMap.h"
namespace WebCore {
RenderWidget::RenderWidget(Element* element)
: RenderReplaced(element)
, m_refCount(1)
{
ASSERT(element);
frameView()->addWidget(this);
}
void RenderWidget::willBeDestroyed()
{
frameView()->removeWidget(this);
if (AXObjectCache* cache = document().existingAXObjectCache()) {
cache->childrenChanged(this->parent());
cache->remove(this);
}
Element* element = toElement(node());
if (element && element->isFrameOwnerElement())
toHTMLFrameOwnerElement(element)->setWidget(nullptr);
RenderReplaced::willBeDestroyed();
}
void RenderWidget::destroy()
{
willBeDestroyed();
clearNode();
deref();
}
RenderWidget::~RenderWidget()
{
ASSERT(m_refCount <= 0);
}
Widget* RenderWidget::widget() const
{
Element* element = toElement(node());
if (element && element->isFrameOwnerElement())
return toHTMLFrameOwnerElement(element)->ownedWidget();
return 0;
}
static inline IntRect roundedIntRect(const LayoutRect& rect)
{
return IntRect(roundedIntPoint(rect.location()), roundedIntSize(rect.size()));
}
bool RenderWidget::setWidgetGeometry(const LayoutRect& frame)
{
if (!node())
return false;
Widget* widget = this->widget();
ASSERT(widget);
IntRect newFrame = roundedIntRect(frame);
if (widget->frameRect() == newFrame)
return false;
RefPtr<RenderWidget> protector(this);
RefPtr<Node> protectedNode(node());
widget->setFrameRect(newFrame);
{
DisableCompositingQueryAsserts disabler;
if (hasLayer() && layer()->compositingState() == PaintsIntoOwnBacking)
layer()->compositedLayerMapping()->updateAfterWidgetResize();
}
return widget->frameRect().size() != newFrame.size();
}
bool RenderWidget::updateWidgetGeometry()
{
Widget* widget = this->widget();
ASSERT(widget);
LayoutRect contentBox = contentBoxRect();
LayoutRect absoluteContentBox(localToAbsoluteQuad(FloatQuad(contentBox)).boundingBox());
if (widget->isFrameView()) {
contentBox.setLocation(absoluteContentBox.location());
return setWidgetGeometry(contentBox);
}
return setWidgetGeometry(absoluteContentBox);
}
void RenderWidget::layout()
{
ASSERT(needsLayout());
LayoutRectRecorder recorder(*this);
clearNeedsLayout();
}
void RenderWidget::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
RenderReplaced::styleDidChange(diff, oldStyle);
Widget* widget = this->widget();
if (widget) {
if (style()->visibility() != VISIBLE) {
widget->hide();
} else {
widget->show();
}
}
}
void RenderWidget::paintContents(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
LayoutPoint adjustedPaintOffset = paintOffset + location();
Widget* widget = this->widget();
ASSERT(widget);
IntPoint widgetLocation = widget->frameRect().location();
IntPoint paintLocation(roundToInt(adjustedPaintOffset.x() + borderLeft() + paddingLeft()),
roundToInt(adjustedPaintOffset.y() + borderTop() + paddingTop()));
IntRect paintRect = paintInfo.rect;
IntSize widgetPaintOffset = paintLocation - widgetLocation;
if (!widgetPaintOffset.isZero()) {
paintInfo.context->translate(widgetPaintOffset);
paintRect.move(-widgetPaintOffset);
}
widget->paint(paintInfo.context, paintRect);
if (!widgetPaintOffset.isZero())
paintInfo.context->translate(-widgetPaintOffset);
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, widget->frameRect());
}
}
}
void RenderWidget::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
ANNOTATE_GRAPHICS_CONTEXT(paintInfo, this);
if (!shouldPaint(paintInfo, paintOffset))
return;
LayoutPoint adjustedPaintOffset = paintOffset + location();
if (hasBoxDecorations() && (paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseSelection))
paintBoxDecorations(paintInfo, adjustedPaintOffset);
if (paintInfo.phase == PaintPhaseMask) {
paintMask(paintInfo, adjustedPaintOffset);
return;
}
if ((paintInfo.phase == PaintPhaseOutline || paintInfo.phase == PaintPhaseSelfOutline) && hasOutline())
paintOutline(paintInfo, LayoutRect(adjustedPaintOffset, size()));
if (paintInfo.phase != PaintPhaseForeground)
return;
if (style()->hasBorderRadius()) {
LayoutRect borderRect = LayoutRect(adjustedPaintOffset, size());
if (borderRect.isEmpty())
return;
paintInfo.context->save();
RoundedRect roundedInnerRect = style()->getRoundedInnerBorderFor(borderRect,
paddingTop() + borderTop(), paddingBottom() + borderBottom(), paddingLeft() + borderLeft(), paddingRight() + borderRight(), true, true);
clipRoundedInnerRect(paintInfo.context, borderRect, roundedInnerRect);
}
Widget* widget = this->widget();
if (widget)
paintContents(paintInfo, paintOffset);
if (style()->hasBorderRadius())
paintInfo.context->restore();
if (isSelected() && !document().printing()) {
paintInfo.context->fillRect(pixelSnappedIntRect(selectionRect()), selectionBackgroundColor());
}
if (canResize())
layer()->scrollableArea()->paintResizer(paintInfo.context, roundedIntPoint(adjustedPaintOffset), paintInfo.rect);
}
void RenderWidget::setIsOverlapped(bool isOverlapped)
{
Widget* widget = this->widget();
ASSERT(widget);
ASSERT(widget->isFrameView());
toFrameView(widget)->setIsOverlapped(isOverlapped);
}
void RenderWidget::deref()
{
if (--m_refCount <= 0)
postDestroy();
}
void RenderWidget::updateOnWidgetChange()
{
Widget* widget = this->widget();
if (!widget)
return;
if (!style())
return;
if (!needsLayout())
updateWidgetGeometry();
if (style()->visibility() != VISIBLE) {
widget->hide();
} else {
widget->show();
repaint();
}
}
void RenderWidget::updateWidgetPosition()
{
Widget* widget = this->widget();
if (!widget || !node())
return;
bool boundsChanged = updateWidgetGeometry();
if (widget && widget->isFrameView()) {
FrameView* frameView = toFrameView(widget);
if ((boundsChanged || frameView->needsLayout()) && frameView->frame().page())
frameView->layout();
}
}
void RenderWidget::widgetPositionsUpdated()
{
Widget* widget = this->widget();
if (!widget)
return;
widget->widgetPositionsUpdated();
}
bool RenderWidget::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction action)
{
bool hadResult = result.innerNode();
bool inside = RenderReplaced::nodeAtPoint(request, result, locationInContainer, accumulatedOffset, action);
if ((inside || result.isRectBasedTest()) && !hadResult && result.innerNode() == node())
result.setIsOverWidget(contentBoxRect().contains(result.localPoint()));
return inside;
}
CursorDirective RenderWidget::getCursor(const LayoutPoint& point, Cursor& cursor) const
{
if (widget() && widget()->isPluginView()) {
return DoNotSetCursor;
}
return RenderReplaced::getCursor(point, cursor);
}
}