Commit a2cf5704 authored by andersca@apple.com's avatar andersca@apple.com

Add WTF::StringView and use it for grammar checking

https://bugs.webkit.org/show_bug.cgi?id=126644

Reviewed by Antti Koivisto.

Source/WebCore:

Use a StringView in TextCheckerClient::checkTextOfParagraph to avoid upconverting strings unnecessarily.

* editing/TextCheckingHelper.cpp:
(WebCore::checkTextOfParagraph):
Pass a StringView to TextCheckerClient::checkTextOfParagraph.

* loader/EmptyClients.h:
Update for TextCheckerClient changes.

* platform/text/TextCheckerClient.h:
Change TextCheckerClient::checkTextOfParagraph to take a StringView.

Source/WebKit/efl:

Update to match WebCore changes.

* WebCoreSupport/EditorClientEfl.h:
(WebCore::EditorClientEfl::checkTextOfParagraph):

Source/WebKit/mac:

* WebCoreSupport/WebEditorClient.h:
* WebCoreSupport/WebEditorClient.mm:
(WebEditorClient::checkTextOfParagraph):
Update to match the new signature.

(nsStringWithoutCopying):
New function that creates an NSString that references StringView data
without copying the data. (If this function proves to be useful elsewhere, it could
potentially be added to StringView).

Source/WebKit2:

Use a StringView and remove a FIXME.

* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::checkTextOfParagraph):
* WebProcess/WebCoreSupport/WebEditorClient.h:

Source/WTF:

Add a new StringView class which is an immutable reference to either an 8-bit or a 16-bit string.

This makes it easier to pass substrings around without having to either copy string data
or upconvert and use UChar pointers.

The StringView class is very loosely based on the std::string_view class which is proposed for a future version of C++,
see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3609.html for more details.

