Patch by Duncan Wilcox, reviewed by Darin.
authorap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Jan 2006 18:14:53 +0000 (18:14 +0000)
committerap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Jan 2006 18:14:53 +0000 (18:14 +0000)
        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=6609
          Use Selection instead of SelectionController where possible

        This patch replaces the use of SelectionController with Selection in the edit commands.

        It also cleans up the relationship between Selection and SelectionController:
        SelectionController used to need to be friend to Selection to call validate()
        on it, now validation is enforced on every update of Selection.

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

21 files changed:
WebCore/ChangeLog
WebCore/khtml/editing/Selection.cpp
WebCore/khtml/editing/Selection.h
WebCore/khtml/editing/SelectionController.cpp
WebCore/khtml/editing/SelectionController.h
WebCore/khtml/editing/apply_style_command.cpp
WebCore/khtml/editing/break_blockquote_command.cpp
WebCore/khtml/editing/composite_edit_command.cpp
WebCore/khtml/editing/composite_edit_command.h
WebCore/khtml/editing/delete_selection_command.cpp
WebCore/khtml/editing/delete_selection_command.h
WebCore/khtml/editing/edit_command.cpp
WebCore/khtml/editing/edit_command.h
WebCore/khtml/editing/insert_line_break_command.cpp
WebCore/khtml/editing/insert_paragraph_separator_command.cpp
WebCore/khtml/editing/insert_text_command.cpp
WebCore/khtml/editing/move_selection_command.cpp
WebCore/khtml/editing/replace_selection_command.cpp
WebCore/khtml/editing/typing_command.cpp
WebCore/page/Frame.cpp
WebCore/page/Frame.h

index cf065b506a3df211bf1fd34895cefff1c50f9463..f1cd6d12e35579e4b67ec773750f026180054acc 100644 (file)
@@ -1,3 +1,79 @@
+2006-01-17  Duncan Wilcox  <duncan@mclink.it>
+
+        Reviewed by Darin, landed by ap.
+
+        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=6609
+          Use Selection instead of SelectionController where possible
+
+        This patch replaces the use of SelectionController with Selection in the edit commands.
+
+        It also cleans up the relationship between Selection and SelectionController: 
+        SelectionController used to need to be friend to Selection to call validate() 
+        on it, now validation is enforced on every update of Selection.
+
+        * khtml/editing/Selection.cpp:
+        (WebCore::Selection::Selection):
+        (WebCore::Selection::expandUsingGranularity):
+        (WebCore::Selection::validate):
+        * khtml/editing/Selection.h:
+        (WebCore::Selection::setExtent):
+        (WebCore::Selection::granularity):
+        (WebCore::operator==):
+        * khtml/editing/SelectionController.cpp:
+        (WebCore::SelectionController::SelectionController):
+        (WebCore::SelectionController::moveTo):
+        (WebCore::SelectionController::expandUsingGranularity):
+        (WebCore::SelectionController::clear):
+        (WebCore::SelectionController::setBase):
+        (WebCore::SelectionController::setExtent):
+        * khtml/editing/SelectionController.h:
+        (WebCore::SelectionController::selection):
+        * khtml/editing/apply_style_command.cpp:
+        (WebCore::ApplyStyleCommand::updateStartEnd):
+        (WebCore::ApplyStyleCommand::doApply):
+        * khtml/editing/break_blockquote_command.cpp:
+        (khtml::BreakBlockquoteCommand::doApply):
+        * khtml/editing/composite_edit_command.cpp:
+        (WebCore::CompositeEditCommand::deleteSelection):
+        (WebCore::CompositeEditCommand::rebalanceWhitespace):
+        * khtml/editing/composite_edit_command.h:
+        * khtml/editing/delete_selection_command.cpp:
+        (WebCore::DeleteSelectionCommand::DeleteSelectionCommand):
+        (WebCore::DeleteSelectionCommand::calculateTypingStyleAfterDelete):
+        (WebCore::DeleteSelectionCommand::clearTransientState):
+        (WebCore::DeleteSelectionCommand::doApply):
+        * khtml/editing/delete_selection_command.h:
+        * khtml/editing/edit_command.cpp:
+        (WebCore::EditCommandPtr::startingSelection):
+        (WebCore::EditCommandPtr::endingSelection):
+        (WebCore::EditCommandPtr::setStartingSelection):
+        (WebCore::EditCommandPtr::setEndingSelection):
+        (WebCore::EditCommand::EditCommand):
+        (WebCore::EditCommand::setStartingSelection):
+        (WebCore::EditCommand::setEndingSelection):
+        * khtml/editing/edit_command.h:
+        (WebCore::EditCommand::startingSelection):
+        (WebCore::EditCommand::endingSelection):
+        * khtml/editing/insert_line_break_command.cpp:
+        (khtml::InsertLineBreakCommand::doApply):
+        * khtml/editing/insert_paragraph_separator_command.cpp:
+        (khtml::InsertParagraphSeparatorCommand::doApply):
+        * khtml/editing/insert_text_command.cpp:
+        (khtml::InsertTextCommand::input):
+        * khtml/editing/move_selection_command.cpp:
+        (khtml::MoveSelectionCommand::doApply):
+        * khtml/editing/replace_selection_command.cpp:
+        (khtml::ReplaceSelectionCommand::doApply):
+        (khtml::ReplaceSelectionCommand::completeHTMLReplacement):
+        * khtml/editing/typing_command.cpp:
+        (khtml::TypingCommand::deleteKeyPressed):
+        (khtml::TypingCommand::forwardDeleteKeyPressed):
+        * page/Frame.cpp:
+        (Frame::appliedEditing):
+        (Frame::unappliedEditing):
+        (Frame::reappliedEditing):
+        * page/Frame.h:
+
 2006-01-17  Mitz Pettel  <opendarwin.org@mitzpettel.com>
 
         Test: fast/dom/generic-form-element-assert.html
