2010-12-06 Ryosuke Niwa <rniwa@webkit.org>
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Dec 2010 01:00:23 +0000 (01:00 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Dec 2010 01:00:23 +0000 (01:00 +0000)
        Reviewed by Tony Chang.

        ApplyStyleCommand should take EditingStyle instead of CSSStyleDeclaration
        https://bugs.webkit.org/show_bug.cgi?id=49938

        Modified ApplyStyleCommand::ApplyStyleCommand and ApplyStyleCommand::create to take EditingStyle*
        instead of CSSStyleDeclaration*. Also replaced much of code in Editor::computeAndSetTypingStyle
        by calls to EditingStyle's member functions and extracted EditingStyle::overrideWith and
        EditingStyle::extractAndRemoveBlockProperties.

        No new tests are added since this is a refactoring.

        * WebCore.exp.in: Added SelectionController::copyTypingStyle and EditingStyle::~EditingStyle.
        * css/CSSMutableStyleDeclaration.cpp: Made CSSMutableStyleDeclaration* in the argument list const.
        (WebCore::CSSMutableStyleDeclaration::merge):
        * css/CSSMutableStyleDeclaration.h:
        * editing/ApplyStyleCommand.cpp:
        (WebCore::ApplyStyleCommand::ApplyStyleCommand): Takes EditingStyle* instead of CSSStyleDeclaration*.
        (WebCore::ApplyStyleCommand::doApply): Uses EditingStyle.
        * editing/ApplyStyleCommand.h: m_style is now a ref-pointer to EditingStyle instead of CSSMutableStyleDeclaration.
        (WebCore::ApplyStyleCommand::create): Takes EditingStyle* instead of CSSStyleDeclaration*.
        * editing/CompositeEditCommand.cpp:
        (WebCore::CompositeEditCommand::applyStyle): Ditto.
        (WebCore::CompositeEditCommand::moveParagraphs): Calls applyStyle.
        (WebCore::CompositeEditCommand::breakOutOfEmptyListItem): Ditto.
        * editing/CompositeEditCommand.h:
        * editing/DeleteSelectionCommand.cpp:
        (WebCore::DeleteSelectionCommand::calculateTypingStyleAfterDelete): Ditto.
        * editing/EditCommand.cpp:
        * editing/EditCommand.h:
        * editing/EditingStyle.cpp:
        (WebCore::EditingStyle::~EditingStyle): Added.
        (WebCore::EditingStyle::overrideWithStyle): Extracted from Editor::calculateTypingStyleAfterDelete.
        (WebCore::EditingStyle::copy): Added.
        (WebCore::EditingStyle::extractAndRemoveBlockProperties): Extracted from Editor::calculateTypingStyleAfterDelete.
        * editing/EditingStyle.h:
        * editing/Editor.cpp:
        (WebCore::Editor::applyStyle): Calls ApplyStyleCommand::create.
        (WebCore::Editor::applyParagraphStyle): Ditto.
        (WebCore::Editor::computeAndSetTypingStyle): Ditto.
        * editing/InsertLineBreakCommand.cpp:
        (WebCore::InsertLineBreakCommand::doApply): Calls applyStyle.
        * editing/InsertParagraphSeparatorCommand.cpp:
        (WebCore::InsertParagraphSeparatorCommand::applyStyleAfterInsertion): Ditto.
        * editing/InsertTextCommand.cpp:
        (WebCore::InsertTextCommand::input): Ditto.
        * editing/RemoveFormatCommand.cpp:
        (WebCore::RemoveFormatCommand::doApply): Calls ApplyStyleCommand::create.
        * editing/ReplaceSelectionCommand.cpp:
        (WebCore::ReplaceSelectionCommand::completeHTMLReplacement): Calls applyStyle.
        * editing/SelectionController.cpp:
        (WebCore::SelectionController::copyTypingStyle): Moved from SelectionController.h
        * editing/SelectionController.h:

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

21 files changed:
WebCore/ChangeLog
WebCore/WebCore.exp.in
WebCore/css/CSSMutableStyleDeclaration.cpp
WebCore/css/CSSMutableStyleDeclaration.h
WebCore/editing/ApplyStyleCommand.cpp
WebCore/editing/ApplyStyleCommand.h
WebCore/editing/CompositeEditCommand.cpp
WebCore/editing/CompositeEditCommand.h
WebCore/editing/DeleteSelectionCommand.cpp
WebCore/editing/EditCommand.cpp
WebCore/editing/EditCommand.h
WebCore/editing/EditingStyle.cpp
WebCore/editing/EditingStyle.h
WebCore/editing/Editor.cpp
WebCore/editing/InsertLineBreakCommand.cpp
WebCore/editing/InsertParagraphSeparatorCommand.cpp
WebCore/editing/InsertTextCommand.cpp
WebCore/editing/RemoveFormatCommand.cpp
WebCore/editing/ReplaceSelectionCommand.cpp
WebCore/editing/SelectionController.cpp
WebCore/editing/SelectionController.h

index c53b9b8..a187b2d 100644 (file)
@@ -1,3 +1,59 @@
+2010-12-06  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Reviewed by Tony Chang.
+
+        ApplyStyleCommand should take EditingStyle instead of CSSStyleDeclaration
+        https://bugs.webkit.org/show_bug.cgi?id=49938
+
+        Modified ApplyStyleCommand::ApplyStyleCommand and ApplyStyleCommand::create to take EditingStyle*
+        instead of CSSStyleDeclaration*. Also replaced much of code in Editor::computeAndSetTypingStyle
+        by calls to EditingStyle's member functions and extracted EditingStyle::overrideWith and
+        EditingStyle::extractAndRemoveBlockProperties.
+
+        No new tests are added since this is a refactoring.
+
+        * WebCore.exp.in: Added SelectionController::copyTypingStyle and EditingStyle::~EditingStyle.
+        * css/CSSMutableStyleDeclaration.cpp: Made CSSMutableStyleDeclaration* in the argument list const.
+        (WebCore::CSSMutableStyleDeclaration::merge):
+        * css/CSSMutableStyleDeclaration.h:
+        * editing/ApplyStyleCommand.cpp:
+        (WebCore::ApplyStyleCommand::ApplyStyleCommand): Takes EditingStyle* instead of CSSStyleDeclaration*.
+        (WebCore::ApplyStyleCommand::doApply): Uses EditingStyle.
+        * editing/ApplyStyleCommand.h: m_style is now a ref-pointer to EditingStyle instead of CSSMutableStyleDeclaration.
+        (WebCore::ApplyStyleCommand::create): Takes EditingStyle* instead of CSSStyleDeclaration*.
+        * editing/CompositeEditCommand.cpp:
+        (WebCore::CompositeEditCommand::applyStyle): Ditto.
+        (WebCore::CompositeEditCommand::moveParagraphs): Calls applyStyle.
+        (WebCore::CompositeEditCommand::breakOutOfEmptyListItem): Ditto.
+        * editing/CompositeEditCommand.h:
+        * editing/DeleteSelectionCommand.cpp:
+        (WebCore::DeleteSelectionCommand::calculateTypingStyleAfterDelete): Ditto.
+        * editing/EditCommand.cpp:
+        * editing/EditCommand.h:
+        * editing/EditingStyle.cpp:
+        (WebCore::EditingStyle::~EditingStyle): Added.
+        (WebCore::EditingStyle::overrideWithStyle): Extracted from Editor::calculateTypingStyleAfterDelete.
+        (WebCore::EditingStyle::copy): Added.
+        (WebCore::EditingStyle::extractAndRemoveBlockProperties): Extracted from Editor::calculateTypingStyleAfterDelete.
+        * editing/EditingStyle.h:
+        * editing/Editor.cpp:
+        (WebCore::Editor::applyStyle): Calls ApplyStyleCommand::create.
+        (WebCore::Editor::applyParagraphStyle): Ditto.
+        (WebCore::Editor::computeAndSetTypingStyle): Ditto.
+        * editing/InsertLineBreakCommand.cpp:
+        (WebCore::InsertLineBreakCommand::doApply): Calls applyStyle.
+        * editing/InsertParagraphSeparatorCommand.cpp:
+        (WebCore::InsertParagraphSeparatorCommand::applyStyleAfterInsertion): Ditto.
+        * editing/InsertTextCommand.cpp:
+        (WebCore::InsertTextCommand::input): Ditto.
+        * editing/RemoveFormatCommand.cpp:
+        (WebCore::RemoveFormatCommand::doApply): Calls ApplyStyleCommand::create.
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::ReplaceSelectionCommand::completeHTMLReplacement): Calls applyStyle.
+        * editing/SelectionController.cpp:
+        (WebCore::SelectionController::copyTypingStyle): Moved from SelectionController.h
+        * editing/SelectionController.h:
+
 2010-12-05  Ryosuke Niwa  <rniwa@webkit.org>
 
         Reviewed by Tony Chang.
