Stop using live ranges in DocumentMarkerController
https://bugs.webkit.org/show_bug.cgi?id=209985

Reviewed by Antti Koivisto.

Source/WebCore:

- Removed uses of live ranges from DocumentMarkerController.
- Removed "active/inactive text match marker", which was only ever used
  by Chromium, and has been dead code in WebKit for while now.
- Made a replacement for Range::absoluteTextQuads, in RenderObject,
  and moved all callers over.
- Added a fast path for Node::isCharacterDataNode that makes it work
  without a virtual function call for the common node types.
- Added a Node::length function that matches the DOM specification's
  definiton of a node's length, part of how ranges are defined.
- Added a structure OffsetRange to represent start/end offsets within
  a single character data node. This is a common idiom to handle possible
  partial selection of text nodes at the start and end of the range when
  iterating text within a range.
- Changed DocumentMarker functions to use OffsetRange.
- Added helper functions for turning a vector of quads into a vector
  of bounding box rectangles, and for computing a union of all the
  rectangles, since both of these are common coding patterns.
- Added an intersectingNodes function, producing a for-loop-compatible
  range for iterating all nodes covered by a DOM range.
- Changed RenderObject::SetLayoutNeededForbiddenScope so it can be used
  without an #if at each call site, expands to nothing in release builds.
- Eliminated uses of RetainPtr<id> instead of just id to pass arguments.

* dom/CharacterData.h: Updated since isCharacterDataNode is no longer a
virtual function.

* dom/Document.cpp:
(WebCore::Document::textInserted): Pass an OffsetRange to removeMarkers.
(WebCore::Document::textRemoved): Ditto.

* dom/DocumentMarker.h: Removed most platform-specific functions.
Removed the active match boolean, which was only ever used for Chromium.
Use OffsetRange. Updated some obsolete comments.

* dom/DocumentMarkerController.cpp: Removed include of "Range.h".
(WebCore::DocumentMarkerController::collectTextRanges): Change return value
to return a structure with a node and an offset range rather than using a
SimpleRange; adds clarity to the fact that it's guranteed to be only a
single node. May even want to consider some day moving TextIterator over
to this, but it's definitely better here for now.
(WebCore::DocumentMarkerController::addMarker): Updated for the change to
collectTextRanges and to DocumentMarker construction, and to use construction
syntax that doesn't repeat the DocumentMarker class name. Deleted overloads
that are no longer needed.
(WebCore::DocumentMarkerController::addMarkerToNode): Ditto.
(WebCore::DocumentMarkerController::addTextMatchMarker): Ditto.
(WebCore::DocumentMarkerController::addDictationPhraseWithAlternativesMarker): Deleted.
(WebCore::DocumentMarkerController::addDictationResultMarker): Deleted.
(WebCore::DocumentMarkerController::addDraggedContentMarker): Updated as above.
(WebCore::DocumentMarkerController::addPlatformTextCheckingMarker): Deleted.
(WebCore::DocumentMarkerController::copyMarkers): Fix a mistake where copying
markers would have a side effect of modifying the original.
(WebCore::DocumentMarkerController::removeMarkers): Just have this call
filterMarkers with null for the function.
(WebCore::DocumentMarkerController::filterMarkers): Updated for the change to
collectTextRanges and to pass a OffsetRange.
(WebCore::updateRenderedRectsForMarker): Use SimpleRange instead of a live
range. Use the new RenderObject::absoluteTextQuads and boundingBoxes functions
to make this clearer and simpler.
(WebCore::shouldInsertAsSeparateMarker): Update for changes to DocumentMarker.
(WebCore::DocumentMarkerController::copyMarkers): Take an OffsetRange instead
of a start and length. Also removed the unused "delta" argument since all
callers were passing 0.
(WebCore::DocumentMarkerController::removeMarkers): Removed unneeded
check if a key is still in the map.
(WebCore::DocumentMarkerController::forEach): Added. Shared logic for the multiple
functions that iterate the markers covered by a SimpleRange.
(WebCore::DocumentMarkerController::markersInRange): Call forEach.
(WebCore::DocumentMarkerController::repaintMarkers): Simplified loops.
(WebCore::DocumentMarkerController::setMarkersActive): Deleted. Was only
used for Chromium and has been dead code since.
(WebCore::DocumentMarkerController::hasMarkers): Call forEach.
(WebCore::DocumentMarkerController::clearDescriptionOnMarkersIntersectingRange):
Call forEach.
* dom/DocumentMarkerController.h: Updated for the above.

