Skip to content

Commit

Permalink
Move TextIterator::rangeFromLocationAndLength off of live ranges
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=209408

Source/WebCore:

Reviewed by Antti Koivisto.

- Put CharacterRange into a header, CharacterRange.h.
- Replaced CharacterOffset with direct uses of uint64_t.
  Because this can be a single offset into an entire document, use a
  64-bit integer so we don't limit an entire document to 2^32 characters;
  in theory this makes it so we can support a document with tons of
  text nodes that add up to more than 2^32.
- Because CharacterRange uses 64-bit integers we can now convert more
  easily to and from NSRange and CFRange on Cocoa platforms.

* Headers.cmake: Added CharacterRange.h.
* WebCore.xcodeproj/project.pbxproj: Ditto.

* accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:
(-[WebAccessibilityObjectWrapper _convertToDOMRange:]):
Use CharacterRange, resolveCharacterLocation/Range.
* accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
(AXAttributeStringSetSpelling): Ditto.
(-[WebAccessibilityObjectWrapper _textMarkerForIndex:]): Ditto.

* dom/DocumentMarkerController.cpp:
(WebCore::DocumentMarkerController::collectTextRanges): Take SimpleRange.
(WebCore::DocumentMarkerController::addMarker): Ditto.
(WebCore::DocumentMarkerController::addDictationResultMarker): Ditto.
(WebCore::DocumentMarkerController::addPlatformTextCheckingMarker): Ditto.
* dom/DocumentMarkerController.h: Updated for above changes.

* dom/Position.h: Export createLegacyEditingPosition so it can be used
outside of WebCore.

* dom/SimpleRange.cpp:
(WebCore::fastIsCharacterData): Added. Could be moved to the Node class.
(WebCore::length): Added. Could be moved to the Node class.
(WebCore::makeRangeSelectingNodeContents): Added. Analogous to the
Range::selectNodeContents function.
* dom/SimpleRange.h: Updated for the above.

* editing/AlternativeTextController.cpp:
(WebCore::AlternativeTextController::applyAlternativeTextToRange):
Use CharacterRange, resolveCharacterLocation/Range.
* editing/ApplyStyleCommand.cpp:
(WebCore::ApplyStyleCommand::applyBlockStyle): Ditto.

* editing/CharacterRange.h: Added.

* editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::moveParagraphs):
Use CharacterRange, resolveCharacterLocation/Range.
* editing/Editing.cpp:
(WebCore::visiblePositionForIndex): Ditto.
* editing/Editor.cpp:
(WebCore::Editor::advanceToNextMisspelling): Ditto.
(WebCore::correctSpellcheckingPreservingTextCheckingParagraph): Ditto.
(WebCore::Editor::markAndReplaceFor): Ditto.
(WebCore::Editor::changeBackToReplacedString): Ditto.
(WebCore::Editor::scanRangeForTelephoneNumbers): Ditto.
(WebCore::Editor::rangeForTextCheckingResult const): Ditto.
* editing/TextCheckingHelper.cpp:
(WebCore::findGrammaticalErrors): Ditto.
(WebCore::findMisspellings): Ditto.
(WebCore::TextCheckingParagraph::invalidateParagraphRangeValues): Ditto.
(WebCore::TextCheckingParagraph::rangeLength const): Ditto.
(WebCore::TextCheckingParagraph::subrange const): Ditto.
(WebCore::TextCheckingParagraph::offsetTo const): Ditto.
(WebCore::TextCheckingParagraph::text const): Ditto. Also use StringView.
(WebCore::TextCheckingParagraph::checkingStart const): Ditto.
(WebCore::TextCheckingParagraph::checkingEnd const): Ditto. Also compute
this by adding start and length, and don't cache it.
(WebCore::TextCheckingParagraph::checkingLength const): Ditto.
(WebCore::TextCheckingParagraph::automaticReplacementStart const): Ditto.
(WebCore::TextCheckingParagraph::automaticReplacementLength const): Ditto.
(WebCore::TextCheckingHelper::findFirstMisspelling): Ditto.
(WebCore::TextCheckingHelper::findFirstMisspellingOrBadGrammar): Ditto.
(WebCore::TextCheckingHelper::findFirstGrammarDetail const): Ditto.
(WebCore::TextCheckingHelper::findFirstBadGrammar const): Ditto.
(WebCore::TextCheckingHelper::isUngrammatical const): Ditto.
(WebCore::TextCheckingHelper::guessesForMisspelledOrUngrammaticalRange const): Ditto.
(WebCore::TextCheckingHelper::markAllMisspellings): Ditto.
(WebCore::TextCheckingHelper::markAllBadGrammar): Ditto.
(WebCore::checkTextOfParagraph): Ditto.
* editing/TextCheckingHelper.h: Updated for the above. Also got rid of
m_checkingEnd since it's sufficient to cache the start and the length.
Should come back later and use CharacterRange instead of 2x CharacterCount.

