WebCore:
authorjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Nov 2007 22:58:47 +0000 (22:58 +0000)
committerjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Nov 2007 22:58:47 +0000 (22:58 +0000)
        Reviewed by Oliver Hunt.

        <rdar://problem/5195056> Huge plain text pastes are slow, time spent in ApplyStyleCommand::doApply

        * editing/ReplaceSelectionCommand.cpp:
        (WebCore::ReplaceSelectionCommand::doApply): No need to match style when pasting
        into a plaintext-only region, since when we build the fragment to insert from
        plain text, we don't put any style information on it, so it will automatically
        match style with no intervention.
        * editing/markup.cpp:
        (WebCore::createFragmentFromText): Place paragraphs into clones of the
        block being inserted into, instead of default paragraph elements,
        so that when inserted content will match the surrounding paragraph style.
        This was broken before, but I haven't added a layout test yet because
        there currently isn't a way to get only plain text onto the pasteboard
        in a layout test.

WebKit:

        Reviewed by Oliver Hunt.

        <rdar://problem/5195056> Huge plain text pastes are slow, time spent in ApplyStyleCommand::doApply

        No need to match style when pasting plain text, since the fragment we build for plain text
        won't have any style information on it.

        * WebView/WebHTMLView.mm:
        (-[WebHTMLView _documentFragmentFromPasteboard:inContext:allowPlainText:]): There's no
        longer a need to know whether this function chosePlaintext.
        (-[WebHTMLView _pasteWithPasteboard:allowPlainText:]):
        (-[WebHTMLView _documentFragmentFromPasteboard:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@27369 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/editing/ReplaceSelectionCommand.cpp
WebCore/editing/markup.cpp
WebKit/ChangeLog
WebKit/WebView/WebHTMLView.mm

index 1ab27afbefcb4542f5022e7b63002d862104d759..ce96433713f573073662c36cae3a410bb3a68dcd 100644 (file)
@@ -1,3 +1,22 @@
+2007-11-01  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by Oliver Hunt.
+
+        <rdar://problem/5195056> Huge plain text pastes are slow, time spent in ApplyStyleCommand::doApply
+
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::ReplaceSelectionCommand::doApply): No need to match style when pasting
+        into a plaintext-only region, since when we build the fragment to insert from
+        plain text, we don't put any style information on it, so it will automatically
+        match style with no intervention.
+        * editing/markup.cpp:
+        (WebCore::createFragmentFromText): Place paragraphs into clones of the
+        block being inserted into, instead of default paragraph elements,
+        so that when inserted content will match the surrounding paragraph style.
+        This was broken before, but I haven't added a layout test yet because
+        there currently isn't a way to get only plain text onto the pasteboard
+        in a layout test.
+
 2007-11-01  Sam Weinig  <sam@webkit.org>
 
         Reviewed by Adam Roben. 
index 348bc0174d806db01a0f0ba847fdbd3aae79b44e..fcad5c3a6d3c6e7bcb21bca292ac4ee922ea6aee 100644 (file)
@@ -517,8 +517,6 @@ void ReplaceSelectionCommand::doApply()
         return;
     
     bool selectionIsPlainText = !selection.isContentRichlyEditable();
-    if (selectionIsPlainText)
-        m_matchStyle = true;
     
     Element* currentRoot = selection.rootEditableElement();
     ReplacementFragment fragment(document(), m_documentFragment.get(), m_matchStyle, selection);
index 205790dc81a7db323c8483e0669ee762993f60de..6b42bc511a276661f134df956bb844a0859e3cbe 100644 (file)
@@ -971,6 +971,8 @@ PassRefPtr<DocumentFragment> createFragmentFromText(Range* context, const String
 {
     if (!context)
         return 0;
+        
+    Node* block = enclosingBlock(context->startNode());
 
     Node* styleNode = context->startNode();
     if (!styleNode) {
@@ -1024,7 +1026,7 @@ PassRefPtr<DocumentFragment> createFragmentFromText(Range* context, const String
             ASSERT(ec == 0);
             element->setAttribute(classAttr, AppleInterchangeNewline);            
         } else {
-            element = createDefaultParagraphElement(document);
+            element = static_cast<Element *>(block->cloneNode(false).get());
             fillContainerFromString(element.get(), s);
         }
         fragment->appendChild(element.release(), ec);
index b1ddd3ced05cf0e7124a95d7c1080368784d27f9..c9984816d19569d69c9bb819e150d6050f64a702 100644 (file)
@@ -1,3 +1,18 @@
+2007-11-01  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by Oliver Hunt.
+        
+        <rdar://problem/5195056> Huge plain text pastes are slow, time spent in ApplyStyleCommand::doApply
+        
+        No need to match style when pasting plain text, since the fragment we build for plain text
+        won't have any style information on it.
+
+        * WebView/WebHTMLView.mm:
+        (-[WebHTMLView _documentFragmentFromPasteboard:inContext:allowPlainText:]): There's no
+        longer a need to know whether this function chosePlaintext.
+        (-[WebHTMLView _pasteWithPasteboard:allowPlainText:]):
+        (-[WebHTMLView _documentFragmentFromPasteboard:]):
+
 2007-10-31  Timothy Hatcher  <timothy@apple.com>
 
         Reviewed by John Sullivan.
index 7171e423b3b6cd50f16849f3123c3e345cde429b..ee94dab85d4b7758fe9d71bda8db2830baa05336 100644 (file)
@@ -295,7 +295,7 @@ static CachedResourceClient* promisedDataClient()
 
 @interface WebHTMLView (WebHTMLViewFileInternal)
 - (BOOL)_imageExistsAtPaths:(NSArray *)paths;
-- (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard inContext:(DOMRange *)context allowPlainText:(BOOL)allowPlainText chosePlainText:(BOOL *)chosePlainText;
+- (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard inContext:(DOMRange *)context allowPlainText:(BOOL)allowPlainText;
 - (NSString *)_plainTextFromPasteboard:(NSPasteboard *)pasteboard;
 - (void)_pasteWithPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText;
 - (void)_pasteAsPlainTextWithPasteboard:(NSPasteboard *)pasteboard;
@@ -552,10 +552,8 @@ static NSURL* uniqueURLWithRelativePart(NSString *relativePart)
 - (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard
                                                inContext:(DOMRange *)context
                                           allowPlainText:(BOOL)allowPlainText
-                                          chosePlainText:(BOOL *)chosePlainText
 {
     NSArray *types = [pasteboard types];
-    *chosePlainText = NO;
     DOMDocumentFragment *fragment = nil;
 
     if ([types containsObject:WebArchivePboardType] &&
@@ -619,7 +617,6 @@ static NSURL* uniqueURLWithRelativePart(NSString *relativePart)
                                                   forType:NSStringPboardType
                                                 inContext:context
                                              subresources:0])) {
-        *chosePlainText = YES;
         return fragment;
     }
     
@@ -666,12 +663,11 @@ static NSURL* uniqueURLWithRelativePart(NSString *relativePart)
 - (void)_pasteWithPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText
 {
     DOMRange *range = [self _selectedRange];
-    BOOL chosePlainText;
     DOMDocumentFragment *fragment = [self _documentFragmentFromPasteboard:pasteboard
-        inContext:range allowPlainText:allowPlainText chosePlainText:&chosePlainText];
+        inContext:range allowPlainText:allowPlainText];
     WebFrameBridge *bridge = [self _bridge];
     if (fragment && [self _shouldInsertFragment:fragment replacingDOMRange:[self _selectedRange] givenAction:WebViewInsertActionPasted]) {
-        [bridge replaceSelectionWithFragment:fragment selectReplacement:NO smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard] matchStyle:chosePlainText];
+        [bridge replaceSelectionWithFragment:fragment selectReplacement:NO smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard] matchStyle:NO];
     }
 }
 
@@ -5092,8 +5088,7 @@ static DOMRange *unionDOMRanges(DOMRange *a, DOMRange *b)
 
 - (DOMDocumentFragment*)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard
 {
-    BOOL discard;
-    return [self _documentFragmentFromPasteboard:pasteboard inContext:nil allowPlainText:NO chosePlainText:&discard];
+    return [self _documentFragmentFromPasteboard:pasteboard inContext:nil allowPlainText:NO];
 }
 
 #ifndef BUILDING_ON_TIGER