[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

kocienda kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:44:15 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit b873b5349638e6c8097ccaaac19104f4914c5a5f
Author: kocienda <kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Jun 7 22:09:58 2004 +0000

            Reviewed by Hyatt
    
            Fix for this bug:
    
            <rdar://problem/3682354>: "Typing style does not work yet"
    
            Did the final hook-up of support that has landed in the tree in the
            recent past as part of ongoing style-application work.
    
            For the most part, this patch modifies the InputNewlineCommandImpl and
            InputTextCommandImpl commands to insert a styling span when there is
            a typing style active.
    
            * khtml/editing/htmlediting_impl.cpp:
            (khtml::CompositeEditCommandImpl::createTypingStyleElement): Helper
            shared by the two commands modified.
            (khtml::InputNewlineCommandImpl::doApply): Create a styling span if the
            part has a typing style. Maintain a nodeToInsert local variable, which is
            either the break to insert or a styling span containing the break. Also,
            remove some utterly bogus derefs. They are just plain wrong.
            (khtml::InputTextCommandImpl::InputTextCommandImpl): Don't need to keep
            m_insertedTextNode. The composite commands this command uses will keep
            track of that object's lifetime. We do not need to do that here.
            (khtml::InputTextCommandImpl::~InputTextCommandImpl): No longer need
            to deref obsolete m_insertedTextNode.
            (khtml::InputTextCommandImpl::prepareForTextInsertion): Handle the case
            where a styling span needs to be added.
            (khtml::TypingCommandImpl::insertText): Create a new InputTextCommand when
            there is an active typping style.
            * khtml/editing/htmlediting_impl.h: Declare createTypingStyleElement helper.
            Remove m_insertedTextNode from InputTextCommandImpl.
            * kwq/WebCoreBridge.mm:
            (-[WebCoreBridge applyStyle:]): Swicth on the state of the selection, calling
            setTypingStyle when a caret and ApplyStyleCommand when a range.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6784 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index ac7ce62..aa8cd1d 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,40 @@
+2004-06-07  Ken Kocienda  <kocienda at apple.com>
+
+        Reviewed by Hyatt
+
+        Fix for this bug:
+        
+        <rdar://problem/3682354>: "Typing style does not work yet"
+        
+        Did the final hook-up of support that has landed in the tree in the
+        recent past as part of ongoing style-application work.
+        
+        For the most part, this patch modifies the InputNewlineCommandImpl and
+        InputTextCommandImpl commands to insert a styling span when there is
+        a typing style active. 
+
+        * khtml/editing/htmlediting_impl.cpp:
+        (khtml::CompositeEditCommandImpl::createTypingStyleElement): Helper
+        shared by the two commands modified.
+        (khtml::InputNewlineCommandImpl::doApply): Create a styling span if the
+        part has a typing style. Maintain a nodeToInsert local variable, which is
+        either the break to insert or a styling span containing the break. Also,
+        remove some utterly bogus derefs. They are just plain wrong.
+        (khtml::InputTextCommandImpl::InputTextCommandImpl): Don't need to keep
+        m_insertedTextNode. The composite commands this command uses will keep
+        track of that object's lifetime. We do not need to do that here.
+        (khtml::InputTextCommandImpl::~InputTextCommandImpl): No longer need 
+        to deref obsolete m_insertedTextNode.
+        (khtml::InputTextCommandImpl::prepareForTextInsertion): Handle the case
+        where a styling span needs to be added.
+        (khtml::TypingCommandImpl::insertText): Create a new InputTextCommand when
+        there is an active typping style.
+        * khtml/editing/htmlediting_impl.h: Declare createTypingStyleElement helper.
+        Remove m_insertedTextNode from InputTextCommandImpl.
+        * kwq/WebCoreBridge.mm:
+        (-[WebCoreBridge applyStyle:]): Swicth on the state of the selection, calling
+        setTypingStyle when a caret and ApplyStyleCommand when a range.
+
 2004-06-07  Darin Adler  <darin at apple.com>
 
         Reviewed by Ken.
diff --git a/WebCore/khtml/editing/htmlediting_impl.cpp b/WebCore/khtml/editing/htmlediting_impl.cpp
index b6943fb..48742ab 100644
--- a/WebCore/khtml/editing/htmlediting_impl.cpp
+++ b/WebCore/khtml/editing/htmlediting_impl.cpp
@@ -531,6 +531,21 @@ void CompositeEditCommandImpl::setNodeAttribute(ElementImpl *element, int attrib
     applyCommandToComposite(cmd);
 }
 
+ElementImpl *CompositeEditCommandImpl::createTypingStyleElement() const
+{
+    int exceptionCode = 0;
+    ElementImpl *styleElement = document()->createHTMLElement("SPAN", exceptionCode);
+    ASSERT(exceptionCode == 0);
+    
+    styleElement->setAttribute(ATTR_STYLE, document()->part()->typingStyle()->cssText().implementation(), exceptionCode);
+    ASSERT(exceptionCode == 0);
+
+    styleElement->setAttribute(ATTR_CLASS, styleSpanClassString());
+    ASSERT(exceptionCode == 0);
+
+    return styleElement;
+}
+
 //==========================================================================================
 // Concrete commands
 //------------------------------------------------------------------------------------------
@@ -1610,6 +1625,17 @@ void InputNewlineCommandImpl::doApply()
     ElementImpl *breakNode = document()->createHTMLElement("BR", exceptionCode);
     ASSERT(exceptionCode == 0);
 
+    NodeImpl *nodeToInsert = breakNode;
+    
+    // Handle the case where there is a typing style.
+    if (document()->part()->typingStyle()) {
+        int exceptionCode = 0;
+        ElementImpl *styleElement = createTypingStyleElement();
+        styleElement->appendChild(breakNode, exceptionCode);
+        ASSERT(exceptionCode == 0);
+        nodeToInsert = styleElement;
+    }
+    
     Position pos(selection.start().equivalentDownstreamPosition());
     bool atEnd = pos.offset() >= pos.node()->caretMaxOffset();
     bool atStart = pos.offset() <= pos.node()->caretMinOffset();
@@ -1618,7 +1644,7 @@ void InputNewlineCommandImpl::doApply()
     if (atEndOfBlock) {
         LOG(Editing, "input newline case 1");
         NodeImpl *cb = pos.node()->enclosingBlockFlowElement();
-        appendNode(cb, breakNode);
+        appendNode(cb, nodeToInsert);
         
         // Insert an "extra" BR at the end of the block. This makes the "real" BR we want
         // to insert appear in the rendering without any significant side effects (and no
@@ -1631,12 +1657,12 @@ void InputNewlineCommandImpl::doApply()
     }
     else if (atEnd) {
         LOG(Editing, "input newline case 2");
-        insertNodeAfter(breakNode, pos.node());
+        insertNodeAfter(nodeToInsert, pos.node());
         setEndingSelection(Position(breakNode, 0));
     }
     else if (atStart) {
         LOG(Editing, "input newline case 3");
-        insertNodeAt(breakNode, pos.node(), 0);
+        insertNodeAt(nodeToInsert, pos.node(), 0);
         setEndingSelection(Position(pos.node(), 0));
     }
     else {
@@ -1646,26 +1672,21 @@ void InputNewlineCommandImpl::doApply()
         TextImpl *textBeforeNode = document()->createTextNode(textNode->substringData(0, selection.start().offset(), exceptionCode));
         deleteText(textNode, 0, selection.start().offset());
         insertNodeBefore(textBeforeNode, textNode);
-        insertNodeBefore(breakNode, textNode);
-        textBeforeNode->deref();
+        insertNodeBefore(nodeToInsert, textNode);
         setEndingSelection(Position(textNode, 0));
     }
-        
-    breakNode->deref();
 }
 
 //------------------------------------------------------------------------------------------
 // InputTextCommandImpl
 
 InputTextCommandImpl::InputTextCommandImpl(DocumentImpl *document) 
