From ef508986ba527f03789124976ca0a5481d64855b Mon Sep 17 00:00:00 2001 From: eseidel Date: Tue, 3 Jan 2006 09:19:17 +0000 Subject: [PATCH] Bug #: 6109 Submitted by: eseidel Reviewed by: darin No functionality changes, no tests possible. khtml/editing should use RefPtr instead of manual ref/deref http://bugzilla.opendarwin.org/show_bug.cgi?id=6109 Results in a slight performance gain < 1% on the PLT. * khtml/editing/SelectionController.cpp: (khtml::SelectionController::toRange): * khtml/editing/SelectionController.h: * khtml/editing/append_node_command.cpp: (khtml::AppendNodeCommand::AppendNodeCommand): (khtml::AppendNodeCommand::doApply): (khtml::AppendNodeCommand::doUnapply): * khtml/editing/append_node_command.h: (khtml::AppendNodeCommand::~AppendNodeCommand): (khtml::AppendNodeCommand::appendChild): (khtml::AppendNodeCommand::parentNode): * khtml/editing/apply_style_command.cpp: (khtml::StyleChange::init): (khtml::ApplyStyleCommand::removeInlineStyle): * khtml/editing/apply_style_command.h: * khtml/editing/composite_edit_command.cpp: (khtml::CompositeEditCommand::deleteInsignificantText): * khtml/editing/delete_from_text_node_command.cpp: (khtml::DeleteFromTextNodeCommand::DeleteFromTextNodeCommand): * khtml/editing/delete_from_text_node_command.h: (khtml::DeleteFromTextNodeCommand::~DeleteFromTextNodeCommand): (khtml::DeleteFromTextNodeCommand::node): * khtml/editing/delete_selection_command.cpp: (khtml::DeleteSelectionCommand::initializePositionData): (khtml::DeleteSelectionCommand::saveTypingStyleState): (khtml::DeleteSelectionCommand::handleGeneralDelete): (khtml::DeleteSelectionCommand::calculateEndingPosition): (khtml::DeleteSelectionCommand::calculateTypingStyleAfterDelete): (khtml::DeleteSelectionCommand::clearTransientState): * khtml/editing/delete_selection_command.h: * khtml/editing/edit_command.cpp: (khtml::EditCommand::EditCommand): (khtml::EditCommand::~EditCommand): (khtml::EditCommand::setTypingStyle): (khtml::EditCommand::styleAtPosition): * khtml/editing/edit_command.h: (khtml::EditCommand::document): (khtml::EditCommand::typingStyle): * khtml/editing/insert_into_text_node_command.cpp: (khtml::InsertIntoTextNodeCommand::InsertIntoTextNodeCommand): * khtml/editing/insert_into_text_node_command.h: (khtml::InsertIntoTextNodeCommand::~InsertIntoTextNodeCommand): (khtml::InsertIntoTextNodeCommand::node): * khtml/editing/insert_node_before_command.cpp: (khtml::InsertNodeBeforeCommand::InsertNodeBeforeCommand): (khtml::InsertNodeBeforeCommand::doApply): (khtml::InsertNodeBeforeCommand::doUnapply): * khtml/editing/insert_node_before_command.h: (khtml::InsertNodeBeforeCommand::~InsertNodeBeforeCommand): (khtml::InsertNodeBeforeCommand::insertChild): (khtml::InsertNodeBeforeCommand::refChild): * khtml/editing/insert_paragraph_separator_command.cpp: (khtml::InsertParagraphSeparatorCommand::InsertParagraphSeparatorCommand): (khtml::InsertParagraphSeparatorCommand::~InsertParagraphSeparatorCommand): (khtml::InsertParagraphSeparatorCommand::calculateStyleBeforeInsertion): (khtml::InsertParagraphSeparatorCommand::applyStyleAfterInsertion): * khtml/editing/insert_paragraph_separator_command.h: * khtml/editing/join_text_nodes_command.cpp: (khtml::JoinTextNodesCommand::JoinTextNodesCommand): (khtml::JoinTextNodesCommand::doApply): (khtml::JoinTextNodesCommand::doUnapply): * khtml/editing/join_text_nodes_command.h: (khtml::JoinTextNodesCommand::~JoinTextNodesCommand): (khtml::JoinTextNodesCommand::firstNode): (khtml::JoinTextNodesCommand::secondNode): * khtml/editing/jsediting.cpp: * khtml/editing/markup.cpp: (khtml::createMarkup): (khtml::createFragmentFromMarkup): (khtml::createFragmentFromText): (khtml::createFragmentFromNodeList): * khtml/editing/markup.h: * khtml/editing/merge_identical_elements_command.cpp: (khtml::MergeIdenticalElementsCommand::MergeIdenticalElementsCommand): (khtml::MergeIdenticalElementsCommand::doApply): (khtml::MergeIdenticalElementsCommand::doUnapply): * khtml/editing/merge_identical_elements_command.h: (khtml::MergeIdenticalElementsCommand::~MergeIdenticalElementsCommand): * khtml/editing/move_selection_command.cpp: (khtml::MoveSelectionCommand::MoveSelectionCommand): (khtml::MoveSelectionCommand::~MoveSelectionCommand): (khtml::MoveSelectionCommand::doApply): * khtml/editing/move_selection_command.h: * khtml/editing/rebalance_whitespace_command.cpp: * khtml/editing/rebalance_whitespace_command.h: (khtml::RebalanceWhitespaceCommand::~RebalanceWhitespaceCommand): * khtml/editing/remove_css_property_command.cpp: (khtml::RemoveCSSPropertyCommand::RemoveCSSPropertyCommand): * khtml/editing/remove_css_property_command.h: (khtml::RemoveCSSPropertyCommand::~RemoveCSSPropertyCommand): (khtml::RemoveCSSPropertyCommand::styleDeclaration): * khtml/editing/remove_node_attribute_command.cpp: (khtml::RemoveNodeAttributeCommand::RemoveNodeAttributeCommand): * khtml/editing/remove_node_attribute_command.h: (khtml::RemoveNodeAttributeCommand::~RemoveNodeAttributeCommand): (khtml::RemoveNodeAttributeCommand::element): * khtml/editing/remove_node_command.cpp: (khtml::RemoveNodeCommand::RemoveNodeCommand): (khtml::RemoveNodeCommand::doApply): (khtml::RemoveNodeCommand::doUnapply): * khtml/editing/remove_node_command.h: (khtml::RemoveNodeCommand::~RemoveNodeCommand): (khtml::RemoveNodeCommand::node): * khtml/editing/remove_node_preserving_children_command.cpp: (khtml::RemoveNodePreservingChildrenCommand::RemoveNodePreservingChildrenCommand): * khtml/editing/remove_node_preserving_children_command.h: (khtml::RemoveNodePreservingChildrenCommand::~RemoveNodePreservingChildrenCommand): (khtml::RemoveNodePreservingChildrenCommand::node): * khtml/editing/replace_selection_command.cpp: (khtml::ReplacementFragment::ReplacementFragment): (khtml::ReplacementFragment::~ReplacementFragment): (khtml::ReplacementFragment::enclosingBlock): (khtml::ReplacementFragment::removeNodePreservingChildren): (khtml::ReplacementFragment::removeNode): (khtml::ReplacementFragment::insertFragmentForTestRendering): (khtml::ReplacementFragment::restoreTestRenderingNodesToFragment): (khtml::ReplaceSelectionCommand::fixupNodeStyles): (khtml::computeAndStoreNodeDesiredStyle): (khtml::NodeDesiredStyle::NodeDesiredStyle): (khtml::ReplaceSelectionCommand::ReplaceSelectionCommand): (khtml::ReplaceSelectionCommand::~ReplaceSelectionCommand): (khtml::ReplaceSelectionCommand::doApply): (khtml::ReplaceSelectionCommand::completeHTMLReplacement): (khtml::ReplaceSelectionCommand::updateNodesInserted): * khtml/editing/replace_selection_command.h: (khtml::NodeDesiredStyle::node): (khtml::NodeDesiredStyle::style): (khtml::ReplacementFragment::root): * khtml/editing/set_node_attribute_command.cpp: (khtml::SetNodeAttributeCommand::SetNodeAttributeCommand): * khtml/editing/set_node_attribute_command.h: (khtml::SetNodeAttributeCommand::~SetNodeAttributeCommand): (khtml::SetNodeAttributeCommand::element): * khtml/editing/split_element_command.cpp: (khtml::SplitElementCommand::SplitElementCommand): (khtml::SplitElementCommand::doApply): (khtml::SplitElementCommand::doUnapply): * khtml/editing/split_element_command.h: (khtml::SplitElementCommand::~SplitElementCommand): * khtml/editing/split_text_node_command.cpp: (khtml::SplitTextNodeCommand::SplitTextNodeCommand): (khtml::SplitTextNodeCommand::doApply): (khtml::SplitTextNodeCommand::doUnapply): * khtml/editing/split_text_node_command.h: (khtml::SplitTextNodeCommand::~SplitTextNodeCommand): (khtml::SplitTextNodeCommand::node): * khtml/editing/split_text_node_containing_element.cpp: (khtml::SplitTextNodeContainingElementCommand::SplitTextNodeContainingElementCommand): (khtml::SplitTextNodeContainingElementCommand::doApply): * khtml/editing/split_text_node_containing_element_command.h: (khtml::SplitTextNodeContainingElementCommand::~SplitTextNodeContainingElementCommand): * khtml/editing/visible_position.cpp: (khtml::makeRange): * khtml/editing/visible_position.h: * khtml/editing/visible_text.cpp: (khtml::TextIterator::range): (khtml::SimplifiedBackwardsTextIterator::range): (khtml::CharacterIterator::range): (khtml::findPlainText): * khtml/editing/visible_text.h: (khtml::WordAwareIterator::range): * khtml/editing/wrap_contents_in_dummy_span_command.cpp: (khtml::WrapContentsInDummySpanCommand::WrapContentsInDummySpanCommand): (khtml::WrapContentsInDummySpanCommand::doApply): (khtml::WrapContentsInDummySpanCommand::doUnapply): * khtml/editing/wrap_contents_in_dummy_span_command.h: (khtml::WrapContentsInDummySpanCommand::~WrapContentsInDummySpanCommand): * kwq/DOMHTML.mm: (-[DOMHTMLDocument _createDocumentFragmentWithMarkupString:baseURLString:]): (-[DOMHTMLDocument _createDocumentFragmentWithText:]): * kwq/WebCoreBridge.mm: (-[WebCoreBridge documentFragmentWithMarkupString:baseURLString:]): (-[WebCoreBridge documentFragmentWithText:]): (-[WebCoreBridge documentFragmentWithNodesAsParagraphs:]): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@11854 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- WebCore/ChangeLog | 186 ++++++++++++++++ WebCore/khtml/editing/SelectionController.cpp | 10 +- WebCore/khtml/editing/SelectionController.h | 3 +- WebCore/khtml/editing/append_node_command.cpp | 16 +- WebCore/khtml/editing/append_node_command.h | 10 +- WebCore/khtml/editing/apply_style_command.cpp | 30 +-- WebCore/khtml/editing/apply_style_command.h | 3 +- .../khtml/editing/composite_edit_command.cpp | 9 +- .../editing/delete_from_text_node_command.cpp | 8 - .../editing/delete_from_text_node_command.h | 6 +- .../editing/delete_selection_command.cpp | 104 +++------ .../khtml/editing/delete_selection_command.h | 12 +- WebCore/khtml/editing/edit_command.cpp | 40 +--- WebCore/khtml/editing/edit_command.h | 14 +- .../editing/insert_into_text_node_command.cpp | 7 - .../editing/insert_into_text_node_command.h | 6 +- .../editing/insert_node_before_command.cpp | 16 +- .../editing/insert_node_before_command.h | 10 +- .../insert_paragraph_separator_command.cpp | 14 +- .../insert_paragraph_separator_command.h | 2 +- .../khtml/editing/join_text_nodes_command.cpp | 15 +- .../khtml/editing/join_text_nodes_command.h | 10 +- WebCore/khtml/editing/jsediting.cpp | 20 +- WebCore/khtml/editing/markup.cpp | 65 ++---- WebCore/khtml/editing/markup.h | 7 +- .../merge_identical_elements_command.cpp | 24 +-- .../merge_identical_elements_command.h | 8 +- .../khtml/editing/move_selection_command.cpp | 5 +- .../khtml/editing/move_selection_command.h | 2 +- .../editing/rebalance_whitespace_command.cpp | 4 - .../editing/rebalance_whitespace_command.h | 2 +- .../editing/remove_css_property_command.cpp | 7 - .../editing/remove_css_property_command.h | 6 +- .../editing/remove_node_attribute_command.cpp | 7 - .../editing/remove_node_attribute_command.h | 6 +- WebCore/khtml/editing/remove_node_command.cpp | 27 +-- WebCore/khtml/editing/remove_node_command.h | 10 +- ...emove_node_preserving_children_command.cpp | 7 - .../remove_node_preserving_children_command.h | 6 +- .../editing/replace_selection_command.cpp | 204 +++++------------- .../khtml/editing/replace_selection_command.h | 31 ++- .../editing/set_node_attribute_command.cpp | 7 - .../editing/set_node_attribute_command.h | 6 +- .../khtml/editing/split_element_command.cpp | 21 +- WebCore/khtml/editing/split_element_command.h | 8 +- .../khtml/editing/split_text_node_command.cpp | 22 +- .../khtml/editing/split_text_node_command.h | 8 +- .../split_text_node_containing_element.cpp | 12 +- ...lit_text_node_containing_element_command.h | 4 +- WebCore/khtml/editing/visible_position.cpp | 4 +- WebCore/khtml/editing/visible_position.h | 5 +- WebCore/khtml/editing/visible_text.cpp | 31 ++- WebCore/khtml/editing/visible_text.h | 12 +- .../wrap_contents_in_dummy_span_command.cpp | 23 +- .../wrap_contents_in_dummy_span_command.h | 6 +- WebCore/kwq/DOMHTML.mm | 6 +- WebCore/kwq/WebCoreBridge.mm | 8 +- 57 files changed, 463 insertions(+), 699 deletions(-) diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index b613a58abe4..0fe88bf701f 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -1,3 +1,189 @@ +2006-01-03 Eric Seidel + + Reviewed by darin. + + No functionality changes, no tests possible. + + khtml/editing should use RefPtr instead of manual ref/deref + http://bugzilla.opendarwin.org/show_bug.cgi?id=6109 + + Results in a slight performance gain < 1% on the PLT. + + * khtml/editing/SelectionController.cpp: + (khtml::SelectionController::toRange): + * khtml/editing/SelectionController.h: + * khtml/editing/append_node_command.cpp: + (khtml::AppendNodeCommand::AppendNodeCommand): + (khtml::AppendNodeCommand::doApply): + (khtml::AppendNodeCommand::doUnapply): + * khtml/editing/append_node_command.h: + (khtml::AppendNodeCommand::~AppendNodeCommand): + (khtml::AppendNodeCommand::appendChild): + (khtml::AppendNodeCommand::parentNode): + * khtml/editing/apply_style_command.cpp: + (khtml::StyleChange::init): + (khtml::ApplyStyleCommand::removeInlineStyle): + * khtml/editing/apply_style_command.h: + * khtml/editing/composite_edit_command.cpp: + (khtml::CompositeEditCommand::deleteInsignificantText): + * khtml/editing/delete_from_text_node_command.cpp: + (khtml::DeleteFromTextNodeCommand::DeleteFromTextNodeCommand): + * khtml/editing/delete_from_text_node_command.h: + (khtml::DeleteFromTextNodeCommand::~DeleteFromTextNodeCommand): + (khtml::DeleteFromTextNodeCommand::node): + * khtml/editing/delete_selection_command.cpp: + (khtml::DeleteSelectionCommand::initializePositionData): + (khtml::DeleteSelectionCommand::saveTypingStyleState): + (khtml::DeleteSelectionCommand::handleGeneralDelete): + (khtml::DeleteSelectionCommand::calculateEndingPosition): + (khtml::DeleteSelectionCommand::calculateTypingStyleAfterDelete): + (khtml::DeleteSelectionCommand::clearTransientState): + * khtml/editing/delete_selection_command.h: + * khtml/editing/edit_command.cpp: + (khtml::EditCommand::EditCommand): + (khtml::EditCommand::~EditCommand): + (khtml::EditCommand::setTypingStyle): + (khtml::EditCommand::styleAtPosition): + * khtml/editing/edit_command.h: + (khtml::EditCommand::document): + (khtml::EditCommand::typingStyle): + * khtml/editing/insert_into_text_node_command.cpp: + (khtml::InsertIntoTextNodeCommand::InsertIntoTextNodeCommand): + * khtml/editing/insert_into_text_node_command.h: + (khtml::InsertIntoTextNodeCommand::~InsertIntoTextNodeCommand): + (khtml::InsertIntoTextNodeCommand::node): + * khtml/editing/insert_node_before_command.cpp: + (khtml::InsertNodeBeforeCommand::InsertNodeBeforeCommand): + (khtml::InsertNodeBeforeCommand::doApply): + (khtml::InsertNodeBeforeCommand::doUnapply): + * khtml/editing/insert_node_before_command.h: + (khtml::InsertNodeBeforeCommand::~InsertNodeBeforeCommand): + (khtml::InsertNodeBeforeCommand::insertChild): + (khtml::InsertNodeBeforeCommand::refChild): + * khtml/editing/insert_paragraph_separator_command.cpp: + (khtml::InsertParagraphSeparatorCommand::InsertParagraphSeparatorCommand): + (khtml::InsertParagraphSeparatorCommand::~InsertParagraphSeparatorCommand): + (khtml::InsertParagraphSeparatorCommand::calculateStyleBeforeInsertion): + (khtml::InsertParagraphSeparatorCommand::applyStyleAfterInsertion): + * khtml/editing/insert_paragraph_separator_command.h: + * khtml/editing/join_text_nodes_command.cpp: + (khtml::JoinTextNodesCommand::JoinTextNodesCommand): + (khtml::JoinTextNodesCommand::doApply): + (khtml::JoinTextNodesCommand::doUnapply): + * khtml/editing/join_text_nodes_command.h: + (khtml::JoinTextNodesCommand::~JoinTextNodesCommand): + (khtml::JoinTextNodesCommand::firstNode): + (khtml::JoinTextNodesCommand::secondNode): + * khtml/editing/jsediting.cpp: + * khtml/editing/markup.cpp: + (khtml::createMarkup): + (khtml::createFragmentFromMarkup): + (khtml::createFragmentFromText): + (khtml::createFragmentFromNodeList): + * khtml/editing/markup.h: + * khtml/editing/merge_identical_elements_command.cpp: + (khtml::MergeIdenticalElementsCommand::MergeIdenticalElementsCommand): + (khtml::MergeIdenticalElementsCommand::doApply): + (khtml::MergeIdenticalElementsCommand::doUnapply): + * khtml/editing/merge_identical_elements_command.h: + (khtml::MergeIdenticalElementsCommand::~MergeIdenticalElementsCommand): + * khtml/editing/move_selection_command.cpp: + (khtml::MoveSelectionCommand::MoveSelectionCommand): + (khtml::MoveSelectionCommand::~MoveSelectionCommand): + (khtml::MoveSelectionCommand::doApply): + * khtml/editing/move_selection_command.h: + * khtml/editing/rebalance_whitespace_command.cpp: + * khtml/editing/rebalance_whitespace_command.h: + (khtml::RebalanceWhitespaceCommand::~RebalanceWhitespaceCommand): + * khtml/editing/remove_css_property_command.cpp: + (khtml::RemoveCSSPropertyCommand::RemoveCSSPropertyCommand): + * khtml/editing/remove_css_property_command.h: + (khtml::RemoveCSSPropertyCommand::~RemoveCSSPropertyCommand): + (khtml::RemoveCSSPropertyCommand::styleDeclaration): + * khtml/editing/remove_node_attribute_command.cpp: + (khtml::RemoveNodeAttributeCommand::RemoveNodeAttributeCommand): + * khtml/editing/remove_node_attribute_command.h: + (khtml::RemoveNodeAttributeCommand::~RemoveNodeAttributeCommand): + (khtml::RemoveNodeAttributeCommand::element): + * khtml/editing/remove_node_command.cpp: + (khtml::RemoveNodeCommand::RemoveNodeCommand): + (khtml::RemoveNodeCommand::doApply): + (khtml::RemoveNodeCommand::doUnapply): + * khtml/editing/remove_node_command.h: + (khtml::RemoveNodeCommand::~RemoveNodeCommand): + (khtml::RemoveNodeCommand::node): + * khtml/editing/remove_node_preserving_children_command.cpp: + (khtml::RemoveNodePreservingChildrenCommand::RemoveNodePreservingChildrenCommand): + * khtml/editing/remove_node_preserving_children_command.h: + (khtml::RemoveNodePreservingChildrenCommand::~RemoveNodePreservingChildrenCommand): + (khtml::RemoveNodePreservingChildrenCommand::node): + * khtml/editing/replace_selection_command.cpp: + (khtml::ReplacementFragment::ReplacementFragment): + (khtml::ReplacementFragment::~ReplacementFragment): + (khtml::ReplacementFragment::enclosingBlock): + (khtml::ReplacementFragment::removeNodePreservingChildren): + (khtml::ReplacementFragment::removeNode): + (khtml::ReplacementFragment::insertFragmentForTestRendering): + (khtml::ReplacementFragment::restoreTestRenderingNodesToFragment): + (khtml::ReplaceSelectionCommand::fixupNodeStyles): + (khtml::computeAndStoreNodeDesiredStyle): + (khtml::NodeDesiredStyle::NodeDesiredStyle): + (khtml::ReplaceSelectionCommand::ReplaceSelectionCommand): + (khtml::ReplaceSelectionCommand::~ReplaceSelectionCommand): + (khtml::ReplaceSelectionCommand::doApply): + (khtml::ReplaceSelectionCommand::completeHTMLReplacement): + (khtml::ReplaceSelectionCommand::updateNodesInserted): + * khtml/editing/replace_selection_command.h: + (khtml::NodeDesiredStyle::node): + (khtml::NodeDesiredStyle::style): + (khtml::ReplacementFragment::root): + * khtml/editing/set_node_attribute_command.cpp: + (khtml::SetNodeAttributeCommand::SetNodeAttributeCommand): + * khtml/editing/set_node_attribute_command.h: + (khtml::SetNodeAttributeCommand::~SetNodeAttributeCommand): + (khtml::SetNodeAttributeCommand::element): + * khtml/editing/split_element_command.cpp: + (khtml::SplitElementCommand::SplitElementCommand): + (khtml::SplitElementCommand::doApply): + (khtml::SplitElementCommand::doUnapply): + * khtml/editing/split_element_command.h: + (khtml::SplitElementCommand::~SplitElementCommand): + * khtml/editing/split_text_node_command.cpp: + (khtml::SplitTextNodeCommand::SplitTextNodeCommand): + (khtml::SplitTextNodeCommand::doApply): + (khtml::SplitTextNodeCommand::doUnapply): + * khtml/editing/split_text_node_command.h: + (khtml::SplitTextNodeCommand::~SplitTextNodeCommand): + (khtml::SplitTextNodeCommand::node): + * khtml/editing/split_text_node_containing_element.cpp: + (khtml::SplitTextNodeContainingElementCommand::SplitTextNodeContainingElementCommand): + (khtml::SplitTextNodeContainingElementCommand::doApply): + * khtml/editing/split_text_node_containing_element_command.h: + (khtml::SplitTextNodeContainingElementCommand::~SplitTextNodeContainingElementCommand): + * khtml/editing/visible_position.cpp: + (khtml::makeRange): + * khtml/editing/visible_position.h: + * khtml/editing/visible_text.cpp: + (khtml::TextIterator::range): + (khtml::SimplifiedBackwardsTextIterator::range): + (khtml::CharacterIterator::range): + (khtml::findPlainText): + * khtml/editing/visible_text.h: + (khtml::WordAwareIterator::range): + * khtml/editing/wrap_contents_in_dummy_span_command.cpp: + (khtml::WrapContentsInDummySpanCommand::WrapContentsInDummySpanCommand): + (khtml::WrapContentsInDummySpanCommand::doApply): + (khtml::WrapContentsInDummySpanCommand::doUnapply): + * khtml/editing/wrap_contents_in_dummy_span_command.h: + (khtml::WrapContentsInDummySpanCommand::~WrapContentsInDummySpanCommand): + * kwq/DOMHTML.mm: + (-[DOMHTMLDocument _createDocumentFragmentWithMarkupString:baseURLString:]): + (-[DOMHTMLDocument _createDocumentFragmentWithText:]): + * kwq/WebCoreBridge.mm: + (-[WebCoreBridge documentFragmentWithMarkupString:baseURLString:]): + (-[WebCoreBridge documentFragmentWithText:]): + (-[WebCoreBridge documentFragmentWithNodesAsParagraphs:]): + 2006-01-03 Anders Carlsson Reviewed by Darin. diff --git a/WebCore/khtml/editing/SelectionController.cpp b/WebCore/khtml/editing/SelectionController.cpp index 4199f0f4319..a667fa97555 100644 --- a/WebCore/khtml/editing/SelectionController.cpp +++ b/WebCore/khtml/editing/SelectionController.cpp @@ -601,10 +601,10 @@ void SelectionController::setNeedsLayout(bool flag) m_needsLayout = flag; } -RefPtr SelectionController::toRange() const +PassRefPtr SelectionController::toRange() const { if (isNone()) - return RefPtr(); + return 0; // Make sure we have an updated layout since this function is called // in the course of running edit commands which modify the DOM. @@ -647,16 +647,16 @@ RefPtr SelectionController::toRange() const } int exceptionCode = 0; - RefPtr result(new RangeImpl(s.node()->getDocument())); + PassRefPtr result(new RangeImpl(s.node()->getDocument())); result->setStart(s.node(), s.offset(), exceptionCode); if (exceptionCode) { ERROR("Exception setting Range start from SelectionController: %d", exceptionCode); - return RefPtr(); + return 0; } result->setEnd(e.node(), e.offset(), exceptionCode); if (exceptionCode) { ERROR("Exception setting Range end from SelectionController: %d", exceptionCode); - return RefPtr(); + return 0; } return result; } diff --git a/WebCore/khtml/editing/SelectionController.h b/WebCore/khtml/editing/SelectionController.h index 0c21ff2a4e2..0e5c99c3028 100644 --- a/WebCore/khtml/editing/SelectionController.h +++ b/WebCore/khtml/editing/SelectionController.h @@ -27,6 +27,7 @@ #define KHTML_EDITING_SELECTION_H #include +#include #include "xml/dom_position.h" #include "text_granularity.h" #include "misc/shared.h" @@ -105,7 +106,7 @@ public: bool isRange() const { return state() == RANGE; } bool isCaretOrRange() const { return state() != NONE; } - RefPtr toRange() const; + PassRefPtr toRange() const; void debugPosition() const; void debugRenderer(khtml::RenderObject *r, bool selected) const; diff --git a/WebCore/khtml/editing/append_node_command.cpp b/WebCore/khtml/editing/append_node_command.cpp index 4c015327939..f8fd80a5c09 100644 --- a/WebCore/khtml/editing/append_node_command.cpp +++ b/WebCore/khtml/editing/append_node_command.cpp @@ -39,19 +39,7 @@ AppendNodeCommand::AppendNodeCommand(DocumentImpl *document, NodeImpl *appendChi : EditCommand(document), m_appendChild(appendChild), m_parentNode(parentNode) { ASSERT(m_appendChild); - m_appendChild->ref(); - - ASSERT(m_parentNode); - m_parentNode->ref(); -} - -AppendNodeCommand::~AppendNodeCommand() -{ - ASSERT(m_appendChild); - m_appendChild->deref(); - ASSERT(m_parentNode); - m_parentNode->deref(); } void AppendNodeCommand::doApply() @@ -60,7 +48,7 @@ void AppendNodeCommand::doApply() ASSERT(m_parentNode); int exceptionCode = 0; - m_parentNode->appendChild(m_appendChild, exceptionCode); + m_parentNode->appendChild(m_appendChild.get(), exceptionCode); ASSERT(exceptionCode == 0); } @@ -71,7 +59,7 @@ void AppendNodeCommand::doUnapply() ASSERT(state() == Applied); int exceptionCode = 0; - m_parentNode->removeChild(m_appendChild, exceptionCode); + m_parentNode->removeChild(m_appendChild.get(), exceptionCode); ASSERT(exceptionCode == 0); } diff --git a/WebCore/khtml/editing/append_node_command.h b/WebCore/khtml/editing/append_node_command.h index bac20732a48..a915034055d 100644 --- a/WebCore/khtml/editing/append_node_command.h +++ b/WebCore/khtml/editing/append_node_command.h @@ -38,17 +38,17 @@ class AppendNodeCommand : public EditCommand { public: AppendNodeCommand(DOM::DocumentImpl *, DOM::NodeImpl *appendChild, DOM::NodeImpl *parentNode); - virtual ~AppendNodeCommand(); + virtual ~AppendNodeCommand() { } virtual void doApply(); virtual void doUnapply(); - DOM::NodeImpl *appendChild() const { return m_appendChild; } - DOM::NodeImpl *parentNode() const { return m_parentNode; } + DOM::NodeImpl *appendChild() const { return m_appendChild.get(); } + DOM::NodeImpl *parentNode() const { return m_parentNode.get(); } private: - DOM::NodeImpl *m_appendChild; - DOM::NodeImpl *m_parentNode; + RefPtr m_appendChild; + RefPtr m_parentNode; }; } // namespace khtml diff --git a/WebCore/khtml/editing/apply_style_command.cpp b/WebCore/khtml/editing/apply_style_command.cpp index 5e7bf3142ca..caa46431be9 100644 --- a/WebCore/khtml/editing/apply_style_command.cpp +++ b/WebCore/khtml/editing/apply_style_command.cpp @@ -90,7 +90,7 @@ public: bool usesLegacyStyles() const { return m_usesLegacyStyles; } private: - void init(CSSStyleDeclarationImpl *, const Position &); + void init(PassRefPtr, const Position &); bool checkForLegacyHTMLStyleChange(const CSSProperty *); static bool currentlyHasStyle(const Position &, const CSSProperty *); @@ -117,13 +117,11 @@ StyleChange::StyleChange(CSSStyleDeclarationImpl *style, const Position &positio init(style, position); } -void StyleChange::init(CSSStyleDeclarationImpl *style, const Position &position) +void StyleChange::init(PassRefPtr style, const Position &position) { - style->ref(); RefPtr mutableStyle = style->makeMutable(); - style->deref(); - QString styleText(""); + DOMString styleText(""); QValueListConstIterator end; for (QValueListConstIterator it = mutableStyle->valuesIterator(); it != end; ++it) { @@ -143,14 +141,13 @@ void StyleChange::init(CSSStyleDeclarationImpl *style, const Position &position) if (property->id() == CSS_PROP__KHTML_TEXT_DECORATIONS_IN_EFFECT) { // we have to special-case text decorations CSSProperty alteredProperty = CSSProperty(CSS_PROP_TEXT_DECORATION, property->value(), property->isImportant()); - styleText += alteredProperty.cssText().qstring(); - } else { - styleText += property->cssText().qstring(); - } + styleText += alteredProperty.cssText(); + } else + styleText += property->cssText(); } // Save the result for later - m_cssStyle = styleText.stripWhiteSpace(); + m_cssStyle = styleText.qstring().stripWhiteSpace(); } StyleChange::ELegacyHTMLStyles StyleChange::styleModeForParseMode(bool isQuirksMode) @@ -876,7 +873,7 @@ static int maxRangeOffset(NodeImpl *n) return 1; } -void ApplyStyleCommand::removeInlineStyle(CSSMutableStyleDeclarationImpl *style, const Position &start, const Position &end) +void ApplyStyleCommand::removeInlineStyle(PassRefPtr style, const Position &start, const Position &end) { ASSERT(start.isNotNull()); ASSERT(end.isNotNull()); @@ -905,12 +902,12 @@ void ApplyStyleCommand::removeInlineStyle(CSSMutableStyleDeclarationImpl *style, HTMLElementImpl *elem = static_cast(node); NodeImpl *prev = elem->traversePreviousNodePostOrder(); NodeImpl *next = elem->traverseNextNode(); - if (isHTMLStyleNode(style, elem)) { + if (isHTMLStyleNode(style.get(), elem)) { removeHTMLStyleNode(elem); } else { - removeHTMLFontStyle(style, elem); - removeCSSStyle(style, elem); + removeHTMLFontStyle(style.get(), elem); + removeCSSStyle(style.get(), elem); } if (!elem->inDocument()) { if (s.node() == elem) { @@ -932,11 +929,6 @@ void ApplyStyleCommand::removeInlineStyle(CSSMutableStyleDeclarationImpl *style, break; node = next; } - - - if (textDecorationSpecialProperty) { - style->deref(); - } ASSERT(s.node()->inDocument()); ASSERT(e.node()->inDocument()); diff --git a/WebCore/khtml/editing/apply_style_command.h b/WebCore/khtml/editing/apply_style_command.h index e360f79b201..4e06f267e6a 100644 --- a/WebCore/khtml/editing/apply_style_command.h +++ b/WebCore/khtml/editing/apply_style_command.h @@ -27,6 +27,7 @@ #define __apply_style_command_h__ #include "composite_edit_command.h" +#include namespace DOM { class HTMLElementImpl; @@ -55,7 +56,7 @@ private: void removeHTMLFontStyle(DOM::CSSMutableStyleDeclarationImpl *, DOM::HTMLElementImpl *); void removeCSSStyle(DOM::CSSMutableStyleDeclarationImpl *, DOM::HTMLElementImpl *); void removeBlockStyle(DOM::CSSMutableStyleDeclarationImpl *, const DOM::Position &start, const DOM::Position &end); - void removeInlineStyle(DOM::CSSMutableStyleDeclarationImpl *, const DOM::Position &start, const DOM::Position &end); + void removeInlineStyle(PassRefPtr, const DOM::Position &start, const DOM::Position &end); bool nodeFullySelected(DOM::NodeImpl *, const DOM::Position &start, const DOM::Position &end) const; bool nodeFullyUnselected(DOM::NodeImpl *node, const DOM::Position &start, const DOM::Position &end) const; DOM::CSSMutableStyleDeclarationImpl *extractTextDecorationStyle(DOM::NodeImpl *node); diff --git a/WebCore/khtml/editing/composite_edit_command.cpp b/WebCore/khtml/editing/composite_edit_command.cpp index a4885ba5730..3fec797abec 100644 --- a/WebCore/khtml/editing/composite_edit_command.cpp +++ b/WebCore/khtml/editing/composite_edit_command.cpp @@ -380,7 +380,7 @@ void CompositeEditCommand::deleteInsignificantText(TextImpl *textNode, int start int removed = 0; InlineTextBox *prevBox = 0; - DOMStringImpl *str = 0; + RefPtr str; // This loop structure works to process all gaps preceding a box, // and also will look at the gap after the last box. @@ -396,10 +396,8 @@ void CompositeEditCommand::deleteInsignificantText(TextImpl *textNode, int start if (indicesIntersect && gapLen > 0) { gapStart = kMax(gapStart, start); gapEnd = kMin(gapEnd, end); - if (!str) { + if (!str) str = textNode->string()->substring(start, end - start); - str->ref(); - } // remove text in the gap str->remove(gapStart - start - removed, gapLen); removed += gapLen; @@ -413,7 +411,7 @@ void CompositeEditCommand::deleteInsignificantText(TextImpl *textNode, int start if (str) { // Replace the text between start and end with our pruned version. if (str->l > 0) { - replaceTextInNode(textNode, start, end - start, str); + replaceTextInNode(textNode, start, end - start, str.get()); } else { // Assert that we are not going to delete all of the text in the node. @@ -422,7 +420,6 @@ void CompositeEditCommand::deleteInsignificantText(TextImpl *textNode, int start ASSERT(start > 0 || (unsigned)end - start < textNode->length()); deleteTextFromNode(textNode, start, end - start); } - str->deref(); } } diff --git a/WebCore/khtml/editing/delete_from_text_node_command.cpp b/WebCore/khtml/editing/delete_from_text_node_command.cpp index 9dd6296030b..ff81adb6cef 100644 --- a/WebCore/khtml/editing/delete_from_text_node_command.cpp +++ b/WebCore/khtml/editing/delete_from_text_node_command.cpp @@ -42,14 +42,6 @@ DeleteFromTextNodeCommand::DeleteFromTextNodeCommand(DocumentImpl *document, Tex ASSERT(m_offset >= 0); ASSERT(m_offset < (int)m_node->length()); ASSERT(m_count >= 0); - - m_node->ref(); -} - -DeleteFromTextNodeCommand::~DeleteFromTextNodeCommand() -{ - ASSERT(m_node); - m_node->deref(); } void DeleteFromTextNodeCommand::doApply() diff --git a/WebCore/khtml/editing/delete_from_text_node_command.h b/WebCore/khtml/editing/delete_from_text_node_command.h index fc893460916..aeadc98a9a7 100644 --- a/WebCore/khtml/editing/delete_from_text_node_command.h +++ b/WebCore/khtml/editing/delete_from_text_node_command.h @@ -40,17 +40,17 @@ class DeleteFromTextNodeCommand : public EditCommand { public: DeleteFromTextNodeCommand(DOM::DocumentImpl *document, DOM::TextImpl *node, int offset, int count); - virtual ~DeleteFromTextNodeCommand(); + virtual ~DeleteFromTextNodeCommand() { } virtual void doApply(); virtual void doUnapply(); - DOM::TextImpl *node() const { return m_node; } + DOM::TextImpl *node() const { return m_node.get(); } int offset() const { return m_offset; } int count() const { return m_count; } private: - DOM::TextImpl *m_node; + RefPtr m_node; int m_offset; int m_count; DOM::DOMString m_text; diff --git a/WebCore/khtml/editing/delete_selection_command.cpp b/WebCore/khtml/editing/delete_selection_command.cpp index 4dac84fb024..6a3e6580557 100644 --- a/WebCore/khtml/editing/delete_selection_command.cpp +++ b/WebCore/khtml/editing/delete_selection_command.cpp @@ -204,11 +204,8 @@ void DeleteSelectionCommand::initializePositionData() // Handle setting start and end blocks and the start node. // m_startBlock = m_downstreamStart.node()->enclosingBlockFlowElement(); - m_startBlock->ref(); m_endBlock = m_upstreamEnd.node()->enclosingBlockFlowElement(); - m_endBlock->ref(); m_startNode = m_upstreamStart.node(); - m_startNode->ref(); // // Handle detecting if the line containing the selection end is itself fully selected. @@ -227,9 +224,9 @@ void DeleteSelectionCommand::initializePositionData() debugPosition("m_downstreamEnd ", m_downstreamEnd); debugPosition("m_leadingWhitespace ", m_leadingWhitespace); debugPosition("m_trailingWhitespace ", m_trailingWhitespace); - debugNode( "m_startBlock ", m_startBlock); - debugNode( "m_endBlock ", m_endBlock); - debugNode( "m_startNode ", m_startNode); + debugNode( "m_startBlock ", m_startBlock.get()); + debugNode( "m_endBlock ", m_endBlock.get()); + debugNode( "m_startNode ", m_startNode.get()); } void DeleteSelectionCommand::insertPlaceholderForAncestorBlockContent() @@ -272,20 +269,14 @@ void DeleteSelectionCommand::saveTypingStyleState() // Figure out the typing style in effect before the delete is done. // FIXME: Improve typing style. // See this bug: Implementation of typing style needs improvement - CSSComputedStyleDeclarationImpl *computedStyle = positionBeforeTabSpan(m_selectionToDelete.start()).computedStyle(); - computedStyle->ref(); + RefPtr computedStyle = positionBeforeTabSpan(m_selectionToDelete.start()).computedStyle(); m_typingStyle = computedStyle->copyInheritableProperties(); - m_typingStyle->ref(); - computedStyle->deref(); // If we're deleting into a Mail blockquote, save the style at end() instead of start() // We'll use this later in computeTypingStyleAfterDelete if we end up outside of a Mail blockquote if (nearestMailBlockquote(m_selectionToDelete.start().node())) { computedStyle = m_selectionToDelete.end().computedStyle(); - computedStyle->ref(); m_deleteIntoBlockquoteStyle = computedStyle->copyInheritableProperties(); - m_deleteIntoBlockquoteStyle->ref(); - computedStyle->deref(); } else m_deleteIntoBlockquoteStyle = 0; } @@ -312,16 +303,6 @@ bool DeleteSelectionCommand::handleSpecialCaseBRDelete() return false; } -void DeleteSelectionCommand::setStartNode(NodeImpl *node) -{ - NodeImpl *old = m_startNode; - m_startNode = node; - if (m_startNode) - m_startNode->ref(); - if (old) - old->deref(); -} - void DeleteSelectionCommand::handleGeneralDelete() { int startOffset = m_upstreamStart.offset(); @@ -343,13 +324,13 @@ void DeleteSelectionCommand::handleGeneralDelete() // end of a block other than the block containing the selection start, then do not delete the // start block, otherwise delete the start block. if (startOffset == 1 && m_startNode && m_startNode->hasTagName(brTag)) { - setStartNode(m_startNode->traverseNextNode()); + m_startNode = m_startNode->traverseNextNode(); startOffset = 0; } if (m_startBlock != m_endBlock && isStartOfBlock(VisiblePosition(m_upstreamStart, m_selectionToDelete.startAffinity()))) { - if (!m_startBlock->isAncestor(m_endBlock) && !isStartOfBlock(visibleEnd) && endAtEndOfBlock) { + if (!m_startBlock->isAncestor(m_endBlock.get()) && !isStartOfBlock(visibleEnd) && endAtEndOfBlock) { // Delete all the children of the block, but not the block itself. - setStartNode(m_startBlock->firstChild()); + m_startNode = m_startBlock->firstChild(); startOffset = 0; } } @@ -362,13 +343,13 @@ void DeleteSelectionCommand::handleGeneralDelete() // Also, before moving on, delete any insignificant text that may be present in a text node. if (m_startNode->isTextNode()) { // Delete any insignificant text from this node. - TextImpl *text = static_cast(m_startNode); + TextImpl *text = static_cast(m_startNode.get()); if (text->length() > (unsigned)m_startNode->caretMaxOffset()) deleteTextFromNode(text, m_startNode->caretMaxOffset(), text->length() - m_startNode->caretMaxOffset()); } // shift the start node to the next - setStartNode(m_startNode->traverseNextNode()); + m_startNode = m_startNode->traverseNextNode(); startOffset = 0; } @@ -379,24 +360,24 @@ void DeleteSelectionCommand::handleGeneralDelete() if (m_startNode == m_downstreamEnd.node()) { // The selection to delete is all in one node. if (!m_startNode->renderer() || - (startOffset == 0 && m_downstreamEnd.offset() >= maxDeepOffset(m_startNode))) { + (startOffset == 0 && m_downstreamEnd.offset() >= maxDeepOffset(m_startNode.get()))) { // just delete - removeFullySelectedNode(m_startNode); + removeFullySelectedNode(m_startNode.get()); } else if (m_downstreamEnd.offset() - startOffset > 0) { if (m_startNode->isTextNode()) { // in a text node that needs to be trimmed - TextImpl *text = static_cast(m_startNode); + TextImpl *text = static_cast(m_startNode.get()); deleteTextFromNode(text, startOffset, m_downstreamEnd.offset() - startOffset); m_trailingWhitespaceValid = false; } else { - removeChildrenInRange(m_startNode, startOffset, m_downstreamEnd.offset()); + removeChildrenInRange(m_startNode.get(), startOffset, m_downstreamEnd.offset()); m_endingPosition = m_upstreamStart; } } } else { // The selection to delete spans more than one node. - NodeImpl *node = m_startNode; + NodeImpl *node = m_startNode.get(); if (startOffset > 0) { if (m_startNode->isTextNode()) { @@ -614,11 +595,11 @@ void DeleteSelectionCommand::calculateEndingPosition() if (m_endingPosition.node()->inDocument()) return; - m_endingPosition = Position(m_startBlock, 0); + m_endingPosition = Position(m_startBlock.get(), 0); if (m_endingPosition.node()->inDocument()) return; - m_endingPosition = Position(m_endBlock, 0); + m_endingPosition = Position(m_endBlock.get(), 0); if (m_endingPosition.node()->inDocument()) return; @@ -635,25 +616,15 @@ void DeleteSelectionCommand::calculateTypingStyleAfterDelete(NodeImpl *insertedP // FIXME: Improve typing style. // See this bug: Implementation of typing style needs improvement - if (m_deleteIntoBlockquoteStyle) { - // If we deleted into a blockquote, but are now no longer in a blockquote, use the alternate typing style - if (!nearestMailBlockquote(m_endingPosition.node())) { - CSSMutableStyleDeclarationImpl *oldStyle = m_typingStyle; - m_typingStyle = m_deleteIntoBlockquoteStyle; - m_deleteIntoBlockquoteStyle = 0; - oldStyle->deref(); - } else { - m_deleteIntoBlockquoteStyle->deref(); - m_deleteIntoBlockquoteStyle = 0; - } - } + // If we deleted into a blockquote, but are now no longer in a blockquote, use the alternate typing style + if (m_deleteIntoBlockquoteStyle && !nearestMailBlockquote(m_endingPosition.node())) + m_typingStyle = m_deleteIntoBlockquoteStyle; + m_deleteIntoBlockquoteStyle = 0; - CSSComputedStyleDeclarationImpl endingStyle(m_endingPosition.node()); - endingStyle.diff(m_typingStyle); - if (!m_typingStyle->length()) { - m_typingStyle->deref(); + RefPtr endingStyle = new CSSComputedStyleDeclarationImpl(m_endingPosition.node()); + endingStyle->diff(m_typingStyle.get()); + if (!m_typingStyle->length()) m_typingStyle = 0; - } if (insertedPlaceholder && m_typingStyle) { // Apply style to the placeholder. This makes sure that the single line in the // paragraph has the right height, and that the paragraph takes on the style @@ -662,15 +633,13 @@ void DeleteSelectionCommand::calculateTypingStyleAfterDelete(NodeImpl *insertedP // is not retained until the next typing action. setEndingSelection(SelectionController(Position(insertedPlaceholder, 0), DOWNSTREAM)); - applyStyle(m_typingStyle, EditActionUnspecified); - - m_typingStyle->deref(); + applyStyle(m_typingStyle.get(), EditActionUnspecified); m_typingStyle = 0; } // Set m_typingStyle as the typing style. // It's perfectly OK for m_typingStyle to be null. - document()->part()->setTypingStyle(m_typingStyle); - setTypingStyle(m_typingStyle); + document()->part()->setTypingStyle(m_typingStyle.get()); + setTypingStyle(m_typingStyle.get()); } void DeleteSelectionCommand::clearTransientState() @@ -683,27 +652,6 @@ void DeleteSelectionCommand::clearTransientState() m_endingPosition.clear(); m_leadingWhitespace.clear(); m_trailingWhitespace.clear(); - - if (m_startBlock) { - m_startBlock->deref(); - m_startBlock = 0; - } - if (m_endBlock) { - m_endBlock->deref(); - m_endBlock = 0; - } - if (m_startNode) { - m_startNode->deref(); - m_startNode = 0; - } - if (m_typingStyle) { - m_typingStyle->deref(); - m_typingStyle = 0; - } - if (m_deleteIntoBlockquoteStyle) { - m_deleteIntoBlockquoteStyle->deref(); - m_deleteIntoBlockquoteStyle = 0; - } } void DeleteSelectionCommand::doApply() diff --git a/WebCore/khtml/editing/delete_selection_command.h b/WebCore/khtml/editing/delete_selection_command.h index a6058779a2c..7f147387a1e 100644 --- a/WebCore/khtml/editing/delete_selection_command.h +++ b/WebCore/khtml/editing/delete_selection_command.h @@ -53,8 +53,6 @@ private: void calculateTypingStyleAfterDelete(DOM::NodeImpl *insertedPlaceholder); void clearTransientState(); - void setStartNode(DOM::NodeImpl *); - bool m_hasSelectionToDelete; bool m_smartDelete; bool m_mergeBlocksAfterDelete; @@ -69,11 +67,11 @@ private: DOM::Position m_endingPosition; DOM::Position m_leadingWhitespace; DOM::Position m_trailingWhitespace; - DOM::NodeImpl *m_startBlock; - DOM::NodeImpl *m_endBlock; - DOM::NodeImpl *m_startNode; - DOM::CSSMutableStyleDeclarationImpl *m_typingStyle; - DOM::CSSMutableStyleDeclarationImpl *m_deleteIntoBlockquoteStyle; + RefPtr m_startBlock; + RefPtr m_endBlock; + RefPtr m_startNode; + RefPtr m_typingStyle; + RefPtr m_deleteIntoBlockquoteStyle; }; } // namespace khtml diff --git a/WebCore/khtml/editing/edit_command.cpp b/WebCore/khtml/editing/edit_command.cpp index 0ce88f52658..9eb349b2b76 100644 --- a/WebCore/khtml/editing/edit_command.cpp +++ b/WebCore/khtml/editing/edit_command.cpp @@ -59,20 +59,6 @@ EditCommandPtr::EditCommandPtr(EditCommand *impl) : RefPtr(impl) { } -EditCommandPtr::EditCommandPtr(const EditCommandPtr &o) : RefPtr(o) -{ -} - -EditCommandPtr::~EditCommandPtr() -{ -} - -EditCommandPtr &EditCommandPtr::operator=(const EditCommandPtr &c) -{ - static_cast &>(*this) = c; - return *this; -} - bool EditCommandPtr::isCompositeStep() const { IF_IMPL_NULL_RETURN_ARG(false); @@ -202,21 +188,16 @@ EditCommandPtr &EditCommandPtr::emptyCommand() } EditCommand::EditCommand(DocumentImpl *document) - : m_document(document), m_state(NotApplied), m_typingStyle(0), m_parent(0) + : m_document(document), m_state(NotApplied), m_parent(0) { ASSERT(m_document); ASSERT(m_document->part()); - m_document->ref(); m_startingSelection = m_document->part()->selection(); m_endingSelection = m_startingSelection; } EditCommand::~EditCommand() { - ASSERT(m_document); - m_document->deref(); - if (m_typingStyle) - m_typingStyle->deref(); } void EditCommand::apply() @@ -335,25 +316,12 @@ void EditCommand::setEndingSelection(const Position &p, EAffinity affinity) cmd->m_endingSelection = s; } -void EditCommand::assignTypingStyle(CSSMutableStyleDeclarationImpl *style) -{ - if (m_typingStyle == style) - return; - - CSSMutableStyleDeclarationImpl *old = m_typingStyle; - m_typingStyle = style; - if (m_typingStyle) - m_typingStyle->ref(); - if (old) - old->deref(); -} - void EditCommand::setTypingStyle(CSSMutableStyleDeclarationImpl *style) { // FIXME: Improve typing style. // See this bug: Implementation of typing style needs improvement for (EditCommand *cmd = this; cmd; cmd = cmd->m_parent) - cmd->assignTypingStyle(style); + cmd->m_typingStyle = style; } bool EditCommand::preservesTypingStyle() const @@ -373,10 +341,8 @@ bool EditCommand::isTypingCommand() const CSSMutableStyleDeclarationImpl *EditCommand::styleAtPosition(const Position &pos) { - CSSComputedStyleDeclarationImpl *computedStyle = positionBeforeTabSpan(pos).computedStyle(); - computedStyle->ref(); + RefPtr computedStyle = positionBeforeTabSpan(pos).computedStyle(); CSSMutableStyleDeclarationImpl *style = computedStyle->copyInheritableProperties(); - computedStyle->deref(); // FIXME: Improve typing style. // See this bug: Implementation of typing style needs improvement diff --git a/WebCore/khtml/editing/edit_command.h b/WebCore/khtml/editing/edit_command.h index b57200df57f..8f8ae997159 100644 --- a/WebCore/khtml/editing/edit_command.h +++ b/WebCore/khtml/editing/edit_command.h @@ -62,7 +62,7 @@ public: virtual EditAction editingAction() const; - virtual DOM::DocumentImpl * const document() const { return m_document; } + virtual DOM::DocumentImpl * const document() const { return m_document.get(); } SelectionController startingSelection() const { return m_startingSelection; } SelectionController endingSelection() const { return m_endingSelection; } @@ -79,7 +79,7 @@ public: void setEndingSelection(const VisiblePosition &p); void setEndingSelection(const DOM::Position &p, EAffinity affinity); - DOM::CSSMutableStyleDeclarationImpl *typingStyle() const { return m_typingStyle; }; + DOM::CSSMutableStyleDeclarationImpl *typingStyle() const { return m_typingStyle.get(); }; void setTypingStyle(DOM::CSSMutableStyleDeclarationImpl *); DOM::CSSMutableStyleDeclarationImpl *styleAtPosition(const DOM::Position &pos); @@ -90,15 +90,13 @@ public: void updateLayout() const; private: - void assignTypingStyle(DOM::CSSMutableStyleDeclarationImpl *); - virtual bool preservesTypingStyle() const; - DOM::DocumentImpl *m_document; + RefPtr m_document; ECommandState m_state; SelectionController m_startingSelection; SelectionController m_endingSelection; - DOM::CSSMutableStyleDeclarationImpl *m_typingStyle; + RefPtr m_typingStyle; EditCommand *m_parent; }; @@ -107,10 +105,6 @@ class EditCommandPtr : public RefPtr public: EditCommandPtr(); EditCommandPtr(EditCommand *); - EditCommandPtr(const EditCommandPtr &); - ~EditCommandPtr(); - - EditCommandPtr &operator=(const EditCommandPtr &); bool isCompositeStep() const; diff --git a/WebCore/khtml/editing/insert_into_text_node_command.cpp b/WebCore/khtml/editing/insert_into_text_node_command.cpp index d034281b2da..2a729915074 100644 --- a/WebCore/khtml/editing/insert_into_text_node_command.cpp +++ b/WebCore/khtml/editing/insert_into_text_node_command.cpp @@ -43,16 +43,9 @@ InsertIntoTextNodeCommand::InsertIntoTextNodeCommand(DocumentImpl *document, Tex ASSERT(m_offset >= 0); ASSERT(!text.isEmpty()); - m_node->ref(); m_text = text.copy(); // make a copy to ensure that the string never changes } -InsertIntoTextNodeCommand::~InsertIntoTextNodeCommand() -{ - if (m_node) - m_node->deref(); -} - void InsertIntoTextNodeCommand::doApply() { ASSERT(m_node); diff --git a/WebCore/khtml/editing/insert_into_text_node_command.h b/WebCore/khtml/editing/insert_into_text_node_command.h index b95c6c1cfad..048d2f63a7c 100644 --- a/WebCore/khtml/editing/insert_into_text_node_command.h +++ b/WebCore/khtml/editing/insert_into_text_node_command.h @@ -41,17 +41,17 @@ class InsertIntoTextNodeCommand : public EditCommand { public: InsertIntoTextNodeCommand(DOM::DocumentImpl *document, DOM::TextImpl *, int, const DOM::DOMString &); - virtual ~InsertIntoTextNodeCommand(); + virtual ~InsertIntoTextNodeCommand() { } virtual void doApply(); virtual void doUnapply(); - DOM::TextImpl *node() const { return m_node; } + DOM::TextImpl *node() const { return m_node.get(); } int offset() const { return m_offset; } DOM::DOMString text() const { return m_text; } private: - DOM::TextImpl *m_node; + RefPtr m_node; int m_offset; DOM::DOMString m_text; }; diff --git a/WebCore/khtml/editing/insert_node_before_command.cpp b/WebCore/khtml/editing/insert_node_before_command.cpp index eb07385626d..7332c5733d7 100644 --- a/WebCore/khtml/editing/insert_node_before_command.cpp +++ b/WebCore/khtml/editing/insert_node_before_command.cpp @@ -39,19 +39,7 @@ InsertNodeBeforeCommand::InsertNodeBeforeCommand(DocumentImpl *document, NodeImp : EditCommand(document), m_insertChild(insertChild), m_refChild(refChild) { ASSERT(m_insertChild); - m_insertChild->ref(); - - ASSERT(m_refChild); - m_refChild->ref(); -} - -InsertNodeBeforeCommand::~InsertNodeBeforeCommand() -{ - ASSERT(m_insertChild); - m_insertChild->deref(); - ASSERT(m_refChild); - m_refChild->deref(); } void InsertNodeBeforeCommand::doApply() @@ -61,7 +49,7 @@ void InsertNodeBeforeCommand::doApply() ASSERT(m_refChild->parentNode()); int exceptionCode = 0; - m_refChild->parentNode()->insertBefore(m_insertChild, m_refChild, exceptionCode); + m_refChild->parentNode()->insertBefore(m_insertChild.get(), m_refChild.get(), exceptionCode); ASSERT(exceptionCode == 0); } @@ -72,7 +60,7 @@ void InsertNodeBeforeCommand::doUnapply() ASSERT(m_refChild->parentNode()); int exceptionCode = 0; - m_refChild->parentNode()->removeChild(m_insertChild, exceptionCode); + m_refChild->parentNode()->removeChild(m_insertChild.get(), exceptionCode); ASSERT(exceptionCode == 0); } diff --git a/WebCore/khtml/editing/insert_node_before_command.h b/WebCore/khtml/editing/insert_node_before_command.h index df6f42b222d..32c573e5da2 100644 --- a/WebCore/khtml/editing/insert_node_before_command.h +++ b/WebCore/khtml/editing/insert_node_before_command.h @@ -34,17 +34,17 @@ class InsertNodeBeforeCommand : public EditCommand { public: InsertNodeBeforeCommand(DOM::DocumentImpl *, DOM::NodeImpl *insertChild, DOM::NodeImpl *refChild); - virtual ~InsertNodeBeforeCommand(); + virtual ~InsertNodeBeforeCommand() { } virtual void doApply(); virtual void doUnapply(); - DOM::NodeImpl *insertChild() const { return m_insertChild; } - DOM::NodeImpl *refChild() const { return m_refChild; } + DOM::NodeImpl *insertChild() const { return m_insertChild.get(); } + DOM::NodeImpl *refChild() const { return m_refChild.get(); } private: - DOM::NodeImpl *m_insertChild; - DOM::NodeImpl *m_refChild; + RefPtr m_insertChild; + RefPtr m_refChild; }; } // namespace khtml diff --git a/WebCore/khtml/editing/insert_paragraph_separator_command.cpp b/WebCore/khtml/editing/insert_paragraph_separator_command.cpp index 74b0d10217a..071adc41736 100644 --- a/WebCore/khtml/editing/insert_paragraph_separator_command.cpp +++ b/WebCore/khtml/editing/insert_paragraph_separator_command.cpp @@ -52,15 +52,13 @@ using DOM::TextImpl; namespace khtml { InsertParagraphSeparatorCommand::InsertParagraphSeparatorCommand(DocumentImpl *document) - : CompositeEditCommand(document), m_style(0) + : CompositeEditCommand(document) { } InsertParagraphSeparatorCommand::~InsertParagraphSeparatorCommand() { derefNodesInList(clonedNodes); - if (m_style) - m_style->deref(); } bool InsertParagraphSeparatorCommand::preservesTypingStyle() const @@ -85,10 +83,7 @@ void InsertParagraphSeparatorCommand::calculateStyleBeforeInsertion(const Positi if (!isStartOfParagraph(visiblePos) && !isEndOfParagraph(visiblePos)) return; - if (m_style) - m_style->deref(); m_style = styleAtPosition(pos); - m_style->ref(); } void InsertParagraphSeparatorCommand::applyStyleAfterInsertion() @@ -99,10 +94,9 @@ void InsertParagraphSeparatorCommand::applyStyleAfterInsertion() return; CSSComputedStyleDeclarationImpl endingStyle(endingSelection().start().node()); - endingStyle.diff(m_style); - if (m_style->length() > 0) { - applyStyle(m_style); - } + endingStyle.diff(m_style.get()); + if (m_style->length() > 0) + applyStyle(m_style.get()); } void InsertParagraphSeparatorCommand::doApply() diff --git a/WebCore/khtml/editing/insert_paragraph_separator_command.h b/WebCore/khtml/editing/insert_paragraph_separator_command.h index 765e98a4cf3..899fade5bab 100644 --- a/WebCore/khtml/editing/insert_paragraph_separator_command.h +++ b/WebCore/khtml/editing/insert_paragraph_separator_command.h @@ -48,7 +48,7 @@ private: QPtrList ancestors; QPtrList clonedNodes; - DOM::CSSMutableStyleDeclarationImpl *m_style; + RefPtr m_style; }; } // namespace khtml diff --git a/WebCore/khtml/editing/join_text_nodes_command.cpp b/WebCore/khtml/editing/join_text_nodes_command.cpp index ed1a2d03136..51ff09e442e 100644 --- a/WebCore/khtml/editing/join_text_nodes_command.cpp +++ b/WebCore/khtml/editing/join_text_nodes_command.cpp @@ -44,17 +44,6 @@ JoinTextNodesCommand::JoinTextNodesCommand(DocumentImpl *document, TextImpl *tex ASSERT(m_text1->nextSibling() == m_text2); ASSERT(m_text1->length() > 0); ASSERT(m_text2->length() > 0); - - m_text1->ref(); - m_text2->ref(); -} - -JoinTextNodesCommand::~JoinTextNodesCommand() -{ - ASSERT(m_text1); - m_text1->deref(); - ASSERT(m_text2); - m_text2->deref(); } void JoinTextNodesCommand::doApply() @@ -67,7 +56,7 @@ void JoinTextNodesCommand::doApply() m_text2->insertData(0, m_text1->data(), exceptionCode); ASSERT(exceptionCode == 0); - m_text2->parentNode()->removeChild(m_text1, exceptionCode); + m_text2->parentNode()->removeChild(m_text1.get(), exceptionCode); ASSERT(exceptionCode == 0); m_offset = m_text1->length(); @@ -83,7 +72,7 @@ void JoinTextNodesCommand::doUnapply() m_text2->deleteData(0, m_offset, exceptionCode); ASSERT(exceptionCode == 0); - m_text2->parentNode()->insertBefore(m_text1, m_text2, exceptionCode); + m_text2->parentNode()->insertBefore(m_text1.get(), m_text2.get(), exceptionCode); ASSERT(exceptionCode == 0); ASSERT(m_text2->previousSibling()->isTextNode()); diff --git a/WebCore/khtml/editing/join_text_nodes_command.h b/WebCore/khtml/editing/join_text_nodes_command.h index 7fb4b24dc42..e736a50af3f 100644 --- a/WebCore/khtml/editing/join_text_nodes_command.h +++ b/WebCore/khtml/editing/join_text_nodes_command.h @@ -38,17 +38,17 @@ class JoinTextNodesCommand : public EditCommand { public: JoinTextNodesCommand(DOM::DocumentImpl *, DOM::TextImpl *, DOM::TextImpl *); - virtual ~JoinTextNodesCommand(); + virtual ~JoinTextNodesCommand() { } virtual void doApply(); virtual void doUnapply(); - DOM::TextImpl *firstNode() const { return m_text1; } - DOM::TextImpl *secondNode() const { return m_text2; } + DOM::TextImpl *firstNode() const { return m_text1.get(); } + DOM::TextImpl *secondNode() const { return m_text2.get(); } private: - DOM::TextImpl *m_text1; - DOM::TextImpl *m_text2; + RefPtr m_text1; + RefPtr m_text2; unsigned m_offset; }; diff --git a/WebCore/khtml/editing/jsediting.cpp b/WebCore/khtml/editing/jsediting.cpp index 55d1d273cbc..9f670db537f 100644 --- a/WebCore/khtml/editing/jsediting.cpp +++ b/WebCore/khtml/editing/jsediting.cpp @@ -145,11 +145,9 @@ namespace { bool execStyleChange(KHTMLPart *part, int propertyID, const DOMString &propertyValue) { - CSSMutableStyleDeclarationImpl *style = new CSSMutableStyleDeclarationImpl; + RefPtr style = new CSSMutableStyleDeclarationImpl; style->setProperty(propertyID, propertyValue); - style->ref(); - part->applyStyle(style); - style->deref(); + part->applyStyle(style.get()); return true; } @@ -160,22 +158,16 @@ bool execStyleChange(KHTMLPart *part, int propertyID, const char *propertyValue) KHTMLPart::TriState stateStyle(KHTMLPart *part, int propertyID, const char *desiredValue) { - CSSMutableStyleDeclarationImpl *style = new CSSMutableStyleDeclarationImpl; + RefPtr style = new CSSMutableStyleDeclarationImpl; style->setProperty(propertyID, desiredValue); - style->ref(); - KHTMLPart::TriState state = part->selectionHasStyle(style); - style->deref(); - return state; + return part->selectionHasStyle(style.get()); } bool selectionStartHasStyle(KHTMLPart *part, int propertyID, const char *desiredValue) { - CSSMutableStyleDeclarationImpl *style = new CSSMutableStyleDeclarationImpl; + RefPtr style = new CSSMutableStyleDeclarationImpl; style->setProperty(propertyID, desiredValue); - style->ref(); - bool hasStyle = part->selectionStartHasStyle(style); - style->deref(); - return hasStyle; + return part->selectionStartHasStyle(style.get()); } DOMString valueStyle(KHTMLPart *part, int propertyID) diff --git a/WebCore/khtml/editing/markup.cpp b/WebCore/khtml/editing/markup.cpp index bd1b02ac6a6..e4e19f42fb4 100644 --- a/WebCore/khtml/editing/markup.cpp +++ b/WebCore/khtml/editing/markup.cpp @@ -353,20 +353,15 @@ QString createMarkup(const RangeImpl *range, QPtrList *nodes, EAnnotat // calculate the "default style" for this markup Position pos(doc->documentElement(), 0); - CSSComputedStyleDeclarationImpl *computedStyle = pos.computedStyle(); - computedStyle->ref(); - CSSMutableStyleDeclarationImpl *defaultStyle = computedStyle->copyInheritableProperties(); - computedStyle->deref(); - defaultStyle->ref(); + RefPtr computedStyle = pos.computedStyle(); + RefPtr defaultStyle = computedStyle->copyInheritableProperties(); NodeImpl *startNode = range->startNode(); VisiblePosition visibleStart(range->startPosition(), VP_DEFAULT_AFFINITY); VisiblePosition visibleEnd(range->endPosition(), VP_DEFAULT_AFFINITY); if (!inSameBlock(visibleStart, visibleStart.next())) { - if (visibleStart == visibleEnd.previous()) { - defaultStyle->deref(); + if (visibleStart == visibleEnd.previous()) return interchangeNewlineString; - } markups.append(interchangeNewlineString); startNode = startNode->traverseNextNode(); } @@ -383,7 +378,7 @@ QString createMarkup(const RangeImpl *range, QPtrList *nodes, EAnnotat // Add the node to the markup. if (n->renderer()) { - markups.append(startMarkup(n, range, annotate, defaultStyle)); + markups.append(startMarkup(n, range, annotate, defaultStyle.get())); if (nodes) { nodes->append(n); } @@ -415,7 +410,7 @@ QString createMarkup(const RangeImpl *range, QPtrList *nodes, EAnnotat NodeImpl *nextParent = next->parentNode(); if (n != nextParent) { for (NodeImpl *parent = n->parent(); parent != 0 && parent != nextParent; parent = parent->parentNode()) { - markups.prepend(startMarkup(parent, range, annotate, defaultStyle)); + markups.prepend(startMarkup(parent, range, annotate, defaultStyle.get())); markups.append(endMarkup(parent)); if (nodes) { nodes->append(parent); @@ -453,7 +448,7 @@ QString createMarkup(const RangeImpl *range, QPtrList *nodes, EAnnotat break; } } - markups.prepend(startMarkup(ancestor, range, annotate, defaultStyle)); + markups.prepend(startMarkup(ancestor, range, annotate, defaultStyle.get())); markups.append(endMarkup(ancestor)); if (nodes) { nodes->append(ancestor); @@ -472,7 +467,7 @@ QString createMarkup(const RangeImpl *range, QPtrList *nodes, EAnnotat // Retain the Mail quote level by including all ancestor mail block quotes. for (NodeImpl *ancestor = commonAncestorBlock; ancestor; ancestor = ancestor->parentNode()) { if (isMailBlockquote(ancestor)) { - markups.prepend(startMarkup(ancestor, range, annotate, defaultStyle)); + markups.prepend(startMarkup(ancestor, range, annotate, defaultStyle.get())); markups.append(endMarkup(ancestor)); } } @@ -482,22 +477,21 @@ QString createMarkup(const RangeImpl *range, QPtrList *nodes, EAnnotat QString openTag = QString("cssText().qstring() + "\">"; markups.prepend(openTag); markups.append(""); - defaultStyle->deref(); return markups.join(""); } -DocumentFragmentImpl *createFragmentFromMarkup(DocumentImpl *document, const QString &markup, const QString &baseURL) +PassRefPtr createFragmentFromMarkup(DocumentImpl *document, const QString &markup, const QString &baseURL) { ASSERT(document->documentElement()->isHTMLElement()); // FIXME: What if the document element is not an HTML element? HTMLElementImpl *element = static_cast(document->documentElement()); - DocumentFragmentImpl *fragment = element->createContextualFragment(markup); + PassRefPtr fragment = element->createContextualFragment(markup); ASSERT(fragment); if (!baseURL.isEmpty() && baseURL != document->baseURL()) - completeURLs(fragment, baseURL); + completeURLs(fragment.get(), baseURL); return fragment; } @@ -552,13 +546,12 @@ static void createParagraphContentsFromString(DOM::DocumentImpl *document, Eleme } } -DOM::DocumentFragmentImpl *createFragmentFromText(DOM::DocumentImpl *document, const QString &text) +PassRefPtr createFragmentFromText(DocumentImpl *document, const QString &text) { if (!document) return 0; - DocumentFragmentImpl *fragment = document->createDocumentFragment(); - fragment->ref(); + PassRefPtr fragment = document->createDocumentFragment(); if (!text.isEmpty()) { QString string = text; @@ -572,59 +565,39 @@ DOM::DocumentFragmentImpl *createFragmentFromText(DOM::DocumentImpl *document, c list.pop_front(); int exceptionCode = 0; - ElementImpl *element; + RefPtr element; if (s.isEmpty() && list.isEmpty()) { // For last line, use the "magic BR" rather than a P. element = document->createElementNS(xhtmlNamespaceURI, "br", exceptionCode); ASSERT(exceptionCode == 0); - element->ref(); element->setAttribute(classAttr, AppleInterchangeNewline); } else { element = createDefaultParagraphElement(document); - element->ref(); - createParagraphContentsFromString(document, element, s); + createParagraphContentsFromString(document, element.get(), s); } - fragment->appendChild(element, exceptionCode); + fragment->appendChild(element.get(), exceptionCode); ASSERT(exceptionCode == 0); - element->deref(); } } - - // Trick to get the fragment back to the floating state, with 0 - // refs but not destroyed. - fragment->setParent(document); - fragment->deref(); - fragment->setParent(0); - return fragment; } -DOM::DocumentFragmentImpl *createFragmentFromNodeList(DOM::DocumentImpl *document, const QPtrList &nodeList) +PassRefPtr createFragmentFromNodeList(DocumentImpl *document, const QPtrList &nodeList) { if (!document) return 0; - DocumentFragmentImpl *fragment = document->createDocumentFragment(); - fragment->ref(); + PassRefPtr fragment = document->createDocumentFragment(); - ElementImpl *element; + RefPtr element; int exceptionCode = 0; for (QPtrListIterator i(nodeList); i.current(); ++i) { element = createDefaultParagraphElement(document); - element->ref(); element->appendChild(i.current(), exceptionCode); ASSERT(exceptionCode == 0); - fragment->appendChild(element, exceptionCode); + fragment->appendChild(element.get(), exceptionCode); ASSERT(exceptionCode == 0); - element->deref(); } - - // Trick to get the fragment back to the floating state, with 0 - // refs but not destroyed. - fragment->setParent(document); - fragment->deref(); - fragment->setParent(0); - return fragment; } diff --git a/WebCore/khtml/editing/markup.h b/WebCore/khtml/editing/markup.h index f9b31aa2b10..c856ec74162 100644 --- a/WebCore/khtml/editing/markup.h +++ b/WebCore/khtml/editing/markup.h @@ -28,14 +28,15 @@ #include #include "html_interchange.h" +#include namespace khtml { enum EChildrenOnly { IncludeNode, ChildrenOnly }; -DOM::DocumentFragmentImpl *createFragmentFromText(DOM::DocumentImpl *document, const QString &text); -DOM::DocumentFragmentImpl *createFragmentFromMarkup(DOM::DocumentImpl *document, const QString &markup, const QString &baseURL); -DOM::DocumentFragmentImpl *createFragmentFromNodeList(DOM::DocumentImpl *document, const QPtrList &nodeList); +PassRefPtr createFragmentFromText(DOM::DocumentImpl *document, const QString &text); +PassRefPtr createFragmentFromMarkup(DOM::DocumentImpl *document, const QString &markup, const QString &baseURL); +PassRefPtr createFragmentFromNodeList(DOM::DocumentImpl *document, const QPtrList &nodeList); QString createMarkup(const DOM::RangeImpl *range, QPtrList *nodes = 0, EAnnotateForInterchange = DoNotAnnotateForInterchange); diff --git a/WebCore/khtml/editing/merge_identical_elements_command.cpp b/WebCore/khtml/editing/merge_identical_elements_command.cpp index 25d2c2897a8..bf28f2eb032 100644 --- a/WebCore/khtml/editing/merge_identical_elements_command.cpp +++ b/WebCore/khtml/editing/merge_identical_elements_command.cpp @@ -37,24 +37,10 @@ using DOM::ElementImpl; namespace khtml { MergeIdenticalElementsCommand::MergeIdenticalElementsCommand(DOM::DocumentImpl *document, DOM::ElementImpl *first, DOM::ElementImpl *second) - : EditCommand(document), m_element1(first), m_element2(second), m_atChild(0) + : EditCommand(document), m_element1(first), m_element2(second) { ASSERT(m_element1); ASSERT(m_element2); - - m_element1->ref(); - m_element2->ref(); -} - -MergeIdenticalElementsCommand::~MergeIdenticalElementsCommand() -{ - if (m_atChild) - m_atChild->deref(); - - ASSERT(m_element1); - m_element1->deref(); - ASSERT(m_element2); - m_element2->deref(); } void MergeIdenticalElementsCommand::doApply() @@ -65,17 +51,15 @@ void MergeIdenticalElementsCommand::doApply() int exceptionCode = 0; - if (!m_atChild) { + if (!m_atChild) m_atChild = m_element2->firstChild(); - m_atChild->ref(); - } while (m_element1->lastChild()) { m_element2->insertBefore(m_element1->lastChild(), m_element2->firstChild(), exceptionCode); ASSERT(exceptionCode == 0); } - m_element2->parentNode()->removeChild(m_element1, exceptionCode); + m_element2->parentNode()->removeChild(m_element1.get(), exceptionCode); ASSERT(exceptionCode == 0); } @@ -86,7 +70,7 @@ void MergeIdenticalElementsCommand::doUnapply() int exceptionCode = 0; - m_element2->parent()->insertBefore(m_element1, m_element2, exceptionCode); + m_element2->parent()->insertBefore(m_element1.get(), m_element2.get(), exceptionCode); ASSERT(exceptionCode == 0); while (m_element2->firstChild() != m_atChild) { diff --git a/WebCore/khtml/editing/merge_identical_elements_command.h b/WebCore/khtml/editing/merge_identical_elements_command.h index 8c6adf30f29..a58d360bcaa 100644 --- a/WebCore/khtml/editing/merge_identical_elements_command.h +++ b/WebCore/khtml/editing/merge_identical_elements_command.h @@ -34,15 +34,15 @@ class MergeIdenticalElementsCommand : public EditCommand { public: MergeIdenticalElementsCommand(DOM::DocumentImpl *, DOM::ElementImpl *first, DOM::ElementImpl *second); - virtual ~MergeIdenticalElementsCommand(); + virtual ~MergeIdenticalElementsCommand() { } virtual void doApply(); virtual void doUnapply(); private: - DOM::ElementImpl *m_element1; - DOM::ElementImpl *m_element2; - DOM::NodeImpl *m_atChild; + RefPtr m_element1; + RefPtr m_element2; + RefPtr m_atChild; }; } // namespace khtml diff --git a/WebCore/khtml/editing/move_selection_command.cpp b/WebCore/khtml/editing/move_selection_command.cpp index 2291dddc52c..0680b2b5dc2 100644 --- a/WebCore/khtml/editing/move_selection_command.cpp +++ b/WebCore/khtml/editing/move_selection_command.cpp @@ -42,13 +42,10 @@ MoveSelectionCommand::MoveSelectionCommand(DocumentImpl *document, DocumentFragm : CompositeEditCommand(document), m_fragment(fragment), m_position(position), m_smartMove(smartMove) { ASSERT(m_fragment); - m_fragment->ref(); } MoveSelectionCommand::~MoveSelectionCommand() { - ASSERT(m_fragment); - m_fragment->deref(); } void MoveSelectionCommand::doApply() @@ -84,7 +81,7 @@ void MoveSelectionCommand::doApply() pos = endingSelection().start(); setEndingSelection(pos, endingSelection().startAffinity()); - EditCommandPtr cmd(new ReplaceSelectionCommand(document(), m_fragment, true, m_smartMove)); + EditCommandPtr cmd(new ReplaceSelectionCommand(document(), m_fragment.get(), true, m_smartMove)); applyCommandToComposite(cmd); } diff --git a/WebCore/khtml/editing/move_selection_command.h b/WebCore/khtml/editing/move_selection_command.h index 4b37d8c51d6..eeb9dc35640 100644 --- a/WebCore/khtml/editing/move_selection_command.h +++ b/WebCore/khtml/editing/move_selection_command.h @@ -44,7 +44,7 @@ public: virtual EditAction editingAction() const; private: - DOM::DocumentFragmentImpl *m_fragment; + RefPtr m_fragment; DOM::Position m_position; bool m_smartMove; }; diff --git a/WebCore/khtml/editing/rebalance_whitespace_command.cpp b/WebCore/khtml/editing/rebalance_whitespace_command.cpp index f9c02a388dc..63b6986b0fc 100644 --- a/WebCore/khtml/editing/rebalance_whitespace_command.cpp +++ b/WebCore/khtml/editing/rebalance_whitespace_command.cpp @@ -45,10 +45,6 @@ RebalanceWhitespaceCommand::RebalanceWhitespaceCommand(DocumentImpl *document, c { } -RebalanceWhitespaceCommand::~RebalanceWhitespaceCommand() -{ -} - static inline bool isWhitespace(const QChar &c) { return c.unicode() == 0xa0 || isCollapsibleWhitespace(c); diff --git a/WebCore/khtml/editing/rebalance_whitespace_command.h b/WebCore/khtml/editing/rebalance_whitespace_command.h index fb3a22a657e..43d08b71c77 100644 --- a/WebCore/khtml/editing/rebalance_whitespace_command.h +++ b/WebCore/khtml/editing/rebalance_whitespace_command.h @@ -35,7 +35,7 @@ class RebalanceWhitespaceCommand : public EditCommand { public: RebalanceWhitespaceCommand(DOM::DocumentImpl *, const DOM::Position &); - virtual ~RebalanceWhitespaceCommand(); + virtual ~RebalanceWhitespaceCommand() { } virtual void doApply(); virtual void doUnapply(); diff --git a/WebCore/khtml/editing/remove_css_property_command.cpp b/WebCore/khtml/editing/remove_css_property_command.cpp index c82be0f4f63..2e50607d8ad 100644 --- a/WebCore/khtml/editing/remove_css_property_command.cpp +++ b/WebCore/khtml/editing/remove_css_property_command.cpp @@ -40,13 +40,6 @@ RemoveCSSPropertyCommand::RemoveCSSPropertyCommand(DocumentImpl *document, CSSSt : EditCommand(document), m_decl(decl->makeMutable()), m_property(property), m_important(false) { ASSERT(m_decl); - m_decl->ref(); -} - -RemoveCSSPropertyCommand::~RemoveCSSPropertyCommand() -{ - ASSERT(m_decl); - m_decl->deref(); } void RemoveCSSPropertyCommand::doApply() diff --git a/WebCore/khtml/editing/remove_css_property_command.h b/WebCore/khtml/editing/remove_css_property_command.h index 7e1e9879884..b0e21e9eac9 100644 --- a/WebCore/khtml/editing/remove_css_property_command.h +++ b/WebCore/khtml/editing/remove_css_property_command.h @@ -40,16 +40,16 @@ class RemoveCSSPropertyCommand : public EditCommand { public: RemoveCSSPropertyCommand(DOM::DocumentImpl *, DOM::CSSStyleDeclarationImpl *, int property); - virtual ~RemoveCSSPropertyCommand(); + virtual ~RemoveCSSPropertyCommand() { } virtual void doApply(); virtual void doUnapply(); - DOM::CSSMutableStyleDeclarationImpl *styleDeclaration() const { return m_decl; } + DOM::CSSMutableStyleDeclarationImpl *styleDeclaration() const { return m_decl.get(); } int property() const { return m_property; } private: - DOM::CSSMutableStyleDeclarationImpl *m_decl; + RefPtr m_decl; int m_property; DOM::DOMString m_oldValue; bool m_important; diff --git a/WebCore/khtml/editing/remove_node_attribute_command.cpp b/WebCore/khtml/editing/remove_node_attribute_command.cpp index 63f29376723..2d9fb464f9d 100644 --- a/WebCore/khtml/editing/remove_node_attribute_command.cpp +++ b/WebCore/khtml/editing/remove_node_attribute_command.cpp @@ -41,13 +41,6 @@ RemoveNodeAttributeCommand::RemoveNodeAttributeCommand(DocumentImpl *document, E : EditCommand(document), m_element(element), m_attribute(attribute) { ASSERT(m_element); - m_element->ref(); -} - -RemoveNodeAttributeCommand::~RemoveNodeAttributeCommand() -{ - ASSERT(m_element); - m_element->deref(); } void RemoveNodeAttributeCommand::doApply() diff --git a/WebCore/khtml/editing/remove_node_attribute_command.h b/WebCore/khtml/editing/remove_node_attribute_command.h index 28e18d72b4d..94836929494 100644 --- a/WebCore/khtml/editing/remove_node_attribute_command.h +++ b/WebCore/khtml/editing/remove_node_attribute_command.h @@ -37,16 +37,16 @@ class RemoveNodeAttributeCommand : public EditCommand { public: RemoveNodeAttributeCommand(DOM::DocumentImpl *, DOM::ElementImpl *, const DOM::QualifiedName& attribute); - virtual ~RemoveNodeAttributeCommand(); + virtual ~RemoveNodeAttributeCommand() { } virtual void doApply(); virtual void doUnapply(); - DOM::ElementImpl *element() const { return m_element; } + DOM::ElementImpl *element() const { return m_element.get(); } const DOM::QualifiedName& attribute() const { return m_attribute; } private: - DOM::ElementImpl *m_element; + RefPtr m_element; DOM::QualifiedName m_attribute; DOM::DOMString m_oldValue; }; diff --git a/WebCore/khtml/editing/remove_node_command.cpp b/WebCore/khtml/editing/remove_node_command.cpp index 95f9bec5a31..25a4fea9f6c 100644 --- a/WebCore/khtml/editing/remove_node_command.cpp +++ b/WebCore/khtml/editing/remove_node_command.cpp @@ -36,30 +36,9 @@ using DOM::NodeImpl; namespace khtml { RemoveNodeCommand::RemoveNodeCommand(DocumentImpl *document, NodeImpl *removeChild) - : EditCommand(document), m_parent(0), m_removeChild(removeChild), m_refChild(0) + : EditCommand(document), m_removeChild(removeChild), m_parent(m_removeChild->parentNode()), m_refChild(m_removeChild->nextSibling()) { - ASSERT(m_removeChild); - m_removeChild->ref(); - - m_parent = m_removeChild->parentNode(); ASSERT(m_parent); - m_parent->ref(); - - m_refChild = m_removeChild->nextSibling(); - if (m_refChild) - m_refChild->ref(); -} - -RemoveNodeCommand::~RemoveNodeCommand() -{ - ASSERT(m_parent); - m_parent->deref(); - - ASSERT(m_removeChild); - m_removeChild->deref(); - - if (m_refChild) - m_refChild->deref(); } void RemoveNodeCommand::doApply() @@ -68,7 +47,7 @@ void RemoveNodeCommand::doApply() ASSERT(m_removeChild); int exceptionCode = 0; - m_parent->removeChild(m_removeChild, exceptionCode); + m_parent->removeChild(m_removeChild.get(), exceptionCode); ASSERT(exceptionCode == 0); } @@ -78,7 +57,7 @@ void RemoveNodeCommand::doUnapply() ASSERT(m_removeChild); int exceptionCode = 0; - m_parent->insertBefore(m_removeChild, m_refChild, exceptionCode); + m_parent->insertBefore(m_removeChild.get(), m_refChild.get(), exceptionCode); ASSERT(exceptionCode == 0); } diff --git a/WebCore/khtml/editing/remove_node_command.h b/WebCore/khtml/editing/remove_node_command.h index 32edff29434..629ffd74d2b 100644 --- a/WebCore/khtml/editing/remove_node_command.h +++ b/WebCore/khtml/editing/remove_node_command.h @@ -34,17 +34,17 @@ class RemoveNodeCommand : public EditCommand { public: RemoveNodeCommand(DOM::DocumentImpl *, DOM::NodeImpl *); - virtual ~RemoveNodeCommand(); + virtual ~RemoveNodeCommand() { } virtual void doApply(); virtual void doUnapply(); - DOM::NodeImpl *node() const { return m_removeChild; } + DOM::NodeImpl *node() const { return m_removeChild.get(); } private: - DOM::NodeImpl *m_parent; - DOM::NodeImpl *m_removeChild; - DOM::NodeImpl *m_refChild; + RefPtr m_removeChild; + RefPtr m_parent; + RefPtr m_refChild; }; } // namespace khtml diff --git a/WebCore/khtml/editing/remove_node_preserving_children_command.cpp b/WebCore/khtml/editing/remove_node_preserving_children_command.cpp index cd3f9ddf101..75e2bd1cd8e 100644 --- a/WebCore/khtml/editing/remove_node_preserving_children_command.cpp +++ b/WebCore/khtml/editing/remove_node_preserving_children_command.cpp @@ -39,13 +39,6 @@ RemoveNodePreservingChildrenCommand::RemoveNodePreservingChildrenCommand(Documen : CompositeEditCommand(document), m_node(node) { ASSERT(m_node); - m_node->ref(); -} - -RemoveNodePreservingChildrenCommand::~RemoveNodePreservingChildrenCommand() -{ - ASSERT(m_node); - m_node->deref(); } void RemoveNodePreservingChildrenCommand::doApply() diff --git a/WebCore/khtml/editing/remove_node_preserving_children_command.h b/WebCore/khtml/editing/remove_node_preserving_children_command.h index 6ae7a3658dd..fa8df20d268 100644 --- a/WebCore/khtml/editing/remove_node_preserving_children_command.h +++ b/WebCore/khtml/editing/remove_node_preserving_children_command.h @@ -34,14 +34,14 @@ class RemoveNodePreservingChildrenCommand : public CompositeEditCommand { public: RemoveNodePreservingChildrenCommand(DOM::DocumentImpl *, DOM::NodeImpl *); - virtual ~RemoveNodePreservingChildrenCommand(); + virtual ~RemoveNodePreservingChildrenCommand() { } virtual void doApply(); - DOM::NodeImpl *node() const { return m_node; } + DOM::NodeImpl *node() const { return m_node.get(); } private: - DOM::NodeImpl *m_node; + RefPtr m_node; }; } // namespace khtml diff --git a/WebCore/khtml/editing/replace_selection_command.cpp b/WebCore/khtml/editing/replace_selection_command.cpp index 3ff4d0d1f86..4dddac35bff 100644 --- a/WebCore/khtml/editing/replace_selection_command.cpp +++ b/WebCore/khtml/editing/replace_selection_command.cpp @@ -74,10 +74,7 @@ ReplacementFragment::ReplacementFragment(DocumentImpl *document, DocumentFragmen m_type = EmptyFragment; return; } - - m_document->ref(); - m_fragment->ref(); - + NodeImpl *firstChild = m_fragment->firstChild(); NodeImpl *lastChild = m_fragment->lastChild(); @@ -109,12 +106,10 @@ ReplacementFragment::ReplacementFragment(DocumentImpl *document, DocumentFragmen } } else if (isInterchangeConvertedSpaceSpan(node)) { - NodeImpl *n = 0; + RefPtr n = 0; while ((n = node->firstChild())) { - n->ref(); removeNode(n); - insertNodeBefore(n, node); - n->deref(); + insertNodeBefore(n.get(), node); } removeNode(node); if (n) @@ -128,26 +123,18 @@ ReplacementFragment::ReplacementFragment(DocumentImpl *document, DocumentFragmen if (newlineAtEndNode) removeNode(newlineAtEndNode); - NodeImpl *holder = insertFragmentForTestRendering(); - if (holder) - holder->ref(); - if (!m_matchStyle) { - computeStylesUsingTestRendering(holder); - } - removeUnrenderedNodesUsingTestRendering(holder); - m_hasMoreThanOneBlock = countRenderedBlocks(holder) > 1; - restoreTestRenderingNodesToFragment(holder); + PassRefPtr holder = insertFragmentForTestRendering(); + if (!m_matchStyle) + computeStylesUsingTestRendering(holder.get()); + removeUnrenderedNodesUsingTestRendering(holder.get()); + m_hasMoreThanOneBlock = countRenderedBlocks(holder.get()) > 1; + restoreTestRenderingNodesToFragment(holder.get()); removeNode(holder); - holder->deref(); removeStyleNodes(); } ReplacementFragment::~ReplacementFragment() { - if (m_document) - m_document->deref(); - if (m_fragment) - m_fragment->deref(); } NodeImpl *ReplacementFragment::firstChild() const @@ -209,7 +196,7 @@ NodeImpl *ReplacementFragment::enclosingBlock(NodeImpl *node) const { while (node && !isProbablyBlock(node)) node = node->parentNode(); - return node ? node : m_fragment; + return node ? node : m_fragment.get(); } void ReplacementFragment::removeNodePreservingChildren(NodeImpl *node) @@ -217,28 +204,24 @@ void ReplacementFragment::removeNodePreservingChildren(NodeImpl *node) if (!node) return; - while (NodeImpl *n = node->firstChild()) { - n->ref(); + while (RefPtr n = node->firstChild()) { removeNode(n); - insertNodeBefore(n, node); - n->deref(); + insertNodeBefore(n.get(), node); } removeNode(node); } -void ReplacementFragment::removeNode(NodeImpl *node) +void ReplacementFragment::removeNode(PassRefPtr node) { if (!node) return; - + NodeImpl *parent = node->parentNode(); if (!parent) return; - + int exceptionCode = 0; - node->ref(); - parent->removeChild(node, exceptionCode); - node->deref(); + parent->removeChild(node.get(), exceptionCode); ASSERT(exceptionCode == 0); } @@ -256,22 +239,20 @@ void ReplacementFragment::insertNodeBefore(NodeImpl *node, NodeImpl *refNode) ASSERT(exceptionCode == 0); } -NodeImpl *ReplacementFragment::insertFragmentForTestRendering() +PassRefPtr ReplacementFragment::insertFragmentForTestRendering() { NodeImpl *body = m_document->body(); if (!body) return 0; - ElementImpl *holder = createDefaultParagraphElement(m_document); - holder->ref(); + PassRefPtr holder = createDefaultParagraphElement(m_document.get()); int exceptionCode = 0; - holder->appendChild(m_fragment, exceptionCode); + holder->appendChild(m_fragment.get(), exceptionCode); ASSERT(exceptionCode == 0); - body->appendChild(holder, exceptionCode); + body->appendChild(holder.get(), exceptionCode); ASSERT(exceptionCode == 0); - holder->deref(); m_document->updateLayoutIgnorePendingStylesheets(); @@ -284,13 +265,11 @@ void ReplacementFragment::restoreTestRenderingNodesToFragment(NodeImpl *holder) return; int exceptionCode = 0; - while (NodeImpl *node = holder->firstChild()) { - node->ref(); - holder->removeChild(node, exceptionCode); + while (RefPtr node = holder->firstChild()) { + holder->removeChild(node.get(), exceptionCode); ASSERT(exceptionCode == 0); - m_fragment->appendChild(node, exceptionCode); + m_fragment->appendChild(node.get(), exceptionCode); ASSERT(exceptionCode == 0); - node->deref(); } } @@ -319,8 +298,7 @@ void ReplaceSelectionCommand::fixupNodeStyles(const QValueList // The desiredStyle declaration tells what style this node wants to be. // Compare that to the style that it is right now in the document. Position pos(node, 0); - CSSComputedStyleDeclarationImpl *currentStyle = pos.computedStyle(); - currentStyle->ref(); + RefPtr currentStyle = pos.computedStyle(); // Check for the special "match nearest blockquote color" property and resolve to the correct // color if necessary. @@ -328,11 +306,9 @@ void ReplaceSelectionCommand::fixupNodeStyles(const QValueList if (matchColorCheck == matchNearestBlockquoteColorString()) { NodeImpl *blockquote = nearestMailBlockquote(node); Position pos(blockquote ? blockquote : node->getDocument()->documentElement(), 0); - CSSComputedStyleDeclarationImpl *style = pos.computedStyle(); - style->ref(); + RefPtr style = pos.computedStyle(); DOMString desiredColor = desiredStyle->getPropertyValue(CSS_PROP_COLOR); DOMString nearestColor = style->getPropertyValue(CSS_PROP_COLOR); - style->deref(); if (desiredColor != nearestColor) desiredStyle->setProperty(CSS_PROP_COLOR, nearestColor); } @@ -349,8 +325,6 @@ void ReplaceSelectionCommand::fixupNodeStyles(const QValueList // from the desired by the styles remaining in the desiredStyle declaration. if (desiredStyle->length() > 0) applyStyle(desiredStyle, Position(node, 0), Position(node, node->maxDeepOffset())); - - currentStyle->deref(); } } @@ -359,20 +333,16 @@ static void computeAndStoreNodeDesiredStyle(DOM::NodeImpl *node, QValueListinDocument()) return; - CSSComputedStyleDeclarationImpl *computedStyle = Position(node, 0).computedStyle(); - computedStyle->ref(); + RefPtr computedStyle = Position(node, 0).computedStyle(); CSSMutableStyleDeclarationImpl *style = computedStyle->copyInheritableProperties(); list.append(NodeDesiredStyle(node, style)); - computedStyle->deref(); // In either of the color-matching tests below, set the color to a pseudo-color that will // make the content take on the color of the nearest-enclosing blockquote (if any) after // being pasted in. if (NodeImpl *blockquote = nearestMailBlockquote(node)) { - CSSComputedStyleDeclarationImpl *blockquoteStyle = Position(blockquote, 0).computedStyle(); - blockquoteStyle->ref(); + RefPtr blockquoteStyle = Position(blockquote, 0).computedStyle(); bool match = (blockquoteStyle->getPropertyValue(CSS_PROP_COLOR) == style->getPropertyValue(CSS_PROP_COLOR)); - blockquoteStyle->deref(); if (match) { style->setProperty(CSS_PROP__KHTML_MATCH_NEAREST_MAIL_BLOCKQUOTE_COLOR, matchNearestBlockquoteColorString()); return; @@ -380,13 +350,10 @@ static void computeAndStoreNodeDesiredStyle(DOM::NodeImpl *node, QValueListgetDocument() ? node->getDocument()->documentElement() : 0; if (documentElement) { - CSSComputedStyleDeclarationImpl *documentStyle = Position(documentElement, 0).computedStyle(); - documentStyle->ref(); + RefPtr documentStyle = Position(documentElement, 0).computedStyle(); bool match = (documentStyle->getPropertyValue(CSS_PROP_COLOR) == style->getPropertyValue(CSS_PROP_COLOR)); - documentStyle->deref(); - if (match) { + if (match) style->setProperty(CSS_PROP__KHTML_MATCH_NEAREST_MAIL_BLOCKQUOTE_COLOR, matchNearestBlockquoteColorString()); - } } } @@ -486,57 +453,11 @@ void ReplacementFragment::removeStyleNodes() NodeDesiredStyle::NodeDesiredStyle(NodeImpl *node, CSSMutableStyleDeclarationImpl *style) : m_node(node), m_style(style) { - if (m_node) - m_node->ref(); - if (m_style) - m_style->ref(); -} - -NodeDesiredStyle::NodeDesiredStyle(const NodeDesiredStyle &other) - : m_node(other.node()), m_style(other.style()) -{ - if (m_node) - m_node->ref(); - if (m_style) - m_style->ref(); -} - -NodeDesiredStyle::~NodeDesiredStyle() -{ - if (m_node) - m_node->deref(); - if (m_style) - m_style->deref(); -} - -NodeDesiredStyle &NodeDesiredStyle::operator=(const NodeDesiredStyle &other) -{ - NodeImpl *oldNode = m_node; - CSSMutableStyleDeclarationImpl *oldStyle = m_style; - - m_node = other.node(); - m_style = other.style(); - - if (m_node) - m_node->ref(); - if (m_style) - m_style->ref(); - - if (oldNode) - oldNode->deref(); - if (oldStyle) - oldStyle->deref(); - - return *this; } ReplaceSelectionCommand::ReplaceSelectionCommand(DocumentImpl *document, DocumentFragmentImpl *fragment, bool selectReplacement, bool smartReplace, bool matchStyle) : CompositeEditCommand(document), m_fragment(document, fragment, matchStyle), - m_firstNodeInserted(0), - m_lastNodeInserted(0), - m_lastTopNodeInserted(0), - m_insertionStyle(0), m_selectReplacement(selectReplacement), m_smartReplace(smartReplace), m_matchStyle(matchStyle) @@ -545,14 +466,6 @@ ReplaceSelectionCommand::ReplaceSelectionCommand(DocumentImpl *document, Documen ReplaceSelectionCommand::~ReplaceSelectionCommand() { - if (m_firstNodeInserted) - m_firstNodeInserted->deref(); - if (m_lastNodeInserted) - m_lastNodeInserted->deref(); - if (m_lastTopNodeInserted) - m_lastTopNodeInserted->deref(); - if (m_insertionStyle) - m_insertionStyle->deref(); } static int maxRangeOffset(NodeImpl *n) @@ -589,10 +502,8 @@ void ReplaceSelectionCommand::doApply() SelectionController selection = endingSelection(); ASSERT(selection.isCaretOrRange()); - if (m_matchStyle) { + if (m_matchStyle) m_insertionStyle = styleAtPosition(selection.start()); - m_insertionStyle->ref(); - } VisiblePosition visibleStart(selection.start(), selection.startAffinity()); VisiblePosition visibleEnd(selection.end(), selection.endAffinity()); @@ -759,7 +670,7 @@ void ReplaceSelectionCommand::doApply() // update insertion point to be at the end of the last block inserted if (m_lastNodeInserted) { updateLayout(); - insertionPos = Position(m_lastNodeInserted, m_lastNodeInserted->caretMaxOffset()); + insertionPos = Position(m_lastNodeInserted.get(), m_lastNodeInserted->caretMaxOffset()); } } @@ -789,23 +700,23 @@ void ReplaceSelectionCommand::doApply() node = next; } updateLayout(); - insertionPos = Position(m_lastNodeInserted, m_lastNodeInserted->caretMaxOffset()); + insertionPos = Position(m_lastNodeInserted.get(), m_lastNodeInserted->caretMaxOffset()); } // step 3 : handle "smart replace" whitespace if (addTrailingSpace && m_lastNodeInserted) { updateLayout(); - Position pos(m_lastNodeInserted, m_lastNodeInserted->caretMaxOffset()); + Position pos(m_lastNodeInserted.get(), m_lastNodeInserted->caretMaxOffset()); bool needsTrailingSpace = pos.trailingWhitespacePosition(VP_DEFAULT_AFFINITY, true).isNull(); if (needsTrailingSpace) { if (m_lastNodeInserted->isTextNode()) { - TextImpl *text = static_cast(m_lastNodeInserted); + TextImpl *text = static_cast(m_lastNodeInserted.get()); insertTextIntoNode(text, text->length(), nonBreakingSpaceString()); insertionPos = Position(text, text->length()); } else { NodeImpl *node = document()->createEditingTextNode(nonBreakingSpaceString()); - insertNodeAfterAndUpdateNodesInserted(node, m_lastNodeInserted); + insertNodeAfterAndUpdateNodesInserted(node, m_lastNodeInserted.get()); insertionPos = Position(node, 1); } } @@ -813,15 +724,15 @@ void ReplaceSelectionCommand::doApply() if (addLeadingSpace && m_firstNodeInserted) { updateLayout(); - Position pos(m_firstNodeInserted, 0); + Position pos(m_firstNodeInserted.get(), 0); bool needsLeadingSpace = pos.leadingWhitespacePosition(VP_DEFAULT_AFFINITY, true).isNull(); if (needsLeadingSpace) { if (m_firstNodeInserted->isTextNode()) { - TextImpl *text = static_cast(m_firstNodeInserted); + TextImpl *text = static_cast(m_firstNodeInserted.get()); insertTextIntoNode(text, 0, nonBreakingSpaceString()); } else { NodeImpl *node = document()->createEditingTextNode(nonBreakingSpaceString()); - insertNodeBeforeAndUpdateNodesInserted(node, m_firstNodeInserted); + insertNodeBeforeAndUpdateNodesInserted(node, m_firstNodeInserted.get()); } } } @@ -839,7 +750,7 @@ void ReplaceSelectionCommand::doApply() bool insertParagraph = false; VisiblePosition pos(insertionPos, VP_DEFAULT_AFFINITY); - if (startBlock == endBlock && !isProbablyBlock(m_lastTopNodeInserted)) { + if (startBlock == endBlock && !isProbablyBlock(m_lastTopNodeInserted.get())) { insertParagraph = true; } else { // Handle end-of-document case. @@ -865,23 +776,23 @@ void ReplaceSelectionCommand::doApply() else { if (m_lastNodeInserted && m_lastNodeInserted->hasTagName(brTag) && !document()->inStrictMode()) { updateLayout(); - VisiblePosition pos(Position(m_lastNodeInserted, 1), DOWNSTREAM); + VisiblePosition pos(Position(m_lastNodeInserted.get(), 1), DOWNSTREAM); if (isEndOfBlock(pos)) { NodeImpl *next = m_lastNodeInserted->traverseNextNode(); bool hasTrailingBR = next && next->hasTagName(brTag) && m_lastNodeInserted->enclosingBlockFlowElement() == next->enclosingBlockFlowElement(); if (!hasTrailingBR) { // Insert an "extra" BR at the end of the block. - insertNodeBefore(createBreakElement(document()), m_lastNodeInserted); + insertNodeBefore(createBreakElement(document()), m_lastNodeInserted.get()); } } } - if (moveNodesAfterEnd && !isLastVisiblePositionInSpecialElement(Position(m_lastNodeInserted, maxRangeOffset(m_lastNodeInserted)))) { + if (moveNodesAfterEnd && !isLastVisiblePositionInSpecialElement(Position(m_lastNodeInserted.get(), maxRangeOffset(m_lastNodeInserted.get())))) { updateLayout(); QValueList styles; QPtrList blocks; NodeImpl *node = beyondEndNode; - NodeImpl *refNode = m_lastNodeInserted; + NodeImpl *refNode = m_lastNodeInserted.get(); while (node) { RenderObject *renderer = node->renderer(); // Stop at the first table or block. @@ -948,11 +859,9 @@ void ReplaceSelectionCommand::completeHTMLReplacement(const Position &lastPositi Position start; Position end; - if (m_firstNodeInserted && m_firstNodeInserted->inDocument() && - m_lastNodeInserted && m_lastNodeInserted->inDocument()) { - + if (m_firstNodeInserted && m_firstNodeInserted->inDocument() && m_lastNodeInserted && m_lastNodeInserted->inDocument()) { // Find the last leaf. - NodeImpl *lastLeaf = m_lastNodeInserted; + NodeImpl *lastLeaf = m_lastNodeInserted.get(); while (1) { NodeImpl *nextChild = lastLeaf->lastChild(); if (!nextChild) @@ -961,7 +870,7 @@ void ReplaceSelectionCommand::completeHTMLReplacement(const Position &lastPositi } // Find the first leaf. - NodeImpl *firstLeaf = m_firstNodeInserted; + NodeImpl *firstLeaf = m_firstNodeInserted.get(); while (1) { NodeImpl *nextChild = firstLeaf->firstChild(); if (!nextChild) @@ -976,14 +885,14 @@ void ReplaceSelectionCommand::completeHTMLReplacement(const Position &lastPositi if (m_matchStyle) { assert(m_insertionStyle); - applyStyle(m_insertionStyle, start, end); + applyStyle(m_insertionStyle.get(), start, end); } if (lastPositionToSelect.isNotNull()) end = lastPositionToSelect; - } else if (lastPositionToSelect.isNotNull()) { + } else if (lastPositionToSelect.isNotNull()) start = end = lastPositionToSelect; - } else + else return; if (m_selectReplacement) @@ -1022,27 +931,14 @@ void ReplaceSelectionCommand::updateNodesInserted(NodeImpl *node) if (!node) return; - // update m_lastTopNodeInserted - node->ref(); - if (m_lastTopNodeInserted) - m_lastTopNodeInserted->deref(); m_lastTopNodeInserted = node; - - // update m_firstNodeInserted - if (!m_firstNodeInserted) { + if (!m_firstNodeInserted) m_firstNodeInserted = node; - m_firstNodeInserted->ref(); - } if (node == m_lastNodeInserted) return; - // update m_lastNodeInserted - NodeImpl *old = m_lastNodeInserted; m_lastNodeInserted = node->lastDescendant(); - m_lastNodeInserted->ref(); - if (old) - old->deref(); } } // namespace khtml diff --git a/WebCore/khtml/editing/replace_selection_command.h b/WebCore/khtml/editing/replace_selection_command.h index ea040455261..0aec7864617 100644 --- a/WebCore/khtml/editing/replace_selection_command.h +++ b/WebCore/khtml/editing/replace_selection_command.h @@ -27,6 +27,7 @@ #define __replace_selection_command_h__ #include "composite_edit_command.h" +#include namespace DOM { class DocumentFragmentImpl; @@ -38,17 +39,13 @@ class NodeDesiredStyle { public: NodeDesiredStyle(DOM::NodeImpl *, DOM::CSSMutableStyleDeclarationImpl *); - NodeDesiredStyle(const NodeDesiredStyle &); - ~NodeDesiredStyle(); - DOM::NodeImpl *node() const { return m_node; } - DOM::CSSMutableStyleDeclarationImpl *style() const { return m_style; } - - NodeDesiredStyle &operator=(const NodeDesiredStyle &); + DOM::NodeImpl *node() const { return m_node.get(); } + DOM::CSSMutableStyleDeclarationImpl *style() const { return m_style.get(); } private: - DOM::NodeImpl *m_node; - DOM::CSSMutableStyleDeclarationImpl *m_style; + RefPtr m_node; + RefPtr m_style; }; // --- ReplacementFragment helper class @@ -61,7 +58,7 @@ public: enum EFragmentType { EmptyFragment, SingleTextNodeFragment, TreeFragment }; - DOM::DocumentFragmentImpl *root() const { return m_fragment; } + DOM::DocumentFragmentImpl *root() const { return m_fragment.get(); } DOM::NodeImpl *firstChild() const; DOM::NodeImpl *lastChild() const; @@ -86,7 +83,7 @@ private: static bool isInterchangeNewlineNode(const DOM::NodeImpl *); static bool isInterchangeConvertedSpaceSpan(const DOM::NodeImpl *); - DOM::NodeImpl *insertFragmentForTestRendering(); + PassRefPtr insertFragmentForTestRendering(); void restoreTestRenderingNodesToFragment(DOM::NodeImpl *); void computeStylesUsingTestRendering(DOM::NodeImpl *); void removeUnrenderedNodesUsingTestRendering(DOM::NodeImpl *); @@ -95,13 +92,13 @@ private: // A couple simple DOM helpers DOM::NodeImpl *enclosingBlock(DOM::NodeImpl *) const; - void removeNode(DOM::NodeImpl *); + void removeNode(PassRefPtr); void removeNodePreservingChildren(DOM::NodeImpl *); void insertNodeBefore(DOM::NodeImpl *node, DOM::NodeImpl *refNode); EFragmentType m_type; - DOM::DocumentImpl *m_document; - DOM::DocumentFragmentImpl *m_fragment; + RefPtr m_document; + RefPtr m_fragment; QValueList m_styles; bool m_matchStyle; bool m_hasInterchangeNewlineAtStart; @@ -130,10 +127,10 @@ private: void removeLinePlaceholderIfNeeded(DOM::NodeImpl *); ReplacementFragment m_fragment; - DOM::NodeImpl *m_firstNodeInserted; - DOM::NodeImpl *m_lastNodeInserted; - DOM::NodeImpl *m_lastTopNodeInserted; - DOM::CSSMutableStyleDeclarationImpl *m_insertionStyle; + RefPtr m_firstNodeInserted; + RefPtr m_lastNodeInserted; + RefPtr m_lastTopNodeInserted; + RefPtr m_insertionStyle; bool m_selectReplacement; bool m_smartReplace; bool m_matchStyle; diff --git a/WebCore/khtml/editing/set_node_attribute_command.cpp b/WebCore/khtml/editing/set_node_attribute_command.cpp index b9a866dbaf5..21cfbb98456 100644 --- a/WebCore/khtml/editing/set_node_attribute_command.cpp +++ b/WebCore/khtml/editing/set_node_attribute_command.cpp @@ -43,16 +43,9 @@ SetNodeAttributeCommand::SetNodeAttributeCommand(DocumentImpl *document, Element : EditCommand(document), m_element(element), m_attribute(attribute), m_value(value) { ASSERT(m_element); - m_element->ref(); ASSERT(!m_value.isNull()); } -SetNodeAttributeCommand::~SetNodeAttributeCommand() -{ - ASSERT(m_element); - m_element->deref(); -} - void SetNodeAttributeCommand::doApply() { ASSERT(m_element); diff --git a/WebCore/khtml/editing/set_node_attribute_command.h b/WebCore/khtml/editing/set_node_attribute_command.h index dd6729f48b0..0d362ae2032 100644 --- a/WebCore/khtml/editing/set_node_attribute_command.h +++ b/WebCore/khtml/editing/set_node_attribute_command.h @@ -37,17 +37,17 @@ class SetNodeAttributeCommand : public EditCommand { public: SetNodeAttributeCommand(DOM::DocumentImpl *, DOM::ElementImpl *, const DOM::QualifiedName& attribute, const DOM::DOMString &value); - virtual ~SetNodeAttributeCommand(); + virtual ~SetNodeAttributeCommand() { } virtual void doApply(); virtual void doUnapply(); - DOM::ElementImpl *element() const { return m_element; } + DOM::ElementImpl *element() const { return m_element.get(); } const DOM::QualifiedName& attribute() const { return m_attribute; } DOM::DOMString value() const { return m_value; } private: - DOM::ElementImpl *m_element; + RefPtr m_element; DOM::QualifiedName m_attribute; DOM::DOMString m_value; DOM::DOMString m_oldValue; diff --git a/WebCore/khtml/editing/split_element_command.cpp b/WebCore/khtml/editing/split_element_command.cpp index 8518e828d62..e000d4ec9cc 100644 --- a/WebCore/khtml/editing/split_element_command.cpp +++ b/WebCore/khtml/editing/split_element_command.cpp @@ -37,24 +37,10 @@ using DOM::NodeImpl; namespace khtml { SplitElementCommand::SplitElementCommand(DOM::DocumentImpl *document, DOM::ElementImpl *element, DOM::NodeImpl *atChild) - : EditCommand(document), m_element1(0), m_element2(element), m_atChild(atChild) + : EditCommand(document), m_element2(element), m_atChild(atChild) { ASSERT(m_element2); ASSERT(m_atChild); - - m_element2->ref(); - m_atChild->ref(); -} - -SplitElementCommand::~SplitElementCommand() -{ - if (m_element1) - m_element1->deref(); - - ASSERT(m_element2); - m_element2->deref(); - ASSERT(m_atChild); - m_atChild->deref(); } void SplitElementCommand::doApply() @@ -69,10 +55,9 @@ void SplitElementCommand::doApply() // if reapplying, this object will already exist. m_element1 = static_cast(m_element2->cloneNode(false)); ASSERT(m_element1); - m_element1->ref(); } - m_element2->parent()->insertBefore(m_element1, m_element2, exceptionCode); + m_element2->parent()->insertBefore(m_element1.get(), m_element2.get(), exceptionCode); ASSERT(exceptionCode == 0); while (m_element2->firstChild() != m_atChild) { @@ -98,7 +83,7 @@ void SplitElementCommand::doUnapply() ASSERT(exceptionCode == 0); } - m_element2->parentNode()->removeChild(m_element1, exceptionCode); + m_element2->parentNode()->removeChild(m_element1.get(), exceptionCode); ASSERT(exceptionCode == 0); } diff --git a/WebCore/khtml/editing/split_element_command.h b/WebCore/khtml/editing/split_element_command.h index 3e51d7d7da5..95e1649207e 100644 --- a/WebCore/khtml/editing/split_element_command.h +++ b/WebCore/khtml/editing/split_element_command.h @@ -34,15 +34,15 @@ class SplitElementCommand : public EditCommand { public: SplitElementCommand(DOM::DocumentImpl *, DOM::ElementImpl *element, DOM::NodeImpl *atChild); - virtual ~SplitElementCommand(); + virtual ~SplitElementCommand() { } virtual void doApply(); virtual void doUnapply(); private: - DOM::ElementImpl *m_element1; - DOM::ElementImpl *m_element2; - DOM::NodeImpl *m_atChild; + RefPtr m_element1; + RefPtr m_element2; + RefPtr m_atChild; }; } // namespace khtml diff --git a/WebCore/khtml/editing/split_text_node_command.cpp b/WebCore/khtml/editing/split_text_node_command.cpp index bd212eedc21..08be965db56 100644 --- a/WebCore/khtml/editing/split_text_node_command.cpp +++ b/WebCore/khtml/editing/split_text_node_command.cpp @@ -38,21 +38,10 @@ using DOM::NodeImpl; namespace khtml { SplitTextNodeCommand::SplitTextNodeCommand(DocumentImpl *document, TextImpl *text, int offset) - : EditCommand(document), m_text1(0), m_text2(text), m_offset(offset) + : EditCommand(document), m_text2(text), m_offset(offset) { ASSERT(m_text2); ASSERT(m_text2->length() > 0); - - m_text2->ref(); -} - -SplitTextNodeCommand::~SplitTextNodeCommand() -{ - if (m_text1) - m_text1->deref(); - - ASSERT(m_text2); - m_text2->deref(); } void SplitTextNodeCommand::doApply() @@ -72,14 +61,13 @@ void SplitTextNodeCommand::doApply() m_text1 = document()->createTextNode(m_text2->substringData(0, m_offset, exceptionCode)); ASSERT(exceptionCode == 0); ASSERT(m_text1); - m_text1->ref(); } - document()->copyMarkers(m_text2, 0, m_offset, m_text1, 0); + document()->copyMarkers(m_text2.get(), 0, m_offset, m_text1.get(), 0); m_text2->deleteData(0, m_offset, exceptionCode); ASSERT(exceptionCode == 0); - m_text2->parentNode()->insertBefore(m_text1, m_text2, exceptionCode); + m_text2->parentNode()->insertBefore(m_text1.get(), m_text2.get(), exceptionCode); ASSERT(exceptionCode == 0); ASSERT(m_text2->previousSibling()->isTextNode()); @@ -96,9 +84,9 @@ void SplitTextNodeCommand::doUnapply() m_text2->insertData(0, m_text1->data(), exceptionCode); ASSERT(exceptionCode == 0); - document()->copyMarkers(m_text1, 0, m_offset, m_text2, 0); + document()->copyMarkers(m_text1.get(), 0, m_offset, m_text2.get(), 0); - m_text2->parentNode()->removeChild(m_text1, exceptionCode); + m_text2->parentNode()->removeChild(m_text1.get(), exceptionCode); ASSERT(exceptionCode == 0); m_offset = m_text1->length(); diff --git a/WebCore/khtml/editing/split_text_node_command.h b/WebCore/khtml/editing/split_text_node_command.h index 196f480a73b..40e5946c096 100644 --- a/WebCore/khtml/editing/split_text_node_command.h +++ b/WebCore/khtml/editing/split_text_node_command.h @@ -38,17 +38,17 @@ class SplitTextNodeCommand : public EditCommand { public: SplitTextNodeCommand(DOM::DocumentImpl *, DOM::TextImpl *, int); - virtual ~SplitTextNodeCommand(); + virtual ~SplitTextNodeCommand() { } virtual void doApply(); virtual void doUnapply(); - DOM::TextImpl *node() const { return m_text2; } + DOM::TextImpl *node() const { return m_text2.get(); } int offset() const { return m_offset; } private: - DOM::TextImpl *m_text1; - DOM::TextImpl *m_text2; + RefPtr m_text1; + RefPtr m_text2; unsigned m_offset; }; diff --git a/WebCore/khtml/editing/split_text_node_containing_element.cpp b/WebCore/khtml/editing/split_text_node_containing_element.cpp index f28008fe0a3..33eea62a20c 100644 --- a/WebCore/khtml/editing/split_text_node_containing_element.cpp +++ b/WebCore/khtml/editing/split_text_node_containing_element.cpp @@ -44,14 +44,6 @@ SplitTextNodeContainingElementCommand::SplitTextNodeContainingElementCommand(Doc { ASSERT(m_text); ASSERT(m_text->length() > 0); - - m_text->ref(); -} - -SplitTextNodeContainingElementCommand::~SplitTextNodeContainingElementCommand() -{ - ASSERT(m_text); - m_text->deref(); } void SplitTextNodeContainingElementCommand::doApply() @@ -59,7 +51,7 @@ void SplitTextNodeContainingElementCommand::doApply() ASSERT(m_text); ASSERT(m_offset > 0); - splitTextNode(m_text, m_offset); + splitTextNode(m_text.get(), m_offset); NodeImpl *parentNode = m_text->parentNode(); if (!parentNode->renderer() || !parentNode->renderer()->isInline()) { @@ -67,7 +59,7 @@ void SplitTextNodeContainingElementCommand::doApply() parentNode = parentNode->firstChild(); } - splitElement(static_cast(parentNode), m_text); + splitElement(static_cast(parentNode), m_text.get()); } } // namespace khtml diff --git a/WebCore/khtml/editing/split_text_node_containing_element_command.h b/WebCore/khtml/editing/split_text_node_containing_element_command.h index 710f8d8fb8a..56e072c9118 100644 --- a/WebCore/khtml/editing/split_text_node_containing_element_command.h +++ b/WebCore/khtml/editing/split_text_node_containing_element_command.h @@ -34,12 +34,12 @@ class SplitTextNodeContainingElementCommand : public CompositeEditCommand { public: SplitTextNodeContainingElementCommand(DOM::DocumentImpl *, DOM::TextImpl *, int); - virtual ~SplitTextNodeContainingElementCommand(); + virtual ~SplitTextNodeContainingElementCommand() { } virtual void doApply(); private: - DOM::TextImpl *m_text; + RefPtr m_text; int m_offset; }; diff --git a/WebCore/khtml/editing/visible_position.cpp b/WebCore/khtml/editing/visible_position.cpp index 217d1422abc..d122b7be676 100644 --- a/WebCore/khtml/editing/visible_position.cpp +++ b/WebCore/khtml/editing/visible_position.cpp @@ -387,11 +387,11 @@ void VisiblePosition::showTree() const } #endif -RefPtr makeRange(const VisiblePosition &start, const VisiblePosition &end) +PassRefPtr makeRange(const VisiblePosition &start, const VisiblePosition &end) { Position s = start.position(); Position e = end.position(); - return RefPtr(new RangeImpl(s.node()->getDocument(), s.node(), s.offset(), e.node(), e.offset())); + return new RangeImpl(s.node()->getDocument(), s.node(), s.offset(), e.node(), e.offset()); } VisiblePosition startVisiblePosition(const RangeImpl *r, EAffinity affinity) diff --git a/WebCore/khtml/editing/visible_position.h b/WebCore/khtml/editing/visible_position.h index 6445b015114..fb958dd6891 100644 --- a/WebCore/khtml/editing/visible_position.h +++ b/WebCore/khtml/editing/visible_position.h @@ -26,7 +26,8 @@ #ifndef KHTML_EDITING_VISIBLE_POSITION_H #define KHTML_EDITING_VISIBLE_POSITION_H -#include +#include // for QChar +#include #include "xml/dom_position.h" #include "text_affinity.h" @@ -128,7 +129,7 @@ inline bool operator!=(const VisiblePosition &a, const VisiblePosition &b) return !(a == b); } -RefPtr makeRange(const VisiblePosition &start, const VisiblePosition &end); +PassRefPtr makeRange(const VisiblePosition &start, const VisiblePosition &end); bool setStart(DOM::RangeImpl *, const VisiblePosition &start); bool setEnd(DOM::RangeImpl *, const VisiblePosition &start); VisiblePosition startVisiblePosition(const DOM::RangeImpl *, EAffinity); diff --git a/WebCore/khtml/editing/visible_text.cpp b/WebCore/khtml/editing/visible_text.cpp index 800fd062027..68cb72a70d4 100644 --- a/WebCore/khtml/editing/visible_text.cpp +++ b/WebCore/khtml/editing/visible_text.cpp @@ -459,7 +459,7 @@ void TextIterator::emitCharacter(QChar c, NodeImpl *textNode, NodeImpl *offsetBa m_lastCharacter = c; } -RefPtr TextIterator::range() const +PassRefPtr TextIterator::range() const { // use the current run information, if we have it if (m_positionNode) { @@ -469,16 +469,14 @@ RefPtr TextIterator::range() const m_positionEndOffset += index; m_positionOffsetBaseNode = 0; } - return RefPtr(new RangeImpl(m_positionNode->getDocument(), - m_positionNode, m_positionStartOffset, m_positionNode, m_positionEndOffset)); + return new RangeImpl(m_positionNode->getDocument(), m_positionNode, m_positionStartOffset, m_positionNode, m_positionEndOffset); } // otherwise, return the end of the overall range we were given if (m_endContainer) - return RefPtr(new RangeImpl(m_endContainer->getDocument(), - m_endContainer, m_endOffset, m_endContainer, m_endOffset)); + return new RangeImpl(m_endContainer->getDocument(), m_endContainer, m_endOffset, m_endContainer, m_endOffset); - return RefPtr(); + return 0; } SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator() : m_positionNode(0) @@ -712,13 +710,12 @@ void SimplifiedBackwardsTextIterator::emitNewlineForBROrText() } } -RefPtr SimplifiedBackwardsTextIterator::range() const +PassRefPtr SimplifiedBackwardsTextIterator::range() const { - if (m_positionNode) { - return RefPtr(new RangeImpl(m_positionNode->getDocument(), m_positionNode, m_positionStartOffset, m_positionNode, m_positionEndOffset)); - } else { - return RefPtr(new RangeImpl(m_startNode->getDocument(), m_startNode, m_startOffset, m_startNode, m_startOffset)); - } + if (m_positionNode) + return new RangeImpl(m_positionNode->getDocument(), m_positionNode, m_positionStartOffset, m_positionNode, m_positionEndOffset); + + return new RangeImpl(m_startNode->getDocument(), m_startNode, m_startOffset, m_startNode, m_startOffset); } CharacterIterator::CharacterIterator() @@ -734,9 +731,9 @@ CharacterIterator::CharacterIterator(const RangeImpl *r) } } -RefPtr CharacterIterator::range() const +PassRefPtr CharacterIterator::range() const { - RefPtr r = m_textIterator.range(); + PassRefPtr r = m_textIterator.range(); if (!m_textIterator.atEnd()) { if (m_textIterator.length() <= 1) { assert(m_runOffset == 0); @@ -1071,7 +1068,7 @@ QString plainText(const RangeImpl *r) return result; } -RefPtr findPlainText(const RangeImpl *r, const QString &s, bool forward, bool caseSensitive) +PassRefPtr findPlainText(const RangeImpl *r, const QString &s, bool forward, bool caseSensitive) { // FIXME: Can we do Boyer-Moore or equivalent instead for speed? @@ -1081,7 +1078,7 @@ RefPtr findPlainText(const RangeImpl *r, const QString &s, bool forwa int exception = 0; RangeImpl *result = r->cloneRange(exception); result->collapse(forward, exception); - return RefPtr(result); + return result; } CircularSearchBuffer buffer(s, caseSensitive); @@ -1139,7 +1136,7 @@ done: it.advance(buffer.length() - 1); result->setEnd(it.range()->endContainer(exception), it.range()->endOffset(exception), exception); } - return RefPtr(result); + return result; } } diff --git a/WebCore/khtml/editing/visible_text.h b/WebCore/khtml/editing/visible_text.h index 34fdac552f5..8ae2969b554 100644 --- a/WebCore/khtml/editing/visible_text.h +++ b/WebCore/khtml/editing/visible_text.h @@ -51,7 +51,7 @@ inline bool isCollapsibleWhitespace(const QChar &c) } QString plainText(const DOM::RangeImpl *); -RefPtr findPlainText(const DOM::RangeImpl *, const QString &, bool forward, bool caseSensitive); +PassRefPtr findPlainText(const DOM::RangeImpl *, const QString &, bool forward, bool caseSensitive); // Iterates through the DOM range, returning all the text, and 0-length boundaries // at points where replaced elements break up the text flow. The text comes back in @@ -71,7 +71,7 @@ public: int length() const { return m_textLength; } const QChar *characters() const { return m_textCharacters; } - RefPtr range() const; + PassRefPtr range() const; static int TextIterator::rangeLength(const DOM::RangeImpl *r); static DOM::RangeImpl *TextIterator::rangeFromLocationAndLength(DOM::DocumentImpl *doc, int rangeLocation, int rangeLength); @@ -136,7 +136,7 @@ public: int length() const { return m_textLength; } const QChar *characters() const { return m_textCharacters; } - RefPtr range() const; + PassRefPtr range() const; private: void exitNode(); @@ -189,7 +189,7 @@ public: QString string(int numChars); int characterOffset() const { return m_offset; } - RefPtr range() const; + PassRefPtr range() const; private: int m_offset; @@ -213,7 +213,7 @@ public: const QChar *characters() const; // Range of the text we're currently returning - RefPtr range() const { return m_range; } + PassRefPtr range() const { return m_range; } private: // text from the previous chunk from the textIterator @@ -226,7 +226,7 @@ private: // Did we have to look ahead in the textIterator to confirm the current chunk? bool m_didLookAhead; - RefPtr m_range; + PassRefPtr m_range; TextIterator m_textIterator; }; diff --git a/WebCore/khtml/editing/wrap_contents_in_dummy_span_command.cpp b/WebCore/khtml/editing/wrap_contents_in_dummy_span_command.cpp index e11b4c19b17..4de2d31ff98 100644 --- a/WebCore/khtml/editing/wrap_contents_in_dummy_span_command.cpp +++ b/WebCore/khtml/editing/wrap_contents_in_dummy_span_command.cpp @@ -37,20 +37,9 @@ using DOM::ElementImpl; namespace khtml { WrapContentsInDummySpanCommand::WrapContentsInDummySpanCommand(DOM::DocumentImpl *document, DOM::ElementImpl *element) - : EditCommand(document), m_element(element), m_dummySpan(0) + : EditCommand(document), m_element(element) { ASSERT(m_element); - - m_element->ref(); -} - -WrapContentsInDummySpanCommand::~WrapContentsInDummySpanCommand() -{ - if (m_dummySpan) - m_dummySpan->deref(); - - ASSERT(m_element); - m_element->deref(); } void WrapContentsInDummySpanCommand::doApply() @@ -59,17 +48,15 @@ void WrapContentsInDummySpanCommand::doApply() int exceptionCode = 0; - if (!m_dummySpan) { + if (!m_dummySpan) m_dummySpan = createStyleSpanElement(document()); - m_dummySpan->ref(); - } - + while (m_element->firstChild()) { m_dummySpan->appendChild(m_element->firstChild(), exceptionCode); ASSERT(exceptionCode == 0); } - m_element->appendChild(m_dummySpan, exceptionCode); + m_element->appendChild(m_dummySpan.get(), exceptionCode); ASSERT(exceptionCode == 0); } @@ -88,7 +75,7 @@ void WrapContentsInDummySpanCommand::doUnapply() ASSERT(exceptionCode == 0); } - m_element->removeChild(m_dummySpan, exceptionCode); + m_element->removeChild(m_dummySpan.get(), exceptionCode); ASSERT(exceptionCode == 0); } diff --git a/WebCore/khtml/editing/wrap_contents_in_dummy_span_command.h b/WebCore/khtml/editing/wrap_contents_in_dummy_span_command.h index 2afa7678717..434803c11cd 100644 --- a/WebCore/khtml/editing/wrap_contents_in_dummy_span_command.h +++ b/WebCore/khtml/editing/wrap_contents_in_dummy_span_command.h @@ -34,14 +34,14 @@ class WrapContentsInDummySpanCommand : public EditCommand { public: WrapContentsInDummySpanCommand(DOM::DocumentImpl *, DOM::ElementImpl *); - virtual ~WrapContentsInDummySpanCommand(); + virtual ~WrapContentsInDummySpanCommand() { } virtual void doApply(); virtual void doUnapply(); private: - DOM::ElementImpl *m_element; - DOM::ElementImpl *m_dummySpan; + RefPtr m_element; + RefPtr m_dummySpan; }; } // namespace khtml diff --git a/WebCore/kwq/DOMHTML.mm b/WebCore/kwq/DOMHTML.mm index f38804d5a21..e6aef4f5068 100644 --- a/WebCore/kwq/DOMHTML.mm +++ b/WebCore/kwq/DOMHTML.mm @@ -552,13 +552,13 @@ using DOM::NodeImpl; - (DOMDocumentFragment *)_createDocumentFragmentWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString { - DocumentFragmentImpl *fragment = createFragmentFromMarkup([self _documentImpl], QString::fromNSString(markupString), QString::fromNSString(baseURLString)); - return [DOMDocumentFragment _documentFragmentWithImpl:fragment]; + RefPtr fragment = createFragmentFromMarkup([self _documentImpl], QString::fromNSString(markupString), QString::fromNSString(baseURLString)); + return [DOMDocumentFragment _documentFragmentWithImpl:fragment.get()]; } - (DOMDocumentFragment *)_createDocumentFragmentWithText:(NSString *)text { - return [DOMDocumentFragment _documentFragmentWithImpl:createFragmentFromText([self _documentImpl], QString::fromNSString(text))]; + return [DOMDocumentFragment _documentFragmentWithImpl:createFragmentFromText([self _documentImpl], QString::fromNSString(text)).get()]; } @end diff --git a/WebCore/kwq/WebCoreBridge.mm b/WebCore/kwq/WebCoreBridge.mm index 59c51bce773..5e7f5d639ab 100644 --- a/WebCore/kwq/WebCoreBridge.mm +++ b/WebCore/kwq/WebCoreBridge.mm @@ -1881,8 +1881,8 @@ static HTMLFormElementImpl *formElementFromDOMElement(DOMElement *element) if (!_part || !_part->xmlDocImpl()) return 0; - DocumentFragmentImpl *fragment = createFragmentFromMarkup(_part->xmlDocImpl(), QString::fromNSString(markupString), QString::fromNSString(baseURLString)); - return [DOMDocumentFragment _documentFragmentWithImpl:fragment]; + PassRefPtr fragment = createFragmentFromMarkup(_part->xmlDocImpl(), QString::fromNSString(markupString), QString::fromNSString(baseURLString)); + return [DOMDocumentFragment _documentFragmentWithImpl:fragment.get()]; } - (DOMDocumentFragment *)documentFragmentWithText:(NSString *)text @@ -1890,7 +1890,7 @@ static HTMLFormElementImpl *formElementFromDOMElement(DOMElement *element) if (!partHasSelection(self) || !text) return 0; - return [DOMDocumentFragment _documentFragmentWithImpl:createFragmentFromText(_part->xmlDocImpl(), QString::fromNSString(text))]; + return [DOMDocumentFragment _documentFragmentWithImpl:createFragmentFromText(_part->xmlDocImpl(), QString::fromNSString(text)).get()]; } - (DOMDocumentFragment *)documentFragmentWithNodesAsParagraphs:(NSArray *)nodes @@ -1906,7 +1906,7 @@ static HTMLFormElementImpl *formElementFromDOMElement(DOMElement *element) nodeList.append([node _nodeImpl]); } - return [DOMDocumentFragment _documentFragmentWithImpl:createFragmentFromNodeList(_part->xmlDocImpl(), nodeList)]; + return [DOMDocumentFragment _documentFragmentWithImpl:createFragmentFromNodeList(_part->xmlDocImpl(), nodeList).get()]; } - (void)replaceSelectionWithFragment:(DOMDocumentFragment *)fragment selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace matchStyle:(BOOL)matchStyle -- GitLab