WebCore:
authorcblu <cblu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Feb 2005 20:11:13 +0000 (20:11 +0000)
committercblu <cblu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 18 Feb 2005 20:11:13 +0000 (20:11 +0000)
Fixed: <rdar://problem/3945271> REGRESSION (Mail): pasted plain text should pick up typing style instead of being unstyled

        Reviewed by kocienda.

        * khtml/editing/htmlediting.cpp:
        (khtml::ApplyStyleCommand::addInlineStyleIfNeeded): don't set class on element returned by createStyleSpanElement since that's already done
        (khtml::ReplacementFragment::ReplacementFragment): take matchStyle param, don't call computeStylesAndRemoveUnrendered() if !matchStyle
        (khtml::ReplaceSelectionCommand::ReplaceSelectionCommand): take matchStyle param
        (khtml::ReplaceSelectionCommand::doApply): if m_matchStyle, use selection.start() as the insertion position and don't call applyStyleToInsertedNodes()
        * khtml/editing/htmlediting.h:
        * kwq/WebCoreBridge.h:
        * kwq/WebCoreBridge.mm:
        (-[WebCoreBridge replaceSelectionWithFragment:selectReplacement:smartReplace:matchStyle:]): take matchStyle param and pass it
        (-[WebCoreBridge replaceSelectionWithNode:selectReplacement:smartReplace:]): pass NO for matchStyle
        (-[WebCoreBridge replaceSelectionWithMarkupString:baseURLString:selectReplacement:smartReplace:]): pass NO for matchStyle
        (-[WebCoreBridge replaceSelectionWithText:selectReplacement:smartReplace:]): pass YES for matchStyle

WebKit:

Fixed: <rdar://problem/3945271> REGRESSION (Mail): pasted plain text should pick up typing style instead of being unstyled

        Reviewed by kocienda.

        * WebView.subproj/WebDataSource.m:
        (-[WebDataSource _replaceSelectionWithArchive:selectReplacement:]): pass NO for matchStyle to replaceSelection
        * WebView.subproj/WebHTMLView.m:
        (-[WebHTMLView _documentFragmentFromPasteboard:allowPlainText:chosePlainText:]): return new chosePlainText parameter
        (-[WebHTMLView _pasteWithPasteboard:allowPlainText:]): pass chosePlainText for matchStyle to replaceSelection
        (-[WebHTMLView concludeDragForDraggingInfo:actionMask:]): ditto

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

WebCore/ChangeLog-2005-08-23
WebCore/khtml/editing/htmlediting.cpp
WebCore/khtml/editing/htmlediting.h
WebCore/kwq/WebCoreBridge.h
WebCore/kwq/WebCoreBridge.mm
WebKit/ChangeLog
WebKit/WebView.subproj/WebDataSource.m
WebKit/WebView.subproj/WebHTMLView.m

index 6ab813400d21d8ea2898ff8ff8a6cd27449e9a4b..23467b34baf9270b14a6c32c0fc48a43758425f8 100644 (file)
@@ -1,3 +1,22 @@
+2005-02-18  Chris Blumenberg  <cblu@apple.com>
+
+       Fixed: <rdar://problem/3945271> REGRESSION (Mail): pasted plain text should pick up typing style instead of being unstyled
+
+        Reviewed by kocienda.
+
+        * khtml/editing/htmlediting.cpp:
+        (khtml::ApplyStyleCommand::addInlineStyleIfNeeded): don't set class on element returned by createStyleSpanElement since that's already done
+        (khtml::ReplacementFragment::ReplacementFragment): take matchStyle param, don't call computeStylesAndRemoveUnrendered() if !matchStyle
+        (khtml::ReplaceSelectionCommand::ReplaceSelectionCommand): take matchStyle param
+        (khtml::ReplaceSelectionCommand::doApply): if m_matchStyle, use selection.start() as the insertion position and don't call applyStyleToInsertedNodes()
+        * khtml/editing/htmlediting.h:
+        * kwq/WebCoreBridge.h:
+        * kwq/WebCoreBridge.mm:
+        (-[WebCoreBridge replaceSelectionWithFragment:selectReplacement:smartReplace:matchStyle:]): take matchStyle param and pass it
+        (-[WebCoreBridge replaceSelectionWithNode:selectReplacement:smartReplace:]): pass NO for matchStyle
+        (-[WebCoreBridge replaceSelectionWithMarkupString:baseURLString:selectReplacement:smartReplace:]): pass NO for matchStyle
+        (-[WebCoreBridge replaceSelectionWithText:selectReplacement:smartReplace:]): pass YES for matchStyle
+
 2005-02-18  Ken Kocienda  <kocienda@apple.com>
 
         Reviewed by Chris
