RenderReplaced.cpp [plain text]
#include "config.h"
#include "RenderReplaced.h"
#include "DocumentMarkerController.h"
#include "ElementRuleCollector.h"
#include "FloatRoundedRect.h"
#include "Frame.h"
#include "GraphicsContext.h"
#include "HTMLElement.h"
#include "HTMLImageElement.h"
#include "HTMLParserIdioms.h"
#include "HighlightData.h"
#include "HighlightRegister.h"
#include "InlineElementBox.h"
#include "LayoutIntegrationLineIterator.h"
#include "LayoutIntegrationRunIterator.h"
#include "LayoutRepainter.h"
#include "RenderBlock.h"
#include "RenderFragmentedFlow.h"
#include "RenderImage.h"
#include "RenderLayer.h"
#include "RenderTheme.h"
#include "RenderView.h"
#include "RenderedDocumentMarker.h"
#include "RuntimeEnabledFeatures.h"
#include "Settings.h"
#include "VisiblePosition.h"
#include <wtf/IsoMallocInlines.h>
#include <wtf/StackStats.h>
namespace WebCore {
WTF_MAKE_ISO_ALLOCATED_IMPL(RenderReplaced);
const int cDefaultWidth = 300;
const int cDefaultHeight = 150;
RenderReplaced::RenderReplaced(Element& element, RenderStyle&& style)
: RenderBox(element, WTFMove(style), RenderReplacedFlag)
, m_intrinsicSize(cDefaultWidth, cDefaultHeight)
{
setReplaced(true);
}
RenderReplaced::RenderReplaced(Element& element, RenderStyle&& style, const LayoutSize& intrinsicSize)
: RenderBox(element, WTFMove(style), RenderReplacedFlag)
, m_intrinsicSize(intrinsicSize)
{
setReplaced(true);
}
RenderReplaced::RenderReplaced(Document& document, RenderStyle&& style, const LayoutSize& intrinsicSize)
: RenderBox(document, WTFMove(style), RenderReplacedFlag)
, m_intrinsicSize(intrinsicSize)
{
setReplaced(true);
}
RenderReplaced::~RenderReplaced() = default;
void RenderReplaced::willBeDestroyed()
{
if (!renderTreeBeingDestroyed() && parent())
parent()->dirtyLinesFromChangedChild(*this);
RenderBox::willBeDestroyed();
}
void RenderReplaced::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
RenderBox::styleDidChange(diff, oldStyle);
auto previousEffectiveZoom = oldStyle ? oldStyle->effectiveZoom() : RenderStyle::initialZoom();
if (previousEffectiveZoom != style().effectiveZoom())
intrinsicSizeChanged();
}
void RenderReplaced::layout()
{
StackStats::LayoutCheckPoint layoutCheckPoint;
ASSERT(needsLayout());
LayoutRepainter repainter(*this, checkForRepaintDuringLayout());
setHeight(minimumReplacedHeight());
updateLogicalWidth();
updateLogicalHeight();
clearOverflow();
addVisualEffectOverflow();
updateLayerTransform();
invalidateBackgroundObscurationStatus();
repainter.repaintAfterLayout();
clearNeedsLayout();
}
void RenderReplaced::intrinsicSizeChanged()
{
int scaledWidth = static_cast<int>(cDefaultWidth * style().effectiveZoom());
int scaledHeight = static_cast<int>(cDefaultHeight * style().effectiveZoom());
m_intrinsicSize = IntSize(scaledWidth, scaledHeight);
setNeedsLayoutAndPrefWidthsRecalc();
}
bool RenderReplaced::shouldDrawSelectionTint() const
{
return selectionState() != HighlightState::None && !document().printing();
}
inline static bool draggedContentContainsReplacedElement(const Vector<RenderedDocumentMarker*>& markers, const Element& element)
{
for (auto* marker : markers) {
if (WTF::get<RefPtr<Node>>(marker->data()) == &element)
return true;
}
return false;
}
Color RenderReplaced::calculateHighlightColor() const
{
HighlightData highlightData;
#if ENABLE(APP_HIGHLIGHTS)
if (auto appHighlightRegister = document().appHighlightRegisterIfExists()) {
for (auto& highlight : appHighlightRegister->map()) {
for (auto& rangeData : highlight.value->rangesData()) {
if (!highlightData.setRenderRange(rangeData))
continue;
auto state = highlightData.highlightStateForRenderer(*this);
if (!isHighlighted(state, highlightData))
continue;
OptionSet<StyleColor::Options> styleColorOptions = { StyleColor::Options::UseSystemAppearance };
return theme().appHighlightColor(styleColorOptions);
}
}
}
#endif
if (RuntimeEnabledFeatures::sharedFeatures().highlightAPIEnabled()) {
if (auto highlightRegister = document().highlightRegisterIfExists()) {
for (auto& highlight : highlightRegister->map()) {
for (auto& rangeData : highlight.value->rangesData()) {
if (!highlightData.setRenderRange(rangeData))
continue;
auto state = highlightData.highlightStateForRenderer(*this);
if (!isHighlighted(state, highlightData))
continue;
if (auto highlightStyle = getUncachedPseudoStyle({ PseudoId::Highlight, highlight.key }, &style()))
return highlightStyle->backgroundColor();
}
}
}
}
return Color();
}
void RenderReplaced::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
if (!shouldPaint(paintInfo, paintOffset))
return;
LayoutPoint adjustedPaintOffset = paintOffset + location();
if (paintInfo.phase == PaintPhase::EventRegion) {
if (visibleToHitTesting()) {
auto borderRect = LayoutRect(adjustedPaintOffset, size());
auto borderRegion = approximateAsRegion(style().getRoundedBorderFor(borderRect));
paintInfo.eventRegionContext->unite(borderRegion, style());
}
return;
}
SetLayoutNeededForbiddenScope scope(*this);
GraphicsContextStateSaver savedGraphicsContext(paintInfo.context(), false);
if (element() && element()->parentOrShadowHostElement()) {
auto* parentContainer = element()->parentOrShadowHostElement();
ASSERT(parentContainer);
if (draggedContentContainsReplacedElement(document().markers().markersFor(*parentContainer, DocumentMarker::DraggedContent), *element())) {
savedGraphicsContext.save();
paintInfo.context().setAlpha(0.25);
}
}
if (hasVisibleBoxDecorations() && paintInfo.phase == PaintPhase::Foreground)
paintBoxDecorations(paintInfo, adjustedPaintOffset);
if (paintInfo.phase == PaintPhase::Mask) {
paintMask(paintInfo, adjustedPaintOffset);
return;
}
LayoutRect paintRect = LayoutRect(adjustedPaintOffset, size());
if (paintInfo.phase == PaintPhase::Outline || paintInfo.phase == PaintPhase::SelfOutline) {
if (style().outlineWidth())
paintOutline(paintInfo, paintRect);
return;
}
if (paintInfo.phase != PaintPhase::Foreground && paintInfo.phase != PaintPhase::Selection)
return;
if (!paintInfo.shouldPaintWithinRoot(*this))
return;
Color highlightColor;
if (!document().printing() && !paintInfo.paintBehavior.contains(PaintBehavior::ExcludeSelection))
highlightColor = calculateHighlightColor();
bool drawSelectionTint = shouldDrawSelectionTint();
if (paintInfo.phase == PaintPhase::Selection) {
if (selectionState() == HighlightState::None)
return;
drawSelectionTint = false;
}
bool completelyClippedOut = false;
if (style().hasBorderRadius()) {
completelyClippedOut = size().isEmpty();
if (!completelyClippedOut) {
paintInfo.context().save();
auto pixelSnappedRoundedRect = style().getRoundedInnerBorderFor(paintRect,
paddingTop() + borderTop(), paddingBottom() + borderBottom(), paddingLeft() + borderLeft(), paddingRight() + borderRight(), true, true).pixelSnappedRoundedRectForPainting(document().deviceScaleFactor());
clipRoundedInnerRect(paintInfo.context(), paintRect, pixelSnappedRoundedRect);
}
}
if (!completelyClippedOut) {
paintReplaced(paintInfo, adjustedPaintOffset);
if (style().hasBorderRadius())
paintInfo.context().restore();
}
if (drawSelectionTint) {
LayoutRect selectionPaintingRect = localSelectionRect();
selectionPaintingRect.moveBy(adjustedPaintOffset);
paintInfo.context().fillRect(snappedIntRect(selectionPaintingRect), selectionBackgroundColor());
}
if (highlightColor.isVisible()) {
auto selectionPaintingRect = localSelectionRect(false);
selectionPaintingRect.moveBy(adjustedPaintOffset);
paintInfo.context().fillRect(snappedIntRect(selectionPaintingRect), highlightColor);
}
}
bool RenderReplaced::shouldPaint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
if ((paintInfo.paintBehavior.contains(PaintBehavior::ExcludeSelection)) && isSelected())
return false;
if (paintInfo.phase != PaintPhase::Foreground
&& paintInfo.phase != PaintPhase::Outline
&& paintInfo.phase != PaintPhase::SelfOutline
&& paintInfo.phase != PaintPhase::Selection
&& paintInfo.phase != PaintPhase::Mask
&& paintInfo.phase != PaintPhase::EventRegion)
return false;
if (!paintInfo.shouldPaintWithinRoot(*this))
return false;
if (style().visibility() != Visibility::Visible)
return false;
LayoutPoint adjustedPaintOffset = paintOffset + location();
LayoutUnit top = adjustedPaintOffset.y() + visualOverflowRect().y();
LayoutUnit bottom = adjustedPaintOffset.y() + visualOverflowRect().maxY();
if (isSelected() && m_inlineBoxWrapper) {
const RootInlineBox& rootBox = m_inlineBoxWrapper->root();
LayoutUnit selTop = paintOffset.y() + rootBox.selectionTop();
LayoutUnit selBottom = paintOffset.y() + selTop + rootBox.selectionHeight();
top = std::min(selTop, top);
bottom = std::max(selBottom, bottom);
}
LayoutRect localRepaintRect = paintInfo.rect;
if (adjustedPaintOffset.x() + visualOverflowRect().x() >= localRepaintRect.maxX() || adjustedPaintOffset.x() + visualOverflowRect().maxX() <= localRepaintRect.x())
return false;
if (top >= localRepaintRect.maxY() || bottom <= localRepaintRect.y())
return false;
return true;
}
static inline RenderBlock* firstContainingBlockWithLogicalWidth(const RenderReplaced* replaced)
{
RenderBlock* containingBlock = replaced->containingBlock();
if (!containingBlock)
return 0;
for (; containingBlock && !is<RenderView>(*containingBlock) && !containingBlock->isBody(); containingBlock = containingBlock->containingBlock()) {
if (containingBlock->style().logicalWidth().isSpecified())
return containingBlock;
}
return 0;
}
bool RenderReplaced::hasReplacedLogicalWidth() const
{
if (style().logicalWidth().isSpecified())
return true;
if (style().logicalWidth().isAuto())
return false;
return firstContainingBlockWithLogicalWidth(this);
}
bool RenderReplaced::hasReplacedLogicalHeight() const
{
if (style().logicalHeight().isAuto())
return false;
if (style().logicalHeight().isSpecified()) {
if (hasAutoHeightOrContainingBlockWithAutoHeight())
return false;
return true;
}
if (style().logicalHeight().isIntrinsic())
return true;
return false;
}
bool RenderReplaced::setNeedsLayoutIfNeededAfterIntrinsicSizeChange()
{
setPreferredLogicalWidthsDirty(true);
bool imageSizeIsConstrained = style().logicalWidth().isSpecified() && style().logicalHeight().isSpecified();
bool containingBlockNeedsToRecomputePreferredSize =
style().logicalWidth().isPercentOrCalculated()
|| style().logicalMaxWidth().isPercentOrCalculated()
|| style().logicalMinWidth().isPercentOrCalculated();
if (!imageSizeIsConstrained || containingBlockNeedsToRecomputePreferredSize || isFlexItem()) {
setNeedsLayout();
return true;
}
return false;
}
void RenderReplaced::computeAspectRatioInformationForRenderBox(RenderBox* contentRenderer, FloatSize& constrainedSize, double& intrinsicRatio) const
{
FloatSize intrinsicSize;
if (contentRenderer) {
contentRenderer->computeIntrinsicRatioInformation(intrinsicSize, intrinsicRatio);
if (style().aspectRatioType() == AspectRatioType::Ratio || (style().aspectRatioType() == AspectRatioType::AutoAndRatio && !intrinsicRatio))
intrinsicRatio = style().aspectRatioWidth() / style().aspectRatioHeight();
intrinsicSize.scale(style().effectiveZoom());
if (is<RenderImage>(*this))
intrinsicSize.scale(downcast<RenderImage>(*this).imageDevicePixelRatio());
if (intrinsicRatio && !intrinsicSize.isZero())
m_intrinsicSize = LayoutSize(intrinsicSize);
if (!isHorizontalWritingMode()) {
if (intrinsicRatio)
intrinsicRatio = 1 / intrinsicRatio;
intrinsicSize = intrinsicSize.transposedSize();
}
} else {
computeIntrinsicRatioInformation(intrinsicSize, intrinsicRatio);
if (intrinsicRatio && !intrinsicSize.isZero())
m_intrinsicSize = LayoutSize(isHorizontalWritingMode() ? intrinsicSize : intrinsicSize.transposedSize());
}
constrainedSize = intrinsicSize;
if (intrinsicRatio && !intrinsicSize.isEmpty() && style().logicalWidth().isAuto() && style().logicalHeight().isAuto()) {
constrainedSize.setWidth(RenderBox::computeReplacedLogicalHeight() * intrinsicSize.width() / intrinsicSize.height());
constrainedSize.setHeight(RenderBox::computeReplacedLogicalWidth() * intrinsicSize.height() / intrinsicSize.width());
}
}
LayoutRect RenderReplaced::replacedContentRect(const LayoutSize& intrinsicSize) const
{
LayoutRect contentRect = contentBoxRect();
if (intrinsicSize.isEmpty())
return contentRect;
ObjectFit objectFit = style().objectFit();
LayoutRect finalRect = contentRect;
switch (objectFit) {
case ObjectFit::Contain:
case ObjectFit::ScaleDown:
case ObjectFit::Cover:
finalRect.setSize(finalRect.size().fitToAspectRatio(intrinsicSize, objectFit == ObjectFit::Cover ? AspectRatioFitGrow : AspectRatioFitShrink));
if (objectFit != ObjectFit::ScaleDown || finalRect.width() <= intrinsicSize.width())
break;
FALLTHROUGH;
case ObjectFit::None:
finalRect.setSize(intrinsicSize);
break;
case ObjectFit::Fill:
break;
}
LengthPoint objectPosition = style().objectPosition();
LayoutUnit xOffset = minimumValueForLength(objectPosition.x(), contentRect.width() - finalRect.width());
LayoutUnit yOffset = minimumValueForLength(objectPosition.y(), contentRect.height() - finalRect.height());
finalRect.move(xOffset, yOffset);
return finalRect;
}
RoundedRect RenderReplaced::roundedContentBoxRect() const
{
return style().getRoundedInnerBorderFor(borderBoxRect(),
borderTop() + paddingTop(), borderBottom() + paddingBottom(),
borderLeft() + paddingLeft(), borderRight() + paddingRight());
}
void RenderReplaced::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, double& intrinsicRatio) const
{
ASSERT(!embeddedContentBox());
intrinsicSize = FloatSize(intrinsicLogicalWidth(), intrinsicLogicalHeight());
if (style().hasAspectRatio()) {
intrinsicRatio = style().logicalAspectRatio();
if (style().aspectRatioType() == AspectRatioType::Ratio)
return;
}
if (!hasAspectRatio())
return;
if (intrinsicSize.isEmpty()) {
if (!settings().aspectRatioOfImgFromWidthAndHeightEnabled())
return;
auto* node = element();
if (!node || !is<HTMLImageElement>(*node) || !node->hasAttribute(HTMLNames::widthAttr) || !node->hasAttribute(HTMLNames::heightAttr))
return;
if (!is<RenderImage>(*this) || !downcast<RenderImage>(*this).cachedImage())
return;
intrinsicSize.setWidth(parseValidHTMLFloatingPointNumber(node->getAttribute(HTMLNames::widthAttr)).valueOr(0));
intrinsicSize.setHeight(parseValidHTMLFloatingPointNumber(node->getAttribute(HTMLNames::heightAttr)).valueOr(0));
if (intrinsicSize.isEmpty())
return;
}
intrinsicRatio = intrinsicSize.width() / intrinsicSize.height();
}
LayoutUnit RenderReplaced::computeConstrainedLogicalWidth(ShouldComputePreferred shouldComputePreferred) const
{
if (shouldComputePreferred == ComputePreferred)
return computeReplacedLogicalWidthRespectingMinMaxWidth(0_lu, ComputePreferred);
LayoutUnit logicalWidth = containingBlock()->availableLogicalWidth();
LayoutUnit marginStart = minimumValueForLength(style().marginStart(), logicalWidth);
LayoutUnit marginEnd = minimumValueForLength(style().marginEnd(), logicalWidth);
logicalWidth = std::max(0_lu, (logicalWidth - (marginStart + marginEnd + borderLeft() + borderRight())));
return computeReplacedLogicalWidthRespectingMinMaxWidth(logicalWidth, shouldComputePreferred);
}
LayoutUnit RenderReplaced::computeReplacedLogicalWidth(ShouldComputePreferred shouldComputePreferred) const
{
if (style().logicalWidth().isSpecified() || style().logicalWidth().isIntrinsic())
return computeReplacedLogicalWidthRespectingMinMaxWidth(computeReplacedLogicalWidthUsing(MainOrPreferredSize, style().logicalWidth()), shouldComputePreferred);
RenderBox* contentRenderer = embeddedContentBox();
double intrinsicRatio = 0;
FloatSize constrainedSize;
computeAspectRatioInformationForRenderBox(contentRenderer, constrainedSize, intrinsicRatio);
if (style().logicalWidth().isAuto()) {
bool computedHeightIsAuto = style().logicalHeight().isAuto();
bool hasIntrinsicWidth = constrainedSize.width() > 0;
bool hasIntrinsicHeight = constrainedSize.height() > 0;
if (intrinsicRatio && isFlexItem() && hasOverridingLogicalHeight() && hasIntrinsicWidth && hasIntrinsicHeight)
return computeReplacedLogicalWidthRespectingMinMaxWidth(roundToInt(round(overridingContentLogicalHeight() * intrinsicRatio)), shouldComputePreferred);
if (computedHeightIsAuto && hasIntrinsicWidth)
return computeReplacedLogicalWidthRespectingMinMaxWidth(constrainedSize.width(), shouldComputePreferred);
if (intrinsicRatio) {
if (intrinsicRatio && ((computedHeightIsAuto && !hasIntrinsicWidth && hasIntrinsicHeight) || !computedHeightIsAuto)) {
LayoutUnit estimatedUsedWidth = hasIntrinsicWidth ? LayoutUnit(constrainedSize.width()) : computeConstrainedLogicalWidth(shouldComputePreferred);
LayoutUnit logicalHeight = computeReplacedLogicalHeight(Optional<LayoutUnit>(estimatedUsedWidth));
return computeReplacedLogicalWidthRespectingMinMaxWidth(roundToInt(round(logicalHeight * intrinsicRatio)), shouldComputePreferred);
}
if (computedHeightIsAuto && !hasIntrinsicWidth && !hasIntrinsicHeight)
return computeConstrainedLogicalWidth(shouldComputePreferred);
}
if (hasIntrinsicWidth)
return computeReplacedLogicalWidthRespectingMinMaxWidth(constrainedSize.width(), shouldComputePreferred);
}
return computeReplacedLogicalWidthRespectingMinMaxWidth(intrinsicLogicalWidth(), shouldComputePreferred);
}
LayoutUnit RenderReplaced::computeReplacedLogicalHeight(Optional<LayoutUnit> estimatedUsedWidth) const
{
if (hasReplacedLogicalHeight())
return computeReplacedLogicalHeightRespectingMinMaxHeight(computeReplacedLogicalHeightUsing(MainOrPreferredSize, style().logicalHeight()));
RenderBox* contentRenderer = embeddedContentBox();
double intrinsicRatio = 0;
FloatSize constrainedSize;
computeAspectRatioInformationForRenderBox(contentRenderer, constrainedSize, intrinsicRatio);
bool widthIsAuto = style().logicalWidth().isAuto();
bool hasIntrinsicHeight = constrainedSize.height() > 0;
bool hasIntrinsicWidth = constrainedSize.width() > 0;
if (intrinsicRatio && isFlexItem() && hasOverridingLogicalWidth() && hasIntrinsicHeight && hasIntrinsicWidth)
return computeReplacedLogicalHeightRespectingMinMaxHeight(roundToInt(round(overridingContentLogicalWidth() / intrinsicRatio)));
if (widthIsAuto && hasIntrinsicHeight)
return computeReplacedLogicalHeightRespectingMinMaxHeight(constrainedSize.height());
if (intrinsicRatio) {
LayoutUnit usedWidth = estimatedUsedWidth ? estimatedUsedWidth.value() : availableLogicalWidth();
return computeReplacedLogicalHeightRespectingMinMaxHeight(roundToInt(round(usedWidth / intrinsicRatio)));
}
if (hasIntrinsicHeight)
return computeReplacedLogicalHeightRespectingMinMaxHeight(constrainedSize.height());
return computeReplacedLogicalHeightRespectingMinMaxHeight(intrinsicLogicalHeight());
}
void RenderReplaced::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const
{
minLogicalWidth = maxLogicalWidth = intrinsicLogicalWidth();
}
void RenderReplaced::computePreferredLogicalWidths()
{
ASSERT(preferredLogicalWidthsDirty());
if (style().logicalWidth().isPercentOrCalculated()) {
double intrinsicRatio = 0;
FloatSize constrainedSize;
computeAspectRatioInformationForRenderBox(embeddedContentBox(), constrainedSize, intrinsicRatio);
computeIntrinsicLogicalWidths(m_minPreferredLogicalWidth, m_maxPreferredLogicalWidth);
} else
m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = computeReplacedLogicalWidth(ComputePreferred);
const RenderStyle& styleToUse = style();
if (styleToUse.logicalWidth().isPercentOrCalculated() || styleToUse.logicalMaxWidth().isPercentOrCalculated())
m_minPreferredLogicalWidth = 0;
if (styleToUse.logicalMinWidth().isFixed() && styleToUse.logicalMinWidth().value() > 0) {
m_maxPreferredLogicalWidth = std::max(m_maxPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMinWidth()));
m_minPreferredLogicalWidth = std::max(m_minPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMinWidth()));
}
if (styleToUse.logicalMaxWidth().isFixed()) {
m_maxPreferredLogicalWidth = std::min(m_maxPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMaxWidth()));
m_minPreferredLogicalWidth = std::min(m_minPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(styleToUse.logicalMaxWidth()));
}
LayoutUnit borderAndPadding = borderAndPaddingLogicalWidth();
m_minPreferredLogicalWidth += borderAndPadding;
m_maxPreferredLogicalWidth += borderAndPadding;
setPreferredLogicalWidthsDirty(false);
}
VisiblePosition RenderReplaced::positionForPoint(const LayoutPoint& point, const RenderFragmentContainer* fragment)
{
auto [top, bottom] = [&] {
if (auto run = LayoutIntegration::runFor(*this)) {
auto line = run.line();
return std::make_pair(line->selectionTopForHitTesting(), line->selectionBottom());
}
return std::make_pair(logicalTop(), logicalBottom());
}();
LayoutUnit blockDirectionPosition = isHorizontalWritingMode() ? point.y() + y() : point.x() + x();
LayoutUnit lineDirectionPosition = isHorizontalWritingMode() ? point.x() + x() : point.y() + y();
if (blockDirectionPosition < top)
return createVisiblePosition(caretMinOffset(), Affinity::Downstream);
if (blockDirectionPosition >= bottom)
return createVisiblePosition(caretMaxOffset(), Affinity::Downstream);
if (element()) {
if (lineDirectionPosition <= logicalLeft() + (logicalWidth() / 2))
return createVisiblePosition(0, Affinity::Downstream);
return createVisiblePosition(1, Affinity::Downstream);
}
return RenderBox::positionForPoint(point, fragment);
}
LayoutRect RenderReplaced::selectionRectForRepaint(const RenderLayerModelObject* repaintContainer, bool clipToVisibleContent)
{
ASSERT(!needsLayout());
if (!isSelected())
return LayoutRect();
LayoutRect rect = localSelectionRect();
if (clipToVisibleContent)
return computeRectForRepaint(rect, repaintContainer);
return localToContainerQuad(FloatRect(rect), repaintContainer).enclosingBoundingBox();
}
LayoutRect RenderReplaced::localSelectionRect(bool checkWhetherSelected) const
{
if (checkWhetherSelected && !isSelected())
return LayoutRect();
if (!m_inlineBoxWrapper)
return LayoutRect(LayoutPoint(), size());
const RootInlineBox& rootBox = m_inlineBoxWrapper->root();
LayoutUnit newLogicalTop { rootBox.blockFlow().style().isFlippedBlocksWritingMode() ? m_inlineBoxWrapper->logicalBottom() - rootBox.selectionBottom() : rootBox.selectionTop() - m_inlineBoxWrapper->logicalTop() };
if (rootBox.blockFlow().style().isHorizontalWritingMode())
return LayoutRect(0_lu, newLogicalTop, width(), rootBox.selectionHeight());
return LayoutRect(newLogicalTop, 0_lu, rootBox.selectionHeight(), height());
}
bool RenderReplaced::isSelected() const
{
return isHighlighted(selectionState(), view().selection());
}
bool RenderReplaced::isHighlighted(HighlightState state, const HighlightData& rangeData) const
{
if (state == HighlightState::None)
return false;
if (state == HighlightState::Inside)
return true;
auto selectionStart = rangeData.startOffset();
auto selectionEnd = rangeData.endOffset();
if (state == HighlightState::Start)
return !selectionStart;
unsigned end = element()->hasChildNodes() ? element()->countChildNodes() : 1;
if (state == HighlightState::End)
return selectionEnd == end;
if (state == HighlightState::Both)
return !selectionStart && selectionEnd == end;
ASSERT_NOT_REACHED();
return false;
}
LayoutRect RenderReplaced::clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const
{
if (style().visibility() != Visibility::Visible && !enclosingLayer()->hasVisibleContent())
return LayoutRect();
LayoutRect r = unionRect(localSelectionRect(false), visualOverflowRect());
r.move(view().frameView().layoutContext().layoutDelta());
return computeRectForRepaint(r, repaintContainer);
}
}