* dom/Element.cpp:
(WebCore::Element::boundsInRootViewSpace): Use unitedBoundingBoxes.
(WebCore::Element::absoluteEventBounds): Ditto.
(WebCore::Element::boundingAbsoluteRectWithoutLayout): Ditto.

* dom/Node.h: Added inline fast path for isCharacterDataNode.
Moved some inline function bodies out of class definition so it's
easier to read it and get an overview.

* dom/Range.cpp:
(WebCore::Range::absoluteRectsForRangeInText const): Use boundingBoxes.
(WebCore::Range::absoluteTextQuads const): Deleted.
(WebCore::Range::borderAndTextRects const): Use boundingBoxes.

* dom/Range.h: Deleted absoluteTextQuads.

* dom/RenderedDocumentMarker.h: Use rvalue references and move.

* dom/SimpleRange.cpp:
(WebCore::fastIsCharacterData): Deleted. Moved the optimizations into
Node::isCharacterDataNode so now all callers get them.
(WebCore::length): Deleted. Moved to Node::length.
(WebCore::makeBoundaryPointAfterNodeContents): Use Node::length.
(WebCore::IntersectingNodeRange::first const): Added.
(WebCore::IntersectingNodeRange::sentinel const): Added.
(WebCore::characterDataOffsetRange): Added.
(WebCore::IntersectingNodeIterator::operator++): Added.

* dom/SimpleRange.h: Added intersectingNodes function, and the
IntersectingNodeRange and IntersectingNodeIterator classes used
to make it work. Added the OffsetRange structure and the
characterDataOffsetRange function, also to help with iteration.

* editing/AlternativeTextController.cpp:
(WebCore::AlternativeTextController::respondToMarkerAtEndOfWord):
Take out unneeded holds_alternative check.
(WebCore::AlternativeTextController::removeDictationAlternativesForMarker):
Removed unneeded assertion.
(WebCore::AlternativeTextController::dictationAlternativesForMarker):
Removed unneeded assertion.
(WebCore::AlternativeTextController::applyDictationAlternative):
Removed unneeded local variables.
(WebCore::AlternativeTextController::show): Pass reference to range
rather than pointer to rootViewRectForRange.
(WebCore::AlternativeTextController::timerFired): Ditto.
(WebCore::AlternativeTextController::rootViewRectForRange const):
Take a SimpleRange instead of a live range. Also use
RenderObject::absoluteTextQuads and unitedBoundingBoxes.
* editing/AlternativeTextController.h: Updated for above.

* editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::replaceTextInNodePreservingMarkers):
Removed most of the code since we can copy marker data without
separate code for each type. Also use SimpleRange instead of a live range.

* editing/DictationCommand.cpp: Call addMarker instead of
addMarkerToNode.

* editing/Editing.cpp:
(WebCore::visiblePositionForIndexUsingCharacterIterator): Use
SimpleRange instead of a live range.

* editing/Editor.cpp:
(WebCore::Editor::updateMarkersForWordsAffectedByEditing):
Removed a local variable.

* editing/Editor.h: Remove use of RetainPtr<id> for arguments.

* editing/FrameSelection.cpp:
(WebCore::FrameSelection::getTextRectangles const): Deleted.
(WebCore::FrameSelection::getClippedVisibleTextRectangles const):
Merged the logic from getTextRectangles in here, and changed to
use RenderObject::absoluteTextQuads and boundingBoxes.
* editing/FrameSelection.h: Updated for above.

