[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:56 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 9a1fe6109c9c413c69b18f044a02454d4e74a046
Author: kocienda <kocienda at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Jun 10 21:07:20 2004 +0000

            Reviewed by Darin
    
            Fix for this bug:
    
            <rdar://problem/3654850>: "Style changes do not work across blocks"
    
            Now, applying styles works across blocks. I did quite a bit
            of internal redsign on the member functions of this class to
            make this work. As a bonus, from an architectural standpoint,
            all style changes are now done "in place". There is no more
            copying of content in order to perform style changes.
    
            * khtml/editing/htmlediting_impl.cpp:
            (khtml::ApplyStyleCommandImpl::doApply):
            (khtml::ApplyStyleCommandImpl::removeHTMLStyleNode):
            (khtml::ApplyStyleCommandImpl::removeCSSStyle):
            (khtml::ApplyStyleCommandImpl::removeStyle):
            (khtml::ApplyStyleCommandImpl::nodeFullySelected):
            (khtml::ApplyStyleCommandImpl::splitTextAtStartIfNeeded):
            (khtml::ApplyStyleCommandImpl::splitTextAtEndIfNeeded):
            (khtml::ApplyStyleCommandImpl::surroundNodeRangeWithElement):
            (khtml::ApplyStyleCommandImpl::applyStyleIfNeeded):
            (khtml::ApplyStyleCommandImpl::positionInsertionPoint):
            * khtml/editing/htmlediting_impl.h:
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6809 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 1118123..c708187 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,30 @@
+2004-06-10  Ken Kocienda  <kocienda at apple.com>
+
+        Reviewed by Darin
+
+        Fix for this bug:
+        
+        <rdar://problem/3654850>: "Style changes do not work across blocks"
+        
+        Now, applying styles works across blocks. I did quite a bit
+        of internal redsign on the member functions of this class to
+        make this work. As a bonus, from an architectural standpoint,
+        all style changes are now done "in place". There is no more
+        copying of content in order to perform style changes.
+
+        * khtml/editing/htmlediting_impl.cpp:
+        (khtml::ApplyStyleCommandImpl::doApply):
+        (khtml::ApplyStyleCommandImpl::removeHTMLStyleNode):
+        (khtml::ApplyStyleCommandImpl::removeCSSStyle):
+        (khtml::ApplyStyleCommandImpl::removeStyle):
+        (khtml::ApplyStyleCommandImpl::nodeFullySelected):
+        (khtml::ApplyStyleCommandImpl::splitTextAtStartIfNeeded):
+        (khtml::ApplyStyleCommandImpl::splitTextAtEndIfNeeded):
+        (khtml::ApplyStyleCommandImpl::surroundNodeRangeWithElement):
+        (khtml::ApplyStyleCommandImpl::applyStyleIfNeeded):
+        (khtml::ApplyStyleCommandImpl::positionInsertionPoint):
+        * khtml/editing/htmlediting_impl.h:
+
 2004-06-10  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 323296d..7d4e332 100644
--- a/WebCore/khtml/editing/htmlediting_impl.cpp
+++ b/WebCore/khtml/editing/htmlediting_impl.cpp
@@ -624,15 +624,45 @@ void ApplyStyleCommandImpl::doApply()
     if (endingSelection().state() != Selection::RANGE)
         return;
 
-    // Right now, we only apply in place if the start and end are in the same
-    // node. This could be improved in the future to handle more cases that
-    // are only a bit more complex than this case.
-    Position start(endingSelection().start().equivalentDownstreamPosition());
+    // adjust to the positions we want to use for applying style
+    Position start(endingSelection().start().equivalentDownstreamPosition().equivalentRangeCompliantPosition());
     Position end(endingSelection().end().equivalentUpstreamPosition());
-    if (start.node() == end.node())
-        applyInPlace(start, end);
-    else
-        applyUsingFragment();
+
+    // remove style from the selection
+    removeStyle(start, end);
+    bool splitStart = splitTextAtStartIfNeeded(start, end); 
+    if (splitStart) {
+        start = endingSelection().start();
+        end = endingSelection().end();
+    }
+    splitTextAtEndIfNeeded(start, end);
+    start = endingSelection().start();
+    end = endingSelection().end();
+
+    
+    if (start.node() == end.node()) {
+        // simple case...start and end are the same node
+        applyStyleIfNeeded(start.node(), end.node());
+    }
+    else {
+        NodeImpl *node = start.node();
+        while (1) {
+            if (node->childNodeCount() == 0 && node->renderer() && node->renderer()->isInline()) {
+                NodeImpl *runStart = node;
+                while (1) {
+                    if (runStart->parentNode() != node->parentNode() || node->isHTMLElement() || node == end.node() || 
+                        (node->renderer() && !node->renderer()->isInline())) {
+                        applyStyleIfNeeded(runStart, node);
+                        break;
+                    }
+                    node = node->traverseNextNode();
+                }
+            }
+            if (node == end.node())
+                break;
+            node = node->traverseNextNode();
+        }
+    }
 }
 
 //------------------------------------------------------------------------------------------