-    : CompositeEditCommandImpl(document), m_insertedTextNode(0), m_charactersAdded(0)
+    : CompositeEditCommandImpl(document), m_charactersAdded(0)
 {
 }
 
 InputTextCommandImpl::~InputTextCommandImpl() 
 {
-    if (m_insertedTextNode)
-        m_insertedTextNode->deref();
 }
 
 int InputTextCommandImpl::commandID() const
@@ -1717,33 +1738,64 @@ Position InputTextCommandImpl::prepareForTextInsertion(bool adjustDownstream)
         pos = pos.equivalentUpstreamPosition();
     
     if (!pos.node()->isTextNode()) {
-        if (!m_insertedTextNode) {
-            m_insertedTextNode = document()->createEditingTextNode("");
-            m_insertedTextNode->ref();
+        NodeImpl *textNode = document()->createEditingTextNode("");
+        NodeImpl *nodeToInsert = textNode;
+        if (document()->part()->typingStyle()) {
+            int exceptionCode = 0;
+            ElementImpl *styleElement = createTypingStyleElement();
+            styleElement->appendChild(textNode, exceptionCode);
+            ASSERT(exceptionCode == 0);
+            nodeToInsert = styleElement;
         }
         
+        // Now insert the node in the right place
         if (pos.node()->isEditableBlock()) {
             LOG(Editing, "prepareForTextInsertion case 1");
-            appendNode(pos.node(), m_insertedTextNode);
+            appendNode(pos.node(), nodeToInsert);
         }
         else if (pos.node()->id() == ID_BR && pos.offset() == 1) {
             LOG(Editing, "prepareForTextInsertion case 2");
-            insertNodeBefore(m_insertedTextNode, pos.node());
+            insertNodeBefore(nodeToInsert, pos.node());
         }
         else if (pos.node()->caretMinOffset() == pos.offset()) {
             LOG(Editing, "prepareForTextInsertion case 3");
-            insertNodeBefore(m_insertedTextNode, pos.node());
+            insertNodeBefore(nodeToInsert, pos.node());
         }
         else if (pos.node()->caretMaxOffset() == pos.offset()) {
             LOG(Editing, "prepareForTextInsertion case 4");
-            insertNodeAfter(m_insertedTextNode, pos.node());
+            insertNodeAfter(nodeToInsert, pos.node());
         }
         else
             ASSERT_NOT_REACHED();
         
-        pos = Position(m_insertedTextNode, 0);
+        pos = Position(textNode, 0);
+    }
+    else {
+        // Handle the case where there is a typing style.
+        if (document()->part()->typingStyle()) {
+            if (pos.node()->isTextNode() && pos.offset() > pos.node()->caretMinOffset() && pos.offset() < pos.node()->caretMaxOffset()) {
+                // Need to split current text node in order to insert a span.
+                TextImpl *text = static_cast<TextImpl *>(pos.node());
+                SplitTextNodeCommand cmd(document(), text, pos.offset());
+                applyCommandToComposite(cmd);
+                setEndingSelection(Position(cmd.node(), 0));
+            }
+            
+            int exceptionCode = 0;
+            TextImpl *editingTextNode = document()->createEditingTextNode("");
+
+            ElementImpl *styleElement = createTypingStyleElement();
+            styleElement->appendChild(editingTextNode, exceptionCode);
+            ASSERT(exceptionCode == 0);
+
+            NodeImpl *node = endingSelection().start().node();
+            if (endingSelection().start().isLastRenderedPositionOnLine())
+                insertNodeAfter(styleElement, node);
+            else
+                insertNodeBefore(styleElement, node);
+            pos = Position(editingTextNode, 0);
+        }
     }
-    
     return pos;
 }
 