* editing/SplitTextNodeCommand.cpp:
(WebCore::SplitTextNodeCommand::doApply): Updated for changes to
the copyMarkers function.
(WebCore::SplitTextNodeCommand::doUnapply): Ditto.

* editing/cocoa/DataDetection.mm:
(WebCore::detectItemAtPositionWithRange): Use
RenderObject::absoluteTextQuads and unitedBoundingBoxes.

* editing/ios/DictationCommandIOS.cpp:
(WebCore::DictationCommandIOS::DictationCommandIOS): Remove use of
RetainPtr<id> for arguments.
(WebCore::DictationCommandIOS::create): Move from header.
(WebCore::DictationCommandIOS::doApply): Updated to do the work here
since we don't have addDictationPhraseWithAlternativesMarker any more.
Specifically, remove the first interpretation, which leaves behind a
vector of alternatives. Same for addDictationResultMarker.
* editing/ios/DictationCommandIOS.h: Updated for the above.

* editing/ios/EditorIOS.mm:
(WebCore::Editor::insertDictationPhrases): Take id instead of
RetainPtr<id>.
(WebCore::Editor::setDictationPhrasesAsChildOfElement): Changed
around since we don't have addDictationPhraseWithAlternativesMarker
or addDictationResultMarker any more.

* page/FrameView.cpp:
(WebCore::FrameView::paintContents): Update for changes to
SetLayoutNeededForbiddenScope.

* page/ios/FrameIOS.mm:
(WebCore::Frame::interpretationsForCurrentRoot const):
Get alternatives directly from DocumentMarker::data, now that
there is not a separate DocumentMarker::alternatives function.

* page/mac/ServicesOverlayController.mm:
(WebCore::textQuadsToBoundingRectForRange): Deleted.
(WebCore::ServicesOverlayController::buildPhoneNumberHighlights):
Use RenderObject::absoluteTextQuads, unitedBoundingBoxes,
and enclosingIntRect to do what textQuadsToBoundingRectForRange did.

* platform/SerializedPlatformDataCueValue.h: Remove definition of
id since that's now done in RetainPtr.h.

* platform/graphics/FloatQuad.cpp:
(WebCore::boundingBoxes): Added.
(WebCore::unitedBoundingBoxes): Added.
* platform/graphics/FloatQuad.h: A couple tweaks, plus declared the
functions above.

* platform/network/ResourceHandle.h: Remove definition of
id since that's now done in RetainPtr.h.
* platform/network/cf/AuthenticationChallenge.h: Ditto.

* rendering/InlineTextBox.cpp:
(WebCore::InlineTextBox::resolveStyleForMarkedText): Take out
isActiveMatch logic that was used for Chromium only.

* rendering/RenderBox.cpp:
(WebCore::RenderBox::minPreferredLogicalWidth const): Update for
changes to SetLayoutNeededForbiddenScope.
(WebCore::RenderBox::maxPreferredLogicalWidth const): Ditto.
* rendering/RenderCounter.cpp:
(WebCore::RenderCounter::computePreferredLogicalWidths): Ditto.
* rendering/RenderLayerBacking.cpp:
(WebCore::RenderLayerBacking::paintIntoLayer): Ditto.

* rendering/RenderObject.cpp:
(WebCore::RenderObject::SetLayoutNeededForbiddenScope::SetLayoutNeededForbiddenScope):
Changed to take a const& instead of a *.
(WebCore::RenderObject::SetLayoutNeededForbiddenScope::~SetLayoutNeededForbiddenScope):
Ditto.
(WebCore::RenderObject::markContainingBlocksForLayout): Update for
changes to SetLayoutNeededForbiddenScope.
(WebCore::RenderObject::absoluteBoundingBoxRect const): Use
unitedBoundingBoxes and enclosingIntRect.
(WebCore::RenderObject::absoluteBoundingBoxRectForRange): Use
the new RenderObject::absoluteTextQuads and unitedBoundingBoxes.
(WebCore::RenderObject::absoluteTextQuads): Added. Moved here from
Range::absoluteTextQuads, but refactored for simplicity and removed
the unused, and mildly complex to implement, feature that would
indicate whether some or all of the quads were from fixed positioning.

