Title: [164945] trunk/Source
Revision
164945
Author
[email protected]
Date
2014-03-02 11:36:12 -0800 (Sun, 02 Mar 2014)

Log Message

Change public text iterator API implementations to not depend on 16-bit character pointers
https://bugs.webkit.org/show_bug.cgi?id=129566

Reviewed by Anders Carlsson.

Source/WebKit/mac:

* WebView/WebTextIterator.mm:
(-[WebTextIterator initWithRange:]): Use make_unique instead of adoptPtr.
(-[WebTextIterator advance]): Clear out the upconverted text since we are moving on to the
next text.
(-[WebTextIterator currentTextPointer]): Upconvert if we have 8-bit text.
(-[WebTextIterator currentTextLength]): Call TextIterator::text().length() since we will
probably be removing TextIterator::length eventually.

Source/WebKit2:

* WebView/WebTextIterator.mm:
(-[WKDOMTextIterator initWithRange:]): Use make_unique instead of adoptPtr.
(-[WKDOMTextIterator advance]): Clear out the upconverted text since we are moving on to the
next text.
(-[WKDOMTextIterator currentTextPointer]): Upconvert if we have 8-bit text.
(-[WKDOMTextIterator currentTextLength]): Call TextIterator::text().length() since we will
probably be removing TextIterator::length eventually.

* WebProcess/WebCoreSupport/WebEditorClient.cpp: Removed unneded include of TextIterator.h.
* WebProcess/WebPage/WebPage.cpp: Ditto.

Modified Paths

Diff

Modified: trunk/Source/WebKit/mac/ChangeLog (164944 => 164945)


--- trunk/Source/WebKit/mac/ChangeLog	2014-03-02 18:25:32 UTC (rev 164944)
+++ trunk/Source/WebKit/mac/ChangeLog	2014-03-02 19:36:12 UTC (rev 164945)
@@ -1,3 +1,18 @@
+2014-03-02  Darin Adler  <[email protected]>
+
+        Change public text iterator API implementations to not depend on 16-bit character pointers
+        https://bugs.webkit.org/show_bug.cgi?id=129566
+
+        Reviewed by Anders Carlsson.
+
+        * WebView/WebTextIterator.mm:
+        (-[WebTextIterator initWithRange:]): Use make_unique instead of adoptPtr.
+        (-[WebTextIterator advance]): Clear out the upconverted text since we are moving on to the
+        next text.
+        (-[WebTextIterator currentTextPointer]): Upconvert if we have 8-bit text.
+        (-[WebTextIterator currentTextLength]): Call TextIterator::text().length() since we will
+        probably be removing TextIterator::length eventually.
+
 2014-03-01  Pratik Solanki  <[email protected]>
 
         [iOS] selectionImageForcingBlackText should return autoreleased object

Modified: trunk/Source/WebKit/mac/WebView/WebTextIterator.mm (164944 => 164945)


--- trunk/Source/WebKit/mac/WebView/WebTextIterator.mm	2014-03-02 18:25:32 UTC (rev 164944)
+++ trunk/Source/WebKit/mac/WebView/WebTextIterator.mm	2014-03-02 19:36:12 UTC (rev 164945)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2008, 2009, 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
@@ -35,12 +35,10 @@
 #import <wtf/RunLoop.h>
 #import <wtf/Vector.h>
 
-using namespace JSC;
-using namespace WebCore;
-
 @interface WebTextIteratorPrivate : NSObject {
 @public
-    OwnPtr<TextIterator> _textIterator;
+    std::unique_ptr<WebCore::TextIterator> _textIterator;
+    Vector<unichar> _upconvertedText;
 }
 @end
 
@@ -73,13 +71,14 @@
         return self;
     
     _private = [[WebTextIteratorPrivate alloc] init];
-    _private->_textIterator = adoptPtr(new TextIterator(core(range)));
+    _private->_textIterator = std::make_unique<WebCore::TextIterator>(core(range));
     return self;
 }
 
 - (void)advance
 {
     _private->_textIterator->advance();
+    _private->_upconvertedText.shrink(0);
 }
 
 - (BOOL)atEnd
@@ -92,14 +91,24 @@
     return kit(_private->_textIterator->range().get());
 }
 
-- (const unichar *)currentTextPointer
+// FIXME: Consider deprecating this method and creating one that does not require copying 8-bit characters.
+- (const unichar*)currentTextPointer
 {
-    return _private->_textIterator->deprecatedTextIteratorCharacters();
+    StringView text = _private->_textIterator->text();
+    unsigned length = text.length();
+    if (!length)
+        return nullptr;
+    if (!text.is8Bit())
+        return text.characters16();
+    if (_private->_upconvertedText.isEmpty())
+        _private->_upconvertedText.appendRange(text.characters8(), text.characters8() + length);
+    ASSERT(_private->_upconvertedText.size() == text.length());
+    return _private->_upconvertedText.data();
 }
 
 - (NSUInteger)currentTextLength
 {
-    return _private->_textIterator->length();
+    return _private->_textIterator->text().length();
 }
 
 @end