@@ -2478,7 +2530,7 @@ void TypingCommandImpl::typingAddedToOpenCommand()
 
 void TypingCommandImpl::insertText(const DOMString &text)
 {
-    if (m_cmds.count() == 0) {
+    if (document()->part()->typingStyle() || m_cmds.count() == 0) {
         InputTextCommand cmd(document());
         applyCommandToComposite(cmd);
         cmd.input(text);
diff --git a/WebCore/khtml/editing/htmlediting_impl.h b/WebCore/khtml/editing/htmlediting_impl.h
index 131f49d..33e79a7 100644
--- a/WebCore/khtml/editing/htmlediting_impl.h
+++ b/WebCore/khtml/editing/htmlediting_impl.h
@@ -139,6 +139,8 @@ protected:
     void setNodeAttribute(DOM::ElementImpl *, int attribute, const DOM::DOMString &);
     void splitTextNode(DOM::TextImpl *text, long offset);
 
+    DOM::ElementImpl *createTypingStyleElement() const;
+
     QValueList<EditCommand> m_cmds;
 };
 
@@ -333,7 +335,6 @@ private:
     void execute(const DOM::DOMString &text);
     void insertSpace(DOM::TextImpl *textNode, unsigned long offset);
 
-    DOM::TextImpl *m_insertedTextNode;
     unsigned long m_charactersAdded;
 };
 
diff --git a/WebCore/kwq/WebCoreBridge.mm b/WebCore/kwq/WebCoreBridge.mm
index 8ede873..c1347ff 100644
--- a/WebCore/kwq/WebCoreBridge.mm
+++ b/WebCore/kwq/WebCoreBridge.mm
@@ -1550,8 +1550,20 @@ static HTMLFormElementImpl *formElementFromDOMElement(DOMElement *element)
     if (!_part || !_part->xmlDocImpl() || !style)
         return;
     
-    ApplyStyleCommand cmd(_part->xmlDocImpl(), [style _styleDeclarationImpl]);
-    cmd.apply();
+    Selection selection(_part->selection());
+    switch (selection.state()) {
+        case Selection::NONE:
+            // do nothing
+            break;
+        case Selection::CARET:
+            _part->setTypingStyle([style _styleDeclarationImpl]);
+            break;
+        case Selection::RANGE: {
+            ApplyStyleCommand cmd(_part->xmlDocImpl(), [style _styleDeclarationImpl]);
+            cmd.apply();
+            break;
+        }
+    }
 }
 
 - (NSFont *)fontForCurrentPosition

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list