* rendering/RenderObject.h: Tweaked comments. Moved multi-line function
bodies out of the RenderObject class definition to make it easier to
read. Declared a new absoluteTextQuads function. Made
m_setNeedsLayoutForbidden so setNeedsLayoutIsForbidden can be const.
Conditionalized isSetNeedsLayoutForbidden and SetLayoutNeededForbiddenScope
so both can be used in production builds but expand to no code.

* rendering/RenderReplaced.cpp:
(WebCore::draggedContentContainsReplacedElement): Simplified and updated
now that the dragged content data no longer has its own named structure.
(WebCore::RenderReplaced::paint): Update for changes to
SetLayoutNeededForbiddenScope.
* rendering/RenderTableSection.cpp:
(WebCore::RenderTableSection::calcRowLogicalHeight): Ditto.
(WebCore::RenderTableSection::layoutRows): Ditto.

* rendering/RenderTheme.cpp:
(WebCore::RenderTheme::textSearchHighlightColor const): Removed the Chromium-only
concept of active vs. inactive text search highlight colors.
(WebCore::RenderTheme::platformTextSearchHighlightColor const): Ditto.
(WebCore::RenderTheme::activeTextSearchHighlightColor const): Deleted.
(WebCore::RenderTheme::inactiveTextSearchHighlightColor const): Deleted.
(WebCore::RenderTheme::platformActiveTextSearchHighlightColor const): Deleted.
(WebCore::RenderTheme::platformInactiveTextSearchHighlightColor const): Deleted.
* rendering/RenderTheme.h: Ditto.
* rendering/RenderThemeMac.h: Ditto.
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::platformTextSearchHighlightColor const): Ditto.
(WebCore::RenderThemeMac::platformActiveTextSearchHighlightColor const): Deleted.
(WebCore::RenderThemeMac::platformInactiveTextSearchHighlightColor const): Deleted.

* testing/Internals.cpp:
(WebCore::Internals::addTextMatchMarker): Deleted. Was only used for a test
of Chromium-specific scroll tick marks.
* testing/Internals.h: Deleted addTextMatchMarker.
* testing/Internals.idl: Ditto.

Source/WebKit:

* UIProcess/ViewSnapshotStore.h: Removed unused "Cocoa without IOSurface" code paths.
* UIProcess/mac/ViewSnapshotStoreMac.mm:
(WebKit::ViewSnapshot::create): Ditto.
(WebKit::ViewSnapshot::ViewSnapshot): Ditto.
(WebKit::ViewSnapshot::setSurface): Ditto.
(WebKit::ViewSnapshot::hasImage const): Ditto.
(WebKit::ViewSnapshot::clearImage): Ditto.
(WebKit::ViewSnapshot::setVolatile): Ditto.
(WebKit::ViewSnapshot::asLayerContents): Ditto.
(WebKit::ViewSnapshot::asImageForTesting): Ditto.
(WebKit::ViewSnapshotStore::snapshottingContext): Deleted.

* WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm:
(WebKit::TextCheckingControllerProxy::replaceRelativeToSelection): Updated since
addPlatformTextCheckingMarker no longer exists.
(WebKit::TextCheckingControllerProxy::removeAnnotationRelativeToSelection):
Updated since filterMarkers passes a reference instead of a pointer now.
(WebKit::TextCheckingControllerProxy::annotatedSubstringBetweenPositions):
Simplified code a bit by removing local variables.

* WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
(WebKit::WebPage::dictionaryPopupInfoForRange): Use
RenderObject::absoluteTextQuads.
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performImmediateActionHitTestAtLocation): Use
RenderObject::absoluteTextQuads and unitedBoundingBoxes.

Source/WebKitLegacy/ios:

* WebCoreSupport/WebFrameIOS.mm:
(-[WebFrame previousUnperturbedDictationResultBoundaryFromPosition:]):
Update since DocumentMarker::metadata no longer exists.
(-[WebFrame nextUnperturbedDictationResultBoundaryFromPosition:]):
Ditto.