Modified: trunk/Source/WebKit2/ChangeLog (164944 => 164945)


--- trunk/Source/WebKit2/ChangeLog	2014-03-02 18:25:32 UTC (rev 164944)
+++ trunk/Source/WebKit2/ChangeLog	2014-03-02 19:36:12 UTC (rev 164945)
@@ -1,3 +1,21 @@
+2014-03-02  Darin Adler  <[email protected]>
+
+        Change public text iterator API implementations to not depend on 16-bit character pointers
+        https://bugs.webkit.org/show_bug.cgi?id=129566
+
+        Reviewed by Anders Carlsson.
+
+        * WebView/WebTextIterator.mm:
+        (-[WKDOMTextIterator initWithRange:]): Use make_unique instead of adoptPtr.
+        (-[WKDOMTextIterator advance]): Clear out the upconverted text since we are moving on to the
+        next text.
+        (-[WKDOMTextIterator currentTextPointer]): Upconvert if we have 8-bit text.
+        (-[WKDOMTextIterator currentTextLength]): Call TextIterator::text().length() since we will
+        probably be removing TextIterator::length eventually.
+
+        * WebProcess/WebCoreSupport/WebEditorClient.cpp: Removed unneded include of TextIterator.h.
+        * WebProcess/WebPage/WebPage.cpp: Ditto.
+
 2014-03-02  Carlos Garcia Campos  <[email protected]>
 
         [GTK] Make impossible to build with <webkit2/webkit2.h> and <webkit2/webkit-web-extension.h> included together

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKDOMTextIterator.mm (164944 => 164945)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKDOMTextIterator.mm	2014-03-02 18:25:32 UTC (rev 164944)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKDOMTextIterator.mm	2014-03-02 19:36:12 UTC (rev 164945)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2012, 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
@@ -31,11 +31,11 @@
 #import "WKDOMInternals.h"
 #import "WKDOMRange.h"
 #import <WebCore/TextIterator.h>
-#import <wtf/OwnPtr.h>
 
 @interface WKDOMTextIterator () {
 @public
-    OwnPtr<WebCore::TextIterator> _textIterator;
+    std::unique_ptr<WebCore::TextIterator> _textIterator;
+    Vector<unichar> _upconvertedText;
 }
 @end
 
@@ -47,14 +47,14 @@
     if (!self)
         return nil;
 
-    _textIterator = adoptPtr(new WebCore::TextIterator(WebKit::toWebCoreRange(range)));
-
+    _textIterator = std::make_unique<WebCore::TextIterator>(WebKit::toWebCoreRange(range));
     return self;
 }
 
 - (void)advance
 {
     _textIterator->advance();
+    _upconvertedText.shrink(0);
 }
 
 - (BOOL)atEnd
@@ -67,14 +67,24 @@
     return WebKit::toWKDOMRange(_textIterator->range().get());
 }
 
-- (const unichar *)currentTextPointer
+// FIXME: Consider deprecating this method and creating one that does not require copying 8-bit characters.
+- (const unichar*)currentTextPointer
 {
-    return _textIterator->deprecatedTextIteratorCharacters();
+    StringView text = _textIterator->text();
+    unsigned length = text.length();
+    if (!length)
+        return nullptr;
+    if (!text.is8Bit())
+        return text.characters16();
+    if (_upconvertedText.isEmpty())
+        _upconvertedText.appendRange(text.characters8(), text.characters8() + length);
+    ASSERT(_upconvertedText.size() == text.length());
+    return _upconvertedText.data();
 }
 
 - (NSUInteger)currentTextLength
 {
-    return _textIterator->length();
+    return _textIterator->text().length();
 }
 
 @end

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp (164944 => 164945)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp	2014-03-02 18:25:32 UTC (rev 164944)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp	2014-03-02 19:36:12 UTC (rev 164945)
@@ -47,7 +47,6 @@
 #include <WebCore/Page.h>
 #include <WebCore/SpellChecker.h>
 #include <WebCore/StyleProperties.h>
-#include <WebCore/TextIterator.h>
 #include <WebCore/UndoStep.h>
 #include <WebCore/UserTypingGestureIndicator.h>
 #include <wtf/NeverDestroyed.h>

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (164944 => 164945)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2014-03-02 18:25:32 UTC (rev 164944)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2014-03-02 19:36:12 UTC (rev 164945)
@@ -140,7 +140,6 @@
 #include <WebCore/SharedBuffer.h>
 #include <WebCore/SubframeLoader.h>
 #include <WebCore/SubstituteData.h>
-#include <WebCore/TextIterator.h>
 #include <WebCore/UserInputBridge.h>
 #include <WebCore/VisiblePosition.h>
 #include <WebCore/VisibleUnits.h>
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to