Reviewed by Darin
authorkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Aug 2004 20:19:53 +0000 (20:19 +0000)
committerkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Aug 2004 20:19:53 +0000 (20:19 +0000)
        * khtml/css/css_computedstyle.cpp:
        (DOM::): Changed CopyProperties constant to InheritableProperties. This reflects the
        name change of copy() to copyInheritableProperties()
        (DOM::CSSComputedStyleDeclarationImpl::copyInheritableProperties: Renamed from copy().
        Now just copies those properties which can be inherited.
        (DOM::CSSComputedStyleDeclarationImpl::diff): Add a couple null checks.
        * khtml/css/css_computedstyle.h: copyInheritableProperties name change. No longer needs to be virtual.
        * khtml/css/css_valueimpl.cpp: Removed unneeded copy() function from CSSStyleDeclarationImpl.
        * khtml/css/css_valueimpl.h: Ditto.
        * khtml/editing/htmlediting.cpp:
        (khtml::EditCommand::typingStyle): Added.
        (khtml::EditCommand::setTypingStyle): Added.
        * khtml/editing/htmlediting.h:
        * khtml/editing/htmlediting_impl.cpp:
        (khtml::StyleChange::currentlyHasStyle): Fix leak of computed style used in this function.
        (khtml::EditCommandImpl::EditCommandImpl): Initialize m_typingStyle.
        (khtml::EditCommandImpl::~EditCommandImpl): Deref m_typingStyle.
        (khtml::EditCommandImpl::assignTypingStyle): New helper used in setting typing style.
        (khtml::EditCommandImpl::setTypingStyle): New setter.
        (khtml::DeleteSelectionCommandImpl::doApply): Use new method for managing typing style.
        * khtml/editing/htmlediting_impl.h:
        (khtml::EditCommandImpl::typingStyle): New accessor.
        * khtml/khtml_part.cpp:
        (KHTMLPart::appliedEditing): Restores typing style from command after setting selection.
        (KHTMLPart::applyStyle): Does a diff between the current style and the style of the caret.
        * khtml/khtml_part.h:
        * khtml/xml/dom_position.cpp:
        (DOM::Position::computedStyle): Now returns a CSSComputedStyleDeclarationImpl instead of a plain
        CSSStyleDeclarationImpl.
        * khtml/xml/dom_position.h:
        * layout-tests/editing/style/style-3681552-fix-002-expected.txt:

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

14 files changed:
LayoutTests/editing/style/style-3681552-fix-002-expected.txt
WebCore/ChangeLog-2005-08-23
WebCore/khtml/css/css_computedstyle.cpp
WebCore/khtml/css/css_computedstyle.h
WebCore/khtml/css/css_valueimpl.cpp
WebCore/khtml/css/css_valueimpl.h
WebCore/khtml/editing/htmlediting.cpp
WebCore/khtml/editing/htmlediting.h
WebCore/khtml/editing/htmlediting_impl.cpp
WebCore/khtml/editing/htmlediting_impl.h
WebCore/khtml/khtml_part.cpp
WebCore/khtml/khtml_part.h
WebCore/khtml/xml/dom_position.cpp
WebCore/khtml/xml/dom_position.h

index 94702e6137f0d646b08e6cbf94877b3d80a01d23..8845796deddb1ceea252b4e093e6f35be31ffbe4 100644 (file)
@@ -4,16 +4,16 @@ layer at (0,0) size 800x600
   RenderBlock {HTML} at (0,0) size 800x600
     RenderBody {BODY} at (8,8) size 784x584
       RenderBlock {DIV} at (0,0) size 784x56 [border: (2px solid #FF0000)]
-        RenderInline {SPAN} at (0,0) size 167x28
-          RenderText {TEXT} at (14,14) size 118x28
-            text run at (14,14) width 118: "here is xxxx"
-          RenderInline {I} at (0,0) size 6x28
-            RenderText {TEXT} at (132,14) size 6x28
-              text run at (132,14) width 6: " "
-          RenderText {TEXT} at (138,14) size 43x28
-            text run at (138,14) width 43: " text"
+        RenderInline {SPAN} at (0,0) size 157x28
+          RenderText {TEXT} at (14,14) size 70x28
+            text run at (14,14) width 70: "here is "
+          RenderInline {I} at (0,0) size 44x28
+            RenderText {TEXT} at (84,14) size 44x28
+              text run at (84,14) width 44: "xxxx"
+          RenderText {TEXT} at (128,14) size 43x28
+            text run at (128,14) width 43: " text"
         RenderText {TEXT} at (0,0) size 0x0
 selection is CARET:
-start:      position 12 of child 1 {TEXT} of child 2 {SPAN} of root {DIV}
-upstream:   position 12 of child 1 {TEXT} of child 2 {SPAN} of root {DIV}
-downstream: position 0 of child 1 {TEXT} of child 2 {I} of child 2 {SPAN} of root {DIV}
+start:      position 4 of child 1 {TEXT} of child 2 {I} of child 2 {SPAN} of root {DIV}
+upstream:   position 4 of child 1 {TEXT} of child 2 {I} of child 2 {SPAN} of root {DIV}
+downstream: position 0 of child 3 {TEXT} of child 2 {SPAN} of root {DIV}
index 8445b80821bf438d86623b648df76c8a05bc53f4..a08402ad9803605a48b0011dd9a3078e886d8e3c 100644 (file)
@@ -1,3 +1,39 @@
+2004-08-19  Ken Kocienda  <kocienda@apple.com>
+
+        Reviewed by Darin
+
+        * khtml/css/css_computedstyle.cpp:
+        (DOM::): Changed CopyProperties constant to InheritableProperties. This reflects the
+        name change of copy() to copyInheritableProperties()
+        (DOM::CSSComputedStyleDeclarationImpl::copyInheritableProperties: Renamed from copy().
+        Now just copies those properties which can be inherited.
+        (DOM::CSSComputedStyleDeclarationImpl::diff): Add a couple null checks.
+        * khtml/css/css_computedstyle.h: copyInheritableProperties name change. No longer needs to be virtual.
+        * khtml/css/css_valueimpl.cpp: Removed unneeded copy() function from CSSStyleDeclarationImpl.
+        * khtml/css/css_valueimpl.h: Ditto.
+        * khtml/editing/htmlediting.cpp:
+        (khtml::EditCommand::typingStyle): Added.
+        (khtml::EditCommand::setTypingStyle): Added.
+        * khtml/editing/htmlediting.h:
+        * khtml/editing/htmlediting_impl.cpp:
+        (khtml::StyleChange::currentlyHasStyle): Fix leak of computed style used in this function.
+        (khtml::EditCommandImpl::EditCommandImpl): Initialize m_typingStyle.
+        (khtml::EditCommandImpl::~EditCommandImpl): Deref m_typingStyle.
+        (khtml::EditCommandImpl::assignTypingStyle): New helper used in setting typing style.
+        (khtml::EditCommandImpl::setTypingStyle): New setter.
+        (khtml::DeleteSelectionCommandImpl::doApply): Use new method for managing typing style.
+        * khtml/editing/htmlediting_impl.h:
+        (khtml::EditCommandImpl::typingStyle): New accessor.
+        * khtml/khtml_part.cpp:
+        (KHTMLPart::appliedEditing): Restores typing style from command after setting selection.
+        (KHTMLPart::applyStyle): Does a diff between the current style and the style of the caret.
+        * khtml/khtml_part.h:
+        * khtml/xml/dom_position.cpp:
+        (DOM::Position::computedStyle): Now returns a CSSComputedStyleDeclarationImpl instead of a plain
+        CSSStyleDeclarationImpl.
+        * khtml/xml/dom_position.h:
+        * layout-tests/editing/style/style-3681552-fix-002-expected.txt:
+
 2004-08-20  Trey Matteson  <trey@apple.com>
 
        3655407 - Editing: -complete: method unimplemented (WebKit editing API)
         (DOM::XSLTProcessorImpl::transformDocument):
         * khtml/xsl/xslt_processorimpl.h:
 
+>>>>>>> 1.3109
 === Safari-158 ===
 
 2004-08-18  Trey Matteson  <trey@apple.com>
 
 2004-08-18  Richard Williamson   <rjw@apple.com>
 
+<<<<<<< ChangeLog
+        Replace horrible pollForAppletInView: with new
+        webPlugInGetApplet.  The details of how the applet instance
+        is provided now belong to the Java team.  Yeh.
+               
+        Reviewed by Chris.
+
+=======
         Replace horrible pollForAppletInView: with new
         webPlugInGetApplet.  The details of how the applet instance
         is provided now belong to the Java team.  Yeh.
                
         Reviewed by Chris.
+>>>>>>> 1.3109
         * kwq/KWQKHTMLPart.mm:
         (KWQKHTMLPart::getAppletInstanceForView):
         * kwq/WebCoreBridge.h:
index adad0529e959975088924e1159660c6897fa7ad0..6a783c67a32c009ac5a1335fb64a5a4bdf26ad1a 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "cssproperties.h"
 #include "dom_atomicstring.h"
+#include "dom_string.h"
 #include "font.h"
 #include "khtmllayout.h"
 #include "loader.h"
@@ -43,56 +44,23 @@ using khtml::Length;
 
 namespace DOM {
 
-static const int CopyProperties[] = {
-    CSS_PROP__KHTML_BORDER_HORIZONTAL_SPACING,
-    CSS_PROP__KHTML_BORDER_VERTICAL_SPACING,
-    CSS_PROP_BACKGROUND_ATTACHMENT,
-    CSS_PROP_BACKGROUND_COLOR,
-    CSS_PROP_BACKGROUND_IMAGE,
-    CSS_PROP_BACKGROUND_POSITION_X,
-    CSS_PROP_BACKGROUND_POSITION_Y,
-    CSS_PROP_BACKGROUND_POSITION,
-    CSS_PROP_BACKGROUND_REPEAT,
-    CSS_PROP_BORDER_BOTTOM_COLOR,
-    CSS_PROP_BORDER_BOTTOM_STYLE,
-    CSS_PROP_BORDER_BOTTOM_WIDTH,
+// This is the list of properties we want to copy in the copyInheritableProperties() function.
+// It is the intersection of the list of inherited CSS properties and the
+// properties for which we have a computed implementation in this file.
+static const int InheritableProperties[] = {
     CSS_PROP_BORDER_COLLAPSE,
-    CSS_PROP_BORDER_LEFT_COLOR,
-    CSS_PROP_BORDER_LEFT_STYLE,
-    CSS_PROP_BORDER_LEFT_WIDTH,
-    CSS_PROP_BORDER_RIGHT_COLOR,
-    CSS_PROP_BORDER_RIGHT_STYLE,
-    CSS_PROP_BORDER_RIGHT_WIDTH,
     CSS_PROP_BORDER_SPACING,
-    CSS_PROP_BORDER_TOP_COLOR,
-    CSS_PROP_BORDER_TOP_STYLE,
-    CSS_PROP_BORDER_TOP_WIDTH,
     CSS_PROP_COLOR,
-    CSS_PROP_DISPLAY,
-    CSS_PROP_FLOAT,
     CSS_PROP_FONT_FAMILY,
     CSS_PROP_FONT_SIZE,
     CSS_PROP_FONT_STYLE,
     CSS_PROP_FONT_VARIANT,
     CSS_PROP_FONT_WEIGHT,
-    CSS_PROP_HEIGHT,
     CSS_PROP_LETTER_SPACING,
     CSS_PROP_LINE_HEIGHT,
-    CSS_PROP_MARGIN_BOTTOM,
-    CSS_PROP_MARGIN_LEFT,
-    CSS_PROP_MARGIN_RIGHT,
-    CSS_PROP_MARGIN_TOP,
-    CSS_PROP_OVERFLOW,
-    CSS_PROP_PADDING_BOTTOM,
-    CSS_PROP_PADDING_LEFT,
-    CSS_PROP_PADDING_RIGHT,
-    CSS_PROP_PADDING_TOP,
     CSS_PROP_TEXT_ALIGN,
-    CSS_PROP_TEXT_DECORATION,
     CSS_PROP_TEXT_INDENT,
-    CSS_PROP_VERTICAL_ALIGN,
     CSS_PROP_WHITE_SPACE,
-    CSS_PROP_WIDTH,
     CSS_PROP_WORD_SPACING,
 };
 
@@ -801,25 +769,32 @@ CSSProperty CSSComputedStyleDeclarationImpl::property(int id) const
     return prop;
 }
 
-CSSStyleDeclarationImpl *CSSComputedStyleDeclarationImpl::copy() const
+CSSStyleDeclarationImpl *CSSComputedStyleDeclarationImpl::copyInheritableProperties() const
 {
     QPtrList<CSSProperty> *list = new QPtrList<CSSProperty>;
-    for (unsigned i = 0; i < sizeof(CopyProperties) / sizeof(CopyProperties[0]); i++) {
-        CSSProperty *property = new CSSProperty;
-        property->m_id = CopyProperties[i];
-        property->setValue(getPropertyCSSValue(CopyProperties[i]));
-        list->append(property);
+    list->setAutoDelete(true);
+    for (unsigned i = 0; i < sizeof(InheritableProperties) / sizeof(InheritableProperties[0]); i++) {
+        CSSValueImpl *value = getPropertyCSSValue(InheritableProperties[i]);
+        if (value) {
+            CSSProperty *property = new CSSProperty;
+            property->m_id = InheritableProperties[i];
+            property->setValue(value);
+            list->append(property);
+        }
     }
     return new CSSStyleDeclarationImpl(0, list);
 }
 
 void CSSComputedStyleDeclarationImpl::diff(CSSStyleDeclarationImpl *style) const
 {
+    if (!style)
+        return;
+
     QValueList<int> properties;
     for (QPtrListIterator<CSSProperty> it(*style->values()); it.current(); ++it) {
         CSSProperty *property = it.current();
         CSSValueImpl *value = getPropertyCSSValue(property->id());
-        if (value->cssText() == property->value()->cssText()) {
+        if (value && value->cssText() == property->value()->cssText()) {
             properties.append(property->id());
         }
     }
index cb1d32d472ce4b22c12fcdd01a152f31b082a65b..0cdd6556ae31e2d8322eac7b91b3c8d060da69c7 100644 (file)
@@ -58,7 +58,7 @@ public:
     virtual void setProperty(const DOMString &propertyString);
     virtual DOMString item(unsigned long index) const;
 
-    virtual CSSStyleDeclarationImpl *copy() const;
+    CSSStyleDeclarationImpl *copyInheritableProperties() const;
     void diff(CSSStyleDeclarationImpl *) const;
 
 private:
index 1ec93a7f297aa949ca062045b21b16b947dfd121..360a5692a8ffa140e467685831ad8a93896ab76b 100644 (file)
@@ -423,19 +423,6 @@ void CSSStyleDeclarationImpl::merge(CSSStyleDeclarationImpl *other, bool argOver
     }
 }
 
-CSSStyleDeclarationImpl *CSSStyleDeclarationImpl::copy() const
-{
-    QPtrList<CSSProperty> *list = new QPtrList<CSSProperty>;
-    list->setAutoDelete(true);
-    for (QPtrListIterator<CSSProperty> it(*values()); it.current(); ++it) {
-        CSSProperty *property = it.current();
-        if (getPropertyCSSValue(property->id())) {
-            list->append(new CSSProperty(*property));
-        }
-    }
-    return new CSSStyleDeclarationImpl(0, list);
-}
-
 // --------------------------------------------------------------------------------------
 
 CSSValueImpl::CSSValueImpl()
index e1d3b4963edba98b1f3dc1bf8a36eb430e07aacb..19fb5576d6b37a6b7deaf45a68cfa0bb81bd8e6f 100644 (file)
@@ -87,8 +87,6 @@ public:
     
     void merge(CSSStyleDeclarationImpl *, bool argOverridesOnConflict=true);
 
-    virtual CSSStyleDeclarationImpl *copy() const;
-
     void setChanged();
 
 protected:
index 5eb036a6b86a46cd3bcb194dff64b1949e17e87e..fb440355488ff07dd8c5fc0c382a67ab7482a263 100644 (file)
@@ -157,6 +157,18 @@ void EditCommand::setEndingSelection(const Selection &s)
     get()->setEndingSelection(s);
 }
 
+CSSStyleDeclarationImpl *EditCommand::typingStyle() const
+{
+    IF_IMPL_NULL_RETURN_ARG(0);
+    return get()->typingStyle();
+}
+
+void EditCommand::setTypingStyle(CSSStyleDeclarationImpl *style)
+{
+    IF_IMPL_NULL_RETURN;
+    get()->setTypingStyle(style);
+}
+
 EditCommand EditCommand::parent() const
 {
     IF_IMPL_NULL_RETURN_ARG(0);
index cb2099a56c335166389f4b824b801a3a7e953489..a37e3520ec4b92d8b76dfcd96e98d083f0f717b4 100644 (file)
@@ -118,6 +118,9 @@ public:
     virtual void setStartingSelection(const DOM::Selection &s) = 0;
     virtual void setEndingSelection(const DOM::Selection &s) = 0;
 
+    virtual DOM::CSSStyleDeclarationImpl *typingStyle() const = 0;
+    virtual void setTypingStyle(DOM::CSSStyleDeclarationImpl *) = 0;
+
     virtual EditCommand parent() const = 0;
     virtual void setParent(const EditCommand &) = 0;
 };
@@ -150,6 +153,9 @@ public:
     void setStartingSelection(const DOM::Selection &s);
     void setEndingSelection(const DOM::Selection &s);
 
+    DOM::CSSStyleDeclarationImpl *typingStyle() const;
+    void setTypingStyle(DOM::CSSStyleDeclarationImpl *);
+
     EditCommand parent() const;
     void setParent(const EditCommand &);
 
index 6ce37a66355b39a89877b0855dceda4fcc159e7a..cb49a217a06463861da5794107df68c7476eb569 100644 (file)
@@ -26,6 +26,7 @@
 #include "htmlediting_impl.h"
 
 #include "cssproperties.h"
+#include "css/css_computedstyle.h"
 #include "css/css_valueimpl.h"
 #include "dom/css_value.h"
 #include "dom/dom_position.h"
@@ -55,6 +56,7 @@
 #endif
 
 using DOM::AttrImpl;
+using DOM::CSSComputedStyleDeclarationImpl;
 using DOM::CSSPrimitiveValue;
 using DOM::CSSPrimitiveValueImpl;
 using DOM::CSSProperty;
@@ -198,9 +200,11 @@ void StyleChange::init(CSSStyleDeclarationImpl *style, const Position &position)
 bool StyleChange::currentlyHasStyle(const Position &pos, const CSSProperty *property)
 {
     ASSERT(pos.notEmpty());
-    CSSStyleDeclarationImpl *style = pos.computedStyle();
+    CSSComputedStyleDeclarationImpl *style = pos.computedStyle();
     ASSERT(style);
+    style->ref();
     CSSValueImpl *value = style->getPropertyCSSValue(property->id());
+    style->deref();
     return strcasecmp(value->cssText(), property->value()->cssText()) == 0;
 }
 
@@ -208,7 +212,7 @@ bool StyleChange::currentlyHasStyle(const Position &pos, const CSSProperty *prop
 // EditCommandImpl
 
 EditCommandImpl::EditCommandImpl(DocumentImpl *document) 
-    : SharedCommandImpl(), m_document(document), m_state(NotApplied), m_parent(0)
+    : SharedCommandImpl(), m_document(document), m_state(NotApplied), m_typingStyle(0), m_parent(0)
 {
     ASSERT(m_document);
     ASSERT(m_document->part());
@@ -221,6 +225,8 @@ EditCommandImpl::~EditCommandImpl()
 {
     ASSERT(m_document);
     m_document->deref();
+    if (m_typingStyle)
+        m_typingStyle->deref();
 }
 
 int EditCommandImpl::commandID() const
@@ -238,6 +244,14 @@ void EditCommandImpl::apply()
     
     m_state = Applied;
 
+    // The delete selection command is a special case where we want the  
+    // typing style retained. For all other commands, clear it after
+    // applying.
+    // FIXME: Improve typing style.
+    // See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
+    if (commandID() != DeleteSelectionCommandID)
+        setTypingStyle(0);
+
     if (!isCompositeStep()) {
         EditCommand cmd(this);
         m_document->part()->appliedEditing(cmd);
@@ -301,6 +315,28 @@ void EditCommandImpl::setEndingSelection(const Selection &s)
     }
 }
 
+void EditCommandImpl::assignTypingStyle(DOM::CSSStyleDeclarationImpl *style)
+{
+    CSSStyleDeclarationImpl *old = m_typingStyle;
+    m_typingStyle = style;
+    if (m_typingStyle)
+        m_typingStyle->ref();
+    if (old)
+        old->deref();
+}
+
+void EditCommandImpl::setTypingStyle(CSSStyleDeclarationImpl *style)
+{
+    // FIXME: Improve typing style.
+    // See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
+    assignTypingStyle(style);
+    EditCommand cmd = parent();
+    while (cmd.notNull()) {
+        cmd.handle()->assignTypingStyle(style);
+        cmd = cmd.parent();
+    }
+}
+
 void EditCommandImpl::markMisspellingsInSelection(const Selection &s)
 {
     KWQ(document()->part())->markMisspellingsInSelection(s);
@@ -506,6 +542,8 @@ ElementImpl *CompositeEditCommandImpl::applyTypingStyle(NodeImpl *child) const
     // and ApplyStyleCommandImpl::computeStyleChange.
     // Both function do similar work, and the common parts could be factored out.
 
+    // FIXME: Improve typing style.
+    // See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
     StyleChange styleChange(document()->part()->typingStyle());
 
     NodeImpl *childToAppend = child;
@@ -1022,14 +1060,14 @@ void DeleteSelectionCommandImpl::doApply()
         // be nice to be able to deal with this, but for now, bail.
         return;
 
-    //
-    // Figure out the typing style and set it on the part.
-    // This point in the code is a "bottleneck" that takes care
-    // of updating the typing style for the delete key, the return
-    // key, typed characters, and other deleting functions like the
-    // cut command.
-    //
-    document()->part()->setTypingStyle(computeTypingStyle(downstreamStart));
+    // Figure out the typing style in effect before the delete is done.
+    // FIXME: Improve typing style.
+    // See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
+    CSSComputedStyleDeclarationImpl *computedStyle = downstreamStart.computedStyle();
+    computedStyle->ref();
+    CSSStyleDeclarationImpl *style = computedStyle->copyInheritableProperties();
+    style->ref();
+    computedStyle->deref();
     
     NodeImpl *startNode = upstreamStart.node();
     int startOffset = upstreamStart.offset();
@@ -1169,6 +1207,19 @@ void DeleteSelectionCommandImpl::doApply()
         }
     }
 
+    // Compute the difference between the style before the delete and the style now
+    // after the delete has been done. Set this style on the part, so other editing
+    // commands being composed with this one will work, and also cache it on the command,
+    // so the KHTMLPart::appliedEditing can set it after the whole composite command 
+    // has completed.
+    // FIXME: Improve typing style.
+    // See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
+    CSSComputedStyleDeclarationImpl endingStyle(endingPosition.node());
+    endingStyle.diff(style);
+    document()->part()->setTypingStyle(style);
+    setTypingStyle(style);
+    style->deref();
+
     setEndingSelection(endingPosition);
 }
 
@@ -1276,6 +1327,8 @@ void InputNewlineCommandImpl::doApply()
     NodeImpl *nodeToInsert = breakNode;
     
     // Handle the case where there is a typing style.
+    // FIXME: Improve typing style.
+    // See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
     CSSStyleDeclarationImpl *typingStyle = document()->part()->typingStyle();
     if (typingStyle && typingStyle->length() > 0)
         nodeToInsert = applyTypingStyle(breakNode);
@@ -1407,6 +1460,8 @@ Position InputTextCommandImpl::prepareForTextInsertion(bool adjustDownstream)
         NodeImpl *nodeToInsert = textNode;
 
         // Handle the case where there is a typing style.
+        // FIXME: Improve typing style.
+        // See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
         CSSStyleDeclarationImpl *typingStyle = document()->part()->typingStyle();
         if (typingStyle && typingStyle->length() > 0)
             nodeToInsert = applyTypingStyle(textNode);
@@ -1435,6 +1490,8 @@ Position InputTextCommandImpl::prepareForTextInsertion(bool adjustDownstream)
     }
     else {
         // Handle the case where there is a typing style.
+        // FIXME: Improve typing style.
+        // See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
         CSSStyleDeclarationImpl *typingStyle = document()->part()->typingStyle();
         if (typingStyle && typingStyle->length() > 0) {
             if (pos.node()->isTextNode() && pos.offset() > pos.node()->caretMinOffset() && pos.offset() < pos.node()->caretMaxOffset()) {
@@ -1726,6 +1783,13 @@ void ReplaceSelectionCommandImpl::doApply()
     if (selection.state() == Selection::RANGE)
         deleteSelection();
     
+    // This command does not use any typing style that is set as a residual effect of
+    // a delete.
+    // FIXME: Improve typing style.
+    // See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
+    document()->part()->clearTypingStyle();
+    setTypingStyle(0);
+    
     selection = endingSelection();
     ASSERT(!selection.isEmpty());
     
@@ -2133,7 +2197,7 @@ void SplitTextNodeCommandImpl::doUnapply()
 // TypingCommandImpl
 
 TypingCommandImpl::TypingCommandImpl(DocumentImpl *document, TypingCommand::ETypingCommand commandType, const DOM::DOMString &textToInsert)
-    : CompositeEditCommandImpl(document), m_commandType(commandType), m_textToInsert(textToInsert), m_openForMoreTyping(true)
+    : CompositeEditCommandImpl(document), m_commandType(commandType), m_textToInsert(textToInsert), m_openForMoreTyping(true), m_applyEditing(false)
 {
 }
 
@@ -2176,15 +2240,22 @@ void TypingCommandImpl::markMisspellingsAfterTyping()
 
 void TypingCommandImpl::typingAddedToOpenCommand()
 {
-    ASSERT(document());
-    ASSERT(document()->part());
     markMisspellingsAfterTyping();
-    EditCommand cmd(this);
-    document()->part()->appliedEditing(cmd);
+    // Do not apply editing to the part on the first time through.
+    // The part will get told in the same way as all other commands.
+    // But since this command stays open and is used for additional typing, 
+    // we need to tell the part here as other commands are added.
+    if (m_applyEditing) {
+        EditCommand cmd(this);
+        document()->part()->appliedEditing(cmd);
+    }
+    m_applyEditing = true;
 }
 
 void TypingCommandImpl::insertText(const DOMString &text)
 {
+    // FIXME: Improve typing style.
+    // See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
     if (document()->part()->typingStyle() || m_cmds.count() == 0) {
         InputTextCommand cmd(document());
         applyCommandToComposite(cmd);
index 68c0e01e56df70922b5b5cd8d3d42080e8489e7b..ef594be1ce1f463f3d43177abc3ae46c6ae17556 100644 (file)
@@ -110,14 +110,20 @@ public:
 
     void setStartingSelection(const DOM::Selection &s);
     void setEndingSelection(const DOM::Selection &s);
+
+    DOM::CSSStyleDeclarationImpl *typingStyle() const { return m_typingStyle; };
+    void setTypingStyle(DOM::CSSStyleDeclarationImpl *);
     
     void markMisspellingsInSelection(const DOM::Selection &s);
 
 private:
+    void assignTypingStyle(DOM::CSSStyleDeclarationImpl *);
+
     DOM::DocumentImpl *m_document;
     ECommandState m_state;
     DOM::Selection m_startingSelection;
     DOM::Selection m_endingSelection;
+    DOM::CSSStyleDeclarationImpl *m_typingStyle;
     EditCommand m_parent;
 };
 
@@ -586,6 +592,7 @@ private:
     TypingCommand::ETypingCommand m_commandType;
     DOM::DOMString m_textToInsert;
     bool m_openForMoreTyping;
+    bool m_applyEditing;
 };
 
 //------------------------------------------------------------------------------------------
index 3bfb4bf6ec22c34c7c8ce5580e2852cebb5f432e..7cd852ce4f4b90d5ba9e0ebcc14b151452af3175 100644 (file)
@@ -51,6 +51,7 @@
 #include "xml/dom_selection.h"
 #include "xml/dom2_eventsimpl.h"
 #include "xml/xml_tokenizer.h"
+#include "css/css_computedstyle.h"
 #include "css/cssstyleselector.h"
 #include "css/csshelper.h"
 #include "misc/khtml_text_operations.h"
@@ -4988,6 +4989,18 @@ EditCommand KHTMLPart::lastEditCommand()
 void KHTMLPart::appliedEditing(EditCommand &cmd)
 {
     setSelection(cmd.endingSelection(), false);
+
+    // Now set the typing style from the command. Clear it when done.
+    // This helps make the case work where you completely delete a piece
+    // of styled text and then type a character immediately after.
+    // That new character needs to take on the style of the just-deleted text.
+    // FIXME: Improve typing style.
+    // See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
+    if (cmd.typingStyle()) {
+        setTypingStyle(cmd.typingStyle());
+        cmd.setTypingStyle(0);
+    }
+
     // Command will be equal to last edit command only in the case of typing
     if (d->m_lastEditCommand == cmd) {
         assert(cmd.commandID() == khtml::TypingCommandID);
@@ -5315,12 +5328,16 @@ void KHTMLPart::applyStyle(CSSStyleDeclarationImpl *style)
         case Selection::NONE:
             // do nothing
             break;
-        case Selection::CARET:
-            if (typingStyle())
+        case Selection::CARET: {
+            if (typingStyle()) {
                 typingStyle()->merge(style);
-            else
-                setTypingStyle(style);
+                style = typingStyle();
+            }
+            CSSComputedStyleDeclarationImpl diff(selection().start().upstream(StayInBlock).node());
+            diff.diff(style);
+            setTypingStyle(style);
             break;
+        }
         case Selection::RANGE:
             if (xmlDocImpl() && style) {
                 ApplyStyleCommand cmd(xmlDocImpl(), style);
index 29dbc8a80ae10bd55b80e11d52aa2befdcaccc4c..c2c7096f60475eff9577c93205251052eb8fc8e1 100644 (file)
@@ -46,6 +46,7 @@ class KJavaAppletContext;
 
 namespace DOM
 {
+  class CSSComputedStyleDeclarationImpl;
   class CSSStyleDeclarationImpl;
   class DocumentImpl;
   class EventListener;
index 68910ba7cf8191451a654ccc11aad3f601c8190e..c869a0479dcfa28024b3843f4af1ba8e7aec673e 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "dom_position.h"
 
+#include "css_computedstyle.h"
 #include "css_valueimpl.h"
 #include "dom2_viewsimpl.h"
 #include "helper.h"
@@ -147,16 +148,16 @@ ElementImpl *Position::element() const
     return static_cast<ElementImpl *>(n);
 }
 
-CSSStyleDeclarationImpl *Position::computedStyle() const
+CSSComputedStyleDeclarationImpl *Position::computedStyle() const
 {
     if (isEmpty())
         return 0;
-        
+    
     ElementImpl *elem = element();
     if (!elem)
         return 0;
         
-    return elem->getDocument()->defaultView()->getComputedStyle(elem, 0);
+    return new CSSComputedStyleDeclarationImpl(elem);
 }
 
 long Position::renderedOffset() const
index 92c5e49803ec0353631606d92608833ce2b7870d..33b5822d09f5ac5e4f076b20399dc3661b4364f1 100644 (file)
@@ -28,6 +28,7 @@
 
 namespace DOM {
 
+class CSSComputedStyleDeclarationImpl;
 class CSSStyleDeclarationImpl;
 class ElementImpl;
 class NodeImpl;
@@ -52,7 +53,7 @@ public:
     long offset() const { return m_offset; }
 
     ElementImpl *element() const;
-    CSSStyleDeclarationImpl *computedStyle() const;
+    CSSComputedStyleDeclarationImpl *computedStyle() const;
 
     long renderedOffset() const;