* WebCoreSupport/WebVisiblePosition.mm:
(-[WebVisiblePosition enclosingRangeWithDictationPhraseAlternatives:]):
Update since DocumentMarker::alternatives no longer exists.
(-[WebVisiblePosition enclosingRangeWithCorrectionIndicator]):
Ditto.

Source/WebKitLegacy/mac:

* DOM/DOM.mm:
(-[DOMNode absoluteQuadAndInsideFixedPosition:]): Use unitedBoundingBoxes.
* WebCoreSupport/WebEditorClient.mm:
(WebEditorClient::handleRequestedCandidates): Use RenderObject::absoluteTextQuads.
* WebView/WebFrame.mm:
(-[WebFrame getDictationResultRanges:andMetadatas:]): Updated since DocumentMarker no
longer has a dedicated metadata member function.
(-[WebFrame dictationResultMetadataForRange:]):
* WebView/WebImmediateActionController.mm:
(+[WebImmediateActionController _dictionaryPopupInfoForRange:inFrame:withLookupOptions:indicatorOptions:transition:]):
Use RenderObject::absoluteTextQuads.

Source/WTF:

* wtf/RetainPtr.h: Define "id" here when compiling non-ObjC so it's easier to use
RetainPtr<id> in any header file. Lets us stop doing this many other places.
Harmless when not needed.

Tools:

* TestWebKitAPI/Tests/WebCore/MarkedText.cpp:
(TestWebKitAPI::TEST): Update for change to DocumentMarker constructor.

LayoutTests:

* fast/scrolling/scrollbar-tickmarks-hittest-expected.txt: Removed.
* fast/scrolling/scrollbar-tickmarks-hittest.html: Removed.
* fast/scrolling/scrollbar-tickmarks-styled-expected.txt: Removed.
* fast/scrolling/scrollbar-tickmarks-styled.html: Removed.
* platform/gtk/fast/scrolling/scrollbar-tickmarks-styled-expected.png: Removed.
* platform/ios/TestExpectations: Removed expectation for scrollbar-tickmarks.
These were Chromium-specific tests.

* platform/mac-wk1/TestExpectations: Updated to expect flakiness instead of
repeatable failures for tests that passed locally.
* platform/mac/TestExpectations: Ditto.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@259575 268f45cc-cd09-0410-ab3c-d52691b4dbfc
77 files changed
tree: 5bc5bd2613a825918c2f1dca0883d4f1377733e0
  1. JSTests/
  2. LayoutTests/
  3. ManualTests/
  4. PerformanceTests/
  5. Source/
  6. Tools/
  7. WebDriverTests/
  8. WebKit.xcworkspace/
  9. WebKitLibraries/
  10. Websites/
  11. .clang-format
  12. .dir-locals.el
  13. .gitattributes
  14. .gitignore
  15. ChangeLog
  16. ChangeLog-2012-05-22
  17. ChangeLog-2018-01-01
  18. CMakeLists.txt
  19. Makefile
  20. Makefile.shared
  21. ReadMe.md
ReadMe.md

WebKit

WebKit is a cross-platform web browser engine. On iOS and macOS, it powers Safari, Mail, iBooks, and many other applications.

Feature Status

Visit WebKit Feature Status page to see which Web API has been implemented, in development, or under consideration.

Trying the Latest

On macOS, download Safari Technology Preview to test the latest version of WebKit. On Linux, download Epiphany Technology Preview. On Windows, you'll have to build it yourself.

Reporting Bugs

  1. Search WebKit Bugzilla to see if there is an existing report for the bug you've encountered.
  2. Create a Bugzilla account to to report bugs (and to comment on them) if you haven't done so already.
  3. File a bug in accordance with our guidelines.

Once your bug is filed, you will receive email when it is updated at each stage in the bug life cycle. After the bug is considered fixed, you may be asked to download the latest nightly and confirm that the fix works for you.

Getting the Code

On Windows, follow the instructions on our website.

Cloning the Git SVN Repository

Run the following command to clone WebKit's Git SVN repository:

