Change TextIterator to use StringView, preparing to wean it from deprecatedCharacters
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Feb 2014 16:32:05 +0000 (16:32 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Feb 2014 16:32:05 +0000 (16:32 +0000)
commitd9f476caf437d55feb609de0bf4125591b690abe
tree6db97a08dbf46a5420d2f96700efb73838ba030e
parent5ac8b32339aa038f46dabba42edddb619c0cc24a
Change TextIterator to use StringView, preparing to wean it from deprecatedCharacters
https://bugs.webkit.org/show_bug.cgi?id=128233

Reviewed by Anders Carlsson.

Source/WebCore:

* accessibility/AccessibilityNodeObject.cpp: Removed unneeded TextIterator.h include.

* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::hasMisspelling): Updated to use StringView for checkSpelling.

* accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
(AXAttributeStringSetSpelling): Changed to take a StringView.
(AXAttributedStringAppendText): Ditto.
(-[WebAccessibilityObjectWrapper doAXAttributedStringForTextMarkerRange:]): Pass StringView.

* editing/Editor.cpp:
(WebCore::Editor::misspelledWordAtCaretOrRange): Pass StringView.
(WebCore::Editor::misspelledSelectionString): Ditto.
(WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges): Ditto.

* editing/TextCheckingHelper.cpp:
(WebCore::findGrammaticalErrors): Renamed this function. Changed to use StringView.
(WebCore::findMisspellings): Use StringView.
(WebCore::TextCheckingHelper::findFirstMisspelling): Ditto. Also separated out assertions
that were asserting multiple things with &&.
(WebCore::TextCheckingHelper::findFirstMisspellingOrBadGrammar): Ditto.
(WebCore::TextCheckingHelper::findFirstGrammarDetail): Ditto.
(WebCore::TextCheckingHelper::findFirstBadGrammar): Ditto.
(WebCore::TextCheckingHelper::isUngrammatical): Ditto.
(WebCore::TextCheckingHelper::guessesForMisspelledOrUngrammaticalRange): Ditto.
(WebCore::checkTextOfParagraph): Ditto.

* editing/TextCheckingHelper.h: Made TextCheckingParagraph::text public. Deleted
TextCheckingParagraph::textDeprecatedCharacters. Added comments about additional
TextCheckingParagraph refinements. Changed checkTextOfParagraph to take a client
reference instead of pointer and StringView instead of characters pointer with length.

* editing/TextIterator.cpp:
(WebCore::TextIterator::appendTextToStringBuilder): Use data members directly,
rather than using functions, since we already checked m_textCharacters for null.
(WebCore::CharacterIterator::string): Use text() instead of characters().
(WebCore::WordAwareIterator::WordAwareIterator): Removed initialization of
m_previousText now that it's a StringView rather than a pointer.
(WebCore::WordAwareIterator::advance): Use TextIterator::text instead of
TextIterator::characters. Also added a FIXME about a fundamental problem
with the implementation of this class!
(WebCore::WordAwareIterator::length): Updated for m_previousText change.
(WebCore::WordAwareIterator::text): Replaced WordAwareIterator::characters with this.
(WebCore::SearchBuffer::append): Changed to take a StringView.
(WebCore::SearchBuffer::prependContext): Ditto.
(WebCore::SearchBuffer::isWordStartMatch): Use StringView.
(WebCore::SearchBuffer::search): Ditto.
(WebCore::findPlainText): Ditto.

* editing/TextIterator.h: Added TextIterator::text that returns a StringView, and
renamed TextIterator::characters to TextIterator::deprecatedTextIteratorCharacters
(easy to search for in source code). Added SimplifiedBackwardsTextIterator::text
and removed SimplifiedBackwardsTextIterator::characters. Added CharacterIterator::text,
and removed CharacterIterator::characters. Added WordAwareIterator::text and removed
WorkdAwareIterator::characters. Changed WordAwareIterator data members to use StringView.

* editing/VisibleSelection.cpp:
(WebCore::VisibleSelection::appendTrailingWhitespace): Use TextIterator::text instead
of TextIterator::characters.