index de542b2c360159885ede2f573e49f616f09c0adf..035066ca7f38c6a276191553b2ab223a9886d576 100644 (file)
 #include "htmlediting.h"
 #include "visible_position.h"
 #include "visible_units.h"
+#include "xml/dom2_rangeimpl.h"
 #include <kxmlcore/Assertions.h>
 
 namespace WebCore {
 
 Selection::Selection()
     : m_affinity(DOWNSTREAM)
+    , m_granularity(CHARACTER)
     , m_state(NONE)
     , m_baseIsFirst(true)
 {
 }
 
-Selection::Selection(const Position &base, const Position &extent, EAffinity affinity)
-    : m_base(base), m_extent(extent)
+Selection::Selection(const Position &pos, EAffinity affinity)
+    : m_base(pos), m_extent(pos)
     , m_affinity(affinity)
+    , m_granularity(CHARACTER)
     , m_state(NONE)
     , m_baseIsFirst(true)
 {
     validate();
 }
 
-void Selection::clear()
+Selection::Selection(const Position &base, const Position &extent, EAffinity affinity)
+    : m_base(base), m_extent(extent)
+    , m_affinity(affinity)
+    , m_granularity(CHARACTER)
+    , m_state(NONE)
+    , m_baseIsFirst(true)
 {
-    m_affinity = SEL_DEFAULT_AFFINITY;
-    m_base.clear();
-    m_extent.clear();
+    validate();
 }
 
 PassRefPtr<RangeImpl> Selection::toRange() const
@@ -117,7 +123,17 @@ PassRefPtr<RangeImpl> Selection::toRange() const
     return result;
 }
 
-void Selection::validate(ETextGranularity granularity)
+bool Selection::expandUsingGranularity(ETextGranularity granularity)
+{
+    if (isNone())
+        return false;
+
+    m_granularity = granularity;
+    validate();
+    return true;
+}
+
+void Selection::validate()
 {
     // Move the selection to rendered positions, if possible.
     Position originalBase(m_base);
@@ -168,7 +184,7 @@ void Selection::validate(ETextGranularity granularity)
     }
     
     // Expand the selection if requested.