* editing/TextIterator.cpp:
(WebCore::characterCount): Use uint64_t.
(WebCore::TextIterator::subrange): Deleted.
(WebCore::TextIterator::rangeFromLocationAndLength): Deleted.
(WebCore::clampedAdd): Added. Helps implement resolveCharacterRange in a way
that can work with any character count without concern about overflow.
(WebCore::resolveCharacterRange): Added. Replaces both subrange and
rangeFromLocationAndLength, using an algorithm close to the one from
the latter function, including workarounds it had. Replaced the boolean
"forSelectionPreservation" with the TextIteratorBehavior options, which seems
to make good sense at all the call sites.
(WebCore::resolveCharacterLocation): Added. Like resolveCharacterRange, but
instead of resolving CharacterRange to SimpleRange, resolves a character location
to a BoundaryPoint. Made a separate function for this in case we later refactor
for efficiency, but for now this simply calls resolveCharacterRange with a zero
length range.

* editing/TextIterator.h: Moved CharacterCount and CharagerRange into a
separate header. Replaced TextIterator::rangeFromLocationAndLength and
TextIterator::subrange with resolveCharacterLocation and resolveCharacterRange.

* editing/cocoa/DataDetection.mm:
(WebCore::detectItemAtPositionWithRange): Use CharacterRange,
resolveCharacterLocation/Range.
(WebCore::DataDetection::detectContentInRange): Ditto.
* editing/cocoa/DictionaryLookup.mm:
(WebCore::DictionaryLookup::rangeForSelection): Ditto.
(WebCore::DictionaryLookup::rangeAtHitTestResult): Ditto.
* editing/ios/DictationCommandIOS.cpp:
(WebCore::DictationCommandIOS::doApply): Ditto.
* editing/mac/DictionaryLookupLegacy.mm:
(WebCore::DictionaryLookup::rangeAtHitTestResult): Ditto.
* page/EventHandler.cpp:
(WebCore::textDistance): Ditto.
* page/Page.cpp:
(WebCore::replaceRanges): Ditto.
(WebCore::Page::replaceRangesWithText): Ditto.
* platform/text/TextChecking.h: Ditto.
* testing/Internals.cpp:
(WebCore::Internals::rangeFromLocationAndLength): Ditto.
(WebCore::Internals::subrange): Ditto.
(WebCore::Internals::handleAcceptedCandidate): Ditto.

* testing/Internals.h: Made location and length unsigned rather than signed.
* testing/Internals.idl: Ditto.

Source/WebKit:

Reviewed by Antti Koivisto.

* Shared/EditingRange.cpp:
(WebKit::EditingRange::toRange): Use CharacterRange,
resolveCharacterLocation/Range.

* Shared/EditingRange.h: Added a FIXME about replacing with CharacterRange.

* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<CharacterRange>::encode): Added.
(IPC::ArgumentCoder<CharacterRange>::decode): Added.
(IPC::ArgumentCoder<GrammarDetail>::encode): Updated to use CharacterRange.
(IPC::ArgumentCoder<GrammarDetail>::decode): Ditto.
(IPC::ArgumentCoder<TextCheckingResult>::encode): Ditto.
(IPC::ArgumentCoder<TextCheckingResult>::decode): Ditto.
* Shared/WebCoreArgumentCoders.h: Added CharacterRange.

* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::textCheckingResultFromNSTextCheckingResult): Use CharacterRange,
resolveCharacterLocation/Range.
* UIProcess/WebGrammarDetail.cpp:
(WebKit::WebGrammarDetail::WebGrammarDetail): Ditto.
* UIProcess/WebGrammarDetail.h:
(WebKit::WebGrammarDetail::location const): Ditto.
(WebKit::WebGrammarDetail::length const): Ditto.
* UIProcess/gtk/TextCheckerGtk.cpp:
(WebKit::TextChecker::checkTextOfParagraph): Ditto.
* UIProcess/ios/TextCheckerIOS.mm:
(WebKit::TextChecker::checkTextOfParagraph): Ditto.
* UIProcess/mac/TextCheckerMac.mm:
(WebKit::TextChecker::checkTextOfParagraph): Ditto.
(WebKit::TextChecker::updateSpellingUIWithGrammarString): Ditto.
* WebProcess/WebPage/Cocoa/TextCheckingControllerProxy.mm:
(WebKit::TextCheckingControllerProxy::rangeAndOffsetRelativeToSelection): Ditto.
(WebKit::TextCheckingControllerProxy::replaceRelativeToSelection): Ditto.
(WebKit::TextCheckingControllerProxy::annotatedSubstringBetweenPositions): Ditto.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::deleteSurrounding): Ditto.
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::getPlatformEditorState const): Small tweak.
(WebKit::WebPage::updateSelectionWithDelta): Ditto.
(WebKit::WebPage::requestDocumentEditingContext): Ditto.

Source/WebKitLegacy/mac:

Reviewed by Antti Koivisto.

* WebCoreSupport/WebEditorClient.mm:
(WebEditorClient::checkTextOfParagraph): Use CharacterRange,
resolveCharacterLocation/Range.
(WebEditorClient::checkGrammarOfString): Ditto.
(core): Ditto.
(WebEditorClient::updateSpellingUIWithGrammarString): Ditto.
(WebEditorClient::handleAcceptedCandidateWithSoftSpaces): Ditto.
* WebView/WebFrame.mm:
(-[WebFrame _convertToDOMRange:rangeIsRelativeTo:]): Ditto.
* WebView/WebView.mm:
(textCheckingResultFromNSTextCheckingResult): Ditto.

Source/WebKitLegacy/win:

Reviewed by Antti Koivisto.

* WebCoreSupport/WebEditorClient.cpp:
(WebEditorClient::checkGrammarOfString): Use CharacterRange,
resolveCharacterLocation/Range.
(WebEditorClient::updateSpellingUIWithGrammarString): Ditto.
* WebView.cpp:
(WebView::firstRectForCharacterRangeForTesting): Ditto.

LayoutTests:

Fix Mac-specific firstrectforcharacterrange-styled.html test
https://bugs.webkit.org/show_bug.cgi?id=205314
<rdar://problem/57990717>

Reviewed by Antti Koivisto.

* accessibility/mac/textmarker-for-index-out-of-bounds-crash-expected.txt:
* accessibility/mac/textmarker-for-index-out-of-bounds-crash.html:
Updated to expect textMarkerForIndex to clamp rather than returning something invalid.

* editing/mac/input/firstrectforcharacterrange-plain-expected.txt:
* editing/mac/input/firstrectforcharacterrange-plain.html:
Updated test output to include what is being tested, not just the test result.
Updated test results to expect clamping rather than an empty rectangle, for values
that are out of bounds. Also got rid of dumping of eidting callbacks since there is
no reason to include them in this test.

* editing/mac/input/firstrectforcharacterrange-styled-expected.txt:
* editing/mac/input/firstrectforcharacterrange-styled.html:
Ditto.

* platform/mac-wk1/TestExpectations: Since our oldest supported release is Mojave, deleted
all rules with Sierra or HighSierra conditionals since those conditions are always false,
and removed any conditionals that said Sierra+, HighSierra+, or Mojave+ because those
conditions are always true. One test, firstrectforcharacterrange-styled.html, had results
checked in that were correct for Mojave but incorrect for Catalina. For that test, the
results are now correct for Catalina, so updated expectations for that.

* platform/mac-wk2/TestExpectations: Ditto. Also some tests that claimed ImageOnlyFailure
are flaky and sometimes passing, so marked them for either Pass or ImageOnlyFailure.

* platform/mac/TestExpectations: Ditto. Also some tests marked Failure were flaky and
sometimes passing, so marked them for either Pass or Failure.

* platform/mac/editing/mac/input/firstrectforcharacterrange-styled-expected.txt: Removed.
This is already a Mac-specific test; it doesn't make sense to have an additional
Mac-specific overridden result since the base result is already Mac-specific.

* platform/mac/fast/text/attributed-substring-from-range-001-expected.txt:
* platform/mac/fast/text/attributed-substring-from-range-001.html:
Updated this test to expect the empty string, not "undefined" for an out of range,
since we now clamp instead of failing in such cases.