* editing/VisibleUnits.cpp:
(WebCore::previousBoundary): Updated to use StringView.
(WebCore::nextBoundary): Ditto.
(WebCore::startWordBoundary): Ditto.
(WebCore::startOfWord): Ditto.
(WebCore::endWordBoundary): Ditto.
(WebCore::endOfWord): Fixed formatting.
(WebCore::previousWordPositionBoundary): Updated to use StringView.
(WebCore::previousWordPosition): Fixed formatting and got rid of local variable.
(WebCore::nextWordPositionBoundary): Updated to use StringView.
(WebCore::nextWordPosition): Fixed formatting and got rid of local variable.
(WebCore::inSameLine): Fixed formatting.
(WebCore::isStartOfLine): Ditto.
(WebCore::isEndOfLine): Ditto.
(WebCore::absoluteLineDirectionPointToLocalPointInBlock): Changed to take a reference.
(WebCore::previousLinePosition): Fixed formatting chand changed to pass a reference.
(WebCore::nextLinePosition): Ditto.
(WebCore::startSentenceBoundary): Updated to use StringView and got rid of a local.
(WebCore::startOfSentence): Fixed formatting.
(WebCore::endSentenceBoundary): Updated to use StringView and got rid of a local.
(WebCore::endOfSentence): Fixed formatting.
(WebCore::previousSentencePositionBoundary): Updated to use StringView and got rid of
a local.
(WebCore::previousSentencePosition): Ditto.
(WebCore::nextSentencePositionBoundary): Ditto.
(WebCore::nextSentencePosition): Fixed formatting.
(WebCore::endOfParagraph): Ditto.
(WebCore::inSameParagraph): Ditto.
(WebCore::isStartOfParagraph): Ditto.
(WebCore::isEndOfParagraph): Ditto.
(WebCore::inSameBlock): Ditto.
(WebCore::isStartOfBlock): Ditto.
(WebCore::isEndOfBlock): Ditto.
(WebCore::startOfDocument): Ditto.
(WebCore::endOfDocument): Ditto.
(WebCore::inSameDocument): Ditto.
(WebCore::isStartOfDocument): Ditto.
(WebCore::isEndOfDocument): Ditto.
(WebCore::isEndOfEditableOrNonEditableContent): Ditto.

* loader/EmptyClients.h: Use StringView.

* platform/mac/HTMLConverter.mm:
(+[WebHTMLConverter editingAttributedStringFromRange:]): Use StringView.

* platform/text/TextBoundaries.cpp:
(WebCore::endOfFirstWordBoundaryContext): Use StringView and unsigned.
(WebCore::startOfLastWordBoundaryContext): Ditto.

* platform/text/TextBoundaries.h: Change interfaces to use StringView,
and in some cases, unsigned instead of int. All call sites were better off
with unsigned.

* platform/text/TextCheckerClient.h: Use StringView.

* platform/text/mac/TextBoundaries.mm: Changed conditionals to say
USE(APPKIT) instead of PLATFORM(IOS), since that's the real issue.
(WebCore::isSkipCharacter): Tweaked formatting.
(WebCore::isWhitespaceCharacter): Ditto.
(WebCore::isWordDelimitingCharacter): Ditto, also removed local variable.
(WebCore::isSymbolCharacter): Ditto.
(WebCore::tokenizerForString): Ditto.
(WebCore::findSimpleWordBoundary): Use StringView. Also changed to mostly
use unsigned instead of int.
(WebCore::findComplexWordBoundary): Use StringView. Also restructured to
be much more readable, with early returns and such.
(WebCore::findWordBoundary): Use StringView and unsigned.
(WebCore::findEndWordBoundary): Removed redudant copy of the findWordBoundary
function and changed this to just call findWordBoundary. The reason this
function exists is to optimize this case for some non-Mac, non-iOS platforms.
We can always do that for Mac and/or iOS later if we like.
(WebCore::findNextWordFromIndex): Use StringView. Also use wordBreakIterator
instead of using UBreakIterator directly so we get a cached iterator instead
of creating and destroying a new one each time this function is called.

* bindings/objc/DOMUIKitExtensions.mm: Removed unneeded includes.
* dom/Element.cpp: Ditto.
* dom/PositionIterator.cpp: Ditto.
* editing/ApplyBlockElementCommand.cpp: Ditto.
* editing/IndentOutdentCommand.cpp: Ditto.
* editing/InsertListCommand.cpp: Ditto.
* editing/markup.cpp: Ditto.
* html/HTMLElement.cpp: Ditto.
* html/HTMLTextAreaElement.cpp: Ditto.
* page/Frame.cpp: Ditto.
* rendering/RenderTextControl.cpp: Ditto.

Source/WebKit/efl:

* WebCoreSupport/EditorClientEfl.cpp:
(WebCore::EditorClientEfl::checkSpellingOfString): Use StringView.
(WebCore::EditorClientEfl::checkGrammarOfString): Ditto.
* WebCoreSupport/EditorClientEfl.h: Ditto.

Source/WebKit/gtk:

* WebCoreSupport/TextCheckerClientGtk.cpp:
(WebKit::TextCheckerClientGtk::checkSpellingOfString): Use StringView.
(WebKit::TextCheckerClientGtk::checkGrammarOfString): Ditto.
* WebCoreSupport/TextCheckerClientGtk.h: Ditto.

Source/WebKit/mac:

* WebCoreSupport/WebEditorClient.h: Made most data members private. Moved inlines
for iOS out of the class definition. Fixed formatting. Added missing virtual keyword.
Changed interfaces to use StringView.

