Diff
Added: trunk/LayoutTests/highlight/highlight-world-leak-expected.txt (0 => 253857)
--- trunk/LayoutTests/highlight/highlight-world-leak-expected.txt (rev 0)
+++ trunk/LayoutTests/highlight/highlight-world-leak-expected.txt 2019-12-21 01:33:10 UTC (rev 253857)
@@ -0,0 +1,10 @@
+Tests that using Highlight does not cause the document to get leaked.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Document did not leak
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/highlight/highlight-world-leak.html (0 => 253857)
--- trunk/LayoutTests/highlight/highlight-world-leak.html (rev 0)
+++ trunk/LayoutTests/highlight/highlight-world-leak.html 2019-12-21 01:33:10 UTC (rev 253857)
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<body>
+<iframe id="testFrame" src=""
+<script src=""
+<script>
+description("Tests that using Highlight does not cause the document to get leaked.");
+window.jsTestIsAsync = true;
+
+function documentShouldDie(documentIdentifier)
+{
+ return new Promise(function(resolve, reject) {
+ handle = setInterval(function() {
+ gc();
+ if (internals && !internals.isDocumentAlive(documentIdentifier)) {
+ clearInterval(handle);
+ resolve();
+ }
+ }, 10);
+ });
+}
+
+var testFrame = document.getElementById("testFrame");
+testFrame._onload_ = function() {
+ let frameDocumentIdentifier = internals.documentIdentifier(testFrame.contentDocument);
+ testFrame.remove();
+ setTimeout(function() {
+ documentShouldDie(frameDocumentIdentifier).then(function() {
+ testPassed("Document did not leak");
+ finishJSTest();
+ });
+ });
+};
+</script>
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/highlight/resources/highlight-frame.html (0 => 253857)
--- trunk/LayoutTests/highlight/resources/highlight-frame.html (rev 0)
+++ trunk/LayoutTests/highlight/resources/highlight-frame.html 2019-12-21 01:33:10 UTC (rev 253857)
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<head>
+ <style>
+ ::highlight(example) {
+ background-color: yellow;
+ color:green;
+ }
+</style>
+</head>
+<div id="target">
+ <span id="highlight">highlight</span>
+</div>
+
+<script>
+let highlight = document.getElementById('highlight');
+let highlightRangeGroup = new HighlightRangeGroup(new StaticRange({startContainer: highlight, startOffset: 0, endContainer: highlight, endOffset: 4}));
+CSS.highlights.set("example", highlightRangeGroup);
+</script>
Added: trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-across-elements-expected.html (0 => 253857)
--- trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-across-elements-expected.html (rev 0)
+++ trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-across-elements-expected.html 2019-12-21 01:33:10 UTC (rev 253857)
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <style>
+ #style1 {
+ background-color: yellow;
+ color:green;
+ }
+ #style2 {
+ background-color: blue;
+ color:red;
+ }
+ #style3 {
+ background-color: purple;
+ color:pink;
+ }
+ </style>
+</head>
+<body>
+ One <span id="style1">two</span> th<span id="style2">ree
+ four</span> five <span id="style2">six
+ seven</span> eigh<span id="style3">t nine
+ ten eleven twelve
+ thirteen fou</span>rteen fifteen
+</body>
+</html>
Added: trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-across-elements.html (0 => 253857)
--- trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-across-elements.html (rev 0)
+++ trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-across-elements.html 2019-12-21 01:33:10 UTC (rev 253857)
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Custom highlight pseudo elements across elements.</title>
+ <link rel="help" href=""
+ <link rel="match" href=""
+ <meta name="assert" content="Highlights should be able to be specified across elements.">
+ <style>
+ ::highlight(example-highlight1) {
+ background-color: yellow;
+ color:green;
+ }
+ ::highlight(example-highlight2) {
+ background-color: blue;
+ color:red;
+ }
+ ::highlight(example-highlight3) {
+ background-color: purple;
+ color:pink;
+ }
+ </style>
+</head>
+<body>
+ <span id="text1">One two three</span>
+ <span id="text2">four five six</span>
+ <span id="text3">seven eight nine</span>
+ <span id="text4">ten eleven twelve</span>
+ <span id="text5">thirteen fourteen fifteen</span>
+
+ <script>
+ let textElement1 = document.getElementById('text1');
+ let textElement2 = document.getElementById('text2');
+ let textElement3 = document.getElementById('text3');
+ let textElement4 = document.getElementById('text4');
+ let textElement5 = document.getElementById('text5');
+ let highlightRangeGroup1 = new HighlightRangeGroup(new StaticRange({startContainer: textElement1, startOffset: 4, endContainer: textElement1, endOffset: 7}));
+
+ let highlightRangeGroup2 = new HighlightRangeGroup(new StaticRange({startContainer: textElement1, startOffset: 10, endContainer: textElement2, endOffset: 4}));
+ highlightRangeGroup2.add(new StaticRange({startContainer: textElement2, startOffset: 10, endContainer: textElement3, endOffset: 5}));
+
+ let highlightRangeGroup3 = new HighlightRangeGroup(new StaticRange({startContainer: textElement3, startOffset: 10, endContainer: textElement5, endOffset: 12}));
+
+ CSS.highlights.set("example-highlight1", highlightRangeGroup1);
+ CSS.highlights.set("example-highlight2", highlightRangeGroup2);
+ CSS.highlights.set("example-highlight3", highlightRangeGroup3);
+ </script>
+</body>
+</html>
Added: trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-cascade-expected.html (0 => 253857)
--- trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-cascade-expected.html (rev 0)
+++ trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-cascade-expected.html 2019-12-21 01:33:10 UTC (rev 253857)
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <style>
+ #style1 {
+ background-color: yellow;
+ color:green;
+ }
+ #style2 {
+ background-color: blue;
+ color:red;
+ }
+ #style3 {
+ background-color: purple;
+ color:pink;
+ }
+ </style>
+</head>
+<body>
+ <div id="out"><span id="text1"><span id="style1">One</span> two three</span></div>
+ <div id="scoped"><span id="text2">four <span id="style2">five</span> six</span></div>
+ <span id="text3">seven eight nine</span>
+</body>
+</html>
Added: trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-cascade.html (0 => 253857)
--- trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-cascade.html (rev 0)
+++ trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-cascade.html 2019-12-21 01:33:10 UTC (rev 253857)
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Multiple custom highlight pseudo elements.</title>
+ <link rel="help" href=""
+ <link rel="match" href=""
+ <metad name="assert" content="Multiple highlights should be able to be specified.">
+ <style>
+ #out::highlight(example-highlight) {
+ background-color: yellow;
+ color:green;
+ }
+ #scoped::highlight(example-highlight) {
+ background-color: blue;
+ color:red;
+ }
+ </style>
+</head>
+<body>
+ <div id="out"><span id="text1">One two three</span></div>
+ <div id="scoped"><span id="text2">four five six</span></div>
+ <span id="text3">seven eight nine</span>
+
+ <script>
+ let textElement1 = document.getElementById('text1');
+ let textElement2 = document.getElementById('text2');
+ let textElement3 = document.getElementById('text3');
+ let highlightRangeGroup = new HighlightRangeGroup(new StaticRange({startContainer: textElement1, startOffset: 0, endContainer: textElement1, endOffset: 3}));
+ highlightRangeGroup.add(new StaticRange({startContainer: textElement2, startOffset: 5, endContainer: textElement2, endOffset: 9}));
+
+ CSS.highlights.set("example-highlight", highlightRangeGroup);
+ </script>
+</body>
+</html>
Added: trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-expected.html (0 => 253857)
--- trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-expected.html (rev 0)
+++ trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-expected.html 2019-12-21 01:33:10 UTC (rev 253857)
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <style>
+ #style1 {
+ background-color: yellow;
+ color:green;
+ }
+ #style2 {
+ background-color: blue;
+ color:red;
+ }
+ #style3 {
+ background-color: purple;
+ color:pink;
+ }
+ </style>
+</head>
+<body>
+ O<span id="style1">n</span>e<span id="style2"> </span>t<span id="style2">w</span>o<span id="style3"> </span>t<span id="style3">h</span>re<span id="style3">e</span>
+</body>
+</html>
Added: trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-replace-expected.html (0 => 253857)
--- trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-replace-expected.html (rev 0)
+++ trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-replace-expected.html 2019-12-21 01:33:10 UTC (rev 253857)
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <style>
+ #highlight {
+ background-color: yellow;
+ color:green;
+ }
+ </style>
+</head>
+<body>
+ One<span id="highlight"> </span>t<span id="highlight">w</span>o three
+</body>
+</html>
Added: trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-replace.html (0 => 253857)
--- trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-replace.html (rev 0)
+++ trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text-replace.html 2019-12-21 01:33:10 UTC (rev 253857)
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Multiple custom highlight pseudo elements.</title>
+ <link rel="help" href=""
+ <link rel="match" href=""
+ <meta name="assert" content="Multiple highlights should be able to be specified.">
+ <style>
+ ::highlight(example-highlight) {
+ background-color: yellow;
+ color:green;
+ }
+ </style>
+</head>
+<body>
+ <span id="text1">One two three</span>
+
+ <script>
+ let textElement = document.getElementById('text1');
+ let highlightRangeGroup1 = new HighlightRangeGroup(new StaticRange({startContainer: textElement, startOffset: 1, endContainer: textElement, endOffset: 2}));
+
+ let highlightRangeGroup2 = new HighlightRangeGroup(new StaticRange({startContainer: textElement, startOffset: 3, endContainer: textElement, endOffset: 4}));
+ highlightRangeGroup2.add(new StaticRange({startContainer: textElement, startOffset: 5, endContainer: textElement, endOffset: 6}));
+
+ CSS.highlights.set("example-highlight", highlightRangeGroup1);
+ CSS.highlights.set("example-highlight", highlightRangeGroup2);
+ </script>
+</body>
+</html>
Added: trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text.html (0 => 253857)
--- trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text.html (rev 0)
+++ trunk/LayoutTests/http/wpt/css/css-highlight-api/highlight-text.html 2019-12-21 01:33:10 UTC (rev 253857)
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Multiple custom highlight pseudo elements.</title>
+ <link rel="help" href=""
+ <link rel="match" href=""
+ <meta name="assert" content="Multiple highlights should be able to be specified.">
+ <style>
+ ::highlight(example-highlight1) {
+ background-color: yellow;
+ color:green;
+ }
+ ::highlight(example-highlight2) {
+ background-color: blue;
+ color:red;
+ }
+ ::highlight(example-highlight3) {
+ background-color: purple;
+ color:pink;
+ }
+ </style>
+</head>
+<body>
+ <span id="text1">One two three</span>
+
+ <script>
+ let textElement = document.getElementById('text1');
+ let highlightRangeGroup1 = new HighlightRangeGroup(new StaticRange({startContainer: textElement, startOffset: 1, endContainer: textElement, endOffset: 2}));
+
+ let highlightRangeGroup2 = new HighlightRangeGroup(new StaticRange({startContainer: textElement, startOffset: 3, endContainer: textElement, endOffset: 4}));
+ highlightRangeGroup2.add(new StaticRange({startContainer: textElement, startOffset: 5, endContainer: textElement, endOffset: 6}));
+
+ let highlightRangeGroup3 = new HighlightRangeGroup(new StaticRange({startContainer: textElement, startOffset: 7, endContainer: textElement, endOffset: 8}));
+ highlightRangeGroup3.add(new StaticRange({startContainer: textElement, startOffset: 9, endContainer: textElement, endOffset: 10}));
+ highlightRangeGroup3.add(new StaticRange({startContainer: textElement, startOffset: 12, endContainer: textElement, endOffset: 13}));
+
+
+ CSS.highlights.set("example-highlight1", highlightRangeGroup1);
+ CSS.highlights.set("example-highlight2", highlightRangeGroup2);
+ CSS.highlights.set("example-highlight3", highlightRangeGroup3);
+ </script>
+</body>
+</html>
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (253856 => 253857)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2019-12-21 01:13:54 UTC (rev 253856)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2019-12-21 01:33:10 UTC (rev 253857)
@@ -1,3 +1,15 @@
+2019-12-20 Megan Gardner <[email protected]>
+
+ Paint highlights specified in CSS Highlight API
+ https://bugs.webkit.org/show_bug.cgi?id=205318
+
+ Reviewed by Ryosuke Niwa.
+
+ * web-platform-tests/css/css-highlight-api/highlight-text-across-elements-expected.html: Added.
+ * web-platform-tests/css/css-highlight-api/highlight-text-across-elements.html: Added.
+ * web-platform-tests/css/css-highlight-api/highlight-text-expected.html: Added.
+ * web-platform-tests/css/css-highlight-api/highlight-text.html: Added.
+
2019-12-20 Chris Dumez <[email protected]>
[Bindings] Add @@toStringTag to our iterator prototype object
Modified: trunk/Source/WebCore/ChangeLog (253856 => 253857)
--- trunk/Source/WebCore/ChangeLog 2019-12-21 01:13:54 UTC (rev 253856)
+++ trunk/Source/WebCore/ChangeLog 2019-12-21 01:33:10 UTC (rev 253857)
@@ -1,3 +1,52 @@
+2019-12-20 Megan Gardner <[email protected]>
+
+ Paint highlights specified in CSS Highlight API
+ https://bugs.webkit.org/show_bug.cgi?id=205318
+
+ Reviewed by Ryosuke Niwa.
+
+ Render highlights when present, similar to the way we render selection.
+
+ Tests: imported/w3c/web-platform-tests/css/css-highlight-api/highlight-text-across-elements.html
+ imported/w3c/web-platform-tests/css/css-highlight-api/highlight-text.html
+
+ * Modules/highlight/HighlightMap.h:
+ (WebCore::HighlightMap::map const):
+
+ Add a getter for the internal HashMap.
+
+ * rendering/InlineTextBox.cpp:
+ (WebCore::InlineTextBox::selectionState):
+ (WebCore::InlineTextBox::verifySelectionState const):
+ (WebCore::InlineTextBox::paint):
+ (WebCore::InlineTextBox::clampedStartEndForState const):
+ (WebCore::InlineTextBox::selectionStartEnd const):
+ (WebCore::InlineTextBox::highlightStartEnd const):
+ (WebCore::InlineTextBox::resolveStyleForMarkedText):
+
+ Use the highlight name from the HighlightRangeGroup to obtain the style from the renderer.
+
+ (WebCore::InlineTextBox::collectMarkedTextsForHighlights const):
+
+ Render the highlights when painting text. Determine if a highlight is present in the current RenderObject, and
+ add additional MarkedText to be rendered when painting
+
+ * rendering/InlineTextBox.h:
+ * rendering/MarkedText.cpp:
+ (WebCore::subdivide):
+ * rendering/MarkedText.h:
+ (WebCore::MarkedText::operator== const):
+
+ Expand MarkedText to take a style name.
+
+ * rendering/SelectionRangeData.cpp:
+ (WebCore::SelectionRangeData::setContext):
+ (WebCore::SelectionRangeData::selectionStateForRenderer):
+ (WebCore::SelectionRangeData::set):
+ * rendering/SelectionRangeData.h:
+
+ Leverage SelectionRangeData for highlights.
+
2019-12-20 Chris Dumez <[email protected]>
[iOS Debug] imported/w3c/web-platform-tests/html/dom/usvstring-reflection.https.html is crashing
Modified: trunk/Source/WebCore/Modules/highlight/HighlightMap.h (253856 => 253857)
--- trunk/Source/WebCore/Modules/highlight/HighlightMap.h 2019-12-21 01:13:54 UTC (rev 253856)
+++ trunk/Source/WebCore/Modules/highlight/HighlightMap.h 2019-12-21 01:33:10 UTC (rev 253857)
@@ -45,6 +45,7 @@
bool remove(const String&);
RefPtr<HighlightRangeGroup> getGroupForKey(const String& key);
+ const HashMap<String, Ref<HighlightRangeGroup>>& map() const { return m_map; }
private:
HighlightMap() = default;
Modified: trunk/Source/WebCore/dom/Document.cpp (253856 => 253857)
--- trunk/Source/WebCore/dom/Document.cpp 2019-12-21 01:13:54 UTC (rev 253856)
+++ trunk/Source/WebCore/dom/Document.cpp 2019-12-21 01:33:10 UTC (rev 253857)
@@ -779,6 +779,9 @@
accessSVGExtensions().pauseAnimations();
clearScriptedAnimationController();
+
+ if (m_highlightMap)
+ m_highlightMap->clear();
m_pendingScrollEventTargetList = nullptr;
}
Modified: trunk/Source/WebCore/rendering/InlineTextBox.cpp (253856 => 253857)
--- trunk/Source/WebCore/rendering/InlineTextBox.cpp 2019-12-21 01:13:54 UTC (rev 253856)
+++ trunk/Source/WebCore/rendering/InlineTextBox.cpp 2019-12-21 01:33:10 UTC (rev 253857)
@@ -28,10 +28,12 @@
#include "Document.h"
#include "DocumentMarkerController.h"
#include "Editor.h"
+#include "ElementRuleCollector.h"
#include "EllipsisBox.h"
#include "EventRegion.h"
#include "Frame.h"
#include "GraphicsContext.h"
+#include "HighlightMap.h"
#include "HitTestResult.h"
#include "ImageBuffer.h"
#include "InlineTextBoxStyle.h"
@@ -46,6 +48,8 @@
#include "RenderTheme.h"
#include "RenderView.h"
#include "RenderedDocumentMarker.h"
+#include "RuntimeEnabledFeatures.h"
+#include "SelectionRangeData.h"
#include "Text.h"
#include "TextDecorationPainter.h"
#include "TextPaintStyle.h"
@@ -152,9 +156,33 @@
RenderObject::SelectionState InlineTextBox::selectionState()
{
- RenderObject::SelectionState state = renderer().selectionState();
+ auto state = verifySelectionState(renderer().selectionState(), renderer().view().selection());
+
+ // FIXME: this code mutates selection state, but it's used at a simple getter elsewhere
+ // in this file. This code should likely live in SelectionRangeData, 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()) {
+ EllipsisBox* ellipsis = root().ellipsisBox();
+ if (state != RenderObject::SelectionNone) {
+ 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::SelectionInside : RenderObject::SelectionNone);
+ } else
+ ellipsis->setSelectionState(RenderObject::SelectionNone);
+ }
+
+ return state;
+}
+
+RenderObject::SelectionState InlineTextBox::verifySelectionState(RenderObject::SelectionState state, SelectionRangeData& selection) const
+{
if (state == RenderObject::SelectionStart || state == RenderObject::SelectionEnd || state == RenderObject::SelectionBoth) {
- auto& selection = renderer().view().selection();
auto startPos = selection.startPosition();
auto endPos = selection.endPosition();
// The position after a hard line break is considered to be past its end.
@@ -176,21 +204,6 @@
state = RenderObject::SelectionNone;
}
- // If there are ellipsis following, make sure their selection is updated.
- if (m_truncation != cNoTruncation && root().ellipsisBox()) {
- EllipsisBox* ellipsis = root().ellipsisBox();
- if (state != RenderObject::SelectionNone) {
- 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::SelectionInside : RenderObject::SelectionNone);
- } else
- ellipsis->setSelectionState(RenderObject::SelectionNone);
- }
-
return state;
}
@@ -524,6 +537,9 @@
paintCompositionBackground(paintInfo, boxOrigin);
Vector<MarkedText> markedTexts = collectMarkedTextsForDocumentMarkers(TextPaintPhase::Background);
+ auto highlightMarkedTexts = collectMarkedTextsForHighlights(TextPaintPhase::Background);
+ if (!highlightMarkedTexts.isEmpty())
+ markedTexts.appendVector(WTFMove(highlightMarkedTexts));
#if ENABLE(TEXT_SELECTION)
if (haveSelection && !useCustomUnderlines && !context.paintingDisabled()) {
auto selectionMarkedText = createMarkedTextFromSelectionInBox(*this);
@@ -557,6 +573,9 @@
markedTexts.append({ clampedOffset(m_start), clampedOffset(end()), MarkedText::Unmarked });
if (!isPrinting) {
markedTexts.appendVector(collectMarkedTextsForDocumentMarkers(TextPaintPhase::Foreground));
+ auto highlightMarkedTexts = collectMarkedTextsForHighlights(TextPaintPhase::Foreground);
+ if (!highlightMarkedTexts.isEmpty())
+ markedTexts.appendVector(WTFMove(highlightMarkedTexts));
bool shouldPaintDraggedContent = !(paintInfo.paintBehavior.contains(PaintBehavior::ExcludeSelection));
if (shouldPaintDraggedContent) {
@@ -652,14 +671,11 @@
return offset;
}
-std::pair<unsigned, unsigned> InlineTextBox::selectionStartEnd() const
+std::pair<unsigned, unsigned> InlineTextBox::clampedStartEndForState(unsigned start, unsigned end, RenderObject::SelectionState selectionState) const
{
- auto selectionState = renderer().selectionState();
if (selectionState == RenderObject::SelectionInside)
return { 0, clampedOffset(m_start + m_len) };
- auto start = renderer().view().selection().startPosition();
- auto end = renderer().view().selection().endPosition();
if (selectionState == RenderObject::SelectionStart)
end = renderer().text().length();
else if (selectionState == RenderObject::SelectionEnd)
@@ -667,6 +683,24 @@
return { clampedOffset(start), clampedOffset(end) };
}
+std::pair<unsigned, unsigned> InlineTextBox::selectionStartEnd() const
+{
+ auto selectionState = renderer().selectionState();
+
+ return clampedStartEndForState(renderer().view().selection().startPosition(), renderer().view().selection().endPosition(), selectionState);
+}
+
+std::pair<unsigned, unsigned> InlineTextBox::highlightStartEnd(SelectionRangeData &rangeData) const
+{
+ auto state = rangeData.selectionStateForRenderer(renderer());
+ state = verifySelectionState(state, rangeData);
+
+ if (state == RenderObject::SelectionNone)
+ return {0, 0};
+
+ return clampedStartEndForState(rangeData.startPosition(), rangeData.endPosition(), state);
+}
+
bool InlineTextBox::hasMarkers() const
{
return collectMarkedTextsForDocumentMarkers(TextPaintPhase::Decoration).size();
@@ -770,6 +804,22 @@
case MarkedText::SpellingError:
case MarkedText::Unmarked:
break;
+ case MarkedText::Highlight:
+ if (auto renderStyle = parent()->renderer().getUncachedPseudoStyle({ PseudoId::Highlight, markedText.highlightName }, &parent()->renderer().style())) {
+ style.backgroundColor = renderStyle->backgroundColor();
+ style.textStyles.fillColor = renderStyle->computedStrokeColor();
+ style.textStyles.strokeColor = renderStyle->computedStrokeColor();
+
+ auto color = renderStyle->visitedDependentColorWithColorFilter(CSSPropertyWebkitTextFillColor);
+ auto decorationStyle = renderStyle->textDecorationStyle();
+ auto decorations = renderStyle->textDecorationsInEffect();
+
+ if (decorations.containsAny({ TextDecoration::Underline, TextDecoration::Overline, TextDecoration::LineThrough })) {
+ style.textDecorationStyles.underlineColor = color;
+ style.textDecorationStyles.underlineStyle = decorationStyle;
+ }
+ }
+ break;
case MarkedText::DraggedContent:
style.alpha = 0.25;
break;
@@ -963,6 +1013,46 @@
return markedTexts;
}
+
+Vector<MarkedText> InlineTextBox::collectMarkedTextsForHighlights(TextPaintPhase phase) const
+{
+ if (!RuntimeEnabledFeatures::sharedFeatures().highlightAPIEnabled())
+ return { };
+ ASSERT_ARG(phase, phase == TextPaintPhase::Background || phase == TextPaintPhase::Foreground || phase == TextPaintPhase::Decoration);
+ UNUSED_PARAM(phase);
+ if (!renderer().textNode())
+ return { };
+
+ Vector<MarkedText> markedTexts;
+ auto& parentRenderer = parent()->renderer();
+ auto& parentStyle = parentRenderer.style();
+ for (auto& [highlightKey, highlightGroup] : renderer().document().highlightMap().map()) {
+ auto renderStyle = parentRenderer.getUncachedPseudoStyle({ PseudoId::Highlight, highlightKey }, &parentStyle);
+ if (!renderStyle)
+ continue;
+ for (auto& staticRange : highlightGroup->ranges()) {
+ Position startPos = createLegacyEditingPosition(staticRange->startContainer(), staticRange->startOffset());
+ Position endPos = createLegacyEditingPosition(staticRange->endContainer(), staticRange->endOffset());
+
+ if (startPos.isNotNull() && endPos.isNotNull()) {
+ RenderObject* startRenderer = startPos.deprecatedNode()->renderer();
+ int startOffset = startPos.deprecatedEditingOffset();
+ RenderObject* endRenderer = endPos.deprecatedNode()->renderer();
+ int endOffset = endPos.deprecatedEditingOffset();
+ ASSERT(startOffset >= 0 && endOffset >= 0);
+ if (!startRenderer || !endRenderer)
+ continue;
+ auto highlightData = SelectionRangeData(renderer().view());
+ highlightData.setContext({startRenderer, endRenderer, static_cast<unsigned>(startOffset), static_cast<unsigned>(endOffset)});
+ auto [highlightStart, highlightEnd] = highlightStartEnd(highlightData);
+ if (highlightStart < highlightEnd)
+ markedTexts.append({ highlightStart, highlightEnd, MarkedText::Highlight, nullptr, highlightKey });
+ }
+ }
+ }
+ return markedTexts;
+}
+
FloatPoint InlineTextBox::textOriginFromBoxRect(const FloatRect& boxRect) const
{
FloatPoint textOrigin { boxRect.x(), boxRect.y() + lineFont().fontMetrics().ascent() };
Modified: trunk/Source/WebCore/rendering/InlineTextBox.h (253856 => 253857)
--- trunk/Source/WebCore/rendering/InlineTextBox.h 2019-12-21 01:13:54 UTC (rev 253856)
+++ trunk/Source/WebCore/rendering/InlineTextBox.h 2019-12-21 01:33:10 UTC (rev 253857)
@@ -121,6 +121,7 @@
virtual LayoutRect localSelectionRect(unsigned startPos, unsigned endPos) const;
bool isSelected(unsigned startPosition, unsigned endPosition) const;
std::pair<unsigned, unsigned> selectionStartEnd() const;
+ std::pair<unsigned, unsigned> highlightStartEnd(SelectionRangeData&) const;
protected:
void paint(PaintInfo&, const LayoutPoint&, LayoutUnit lineTop, LayoutUnit lineBottom) override;
@@ -132,6 +133,9 @@
void deleteLine() final;
void extractLine() final;
void attachLine() final;
+
+ RenderObject::SelectionState verifySelectionState(RenderObject::SelectionState, SelectionRangeData&) const;
+ std::pair<unsigned, unsigned> clampedStartEndForState(unsigned, unsigned, RenderObject::SelectionState) const;
public:
RenderObject::SelectionState selectionState() final;
@@ -169,6 +173,7 @@
Vector<MarkedText> collectMarkedTextsForDraggedContent();
Vector<MarkedText> collectMarkedTextsForDocumentMarkers(TextPaintPhase) const;
+ Vector<MarkedText> collectMarkedTextsForHighlights(TextPaintPhase) const;
MarkedTextStyle computeStyleForUnmarkedMarkedText(const PaintInfo&) const;
StyledMarkedText resolveStyleForMarkedText(const MarkedText&, const MarkedTextStyle& baseStyle, const PaintInfo&);
Modified: trunk/Source/WebCore/rendering/MarkedText.cpp (253856 => 253857)
--- trunk/Source/WebCore/rendering/MarkedText.cpp 2019-12-21 01:13:54 UTC (rev 253856)
+++ trunk/Source/WebCore/rendering/MarkedText.cpp 2019-12-21 01:33:10 UTC (rev 253857)
@@ -74,12 +74,12 @@
frontmost = j;
}
if (frontmost)
- result.append({ offsetSoFar, offsets[i].value, offsets[*frontmost].markedText->type, offsets[*frontmost].markedText->marker });
+ result.append({ offsetSoFar, offsets[i].value, offsets[*frontmost].markedText->type, offsets[*frontmost].markedText->marker, offsets[*frontmost].markedText->highlightName });
} else {
// The appended marked texts may not be in paint order. We will fix this up at the end of this function.
for (unsigned j = 0; j < i; ++j) {
if (!processedMarkedTexts.contains(offsets[j].markedText))
- result.append({ offsetSoFar, offsets[i].value, offsets[j].markedText->type, offsets[j].markedText->marker });
+ result.append({ offsetSoFar, offsets[i].value, offsets[j].markedText->type, offsets[j].markedText->marker, offsets[j].markedText->highlightName });
}
}
offsetSoFar = offsets[i].value;
Modified: trunk/Source/WebCore/rendering/MarkedText.h (253856 => 253857)
--- trunk/Source/WebCore/rendering/MarkedText.h 2019-12-21 01:13:54 UTC (rev 253856)
+++ trunk/Source/WebCore/rendering/MarkedText.h 2019-12-21 01:33:10 UTC (rev 253857)
@@ -26,6 +26,7 @@
#pragma once
#include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
namespace WebCore {
@@ -40,6 +41,7 @@
SpellingError,
TextMatch,
DictationAlternatives,
+ Highlight,
#if PLATFORM(IOS_FAMILY)
// FIXME: See <rdar://problem/8933352>. Also, remove the PLATFORM(IOS_FAMILY)-guard.
DictationPhraseWithAlternatives,
@@ -51,12 +53,13 @@
unsigned endOffset;
Type type;
const RenderedDocumentMarker* marker { nullptr };
+ String highlightName { };
bool isEmpty() const { return endOffset <= startOffset; }
bool operator!=(const MarkedText& other) const { return !(*this == other); }
bool operator==(const MarkedText& other) const
{
- return startOffset == other.startOffset && endOffset == other.endOffset && type == other.type && marker == other.marker;
+ return startOffset == other.startOffset && endOffset == other.endOffset && type == other.type && marker == other.marker && highlightName == other.highlightName;
}
};
Modified: trunk/Source/WebCore/rendering/SelectionRangeData.cpp (253856 => 253857)
--- trunk/Source/WebCore/rendering/SelectionRangeData.cpp 2019-12-21 01:13:54 UTC (rev 253856)
+++ trunk/Source/WebCore/rendering/SelectionRangeData.cpp 2019-12-21 01:33:10 UTC (rev 253857)
@@ -154,10 +154,47 @@
{
}
+void SelectionRangeData::setContext(const Context& context)
+{
+ ASSERT(context.start() && context.end());
+ m_selectionContext = context;
+}
+
+RenderObject::SelectionState SelectionRangeData::selectionStateForRenderer(RenderObject& renderer)
+{
+ // FIXME: we shouldln't have to check that a renderer is a descendant of the render node
+ // from the range. This is likely because we aren't using VisiblePositions yet.
+ // Planned fix in a followup: <rdar://problem/58095923>
+ // https://bugs.webkit.org/show_bug.cgi?id=205529
+
+ if (&renderer == m_selectionContext.start() || renderer.isDescendantOf(m_selectionContext.start())) {
+ if (m_selectionContext.start() && m_selectionContext.end() && m_selectionContext.start() == m_selectionContext.end())
+ return RenderObject::SelectionBoth;
+ if (m_selectionContext.start())
+ return RenderObject::SelectionStart;
+ }
+ if (&renderer == m_selectionContext.end() || renderer.isDescendantOf(m_selectionContext.end()))
+ return RenderObject::SelectionEnd;
+
+ RenderObject* selectionEnd = nullptr;
+ auto* selectionDataEnd = m_selectionContext.end();
+ if (selectionDataEnd)
+ selectionEnd = rendererAfterPosition(*selectionDataEnd, m_selectionContext.endPosition().value());
+ SelectionIterator selectionIterator(m_selectionContext.start());
+ for (auto* currentRenderer = m_selectionContext.start(); currentRenderer && currentRenderer != m_selectionContext.end(); currentRenderer = selectionIterator.next()) {
+ if (currentRenderer == m_selectionContext.start() || currentRenderer == m_selectionContext.end())
+ continue;
+ if (!currentRenderer->canBeSelectionLeaf())
+ continue;
+ if (&renderer == currentRenderer)
+ return RenderObject::SelectionInside;
+ }
+ return RenderObject::SelectionNone;
+
+}
+
void SelectionRangeData::set(const Context& selection, RepaintMode blockRepaintMode)
{
- // Make sure both our start and end objects are defined.
- // Check www.msnbc.com and try clicking around to find the case where this happened.
if ((selection.start() && !selection.end()) || (selection.end() && !selection.start()))
return;
// Just return if the selection hasn't changed.
Modified: trunk/Source/WebCore/rendering/SelectionRangeData.h (253856 => 253857)
--- trunk/Source/WebCore/rendering/SelectionRangeData.h 2019-12-21 01:13:54 UTC (rev 253856)
+++ trunk/Source/WebCore/rendering/SelectionRangeData.h 2019-12-21 01:33:10 UTC (rev 253857)
@@ -71,7 +71,9 @@
Optional<unsigned> m_startPosition;
Optional<unsigned> m_endPosition;
};
-
+
+ void setContext(const Context&);
+
enum class RepaintMode { NewXOROld, NewMinusOld, Nothing };
void set(const Context&, RepaintMode = RepaintMode::NewXOROld);
const Context& get() const { return m_selectionContext; }
@@ -86,6 +88,8 @@
IntRect bounds() const { return collectBounds(ClipToVisibleContent::No); }
IntRect boundsClippedToVisibleContent() const { return collectBounds(ClipToVisibleContent::Yes); }
void repaint() const;
+
+ RenderObject::SelectionState selectionStateForRenderer(RenderObject&);
private:
enum class ClipToVisibleContent { Yes, No };
Modified: trunk/Tools/ChangeLog (253856 => 253857)
--- trunk/Tools/ChangeLog 2019-12-21 01:13:54 UTC (rev 253856)
+++ trunk/Tools/ChangeLog 2019-12-21 01:33:10 UTC (rev 253857)
@@ -1,3 +1,15 @@
+2019-12-20 Megan Gardner <[email protected]>
+
+ Paint highlights specified in CSS Highlight API
+ https://bugs.webkit.org/show_bug.cgi?id=205318
+
+ Reviewed by Ryosuke Niwa.
+
+ Expand MarkedText to take a style name.
+
+ * TestWebKitAPI/Tests/WebCore/MarkedText.cpp:
+ (WebCore::operator<<):
+
2019-12-20 Jonathan Bedard <[email protected]>
lldbwebkittester: Strip CLANG_DEBUG_INFORMATION_LEVEL option while building
Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/MarkedText.cpp (253856 => 253857)
--- trunk/Tools/TestWebKitAPI/Tests/WebCore/MarkedText.cpp 2019-12-21 01:13:54 UTC (rev 253856)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/MarkedText.cpp 2019-12-21 01:33:10 UTC (rev 253857)
@@ -55,6 +55,8 @@
return os << "SpellingError";
case MarkedText::TextMatch:
return os << "TextMatch";
+ case MarkedText::Highlight:
+ return os << "Highlight";
case MarkedText::Unmarked:
return os << "Unmarked";
}