@@ -657,17 +687,17 @@ bool ApplyStyleCommandImpl::isHTMLStyleNode(HTMLElementImpl *elem)
     return false;
 }
 
-void ApplyStyleCommandImpl::removeHTMLStyleNode(HTMLElementImpl *elem, EUndoable undoable)
+void ApplyStyleCommandImpl::removeHTMLStyleNode(HTMLElementImpl *elem)
 {
     // This node can be removed.
     // EDIT FIXME: This does not handle the case where the node
     // has attributes. But how often do people add attributes to <B> tags? 
     // Not so often I think.
     ASSERT(elem);
-    removeNodePreservingChildren(elem, undoable);
+    removeNodePreservingChildren(elem);
 }
 
-void ApplyStyleCommandImpl::removeCSSStyle(HTMLElementImpl *elem, EUndoable undoable)
+void ApplyStyleCommandImpl::removeCSSStyle(HTMLElementImpl *elem)
 {
     ASSERT(elem);
 
@@ -678,83 +708,132 @@ void ApplyStyleCommandImpl::removeCSSStyle(HTMLElementImpl *elem, EUndoable undo
     for (QPtrListIterator<CSSProperty> it(*(style()->values())); it.current(); ++it) {
         CSSProperty *property = it.current();
         if (decl->getPropertyCSSValue(property->id()))
-            removeCSSProperty(decl, property->id(), undoable);
+            removeCSSProperty(decl, property->id());
     }
 
-    // EDIT FIXME: These four lines of code should not be necessary.
-    // The DOM should update without having to do this extra work.
-    if (decl->values()->count() > 0)
-        setNodeAttribute(elem, ATTR_STYLE, decl->cssText(), undoable);
-    else
-        removeNodeAttribute(elem, ATTR_STYLE, undoable);
-
     if (elem->id() == ID_SPAN) {
         // Check to see if the span is one we added to apply style.
         // If it is, and there are no more attributes on the span other than our
         // class marker, remove the span.
         NamedAttrMapImpl *map = elem->attributes();
         if (map && map->length() == 1 && elem->getAttribute(ATTR_CLASS) == styleSpanClassString())
-            removeNodePreservingChildren(elem, undoable);
+            removeNodePreservingChildren(elem);
     }
 }
 
-void ApplyStyleCommandImpl::removeCSSProperty(CSSStyleDeclarationImpl *decl, int property, EUndoable undoable)
+void ApplyStyleCommandImpl::removeStyle(const Position &start, const Position &end)
 {
-    if (undoable == UNDOABLE)
-        CompositeEditCommandImpl::removeCSSProperty(decl, property);
-    else
-        decl->removeProperty(property);
+    NodeImpl *node = start.node();
+    while (1) {
+        NodeImpl *next = node->traverseNextNode();
+        if (node->isHTMLElement() && nodeFullySelected(node)) {
+            HTMLElementImpl *elem = static_cast<HTMLElementImpl *>(node);
+            if (isHTMLStyleNode(elem))
+                removeHTMLStyleNode(elem);
+            else
+                removeCSSStyle(elem);
+        }
+        if (node == end.node())
+            break;
+        node = next;
+    }
 }
 
-void ApplyStyleCommandImpl::setNodeAttribute(ElementImpl *elem, int attribute, const DOMString &value, EUndoable undoable)
+bool ApplyStyleCommandImpl::nodeFullySelected(const NodeImpl *node) const
 {
-    if (undoable == UNDOABLE) {
-        CompositeEditCommandImpl::setNodeAttribute(elem, attribute, value);
+    ASSERT(node);
+
+    Position end(endingSelection().end().equivalentUpstreamPosition());
+    
+    if (node == end.node())
+        return end.offset() >= node->caretMaxOffset();
+
+    for (NodeImpl *child = node->lastChild(); child; child = child->lastChild()) {
+        if (child == end.node())
+            return end.offset() >= child->caretMaxOffset();
     }
-    else {
-        int exceptionCode = 0;
-        elem->setAttribute(attribute, value.implementation(), exceptionCode);
-        ASSERT(exceptionCode == 0);
+
+    return !node->isAncestor(end.node());
+}
+
+//------------------------------------------------------------------------------------------
+// ApplyStyleCommandImpl: style-application helpers
+
+
+bool ApplyStyleCommandImpl::splitTextAtStartIfNeeded(const Position &start, const Position &end)
+{
+    if (start.node()->isTextNode() && start.offset() > start.node()->caretMinOffset() && start.offset() < start.node()->caretMaxOffset()) {
+        long endOffsetAdjustment = start.node() == end.node() ? start.offset() : 0;
+        TextImpl *text = static_cast<TextImpl *>(start.node());
+        SplitTextNodeCommand cmd(document(), text, start.offset());
+        applyCommandToComposite(cmd);
+        setEndingSelection(Selection(Position(start.node(), 0), Position(end.node(), end.offset() - endOffsetAdjustment)));
+        return true;
     }
+    return false;
 }
 
-void ApplyStyleCommandImpl::removeNodeAttribute(ElementImpl *elem, int attribute, EUndoable undoable)
+NodeImpl *ApplyStyleCommandImpl::splitTextAtEndIfNeeded(const Position &start, const Position &end)
 {
-    if (undoable == UNDOABLE) {
-        CompositeEditCommandImpl::removeNodeAttribute(elem, attribute);
+    if (end.node()->isTextNode() && end.offset() > end.node()->caretMinOffset() && end.offset() < end.node()->caretMaxOffset()) {
+        TextImpl *text = static_cast<TextImpl *>(end.node());
+        SplitTextNodeCommand cmd(document(), text, end.offset());
+        applyCommandToComposite(cmd);
+        NodeImpl *startNode = start.node() == end.node() ? cmd.node()->previousSibling() : start.node();
+        ASSERT(startNode);
+        setEndingSelection(Selection(Position(startNode, start.offset()), Position(cmd.node()->previousSibling(), cmd.node()->previousSibling()->caretMaxOffset())));
+        return cmd.node()->previousSibling();
     }
-    else {
-        int exceptionCode = 0;
-        elem->removeAttribute(attribute, exceptionCode);
-        ASSERT(exceptionCode == 0);
+    return end.node();
+}
+
+void ApplyStyleCommandImpl::surroundNodeRangeWithElement(NodeImpl *startNode, NodeImpl *endNode, ElementImpl *element)
+{
+    ASSERT(startNode);
+    ASSERT(endNode);
+    ASSERT(element);
+    
+    NodeImpl *node = startNode;
+    while (1) {
+        NodeImpl *next = node->traverseNextNode();
+        if (node->childNodeCount() == 0 && node->renderer() && node->renderer()->isInline()) {
+            removeNode(node);
+            appendNode(element, node);
+        }
+        if (node == endNode)
+            break;
+        node = next;
     }
 }
 
-void ApplyStyleCommandImpl::removeNodePreservingChildren(NodeImpl *parent, EUndoable undoable)
+void ApplyStyleCommandImpl::applyStyleIfNeeded(DOM::NodeImpl *startNode, DOM::NodeImpl *endNode)
 {
-    if (undoable == UNDOABLE) {
-        CompositeEditCommandImpl::removeNodePreservingChildren(parent);
+    StyleChange styleChange = computeStyleChange(Position(startNode, 0), style());
+    int exceptionCode = 0;
+    
+    if (styleChange.cssStyle.length() > 0) {
+        ElementImpl *styleElement = document()->createHTMLElement("SPAN", exceptionCode);
+        ASSERT(exceptionCode == 0);
+        styleElement->setAttribute(ATTR_STYLE, styleChange.cssStyle);
+        styleElement->setAttribute(ATTR_CLASS, styleSpanClassString());
+        insertNodeBefore(styleElement, startNode);
+        surroundNodeRangeWithElement(startNode, endNode, styleElement);
     }
-    else {
-        NodeImpl *grandparent = parent->parentNode();
-        ASSERT(grandparent);
-        int exceptionCode = 0;
-        while (parent->firstChild()) {
-            NodeImpl *child = parent->firstChild();
-            child->ref();
-            parent->removeChild(child, exceptionCode);
-            ASSERT(exceptionCode == 0);
-            grandparent->insertBefore(child, parent, exceptionCode);
-            ASSERT(exceptionCode == 0);
-            child->deref();
-        }
-        parent->parentNode()->removeChild(parent, exceptionCode);
+
+    if (styleChange.applyBold) {
+        ElementImpl *boldElement = document()->createHTMLElement("B", exceptionCode);
         ASSERT(exceptionCode == 0);
+        insertNodeBefore(boldElement, startNode);
+        surroundNodeRangeWithElement(startNode, endNode, boldElement);
     }
-}
 
-//------------------------------------------------------------------------------------------
-// ApplyStyleCommandImpl: shared helpers
+    if (styleChange.applyItalic) {
+        ElementImpl *italicElement = document()->createHTMLElement("I", exceptionCode);
+        ASSERT(exceptionCode == 0);
+        insertNodeBefore(italicElement, startNode);
+        surroundNodeRangeWithElement(startNode, endNode, italicElement);
+    }
+}
 
 bool ApplyStyleCommandImpl::currentlyHasStyle(const Position &pos, const CSSProperty *property) const
 {
@@ -799,9 +878,6 @@ ApplyStyleCommandImpl::StyleChange ApplyStyleCommandImpl::computeStyleChange(con
     return styleChange;
 }
 
-//------------------------------------------------------------------------------------------
-// ApplyStyleCommandImpl: apply-in-place helpers
-
 Position ApplyStyleCommandImpl::positionInsertionPoint(Position pos)
 {
     if (pos.node()->isTextNode() && (pos.offset() > 0 && pos.offset() < pos.node()->maxOffset())) {
@@ -843,288 +919,6 @@ Position ApplyStyleCommandImpl::positionInsertionPoint(Position pos)
     return pos;
 }
 
-bool ApplyStyleCommandImpl::splitTextAtStartIfNeeded(const Position &start, const Position &end)
-{
-    if (start.node()->isTextNode() && start.offset() > start.node()->caretMinOffset() && start.offset() < start.node()->caretMaxOffset()) {
-        long endOffsetAdjustment = start.node() == end.node() ? start.offset() : 0;
-        TextImpl *text = static_cast<TextImpl *>(start.node());
-        SplitTextNodeCommand cmd(document(), text, start.offset());
-        applyCommandToComposite(cmd);
-        setEndingSelection(Selection(Position(start.node(), 0), Position(end.node(), end.offset() - endOffsetAdjustment)));
-        return true;
-    }
-    return false;
-}
-
-bool ApplyStyleCommandImpl::splitTextAtEndIfNeeded(const Position &start, const Position &end)
-{
-    if (end.node()->isTextNode() && end.offset() > end.node()->caretMinOffset() && end.offset() < end.node()->caretMaxOffset()) {
-        TextImpl *text = static_cast<TextImpl *>(end.node());
-        SplitTextNodeCommand cmd(document(), text, end.offset());
-        applyCommandToComposite(cmd);
-        NodeImpl *startNode = start.node() == end.node() ? cmd.node()->previousSibling() : start.node();
-        ASSERT(startNode);
-        ASSERT(startNode->isTextNode());
-        setEndingSelection(Selection(Position(startNode, start.offset()), Position(cmd.node()->previousSibling(), cmd.node()->previousSibling()->caretMaxOffset())));
-        return true;
-    }
-    return false;
-}
-
-void ApplyStyleCommandImpl::applyStyleIfNeeded(const Position &insertionPoint)
-{
-    ASSERT(insertionPoint.notEmpty());
-
-    StyleChange styleChange = computeStyleChange(insertionPoint, style());
-    NodeImpl *contentNode = insertionPoint.node();
-    int exceptionCode = 0;
-
-    if (styleChange.cssStyle.length() > 0) {
-        ElementImpl *styleElement = document()->createHTMLElement("SPAN", exceptionCode);
-        ASSERT(exceptionCode == 0);
-        styleElement->setAttribute(ATTR_STYLE, styleChange.cssStyle);
-        styleElement->setAttribute(ATTR_CLASS, styleSpanClassString());
-        insertNodeBefore(styleElement, contentNode);
-        removeNode(contentNode);
-        appendNode(styleElement, contentNode);
-    }
-
-    if (styleChange.applyBold) {
-        ElementImpl *boldElement = document()->createHTMLElement("B", exceptionCode);
-        ASSERT(exceptionCode == 0);
-        insertNodeBefore(boldElement, contentNode);
-        removeNode(contentNode);
-        appendNode(boldElement, contentNode);
-    }
-
-    if (styleChange.applyItalic) {
-        ElementImpl *italicElement = document()->createHTMLElement("I", exceptionCode);
-        ASSERT(exceptionCode == 0);
-        insertNodeBefore(italicElement, contentNode);
-        removeNode(contentNode);
-        appendNode(italicElement, contentNode);
-    }
-}
-
-void ApplyStyleCommandImpl::removeStyle(const Position &s, const Position &e)
-{
-    Position start(s.equivalentDownstreamPosition().equivalentShallowPosition().equivalentRangeCompliantPosition());
-    Position end(e.equivalentUpstreamPosition());
-    NodeImpl *node = start.node();
-    while (node != end.node()) {
-        NodeImpl *next = node->traverseNextNode();
-        if (node->isHTMLElement()) {
-            HTMLElementImpl *elem = static_cast<HTMLElementImpl *>(node);
-            if (isHTMLStyleNode(elem))
-                removeHTMLStyleNode(elem, UNDOABLE);
-            else
-                removeCSSStyle(elem, UNDOABLE);
-        }
-        node = next;
-    }
-}
-
-//------------------------------------------------------------------------------------------
-// ApplyStyleCommandImpl: apply using fragment helpers
-
-DocumentFragmentImpl *ApplyStyleCommandImpl::cloneSelection() const
-{
-    RangeImpl *range = document()->createRange();
-    range->ref();
-    
-    int exceptionCode = 0;
-    Position pos = endingSelection().start();
-    
-    pos = endingSelection().start().equivalentShallowPosition().equivalentRangeCompliantPosition();
-    range->setStart(pos.node(), pos.offset(), exceptionCode);
-    ASSERT(exceptionCode == 0);
-    
-    pos = endingSelection().end().equivalentUpstreamPosition().equivalentRangeCompliantPosition();
-    range->setEnd(pos.node(), pos.offset(), exceptionCode);
-    ASSERT(exceptionCode == 0);
-
-    DocumentFragmentImpl *fragment = range->cloneContents(exceptionCode);
-    ASSERT(exceptionCode == 0);
-    ASSERT(fragment->firstChild());
-
-    range->detach(exceptionCode);
-    ASSERT(exceptionCode == 0);
-
-    range->deref();
-
-    return fragment;
-}
-
-void ApplyStyleCommandImpl::removeStyle(DocumentFragmentImpl *fragment)
-{
-    ASSERT(fragment);
-    
-    NodeImpl *node = fragment->firstChild();
-    while (node) {
-        NodeImpl *next = node->traverseNextNode();
-        if (node->isHTMLElement()) {
-            HTMLElementImpl *elem = static_cast<HTMLElementImpl *>(node);
-            if (isHTMLStyleNode(elem))
-                removeHTMLStyleNode(elem, NOTUNDOABLE);
-            else
-                removeCSSStyle(elem, NOTUNDOABLE);
-        }
-        node = next;
-    }
-}
-
-void ApplyStyleCommandImpl::surroundContentsWithElement(DocumentFragmentImpl *fragment, ElementImpl *element) 
-{
-    ASSERT(fragment);
-    ASSERT(element);
-
-    int exceptionCode = 0;
-    NodeImpl *node = fragment->firstChild();
-    while (node) {
-        NodeImpl *next = node->nextSibling();
-        node->ref();
-        fragment->removeChild(node, exceptionCode);
-        ASSERT(exceptionCode == 0);
-        element->appendChild(node, exceptionCode);
-        ASSERT(exceptionCode == 0);
-        node->deref();
-        node = next;
-    }
-    fragment->appendChild(element, exceptionCode);
-    ASSERT(exceptionCode == 0);
-}
-
-void ApplyStyleCommandImpl::applyStyleIfNeeded(DocumentFragmentImpl *fragment, const Position &insertionPoint)
-{
-    ASSERT(insertionPoint.notEmpty());
-
-    StyleChange styleChange = computeStyleChange(insertionPoint, style());
-    int exceptionCode = 0;
-
-    if (styleChange.cssStyle.length() > 0) {
-        ElementImpl *styleElement = document()->createHTMLElement("SPAN", exceptionCode);
-        ASSERT(exceptionCode == 0);
-        styleElement->setAttribute(ATTR_STYLE, styleChange.cssStyle);
-        styleElement->setAttribute(ATTR_CLASS, styleSpanClassString());
-        surroundContentsWithElement(fragment, styleElement);
-    }
-
-    if (styleChange.applyBold) {
-        ElementImpl *boldElement = document()->createHTMLElement("B", exceptionCode);
-        ASSERT(exceptionCode == 0);
-        surroundContentsWithElement(fragment, boldElement);
-    }
-
-    if (styleChange.applyItalic) {
-        ElementImpl *italicElement = document()->createHTMLElement("I", exceptionCode);
-        ASSERT(exceptionCode == 0);
-        surroundContentsWithElement(fragment, italicElement);
-    }
-}
-
-void ApplyStyleCommandImpl::insertFragment(DocumentFragmentImpl *fragment, const Position &pos)
-{
-    ASSERT(fragment);
-    ASSERT(pos.notEmpty());
-
-    if (pos.node()->previousSibling()) {
-        NodeImpl *node = fragment->lastChild();
-        while (node) {
-            int exceptionCode = 0;
-            NodeImpl *prev = node->previousSibling();
-            node->ref();
-            fragment->removeChild(node, exceptionCode);
-            ASSERT(exceptionCode == 0);
-            insertNodeAfter(node, pos.node());
-            node->deref();
-            node = prev;
-        }
-    }
-    else {
-        NodeImpl *node = fragment->firstChild();
-        while (node) {
-            int exceptionCode = 0;
-            NodeImpl *next = node->nextSibling();
-            node->ref();
-            fragment->removeChild(node, exceptionCode);
-            ASSERT(exceptionCode == 0);
-            insertNodeBefore(node, pos.node());
-            node->deref();
-            node = next;
-        }
-    }
-}
-
-//------------------------------------------------------------------------------------------
-// ApplyStyleCommandImpl: different cases we recognize and treat differently
-
-void ApplyStyleCommandImpl::applyInPlace(const Position &s, const Position &e)
-{
-    // Style-change request is being done on a sufficiently simple portion of the tree
-    // such that the style change can be done in place.
-
-    // If the start position of the selection is in the middle of a text node, split it.
-    Position start(s);
-    Position end(e);
-    bool splitStart = splitTextAtStartIfNeeded(start, end);
-
-    // If the end position of the selection is in the middle of a text node, split it.
-    if (splitStart) {
-        start = endingSelection().start();
-        end = endingSelection().end();
-    }
-    bool splitEnd = splitTextAtEndIfNeeded(start, end);
-    
-    // If neither start nor end is in the middle of a text node, have a look
-    // to see if any style can be removed from the current selection.
-    if (!splitStart && !splitEnd)
-        removeStyle(start, end);
-    
-    // Apply style if needed (it might not be needed in cases 
-    // where removing style, as done above, makes this content take on the needed style).
-    applyStyleIfNeeded(positionInsertionPoint(endingSelection().start()));
-}
-
-void ApplyStyleCommandImpl::applyUsingFragment()
-{
-    // Style-change request is being done on a sufficiently complex portion of the tree
-    // such that we use a cloned copy of the content in the selection to perform
-    // the style change. 
-    // FIXME: This is more heavy-weight than we might like for some cases,
-    // but it is a start.
-
-    // Start off by creating a cloned document fragment for the selected content
-    // and then delete the selection using the undoable delete. This is an
-    // important part of what makes this operation undoable.
-    DocumentFragmentImpl *fragment = cloneSelection();
-    ASSERT(fragment);
-    fragment->ref();
-    deleteSelection();
-
-    // Move the selection to the edges of the current insertion point left
-    // by the delete selection step. This makes it easy to shift the selection
-    // to the edges of the fragment content once it is reinserted.
-    Position start(endingSelection().start().equivalentUpstreamPosition());
-    Position end(endingSelection().end().equivalentDownstreamPosition());
-
-    // Now process the fragment:
-    // 1. Remove all traces of style we are applying or removing
-    // 2. Apply style if needed (it might not be needed in cases 
-    //    where removing style, as done above, makes this content take on 
-    //    the needed style).
-    // 3. Reinsert fragment into document.
-    // 4. Deref the fragment
-    removeStyle(fragment);
-    applyStyleIfNeeded(fragment, start);
-    insertFragment(fragment, start);
-    fragment->deref();
-
-    // Shift the selection to the edges of the re-inserted fragment content.
-    start = start.equivalentDownstreamPosition();
-    end = end.equivalentUpstreamPosition();
-    setEndingSelection(Selection(start, end));
-}
-
 //------------------------------------------------------------------------------------------
 // DeleteCollapsibleWhitespaceCommandImpl
 
diff --git a/WebCore/khtml/editing/htmlediting_impl.h b/WebCore/khtml/editing/htmlediting_impl.h
index 2031a47..a9462b2 100644
--- a/WebCore/khtml/editing/htmlediting_impl.h
+++ b/WebCore/khtml/editing/htmlediting_impl.h
@@ -192,36 +192,20 @@ public:
 
 private:
     // style-removal helpers
-    enum EUndoable { UNDOABLE, NOTUNDOABLE };
     bool isHTMLStyleNode(DOM::HTMLElementImpl *);
-    void removeHTMLStyleNode(DOM::HTMLElementImpl *, EUndoable undoable);
-    void removeCSSStyle(DOM::HTMLElementImpl *, EUndoable undoable);
-    void removeCSSProperty(DOM::CSSStyleDeclarationImpl *, int property, EUndoable undoable);
-    void setNodeAttribute(DOM::ElementImpl *, int attribute, const DOM::DOMString &, EUndoable undoable);
-    void removeNodeAttribute(DOM::ElementImpl *, int attribute, EUndoable undoable);
-    void removeNodePreservingChildren(DOM::NodeImpl *, EUndoable undoable);
-
-    // shared helpers
+    void removeHTMLStyleNode(DOM::HTMLElementImpl *);
+    void removeCSSStyle(DOM::HTMLElementImpl *);
+    void removeStyle(const DOM::Position &start, const DOM::Position &end);
+    bool nodeFullySelected(const DOM::NodeImpl *node) const;
+
+    // style-application helpers
     bool currentlyHasStyle(const DOM::Position &, const DOM::CSSProperty *) const;
     StyleChange computeStyleChange(const DOM::Position &, DOM::CSSStyleDeclarationImpl *);
-     
-    // apply-in-place helpers
-    DOM::Position positionInsertionPoint(DOM::Position);
     bool splitTextAtStartIfNeeded(const DOM::Position &start, const DOM::Position &end);
-    bool splitTextAtEndIfNeeded(const DOM::Position &start, const DOM::Position &end);
-    void removeStyle(const DOM::Position &start, const DOM::Position &end);
-    void applyStyleIfNeeded(const DOM::Position &);
-
-    // apply using fragment helpers
-    DOM::DocumentFragmentImpl *cloneSelection() const;
-    void removeStyle(DOM::DocumentFragmentImpl *);
-    void surroundContentsWithElement(DOM::DocumentFragmentImpl *, DOM::ElementImpl *);
-    void applyStyleIfNeeded(DOM::DocumentFragmentImpl *, const DOM::Position &);
-    void insertFragment(DOM::DocumentFragmentImpl *, const DOM::Position &);
-
-    // different cases we recognize and treat differently
-    void applyInPlace(const DOM::Position &s, const DOM::Position &e);
-    void applyUsingFragment();
+    DOM::NodeImpl *splitTextAtEndIfNeeded(const DOM::Position &start, const DOM::Position &end);
+    void surroundNodeRangeWithElement(DOM::NodeImpl *start, DOM::NodeImpl *end, DOM::ElementImpl *element);
+    DOM::Position positionInsertionPoint(DOM::Position);
+    void applyStyleIfNeeded(DOM::NodeImpl *start, DOM::NodeImpl *end);
     
     DOM::CSSStyleDeclarationImpl *m_style;
 };

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list