-    switch (granularity) {
+    switch (m_granularity) {
         case CHARACTER:
             // Don't do any expansion.
             break;
index f95d49ef8b58cb03621ec18d1f865674418703c1..a860f6914665965fdda7c83626066221cebe9c91 100644 (file)
@@ -42,6 +42,7 @@ public:
 #define SEL_DEFAULT_AFFINITY DOWNSTREAM
 
     Selection();
+    Selection(const Position &, EAffinity);
     Selection(const Position &, const Position &, EAffinity);
 
     EState state() const { return m_state; }
@@ -49,12 +50,8 @@ public:
     void setAffinity(EAffinity affinity) { m_affinity = affinity; }
     EAffinity affinity() const { return m_affinity; }
 
-    void clear();
-
     void setBase(Position base) { m_base = base; }
     void setExtent(Position extent) { m_extent = extent; }
-    void setStart(Position start) { m_start = start; }
-    void setEnd(Position end) { m_end = end; }
     Position base() const { return m_base; }
     Position extent() const { return m_extent; }
     Position start() const { return m_start; }
@@ -67,30 +64,33 @@ public:
 
     bool isBaseFirst() const { return m_baseIsFirst; }
 
+    bool expandUsingGranularity(ETextGranularity granularity);
+    ETextGranularity granularity() const { return m_granularity; }
+
     PassRefPtr<RangeImpl> toRange() const;
 
     void debugPosition() const;
 
 private:
-    friend class SelectionController; // for access to validate; should be fixed later
-    void validate(ETextGranularity granularity = CHARACTER);
+    void validate();
     void adjustForEditableContent();
 
-    Position m_base;              // base position for the selection
-    Position m_extent;            // extent position for the selection
-    Position m_start;             // start position for the selection
-    Position m_end;               // end position for the selection
+    Position m_base;                  // base position for the selection
+    Position m_extent;                // extent position for the selection
+    Position m_start;                 // start position for the selection
+    Position m_end;                   // end position for the selection
 
-    EAffinity m_affinity;         // the upstream/downstream affinity of the caret
+    EAffinity m_affinity;             // the upstream/downstream affinity of the caret
+    ETextGranularity m_granularity;   // granularity of start/end selection
 
     // these are cached, can be recalculated by validate()
-    EState m_state;               // the state of the selection
-    bool m_baseIsFirst;           // true if base is before the extent
+    EState m_state;                   // the state of the selection
+    bool m_baseIsFirst;               // true if base is before the extent
 };
 
 inline bool operator==(const Selection &a, const Selection &b)
 {
-    return a.start() == b.start() && a.end() == b.end() && a.affinity() == b.affinity();
+    return a.start() == b.start() && a.end() == b.end() && a.affinity() == b.affinity() && a.granularity() == b.granularity();
 }
 
 inline bool operator!=(const Selection &a, const Selection &b)
index a0dd3b0c8c0ac14aea1615396722865ace933a50..91bb0709beba775f5163be8c2823309ea86b745c 100644 (file)
@@ -56,6 +56,13 @@ SelectionController::SelectionController()
 {
 }
 
+SelectionController::SelectionController(const Selection &sel)
+    : m_sel(sel)
+    , m_needsLayout(true)
+    , m_modifyBiasSet(false)
+{
+}
+
 SelectionController::SelectionController(const Position &pos, EAffinity affinity)
     : m_sel(pos, pos, affinity)
     , m_needsLayout(true)
@@ -129,55 +136,37 @@ SelectionController &SelectionController::operator=(const SelectionController &o
 
 void SelectionController::moveTo(const VisiblePosition &pos)
 {
-    m_sel.setAffinity(pos.affinity());
-    m_sel.setBase(pos.deepEquivalent());
-    m_sel.setExtent(pos.deepEquivalent());
-    m_sel.validate();
+    m_sel = Selection(pos.deepEquivalent(), pos.deepEquivalent(), pos.affinity());
     m_needsLayout = true;
 }
 
 void SelectionController::moveTo(const VisiblePosition &base, const VisiblePosition &extent)
 {
-    m_sel.setAffinity(base.affinity());
-    m_sel.setBase(base.deepEquivalent());
-    m_sel.setExtent(extent.deepEquivalent());
-    m_sel.validate();
+    m_sel = Selection(base.deepEquivalent(), extent.deepEquivalent(), base.affinity());
     m_needsLayout = true;
 }
 
 void SelectionController::moveTo(const SelectionController &o)
 {
-    m_sel.setAffinity(o.m_sel.affinity());
-    m_sel.setBase(o.m_sel.start());
-    m_sel.setExtent(o.m_sel.end());
-    m_sel.validate();
+    m_sel = o.m_sel;
     m_needsLayout = true;
 }
 
 void SelectionController::moveTo(const Position &pos, EAffinity affinity)
 {
-    m_sel.setAffinity(affinity);
-    m_sel.setBase(pos);
-    m_sel.setExtent(pos);
-    m_sel.validate();
+    m_sel = Selection(pos, affinity);
     m_needsLayout = true;
 }
 
 void SelectionController::moveTo(const RangeImpl *r, EAffinity affinity)
 {
-    m_sel.setAffinity(affinity);
-    m_sel.setBase(startPosition(r));
-    m_sel.setExtent(endPosition(r));
-    m_sel.validate();
+    m_sel = Selection(startPosition(r), endPosition(r), affinity);
     m_needsLayout = true;
 }
 
 void SelectionController::moveTo(const Position &base, const Position &extent, EAffinity affinity)
 {
-    m_sel.setAffinity(affinity);
-    m_sel.setBase(base);
-    m_sel.setExtent(extent);
-    m_sel.validate();
+    m_sel = Selection(base, extent, affinity);
     m_needsLayout = true;
 }
 
@@ -507,8 +496,8 @@ bool SelectionController::expandUsingGranularity(ETextGranularity granularity)
 {
     if (isNone())
         return false;
-    
-    m_sel.validate(granularity);
+
+    m_sel.expandUsingGranularity(granularity);
     m_needsLayout = true;
     return true;
 }
@@ -553,40 +542,31 @@ int SelectionController::xPosForVerticalArrowNavigation(EPositionType type, bool
 
 void SelectionController::clear()
 {
-    m_sel.clear();
-    m_sel.validate();
+    m_sel = Selection();
     m_needsLayout = true;
 }
 
 void SelectionController::setBase(const VisiblePosition &pos)
 {
-    m_sel.setAffinity(pos.affinity());
-    m_sel.setBase(pos.deepEquivalent());
-    m_sel.validate();
+    m_sel = Selection(pos.deepEquivalent(), m_sel.extent(), pos.affinity());
     m_needsLayout = true;
 }
 
 void SelectionController::setExtent(const VisiblePosition &pos)
 {
-    m_sel.setAffinity(pos.affinity());
-    m_sel.setExtent(pos.deepEquivalent());
-    m_sel.validate();
+    m_sel = Selection(m_sel.base(), pos.deepEquivalent(), pos.affinity());
     m_needsLayout = true;
 }
 
 void SelectionController::setBase(const Position &pos, EAffinity affinity)
 {
-    m_sel.setAffinity(affinity);
-    m_sel.setBase(pos);
-    m_sel.validate();
+    m_sel = Selection(pos, m_sel.extent(), affinity);
     m_needsLayout = true;
 }
 
 void SelectionController::setExtent(const Position &pos, EAffinity affinity)
 {
-    m_sel.setAffinity(affinity);
-    m_sel.setExtent(pos);
-    m_sel.validate();
+    m_sel = Selection(m_sel.base(), pos, affinity);
     m_needsLayout = true;
 }
 
index 309654a3a05186b6281e8c15070b5464bef9a838..43afbaff3d508a9c9c40b34f027997ad89c43a70 100644 (file)
@@ -46,6 +46,7 @@ public:
 #define SEL_DEFAULT_AFFINITY DOWNSTREAM
 
     SelectionController();
+    SelectionController(const Selection &sel);
     SelectionController(const RangeImpl *, EAffinity affinity);
     SelectionController(const VisiblePosition &);
     SelectionController(const VisiblePosition &, const VisiblePosition &);
@@ -63,6 +64,8 @@ public:
     void moveTo(const Position &, const Position &, EAffinity);
     void moveTo(const SelectionController &);
 
+    const Selection &selection() const { return m_sel; }
+
     Selection::EState state() const { return m_sel.state(); }
 
     EAffinity affinity() const { return m_sel.affinity(); }
@@ -185,6 +188,6 @@ inline bool operator!=(const SelectionController &a, const SelectionController &
     return !(a == b);
 }
 
-} // namespace khtml
+} // namespace WebCore
 
 #endif // KHTML_EDITING_SELECTIONCONTROLLER_H
index 497cb749c690b3c466c531b95c399ba37fa17ae8..26ec5c2151b5161491a10ffbd1311f2725f7941b 100644 (file)
@@ -286,7 +286,7 @@ void ApplyStyleCommand::updateStartEnd(Position newStart, Position newEnd)
     if (!m_useEndingSelection && (newStart != m_start || newEnd != m_end))
         m_useEndingSelection = true;
 
-    setEndingSelection(SelectionController(newStart, newEnd, VP_DEFAULT_AFFINITY));
+    setEndingSelection(Selection(newStart, newEnd, VP_DEFAULT_AFFINITY));
     m_start = newStart;
     m_end = newEnd;
 }