index cb7f4c00229a12da7304c34f433e78d8e5693b7e..a0cf7db5dbdef158bea3166d68586267de04c197 100644 (file)
@@ -2069,7 +2069,6 @@ void ApplyStyleCommand::addInlineStyleIfNeeded(CSSMutableStyleDeclarationImpl *s
     if (styleChange.cssStyle().length() > 0) {
         ElementImpl *styleElement = createStyleSpanElement(document());
         styleElement->setAttribute(ATTR_STYLE, styleChange.cssStyle());
-        styleElement->setAttribute(ATTR_CLASS, styleSpanClassString());
         insertNodeBefore(styleElement, startNode);
         surroundNodeRangeWithElement(startNode, endNode, styleElement);
     }
@@ -3926,8 +3925,8 @@ void RemoveNodePreservingChildrenCommand::doApply()
 //------------------------------------------------------------------------------------------
 // ReplaceSelectionCommand
 
-ReplacementFragment::ReplacementFragment(DocumentImpl *document, DocumentFragmentImpl *fragment)
-    : m_document(document), m_fragment(fragment), m_hasInterchangeNewline(false), m_hasMoreThanOneBlock(false)
+ReplacementFragment::ReplacementFragment(DocumentImpl *document, DocumentFragmentImpl *fragment, bool matchStyle)
+    : m_document(document), m_fragment(fragment), m_matchStyle(matchStyle), m_hasInterchangeNewline(false), m_hasMoreThanOneBlock(false)
 {
     if (!m_document)
         return;
@@ -3985,7 +3984,9 @@ ReplacementFragment::ReplacementFragment(DocumentImpl *document, DocumentFragmen
         removeNode(nodeToDelete);
 
     // Prepare this fragment to merge styles correctly into the destination.
-    computeStylesAndRemoveUnrendered();
+    if (!m_matchStyle) {
+        computeStylesAndRemoveUnrendered();
+    }
     removeStyleNodes();
 
     int blockCount = realBlockCount;
@@ -3996,7 +3997,7 @@ ReplacementFragment::ReplacementFragment(DocumentImpl *document, DocumentFragmen
     if (!isProbablyBlock(lastChild) && realBlockCount > 0)
         blockCount++;
 
-     if (blockCount > 1)
+    if (blockCount > 1)
         m_hasMoreThanOneBlock = true;
 }
 
@@ -4227,14 +4228,15 @@ void ReplacementFragment::removeBlockquoteColorsIfNeeded(NodeImpl *node, CSSMuta
     }
 }
 
-ReplaceSelectionCommand::ReplaceSelectionCommand(DocumentImpl *document, DocumentFragmentImpl *fragment, bool selectReplacement, bool smartReplace) 
+ReplaceSelectionCommand::ReplaceSelectionCommand(DocumentImpl *document, DocumentFragmentImpl *fragment, bool selectReplacement, bool smartReplace, bool matchStyle
     : CompositeEditCommand(document), 
-      m_fragment(document, fragment),
+      m_fragment(document, fragment, matchStyle),
       m_firstNodeInserted(0),
       m_lastNodeInserted(0),
       m_lastTopNodeInserted(0),
       m_selectReplacement(selectReplacement), 
-      m_smartReplace(smartReplace)
+      m_smartReplace(smartReplace),
+      m_matchStyle(matchStyle)
 {
 }
 
@@ -4298,12 +4300,16 @@ void ReplaceSelectionCommand::doApply()
     
     // calculate the start and end of the resulting selection
     selection = endingSelection();
-    if (startAtStartOfBlock && startBlock->inDocument()) {
-        startPos = Position(startBlock, 0);
-    } else if (startAtEndOfBlock) {
-        startPos = selection.start().downstream(StayInBlock);
+    if (m_matchStyle) {
+        startPos = selection.start();
     } else {
-        startPos = selection.start().upstream(upstreamStayInBlock);
+        if (startAtStartOfBlock && startBlock->inDocument()) {
+            startPos = Position(startBlock, 0);
+        } else if (startAtEndOfBlock) {
+            startPos = selection.start().downstream(StayInBlock);
+        } else {
+            startPos = selection.start().upstream(upstreamStayInBlock);
+        }
     }
     endPos = selection.end().downstream(); 
     
@@ -4312,8 +4318,8 @@ void ReplaceSelectionCommand::doApply()
     // See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
     KHTMLPart *part = document()->part();
     part->clearTypingStyle();
-    setTypingStyle(0);
-
+    setTypingStyle(0);    
+    
     // done if there is nothing to add
     if (!m_fragment.firstChild())
         return;
@@ -4440,7 +4446,9 @@ void ReplaceSelectionCommand::doApply()
             insertParagraphSeparator();
             endPos = endingSelection().end().downstream();
         }
-        applyStyleToInsertedNodes();
+        if (!m_matchStyle) {
+            applyStyleToInsertedNodes();
+        }
         completeHTMLReplacement(startPos, endPos);
     } else {
         if (m_lastNodeInserted && m_lastNodeInserted->id() == ID_BR && !document()->inStrictMode()) {
@@ -4486,8 +4494,10 @@ void ReplaceSelectionCommand::doApply()
             }
         }
     
-        applyStyleToInsertedNodes();
-    
+        if (!m_matchStyle) {
+            applyStyleToInsertedNodes();
+        }
+        
         completeHTMLReplacement();
     }
     
index f704cd8215fcfe98a63ca087b088788a9af1977d..babcd1c82333287124c89e808afc66c6bbed0d8a 100644 (file)
@@ -659,7 +659,7 @@ private:
 class ReplacementFragment
 {
 public:
-    ReplacementFragment(DOM::DocumentImpl *, DOM::DocumentFragmentImpl *);
+    ReplacementFragment(DOM::DocumentImpl *, DOM::DocumentFragmentImpl *, bool matchStyle);
     ~ReplacementFragment();
 
     enum EFragmentType { EmptyFragment, SingleTextNodeFragment, TreeFragment };
@@ -686,7 +686,7 @@ private:
     // no copy construction or assignment
     ReplacementFragment(const ReplacementFragment &);
     ReplacementFragment &operator=(const ReplacementFragment &);
-
+    
     static bool isInterchangeNewlineNode(const DOM::NodeImpl *);
     static bool isInterchangeConvertedSpaceSpan(const DOM::NodeImpl *);
 
@@ -704,6 +704,7 @@ private:
     DOM::DocumentImpl *m_document;
     DOM::DocumentFragmentImpl *m_fragment;
     QMap<DOM::NodeImpl *, DOM::CSSMutableStyleDeclarationImpl *> m_styles;
+    bool m_matchStyle;
     bool m_hasInterchangeNewline;
     bool m_hasMoreThanOneBlock;
 };
@@ -711,7 +712,7 @@ private:
 class ReplaceSelectionCommand : public CompositeEditCommand
 {
 public:
-    ReplaceSelectionCommand(DOM::DocumentImpl *document, DOM::DocumentFragmentImpl *fragment, bool selectReplacement=true, bool smartReplace=false);
+    ReplaceSelectionCommand(DOM::DocumentImpl *document, DOM::DocumentFragmentImpl *fragment, bool selectReplacement=true, bool smartReplace=false, bool matchStyle=false);
     virtual ~ReplaceSelectionCommand();
     
     virtual void doApply();
@@ -734,6 +735,7 @@ private:
     DOM::NodeImpl *m_lastTopNodeInserted;
     bool m_selectReplacement;
     bool m_smartReplace;
+    bool m_matchStyle;
 };
 
 //------------------------------------------------------------------------------------------
index fbd826253e281e376c891d8bd2a8bb25c3e86276..17a77edaf4f1c50ec18ace36688cb9a65ae9370e 100644 (file)
@@ -367,7 +367,7 @@ typedef enum {
 - (DOMDocumentFragment *)documentFragmentWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString;
 - (DOMDocumentFragment *)documentFragmentWithText:(NSString *)text;
 
-- (void)replaceSelectionWithFragment:(DOMDocumentFragment *)fragment selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace;
+- (void)replaceSelectionWithFragment:(DOMDocumentFragment *)fragment selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace matchStyle:(BOOL)matchStyle;
 - (void)replaceSelectionWithNode:(DOMNode *)node selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace;
 - (void)replaceSelectionWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace;
 - (void)replaceSelectionWithText:(NSString *)text selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace;
index 4d0591e4553584fc4032b58719f7581607cdb248..dc4fa229d56698259bf3788a37af998e5aa72310 100644 (file)
@@ -1611,12 +1611,12 @@ static HTMLFormElementImpl *formElementFromDOMElement(DOMElement *element)
     return [DOMDocumentFragment _documentFragmentWithImpl:createFragmentFromText(_part->xmlDocImpl(), QString::fromNSString(text))];
 }
 
-- (void)replaceSelectionWithFragment:(DOMDocumentFragment *)fragment selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace
+- (void)replaceSelectionWithFragment:(DOMDocumentFragment *)fragment selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace matchStyle:(BOOL)matchStyle
 {
     if (!partHasSelection(self) || !fragment)
         return;
     
-    EditCommandPtr(new ReplaceSelectionCommand(_part->xmlDocImpl(), [fragment _fragmentImpl], selectReplacement, smartReplace)).apply();
+    EditCommandPtr(new ReplaceSelectionCommand(_part->xmlDocImpl(), [fragment _fragmentImpl], selectReplacement, smartReplace, matchStyle)).apply();
     [self ensureSelectionVisible];
 }
 
@@ -1624,18 +1624,18 @@ static HTMLFormElementImpl *formElementFromDOMElement(DOMElement *element)
 {
     DOMDocumentFragment *fragment = [[self DOMDocument] createDocumentFragment];
     [fragment appendChild:node];
-    [self replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:smartReplace];
+    [self replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:smartReplace matchStyle:NO];
 }
 
 - (void)replaceSelectionWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace
 {
     DOMDocumentFragment *fragment = [self documentFragmentWithMarkupString:markupString baseURLString:baseURLString];
-    [self replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:smartReplace];
+    [self replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:smartReplace matchStyle:NO];
 }
 
 - (void)replaceSelectionWithText:(NSString *)text selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace
 {
-    [self replaceSelectionWithFragment:[self documentFragmentWithText:text] selectReplacement:selectReplacement smartReplace:smartReplace];
+    [self replaceSelectionWithFragment:[self documentFragmentWithText:text] selectReplacement:selectReplacement smartReplace:smartReplace matchStyle:YES];
 }
 
 - (void)insertLineBreak
index 0cf3c36fc56e645c52c87742c2198356b7373a2d..53fdf16be13279685468ab645d1994539080bfaf 100644 (file)
@@ -1,3 +1,16 @@
+2005-02-18  Chris Blumenberg  <cblu@apple.com>
+
+       Fixed: <rdar://problem/3945271> REGRESSION (Mail): pasted plain text should pick up typing style instead of being unstyled
+
+        Reviewed by kocienda.
+
+        * WebView.subproj/WebDataSource.m:
+        (-[WebDataSource _replaceSelectionWithArchive:selectReplacement:]): pass NO for matchStyle to replaceSelection
+        * WebView.subproj/WebHTMLView.m:
+        (-[WebHTMLView _documentFragmentFromPasteboard:allowPlainText:chosePlainText:]): return new chosePlainText parameter
+        (-[WebHTMLView _pasteWithPasteboard:allowPlainText:]): pass chosePlainText for matchStyle to replaceSelection
+        (-[WebHTMLView concludeDragForDraggingInfo:actionMask:]): ditto
+
 2005-02-17  Richard Williamson   <rjw@apple.com>
 
        Removed code that should not have been checked in from
index 9631ad04447d6435c74e0cf26c4f53d931488b65..b97d47fc310ac9db5f06c5dcad6aa0ab671b0e57 100644 (file)
 {
     DOMDocumentFragment *fragment = [self _documentFragmentWithArchive:archive];
     if (fragment) {
-        [[self _bridge] replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:NO];
+        [[self _bridge] replaceSelectionWithFragment:fragment selectReplacement:selectReplacement smartReplace:NO matchStyle:NO];
     }
 }
 
index b27ba4ace553734a20863b78b1d4a8c80fae7963..7d3b2aebb1a52f1b457fd9aeb6b303c880f278db 100644 (file)
@@ -151,7 +151,7 @@ void *_NSSoftLinkingGetFrameworkFuncPtr(NSString *inUmbrellaFrameworkName,
 
 @interface WebHTMLView (WebHTMLViewFileInternal)
 - (BOOL)_imageExistsAtPaths:(NSArray *)paths;
-- (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText;
+- (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText chosePlainText:(BOOL *)chosePlainText;
 - (void)_pasteWithPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText;
 - (BOOL)_shouldInsertFragment:(DOMDocumentFragment *)fragment replacingDOMRange:(DOMRange *)range givenAction:(WebViewInsertAction)action;
 - (BOOL)_shouldReplaceSelectionWithText:(NSString *)text givenAction:(WebViewInsertAction)action;
@@ -298,9 +298,10 @@ void *_NSSoftLinkingGetFrameworkFuncPtr(NSString *inUmbrellaFrameworkName,
     return elements;
 }
 
-- (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText
+- (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText chosePlainText:(BOOL *)chosePlainText
 {
     NSArray *types = [pasteboard types];
+    *chosePlainText = NO;
 
     if ([types containsObject:WebArchivePboardType]) {
         WebArchive *archive = [[WebArchive alloc] initWithData:[pasteboard dataForType:WebArchivePboardType]];
@@ -389,6 +390,7 @@ void *_NSSoftLinkingGetFrameworkFuncPtr(NSString *inUmbrellaFrameworkName,
     }
     
     if (allowPlainText && [types containsObject:NSStringPboardType]) {
+        *chosePlainText = YES;
         return [[self _bridge] documentFragmentWithText:[pasteboard stringForType:NSStringPboardType]];
     }
     
@@ -422,10 +424,11 @@ void *_NSSoftLinkingGetFrameworkFuncPtr(NSString *inUmbrellaFrameworkName,
 
 - (void)_pasteWithPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText
 {
-    DOMDocumentFragment *fragment = [self _documentFragmentFromPasteboard:pasteboard allowPlainText:allowPlainText];
+    BOOL chosePlainText;
+    DOMDocumentFragment *fragment = [self _documentFragmentFromPasteboard:pasteboard allowPlainText:allowPlainText chosePlainText:&chosePlainText];
     WebBridge *bridge = [self _bridge];
     if (fragment && [self _shouldInsertFragment:fragment replacingDOMRange:[self _selectedRange] givenAction:WebViewInsertActionPasted]) {
-        [bridge replaceSelectionWithFragment:fragment selectReplacement:NO smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard]];
+        [bridge replaceSelectionWithFragment:fragment selectReplacement:NO smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard] matchStyle:chosePlainText];
     }
 }
 
@@ -2767,7 +2770,8 @@ static WebHTMLView *lastHitView = nil;
             BOOL didInsert = NO;
             if ([self _canProcessDragWithDraggingInfo:draggingInfo]) {
                 NSPasteboard *pasteboard = [draggingInfo draggingPasteboard];
-                DOMDocumentFragment *fragment = [self _documentFragmentFromPasteboard:pasteboard allowPlainText:YES];
+                BOOL chosePlainText;
+                DOMDocumentFragment *fragment = [self _documentFragmentFromPasteboard:pasteboard allowPlainText:YES chosePlainText:&chosePlainText];
                 if (fragment && [self _shouldInsertFragment:fragment replacingDOMRange:[bridge dragCaretDOMRange] givenAction:WebViewInsertActionDropped]) {
                     [[webView _UIDelegateForwarder] webView:webView willPerformDragDestinationAction:WebDragDestinationActionEdit forDraggingInfo:draggingInfo];
                     if ([self _isMoveDrag]) {
@@ -2775,7 +2779,7 @@ static WebHTMLView *lastHitView = nil;
                         [bridge moveSelectionToDragCaret:fragment smartMove:smartMove];
                     } else {
                         [bridge setSelectionToDragCaret];
-                        [bridge replaceSelectionWithFragment:fragment selectReplacement:YES smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard]];
+                        [bridge replaceSelectionWithFragment:fragment selectReplacement:YES smartReplace:[self _canSmartReplaceWithPasteboard:pasteboard] matchStyle:chosePlainText];
                     }
                     didInsert = YES;
                 }