* WebCoreSupport/WebEditorClient.mm:
(WebEditorClient::checkTextOfParagraph): Use the new StringView::createNSStringWithoutCopying
function instead of a similar function that was local in this file.
(WebEditorClient::ignoreWordInSpellDocument): Tweaked formatting.
(WebEditorClient::checkSpellingOfString): Changed to take a StringView.
(WebEditorClient::checkGrammarOfString): Ditto.

* WebView/WebTextIterator.mm:
(-[WebTextIterator currentTextPointer]): Call TextIterator::deprecatedTextIteratorCharacters.
(-[WebTextIterator currentText]): Convert a the text to an NSString with TextIterator::text
instead of with TextIterator::characters/length.

Source/WebKit/win:

* WebCoreSupport/WebEditorClient.cpp:
(WebEditorClient::checkSpellingOfString): Use StringView.
(WebEditorClient::checkGrammarOfString): Ditto.
* WebCoreSupport/WebEditorClient.h: Ditto.

Source/WebKit/wince:

* WebCoreSupport/EditorClientWinCE.cpp:
(WebKit::EditorClientWinCE::checkSpellingOfString): Use StringView.
(WebKit::EditorClientWinCE::checkGrammarOfString): Ditto.
* WebCoreSupport/EditorClientWinCE.h: Ditto.

Source/WebKit2:

* WebProcess/InjectedBundle/API/mac/WKDOMTextIterator.mm:
(-[WKDOMTextIterator currentTextPointer]): Call TextIterator::deprecatedTextIteratorCharacters.

* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::checkSpellingOfString): Use StringView.
(WebKit::WebEditorClient::checkGrammarOfString): Ditto.
* WebProcess/WebCoreSupport/WebEditorClient.h: Ditto.

Source/WTF:

* WTF.xcodeproj/project.pbxproj: Added new source files.

* wtf/text/StringView.h: Added operator[], createCFStringWithoutCopying, and
createNSStringWithoutCopying.
* wtf/text/cf/StringViewCF.cpp:
(WTF::StringView::createCFStringWithoutCopying): Added.
* wtf/text/mac/StringViewObjC.mm:
(WTF::StringView::createNSString): Added.
(WTF::StringView::createNSStringWithoutCopying): Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@163712 268f45cc-cd09-0410-ab3c-d52691b4dbfc
53 files changed:
Source/WTF/ChangeLog
Source/WTF/WTF.xcodeproj/project.pbxproj
Source/WTF/wtf/text/StringView.h
Source/WTF/wtf/text/cf/StringViewCF.cpp [new file with mode: 0644]
Source/WTF/wtf/text/mac/StringViewObjC.mm [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/accessibility/AccessibilityNodeObject.cpp
Source/WebCore/accessibility/AccessibilityObject.cpp
Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm
Source/WebCore/bindings/objc/DOMUIKitExtensions.mm
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/PositionIterator.cpp
Source/WebCore/editing/ApplyBlockElementCommand.cpp
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/IndentOutdentCommand.cpp
Source/WebCore/editing/InsertListCommand.cpp
Source/WebCore/editing/TextCheckingHelper.cpp
Source/WebCore/editing/TextCheckingHelper.h
Source/WebCore/editing/TextIterator.cpp
Source/WebCore/editing/TextIterator.h
Source/WebCore/editing/VisibleSelection.cpp
Source/WebCore/editing/VisibleUnits.cpp
Source/WebCore/editing/markup.cpp
Source/WebCore/html/HTMLElement.cpp
Source/WebCore/html/HTMLTextAreaElement.cpp
Source/WebCore/loader/EmptyClients.h
Source/WebCore/page/Frame.cpp
Source/WebCore/platform/mac/HTMLConverter.mm
Source/WebCore/platform/text/TextBoundaries.cpp
Source/WebCore/platform/text/TextBoundaries.h
Source/WebCore/platform/text/TextCheckerClient.h
Source/WebCore/platform/text/mac/TextBoundaries.mm
Source/WebCore/rendering/RenderTextControl.cpp
Source/WebKit/efl/ChangeLog
Source/WebKit/efl/WebCoreSupport/EditorClientEfl.cpp
Source/WebKit/efl/WebCoreSupport/EditorClientEfl.h
Source/WebKit/gtk/ChangeLog
Source/WebKit/gtk/WebCoreSupport/TextCheckerClientGtk.cpp
Source/WebKit/gtk/WebCoreSupport/TextCheckerClientGtk.h
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebCoreSupport/WebEditorClient.h
Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm
Source/WebKit/mac/WebView/WebTextIterator.mm
Source/WebKit/win/ChangeLog
Source/WebKit/win/WebCoreSupport/WebEditorClient.cpp
Source/WebKit/win/WebCoreSupport/WebEditorClient.h
Source/WebKit/wince/ChangeLog
Source/WebKit/wince/WebCoreSupport/EditorClientWinCE.cpp
Source/WebKit/wince/WebCoreSupport/EditorClientWinCE.h
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKDOMTextIterator.mm
Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h