* platform/mac/fast/text/attributed-substring-from-range-expected.txt:
* platform/mac/fast/text/attributed-substring-from-range.html:
Ditto.

Canonical link: https://commits.webkit.org/222649@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@259184 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
darinadler committed Mar 30, 2020
1 parent 2e47966 commit b19656c
Show file tree
Hide file tree
Showing 67 changed files with 1,239 additions and 1,069 deletions.
52 changes: 52 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,55 @@
2020-03-29 Darin Adler <darin@apple.com>

Move TextIterator::rangeFromLocationAndLength off of live ranges
https://bugs.webkit.org/show_bug.cgi?id=209408

Fix Mac-specific firstrectforcharacterrange-styled.html test
https://bugs.webkit.org/show_bug.cgi?id=205314
<rdar://problem/57990717>

Reviewed by Antti Koivisto.

* accessibility/mac/textmarker-for-index-out-of-bounds-crash-expected.txt:
* accessibility/mac/textmarker-for-index-out-of-bounds-crash.html:
Updated to expect textMarkerForIndex to clamp rather than returning something invalid.

* editing/mac/input/firstrectforcharacterrange-plain-expected.txt:
* editing/mac/input/firstrectforcharacterrange-plain.html:
Updated test output to include what is being tested, not just the test result.
Updated test results to expect clamping rather than an empty rectangle, for values
that are out of bounds. Also got rid of dumping of eidting callbacks since there is
no reason to include them in this test.

* editing/mac/input/firstrectforcharacterrange-styled-expected.txt:
* editing/mac/input/firstrectforcharacterrange-styled.html:
Ditto.

* platform/mac-wk1/TestExpectations: Since our oldest supported release is Mojave, deleted
all rules with Sierra or HighSierra conditionals since those conditions are always false,
and removed any conditionals that said Sierra+, HighSierra+, or Mojave+ because those
conditions are always true. One test, firstrectforcharacterrange-styled.html, had results
checked in that were correct for Mojave but incorrect for Catalina. For that test, the
results are now correct for Catalina, so updated expectations for that.

* platform/mac-wk2/TestExpectations: Ditto. Also some tests that claimed ImageOnlyFailure
are flaky and sometimes passing, so marked them for either Pass or ImageOnlyFailure.

* platform/mac/TestExpectations: Ditto. Also some tests marked Failure were flaky and
sometimes passing, so marked them for either Pass or Failure.

* platform/mac/editing/mac/input/firstrectforcharacterrange-styled-expected.txt: Removed.
This is already a Mac-specific test; it doesn't make sense to have an additional
Mac-specific overridden result since the base result is already Mac-specific.

* platform/mac/fast/text/attributed-substring-from-range-001-expected.txt:
* platform/mac/fast/text/attributed-substring-from-range-001.html:
Updated this test to expect the empty string, not "undefined" for an out of range,
since we now clamp instead of failing in such cases.

* platform/mac/fast/text/attributed-substring-from-range-expected.txt:
* platform/mac/fast/text/attributed-substring-from-range.html:
Ditto.

2020-03-28 Said Abou-Hallawa <sabouhallawa@apple.com>

Regression: fast/hidpi/image-srcset-svg-canvas-2x.html is failing consistently on iOS EWS
Expand Down
@@ -1,12 +1,12 @@
text
text
text
This verifies that textMarkerForIndex for not crash when given an index out of bounds
This verifies that textMarkerForIndex for not crash when given an index greater than 2^31

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS item1.isTextMarkerValid(item1.textMarkerForIndex(99999999999)) is false
PASS item1.isTextMarkerValid(item1.textMarkerForIndex(99999999999)) is true
PASS successfullyParsed is true

TEST COMPLETE
Expand Down
Expand Up @@ -14,12 +14,12 @@

<script>

description("This verifies that textMarkerForIndex for not crash when given an index out of bounds");
description("This verifies that textMarkerForIndex for not crash when given an index greater than 2^31");

if (window.accessibilityController) {
document.getElementById("text1").focus();
var item1 = accessibilityController.focusedElement;
shouldBeFalse("item1.isTextMarkerValid(item1.textMarkerForIndex(99999999999))");
shouldBeTrue("item1.isTextMarkerValid(item1.textMarkerForIndex(99999999999))");
}

