Changeset 165692 in webkit
- Timestamp:
- Mar 15, 2014 11:22:02 PM (10 years ago)
- Location:
- trunk/Source
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r165691 r165692 1 2014-03-15 Darin Adler <darin@apple.com> 2 3 Remove all uses of deprecatedCharacters from WebKit2 4 https://bugs.webkit.org/show_bug.cgi?id=130197 5 6 Reviewed by Andreas Kling. 7 8 * wtf/text/StringView.h: Added new getCharactersWithUpconvert and upconvertedCharacters 9 functions. These are useful for callers that need UTF-16. 10 1 11 2014-03-15 Darin Adler <darin@apple.com> 2 12 -
trunk/Source/WTF/wtf/text/StringView.h
r163727 r165692 86 86 } 87 87 88 void getCharactersWithUpconvert(LChar*) const; 89 void getCharactersWithUpconvert(UChar*) const; 90 91 class UpconvertedCharacters { 92 public: 93 explicit UpconvertedCharacters(const StringView&); 94 operator const UChar*() const { return m_characters; } 95 const UChar* get() const { return m_characters; } 96 private: 97 Vector<UChar, 32> m_upconvertedCharacters; 98 const UChar* m_characters; 99 }; 100 UpconvertedCharacters upconvertedCharacters() const { return UpconvertedCharacters(*this); } 101 88 102 bool isNull() const { return !m_characters; } 89 103 bool isEmpty() const { return !length(); } … … 177 191 }; 178 192 193 inline void StringView::getCharactersWithUpconvert(LChar* destination) const 194 { 195 ASSERT(is8Bit()); 196 memcpy(destination, characters8(), length()); 197 } 198 199 inline void StringView::getCharactersWithUpconvert(UChar* destination) const 200 { 201 if (is8Bit()) { 202 const LChar* characters8 = this->characters8(); 203 unsigned length = this->length(); 204 for (unsigned i = 0; i < length; ++i) 205 destination[i] = characters8[i]; 206 return; 207 } 208 memcpy(destination, characters16(), length() * sizeof(UChar)); 209 } 210 211 inline StringView::UpconvertedCharacters::UpconvertedCharacters(const StringView& string) 212 { 213 if (!string.is8Bit()) { 214 m_characters = string.characters16(); 215 return; 216 } 217 const LChar* characters8 = string.characters8(); 218 unsigned length = string.length(); 219 m_upconvertedCharacters.reserveInitialCapacity(length); 220 for (unsigned i = 0; i < length; ++i) 221 m_upconvertedCharacters.uncheckedAppend(characters8[i]); 222 m_characters = m_upconvertedCharacters.data(); 223 } 224 179 225 } // namespace WTF 180 226 -
trunk/Source/WebKit2/ChangeLog
r165685 r165692 1 2014-03-15 Darin Adler <darin@apple.com> 2 3 Remove all uses of deprecatedCharacters from WebKit2 4 https://bugs.webkit.org/show_bug.cgi?id=130197 5 6 Reviewed by Andreas Kling. 7 8 * Shared/APIString.h: Rewrote getCharacters to use StringView, 9 substring, and getCharactersWithUpconvert. Added an 8-bit case 10 to getUTF8CString. 11 12 * Shared/Plugins/Netscape/x11/NetscapePluginModuleX11.cpp: 13 (WebKit::writeByte): Added. 14 (WebKit::writeCharacter): Added. 15 (WebKit::writeLine): Added. Uses operator[] instead of characters16 to get 16 the UTF-16 characters out of the string. 17 (WebKit::NetscapePluginModule::scanPlugin): Replaced code that writes out 18 text to stdout with much simpler version using the functions above. 19 20 * UIProcess/TextChecker.h: Changed text arguments to use StringView instead 21 of UChar/int pairs. 22 23 * UIProcess/WebPageProxy.cpp: 24 (WebKit::WebPageProxy::internalShowContextMenu): Updated to pass StringView. 25 26 * UIProcess/efl/TextCheckerEfl.cpp: 27 (WebKit::nextWordOffset): Changed function to use StringView and unsigned. 28 (WebKit::TextChecker::checkTextOfParagraph): Changed to use StringView and 29 substring. 30 (WebKit::TextChecker::checkSpellingOfString): Ditto. 31 (WebKit::TextChecker::checkGrammarOfString): Ditto. 32 (WebKit::TextChecker::requestCheckingOfString): Pass in a StringView, so no 33 need to call deprecatedCharacters. 34 35 * UIProcess/ios/TextCheckerIOS.mm: 36 (WebKit::TextChecker::checkTextOfParagraph): Changed to take StringView. 37 (WebKit::TextChecker::checkSpellingOfString): Ditto. 38 (WebKit::TextChecker::checkGrammarOfString): Ditto. 39 40 * UIProcess/mac/TextCheckerMac.mm: 41 (WebKit::TextChecker::checkTextOfParagraph): Changed to take StringView and 42 use StringView::createNSStringWithoutCopying. 43 (WebKit::TextChecker::checkSpellingOfString): CHanged to take StringView. 44 (WebKit::TextChecker::checkGrammarOfString): Ditto. 45 46 * WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm: 47 (WebKit::convertStringToKeyCodes): Changed to take StringView and use 48 upconvertedCharacters instead of deprecatedCharacters. Also use move instead 49 of swap. 50 (WebKit::NetscapePlugin::sendComplexTextInput): Updated to new style for loop. 51 52 * WebProcess/WebPage/EncoderAdapter.cpp: 53 (WebKit::EncoderAdapter::encodeString): Use StringView::upconvertedCharacters 54 instead of String::deprecatedCharacters. 55 1 56 2014-03-15 David Kilzer <ddkilzer@apple.com> 2 57 -
trunk/Source/WebKit2/Shared/APIString.h
r163860 r165692 32 32 #include <JavaScriptCore/OpaqueJSString.h> 33 33 #include <wtf/PassRefPtr.h> 34 #include <wtf/text/StringView.h> 34 35 #include <wtf/text/WTFString.h> 35 36 #include <wtf/unicode/UTF8.h> … … 69 70 size_t getCharacters(UChar* buffer, size_t bufferLength) const 70 71 { 71 if (!bufferLength) 72 return 0; 73 bufferLength = std::min(bufferLength, static_cast<size_t>(m_string.length())); 74 memcpy(buffer, m_string.deprecatedCharacters(), bufferLength * sizeof(UChar)); 75 return bufferLength; 72 unsigned unsignedBufferLength = std::min<size_t>(bufferLength, std::numeric_limits<unsigned>::max()); 73 StringView substring = StringView(m_string).substring(0, unsignedBufferLength); 74 substring.getCharactersWithUpconvert(buffer); 75 return substring.length(); 76 76 } 77 77 … … 82 82 return 0; 83 83 char* p = buffer; 84 const UChar* d = m_string.deprecatedCharacters(); 85 WTF::Unicode::ConversionResult result = WTF::Unicode::convertUTF16ToUTF8(&d, d + m_string.length(), &p, p + bufferSize - 1, /* strict */ true); 86 *p++ = '\0'; 84 WTF::Unicode::ConversionResult result; 85 if (m_string.is8Bit()) { 86 const LChar* characters = m_string.characters8(); 87 result = WTF::Unicode::convertLatin1ToUTF8(&characters, characters + m_string.length(), &p, p + bufferSize - 1); 88 } else { 89 const UChar* characters = m_string.characters16(); 90 result = WTF::Unicode::convertUTF16ToUTF8(&characters, characters + m_string.length(), &p, p + bufferSize - 1, /* strict */ true); 91 } 87 92 if (result != WTF::Unicode::conversionOK && result != WTF::Unicode::targetExhausted) 88 93 return 0; 94 *p++ = '\0'; 89 95 return p - buffer; 90 96 } -
trunk/Source/WebKit2/Shared/Plugins/Netscape/x11/NetscapePluginModuleX11.cpp
r164808 r165692 186 186 } 187 187 188 static String truncateToSingleLine(const String& string) 189 { 190 unsigned oldLength = string.length(); 191 UChar* buffer; 192 String stringBuffer(StringImpl::createUninitialized(oldLength + 1, buffer)); 193 194 unsigned newLength = 0; 195 const UChar* start = string.deprecatedCharacters(); 196 for (const UChar* c = start; c < start + oldLength; ++c) { 197 if (*c != UChar('\n')) 198 buffer[newLength++] = *c; 199 } 200 buffer[newLength++] = UChar('\n'); 201 202 String result = (newLength == oldLength + 1) ? stringBuffer : String(stringBuffer.characters16(), newLength); 203 ASSERT(result.endsWith(UChar('\n'))); 204 return result; 188 static void writeByte(char byte) 189 { 190 int result; 191 while ((result = fputc(byte, stdout)) == EOF && errno == EINTR) { } 192 ASSERT(result != EOF); 193 } 194 195 static void writeCharacter(UChar character) 196 { 197 writeByte(reinterpret_cast<const char*>(&character)[0]); 198 writeByte(reinterpret_cast<const char*>(&character)[1]); 199 } 200 201 static void writeLine(const String& line) 202 { 203 unsigned length = line.length(); 204 for (unsigned i = 0; i < length; ++i) { 205 UChar character = line[i]; 206 if (character != '\n') 207 writeCharacter(character); 208 } 209 writeCharacter('\n'); 205 210 } 206 211 … … 228 233 229 234 // Write data to standard output for the UI process. 230 String output[3] = { 231 truncateToSingleLine(metaData.name), 232 truncateToSingleLine(metaData.description), 233 truncateToSingleLine(metaData.mimeDescription) 234 }; 235 for (unsigned i = 0; i < 3; ++i) { 236 const String& line = output[i]; 237 const char* current = reinterpret_cast<const char*>(line.characters16()); 238 const char* end = reinterpret_cast<const char*>(line.characters16()) + (line.length() * sizeof(UChar)); 239 while (current < end) { 240 int result; 241 while ((result = fputc(*current, stdout)) == EOF && errno == EINTR) { } 242 ASSERT(result != EOF); 243 ++current; 244 } 245 } 235 writeLine(metaData.name); 236 writeLine(metaData.description); 237 writeLine(metaData.mimeDescription); 246 238 247 239 fflush(stdout); -
trunk/Source/WebKit2/UIProcess/TextChecker.h
r164172 r165692 68 68 static void closeSpellDocumentWithTag(int64_t); 69 69 #if USE(UNIFIED_TEXT_CHECKING) 70 static Vector<WebCore::TextCheckingResult> checkTextOfParagraph(int64_t spellDocumentTag, const UChar* text, int length, uint64_t checkingTypes);70 static Vector<WebCore::TextCheckingResult> checkTextOfParagraph(int64_t spellDocumentTag, StringView text, uint64_t checkingTypes); 71 71 #endif 72 static void checkSpellingOfString(int64_t spellDocumentTag, const UChar* text, uint32_t length, int32_t& misspellingLocation, int32_t& misspellingLength);73 static void checkGrammarOfString(int64_t spellDocumentTag, const UChar* text, uint32_t length, Vector<WebCore::GrammarDetail>&, int32_t& badGrammarLocation, int32_t& badGrammarLength);72 static void checkSpellingOfString(int64_t spellDocumentTag, StringView text, int32_t& misspellingLocation, int32_t& misspellingLength); 73 static void checkGrammarOfString(int64_t spellDocumentTag, StringView text, Vector<WebCore::GrammarDetail>&, int32_t& badGrammarLocation, int32_t& badGrammarLength); 74 74 static bool spellingUIIsShowing(); 75 75 static void toggleSpellingUIIsShowing(); -
trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp
r165577 r165692 3470 3470 void WebPageProxy::checkTextOfParagraph(const String& text, uint64_t checkingTypes, Vector<TextCheckingResult>& results) 3471 3471 { 3472 results = TextChecker::checkTextOfParagraph(spellDocumentTag(), text .deprecatedCharacters(), text.length(), checkingTypes);3472 results = TextChecker::checkTextOfParagraph(spellDocumentTag(), text, checkingTypes); 3473 3473 } 3474 3474 #endif … … 3476 3476 void WebPageProxy::checkSpellingOfString(const String& text, int32_t& misspellingLocation, int32_t& misspellingLength) 3477 3477 { 3478 TextChecker::checkSpellingOfString(spellDocumentTag(), text .deprecatedCharacters(), text.length(), misspellingLocation, misspellingLength);3478 TextChecker::checkSpellingOfString(spellDocumentTag(), text, misspellingLocation, misspellingLength); 3479 3479 } 3480 3480 3481 3481 void WebPageProxy::checkGrammarOfString(const String& text, Vector<GrammarDetail>& grammarDetails, int32_t& badGrammarLocation, int32_t& badGrammarLength) 3482 3482 { 3483 TextChecker::checkGrammarOfString(spellDocumentTag(), text .deprecatedCharacters(), text.length(), grammarDetails, badGrammarLocation, badGrammarLength);3483 TextChecker::checkGrammarOfString(spellDocumentTag(), text, grammarDetails, badGrammarLocation, badGrammarLength); 3484 3484 } 3485 3485 -
trunk/Source/WebKit2/UIProcess/efl/TextCheckerEfl.cpp
r163298 r165692 121 121 122 122 #if ENABLE(SPELLCHECK) 123 static int nextWordOffset(const UChar* text, int length, intcurrentOffset)123 static unsigned nextWordOffset(StringView text, unsigned currentOffset) 124 124 { 125 125 // FIXME: avoid creating textIterator object here, it could be passed as a parameter. … … 128 128 // For many word separators, the method doesn't properly determine the boundaries 129 129 // without resetting the iterator. 130 TextBreakIterator* textIterator = wordBreakIterator( StringView(text, length));130 TextBreakIterator* textIterator = wordBreakIterator(text); 131 131 if (!textIterator) 132 132 return currentOffset; 133 133 134 intwordOffset = currentOffset;135 while (wordOffset < length&& isTextBreak(textIterator, wordOffset))134 unsigned wordOffset = currentOffset; 135 while (wordOffset < text.length() && isTextBreak(textIterator, wordOffset)) 136 136 ++wordOffset; 137 137 … … 149 149 150 150 #if USE(UNIFIED_TEXT_CHECKING) 151 Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t spellDocumentTag, const UChar* text, int length, uint64_t checkingTypes)151 Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t spellDocumentTag, StringView text, uint64_t checkingTypes) 152 152 { 153 153 Vector<TextCheckingResult> paragraphCheckingResult; 154 154 #if ENABLE(SPELLCHECK) 155 155 if (checkingTypes & TextCheckingTypeSpelling) { 156 TextBreakIterator* textIterator = wordBreakIterator( StringView(text, length));156 TextBreakIterator* textIterator = wordBreakIterator(text); 157 157 if (!textIterator) 158 158 return paragraphCheckingResult; … … 160 160 // Omit the word separators at the beginning/end of the text to don't unnecessarily 161 161 // involve the client to check spelling for them. 162 int offset = nextWordOffset(text, length, 0);163 int lengthStrip = length;162 unsigned offset = nextWordOffset(text, 0); 163 unsigned lengthStrip = text.length(); 164 164 while (lengthStrip > 0 && isTextBreak(textIterator, lengthStrip - 1)) 165 165 --lengthStrip; 166 166 167 while (offset >= 0 && offset< lengthStrip) {167 while (offset < lengthStrip) { 168 168 int32_t misspellingLocation = -1; 169 169 int32_t misspellingLength = 0; 170 checkSpellingOfString(spellDocumentTag, text + offset, lengthStrip - offset, misspellingLocation, misspellingLength);170 checkSpellingOfString(spellDocumentTag, text.substring(offset, lengthStrip - offset), misspellingLocation, misspellingLength); 171 171 if (!misspellingLength) 172 172 break; … … 179 179 offset += misspellingLocation + misspellingLength; 180 180 // Generally, we end up checking at the word separator, move to the adjacent word. 181 offset = nextWordOffset(text , lengthStrip, offset);181 offset = nextWordOffset(text.substring(0, lengthStrip), offset); 182 182 } 183 183 } … … 192 192 #endif 193 193 194 void TextChecker::checkSpellingOfString(int64_t spellDocumentTag, const UChar* text, uint32_t length, int32_t& misspellingLocation, int32_t& misspellingLength)195 { 196 #if ENABLE(SPELLCHECK) 197 WebTextChecker::shared()->client().checkSpellingOfString(spellDocumentTag, String(text, length), misspellingLocation, misspellingLength);194 void TextChecker::checkSpellingOfString(int64_t spellDocumentTag, StringView text, int32_t& misspellingLocation, int32_t& misspellingLength) 195 { 196 #if ENABLE(SPELLCHECK) 197 WebTextChecker::shared()->client().checkSpellingOfString(spellDocumentTag, text.toStringWithoutCopying(), misspellingLocation, misspellingLength); 198 198 #else 199 199 UNUSED_PARAM(spellDocumentTag); … … 205 205 } 206 206 207 void TextChecker::checkGrammarOfString(int64_t, const UChar*, uint32_t, Vector<GrammarDetail>&, int32_t&, int32_t&)207 void TextChecker::checkGrammarOfString(int64_t, StringView, Vector<GrammarDetail>&, int32_t&, int32_t&) 208 208 { 209 209 notImplemented(); … … 272 272 ASSERT(request.mask() != TextCheckingTypeNone); 273 273 274 String text = request.text(); 275 Vector<TextCheckingResult> result = checkTextOfParagraph(completion->spellDocumentTag(), text.deprecatedCharacters(), text.length(), request.mask()); 276 277 completion->didFinishCheckingText(result); 274 completion->didFinishCheckingText(checkTextOfParagraph(completion->spellDocumentTag(), request.text(), request.mask())); 278 275 #else 279 276 UNUSED_PARAM(completion); -
trunk/Source/WebKit2/UIProcess/ios/TextCheckerIOS.mm
r164776 r165692 31 31 #import "TextCheckerState.h" 32 32 #import <WebCore/NotImplemented.h> 33 #import <wtf/text/StringView.h> 33 34 34 35 using namespace WebCore; … … 132 133 #if USE(UNIFIED_TEXT_CHECKING) 133 134 134 Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t, const UChar*, int, uint64_t)135 Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t, StringView, uint64_t) 135 136 { 136 137 notImplemented(); … … 140 141 #endif 141 142 142 void TextChecker::checkSpellingOfString(int64_t, const UChar*, uint32_t, int32_t&, int32_t&)143 void TextChecker::checkSpellingOfString(int64_t, StringView, int32_t&, int32_t&) 143 144 { 144 // Mac uses checkTextOfParagraph instead.145 145 notImplemented(); 146 146 } 147 147 148 void TextChecker::checkGrammarOfString(int64_t, const UChar*, uint32_t, Vector<WebCore::GrammarDetail>&, int32_t&, int32_t&)148 void TextChecker::checkGrammarOfString(int64_t, StringView, Vector<WebCore::GrammarDetail>&, int32_t&, int32_t&) 149 149 { 150 // Mac uses checkTextOfParagraph instead.151 150 notImplemented(); 152 151 } -
trunk/Source/WebKit2/UIProcess/mac/TextCheckerMac.mm
r164776 r165692 32 32 #import <WebCore/NotImplemented.h> 33 33 #import <wtf/RetainPtr.h> 34 #import <wtf/text/StringView.h> 34 35 35 36 @interface NSSpellChecker (WebNSSpellCheckerDetails) … … 296 297 #if USE(UNIFIED_TEXT_CHECKING) 297 298 298 Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t spellDocumentTag, const UChar* text, int length, uint64_t checkingTypes)299 Vector<TextCheckingResult> TextChecker::checkTextOfParagraph(int64_t spellDocumentTag, StringView text, uint64_t checkingTypes) 299 300 { 300 301 Vector<TextCheckingResult> results; 301 302 302 RetainPtr<NSString> textString = adoptNS([[NSString alloc] initWithCharactersNoCopy:const_cast<UChar*>(text) length:length freeWhenDone:NO]);303 NSArray *incomingResults = [[NSSpellChecker sharedSpellChecker] checkString:textString 304 range:NSMakeRange(0, length)303 RetainPtr<NSString> textString = text.createNSStringWithoutCopying(); 304 NSArray *incomingResults = [[NSSpellChecker sharedSpellChecker] checkString:textString.get() 305 range:NSMakeRange(0, text.length()) 305 306 types:checkingTypes | NSTextCheckingTypeOrthography 306 307 options:nil … … 385 386 #endif 386 387 387 void TextChecker::checkSpellingOfString(int64_t, const UChar*, uint32_t, int32_t&, int32_t&)388 void TextChecker::checkSpellingOfString(int64_t, StringView, int32_t&, int32_t&) 388 389 { 389 390 // Mac uses checkTextOfParagraph instead. … … 391 392 } 392 393 393 void TextChecker::checkGrammarOfString(int64_t, const UChar*, uint32_t, Vector<WebCore::GrammarDetail>&, int32_t&, int32_t&)394 void TextChecker::checkGrammarOfString(int64_t, StringView, Vector<WebCore::GrammarDetail>&, int32_t&, int32_t&) 394 395 { 395 396 // Mac uses checkTextOfParagraph instead. -
trunk/Source/WebKit2/WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm
r163297 r165692 964 964 965 965 #ifndef NP_NO_CARBON 966 static bool convertStringToKeyCodes( const String&string, ScriptCode scriptCode, Vector<UInt8>& keyCodes)966 static bool convertStringToKeyCodes(StringView string, ScriptCode scriptCode, Vector<UInt8>& keyCodes) 967 967 { 968 968 // Create the mapping. … … 974 974 mapping.unicodeEncoding = CreateTextEncoding(kTextEncodingUnicodeDefault, kTextEncodingDefaultVariant, kTextEncodingDefaultFormat); 975 975 mapping.mappingVersion = kUnicodeUseLatestMapping; 976 976 977 977 // Create the converter 978 978 UnicodeToTextInfo textInfo; 979 979 980 980 if (CreateUnicodeToTextInfo(&mapping, &textInfo) != noErr) 981 981 return false; 982 982 983 983 ByteCount inputLength = string.length() * sizeof(UniChar); 984 984 ByteCount inputRead; … … 987 987 988 988 Vector<UInt8> outputData(maxOutputLength); 989 OSStatus status = ConvertFromUnicodeToText(textInfo, inputLength, string. deprecatedCharacters(), kNilOptions, 0, 0, 0, 0, maxOutputLength, &inputRead, &outputLength, outputData.data());989 OSStatus status = ConvertFromUnicodeToText(textInfo, inputLength, string.upconvertedCharacters(), kNilOptions, 0, 0, 0, 0, maxOutputLength, &inputRead, &outputLength, outputData.data()); 990 990 991 991 DisposeUnicodeToTextInfo(&textInfo); … … 994 994 return false; 995 995 996 outputData.swap(keyCodes);996 keyCodes = std::move(outputData); 997 997 return true; 998 998 } … … 1035 1035 event.modifiers = 0; 1036 1036 1037 for ( size_t i = 0; i < keyCodes.size(); i++) {1038 event.message = keyCode s[i];1037 for (auto& keyCode : keyCodes) { 1038 event.message = keyCode; 1039 1039 NPP_HandleEvent(&event); 1040 1040 } -
trunk/Source/WebKit2/WebProcess/WebPage/EncoderAdapter.cpp
r161851 r165692 29 29 #include "DataReference.h" 30 30 #include "WebCoreArgumentCoders.h" 31 #include <wtf/text/ WTFString.h>31 #include <wtf/text/StringView.h> 32 32 33 33 namespace WebKit { … … 109 109 uint64_t lengthInBytes = length * sizeof(UChar); 110 110 m_encoder << lengthInBytes; 111 m_encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>( value.deprecatedCharacters()), length * sizeof(UChar), alignof(UChar));111 m_encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(StringView(value).upconvertedCharacters().get()), length * sizeof(UChar), alignof(UChar)); 112 112 } 113 113
Note: See TracChangeset
for help on using the changeset viewer.