* GNUmakefile.list.am:
* WTF.vcxproj/WTF.vcxproj:
* WTF.vcxproj/WTF.vcxproj.filters:
* WTF.xcodeproj/project.pbxproj:
* wtf/CMakeLists.txt:
* wtf/Forward.h:
* wtf/text/StringView.h: Added.
(WTF::StringView::StringView):
(WTF::StringView::empty):
(WTF::StringView::characters8):
(WTF::StringView::characters16):
(WTF::StringView::isEmpty):
(WTF::StringView::length):
(WTF::StringView::is8Bit):
(WTF::StringView::substring):
(WTF::StringView::toString):
(WTF::StringView::toStringWithoutCopying):
(WTF::StringView::encodedCharacters):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@161518 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 55a22ffc
2014-01-08 Anders Carlsson <andersca@apple.com>
Add WTF::StringView and use it for grammar checking
https://bugs.webkit.org/show_bug.cgi?id=126644
Reviewed by Antti Koivisto.
Add a new StringView class which is an immutable reference to either an 8-bit or a 16-bit string.
This makes it easier to pass substrings around without having to either copy string data
or upconvert and use UChar pointers.
The StringView class is very loosely based on the std::string_view class which is proposed for a future version of C++,
see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3609.html for more details.
* GNUmakefile.list.am:
* WTF.vcxproj/WTF.vcxproj:
* WTF.vcxproj/WTF.vcxproj.filters:
* WTF.xcodeproj/project.pbxproj:
* wtf/CMakeLists.txt:
* wtf/Forward.h:
* wtf/text/StringView.h: Added.
(WTF::StringView::StringView):
(WTF::StringView::empty):
(WTF::StringView::characters8):
(WTF::StringView::characters16):
(WTF::StringView::isEmpty):
(WTF::StringView::length):
(WTF::StringView::is8Bit):
(WTF::StringView::substring):
(WTF::StringView::toString):
(WTF::StringView::toStringWithoutCopying):
(WTF::StringView::encodedCharacters):
2014-01-07 David Farler <dfarler@apple.com>
[ASAN] Building with trunk clang corrupts sandbox profile with comment from Compiler.h
......
......@@ -157,9 +157,9 @@ wtf_sources += \
Source/WTF/wtf/StreamBuffer.h \
Source/WTF/wtf/StringExtras.h \
Source/WTF/wtf/StringHashDumpContext.h \
Source/WTF/wtf/StringHasher.h \
Source/WTF/wtf/StringPrintStream.cpp \
Source/WTF/wtf/StringPrintStream.h \
Source/WTF/wtf/StringHasher.h \
Source/WTF/wtf/TCPackedCache.h \
Source/WTF/wtf/TCPageMap.h \
Source/WTF/wtf/TCSpinLock.h \
......@@ -241,6 +241,7 @@ wtf_sources += \
Source/WTF/wtf/text/StringImpl.h \
Source/WTF/wtf/text/StringOperators.h \
Source/WTF/wtf/text/StringStatics.cpp \
Source/WTF/wtf/text/StringView.h \
Source/WTF/wtf/text/TextPosition.h \
Source/WTF/wtf/text/WTFString.cpp \
Source/WTF/wtf/text/WTFString.h \
......
......@@ -291,6 +291,7 @@
<ClInclude Include="..\wtf\text\StringHash.h" />
<ClInclude Include="..\wtf\text\StringImpl.h" />
<ClInclude Include="..\wtf\text\StringOperators.h" />
<ClInclude Include="..\wtf\text\StringView.h" />
<ClInclude Include="..\wtf\text\WTFString.h" />
<ClInclude Include="..\wtf\Threading.h" />
<ClInclude Include="..\wtf\ThreadingPrimitives.h" />
......
......@@ -318,6 +318,9 @@
<ClInclude Include="..\wtf\text\StringOperators.h">
<Filter>text</Filter>
</ClInclude>
<ClInclude Include="..\wtf\text\StringView.h">
<Filter>wtf</Filter>
</ClInclude>
<ClInclude Include="..\wtf\text\WTFString.h">
<Filter>text</Filter>
</ClInclude>
......
......@@ -55,6 +55,7 @@
1A1D8B9E1731879800141DA4 /* FunctionDispatcher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A1D8B9D1731879800141DA4 /* FunctionDispatcher.cpp */; };
1A233C7D17DAA6E300A93ACF /* MallocPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A233C7C17DAA6E300A93ACF /* MallocPtr.h */; };
1A6BB769162F300500DD16DB /* StreamBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A6BB768162F300500DD16DB /* StreamBuffer.h */; };
1A6EB1E0187D0BD30030126F /* StringView.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A6EB1DF187D0BD30030126F /* StringView.h */; };
1FA47C8A152502DA00568D1B /* WebCoreThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1FA47C88152502DA00568D1B /* WebCoreThread.cpp */; };
1FA47C8B152502DA00568D1B /* WebCoreThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FA47C89152502DA00568D1B /* WebCoreThread.h */; };
26147B0A15DDCCDC00DDB907 /* IntegerToStringConversion.h in Headers */ = {isa = PBXBuildFile; fileRef = 26147B0815DDCCDC00DDB907 /* IntegerToStringConversion.h */; };
......@@ -322,6 +323,7 @@
1A233C7C17DAA6E300A93ACF /* MallocPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MallocPtr.h; sourceTree = "<group>"; };
1A3F6BE6174ADA2100B2EEA7 /* NeverDestroyed.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NeverDestroyed.h; sourceTree = "<group>"; };
1A6BB768162F300500DD16DB /* StreamBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamBuffer.h; sourceTree = "<group>"; };
1A6EB1DF187D0BD30030126F /* StringView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringView.h; sourceTree = "<group>"; };
1FA47C88152502DA00568D1B /* WebCoreThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebCoreThread.cpp; sourceTree = "<group>"; };
1FA47C89152502DA00568D1B /* WebCoreThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreThread.h; sourceTree = "<group>"; };
26147B0815DDCCDC00DDB907 /* IntegerToStringConversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntegerToStringConversion.h; sourceTree = "<group>"; };
......@@ -905,6 +907,7 @@
A8A4732C151A825B004123FF /* TextPosition.h */,
A8A4732D151A825B004123FF /* WTFString.cpp */,
A8A4732E151A825B004123FF /* WTFString.h */,
1A6EB1DF187D0BD30030126F /* StringView.h */,
);
path = text;
sourceTree = "<group>";
......@@ -1104,6 +1107,7 @@
A8A4742F151A825B004123FF /* TCPageMap.h in Headers */,
A8A47430151A825B004123FF /* TCSpinLock.h in Headers */,
A8A47432151A825B004123FF /* TCSystemAlloc.h in Headers */,
1A6EB1E0187D0BD30030126F /* StringView.h in Headers */,
A8A47433151A825B004123FF /* TemporaryChange.h in Headers */,
A8A47444151A825B004123FF /* TextPosition.h in Headers */,
A8A47447151A825B004123FF /* ThreadFunctionInvocation.h in Headers */,
......
......@@ -134,6 +134,7 @@ set(WTF_HEADERS
text/StringBuffer.h
text/StringHash.h
text/StringImpl.h
text/StringView.h
text/WTFString.h
threads/BinarySemaphore.h
......
......@@ -47,6 +47,7 @@ class PrintStream;
class String;
class StringBuilder;
class StringImpl;
class StringView;
}
......@@ -69,6 +70,7 @@ using WTF::String;
using WTF::StringBuffer;
using WTF::StringBuilder;
using WTF::StringImpl;
using WTF::StringView;
using WTF::Vector;
#endif // WTF_Forward_h
/*
* Copyright (C) 2014 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.
*/
#ifndef StringView_h
#define StringView_h
#include <wtf/text/WTFString.h>
namespace WTF {
// StringView is a non-owning reference to a string, similar to the proposed std::string_view.
// Whether the string is 8-bit or 16-bit is encoded in the upper bit of the length member.
// This means that strings longer than 2 Gigabytes can not be represented. If that turns out to be
// a problem we can investigate alternative solutions.
class StringView {
public:
StringView(const LChar *characters, unsigned length)
{
initialize(characters, length);
}
StringView(const UChar *characters, unsigned length)
{
initialize(characters, length);
}
StringView(const String& string)
: m_characters(nullptr)
, m_length(0)
{
if (!string.impl())
return;
if (string.is8Bit())
initialize(string.characters8(), string.length());
else
initialize(string.characters16(), string.length());
}
static StringView empty()
{
return StringView(reinterpret_cast<const LChar*>(""), 0);
}
const LChar* characters8() const
{
ASSERT(is8Bit());
return static_cast<const LChar*>(m_characters);
}
const UChar* characters16() const
{
ASSERT(!is8Bit());
return static_cast<const UChar*>(m_characters);
}
bool isEmpty() const { return !length(); }
unsigned length() const { return m_length & ~is16BitStringFlag; }
bool is8Bit() const { return !(m_length & is16BitStringFlag); }
StringView substring(unsigned start, unsigned length = std::numeric_limits<unsigned>::max()) const
{
if (start >= this->length())
return empty();
unsigned maxLength = this->length() - start;
if (length >= maxLength) {
if (!start)
return *this;
length = maxLength;
}
if (is8Bit())
return StringView(characters8() + start, length);
return StringView(characters16() + start, length);
}
String toString() const
{
if (is8Bit())
return String(characters8(), length());
return String(characters16(), length());
}
String toStringWithoutCopying() const
{
if (is8Bit())
return StringImpl::createWithoutCopying(characters8(), length());
return StringImpl::createWithoutCopying(characters16(), length());
}
private:
void initialize(const LChar *characters, unsigned length)
{
ASSERT(!(length & is16BitStringFlag));
m_characters = characters;
m_length = length;
}
void initialize(const UChar *characters, unsigned length)
{
ASSERT(!(length & is16BitStringFlag));
m_characters = characters;
m_length = is16BitStringFlag | length;
}
static const unsigned is16BitStringFlag = 1u << 31;
const void* m_characters;
unsigned m_length;
};
} // namespace WTF
using WTF::StringView;
#endif // StringView_h
2014-01-08 Anders Carlsson <andersca@apple.com>
Add WTF::StringView and use it for grammar checking
https://bugs.webkit.org/show_bug.cgi?id=126644
Reviewed by Antti Koivisto.
Use a StringView in TextCheckerClient::checkTextOfParagraph to avoid upconverting strings unnecessarily.
* editing/TextCheckingHelper.cpp:
(WebCore::checkTextOfParagraph):
Pass a StringView to TextCheckerClient::checkTextOfParagraph.
* loader/EmptyClients.h:
Update for TextCheckerClient changes.
* platform/text/TextCheckerClient.h:
Change TextCheckerClient::checkTextOfParagraph to take a StringView.
2014-01-08 Eric Carlson <eric.carlson@apple.com>
Unreviewed Windows build fix attempt after r161481.
......@@ -36,6 +36,7 @@
#include "TextIterator.h"
#include "VisiblePosition.h"
#include "VisibleUnits.h"
#include <wtf/text/StringView.h>
namespace WebCore {
......@@ -639,7 +640,7 @@ void checkTextOfParagraph(TextCheckerClient* client, const UChar* text, int leng
TextCheckingTypeMask checkingTypes, Vector<TextCheckingResult>& results)
{
#if USE(UNIFIED_TEXT_CHECKING)
client->checkTextOfParagraph(text, length, checkingTypes, results);
results = client->checkTextOfParagraph(StringView(text, length), checkingTypes);
#else
Vector<TextCheckingResult> spellingResult;
if (checkingTypes & TextCheckingTypeSpelling)
......
......@@ -42,6 +42,7 @@
#include "InspectorClient.h"
#include "Page.h"
#include "ResourceError.h"
#include <wtf/text/StringView.h>
/*
This file holds empty Client stubs for use by WebCore.
......@@ -425,7 +426,7 @@ public:
virtual void checkGrammarOfString(const UChar*, int, Vector<GrammarDetail>&, int*, int*) OVERRIDE { }
#if USE(UNIFIED_TEXT_CHECKING)
virtual void checkTextOfParagraph(const UChar*, int, TextCheckingTypeMask, Vector<TextCheckingResult>&) OVERRIDE { };
virtual Vector<TextCheckingResult> checkTextOfParagraph(StringView, TextCheckingTypeMask) OVERRIDE { return Vector<TextCheckingResult>(); }
#endif
virtual void getGuessesForWord(const String&, const String&, Vector<String>&) OVERRIDE { }
......
......@@ -49,7 +49,7 @@ public:
virtual void checkGrammarOfString(const UChar*, int length, Vector<GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength) = 0;
#if USE(UNIFIED_TEXT_CHECKING)
virtual void checkTextOfParagraph(const UChar* text, int length, TextCheckingTypeMask checkingTypes, Vector<TextCheckingResult>& results) = 0;
virtual Vector<TextCheckingResult> checkTextOfParagraph(StringView, TextCheckingTypeMask checkingTypes) = 0;
#endif
// For spellcheckers that support multiple languages, it's often important to be able to identify the language in order to
......
2014-01-08 Anders Carlsson <andersca@apple.com>
Add WTF::StringView and use it for grammar checking
https://bugs.webkit.org/show_bug.cgi?id=126644
Reviewed by Antti Koivisto.
Update to match WebCore changes.
* WebCoreSupport/EditorClientEfl.h:
(WebCore::EditorClientEfl::checkTextOfParagraph):
2014-01-05 Jinwoo Song <jinwoo7.song@samsung.com>
[EFL] Fix failing WebKit1 API test of ewk_view_setting_tiled_backing_store
......
......@@ -40,6 +40,7 @@
#include "TextCheckerClient.h"
#include <wtf/Deque.h>
#include <wtf/Forward.h>
#include <wtf/text/StringView.h>
struct Ewk_Should_Insert_Node_Event {
WebCore::Node* node;
......@@ -147,7 +148,7 @@ public:
virtual void setInputMethodState(bool enabled);
virtual void requestCheckingOfString(WTF::PassRefPtr<WebCore::TextCheckingRequest>) { }
#if USE(UNIFIED_TEXT_CHECKING)
virtual void checkTextOfParagraph(const UChar*, int, TextCheckingTypeMask, Vector<TextCheckingResult>&) { }
virtual Vector<TextCheckingResult> checkTextOfParagraph(StringView, TextCheckingTypeMask checkingTypes) { return Vector<TextCheckingResult>(); }
#endif
virtual TextCheckerClient* textChecker() { return this; }
......
2014-01-08 Anders Carlsson <andersca@apple.com>
Add WTF::StringView and use it for grammar checking
https://bugs.webkit.org/show_bug.cgi?id=126644
Reviewed by Antti Koivisto.
* WebCoreSupport/WebEditorClient.h:
* WebCoreSupport/WebEditorClient.mm:
(WebEditorClient::checkTextOfParagraph):
Update to match the new signature.
(nsStringWithoutCopying):
New function that creates an NSString that references StringView data
without copying the data. (If this function proves to be useful elsewhere, it could
potentially be added to StringView).
2014-01-02 Andy Estes <aestes@apple.com>
[iOS] Clean up some exported headers
......
......@@ -159,7 +159,7 @@ public:
virtual void checkSpellingOfString(const UChar*, int length, int* misspellingLocation, int* misspellingLength) OVERRIDE;
virtual WTF::String getAutoCorrectSuggestionForMisspelledWord(const WTF::String&) OVERRIDE;
virtual void checkGrammarOfString(const UChar*, int length, WTF::Vector<WebCore::GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength) OVERRIDE;
virtual void checkTextOfParagraph(const UChar* text, int length, WebCore::TextCheckingTypeMask checkingTypes, WTF::Vector<WebCore::TextCheckingResult>& results) OVERRIDE;
virtual Vector<WebCore::TextCheckingResult> checkTextOfParagraph(StringView, WebCore::TextCheckingTypeMask checkingTypes) OVERRIDE;
virtual void updateSpellingUIWithGrammarString(const WTF::String&, const WebCore::GrammarDetail&) OVERRIDE;
virtual void updateSpellingUIWithMisspelledWord(const WTF::String&) OVERRIDE;
virtual void showSpellingUI(bool show) OVERRIDE;
......@@ -173,7 +173,7 @@ public:
virtual WTF::String getAutoCorrectSuggestionForMisspelledWord(const WTF::String&) OVERRIDE { return ""; }
virtual void checkGrammarOfString(const UChar*, int length, WTF::Vector<WebCore::GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength) OVERRIDE { }
// Note: checkTextOfParagraph() is implemented.
virtual void checkTextOfParagraph(const UChar* text, int length, WebCore::TextCheckingTypeMask checkingTypes, WTF::Vector<WebCore::TextCheckingResult>& results) OVERRIDE;
virtual Vector<WebCore::TextCheckingResult> checkTextOfParagraph(StringView, WebCore::TextCheckingTypeMask checkingTypes) OVERRIDE;
virtual void updateSpellingUIWithGrammarString(const WTF::String&, const WebCore::GrammarDetail&) OVERRIDE { }
virtual void updateSpellingUIWithMisspelledWord(const WTF::String&) OVERRIDE { }
virtual void showSpellingUI(bool show) OVERRIDE { }
......
......@@ -71,6 +71,7 @@
#import <wtf/MainThread.h>
#import <wtf/PassRefPtr.h>
#import <wtf/RunLoop.h>
#import <wtf/text/StringView.h>
#import <wtf/text/WTFString.h>
#if PLATFORM(IOS)
......@@ -874,12 +875,14 @@ int WebEditorClient::pasteboardChangeCount()
return 0;
}
void WebEditorClient::checkTextOfParagraph(const UChar* text, int length, TextCheckingTypeMask checkingTypes, Vector<TextCheckingResult>& results)
void WebEditorClient::checkTextOfParagraph(StringView string, TextCheckingTypeMask checkingTypes)
{
ASSERT(checkingTypes & NSTextCheckingTypeSpelling);
NSString *textString = [[NSString alloc] initWithCharactersNoCopy:const_cast<UChar*>(text) length:length freeWhenDone:NO];
NSArray *incomingResults = [[m_webView _UIKitDelegateForwarder] checkSpellingOfString:textString];
[textString release];
NSArray *incomingResults = [[m_webView _UIKitDelegateForwarder] checkSpellingOfString:nsStringWithoutCopying(string).get()];
Vector<TextCheckingResult> results;
for (NSValue *incomingResult in incomingResults) {
NSRange resultRange = [incomingResult rangeValue];
ASSERT(resultRange.location != NSNotFound && resultRange.length > 0);
......@@ -889,9 +892,19 @@ void WebEditorClient::checkTextOfParagraph(const UChar* text, int length, TextCh
result.length = resultRange.length;
results.append(result);
}
return results;
}
#endif // PLATFORM(IOS)
static RetainPtr<NSString> nsStringWithoutCopying(StringView stringView)
{
if (stringView.is8Bit())
return adoptNS([[NSString alloc] initWithBytesNoCopy:const_cast<LChar*>(stringView.characters8()) length:stringView.length() encoding:NSISOLatin1StringEncoding freeWhenDone:NO]);
return adoptNS([[NSString alloc] initWithCharactersNoCopy:const_cast<unichar*>(stringView.characters16()) length:stringView.length() freeWhenDone:NO]);
}
#if !PLATFORM(IOS)
bool WebEditorClient::shouldEraseMarkersAfterChangeSelection(TextCheckingType type) const
{
......@@ -1042,12 +1055,13 @@ static Vector<TextCheckingResult> core(NSArray *incomingResults, TextCheckingTyp
return results;
}
void WebEditorClient::checkTextOfParagraph(const UChar* text, int length, TextCheckingTypeMask checkingTypes, Vector<TextCheckingResult>& results)
Vector<TextCheckingResult> WebEditorClient::checkTextOfParagraph(StringView string, TextCheckingTypeMask checkingTypes)
{
NSString *textString = [[NSString alloc] initWithCharactersNoCopy:const_cast<UChar*>(text) length:length freeWhenDone:NO];
NSArray *incomingResults = [[NSSpellChecker sharedSpellChecker] checkString:textString range:NSMakeRange(0, [textString length]) types:(checkingTypes|NSTextCheckingTypeOrthography) options:nil inSpellDocumentWithTag:spellCheckerDocumentTag() orthography:NULL wordCount:NULL];
[textString release];
results = core(incomingResults, checkingTypes);
auto textString = nsStringWithoutCopying(string);
NSArray *incomingResults = [[NSSpellChecker sharedSpellChecker] checkString:textString.get() range:NSMakeRange(0, [textString length]) types:(checkingTypes|NSTextCheckingTypeOrthography) options:nil inSpellDocumentWithTag:spellCheckerDocumentTag() orthography:NULL wordCount:NULL];
return core(incomingResults, checkingTypes);
}
void WebEditorClient::updateSpellingUIWithGrammarString(const String& badGrammarPhrase, const GrammarDetail& grammarDetail)
......
2014-01-08 Anders Carlsson <andersca@apple.com>
Add WTF::StringView and use it for grammar checking
https://bugs.webkit.org/show_bug.cgi?id=126644
Reviewed by Antti Koivisto.
Use a StringView and remove a FIXME.
* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::checkTextOfParagraph):
* WebProcess/WebCoreSupport/WebEditorClient.h:
2014-01-08 Zan Dobersek <zdobersek@igalia.com>
[Automake] Scripts for generated build targets do not necessarily produce their output
......
......@@ -51,6 +51,7 @@
#include <WebCore/UndoStep.h>
#include <WebCore/UserTypingGestureIndicator.h>
#include <wtf/NeverDestroyed.h>
#include <wtf/text/StringView.h>
using namespace WebCore;
using namespace HTMLNames;
......@@ -442,10 +443,13 @@ void WebEditorClient::checkGrammarOfString(const UChar* text, int length, Vector
}
#if USE(UNIFIED_TEXT_CHECKING)
void WebEditorClient::checkTextOfParagraph(const UChar* text, int length, WebCore::TextCheckingTypeMask checkingTypes, Vector<TextCheckingResult>& results)
Vector<TextCheckingResult> WebEditorClient::checkTextOfParagraph(StringView stringView, WebCore::TextCheckingTypeMask checkingTypes)
{
// FIXME: It would be nice if we wouldn't have to copy the text here.
m_page->sendSync(Messages::WebPageProxy::CheckTextOfParagraph(String(text, length), checkingTypes), Messages::WebPageProxy::CheckTextOfParagraph::Reply(results));
Vector<TextCheckingResult> results;
m_page->sendSync(Messages::WebPageProxy::CheckTextOfParagraph(stringView.toStringWithoutCopying(), checkingTypes), Messages::WebPageProxy::CheckTextOfParagraph::Reply(results));
return results;
}
#endif
......
......@@ -139,7 +139,7 @@ private:
virtual String getAutoCorrectSuggestionForMisspelledWord(const String& misspelledWord) OVERRIDE;
virtual void checkGrammarOfString(const UChar*, int length, Vector<WebCore::GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength) OVERRIDE;
#if USE(UNIFIED_TEXT_CHECKING)
virtual void checkTextOfParagraph(const UChar* text, int length, WebCore::TextCheckingTypeMask checkingTypes, Vector<WebCore::TextCheckingResult>& results) OVERRIDE;
virtual Vector<WebCore::TextCheckingResult> checkTextOfParagraph(StringView, WebCore::TextCheckingTypeMask checkingTypes) OVERRIDE;
#endif
virtual void updateSpellingUIWithGrammarString(const String&, const WebCore::GrammarDetail&) OVERRIDE;
virtual void updateSpellingUIWithMisspelledWord(const String&) OVERRIDE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment