Fixed: <rdar://problem/3976872> REGRESSION (Mail): Pasted plain text doesn't get...
authorcblu <cblu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Mar 2005 00:31:22 +0000 (00:31 +0000)
committercblu <cblu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Mar 2005 00:31:22 +0000 (00:31 +0000)
        Reviewed by kocienda.

        * khtml/editing/htmlediting.cpp:
        (khtml::EditCommand::styleAtPosition): new, factored out from calculateStyleBeforeInsertion
        (khtml::InsertParagraphSeparatorCommand::calculateStyleBeforeInsertion): call styleAtPosition
        (khtml::ReplaceSelectionCommand::ReplaceSelectionCommand): clear new m_insertionStyle ivar
        (khtml::ReplaceSelectionCommand::~ReplaceSelectionCommand): deref new m_insertionStyle  ivar
        (khtml::ReplaceSelectionCommand::doApply): store the style so it later be applied when matching style
        (khtml::ReplaceSelectionCommand::completeHTMLReplacement): apply style from m_insertionStyle when matching style
        * khtml/editing/htmlediting.h:

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

WebCore/ChangeLog-2005-08-23
WebCore/khtml/editing/htmlediting.cpp
WebCore/khtml/editing/htmlediting.h

index ed4d97e78191aa53420be68d7e010ed03b83a7fb..c00049bc4572d9d3279af09f12157bad02fbb971 100644 (file)
@@ -1,3 +1,18 @@
+2005-03-02  Chris Blumenberg  <cblu@apple.com>
+
+       Fixed: <rdar://problem/3976872> REGRESSION (Mail): Pasted plain text doesn't get the proper style if pasted into newlines
+
+        Reviewed by kocienda.
+
+        * khtml/editing/htmlediting.cpp:
+        (khtml::EditCommand::styleAtPosition): new, factored out from calculateStyleBeforeInsertion
+        (khtml::InsertParagraphSeparatorCommand::calculateStyleBeforeInsertion): call styleAtPosition
+        (khtml::ReplaceSelectionCommand::ReplaceSelectionCommand): clear new m_insertionStyle ivar
+        (khtml::ReplaceSelectionCommand::~ReplaceSelectionCommand): deref new m_insertionStyle  ivar
+        (khtml::ReplaceSelectionCommand::doApply): store the style so it later be applied when matching style
+        (khtml::ReplaceSelectionCommand::completeHTMLReplacement): apply style from m_insertionStyle when matching style
+        * khtml/editing/htmlediting.h:
+
 2005-03-02  Maciej Stachowiak  <mjs@apple.com>
 
         Reviewed by Darin.
index 9bcc153932866d46bb506065c131686215ed2b80..fe05d40ce52a21d94207db02c120055829b90f47 100644 (file)
@@ -714,6 +714,23 @@ bool EditCommand::isTypingCommand() const
     return false;
 }
 
+CSSMutableStyleDeclarationImpl *EditCommand::styleAtPosition(const Position &pos)
+{
+    CSSComputedStyleDeclarationImpl *computedStyle = pos.computedStyle();
+    computedStyle->ref();
+    CSSMutableStyleDeclarationImpl *style = computedStyle->copyInheritableProperties();
+    computedStyle->deref();
+    // FIXME: Improve typing style.
+    // See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
+    CSSMutableStyleDeclarationImpl *typingStyle = document()->part()->typingStyle();
+    if (typingStyle)
+        style->merge(typingStyle);
+    
+    return style;
+}
+
+
 //------------------------------------------------------------------------------------------
 // CompositeEditCommand
 
@@ -3131,20 +3148,11 @@ void InsertParagraphSeparatorCommand::calculateStyleBeforeInsertion(const Positi
     VisiblePosition visiblePos(pos, UPSTREAM);
     if (!isFirstVisiblePositionInParagraph(visiblePos) && !isLastVisiblePositionInParagraph(visiblePos))
         return;
-
-    // FIXME: Improve typing style.
-    // See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
-    CSSComputedStyleDeclarationImpl *computedStyle = pos.computedStyle();
-    computedStyle->ref();
+    
     if (m_style)
         m_style->deref();
-    m_style = computedStyle->copyInheritableProperties();
+    m_style = styleAtPosition(pos);
     m_style->ref();
-    computedStyle->deref();
-    
-    CSSMutableStyleDeclarationImpl *typingStyle = document()->part()->typingStyle();
-    if (typingStyle)
-        m_style->merge(typingStyle);
 }
 
 void InsertParagraphSeparatorCommand::applyStyleAfterInsertion()
@@ -4383,6 +4391,7 @@ ReplaceSelectionCommand::ReplaceSelectionCommand(DocumentImpl *document, Documen
       m_firstNodeInserted(0),
       m_lastNodeInserted(0),
       m_lastTopNodeInserted(0),
+      m_insertionStyle(0),
       m_selectReplacement(selectReplacement), 
       m_smartReplace(smartReplace),
       m_matchStyle(matchStyle)
@@ -4397,6 +4406,8 @@ ReplaceSelectionCommand::~ReplaceSelectionCommand()
         m_lastNodeInserted->deref();
     if (m_lastTopNodeInserted)
         m_lastTopNodeInserted->deref();
+    if (m_insertionStyle)
+        m_insertionStyle->deref();
 }
 
 void ReplaceSelectionCommand::doApply()
@@ -4467,15 +4478,17 @@ void ReplaceSelectionCommand::doApply()
     }
     endPos = selection.end().downstream(); 
     
-    // If not matching style, clear typing style.
-    // FIXME: Improve typing style.
-    // See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
     KHTMLPart *part = document()->part();
-    if (!m_matchStyle) {
-        part->clearTypingStyle();
-        setTypingStyle(0);    
+    if (m_matchStyle) {
+        m_insertionStyle = styleAtPosition(startPos);
+        m_insertionStyle->ref();
     }
     
+    // FIXME: Improve typing style.
+    // See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
+    part->clearTypingStyle();
+    setTypingStyle(0);    
+    
     // done if there is nothing to add
     if (!m_fragment.firstChild())
         return;
@@ -4598,6 +4611,8 @@ void ReplaceSelectionCommand::doApply()
             insertNodeBeforeAndUpdateNodesInserted(node, m_firstNodeInserted);
         }
     }
+    
+    Position lastPositionToSelect;
 
     // step 4 : handle trailing newline
     if (m_fragment.hasInterchangeNewline()) {
@@ -4615,12 +4630,13 @@ void ReplaceSelectionCommand::doApply()
         if (insertParagraph) {
             setEndingSelection(insertionPos, DOWNSTREAM);
             insertParagraphSeparator();
-            endPos = endingSelection().end().downstream();
-        }
-        if (!m_matchStyle) {
-            fixupNodeStyles(m_fragment.desiredStyles());
+            updateNodesInserted(endingSelection().end().downstream().node());
+            // Select up to the paragraph separator that was added.
+            lastPositionToSelect = endingSelection().end().downstream();
+        } else {
+            // Select up to the preexising paragraph separator.
+            lastPositionToSelect = Position(m_lastNodeInserted, m_lastNodeInserted->caretMaxOffset()).downstream();
         }
-        completeHTMLReplacement(startPos, endPos);
     } else {
         if (m_lastNodeInserted && m_lastNodeInserted->id() == ID_BR && !document()->inStrictMode()) {
             document()->updateLayout();
@@ -4667,14 +4683,12 @@ void ReplaceSelectionCommand::doApply()
             fixupNodeStyles(styles);
             derefNodesAndStylesInMap(styles);
         }
-    
-        if (!m_matchStyle) {
-            fixupNodeStyles(m_fragment.desiredStyles());
-        }
-        
-        completeHTMLReplacement();
     }
     
+    if (!m_matchStyle)
+        fixupNodeStyles(m_fragment.desiredStyles());
+    completeHTMLReplacement(lastPositionToSelect);
+    
     // step 5 : mop up
     if (linePlaceholder) {
         document()->updateLayout();
@@ -4693,26 +4707,7 @@ void ReplaceSelectionCommand::doApply()
     }
 }
 
-void ReplaceSelectionCommand::completeHTMLReplacement(const Position &start, const Position &end)
- {
-    if (start.isNull() || !start.node()->inDocument() || end.isNull() || !end.node()->inDocument())
-        return;
-    
-    Selection replacementSelection(start, SEL_DEFAULT_AFFINITY, end, SEL_DEFAULT_AFFINITY);
-    setEndingSelection(replacementSelection);
-    
-    CSSMutableStyleDeclarationImpl *typingStyle = document()->part()->typingStyle();
-    if (m_matchStyle && typingStyle) {
-        applyStyle(typingStyle);
-    }    
-    
-    if (!m_selectReplacement)
-        setEndingSelection(end, SEL_DEFAULT_AFFINITY);
-    
-    rebalanceWhitespace();
-}
-
-void ReplaceSelectionCommand::completeHTMLReplacement()
+void ReplaceSelectionCommand::completeHTMLReplacement(const Position &lastPositionToSelect)
 {
     if (!m_firstNodeInserted || !m_firstNodeInserted->inDocument() ||
         !m_lastNodeInserted || !m_lastNodeInserted->inDocument())
@@ -4740,7 +4735,23 @@ void ReplaceSelectionCommand::completeHTMLReplacement()
     document()->updateLayout();
     Position start(firstLeaf, firstLeaf->caretMinOffset());
     Position end(lastLeaf, lastLeaf->caretMaxOffset());
-    completeHTMLReplacement(start, end);
+    
+    if (m_matchStyle) {
+        assert(m_insertionStyle);
+        setEndingSelection(Selection(start, SEL_DEFAULT_AFFINITY, end, SEL_DEFAULT_AFFINITY));
+        applyStyle(m_insertionStyle);
+    }    
+    
+    if (lastPositionToSelect.isNotNull())
+        end = lastPositionToSelect;
+    
+    if (m_selectReplacement) {
+        setEndingSelection(Selection(start, SEL_DEFAULT_AFFINITY, end, SEL_DEFAULT_AFFINITY));
+    } else {
+        setEndingSelection(end, SEL_DEFAULT_AFFINITY);
+    }
+    
+    rebalanceWhitespace();
 }
 
 EditAction ReplaceSelectionCommand::editingAction() const
index db762de60dc1a771c8416f900d3cdb1b2cbb0f02..547cd94b80e218c7f2b127ca70ee77be11312d3a 100644 (file)
@@ -179,6 +179,8 @@ public:
     DOM::CSSMutableStyleDeclarationImpl *typingStyle() const { return m_typingStyle; };
     void setTypingStyle(DOM::CSSMutableStyleDeclarationImpl *);
     
+    DOM::CSSMutableStyleDeclarationImpl *styleAtPosition(const DOM::Position &pos);
+    
     virtual bool isInsertTextCommand() const;
     virtual bool isTypingCommand() const;
     
@@ -736,8 +738,7 @@ public:
     virtual EditAction editingAction() const;
 
 private:
-    void completeHTMLReplacement(const DOM::Position &, const DOM::Position &);
-    void completeHTMLReplacement();
+    void completeHTMLReplacement(const DOM::Position &lastPositionToSelect);
 
     void insertNodeAfterAndUpdateNodesInserted(DOM::NodeImpl *insertChild, DOM::NodeImpl *refChild);
     void insertNodeAtAndUpdateNodesInserted(DOM::NodeImpl *insertChild, DOM::NodeImpl *refChild, long offset);
@@ -750,6 +751,7 @@ private:
     DOM::NodeImpl *m_firstNodeInserted;
     DOM::NodeImpl *m_lastNodeInserted;
     DOM::NodeImpl *m_lastTopNodeInserted;
+    DOM::CSSMutableStyleDeclarationImpl *m_insertionStyle;
     bool m_selectReplacement;
     bool m_smartReplace;
     bool m_matchStyle;