index 99ca93a..2f37c4c 100644 (file)
@@ -210,6 +210,7 @@ __ZN7WebCore11toUserSpaceERK7_NSRectP8NSWindow
 __ZN7WebCore11writeToFileEiPKci
 __ZN7WebCore12ChromeClient20paintCustomScrollbarEPNS_15GraphicsContextERKNS_9FloatRectENS_20ScrollbarControlSizeEjNS_13ScrollbarPartEbffj
 __ZN7WebCore12ChromeClient23paintCustomScrollCornerEPNS_15GraphicsContextERKNS_9FloatRectE
+__ZN7WebCore12EditingStyleD1Ev
 __ZN7WebCore12EventHandler10mouseMovedEP7NSEvent
 __ZN7WebCore12EventHandler10mouseMovedERKNS_18PlatformMouseEventE
 __ZN7WebCore12EventHandler10wheelEventEP7NSEvent
@@ -1031,6 +1032,7 @@ __ZNK7WebCore19ResourceRequestBase15httpHeaderFieldEPKc
 __ZNK7WebCore19ResourceRequestBase3urlEv
 __ZNK7WebCore19ResourceRequestBase7isEmptyEv
 __ZNK7WebCore19SelectionController11currentFormEv
+__ZNK7WebCore19SelectionController15copyTypingStyleEv
 __ZNK7WebCore19SelectionController17isInPasswordFieldEv
 __ZNK7WebCore19SelectionController18isFocusedAndActiveEv
 __ZNK7WebCore19SelectionController31getClippedVisibleTextRectanglesERN3WTF6VectorINS_9FloatRectELm0EEE
