WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
bug-231410-20211013150431.patch (text/plain), 16.38 KB, created by
Megan Gardner
on 2021-10-13 15:04:32 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Megan Gardner
Created:
2021-10-13 15:04:32 PDT
Size:
16.38 KB
patch
obsolete
>Subversion Revision: 284060 >diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog >index eb01bff905c5e1fedce55dfc7a5e0f18df0aeef4..bb7a236b2db8241e18a6b72eeb969b89a0f0ea45 100644 >--- a/Source/WTF/ChangeLog >+++ b/Source/WTF/ChangeLog >@@ -1,3 +1,15 @@ >+2021-10-13 Megan Gardner <megan_gardner@apple.com> >+ >+ Scroll To Text Fragment directive parsing >+ https://bugs.webkit.org/show_bug.cgi?id=231410 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Text directive parsing for >+ https://wicg.github.io/scroll-to-text-fragment/ >+ >+ * Scripts/Preferences/WebPreferencesExperimental.yaml: >+ > 2021-10-12 Sihui Liu <sihui_liu@apple.com> > > Implement FileSystemSyncAccessHandle read() and write() >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 1207d8c55a45098c46940b3b4f5566c62bc76efa..3b639ddbdff61f57ff46ff59805924eb47bf244a 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,37 @@ >+2021-10-13 Megan Gardner <megan_gardner@apple.com> >+ >+ Scroll To Text Fragment directive parsing >+ https://bugs.webkit.org/show_bug.cgi?id=231410 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Text directive parsing for >+ https://wicg.github.io/scroll-to-text-fragment/ >+ >+ Make a new class to handle the parsing of the text directive. >+ The parsing is defined in the linked spec. >+ The directive should be stored on Document and in a future >+ patch the matching algorithm will find the text and scroll >+ and highlight it. >+ >+ * Sources.txt: >+ * WebCore.xcodeproj/project.pbxproj: >+ * dom/Document.h: >+ (WebCore::Document::setFragmentDirective): >+ (WebCore::Document::fragmentDirective const): >+ * dom/FragmentDirectiveParser.cpp: Added. >+ (WebCore::FragmentDirectiveParser::create): >+ (WebCore::FragmentDirectiveParser::FragmentDirectiveParser): >+ (WebCore::FragmentDirectiveParser::parseFragmentDirective): >+ * dom/FragmentDirectiveParser.h: Added. >+ (WebCore::FragmentDirectiveParser::parsedTextDirectives): >+ (WebCore::FragmentDirectiveParser::fragmentDirective): >+ (WebCore::FragmentDirectiveParser::urlFragment): >+ (WebCore::FragmentDirectiveParser::isValid): >+ * page/FrameView.cpp: >+ (WebCore::FrameView::scrollToFragment): >+ * platform/Logging.h: >+ > 2021-10-12 Alan Bujtas <zalan@apple.com> > > [LFC][IFC] LazyLineBreakIterator should be correctly setup for the prior context case >diff --git a/Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml b/Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml >index 6a9e707f676f0dd15010ba637b75bd6813e579e3..eb39adff418a315d288b8e40a09d8fcd4c0053ba 100644 >--- a/Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml >+++ b/Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml >@@ -1149,6 +1149,18 @@ ScreenCaptureEnabled: > default: false > WebCore: > default: false >+ >+ScrollToTextFragmentEnabled: >+ type: bool >+ humanReadableName: "Scroll To Text Fragment" >+ humanReadableDescription: "Enable Scroll To Text Fragment" >+ defaultValue: >+ WebKitLegacy: >+ default: false >+ WebKit: >+ default: false >+ WebCore: >+ default: false > > ServerTimingEnabled: > type: bool >diff --git a/Source/WebCore/Sources.txt b/Source/WebCore/Sources.txt >index 528eceb1d3923a014d7f15159c6b7f353fb349fb..46859934f62382ac6525aaccc463db3a2adc4702 100644 >--- a/Source/WebCore/Sources.txt >+++ b/Source/WebCore/Sources.txt >@@ -921,6 +921,7 @@ dom/ExceptionData.cpp > dom/ExtensionStyleSheets.cpp > dom/FocusEvent.cpp > dom/FormDataEvent.cpp >+dom/FragmentDirectiveParser.cpp > dom/FullscreenManager.cpp > dom/GCReachableRef.cpp > dom/HashChangeEvent.cpp >diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >index 59d6eef710b39c28ac14b27f53190c52e84c9307..9ca014468ef9ec525241b130009b119dbb2f972f 100644 >--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj >+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >@@ -8436,6 +8436,8 @@ > 443F04260E75C8FB007E5407 /* NetworkStateNotifierIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetworkStateNotifierIOS.mm; sourceTree = "<group>"; }; > 444D4E210F708B2E003158E0 /* WebCoreURLResponseIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreURLResponseIOS.mm; sourceTree = "<group>"; }; > 445210DD25D61EFF003A2ED8 /* AppHighlight.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppHighlight.h; sourceTree = "<group>"; }; >+ 445612AA270F6F3700758C97 /* FragmentDirectiveParser.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FragmentDirectiveParser.cpp; sourceTree = "<group>"; }; >+ 445612AB270F6F3800758C97 /* FragmentDirectiveParser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FragmentDirectiveParser.h; sourceTree = "<group>"; }; > 445775E420472F73008DCE5D /* LocalDefaultSystemAppearance.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LocalDefaultSystemAppearance.h; sourceTree = "<group>"; }; > 445775E92047303B008DCE5D /* LocalDefaultSystemAppearance.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalDefaultSystemAppearance.mm; sourceTree = "<group>"; }; > 446DC64624A29D9B0061F390 /* PlaybackTargetClientContextIdentifier.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PlaybackTargetClientContextIdentifier.h; sourceTree = "<group>"; }; >@@ -30679,6 +30681,8 @@ > 2A66439126A006AF00C147A1 /* FormDataEvent.cpp */, > 2A66439026A006AF00C147A1 /* FormDataEvent.h */, > 2A66438E26A006AE00C147A1 /* FormDataEvent.idl */, >+ 445612AA270F6F3700758C97 /* FragmentDirectiveParser.cpp */, >+ 445612AB270F6F3800758C97 /* FragmentDirectiveParser.h */, > A853123C11D0471B00D4D077 /* FragmentScriptingPermission.h */, > CD92F5172261038200F87BB3 /* FullscreenManager.cpp */, > CD92F5162261038200F87BB3 /* FullscreenManager.h */, >diff --git a/Source/WebCore/dom/Document.h b/Source/WebCore/dom/Document.h >index a2254d158e4396aa917b256b760241df00f66d7b..434c52d91f6718d6d2ef97ff2c6b9f6fbd89125c 100644 >--- a/Source/WebCore/dom/Document.h >+++ b/Source/WebCore/dom/Document.h >@@ -1631,6 +1631,9 @@ public: > const Editor& editor() const { return m_editor; } > FrameSelection& selection() { return m_selection; } > const FrameSelection& selection() const { return m_selection; } >+ >+ void setFragmentDirective(String& fragmentDirective) { m_fragmentDirective = fragmentDirective; } >+ const String& fragmentDirective() const { return m_fragmentDirective; } > > void prepareCanvasesForDisplayIfNeeded(); > void clearCanvasPreparation(HTMLCanvasElement&); >@@ -2226,6 +2229,8 @@ private: > > UniqueRef<Editor> m_editor; > UniqueRef<FrameSelection> m_selection; >+ >+ String m_fragmentDirective; > > ListHashSet<Ref<Element>> m_topLayerElements; > UniqueRef<WhitespaceCache> m_whitespaceCache; >diff --git a/Source/WebCore/dom/FragmentDirectiveParser.cpp b/Source/WebCore/dom/FragmentDirectiveParser.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..ea1322f7d93191160952ce2600b638c96d1b8242 >--- /dev/null >+++ b/Source/WebCore/dom/FragmentDirectiveParser.cpp >@@ -0,0 +1,127 @@ >+/* >+ * Copyright (C) 2021 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+#include "FragmentDirectiveParser.h" >+ >+#include "Logging.h" >+#include <wtf/URL.h> >+#include <wtf/text/TextStream.h> >+ >+ >+namespace WebCore { >+ >+FragmentDirectiveParser::FragmentDirectiveParser(const URL& url) >+{ >+ ASCIILiteral fragmentDirectiveDelimiter = ":~:"_s; >+ auto fragmentIdentifier = url.fragmentIdentifier(); >+ >+ if (fragmentIdentifier.isEmpty()) { >+ m_remainingURLFragment = fragmentIdentifier; >+ return; >+ } >+ >+ auto fragmentDirectiveStart = fragmentIdentifier.find(StringView(fragmentDirectiveDelimiter)); >+ >+ if (fragmentDirectiveStart == notFound) { >+ m_remainingURLFragment = fragmentIdentifier; >+ return; >+ } >+ >+ auto fragmentDirective = fragmentIdentifier.substring(fragmentDirectiveStart + fragmentDirectiveDelimiter.length()); >+ >+ // FIXME: this needs to be set on the original URL >+ m_remainingURLFragment = fragmentIdentifier.left(fragmentDirectiveStart); >+ >+ parseFragmentDirective(fragmentDirective); >+ >+ m_fragmentDirective = fragmentDirective.toString(); >+ m_isValid = true; >+} >+ >+bool FragmentDirectiveParser::parseFragmentDirective(StringView fragmentDirective) >+{ >+ LOG_WITH_STREAM(TextFragment, stream << " parseFragmentDirective: "); >+ >+ Vector<ParsedTextDirective> parsedTextDirectives; >+ String textDirectivePrefix = "text="_s; >+ >+ auto directives = fragmentDirective.split('&'); >+ >+ LOG_WITH_STREAM(TextFragment, stream << " parseFragmentDirective: "); >+ >+ for (auto directive : directives) { >+ if (!directive.startsWith(textDirectivePrefix)) >+ continue; >+ >+ auto textDirective = directive.substring(textDirectivePrefix.length()); >+ >+ Deque<String> tokens; >+ for (auto token : textDirective.split(',')) >+ tokens.append(token.toString()); >+ // FIXME: add decoding for % encoded strings. >+ if (tokens.size() > 4 || tokens.size() < 1) { >+ LOG_WITH_STREAM(TextFragment, stream << " wrong number of tokens "); >+ continue; >+ } >+ for (auto& token : tokens) { >+ if (token.isEmpty()) { >+ LOG_WITH_STREAM(TextFragment, stream << " empty token "); >+ continue; >+ } >+ } >+ ParsedTextDirective parsedTextDirective; >+ >+ if (tokens.first().endsWith('-') && tokens.first().length() > 1) { >+ tokens.first().truncate(tokens.first().length() - 2); >+ parsedTextDirective.prefix = tokens.first(); >+ tokens.removeFirst(); >+ } >+ >+ if (tokens.last().startsWith('-') && tokens.last().length() > 1) { >+ tokens.last().remove(0); >+ parsedTextDirective.suffix = tokens.takeLast(); >+ } >+ >+ if (tokens.size() != 1 && tokens.size() != 2) { >+ LOG_WITH_STREAM(TextFragment, stream << " not enough tokens "); >+ continue; >+ } >+ >+ parsedTextDirective.textStart = tokens.first(); >+ >+ if (tokens.size() == 2) >+ parsedTextDirective.textEnd = tokens.last(); >+ >+ parsedTextDirectives.append(parsedTextDirective); >+ } >+ >+ m_parsedTextDirectives = parsedTextDirectives; >+ >+ return true; >+ >+} >+ >+} // namespace WebCore >diff --git a/Source/WebCore/dom/FragmentDirectiveParser.h b/Source/WebCore/dom/FragmentDirectiveParser.h >new file mode 100644 >index 0000000000000000000000000000000000000000..3b602827f5049352e9333bd44d8b35c614546705 >--- /dev/null >+++ b/Source/WebCore/dom/FragmentDirectiveParser.h >@@ -0,0 +1,58 @@ >+/* >+ * Copyright (C) 2021 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#pragma once >+ >+#include <wtf/Forward.h> >+ >+namespace WebCore { >+ >+struct ParsedTextDirective { >+ String textStart; >+ String textEnd; >+ String prefix; >+ String suffix; >+}; >+ >+class FragmentDirectiveParser { >+public: >+ explicit FragmentDirectiveParser(const URL&); >+ >+ const Vector<ParsedTextDirective>& parsedTextDirectives() const { return m_parsedTextDirectives; }; >+ StringView fragmentDirective() const { return m_fragmentDirective; }; >+ StringView remainingURLFragment() const { return m_remainingURLFragment; }; >+ bool isValid() const { return m_isValid; }; >+ >+private: >+ FragmentDirectiveParser() = delete; >+ bool parseFragmentDirective(StringView); >+ >+ Vector<ParsedTextDirective> m_parsedTextDirectives; >+ StringView m_remainingURLFragment; >+ StringView m_fragmentDirective; >+ bool m_isValid { false }; >+}; >+ >+} // namespace WebCore >diff --git a/Source/WebCore/page/FrameView.cpp b/Source/WebCore/page/FrameView.cpp >index 5da3004285711095d21e190c3c69512188255ee1..c128d140bd729257e83206e16d88c04c9b65a96f 100644 >--- a/Source/WebCore/page/FrameView.cpp >+++ b/Source/WebCore/page/FrameView.cpp >@@ -46,6 +46,7 @@ > #include "EventNames.h" > #include "FloatRect.h" > #include "FocusController.h" >+#include "FragmentDirectiveParser.h" > #include "Frame.h" > #include "FrameFlattening.h" > #include "FrameLoader.h" >@@ -2215,7 +2216,25 @@ void FrameView::restoreScrollbar() > > bool FrameView::scrollToFragment(const URL& url) > { >+ ASSERT(frame().document()); >+ Ref document = *frame().document(); >+ > auto fragmentIdentifier = url.fragmentIdentifier(); >+ >+ if (document->settings().scrollToTextFragmentEnabled()) { >+ FragmentDirectiveParser fragmentDirectiveParser(url); >+ >+ if (fragmentDirectiveParser.isValid()) { >+ auto fragmentDirective = fragmentDirectiveParser.fragmentDirective().toString(); >+ document->setFragmentDirective(fragmentDirective); >+ >+ auto parsedTextDirectives = fragmentDirectiveParser.parsedTextDirectives(); >+ // FIXME: Scroll to the range specified by the directive. >+ >+ } else >+ fragmentIdentifier = fragmentDirectiveParser.remainingURLFragment(); >+ } >+ > if (scrollToFragmentInternal(fragmentIdentifier)) > return true; > >diff --git a/Source/WebCore/platform/Logging.h b/Source/WebCore/platform/Logging.h >index 5cdd8b3b95f41a38b326cf097a9df369dda88be5..3fbe417be981b75e779de238fc4be05a6d730faa 100644 >--- a/Source/WebCore/platform/Logging.h >+++ b/Source/WebCore/platform/Logging.h >@@ -115,6 +115,7 @@ namespace WebCore { > M(StyleSheets) \ > M(SVG) \ > M(TextAutosizing) \ >+ M(TextFragment) \ > M(TextShaping) \ > M(Tiling) \ > M(Threading) \
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 231410
:
440570
|
440628
|
440632
|
440638
|
440658
|
440699
|
440823
|
440843
|
440874
|
440962
|
440975
|
440989
|
441016
|
441141
|
441148
|
441153
|
441170
|
443639
|
443645
|
443647