@@ -329,8 +329,6 @@ void ApplyStyleCommand::doApply()
             applyBlockStyle(m_style.get());
             break;
     }
-   
-    setEndingSelectionNeedsLayout();
 }
 
 EditAction ApplyStyleCommand::editingAction() const
index a12eea8b457ddb41e450f32be7a362ef3764cbef..9a0a137f24a8daf19ff3ba2ec77bf01832aec2db 100644 (file)
@@ -55,7 +55,7 @@ void BreakBlockquoteCommand::doApply()
     DOM::ElementImpl *breakNode;
     QPtrList<DOM::NodeImpl> ancestors;
     
-    SelectionController selection = endingSelection();
+    Selection selection = endingSelection();
     if (selection.isNone())
         return;
     
index 8bdfda14ff658ec2e8506aefd20215b9298d113e..e7b3ea1109894e33df0516c58365beaeabdfcd0e 100644 (file)
@@ -302,7 +302,7 @@ void CompositeEditCommand::deleteSelection(bool smartDelete, bool mergeBlocksAft
     }
 }
 
-void CompositeEditCommand::deleteSelection(const SelectionController &selection, bool smartDelete, bool mergeBlocksAfterDelete)
+void CompositeEditCommand::deleteSelection(const Selection &selection, bool smartDelete, bool mergeBlocksAfterDelete)
 {
     if (selection.isRange()) {
         EditCommandPtr cmd(new DeleteSelectionCommand(document(), selection, smartDelete, mergeBlocksAfterDelete));
@@ -339,7 +339,7 @@ void CompositeEditCommand::rebalanceWhitespaceAt(const Position &position)
 
 void CompositeEditCommand::rebalanceWhitespace()
 {
-    SelectionController selection = endingSelection();
+    Selection selection = endingSelection();
     if (selection.isCaretOrRange()) {
         EditCommandPtr startCmd(new RebalanceWhitespaceCommand(document(), endingSelection().start()));
         applyCommandToComposite(startCmd);
index 3de3998a3d176ebc625b37bd6487a873ad9fc36d..83861932d64caabc3b5d972a008fd9a87ce0f04c 100644 (file)
@@ -56,7 +56,7 @@ protected:
     void applyStyle(DOM::CSSStyleDeclarationImpl *style, DOM::Position start, DOM::Position end, EditAction editingAction=EditActionChangeAttributes);
     void deleteKeyPressed();
     void deleteSelection(bool smartDelete=false, bool mergeBlocksAfterDelete=true);
-    void deleteSelection(const SelectionController &selection, bool smartDelete=false, bool mergeBlocksAfterDelete=true);
+    void deleteSelection(const Selection &selection, bool smartDelete=false, bool mergeBlocksAfterDelete=true);
     void deleteTextFromNode(DOM::TextImpl *node, int offset, int count);
     void inputText(const DOM::DOMString &text, bool selectInsertedText = false);
     void insertNodeAfter(DOM::NodeImpl *insertChild, DOM::NodeImpl *refChild);
index 4e27764dfd06b8c36073b0e5a07e56a6c06ce86b..6d73adae3c80c13104f617cc7cc357232cec3a14 100644 (file)
@@ -111,7 +111,7 @@ DeleteSelectionCommand::DeleteSelectionCommand(DocumentImpl *document, bool smar
 {
 }
 
-DeleteSelectionCommand::DeleteSelectionCommand(DocumentImpl *document, const SelectionController &selection, bool smartDelete, bool mergeBlocksAfterDelete)
+DeleteSelectionCommand::DeleteSelectionCommand(DocumentImpl *document, const Selection &selection, bool smartDelete, bool mergeBlocksAfterDelete)
     : CompositeEditCommand(document), 
       m_hasSelectionToDelete(true), 
       m_smartDelete(smartDelete), 
@@ -611,7 +611,7 @@ void DeleteSelectionCommand::calculateTypingStyleAfterDelete(NodeImpl *insertedP
         // then start typing. In this case, the typing style is applied right now, and
         // is not retained until the next typing action.
 
-        setEndingSelection(SelectionController(Position(insertedPlaceholder, 0), DOWNSTREAM));
+        setEndingSelection(Selection(Position(insertedPlaceholder, 0), DOWNSTREAM));
         applyStyle(m_typingStyle.get(), EditActionUnspecified);
         m_typingStyle = 0;
     }
@@ -623,7 +623,7 @@ void DeleteSelectionCommand::calculateTypingStyleAfterDelete(NodeImpl *insertedP
 
 void DeleteSelectionCommand::clearTransientState()
 {
-    m_selectionToDelete.clear();
+    m_selectionToDelete = Selection();
     m_upstreamStart.clear();
     m_downstreamStart.clear();
     m_upstreamEnd.clear();
@@ -673,7 +673,7 @@ void DeleteSelectionCommand::doApply()
     if (handleSpecialCaseBRDelete()) {
         calculateTypingStyleAfterDelete(false);
         debugPosition("endingPosition   ", m_endingPosition);
-        setEndingSelection(SelectionController(m_endingPosition, affinity));
+        setEndingSelection(Selection(m_endingPosition, affinity));
         clearTransientState();
         rebalanceWhitespace();
         return;
@@ -702,7 +702,7 @@ void DeleteSelectionCommand::doApply()
     calculateTypingStyleAfterDelete(addedPlaceholder);
 
     debugPosition("endingPosition   ", m_endingPosition);
-    setEndingSelection(SelectionController(m_endingPosition, affinity));
+    setEndingSelection(Selection(m_endingPosition, affinity));
     clearTransientState();
     rebalanceWhitespace();
 }
index a1afead873aca72e8b3be14a6472cf78e7638ce9..d55c3443d52e14c0ed59ec767883a272540f45aa 100644 (file)
@@ -34,7 +34,7 @@ class DeleteSelectionCommand : public CompositeEditCommand
 { 
 public:
     DeleteSelectionCommand(DOM::DocumentImpl *document, bool smartDelete=false, bool mergeBlocksAfterDelete=true);
-    DeleteSelectionCommand(DOM::DocumentImpl *document, const SelectionController &selection, bool smartDelete=false, bool mergeBlocksAfterDelete=true);
+    DeleteSelectionCommand(DOM::DocumentImpl *document, const Selection &selection, bool smartDelete=false, bool mergeBlocksAfterDelete=true);
 
     virtual void doApply();
     virtual EditAction editingAction() const;
@@ -59,7 +59,7 @@ private:
     bool m_trailingWhitespaceValid;
 
     // This data is transient and should be cleared at the end of the doApply function.
-    SelectionController m_selectionToDelete;
+    Selection m_selectionToDelete;
     DOM::Position m_upstreamStart;
     DOM::Position m_downstreamStart;
     DOM::Position m_upstreamEnd;
index d332a39394f2e2191d5c138d8e23b027ec4176b8..5e73304d014f66e69cca8d62c0a16a0af4416338 100644 (file)
 
 #include "xml/dom_position.h"
 #include "DocumentImpl.h"
+#include "visible_position.h"
 #include "css/css_valueimpl.h"
 #include "css/css_computedstyle.h"
 
 #include <kxmlcore/Assertions.h>
 
-using DOM::DocumentImpl;
-using DOM::Position;
-using DOM::CSSMutableStyleDeclarationImpl;
-using DOM::CSSComputedStyleDeclarationImpl;
+namespace WebCore {
 
 #define IF_IMPL_NULL_RETURN_ARG(arg) do { \
         if (*this == 0) { return arg; } \
@@ -49,8 +47,6 @@ using DOM::CSSComputedStyleDeclarationImpl;
         if (*this == 0) { return; } \
     } while (0)
 
-namespace khtml {
-
 EditCommandPtr::EditCommandPtr()
 {
 }
@@ -107,19 +103,19 @@ DocumentImpl * const EditCommandPtr::document() const
     return get()->document();
 }
 
-SelectionController EditCommandPtr::startingSelection() const
+Selection EditCommandPtr::startingSelection() const
 {
-    IF_IMPL_NULL_RETURN_ARG(SelectionController());
+    IF_IMPL_NULL_RETURN_ARG(Selection());
     return get()->startingSelection();
 }
 
-SelectionController EditCommandPtr::endingSelection() const
+Selection EditCommandPtr::endingSelection() const
 {
-    IF_IMPL_NULL_RETURN_ARG(SelectionController());
+    IF_IMPL_NULL_RETURN_ARG(Selection());
     return get()->endingSelection();
 }
 
-void EditCommandPtr::setStartingSelection(const SelectionController &s) const
+void EditCommandPtr::setStartingSelection(const Selection &s) const
 {
     IF_IMPL_NULL_RETURN;
     get()->setStartingSelection(s);
@@ -134,11 +130,11 @@ void EditCommandPtr::setStartingSelection(const VisiblePosition &p) const
 void EditCommandPtr::setStartingSelection(const Position &p, EAffinity affinity) const
 {
     IF_IMPL_NULL_RETURN;
-    SelectionController s = SelectionController(p, affinity);
+    Selection s = Selection(p, affinity);
     get()->setStartingSelection(s);
 }
 
-void EditCommandPtr::setEndingSelection(const SelectionController &s) const
+void EditCommandPtr::setEndingSelection(const Selection &s) const
 {
     IF_IMPL_NULL_RETURN;
     get()->setEndingSelection(s);
@@ -153,7 +149,7 @@ void EditCommandPtr::setEndingSelection(const VisiblePosition &p) const
 void EditCommandPtr::setEndingSelection(const Position &p, EAffinity affinity) const
 {
     IF_IMPL_NULL_RETURN;
-    SelectionController s = SelectionController(p, affinity);
+    Selection s = Selection(p, affinity);
     get()->setEndingSelection(s);
 }
 
@@ -192,7 +188,7 @@ EditCommand::EditCommand(DocumentImpl *document)
 {
     ASSERT(m_document);
     ASSERT(m_document->frame());
-    m_startingSelection = m_document->frame()->selection();
+    m_startingSelection = m_document->frame()->selection().selection();
     m_endingSelection = m_startingSelection;
 }
 
@@ -276,7 +272,7 @@ EditAction EditCommand::editingAction() const
     return EditActionUnspecified;
 }
 
-void EditCommand::setStartingSelection(const SelectionController &s)
+void EditCommand::setStartingSelection(const Selection &s)
 {
     for (EditCommand *cmd = this; cmd; cmd = cmd->m_parent)
         cmd->m_startingSelection = s;
@@ -284,19 +280,19 @@ void EditCommand::setStartingSelection(const SelectionController &s)
 
 void EditCommand::setStartingSelection(const VisiblePosition &p)
 {
-    SelectionController s = SelectionController(p);
+    Selection s = Selection(p.deepEquivalent(), p.affinity());
     for (EditCommand *cmd = this; cmd; cmd = cmd->m_parent)
         cmd->m_startingSelection = s;
 }
 
 void EditCommand::setStartingSelection(const Position &p, EAffinity affinity)
 {
-    SelectionController s = SelectionController(p, affinity);
+    Selection s = Selection(p, affinity);
     for (EditCommand *cmd = this; cmd; cmd = cmd->m_parent)
         cmd->m_startingSelection = s;
 }
 
-void EditCommand::setEndingSelection(const SelectionController &s)
+void EditCommand::setEndingSelection(const Selection &s)
 {
     for (EditCommand *cmd = this; cmd; cmd = cmd->m_parent)
         cmd->m_endingSelection = s;
@@ -304,14 +300,14 @@ void EditCommand::setEndingSelection(const SelectionController &s)
 
 void EditCommand::setEndingSelection(const VisiblePosition &p)
 {
-    SelectionController s = SelectionController(p);
+    Selection s = Selection(p.deepEquivalent(), p.affinity());
     for (EditCommand *cmd = this; cmd; cmd = cmd->m_parent)
         cmd->m_endingSelection = s;
 }
 
 void EditCommand::setEndingSelection(const Position &p, EAffinity affinity)
 {
-    SelectionController s = SelectionController(p, affinity);
+    Selection s = Selection(p, affinity);
     for (EditCommand *cmd = this; cmd; cmd = cmd->m_parent)
         cmd->m_endingSelection = s;
 }
@@ -358,4 +354,4 @@ void EditCommand::updateLayout() const
     document()->updateLayoutIgnorePendingStylesheets();
 }
 
-} // namespace khtml
+} // namespace WebCore
index 772b15e936b064c63dbba7f3cc3167e1ef9a465e..ff13e417f9254c070cabb053dc4d51b2c80887c9 100644 (file)
 
 #include "Shared.h"
 #include "edit_actions.h"
-#include "SelectionController.h"
+#include "Selection.h"
 
-namespace DOM {
-    class CSSMutableStyleDeclarationImpl;
-    class DocumentImpl;
-}
+namespace WebCore {
 
-namespace khtml {
+class CSSMutableStyleDeclarationImpl;
+class DocumentImpl;
+class VisiblePosition;
 
 //------------------------------------------------------------------------------------------
 // EditCommand
@@ -64,18 +63,16 @@ public:
 
     virtual DOM::DocumentImpl * const document() const { return m_document.get(); }
 
-    SelectionController startingSelection() const { return m_startingSelection; }
-    SelectionController endingSelection() const { return m_endingSelection; }
+    Selection startingSelection() const { return m_startingSelection; }
+    Selection endingSelection() const { return m_endingSelection; }
 
-    void setEndingSelectionNeedsLayout(bool flag=true) { m_endingSelection.setNeedsLayout(flag); }
-        
     ECommandState state() const { return m_state; }
     void setState(ECommandState state) { m_state = state; }
 
-    void setStartingSelection(const SelectionController &s);
+    void setStartingSelection(const Selection &s);
     void setStartingSelection(const VisiblePosition &p);
     void setStartingSelection(const DOM::Position &p, EAffinity affinity);
-    void setEndingSelection(const SelectionController &s);
+    void setEndingSelection(const Selection &s);
     void setEndingSelection(const VisiblePosition &p);
     void setEndingSelection(const DOM::Position &p, EAffinity affinity);
 
@@ -94,8 +91,8 @@ private:
 
     RefPtr<DOM::DocumentImpl> m_document;
     ECommandState m_state;
-    SelectionController m_startingSelection;
-    SelectionController m_endingSelection;
+    Selection m_startingSelection;
+    Selection m_endingSelection;
     RefPtr<DOM::CSSMutableStyleDeclarationImpl> m_typingStyle;
     EditCommand *m_parent;
 };
@@ -116,13 +113,13 @@ public:
 
     DOM::DocumentImpl * const document() const;
 
-    SelectionController startingSelection() const;
-    SelectionController endingSelection() const;
+    Selection startingSelection() const;
+    Selection endingSelection() const;
 
-    void setStartingSelection(const SelectionController &s) const;
+    void setStartingSelection(const Selection &s) const;
     void setStartingSelection(const VisiblePosition &p) const;
     void setStartingSelection(const DOM::Position &p, EAffinity affinity) const;
-    void setEndingSelection(const SelectionController &s) const;
+    void setEndingSelection(const Selection &s) const;
     void setEndingSelection(const VisiblePosition &p) const;
     void setEndingSelection(const DOM::Position &p, EAffinity affinity) const;
 
@@ -139,6 +136,6 @@ public:
     static EditCommandPtr &emptyCommand();
 };
 
-} // namespace khtml
+} // namespace WebCore
 
 #endif // __edit_command_h__
index 5d8005f75c563c146004bd596a3531aa5642c563..683252c72d73bef407517bf9a57fb13b1fdf142a 100644 (file)
@@ -90,7 +90,7 @@ void InsertLineBreakCommand::insertNodeBeforePosition(NodeImpl *node, const Posi
 void InsertLineBreakCommand::doApply()
 {
     deleteSelection();
-    SelectionController selection = endingSelection();
+    Selection selection = endingSelection();
 
     ElementImpl *breakNode = createBreakElement(document());
     NodeImpl *nodeToInsert = breakNode;
@@ -116,7 +116,7 @@ void InsertLineBreakCommand::doApply()
             bool hasTrailingBR = next && next->hasTagName(brTag) && pos.node()->enclosingBlockFlowElement() == next->enclosingBlockFlowElement();
             insertNodeAfterPosition(nodeToInsert, pos);
             if (hasTrailingBR)
-                setEndingSelection(SelectionController(Position(next, 0), DOWNSTREAM));
+                setEndingSelection(Selection(Position(next, 0), DOWNSTREAM));
             else if (!document()->inStrictMode()) {
                 // Insert an "extra" BR at the end of the block. 
                 ElementImpl *extraBreakNode = createBreakElement(document());
@@ -170,7 +170,7 @@ void InsertLineBreakCommand::doApply()
     CSSMutableStyleDeclarationImpl *typingStyle = document()->frame()->typingStyle();
     
     if (typingStyle && typingStyle->length() > 0) {
-        SelectionController selectionBeforeStyle = endingSelection();
+        Selection selectionBeforeStyle = endingSelection();
         applyStyle(typingStyle, Position(nodeToInsert, 0), Position(nodeToInsert, maxDeepOffset(nodeToInsert)));
         setEndingSelection(selectionBeforeStyle);
     }
index ff0f45410a5e3f4ee5cef8b0fca97ea22e1a6528..b4b20b3dada3950291928ee01a08a899fd627441 100644 (file)
@@ -102,7 +102,7 @@ void InsertParagraphSeparatorCommand::applyStyleAfterInsertion()
 void InsertParagraphSeparatorCommand::doApply()
 {
     bool splitText = false;
-    SelectionController selection = endingSelection();
+    Selection selection = endingSelection();
     if (selection.isNone())
         return;
     
index 3bb7ffd7a5ff2e1c1fb0a8b6e2862cb771bc5f01..fef6b3c4662383e55d16eee3e24cd2a3a97a3f7b 100644 (file)
@@ -102,7 +102,7 @@ void InsertTextCommand::input(const DOMString &text, bool selectInsertedText)
 {
     assert(text.find('\n') == -1);
 
-    SelectionController selection = endingSelection();
+    Selection selection = endingSelection();
     bool adjustDownstream = isStartOfLine(VisiblePosition(selection.start().downstream(), DOWNSTREAM));
 
     // Delete the current selection, or collapse whitespace, as needed
@@ -147,7 +147,7 @@ void InsertTextCommand::input(const DOMString &text, bool selectInsertedText)
         m_charactersAdded += text.length();
     }
 
-    setEndingSelection(SelectionController(startPosition, endPosition, DOWNSTREAM));
+    setEndingSelection(Selection(startPosition, endPosition, DOWNSTREAM));
 
     // Handle the case where there is a typing style.
     // FIXME: Improve typing style.
index 8d54fd4054a63dda14aa27c14b61781bc0b7c991..80384bc11a3d57e57b233e67ac4af3c206de37aa 100644 (file)
@@ -50,7 +50,7 @@ MoveSelectionCommand::~MoveSelectionCommand()
 
 void MoveSelectionCommand::doApply()
 {
-    SelectionController selection = endingSelection();
+    Selection selection = endingSelection();
     ASSERT(selection.isRange());
 
     Position pos = m_position;
index 36fae494db280c75770848468bbc3b5cd46482dc..a9fac6e5330108921ac0c48bc016f4524447758c 100644 (file)
@@ -500,7 +500,7 @@ bool isFirstVisiblePositionInSpecialElementInFragment(const Position& pos)
 void ReplaceSelectionCommand::doApply()
 {
     // collect information about the current selection, prior to deleting the selection
-    SelectionController selection = endingSelection();
+    Selection selection = endingSelection();
     ASSERT(selection.isCaretOrRange());
     
     if (m_matchStyle)
@@ -896,7 +896,7 @@ void ReplaceSelectionCommand::completeHTMLReplacement(const Position &lastPositi
         return;
     
     if (m_selectReplacement)
-        setEndingSelection(SelectionController(start, end, SEL_DEFAULT_AFFINITY));
+        setEndingSelection(Selection(start, end, SEL_DEFAULT_AFFINITY));
     else
         setEndingSelection(end, SEL_DEFAULT_AFFINITY);
     
index c3a408d802780bfcdc619cc28fbab87b72e77c34..7c0b47e3a2682b2cd4f2332831cb2544cc4b2f5d 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "config.h"
 #include "typing_command.h"
+#include "SelectionController.h"
 
 #include "insert_text_command.h"
 #include "insert_line_break_command.h"
@@ -67,7 +68,7 @@ void TypingCommand::deleteKeyPressed(DocumentImpl *document, bool smartDelete)
         static_cast<TypingCommand *>(lastEditCommand.get())->deleteKeyPressed();
     }
     else {
-        SelectionController selection = frame->selection();
+        Selection selection = frame->selection().selection();
         if (selection.isCaret() && VisiblePosition(selection.start(), selection.affinity()).previous().isNull()) {
             // do nothing for a delete key at the start of an editable element.
         }
@@ -92,7 +93,7 @@ void TypingCommand::forwardDeleteKeyPressed(DocumentImpl *document, bool smartDe
         static_cast<TypingCommand *>(lastEditCommand.get())->forwardDeleteKeyPressed();
     }
     else {
-        SelectionController selection = frame->selection();
+        Selection selection = frame->selection().selection();
         if (selection.isCaret() && isEndOfDocument(VisiblePosition(selection.start(), selection.affinity()))) {
             // do nothing for a delete key at the start of an editable element.
         }
@@ -324,7 +325,7 @@ void TypingCommand::insertParagraphSeparatorInQuotedContent()
 
 void TypingCommand::deleteKeyPressed()
 {
-    SelectionController selectionToDelete;
+    Selection selectionToDelete;
     
     switch (endingSelection().state()) {
         case khtml::Selection::RANGE:
@@ -338,7 +339,7 @@ void TypingCommand::deleteKeyPressed()
             Position start = VisiblePosition(pos, endingSelection().affinity()).previous().deepEquivalent();
             Position end = VisiblePosition(pos, endingSelection().affinity()).deepEquivalent();
             if (start.isNotNull() && end.isNotNull() && start.node()->rootEditableElement() == end.node()->rootEditableElement())
-                selectionToDelete = SelectionController(start, end, SEL_DEFAULT_AFFINITY);
+                selectionToDelete = Selection(start, end, SEL_DEFAULT_AFFINITY);
             break;
         }
         case khtml::Selection::NONE:
@@ -355,7 +356,7 @@ void TypingCommand::deleteKeyPressed()
 
 void TypingCommand::forwardDeleteKeyPressed()
 {
-    SelectionController selectionToDelete;
+    Selection selectionToDelete;
     
     switch (endingSelection().state()) {
         case khtml::Selection::RANGE:
@@ -369,7 +370,7 @@ void TypingCommand::forwardDeleteKeyPressed()
             Position start = VisiblePosition(pos, endingSelection().affinity()).next().deepEquivalent();
             Position end = VisiblePosition(pos, endingSelection().affinity()).deepEquivalent();
             if (start.isNotNull() && end.isNotNull() && start.node()->rootEditableElement() == end.node()->rootEditableElement())
-                selectionToDelete = SelectionController(start, end, SEL_DEFAULT_AFFINITY);
+                selectionToDelete = Selection(start, end, SEL_DEFAULT_AFFINITY);
             break;
         }
         case khtml::Selection::NONE:
index 4df02330f5831969178067074277d45c1a349ac3..39815551643797027cb691ce6dfe0e4ca8ea8241 100644 (file)
@@ -2467,8 +2467,9 @@ EditCommandPtr Frame::lastEditCommand()
 
 void Frame::appliedEditing(EditCommandPtr &cmd)
 {
-    if (shouldChangeSelection(cmd.endingSelection())) {
-        setSelection(cmd.endingSelection(), false);
+    SelectionController sel(cmd.endingSelection());
+    if (shouldChangeSelection(sel)) {
+        setSelection(sel, false);
     }
 
     // Now set the typing style from the command. Clear it when done.
@@ -2497,8 +2498,9 @@ void Frame::appliedEditing(EditCommandPtr &cmd)
 
 void Frame::unappliedEditing(EditCommandPtr &cmd)
 {
-    if (shouldChangeSelection(cmd.startingSelection())) {
-        setSelection(cmd.startingSelection(), true);
+    SelectionController sel(cmd.startingSelection());
+    if (shouldChangeSelection(sel)) {
+        setSelection(sel, true);
     }
     Mac(this)->registerCommandForRedo(cmd);
     Mac(this)->respondToChangedContents();
@@ -2507,8 +2509,9 @@ void Frame::unappliedEditing(EditCommandPtr &cmd)
 
 void Frame::reappliedEditing(EditCommandPtr &cmd)
 {
-    if (shouldChangeSelection(cmd.endingSelection())) {
-        setSelection(cmd.endingSelection(), true);
+    SelectionController sel(cmd.endingSelection());
+    if (shouldChangeSelection(sel)) {
+        setSelection(sel, true);
     }
     Mac(this)->registerCommandForUndo(cmd);
     Mac(this)->respondToChangedContents();
index e48b12afcd2c3875b5c8fdb6f19fa7516051393e..b12385039d8ad9ca2f586dd26e7ceec6a1707ba1 100644 (file)
@@ -1045,7 +1045,6 @@ protected:
 
   FramePrivate *d;
   friend class FramePrivate;
-  friend class khtml::SelectionController;
 
 public:  
   friend class MacFrame;