git clone git://git.webkit.org/WebKit.git WebKit

or

git clone https://git.webkit.org/git/WebKit.git WebKit

If you want to be able to commit changes to the repository, or just want to check out branches that aren’t contained in WebKit.git, you will need track WebKit's Subversion repository. You can run the following command to configure this and other options of the new Git clone for WebKit development.

Tools/Scripts/webkit-patch setup-git-clone

For information about this, and other aspects of using Git with WebKit, read the wiki page.

Checking out the Subversion Repository

If you don‘t want to use Git, run the following command to check out WebKit’s Subversion repository:

svn checkout https://svn.webkit.org/repository/webkit/trunk WebKit

Building WebKit

Building macOS Port

Install Xcode and its command line tools if you haven't done so already:

  1. Install Xcode Get Xcode from https://developer.apple.com/downloads. To build WebKit for OS X, Xcode 5.1.1 or later is required. To build WebKit for iOS Simulator, Xcode 7 or later is required.
  2. Install the Xcode Command Line Tools In Terminal, run the command: xcode-select --install

Run the following command to build a debug build with debugging symbols and assertions:

Tools/Scripts/build-webkit --debug

For performance testing, and other purposes, use --release instead.

Using Xcode

You can open WebKit.xcworkspace to build and debug WebKit within Xcode.

If you don't use a custom build location in Xcode preferences, you have to update the workspace settings to use WebKitBuild directory. In menu bar, choose File > Workspace Settings, then click the Advanced button, select “Custom”, “Relative to Workspace”, and enter WebKitBuild for both Products and Intermediates.

Building iOS Port

The first time after you install a new Xcode, you will need to run the following command to enable Xcode to build command line tools for iOS Simulator:

sudo Tools/Scripts/configure-xcode-for-ios-development

Without this step, you will see the error message: “target specifies product type ‘com.apple.product-type.tool’, but there’s no such product type for the ‘iphonesimulator’ platform.” when building target JSCLLIntOffsetsExtractor of project JavaScriptCore.

Run the following command to build a debug build with debugging symbols and assertions for iOS:

Tools/Scripts/build-webkit --debug --ios-simulator

Building the GTK+ Port

For production builds:

cmake -DPORT=GTK -DCMAKE_BUILD_TYPE=RelWithDebInfo -GNinja
ninja
sudo ninja install

For development builds:

Tools/gtk/install-dependencies
Tools/Scripts/update-webkitgtk-libs
Tools/Scripts/build-webkit --gtk --debug

For more information on building WebKitGTK+, see the wiki page.

Building the WPE Port

For production builds:

cmake -DPORT=WPE -DCMAKE_BUILD_TYPE=RelWithDebInfo -GNinja
ninja
sudo ninja install

For development builds:

Tools/wpe/install-dependencies
Tools/Scripts/update-webkitwpe-libs
Tools/Scripts/build-webkit --wpe --debug

Building Windows Port

For building WebKit on Windows, see the wiki page.

Running WebKit

With Safari and Other macOS Applications

Run the following command to launch Safari with your local build of WebKit:

Tools/Scripts/run-safari --debug

The run-safari script sets the DYLD_FRAMEWORK_PATH environment variable to point to your build products, and then launches /Applications/Safari.app. DYLD_FRAMEWORK_PATH tells the system loader to prefer your build products over the frameworks installed in /System/Library/Frameworks.

To run other applications with your local build of WebKit, run the following command:

Tools/Scripts/run-webkit-app <application-path>

iOS Simulator

Run the following command to launch iOS simulator with your local build of WebKit:

run-safari --debug --ios-simulator

In both cases, if you have built release builds instead, use --release instead of --debug.

Linux Ports

If you have a development build, you can use the run-minibrowser script, e.g.:

run-minibrowser --debug --wpe

Pass one of --gtk, --jsc-only, or --wpe to indicate the port to use.

Contribute

Congratulations! You’re up and running. Now you can begin coding in WebKit and contribute your fixes and new features to the project. For details on submitting your code to the project, read Contributing Code.