</script>
Expand Down
@@ -1,20 +1,17 @@
EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of BODY > HTML > #document to 2 of BODY > HTML > #document
EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
123456
10,572,0,18
18,572,0,18
58,572,0,18
58,572,0,18
10,572,8,18
50,572,8,18
50,572,8,18
50,572,8,18
10,572,48,18
10,572,48,18
10,572,48,18
18,572,40,18
0,0,0,0
0,0,0,0
0,0,0,0
0,0,0,0
caret at the beginning: (0,0), (10,572,0,18)
caret after the first character: (1,0), (18,572,0,18)
caret at the end of line: (6,0), (58,572,0,18)
caret at the end of line: (6,100), (58,572,0,18)
first character: (0,1), (10,572,8,18)
last character: (5,1), (50,572,8,18)
last character: (5,2), (50,572,8,18)
last character: (5,100), (50,572,8,18)
first line: (0,6), (10,572,48,18)
first line: (0,7), (10,572,48,18)
first line: (0,4294967295), (10,572,48,18)
first line without the first character: (1,4294967295), (18,572,40,18)
out of bounds, clamped to the end: (7,0), (58,572,0,18)
out of bounds, clamped to the end: (1000,0), (58,572,0,18)
out of bounds, clamped to the end: (7,1), (58,572,0,18)
out of bounds, clamped to the end: (7,4294967295), (58,572,0,18)
54 changes: 25 additions & 29 deletions LayoutTests/editing/mac/input/firstrectforcharacterrange-plain.html
@@ -1,18 +1,12 @@
<html>
<head>
<script>
if (window.testRunner)
testRunner.dumpEditingCallbacks();
</script>

<style>
body { margin: 10; padding: 0 }
</style>
</head>
<body contenteditable>
123456
<script type="text/javascript">

var console_messages = document.createElement("ol");

function log(message)
Expand All @@ -21,40 +15,42 @@
item.appendChild(document.createTextNode(message));
console_messages.appendChild(item);
}


function logRect(comment, start, length)
{
log(comment + ": (" + start + "," + length + "), ("
+ textInputController.firstRectForCharacterRange(start, length) + ")");
}

if (window.testRunner) {

try {

testRunner.dumpAsText();

window.getSelection().setPosition(document.body, 0);

log(textInputController.firstRectForCharacterRange(0, 0)); // caret at the beginning
log(textInputController.firstRectForCharacterRange(1, 0)); // caret after the first character
log(textInputController.firstRectForCharacterRange(6, 0)); // caret at the end of line
log(textInputController.firstRectForCharacterRange(6, 100)); // -"-
log(textInputController.firstRectForCharacterRange(0, 1)); // first character
log(textInputController.firstRectForCharacterRange(5, 1)); // last character
log(textInputController.firstRectForCharacterRange(5, 2)); // -"-
log(textInputController.firstRectForCharacterRange(5, 100)); // -"-
log(textInputController.firstRectForCharacterRange(0, 6)); // first line
log(textInputController.firstRectForCharacterRange(0, 7)); // -"-
log(textInputController.firstRectForCharacterRange(0, 4294967295)); // -"-
log(textInputController.firstRectForCharacterRange(1, 4294967295)); // first line without the first character
log(textInputController.firstRectForCharacterRange(7, 0)); // out of bounds, should be zero rect
log(textInputController.firstRectForCharacterRange(1000, 0)); // -"-
log(textInputController.firstRectForCharacterRange(7, 1)); // -"-
log(textInputController.firstRectForCharacterRange(7, 4294967295)); // -"-
window.getSelection().setPosition(document.body, 0);

logRect("caret at the beginning", 0, 0);
logRect("caret after the first character", 1, 0);
logRect("caret at the end of line", 6, 0);
logRect("caret at the end of line", 6, 100);
logRect("first character", 0, 1);
logRect("last character", 5, 1);
logRect("last character", 5, 2);
logRect("last character", 5, 100);
logRect("first line", 0, 6);
logRect("first line", 0, 7);
logRect("first line", 0, 4294967295);
logRect("first line without the first character", 1, 4294967295);
logRect("out of bounds, clamped to the end", 7, 0);
logRect("out of bounds, clamped to the end", 1000, 0);
logRect("out of bounds, clamped to the end", 7, 1);
logRect("out of bounds, clamped to the end", 7, 4294967295);
} catch (ex) {
log("Exception: " + ex.description);
}

var console = document.createElement("p");
console.appendChild(console_messages);
document.body.appendChild(console);

} else {
document.write("(cannot run interactively)");
}
Expand Down
@@ -1,24 +1,17 @@
EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of BODY > HTML > #document to 4 of BODY > HTML > #document
EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 1 of #text > I > B > BODY > HTML > #document to 1 of #text > I > B > BODY > HTML > #document toDOMRange:range from 1 of #text > I > B > BODY > HTML > #document to 3 of #text > I > B > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
123456
10,572,0,18
18,572,0,18
58,572,0,18
58,572,0,18
10,572,8,18
50,572,8,18
50,572,8,18
50,572,8,18
10,572,48,18
10,572,48,18
10,572,48,18
18,572,40,18
0,0,0,0
0,0,0,0
0,0,0,0
0,0,0,0
caret at the beginning: (0,0), (10,572,0,18)
caret after the first character: (1,0), (18,572,0,18)
caret at the end of line: (6,0), (58,572,0,18)
caret at the end of line: (6,100), (58,572,0,18)
first character: (0,1), (10,572,8,18)
last character: (5,1), (50,572,8,18)
last character: (5,2), (50,572,8,18)
last character: (5,100), (50,572,8,18)
first line: (0,6), (10,572,48,18)
first line: (0,7), (10,572,48,18)
first line: (0,4294967295), (10,572,48,18)
first line without the first character: (1,4294967295), (18,572,40,18)
out of bounds, clamped to the end: (7,0), (58,572,0,18)
out of bounds, clamped to the end: (1000,0), (58,572,0,18)
out of bounds, clamped to the end: (7,1), (58,572,0,18)
out of bounds, clamped to the end: (7,4294967295), (58,572,0,18)
@@ -1,10 +1,5 @@
<html>
<head>
<script>
if (window.testRunner)
testRunner.dumpEditingCallbacks();
</script>