index 09655ae..9105cd7 100644 (file)
@@ -708,13 +708,13 @@ void CSSMutableStyleDeclaration::setCssText(const String& text, ExceptionCode& e
     setNeedsStyleRecalc();
 }
 
-void CSSMutableStyleDeclaration::merge(CSSMutableStyleDeclaration* other, bool argOverridesOnConflict)
+void CSSMutableStyleDeclaration::merge(const CSSMutableStyleDeclaration* other, bool argOverridesOnConflict)
 {
     ASSERT(!m_iteratorCount);
 
     unsigned size = other->m_properties.size();
     for (unsigned n = 0; n < size; ++n) {
-        CSSProperty& toMerge = other->m_properties[n];
+        const CSSProperty& toMerge = other->m_properties[n];
         CSSProperty* old = findPropertyWithId(toMerge.id());
         if (old) {
             if (!argOverridesOnConflict && old->value())
index 72536b6..f7d8ca9 100644 (file)
@@ -129,7 +129,7 @@ public:
     void removeBlockProperties();
     void removePropertiesInSet(const int* set, unsigned length, bool notifyChanged = true);
 
-    void merge(CSSMutableStyleDeclaration*, bool argOverridesOnConflict = true);
+    void merge(const CSSMutableStyleDeclaration*, bool argOverridesOnConflict = true);
 
     void setStrictParsing(bool b) { m_strictParsing = b; }
     bool useStrictParsing() const { return m_strictParsing; }
index c43a574..1973a94 100644 (file)
@@ -34,6 +34,7 @@
 #include "CSSStyleSelector.h"
 #include "CSSValueKeywords.h"
 #include "Document.h"
+#include "EditingStyle.h"
 #include "Editor.h"
 #include "Frame.h"
 #include "HTMLFontElement.h"
@@ -429,9 +430,9 @@ RefPtr<CSSMutableStyleDeclaration> getPropertiesNotIn(CSSStyleDeclaration* style
     return result;
 }
 
-ApplyStyleCommand::ApplyStyleCommand(Document* document, CSSStyleDeclaration* style, EditAction editingAction, EPropertyLevel propertyLevel)
+ApplyStyleCommand::ApplyStyleCommand(Document* document, const EditingStyle* style, EditAction editingAction, EPropertyLevel propertyLevel)
     : CompositeEditCommand(document)
-    , m_style(style->makeMutable())
+    , m_style(style->copy())
     , m_editingAction(editingAction)
     , m_propertyLevel(propertyLevel)
     , m_start(endingSelection().start().downstream())
@@ -443,9 +444,9 @@ ApplyStyleCommand::ApplyStyleCommand(Document* document, CSSStyleDeclaration* st
 {
 }
 
-ApplyStyleCommand::ApplyStyleCommand(Document* document, CSSStyleDeclaration* style, const Position& start, const Position& end, EditAction editingAction, EPropertyLevel propertyLevel)
+ApplyStyleCommand::ApplyStyleCommand(Document* document, const EditingStyle* style, const Position& start, const Position& end, EditAction editingAction, EPropertyLevel propertyLevel)
     : CompositeEditCommand(document)
-    , m_style(style->makeMutable())
+    , m_style(style->copy())
     , m_editingAction(editingAction)
     , m_propertyLevel(propertyLevel)
     , m_start(start)
@@ -459,7 +460,7 @@ ApplyStyleCommand::ApplyStyleCommand(Document* document, CSSStyleDeclaration* st
 
 ApplyStyleCommand::ApplyStyleCommand(PassRefPtr<Element> element, bool removeOnly, EditAction editingAction)
     : CompositeEditCommand(element->document())
-    , m_style(CSSMutableStyleDeclaration::create())
+    , m_style(EditingStyle::create())
     , m_editingAction(editingAction)
     , m_propertyLevel(PropertyDefault)
     , m_start(endingSelection().start().downstream())
@@ -471,9 +472,9 @@ ApplyStyleCommand::ApplyStyleCommand(PassRefPtr<Element> element, bool removeOnl
 {
 }
 
-ApplyStyleCommand::ApplyStyleCommand(Document* document, CSSStyleDeclaration* style, IsInlineElementToRemoveFunction isInlineElementToRemoveFunction, EditAction editingAction)
+ApplyStyleCommand::ApplyStyleCommand(Document* document, const EditingStyle* style, IsInlineElementToRemoveFunction isInlineElementToRemoveFunction, EditAction editingAction)
     : CompositeEditCommand(document)
-    , m_style(style->makeMutable())
+    , m_style(style->copy())
     , m_editingAction(editingAction)
     , m_propertyLevel(PropertyDefault)
     , m_start(endingSelection().start().downstream())
@@ -516,25 +517,23 @@ Position ApplyStyleCommand::endPosition()
 void ApplyStyleCommand::doApply()
 {
     switch (m_propertyLevel) {
-        case PropertyDefault: {
-            // apply the block-centric properties of the style
-            RefPtr<CSSMutableStyleDeclaration> blockStyle = m_style->copyBlockProperties();
-            if (blockStyle->length())
-                applyBlockStyle(blockStyle.get());
-            // apply any remaining styles to the inline elements
-            // NOTE: hopefully, this string comparison is the same as checking for a non-null diff
-            if (blockStyle->length() < m_style->length() || m_styledInlineElement || m_isInlineElementToRemoveFunction) {
-                RefPtr<CSSMutableStyleDeclaration> inlineStyle = m_style->copy();
-                applyRelativeFontStyleChange(inlineStyle.get());
-                blockStyle->diff(inlineStyle.get());
-                applyInlineStyle(inlineStyle.get());
-            }
-            break;
+    case PropertyDefault: {
+        // Apply the block-centric properties of the style.
+        RefPtr<EditingStyle> blockStyle = m_style->extractAndRemoveBlockProperties();
+        if (!blockStyle->isEmpty())
+            applyBlockStyle(blockStyle->style());
+        // Apply any remaining styles to the inline elements.
+        if (!m_style->isEmpty() || m_styledInlineElement || m_isInlineElementToRemoveFunction) {
+            RefPtr<CSSMutableStyleDeclaration> style = m_style->style() ? m_style->style() : CSSMutableStyleDeclaration::create();
+            applyRelativeFontStyleChange(style.get());
+            applyInlineStyle(style.get());
         }
-        case ForceBlockProperties:
-            // Force all properties to be applied as block styles.
-            applyBlockStyle(m_style.get());
-            break;
+        break;
+    }
+    case ForceBlockProperties:
+        // Force all properties to be applied as block styles.
+        applyBlockStyle(m_style->style());
+        break;
     }
 }
 
index 018148f..44197cc 100644 (file)
@@ -32,6 +32,7 @@
 namespace WebCore {
 
 class CSSPrimitiveValue;
+class EditingStyle;
 class HTMLElement;
 class StyleChange;
 
@@ -47,11 +48,11 @@ public:
     enum EAddStyledElement { AddStyledElement, DoNotAddStyledElement };
     typedef bool (*IsInlineElementToRemoveFunction)(const Element*);
 
-    static PassRefPtr<ApplyStyleCommand> create(Document* document, CSSStyleDeclaration* style, EditAction action = EditActionChangeAttributes, EPropertyLevel level = PropertyDefault)
+    static PassRefPtr<ApplyStyleCommand> create(Document* document, const EditingStyle* style, EditAction action = EditActionChangeAttributes, EPropertyLevel level = PropertyDefault)
     {
         return adoptRef(new ApplyStyleCommand(document, style, action, level));
     }
-    static PassRefPtr<ApplyStyleCommand> create(Document* document, CSSStyleDeclaration* style, const Position& start, const Position& end, EditAction action = EditActionChangeAttributes, EPropertyLevel level = PropertyDefault)
+    static PassRefPtr<ApplyStyleCommand> create(Document* document, const EditingStyle* style, const Position& start, const Position& end, EditAction action = EditActionChangeAttributes, EPropertyLevel level = PropertyDefault)
     {
         return adoptRef(new ApplyStyleCommand(document, style, start, end, action, level));
     }
@@ -59,22 +60,20 @@ public:
     {
         return adoptRef(new ApplyStyleCommand(element, removeOnly, action));
     }
-    static PassRefPtr<ApplyStyleCommand> create(Document* document, CSSStyleDeclaration* style, IsInlineElementToRemoveFunction isInlineElementToRemoveFunction, EditAction action = EditActionChangeAttributes)
+    static PassRefPtr<ApplyStyleCommand> create(Document* document, const EditingStyle* style, IsInlineElementToRemoveFunction isInlineElementToRemoveFunction, EditAction action = EditActionChangeAttributes)
     {
         return adoptRef(new ApplyStyleCommand(document, style, isInlineElementToRemoveFunction, action));
     }
 
 private:
-    ApplyStyleCommand(Document*, CSSStyleDeclaration*, EditAction, EPropertyLevel);
-    ApplyStyleCommand(Document*, CSSStyleDeclaration*, const Position& start, const Position& end, EditAction, EPropertyLevel);
+    ApplyStyleCommand(Document*, const EditingStyle*, EditAction, EPropertyLevel);
+    ApplyStyleCommand(Document*, const EditingStyle*, const Position& start, const Position& end, EditAction, EPropertyLevel);
     ApplyStyleCommand(PassRefPtr<Element>, bool removeOnly, EditAction);
-    ApplyStyleCommand(Document*, CSSStyleDeclaration*, bool (*isInlineElementToRemove)(const Element*), EditAction);
+    ApplyStyleCommand(Document*, const EditingStyle*, bool (*isInlineElementToRemove)(const Element*), EditAction);
 
     virtual void doApply();
     virtual EditAction editingAction() const;
 
-    CSSMutableStyleDeclaration* style() const { return m_style.get(); }
-
     // style-removal helpers
     bool isStyledInlineElementToRemove(Element*) const;
     bool removeStyleFromRunBeforeApplyingStyle(CSSMutableStyleDeclaration* style, RefPtr<Node>& runStart, RefPtr<Node>& runEnd);
@@ -119,7 +118,7 @@ private:
     Position startPosition();
     Position endPosition();
 
-    RefPtr<CSSMutableStyleDeclaration> m_style;
+    RefPtr<EditingStyle> m_style;
     EditAction m_editingAction;
     EPropertyLevel m_propertyLevel;
     Position m_start;
index 602ca0f..92e3de5 100644 (file)
@@ -28,8 +28,6 @@
 
 #include "AppendNodeCommand.h"
 #include "ApplyStyleCommand.h"
-#include "CSSComputedStyleDeclaration.h"
-#include "CSSMutableStyleDeclaration.h"
 #include "CharacterNames.h"
 #include "DeleteFromTextNodeCommand.h"
 #include "DeleteSelectionCommand.h"
@@ -105,12 +103,12 @@ void CompositeEditCommand::applyCommandToComposite(PassRefPtr<EditCommand> cmd)
     m_commands.append(cmd);
 }
 
-void CompositeEditCommand::applyStyle(CSSStyleDeclaration* style, EditAction editingAction)
+void CompositeEditCommand::applyStyle(const EditingStyle* style, EditAction editingAction)
 {
     applyCommandToComposite(ApplyStyleCommand::create(document(), style, editingAction));
 }
 
-void CompositeEditCommand::applyStyle(CSSStyleDeclaration* style, const Position& start, const Position& end, EditAction editingAction)
+void CompositeEditCommand::applyStyle(const EditingStyle* style, const Position& start, const Position& end, EditAction editingAction)
 {
     applyCommandToComposite(ApplyStyleCommand::create(document(), style, start, end, editingAction));
 }
@@ -983,7 +981,7 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap
     // If the selection is in an empty paragraph, restore styles from the old empty paragraph to the new empty paragraph.
     bool selectionIsEmptyParagraph = endingSelection().isCaret() && isStartOfParagraph(endingSelection().visibleStart()) && isEndOfParagraph(endingSelection().visibleStart());
     if (styleInEmptyParagraph && selectionIsEmptyParagraph)
-        applyStyle(styleInEmptyParagraph->style());
+        applyStyle(styleInEmptyParagraph.get());
 
     if (preserveSelection && startIndex != -1) {
         // Fragment creation (using createMarkup) incorrectly uses regular
@@ -1056,7 +1054,7 @@ bool CompositeEditCommand::breakOutOfEmptyListItem()
 
     style->prepareToApplyAt(endingSelection().start());
     if (!style->isEmpty())
-        applyStyle(style->style());
+        applyStyle(style.get());
 
     return true;
 }
index b4c3b2d..6db4eb1 100644 (file)
@@ -33,6 +33,7 @@
 namespace WebCore {
 
 class CSSStyleDeclaration;
+class EditingStyle;
 class HTMLElement;
 class StyledElement;
 class Text;
@@ -51,8 +52,8 @@ protected:
     //
     void appendNode(PassRefPtr<Node>, PassRefPtr<Element> parent);
     void applyCommandToComposite(PassRefPtr<EditCommand>);
-    void applyStyle(CSSStyleDeclaration*, EditAction = EditActionChangeAttributes);
-    void applyStyle(CSSStyleDeclaration*, const Position& start, const Position& end, EditAction = EditActionChangeAttributes);
+    void applyStyle(const EditingStyle*, EditAction = EditActionChangeAttributes);
+    void applyStyle(const EditingStyle*, const Position& start, const Position& end, EditAction = EditActionChangeAttributes);
     void applyStyledElement(PassRefPtr<Element>);
     void removeStyledElement(PassRefPtr<Element>);
     void deleteSelection(bool smartDelete = false, bool mergeBlocksAfterDelete = true, bool replace = false, bool expandForSpecialElements = true);
index 594a94f..24c1968 100644 (file)
@@ -691,7 +691,7 @@ void DeleteSelectionCommand::calculateTypingStyleAfterDelete()
         // then move it back (which will clear typing style).
 
         setEndingSelection(visibleEnd);
-        applyStyle(m_typingStyle->style(), EditActionUnspecified);
+        applyStyle(m_typingStyle.get(), EditActionUnspecified);
         // applyStyle can destroy the placeholder that was at m_endingPosition if it needs to 
         // move it, but it will set an endingSelection() at [movedPlaceholder, 0] if it does so.
         m_endingPosition = endingSelection().start();
index db447a5..5f0cfd4 100644 (file)
@@ -27,8 +27,6 @@
 #include "EditCommand.h"
 
 #include "CompositeEditCommand.h"
-#include "CSSComputedStyleDeclaration.h"
-#include "CSSMutableStyleDeclaration.h"
 #include "DeleteButtonController.h"
 #include "Document.h"
 #include "Editor.h"
index e50e88d..4826ec0 100644 (file)
@@ -33,7 +33,6 @@
 namespace WebCore {
 
 class CompositeEditCommand;
-class CSSMutableStyleDeclaration;
 
 class EditCommand : public RefCounted<EditCommand> {
 public:
index ad77696..c46c075 100644 (file)
@@ -103,6 +103,10 @@ EditingStyle::EditingStyle(const CSSStyleDeclaration* style)
 {
 }
 
+EditingStyle::~EditingStyle()
+{
+}
+
 void EditingStyle::init(Node* node)
 {
     RefPtr<CSSComputedStyleDeclaration> computedStyleAtPosition = computedStyle(node);
@@ -177,12 +181,42 @@ void EditingStyle::setStyle(PassRefPtr<CSSMutableStyleDeclaration> style)
     m_shouldUseFixedDefaultFontSize = false;
 }
 
+void EditingStyle::overrideWithStyle(const CSSMutableStyleDeclaration* style)
+{
+    if (!style || !style->length())
+        return;
+    if (!m_mutableStyle)
+        m_mutableStyle = CSSMutableStyleDeclaration::create();
+    m_mutableStyle->merge(style);
+}
+
 void EditingStyle::clear()
 {
     m_mutableStyle.clear();
     m_shouldUseFixedDefaultFontSize = false;
 }
 
+PassRefPtr<EditingStyle> EditingStyle::copy() const
+{
+    RefPtr<EditingStyle> copy = EditingStyle::create();
+    if (m_mutableStyle)
+        copy->m_mutableStyle = m_mutableStyle->copy();
+    copy->m_shouldUseFixedDefaultFontSize = m_shouldUseFixedDefaultFontSize;
+    return copy;
+}
+
+PassRefPtr<EditingStyle> EditingStyle::extractAndRemoveBlockProperties()
+{
+    RefPtr<EditingStyle> blockProperties = EditingStyle::create();
+    if (!m_mutableStyle)
+        return blockProperties;
+
+    blockProperties->m_mutableStyle = m_mutableStyle->copyBlockProperties();
+    m_mutableStyle->removeBlockProperties();
+
+    return blockProperties;
+}
+
 void EditingStyle::removeBlockProperties()
 {
     if (!m_mutableStyle)
index b1c370b..d444afe 100644 (file)
@@ -31,7 +31,6 @@
 #ifndef EditingStyle_h
 #define EditingStyle_h
 
-#include "CSSMutableStyleDeclaration.h"
 #include "Document.h"
 #include "Position.h"
 
@@ -39,6 +38,7 @@ namespace WebCore {
 
 class CSSStyleDeclaration;
 class CSSComputedStyleDeclaration;
+class CSSMutableStyleDeclaration;
 
 enum WritingDirection { NaturalWritingDirection, LeftToRightWritingDirection, RightToLeftWritingDirection };
 
@@ -67,14 +67,19 @@ public:
         return adoptRef(new EditingStyle(style));
     }
 
+    ~EditingStyle();
+
     CSSMutableStyleDeclaration* style() { return m_mutableStyle.get(); }
     bool textDirection(WritingDirection&) const;
     bool isEmpty() const;
     void setStyle(PassRefPtr<CSSMutableStyleDeclaration>);
+    void overrideWithStyle(const CSSMutableStyleDeclaration*);
     void clear();
+    PassRefPtr<EditingStyle> copy() const;
+    PassRefPtr<EditingStyle> extractAndRemoveBlockProperties();
     void removeBlockProperties();
-    void removeStyleAddedByNode(Node* node);
-    void removeStyleConflictingWithStyleOfNode(Node* node);
+    void removeStyleAddedByNode(Node*);
+    void removeStyleConflictingWithStyleOfNode(Node*);
     void removeNonEditingProperties();
     void prepareToApplyAt(const Position&, ShouldPreserveWritingDirection = DoNotPreserveWritingDirection);
 
index 816ae90..2b22651 100644 (file)
@@ -892,7 +892,7 @@ void Editor::applyStyle(CSSStyleDeclaration* style, EditAction editingAction)
         break;
     case VisibleSelection::RangeSelection:
         if (style)
-            applyCommand(ApplyStyleCommand::create(m_frame->document(), style, editingAction));
+            applyCommand(ApplyStyleCommand::create(m_frame->document(), EditingStyle::create(style).get(), editingAction));
         break;
     }
 }
@@ -911,7 +911,7 @@ void Editor::applyParagraphStyle(CSSStyleDeclaration* style, EditAction editingA
     case VisibleSelection::CaretSelection:
     case VisibleSelection::RangeSelection:
         if (style)
-            applyCommand(ApplyStyleCommand::create(m_frame->document(), style, editingAction, ApplyStyleCommand::ForceBlockProperties));
+            applyCommand(ApplyStyleCommand::create(m_frame->document(), EditingStyle::create(style).get(), editingAction, ApplyStyleCommand::ForceBlockProperties));
         break;
     }
 }
@@ -3086,40 +3086,22 @@ void Editor::computeAndSetTypingStyle(CSSStyleDeclaration* style, EditAction edi
     }
 
     // Calculate the current typing style.
-    RefPtr<CSSMutableStyleDeclaration> mutableStyle = style->makeMutable();
-    RefPtr<EditingStyle> typingStyle = m_frame->selection()->typingStyle();
-    if (typingStyle && typingStyle->style()) {
-        typingStyle->style()->merge(mutableStyle.get());
-        mutableStyle = typingStyle->style();
-    }
-
-    RefPtr<CSSValue> unicodeBidi;
-    RefPtr<CSSValue> direction;
-    if (editingAction == EditActionSetWritingDirection) {
-        unicodeBidi = mutableStyle->getPropertyCSSValue(CSSPropertyUnicodeBidi);
-        direction = mutableStyle->getPropertyCSSValue(CSSPropertyDirection);
-    }
-
-    Node* node = m_frame->selection()->selection().visibleStart().deepEquivalent().node();
-    computedStyle(node)->diff(mutableStyle.get());
+    RefPtr<EditingStyle> typingStyle;
+    if (m_frame->selection()->typingStyle()) {
+        typingStyle = m_frame->selection()->typingStyle()->copy();
+        typingStyle->overrideWithStyle(style->makeMutable().get());
+    } else
+        typingStyle = EditingStyle::create(style);
 
-    if (editingAction == EditActionSetWritingDirection && unicodeBidi) {
-        ASSERT(unicodeBidi->isPrimitiveValue());
-        mutableStyle->setProperty(CSSPropertyUnicodeBidi, static_cast<CSSPrimitiveValue*>(unicodeBidi.get())->getIdent());
-        if (direction) {
-            ASSERT(direction->isPrimitiveValue());
-            mutableStyle->setProperty(CSSPropertyDirection, static_cast<CSSPrimitiveValue*>(direction.get())->getIdent());
-        }
-    }
+    typingStyle->prepareToApplyAt(m_frame->selection()->selection().visibleStart().deepEquivalent(), EditingStyle::PreserveWritingDirection);
 
     // Handle block styles, substracting these from the typing style.
-    RefPtr<CSSMutableStyleDeclaration> blockStyle = mutableStyle->copyBlockProperties();
-    blockStyle->diff(mutableStyle.get());
-    if (blockStyle->length() > 0)
+    RefPtr<EditingStyle> blockStyle = typingStyle->extractAndRemoveBlockProperties();
+    if (!blockStyle->isEmpty())
         applyCommand(ApplyStyleCommand::create(m_frame->document(), blockStyle.get(), editingAction));
 
     // Set the remaining style as the typing style.
-    m_frame->selection()->setTypingStyle(EditingStyle::create(mutableStyle.get()));
+    m_frame->selection()->setTypingStyle(typingStyle);
 }
 
 PassRefPtr<CSSMutableStyleDeclaration> Editor::selectionComputedStyle(bool& shouldUseFixedFontDefaultSize) const
index 9397000..3070edf 100644 (file)
@@ -172,7 +172,7 @@ void InsertLineBreakCommand::doApply()
         // leaves and then comes back, new input will have the right style.
         // FIXME: We shouldn't always apply the typing style to the line break here,
         // see <rdar://problem/5794462>.
-        applyStyle(typingStyle->style(), firstDeepEditingPositionForNode(nodeToInsert.get()), lastDeepEditingPositionForNode(nodeToInsert.get()));
+        applyStyle(typingStyle.get(), firstDeepEditingPositionForNode(nodeToInsert.get()), lastDeepEditingPositionForNode(nodeToInsert.get()));
         // Even though this applyStyle operates on a Range, it still sets an endingSelection().
         // It tries to set a VisibleSelection around the content it operated on. So, that VisibleSelection
         // will either (a) select the line break we inserted, or it will (b) be a caret just 
index abd744c..1838382 100644 (file)
@@ -98,7 +98,7 @@ void InsertParagraphSeparatorCommand::applyStyleAfterInsertion(Node* originalEnc
 
     m_style->prepareToApplyAt(endingSelection().start());
     if (!m_style->isEmpty())
-        applyStyle(m_style->style());
+        applyStyle(m_style.get());
 }
 
 bool InsertParagraphSeparatorCommand::shouldUseDefaultParagraphElement(Node* enclosingBlock) const
index 9eb8aa7..0462cfb 100644 (file)
@@ -193,7 +193,7 @@ void InsertTextCommand::input(const String& text, bool selectInsertedText)
     if (RefPtr<EditingStyle> typingStyle = document()->frame()->selection()->typingStyle()) {
         typingStyle->prepareToApplyAt(endPosition, EditingStyle::PreserveWritingDirection);
         if (!typingStyle->isEmpty())
-            applyStyle(typingStyle->style());
+            applyStyle(typingStyle.get());
     }
 
     if (!selectInsertedText)
index 42833cb..0445b60 100644 (file)
@@ -87,7 +87,7 @@ void RemoveFormatCommand::doApply()
     Node* root = frame->selection()->rootEditableElement();
     RefPtr<EditingStyle> defaultStyle = EditingStyle::create(root);
 
-    applyCommandToComposite(ApplyStyleCommand::create(document(), defaultStyle->style(), isElementForRemoveFormatCommand, editingAction()));
+    applyCommandToComposite(ApplyStyleCommand::create(document(), defaultStyle.get(), isElementForRemoveFormatCommand, editingAction()));
 }
 
 }
index fb52e56..54a7fde 100644 (file)
@@ -1143,7 +1143,7 @@ void ReplaceSelectionCommand::completeHTMLReplacement(const Position &lastPositi
 
         if (m_matchStyle) {
             ASSERT(m_insertionStyle);
-            applyStyle(m_insertionStyle->style(), start, end);
+            applyStyle(m_insertionStyle.get(), start, end);
         }    
         
         if (lastPositionToSelect.isNotNull())
index bc6ef24..bc00442 100644 (file)
@@ -1590,6 +1590,13 @@ void SelectionController::paintDragCaret(GraphicsContext* p, int tx, int ty, con
 #endif
 }
 
+PassRefPtr<CSSMutableStyleDeclaration> SelectionController::copyTypingStyle() const
+{
+    if (!m_typingStyle || !m_typingStyle->style())
+        return 0;
+    return m_typingStyle->style()->copy();
+}
+
 bool SelectionController::shouldDeleteSelection(const VisibleSelection& selection) const
 {
     return m_frame->editor()->client()->shouldDeleteRange(selection.toNormalizedRange().get());
index 8cc89e4..03406a4 100644 (file)
@@ -36,8 +36,8 @@
 
 namespace WebCore {
 
-class Frame;
 class CSSMutableStyleDeclaration;
+class Frame;
 class GraphicsContext;
 class HTMLFormElement;
 class RenderObject;
@@ -239,13 +239,6 @@ inline EditingStyle* SelectionController::typingStyle() const
     return m_typingStyle.get();
 }
 
-inline PassRefPtr<CSSMutableStyleDeclaration> SelectionController::copyTypingStyle() const
-{
-    if (!m_typingStyle || !m_typingStyle->style())
-        return 0;
-    return m_typingStyle->style()->copy();
-}
-
 inline void SelectionController::clearTypingStyle()
 {
     m_typingStyle.clear();