Diff
Modified: trunk/Source/WebCore/ChangeLog (282336 => 282337)
--- trunk/Source/WebCore/ChangeLog 2021-09-13 17:37:02 UTC (rev 282336)
+++ trunk/Source/WebCore/ChangeLog 2021-09-13 17:47:56 UTC (rev 282337)
@@ -1,3 +1,35 @@
+2021-09-13 Antti Koivisto <[email protected]>
+
+ LegacyInlineTextBox::selectionState accessor mutates ellipsis selection state
+ https://bugs.webkit.org/show_bug.cgi?id=205528
+ <rdar://problem/58125978>
+
+ Reviewed by Alan Bujtas.
+
+ An accessor shouldn't mutate state.
+
+ * rendering/LegacyEllipsisBox.cpp:
+ (WebCore::LegacyEllipsisBox::paintSelection):
+
+ Also position ellipsis selection correctly when painting.
+
+ (WebCore::LegacyEllipsisBox::nodeAtPoint):
+ (WebCore::LegacyEllipsisBox::selectionState const):
+ * rendering/LegacyEllipsisBox.h:
+ * rendering/LegacyInlineTextBox.cpp:
+ (WebCore::LegacyInlineTextBox::selectionState const):
+
+ Compute the selection state of the ellipsis box by looking at the selection state of the
+ last text box on the line.
+
+ * rendering/LegacyRootInlineBox.cpp:
+ (WebCore::LegacyRootInlineBox::lineSelectionGap):
+ (WebCore::LegacyRootInlineBox::firstSelectedBox const):
+ (WebCore::LegacyRootInlineBox::lastSelectedBox const):
+ (WebCore::LegacyRootInlineBox::firstSelectedBox): Deleted.
+ (WebCore::LegacyRootInlineBox::lastSelectedBox): Deleted.
+ * rendering/LegacyRootInlineBox.h:
+
2021-09-13 Kimmo Kinnunen <[email protected]>
image-rendering: pixelated does not work with WebGL (but does with Canvas2D)
Modified: trunk/Source/WebCore/rendering/LegacyEllipsisBox.cpp (282336 => 282337)
--- trunk/Source/WebCore/rendering/LegacyEllipsisBox.cpp 2021-09-13 17:37:02 UTC (rev 282336)
+++ trunk/Source/WebCore/rendering/LegacyEllipsisBox.cpp 2021-09-13 17:47:56 UTC (rev 282337)
@@ -112,7 +112,7 @@
markupBox->paint(paintInfo, adjustedPaintOffset, lineTop, lineBottom);
}
-IntRect LegacyEllipsisBox::selectionRect()
+IntRect LegacyEllipsisBox::selectionRect() const
{
const RenderStyle& lineStyle = this->lineStyle();
const FontCascade& font = lineStyle.fontCascade();
@@ -139,7 +139,7 @@
const LegacyRootInlineBox& rootBox = root();
GraphicsContextStateSaver stateSaver(context);
// FIXME: Why is this always LTR? Fix by passing correct text run flags below.
- LayoutRect selectionRect { LayoutUnit(x() + paintOffset.x()), LayoutUnit(y() + paintOffset.y() + rootBox.selectionTop()), 0_lu, rootBox.selectionHeight() };
+ LayoutRect selectionRect { LayoutUnit(x() + paintOffset.x()), rootBox.selectionTop() + paintOffset.y(), 0_lu, rootBox.selectionHeight() };
TextRun run = RenderBlock::constructTextRun(m_str, style, AllowRightExpansion);
font.adjustSelectionRectForText(run, selectionRect);
context.fillRect(snapRectToDevicePixelsWithWritingDirection(selectionRect, renderer().document().deviceScaleFactor(), run.ltr()), c);
@@ -170,4 +170,19 @@
return false;
}
+RenderObject::HighlightState LegacyEllipsisBox::selectionState() const
+{
+ auto* lastSelectedBox = root().lastSelectedBox();
+ if (!is<LegacyInlineTextBox>(lastSelectedBox))
+ return RenderObject::HighlightState::None;
+
+ auto& textBox = downcast<LegacyInlineTextBox>(*lastSelectedBox);
+
+ auto [selectionStart, selectionEnd] = textBox.selectionStartEnd();
+ if (selectionEnd >= textBox.truncation() && selectionStart <= textBox.truncation())
+ return RenderObject::HighlightState::Inside;
+
+ return RenderObject::HighlightState::None;
+}
+
} // namespace WebCore
Modified: trunk/Source/WebCore/rendering/LegacyEllipsisBox.h (282336 => 282337)
--- trunk/Source/WebCore/rendering/LegacyEllipsisBox.h 2021-09-13 17:37:02 UTC (rev 282336)
+++ trunk/Source/WebCore/rendering/LegacyEllipsisBox.h 2021-09-13 17:47:56 UTC (rev 282337)
@@ -33,8 +33,7 @@
LegacyEllipsisBox(RenderBlockFlow&, const AtomString& ellipsisStr, LegacyInlineFlowBox* parent, int width, int height, int y, bool firstLine, bool isHorizontal, LegacyInlineBox* markupBox);
void paint(PaintInfo&, const LayoutPoint&, LayoutUnit lineTop, LayoutUnit lineBottom) override;
bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit lineTop, LayoutUnit lineBottom, HitTestAction) final;
- void setSelectionState(RenderObject::HighlightState s) { m_selectionState = s; }
- IntRect selectionRect();
+ IntRect selectionRect() const;
RenderBlockFlow& blockFlow() const { return downcast<RenderBlockFlow>(LegacyInlineBox::renderer()); }
@@ -41,12 +40,11 @@
private:
void paintMarkupBox(PaintInfo&, const LayoutPoint& paintOffset, LayoutUnit lineTop, LayoutUnit lineBottom, const RenderStyle&);
int height() const { return m_height; }
- RenderObject::HighlightState selectionState() const override { return m_selectionState; }
+ RenderObject::HighlightState selectionState() const override;
void paintSelection(GraphicsContext&, const LayoutPoint&, const RenderStyle&, const FontCascade&);
LegacyInlineBox* markupBox() const;
bool m_shouldPaintMarkupBox;
- RenderObject::HighlightState m_selectionState { RenderObject::HighlightState::None };
int m_height;
AtomString m_str;
};
Modified: trunk/Source/WebCore/rendering/LegacyInlineTextBox.cpp (282336 => 282337)
--- trunk/Source/WebCore/rendering/LegacyInlineTextBox.cpp 2021-09-13 17:37:02 UTC (rev 282336)
+++ trunk/Source/WebCore/rendering/LegacyInlineTextBox.cpp 2021-09-13 17:47:56 UTC (rev 282337)
@@ -161,28 +161,7 @@
RenderObject::HighlightState LegacyInlineTextBox::selectionState() const
{
- auto state = renderer().view().selection().highlightStateForTextBox(renderer(), selectableRange());
-
- // FIXME: this code mutates selection state, but it's used at a simple getter elsewhere
- // in this file. This code should likely live in HighlightData, or somewhere else.
- // <rdar://problem/58125978>
- // https://bugs.webkit.org/show_bug.cgi?id=205528
- // If there are ellipsis following, make sure their selection is updated.
- if (m_truncation != cNoTruncation && root().ellipsisBox()) {
- LegacyEllipsisBox* ellipsis = root().ellipsisBox();
- if (state != RenderObject::HighlightState::None) {
- auto [selectionStart, selectionEnd] = selectionStartEnd();
- // The ellipsis should be considered to be selected if the end of
- // the selection is past the beginning of the truncation and the
- // beginning of the selection is before or at the beginning of the
- // truncation.
- ellipsis->setSelectionState(selectionEnd >= m_truncation && selectionStart <= m_truncation ?
- RenderObject::HighlightState::Inside : RenderObject::HighlightState::None);
- } else
- ellipsis->setSelectionState(RenderObject::HighlightState::None);
- }
-
- return state;
+ return renderer().view().selection().highlightStateForTextBox(renderer(), selectableRange());
}
const FontCascade& LegacyInlineTextBox::lineFont() const
Modified: trunk/Source/WebCore/rendering/LegacyRootInlineBox.cpp (282336 => 282337)
--- trunk/Source/WebCore/rendering/LegacyRootInlineBox.cpp 2021-09-13 17:37:02 UTC (rev 282336)
+++ trunk/Source/WebCore/rendering/LegacyRootInlineBox.cpp 2021-09-13 17:47:56 UTC (rev 282337)
@@ -438,8 +438,8 @@
GapRects result;
- LegacyInlineBox* firstBox = firstSelectedBox();
- LegacyInlineBox* lastBox = lastSelectedBox();
+ auto* firstBox = firstSelectedBox();
+ auto* lastBox = lastSelectedBox();
if (leftGap) {
result.uniteLeft(blockFlow().logicalLeftSelectionGap(rootBlock, rootBlockPhysicalPosition, offsetFromRootBlock, &firstBox->parent()->renderer(), LayoutUnit(firstBox->logicalLeft()),
selTop, selHeight, cache, paintInfo));
@@ -505,7 +505,7 @@
return state;
}
-LegacyInlineBox* LegacyRootInlineBox::firstSelectedBox()
+const LegacyInlineBox* LegacyRootInlineBox::firstSelectedBox() const
{
for (auto* box = firstLeafDescendant(); box; box = box->nextLeafOnLine()) {
if (box->selectionState() != RenderObject::HighlightState::None)
@@ -514,7 +514,7 @@
return nullptr;
}
-LegacyInlineBox* LegacyRootInlineBox::lastSelectedBox()
+const LegacyInlineBox* LegacyRootInlineBox::lastSelectedBox() const
{
for (auto* box = lastLeafDescendant(); box; box = box->previousLeafOnLine()) {
if (box->selectionState() != RenderObject::HighlightState::None)
Modified: trunk/Source/WebCore/rendering/LegacyRootInlineBox.h (282336 => 282337)
--- trunk/Source/WebCore/rendering/LegacyRootInlineBox.h 2021-09-13 17:37:02 UTC (rev 282336)
+++ trunk/Source/WebCore/rendering/LegacyRootInlineBox.h 2021-09-13 17:47:56 UTC (rev 282337)
@@ -127,8 +127,8 @@
bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit lineTop, LayoutUnit lineBottom, HitTestAction) override;
RenderObject::HighlightState selectionState() const final;
- LegacyInlineBox* firstSelectedBox();
- LegacyInlineBox* lastSelectedBox();
+ const LegacyInlineBox* firstSelectedBox() const;
+ const LegacyInlineBox* lastSelectedBox() const;
GapRects lineSelectionGap(RenderBlock& rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
LayoutUnit selTop, LayoutUnit selHeight, const LogicalSelectionOffsetCaches&, const PaintInfo*);