<style>
body { margin: 10; padding: 0 }
</style>
Expand All @@ -21,33 +16,36 @@
item.appendChild(document.createTextNode(message));
console_messages.appendChild(item);
}


function logRect(comment, start, length)
{
log(comment + ": (" + start + "," + length + "), ("
+ textInputController.firstRectForCharacterRange(start, length) + ")");
}

if (window.testRunner) {

try {

testRunner.dumpAsText();

window.getSelection().setPosition(document.body, 4);
textInputController.setMarkedText("56", 0, 1);

log(textInputController.firstRectForCharacterRange(0, 0)); // caret at the beginning
log(textInputController.firstRectForCharacterRange(1, 0)); // caret after the first character
log(textInputController.firstRectForCharacterRange(6, 0)); // caret at the end of line
log(textInputController.firstRectForCharacterRange(6, 100)); // -"-
log(textInputController.firstRectForCharacterRange(0, 1)); // first character
log(textInputController.firstRectForCharacterRange(5, 1)); // last character
log(textInputController.firstRectForCharacterRange(5, 2)); // -"-
log(textInputController.firstRectForCharacterRange(5, 100)); // -"-
log(textInputController.firstRectForCharacterRange(0, 6)); // first line
log(textInputController.firstRectForCharacterRange(0, 7)); // -"-
log(textInputController.firstRectForCharacterRange(0, 4294967295)); // -"-
log(textInputController.firstRectForCharacterRange(1, 4294967295)); // first line without the first character
log(textInputController.firstRectForCharacterRange(7, 0)); // out of bounds, should be zero rect
log(textInputController.firstRectForCharacterRange(1000, 0)); // -"-
log(textInputController.firstRectForCharacterRange(7, 1)); // -"-
log(textInputController.firstRectForCharacterRange(7, 4294967295)); // -"-

logRect("caret at the beginning", 0, 0);
logRect("caret after the first character", 1, 0);
logRect("caret at the end of line", 6, 0);
logRect("caret at the end of line", 6, 100);
logRect("first character", 0, 1);
logRect("last character", 5, 1);
logRect("last character", 5, 2);
logRect("last character", 5, 100);
logRect("first line", 0, 6);
logRect("first line", 0, 7);
logRect("first line", 0, 4294967295);
logRect("first line without the first character", 1, 4294967295);
logRect("out of bounds, clamped to the end", 7, 0);
logRect("out of bounds, clamped to the end", 1000, 0);
logRect("out of bounds, clamped to the end", 7, 1);
logRect("out of bounds, clamped to the end", 7, 4294967295);
} catch (ex) {
log("Exception: " + ex.description);
}
Expand Down

0 comments on commit b19656c

Please sign in to comment.