+2006-02-09 Darin Adler <darin@apple.com>
+
+ Reviewed by Eric and Geoff.
+
+ - changed basic DOM mutation calls to assert that "this"
+ is not floating, then added more uses of RefPtr to prevent the
+ assertion from firing (at least during my testing and layout tests)
+
+ - removed use of PassRefPtr as the type of a local variable; after talking
+ with Maciej and Eric, this type of use is now "deprecated"
+
+ * bindings/js/JSDOMCore.cpp: Touched this file to get things to build.
+
+ * bindings/objc/DOM.mm:
+ (-[DOMRange extractContents]):
+ (-[DOMRange cloneContents]):
+ (-[DOMRange cloneRange]):
+ * khtml/ecma/kjs_range.cpp:
+ (KJS::DOMRange::getValueProperty):
+ (KJS::DOMRangeProtoFunc::callAsFunction):
+ * khtml/editing/Selection.cpp:
+ (WebCore::Selection::toRange):
+ * bridge/mac/WebCoreFrameBridge.mm:
+ (-[WebCoreFrameBridge documentFragmentWithMarkupString:baseURLString:]):
+ * dom/ContainerNodeImpl.cpp:
+ (WebCore::ContainerNodeImpl::insertBefore):
+ (WebCore::ContainerNodeImpl::replaceChild):
+ (WebCore::ContainerNodeImpl::removeChild):
+ (WebCore::ContainerNodeImpl::appendChild):
+ * dom/DocPtr.h: Removed uses of NULL and unused deprecated functions.
+ * dom/dom2_rangeimpl.h:
+ * dom/dom2_rangeimpl.cpp:
+ (WebCore::RangeImpl::RangeImpl):
+ (WebCore::RangeImpl::startContainer):
+ (WebCore::RangeImpl::endContainer):
+ (WebCore::RangeImpl::commonAncestorContainer):
+ (WebCore::RangeImpl::setStart):
+ (WebCore::RangeImpl::setEnd):
+ (WebCore::RangeImpl::collapse):
+ (WebCore::RangeImpl::compareBoundaryPoints):
+ (WebCore::RangeImpl::boundaryPointsValid):
+ (WebCore::RangeImpl::processContents):
+ (WebCore::RangeImpl::extractContents):
+ (WebCore::RangeImpl::cloneContents):
+ (WebCore::RangeImpl::insertNode):
+ (WebCore::RangeImpl::createContextualFragment):
+ (WebCore::RangeImpl::detach):
+ (WebCore::RangeImpl::cloneRange):
+ (WebCore::RangeImpl::selectNodeContents):
+ (WebCore::RangeImpl::surroundContents):
+ (WebCore::RangeImpl::containedByReadOnly):
+ (WebCore::RangeImpl::startPosition):
+ (WebCore::RangeImpl::endPosition):
+ (WebCore::RangeImpl::startNode):
+ (WebCore::RangeImpl::editingStartPosition):
+ (WebCore::rangeOfContents):
+ * dom/dom_elementimpl.h:
+ * dom/dom_elementimpl.cpp:
+ (WebCore::AttrImpl::AttrImpl):
+ (WebCore::AttrImpl::~AttrImpl):
+ (WebCore::AttrImpl::setValue):
+ (WebCore::AttrImpl::childTypeAllowed):
+ (WebCore::AttrImpl::childrenChanged):
+ (WebCore::ElementImpl::removeAttributeNode):
+ (WebCore::NamedAttrMapImpl::clearAttributes):
+ (WebCore::CSSMappedAttributeDeclarationImpl::~CSSMappedAttributeDeclarationImpl):
+ (WebCore::MappedAttributeImpl::clone):
+ * dom/DocumentFragmentImpl.cpp:
+ (DOM::DocumentFragmentImpl::cloneNode):
+ * dom/dom_xmlimpl.cpp:
+ (WebCore::EntityReferenceImpl::cloneNode):
+ (WebCore::ProcessingInstructionImpl::ProcessingInstructionImpl):
+ (WebCore::ProcessingInstructionImpl::checkStyleSheet):
+ (WebCore::ProcessingInstructionImpl::setStyleSheet):
+ * dom/dom_position.cpp:
+ * khtml/editing/break_blockquote_command.cpp:
+ (WebCore::BreakBlockquoteCommand::doApply):
+ * khtml/editing/composite_edit_command.cpp:
+ (WebCore::CompositeEditCommand::appendBlockPlaceholder):
+ (WebCore::CompositeEditCommand::insertBlockPlaceholder):
+ (WebCore::CompositeEditCommand::moveParagraphContentsToNewBlockIfNecessary):
+ (WebCore::createBlockPlaceholderElement):
+ * khtml/editing/delete_selection_command.cpp:
+ (WebCore::DeleteSelectionCommand::insertPlaceholderForAncestorBlockContent):
+ (WebCore::DeleteSelectionCommand::moveNodesAfterNode):
+ * khtml/editing/html_interchange.cpp:
+ * khtml/editing/htmlediting.cpp:
+ (WebCore::rebalanceWhitespaceInTextNode):
+ (WebCore::nonBreakingSpaceString):
+ (WebCore::createDefaultParagraphElement):
+ (WebCore::createBreakElement):
+ (WebCore::createTabSpanElement):
+ * khtml/editing/insert_line_break_command.cpp:
+ (khtml::InsertLineBreakCommand::doApply):
+ * khtml/editing/insert_paragraph_separator_command.cpp:
+ (WebCore::InsertParagraphSeparatorCommand::doApply):
+ * khtml/editing/insert_paragraph_separator_command.h:
+ * khtml/editing/insert_text_command.cpp:
+ (khtml::InsertTextCommand::insertTab):
+ * khtml/editing/markup.cpp:
+ (khtml::createFragmentFromMarkup):
+ (khtml::createParagraphContentsFromString):
+ (khtml::createFragmentFromText):
+ (khtml::createFragmentFromNodeList):
+ * khtml/editing/rebalance_whitespace_command.cpp:
+ * khtml/editing/replace_selection_command.cpp:
+ (WebCore::ReplacementFragment::ReplacementFragment):
+ (WebCore::ReplacementFragment::insertFragmentForTestRendering):
+ (WebCore::ReplaceSelectionCommand::doApply):
+ * khtml/editing/visible_text.cpp:
+ (khtml::CharacterIterator::range):
+ (khtml::findPlainText):
+ * khtml/html/HTMLElementImpl.cpp:
+ (WebCore::HTMLElementImpl::cloneNode):
+ * khtml/html/htmlparser.cpp:
+ (HTMLParser::handleResidualStyleCloseTagAcrossBlocks):
+ * ksvg2/svg/SVGTransformableImpl.cpp:
+ (SVGTransformableImpl::parseTransformAttribute):
+ * ksvg2/svg/SVGUseElementImpl.cpp:
+ (SVGUseElementImpl::closeRenderer):
+
2006-02-09 Alexander Kellett <lypanov@kde.org>
Reviewed and landed by Maciej.
#include "config.h"
-// These are generated files
+// These are generated files.
#include "JSAttr.cpp"
#include "JSCharacterData.cpp"
- (DOMDocumentFragment *)extractContents
{
int exceptionCode = 0;
- DOMDocumentFragment *result = [DOMDocumentFragment _documentFragmentWithImpl:[self _rangeImpl]->extractContents(exceptionCode)];
+ DOMDocumentFragment *result = [DOMDocumentFragment _documentFragmentWithImpl:[self _rangeImpl]->extractContents(exceptionCode).get()];
raiseOnDOMError(exceptionCode);
return result;
}
- (DOMDocumentFragment *)cloneContents
{
int exceptionCode = 0;
- DOMDocumentFragment *result = [DOMDocumentFragment _documentFragmentWithImpl:[self _rangeImpl]->cloneContents(exceptionCode)];
+ DOMDocumentFragment *result = [DOMDocumentFragment _documentFragmentWithImpl:[self _rangeImpl]->cloneContents(exceptionCode).get()];
raiseOnDOMError(exceptionCode);
return result;
}
- (DOMRange *)cloneRange
{
int exceptionCode = 0;
- DOMRange *result = [DOMRange _rangeWithImpl:[self _rangeImpl]->cloneRange(exceptionCode)];
+ DOMRange *result = [DOMRange _rangeWithImpl:[self _rangeImpl]->cloneRange(exceptionCode).get()];
raiseOnDOMError(exceptionCode);
return result;
}
if (!m_frame || !m_frame->document())
return 0;
- PassRefPtr<DocumentFragmentImpl> fragment = createFragmentFromMarkup(m_frame->document(), QString::fromNSString(markupString), QString::fromNSString(baseURLString));
- return [DOMDocumentFragment _documentFragmentWithImpl:fragment.get()];
+ return [DOMDocumentFragment _documentFragmentWithImpl:createFragmentFromMarkup(m_frame->document(),
+ QString::fromNSString(markupString), QString::fromNSString(baseURLString)).get()];
}
- (DOMDocumentFragment *)documentFragmentWithText:(NSString *)text
bool ContainerNodeImpl::insertBefore(PassRefPtr<NodeImpl> newChild, NodeImpl* refChild, ExceptionCode& ec)
{
+ // Check that this node is not "floating".
+ // If it is, it can be deleted as a side effect of sending mutation events.
+ ASSERT(refCount() || parent());
+
ec = 0;
// insertBefore(node, 0) is equivalent to appendChild(node)
bool ContainerNodeImpl::replaceChild(PassRefPtr<NodeImpl> newChild, NodeImpl* oldChild, ExceptionCode& ec)
{
+ // Check that this node is not "floating".
+ // If it is, it can be deleted as a side effect of sending mutation events.
+ ASSERT(refCount() || parent());
+
ec = 0;
if (oldChild == newChild) // nothing to do
bool ContainerNodeImpl::removeChild(NodeImpl* oldChild, ExceptionCode& ec)
{
+ // Check that this node is not "floating".
+ // If it is, it can be deleted as a side effect of sending mutation events.
+ ASSERT(refCount() || parent());
+
ec = 0;
// NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
bool ContainerNodeImpl::appendChild(PassRefPtr<NodeImpl> newChild, ExceptionCode& ec)
{
+ // Check that this node is not "floating".
+ // If it is, it can be deleted as a side effect of sending mutation events.
+ ASSERT(refCount() || parent());
+
ec = 0;
// Make sure adding the new child is ok
// -*- mode: c++; c-basic-offset: 4 -*-
/*
* This file is part of the DOM implementation for KDE.
- * Copyright (C) 2005 Apple Computer, Inc.
+ * Copyright (C) 2005, 2006 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* Boston, MA 02111-1307, USA.
*
*/
+
#ifndef DOM_DocPtr_h
#define DOM_DocPtr_h
template <class T> class DocPtr
{
public:
- DocPtr() : m_ptr(NULL) {}
+ DocPtr() : m_ptr(0) {}
DocPtr(T *ptr) : m_ptr(ptr) { if (ptr) ptr->selfOnlyRef(); }
DocPtr(const DocPtr &o) : m_ptr(o.m_ptr) { if (T *ptr = m_ptr) ptr->selfOnlyRefRef(); }
~DocPtr() { if (T *ptr = m_ptr) ptr->selfOnlyDeref(); }
template <class U> DocPtr(const DocPtr<U> &o) : m_ptr(o.get()) { if (T *ptr = m_ptr) ptr->selfOnlyRef(); }
- // FIXME: Deprecate in favor of operators below, then remove?
- bool isNull() const { return m_ptr == NULL; }
- bool notNull() const { return m_ptr != NULL; }
-
- // FIXME: Deprecate in favor of operator=, then remove?
- void reset() { if (T *ptr = m_ptr) ptr->selfOnlyDeref(); m_ptr = NULL; }
- void reset(T *o) { if (o) o->selfOnlyRef(); if (T *ptr = m_ptr) ptr->selfOnlyDeref(); m_ptr = o; }
-
void resetSkippingRef(T *o) { m_ptr = o; }
T *get() const { return m_ptr; }
T &operator*() const { return *m_ptr; }
T *operator->() const { return m_ptr; }
- bool operator!() const { return m_ptr == NULL; }
+ bool operator!() const { return !m_ptr; }
// this type conversion operator allows implicit conversion to
// bool but not to other integer types
PassRefPtr<NodeImpl> DocumentFragmentImpl::cloneNode(bool deep)
{
- PassRefPtr<DocumentFragmentImpl> clone = new DocumentFragmentImpl(getDocument());
+ RefPtr<DocumentFragmentImpl> clone = new DocumentFragmentImpl(getDocument());
if (deep)
cloneChildNodes(clone.get());
- return clone;
+ return clone.release();
}
}
#include "dom2_rangeimpl.h"
#include "DocumentImpl.h"
-#include "dom/dom_exception.h"
+#include "dom_exception.h"
#include "dom_textimpl.h"
#include "dom_xmlimpl.h"
#include "HTMLElementImpl.h"
-#include "editing/markup.h"
-#include "editing/visible_position.h"
-#include "editing/visible_units.h"
-#include "editing/visible_text.h"
+#include "markup.h"
+#include "visible_position.h"
+#include "visible_units.h"
+#include "visible_text.h"
#include "dom_position.h"
-
#include "RenderBlock.h"
-using khtml::createMarkup;
-using khtml::RenderBlock;
-using khtml::RenderObject;
-using khtml::VisiblePosition;
-using khtml::DOWNSTREAM;
-using khtml::isEndOfParagraph;
-
-namespace DOM {
-
-RangeImpl::RangeImpl(DocumentImpl *_ownerDocument)
-{
- m_ownerDocument = _ownerDocument;
- m_ownerDocument->ref();
- m_startContainer = _ownerDocument;
- m_startContainer->ref();
- m_endContainer = _ownerDocument;
- m_endContainer->ref();
- m_startOffset = 0;
- m_endOffset = 0;
- m_detached = false;
-}
+namespace WebCore {
-RangeImpl::RangeImpl(DocumentImpl *_ownerDocument,
- NodeImpl *_startContainer, int _startOffset,
- NodeImpl *_endContainer, int _endOffset)
+RangeImpl::RangeImpl(DocumentImpl* ownerDocument)
+ : m_ownerDocument(ownerDocument)
+ , m_startContainer(ownerDocument), m_startOffset(0)
+ , m_endContainer(ownerDocument), m_endOffset(0)
+ , m_detached(false)
{
- m_ownerDocument = _ownerDocument;
- m_ownerDocument->ref();
- m_startContainer = _startContainer;
- m_startContainer->ref();
- m_startOffset = _startOffset;
- m_endContainer = _endContainer;
- m_endContainer->ref();
- m_endOffset = _endOffset;
- m_detached = false;
}
-RangeImpl::~RangeImpl()
+RangeImpl::RangeImpl(DocumentImpl* ownerDocument,
+ NodeImpl* startContainer, int startOffset,
+ NodeImpl* endContainer, int endOffset)
+ : m_ownerDocument(ownerDocument)
+ , m_startContainer(startContainer), m_startOffset(startOffset)
+ , m_endContainer(endContainer), m_endOffset(endOffset)
+ , m_detached(false)
{
- m_ownerDocument->deref();
- int exceptioncode = 0;
- if (!m_detached)
- detach(exceptioncode);
}
NodeImpl *RangeImpl::startContainer(int &exceptioncode) const
return 0;
}
- return m_startContainer;
+ return m_startContainer.get();
}
int RangeImpl::startOffset(int &exceptioncode) const
return 0;
}
- return m_endContainer;
+ return m_endContainer.get();
}
int RangeImpl::endOffset(int &exceptioncode) const
return 0;
}
- NodeImpl *com = commonAncestorContainer(m_startContainer,m_endContainer);
+ NodeImpl *com = commonAncestorContainer(m_startContainer.get(), m_endContainer.get());
if (!com) // should never happen
exceptioncode = DOMException::WRONG_DOCUMENT_ERR;
return com;
if (exceptioncode)
return;
- setStartContainer(refNode);
+ m_startContainer = refNode;
m_startOffset = offset;
// check if different root container
- NodeImpl *endRootContainer = m_endContainer;
+ NodeImpl* endRootContainer = m_endContainer.get();
while (endRootContainer->parentNode())
endRootContainer = endRootContainer->parentNode();
- NodeImpl *startRootContainer = m_startContainer;
+ NodeImpl* startRootContainer = m_startContainer.get();
while (startRootContainer->parentNode())
startRootContainer = startRootContainer->parentNode();
if (startRootContainer != endRootContainer)
- collapse(true,exceptioncode);
+ collapse(true, exceptioncode);
// check if new start after end
- else if (compareBoundaryPoints(m_startContainer,m_startOffset,m_endContainer,m_endOffset) > 0)
- collapse(true,exceptioncode);
+ else if (compareBoundaryPoints(m_startContainer.get(), m_startOffset, m_endContainer.get(), m_endOffset) > 0)
+ collapse(true, exceptioncode);
}
void RangeImpl::setEnd( NodeImpl *refNode, int offset, int &exceptioncode )
if (exceptioncode)
return;
- setEndContainer(refNode);
+ m_endContainer = refNode;
m_endOffset = offset;
// check if different root container
- NodeImpl *endRootContainer = m_endContainer;
+ NodeImpl* endRootContainer = m_endContainer.get();
while (endRootContainer->parentNode())
endRootContainer = endRootContainer->parentNode();
- NodeImpl *startRootContainer = m_startContainer;
+ NodeImpl* startRootContainer = m_startContainer.get();
while (startRootContainer->parentNode())
startRootContainer = startRootContainer->parentNode();
if (startRootContainer != endRootContainer)
- collapse(false,exceptioncode);
+ collapse(false, exceptioncode);
// check if new end before start
- if (compareBoundaryPoints(m_startContainer,m_startOffset,m_endContainer,m_endOffset) > 0)
- collapse(false,exceptioncode);
+ if (compareBoundaryPoints(m_startContainer.get(), m_startOffset, m_endContainer.get(), m_endOffset) > 0)
+ collapse(false, exceptioncode);
}
void RangeImpl::collapse( bool toStart, int &exceptioncode )
return;
}
- if( toStart ) // collapse to start
- {
- setEndContainer(m_startContainer);
+ if (toStart) { // collapse to start
+ m_endContainer = m_startContainer;
m_endOffset = m_startOffset;
- }
- else // collapse to end
- {
- setStartContainer(m_endContainer);
+ } else { // collapse to end
+ m_startContainer = m_endContainer;
m_startOffset = m_endOffset;
}
}
switch(how)
{
case Range::START_TO_START:
- return compareBoundaryPoints( m_startContainer, m_startOffset,
+ return compareBoundaryPoints( m_startContainer.get(), m_startOffset,
sourceRange->startContainer(exceptioncode), sourceRange->startOffset(exceptioncode) );
break;
case Range::START_TO_END:
- return compareBoundaryPoints( m_startContainer, m_startOffset,
+ return compareBoundaryPoints( m_startContainer.get(), m_startOffset,
sourceRange->endContainer(exceptioncode), sourceRange->endOffset(exceptioncode) );
break;
case Range::END_TO_END:
- return compareBoundaryPoints( m_endContainer, m_endOffset,
+ return compareBoundaryPoints( m_endContainer.get(), m_endOffset,
sourceRange->endContainer(exceptioncode), sourceRange->endOffset(exceptioncode) );
break;
case Range::END_TO_START:
- return compareBoundaryPoints( m_endContainer, m_endOffset,
+ return compareBoundaryPoints( m_endContainer.get(), m_endOffset,
sourceRange->startContainer(exceptioncode), sourceRange->startOffset(exceptioncode) );
break;
default:
return compareBoundaryPoints(a.node(), a.offset(), b.node(), b.offset());
}
-bool RangeImpl::boundaryPointsValid( ) const
+bool RangeImpl::boundaryPointsValid() const
{
- return compareBoundaryPoints( m_startContainer, m_startOffset, m_endContainer, m_endOffset ) <= 0;
+ return compareBoundaryPoints(m_startContainer.get(), m_startOffset, m_endContainer.get(), m_endOffset) <= 0;
}
void RangeImpl::deleteContents( int &exceptioncode ) {
processContents(DELETE_CONTENTS,exceptioncode);
}
-DocumentFragmentImpl *RangeImpl::processContents ( ActionType action, int &exceptioncode )
+PassRefPtr<DocumentFragmentImpl> RangeImpl::processContents ( ActionType action, int &exceptioncode )
{
// ### when mutation events are implemented, we will have to take into account
// situations where the tree is being transformed while we delete - ugh!
// what is the highest node that partially selects the start of the range?
NodeImpl *partialStart = 0;
if (m_startContainer != cmnRoot) {
- partialStart = m_startContainer;
+ partialStart = m_startContainer.get();
while (partialStart->parentNode() != cmnRoot)
partialStart = partialStart->parentNode();
}
// what is the highest node that partially selects the end of the range?
NodeImpl *partialEnd = 0;
if (m_endContainer != cmnRoot) {
- partialEnd = m_endContainer;
+ partialEnd = m_endContainer.get();
while (partialEnd->parentNode() != cmnRoot)
partialEnd = partialEnd->parentNode();
}
- DocumentFragmentImpl *fragment = 0;
+ RefPtr<DocumentFragmentImpl> fragment;
if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS)
fragment = new DocumentFragmentImpl(m_ownerDocument.get());
m_startContainer->nodeType() == Node::COMMENT_NODE) {
if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) {
- PassRefPtr<CharacterDataImpl> c = static_pointer_cast<CharacterDataImpl>(m_startContainer->cloneNode(true));
- c->deleteData(m_endOffset,static_cast<CharacterDataImpl*>(m_startContainer)->length()-m_endOffset,exceptioncode);
- c->deleteData(0,m_startOffset,exceptioncode);
- fragment->appendChild(c, exceptioncode);
+ RefPtr<CharacterDataImpl> c = static_pointer_cast<CharacterDataImpl>(m_startContainer->cloneNode(true));
+ c->deleteData(m_endOffset, c->length() - m_endOffset, exceptioncode);
+ c->deleteData(0, m_startOffset, exceptioncode);
+ fragment->appendChild(c.release(), exceptioncode);
}
if (action == EXTRACT_CONTENTS || action == DELETE_CONTENTS)
- static_cast<CharacterDataImpl*>(m_startContainer)->deleteData(m_startOffset,m_endOffset-m_startOffset,exceptioncode);
+ static_cast<CharacterDataImpl*>(m_startContainer.get())->deleteData(m_startOffset,m_endOffset-m_startOffset,exceptioncode);
}
else if (m_startContainer->nodeType() == Node::PROCESSING_INSTRUCTION_NODE) {
// ### operate just on data ?
fragment->appendChild(n,exceptioncode); // will remove n from it's parent
else if (action == CLONE_CONTENTS)
fragment->appendChild(n->cloneNode(true),exceptioncode);
- else {
- n->ref();
+ else
m_startContainer->removeChild(n,exceptioncode);
- n->deref();
- }
n = next;
i++;
}
}
if (action == EXTRACT_CONTENTS || action == DELETE_CONTENTS)
collapse(true,exceptioncode);
- return fragment;
+ return fragment.release();
}
// Complex case: Start and end containers are different.
m_startContainer->nodeType() == Node::COMMENT_NODE) {
if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) {
- PassRefPtr<CharacterDataImpl> c = static_pointer_cast<CharacterDataImpl>(m_startContainer->cloneNode(true));
- c->deleteData(0,m_startOffset,exceptioncode);
- leftContents = c;
+ RefPtr<CharacterDataImpl> c = static_pointer_cast<CharacterDataImpl>(m_startContainer->cloneNode(true));
+ c->deleteData(0, m_startOffset, exceptioncode);
+ leftContents = c.release();
}
if (action == EXTRACT_CONTENTS || action == DELETE_CONTENTS)
- static_cast<CharacterDataImpl*>(m_startContainer)->deleteData(
- m_startOffset,static_cast<CharacterDataImpl*>(m_startContainer)->length()-m_startOffset,exceptioncode);
+ static_cast<CharacterDataImpl*>(m_startContainer.get())->deleteData(
+ m_startOffset, static_cast<CharacterDataImpl*>(m_startContainer.get())->length() - m_startOffset, exceptioncode);
}
else if (m_startContainer->nodeType() == Node::PROCESSING_INSTRUCTION_NODE) {
// ### operate just on data ?
leftContents->appendChild(n,exceptioncode); // will remove n from m_startContainer
else if (action == CLONE_CONTENTS)
leftContents->appendChild(n->cloneNode(true),exceptioncode);
- else {
- n->ref();
+ else
m_startContainer->removeChild(n,exceptioncode);
- n->deref();
- }
n = next;
}
}
leftContents->appendChild(n,exceptioncode); // will remove n from leftParent
else if (action == CLONE_CONTENTS)
leftContents->appendChild(n->cloneNode(true),exceptioncode);
- else {
- n->ref();
+ else
leftParent->removeChild(n,exceptioncode);
- n->deref();
- }
}
n = leftParent->nextSibling();
}
if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) {
RefPtr<CharacterDataImpl> c = static_pointer_cast<CharacterDataImpl>(m_endContainer->cloneNode(true));
- c->deleteData(m_endOffset,static_cast<CharacterDataImpl*>(m_endContainer)->length()-m_endOffset,exceptioncode);
+ c->deleteData(m_endOffset, static_cast<CharacterDataImpl*>(m_endContainer.get())->length() - m_endOffset, exceptioncode);
rightContents = c;
}
if (action == EXTRACT_CONTENTS || action == DELETE_CONTENTS)
- static_cast<CharacterDataImpl*>(m_endContainer)->deleteData(0,m_endOffset,exceptioncode);
+ static_cast<CharacterDataImpl*>(m_endContainer.get())->deleteData(0, m_endOffset, exceptioncode);
}
else if (m_startContainer->nodeType() == Node::PROCESSING_INSTRUCTION_NODE) {
// ### operate just on data ?
rightContents->insertBefore(n,rightContents->firstChild(),exceptioncode); // will remove n from it's parent
else if (action == CLONE_CONTENTS)
rightContents->insertBefore(n->cloneNode(true),rightContents->firstChild(),exceptioncode);
- else {
- n->ref();
+ else
rightParent->removeChild(n,exceptioncode);
- n->deref();
- }
-
}
n = rightParent->previousSibling();
}
processStart = processStart->nextSibling();
}
else {
- processStart = m_startContainer;
+ processStart = m_startContainer.get();
while (processStart->parentNode() != cmnRoot)
processStart = processStart->parentNode();
processStart = processStart->nextSibling();
processEnd = processEnd->nextSibling();
}
else {
- processEnd = m_endContainer;
+ processEnd = m_endContainer.get();
while (processEnd->parentNode() != cmnRoot)
processEnd = processEnd->parentNode();
}
fragment->appendChild(n,exceptioncode); // will remove from cmnRoot
else if (action == CLONE_CONTENTS)
fragment->appendChild(n->cloneNode(true),exceptioncode);
- else {
- n->ref();
+ else
cmnRoot->removeChild(n,exceptioncode);
- n->deref();
- }
}
}
if (!partialStart && !partialEnd)
collapse(true,exceptioncode);
else if (partialStart) {
- setStartContainer(partialStart->parentNode());
- setEndContainer(partialStart->parentNode());
+ m_startContainer = partialStart->parentNode();
+ m_endContainer = partialStart->parentNode();
m_startOffset = m_endOffset = partialStart->nodeIndex()+1;
}
else if (partialEnd) {
- setStartContainer(partialEnd->parentNode());
- setEndContainer(partialEnd->parentNode());
+ m_startContainer = partialEnd->parentNode();
+ m_endContainer = partialEnd->parentNode();
m_startOffset = m_endOffset = partialEnd->nodeIndex();
}
}
- return fragment;
+ return fragment.release();
}
-DocumentFragmentImpl *RangeImpl::extractContents( int &exceptioncode )
+PassRefPtr<DocumentFragmentImpl> RangeImpl::extractContents( int &exceptioncode )
{
if (m_detached) {
exceptioncode = DOMException::INVALID_STATE_ERR;
return processContents(EXTRACT_CONTENTS,exceptioncode);
}
-DocumentFragmentImpl *RangeImpl::cloneContents( int &exceptioncode )
+PassRefPtr<DocumentFragmentImpl> RangeImpl::cloneContents( int &exceptioncode )
{
if (m_detached) {
exceptioncode = DOMException::INVALID_STATE_ERR;
return processContents(CLONE_CONTENTS,exceptioncode);
}
-void RangeImpl::insertNode( NodeImpl *newNode, int &exceptioncode )
+void RangeImpl::insertNode(PassRefPtr<NodeImpl> newNode, int &exceptioncode )
{
if (m_detached) {
exceptioncode = DOMException::INVALID_STATE_ERR;
if (m_startContainer->nodeType() == Node::TEXT_NODE)
checkAgainst = m_startContainer->parentNode();
else
- checkAgainst = m_startContainer;
+ checkAgainst = m_startContainer.get();
if (newNode->nodeType() == Node::DOCUMENT_FRAGMENT_NODE) {
// check each child node, not the DocumentFragment itself
}
}
- for (NodeImpl *n = m_startContainer; n; n = n->parentNode()) {
+ for (NodeImpl *n = m_startContainer.get(); n; n = n->parentNode()) {
if (n == newNode) {
exceptioncode = DOMException::HIERARCHY_REQUEST_ERR;
return;
if( m_startContainer->nodeType() == Node::TEXT_NODE ||
m_startContainer->nodeType() == Node::CDATA_SECTION_NODE )
{
- TextImpl *newText = static_cast<TextImpl*>(m_startContainer)->splitText(m_startOffset,exceptioncode);
+ TextImpl *newText = static_cast<TextImpl*>(m_startContainer.get())->splitText(m_startOffset,exceptioncode);
if (exceptioncode)
return;
m_startContainer->parentNode()->insertBefore( newNode, newText, exceptioncode );
return khtml::plainText(const_cast<RangeImpl *>(this));
}
-DocumentFragmentImpl *RangeImpl::createContextualFragment(const DOMString &html, int &exceptioncode) const
+PassRefPtr<DocumentFragmentImpl> RangeImpl::createContextualFragment(const DOMString &html, int &exceptioncode) const
{
- if (m_detached) {
+ if (m_detached) {
exceptioncode = DOMException::INVALID_STATE_ERR;
- return NULL;
+ return 0;
}
if (! m_startContainer->isHTMLElement()) {
exceptioncode = DOMException::NOT_SUPPORTED_ERR;
- return NULL;
+ return 0;
}
- HTMLElementImpl *e = static_cast<HTMLElementImpl *>(m_startContainer);
- DocumentFragmentImpl *fragment = e->createContextualFragment(html);
+ RefPtr<DocumentFragmentImpl> fragment = static_cast<HTMLElementImpl*>(m_startContainer.get())->createContextualFragment(html);
if (!fragment) {
exceptioncode = DOMException::NOT_SUPPORTED_ERR;
- return NULL;
+ return 0;
}
- return fragment;
+ return fragment.release();
}
return;
}
- if (m_startContainer)
- m_startContainer->deref();
m_startContainer = 0;
- if (m_endContainer)
- m_endContainer->deref();
m_endContainer = 0;
m_detached = true;
}
}
-RangeImpl *RangeImpl::cloneRange(int &exceptioncode) const
+PassRefPtr<RangeImpl> RangeImpl::cloneRange(int &exceptioncode) const
{
if (m_detached) {
exceptioncode = DOMException::INVALID_STATE_ERR;
return 0;
}
- return new RangeImpl(m_ownerDocument.get(), m_startContainer, m_startOffset, m_endContainer, m_endOffset);
+ return new RangeImpl(m_ownerDocument.get(), m_startContainer.get(), m_startOffset, m_endContainer.get(), m_endOffset);
}
void RangeImpl::setStartAfter( NodeImpl *refNode, int &exceptioncode )
}
}
- setStartContainer(refNode);
+ m_startContainer = refNode;
m_startOffset = 0;
- setEndContainer(refNode);
+ m_endContainer = refNode;
m_endOffset = refNode->childNodeCount();
}
-void RangeImpl::surroundContents( NodeImpl *newParent, int &exceptioncode )
+void RangeImpl::surroundContents(PassRefPtr<NodeImpl> passNewParent, int &exceptioncode )
{
+ RefPtr<NodeImpl> newParent = passNewParent;
+
if (m_detached) {
exceptioncode = DOMException::INVALID_STATE_ERR;
return;
}
- if( !newParent ) {
+ if (!newParent) {
exceptioncode = DOMException::NOT_FOUND_ERR;
return;
}
return;
}
- for (NodeImpl *n = m_startContainer; n; n = n->parentNode()) {
+ for (NodeImpl *n = m_startContainer.get(); n; n = n->parentNode()) {
if (n == newParent) {
exceptioncode = DOMException::HIERARCHY_REQUEST_ERR;
return;
}
}
- while (NodeImpl *n = newParent->firstChild()) {
- n->ref();
- newParent->removeChild(n,exceptioncode);
- n->deref();
+ while (NodeImpl* n = newParent->firstChild()) {
+ newParent->removeChild(n, exceptioncode);
if (exceptioncode)
return;
}
- DocumentFragmentImpl *fragment = extractContents(exceptioncode);
+ RefPtr<DocumentFragmentImpl> fragment = extractContents(exceptioncode);
if (exceptioncode)
return;
- insertNode( newParent, exceptioncode );
+ insertNode(newParent, exceptioncode);
if (exceptioncode)
return;
- newParent->appendChild( fragment, exceptioncode );
+ newParent->appendChild(fragment.release(), exceptioncode);
if (exceptioncode)
return;
- selectNode( newParent, exceptioncode );
+ selectNode(newParent.get(), exceptioncode);
}
void RangeImpl::setStartBefore( NodeImpl *refNode, int &exceptioncode )
setStart( refNode->parentNode(), refNode->nodeIndex(), exceptioncode );
}
-void RangeImpl::setStartContainer(NodeImpl *_startContainer)
-{
- if (m_startContainer == _startContainer)
- return;
-
- if (m_startContainer)
- m_startContainer->deref();
- m_startContainer = _startContainer;
- if (m_startContainer)
- m_startContainer->ref();
-}
-
-void RangeImpl::setEndContainer(NodeImpl *_endContainer)
-{
- if (m_endContainer == _endContainer)
- return;
-
- if (m_endContainer)
- m_endContainer->deref();
- m_endContainer = _endContainer;
- if (m_endContainer)
- m_endContainer->ref();
-}
-
void RangeImpl::checkDeleteExtract(int &exceptioncode)
{
NodeImpl *pastEnd = pastEndNode();
bool RangeImpl::containedByReadOnly() const
{
NodeImpl *n;
- for (n = m_startContainer; n; n = n->parentNode()) {
+ for (n = m_startContainer.get(); n; n = n->parentNode()) {
if (n->isReadOnly())
return true;
}
- for (n = m_endContainer; n; n = n->parentNode()) {
+ for (n = m_endContainer.get(); n; n = n->parentNode()) {
if (n->isReadOnly())
return true;
}
Position RangeImpl::startPosition() const
{
- return Position(m_startContainer, m_startOffset);
+ return Position(m_startContainer.get(), m_startOffset);
}
Position RangeImpl::endPosition() const
{
- return Position(m_endContainer, m_endOffset);
+ return Position(m_endContainer.get(), m_endOffset);
}
NodeImpl *RangeImpl::startNode() const
if (!m_startContainer)
return 0;
if (offsetInCharacters(m_startContainer->nodeType()))
- return m_startContainer;
+ return m_startContainer.get();
NodeImpl *child = m_startContainer->childNode(m_startOffset);
if (child)
return child;
if (m_startOffset == 0)
- return m_startContainer;
+ return m_startContainer.get();
return m_startContainer->traverseNextSibling();
}
// It is important to skip certain irrelevant content at the start of the selection, so we do not wind up
// with a spurious "mixed" style.
- VisiblePosition visiblePosition(m_startContainer, m_startOffset, VP_DEFAULT_AFFINITY);
+ VisiblePosition visiblePosition(m_startContainer.get(), m_startOffset, VP_DEFAULT_AFFINITY);
if (visiblePosition.isNull())
return Position();
&& a.endOffset(exception) == b.endOffset(exception);
}
-RefPtr<RangeImpl> rangeOfContents(NodeImpl *node)
+PassRefPtr<RangeImpl> rangeOfContents(NodeImpl *node)
{
- RangeImpl *range = new RangeImpl(node->getDocument());
+ RefPtr<RangeImpl> range = new RangeImpl(node->getDocument());
int exception = 0;
range->selectNodeContents(node, exception);
- return RefPtr<RangeImpl>(range);
+ return range.release();
}
}
* (C) 2000 Gunnstein Lye (gunnstein@netcom.no)
* (C) 2000 Frederik Holljen (frederik.holljen@hig.no)
* (C) 2001 Peter Kelly (pmk@post.com)
- * Copyright (C) 2004 Apple Computer, Inc.
+ * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
*
*/
-#ifndef _DOM2_RangeImpl_h_
-#define _DOM2_RangeImpl_h_
+#ifndef DOM2_RangeImpl_h_
+#define DOM2_RangeImpl_h_
-#include "dom/dom2_range.h"
+#include "dom2_range.h"
#include "Shared.h"
-#include "DocPtr.h"
+#include <kxmlcore/RefPtr.h>
-namespace DOM {
+namespace KXMLCore {
+ template <typename T> class PassRefPtr;
+}
+using KXMLCore::PassRefPtr;
+
+namespace WebCore {
+
+typedef int ExceptionCode;
class DocumentFragmentImpl;
-class DOMString;
+class DocumentImpl;
class NodeImpl;
class Position;
+class String;
class RangeImpl : public Shared<RangeImpl>
{
- friend class DocumentImpl;
public:
- RangeImpl(DocumentImpl *_ownerDocument);
- RangeImpl(DocumentImpl *_ownerDocument,
- NodeImpl *_startContainer, int _startOffset,
- NodeImpl *_endContainer, int _endOffset);
-
- ~RangeImpl();
-
- NodeImpl *startContainer(int &exceptioncode) const;
- int startOffset(int &exceptioncode) const;
- NodeImpl *endContainer(int &exceptioncode) const;
- int endOffset(int &exceptioncode) const;
- bool collapsed(int &exceptioncode) const;
-
- NodeImpl *commonAncestorContainer(int &exceptioncode) const;
- static NodeImpl *commonAncestorContainer(NodeImpl *containerA, NodeImpl *containerB);
- void setStart ( NodeImpl *refNode, int offset, int &exceptioncode );
- void setEnd ( NodeImpl *refNode, int offset, int &exceptioncode );
- void collapse ( bool toStart, int &exceptioncode );
- short compareBoundaryPoints ( Range::CompareHow how, const RangeImpl *sourceRange, int &exceptioncode ) const;
- static short compareBoundaryPoints ( NodeImpl *containerA, int offsetA, NodeImpl *containerB, int offsetB );
- static short compareBoundaryPoints ( const Position &a, const Position &b );
- bool boundaryPointsValid ( ) const;
- void deleteContents ( int &exceptioncode );
- DocumentFragmentImpl *extractContents ( int &exceptioncode );
- DocumentFragmentImpl *cloneContents ( int &exceptioncode );
- void insertNode( NodeImpl *newNode, int &exceptioncode );
- DOMString toString ( int &exceptioncode ) const;
- DOMString toHTML() const;
- DOMString text() const;
-
- DocumentFragmentImpl *createContextualFragment(const DOMString &html, int &exceptioncode) const;
-
- void detach ( int &exceptioncode );
+ RangeImpl(DocumentImpl*);
+ RangeImpl(DocumentImpl*, NodeImpl* startContainer, int startOffset, NodeImpl* endContainer, int endOffset);
+
+ NodeImpl* startContainer(ExceptionCode&) const;
+ int startOffset(ExceptionCode&) const;
+ NodeImpl* endContainer(ExceptionCode&) const;
+ int endOffset(ExceptionCode&) const;
+ bool collapsed(ExceptionCode&) const;
+
+ NodeImpl* commonAncestorContainer(ExceptionCode&) const;
+ static NodeImpl* commonAncestorContainer(NodeImpl* containerA, NodeImpl* containerB);
+ void setStart(NodeImpl* container, int offset, ExceptionCode&);
+ void setEnd(NodeImpl* container, int offset, ExceptionCode&);
+ void collapse(bool toStart, ExceptionCode&);
+ short compareBoundaryPoints(Range::CompareHow how, const RangeImpl* sourceRange, ExceptionCode&) const;
+ static short compareBoundaryPoints(NodeImpl* containerA, int offsetA, NodeImpl* containerB, int offsetB );
+ static short compareBoundaryPoints(const Position&, const Position&);
+ bool boundaryPointsValid() const;
+ void deleteContents(ExceptionCode&);
+ PassRefPtr<DocumentFragmentImpl> extractContents(ExceptionCode&);
+ PassRefPtr<DocumentFragmentImpl> cloneContents(ExceptionCode&);
+ void insertNode(PassRefPtr<NodeImpl>, ExceptionCode&);
+ String toString(ExceptionCode&) const;
+ String toHTML() const;
+ String text() const;
+
+ PassRefPtr<DocumentFragmentImpl> createContextualFragment(const String& html, ExceptionCode&) const;
+
+ void detach(ExceptionCode&);
bool isDetached() const;
- RangeImpl *cloneRange(int &exceptioncode) const;
+ PassRefPtr<RangeImpl> cloneRange(ExceptionCode&) const;
- void setStartAfter( NodeImpl *refNode, int &exceptioncode );
- void setEndBefore( NodeImpl *refNode, int &exceptioncode );
- void setEndAfter( NodeImpl *refNode, int &exceptioncode );
- void selectNode( NodeImpl *refNode, int &exceptioncode );
- void selectNodeContents( NodeImpl *refNode, int &exceptioncode );
- void surroundContents( NodeImpl *newParent, int &exceptioncode );
- void setStartBefore( NodeImpl *refNode, int &exceptioncode );
+ void setStartAfter(NodeImpl*, ExceptionCode&);
+ void setEndBefore(NodeImpl*, ExceptionCode&);
+ void setEndAfter(NodeImpl*, ExceptionCode&);
+ void selectNode(NodeImpl*, ExceptionCode&);
+ void selectNodeContents(NodeImpl*, ExceptionCode&);
+ void surroundContents(PassRefPtr<NodeImpl>, ExceptionCode&);
+ void setStartBefore(NodeImpl*, ExceptionCode&);
enum ActionType {
DELETE_CONTENTS,
EXTRACT_CONTENTS,
CLONE_CONTENTS
};
- DocumentFragmentImpl *processContents ( ActionType action, int &exceptioncode );
+ PassRefPtr<DocumentFragmentImpl> processContents(ActionType, ExceptionCode&);
Position startPosition() const;
Position endPosition() const;
- NodeImpl *startNode() const;
- NodeImpl *pastEndNode() const;
+ NodeImpl* startNode() const;
+ NodeImpl* pastEndNode() const;
Position editingStartPosition() const;
-#ifndef NDEBUG
+#if !NDEBUG
void formatForDebugger(char *buffer, unsigned length) const;
#endif
-protected:
- // FIXME - this could be a full-on RefPtr in principle...
- DocPtr<DocumentImpl> m_ownerDocument;
- NodeImpl *m_startContainer;
+private:
+ RefPtr<DocumentImpl> m_ownerDocument;
+ RefPtr<NodeImpl> m_startContainer;
unsigned m_startOffset;
- NodeImpl *m_endContainer;
+ RefPtr<NodeImpl> m_endContainer;
unsigned m_endOffset;
bool m_detached;
-private:
- void checkNodeWOffset( NodeImpl *n, int offset, int &exceptioncode) const;
- void checkNodeBA( NodeImpl *n, int &exceptioncode ) const;
- void setStartContainer(NodeImpl *_startContainer);
- void setEndContainer(NodeImpl *_endContainer);
- void checkDeleteExtract(int &exceptioncode);
+ void checkNodeWOffset(NodeImpl*, int offset, ExceptionCode&) const;
+ void checkNodeBA(NodeImpl*, ExceptionCode&) const;
+ void checkDeleteExtract(ExceptionCode&);
bool containedByReadOnly() const;
};
-RefPtr<RangeImpl> rangeOfContents(NodeImpl *node);
+PassRefPtr<RangeImpl> rangeOfContents(NodeImpl*);
-bool operator==(const RangeImpl &, const RangeImpl &);
-inline bool operator!=(const RangeImpl &a, const RangeImpl &b) { return !(a == b); }
+bool operator==(const RangeImpl&, const RangeImpl&);
+inline bool operator!=(const RangeImpl& a, const RangeImpl& b) { return !(a == b); }
} // namespace
{
assert(!m_attribute->m_impl);
m_attribute->m_impl = this;
- m_attribute->ref();
m_specified = true;
}
{
assert(m_attribute->m_impl == this);
m_attribute->m_impl = 0;
- m_attribute->deref();
}
void AttrImpl::createTextChild()
m_attribute->setValue(v.impl());
if (m_element)
- m_element->attributeChanged(m_attribute);
+ m_element->attributeChanged(m_attribute.get());
}
void AttrImpl::setNodeValue( const DOMString &v, int &exceptioncode )
}
// DOM Section 1.1.1
-bool AttrImpl::childAllowed( NodeImpl *newChild )
-{
- if(!newChild)
- return false;
-
- return childTypeAllowed(newChild->nodeType());
-}
-
-bool AttrImpl::childTypeAllowed( unsigned short type )
+bool AttrImpl::childTypeAllowed(unsigned short type)
{
switch (type) {
case Node::TEXT_NODE:
case Node::ENTITY_REFERENCE_NODE:
return true;
- break;
default:
return false;
}
m_attribute->setValue(val.impl());
if (m_element)
- m_element->attributeChanged(m_attribute);
+ m_element->attributeChanged(m_attribute.get());
}
DOMString AttrImpl::toString() const
return result;
}
-DOMString AttrImpl::name() const
-{
- return m_attribute->name().toString();
-}
-
-DOMString AttrImpl::value() const
-{
- return m_attribute->value();
-}
-
// -------------------------------------------------------------------------
#ifndef NDEBUG
if (!attrs)
return 0;
- return static_pointer_cast<AttrImpl>(attrs->removeNamedItem(attr->m_attribute->name(), exception));
+ return static_pointer_cast<AttrImpl>(attrs->removeNamedItem(attr->qualifiedName(), exception));
}
void ElementImpl::setAttributeNS(const DOMString &namespaceURI, const DOMString &qualifiedName, const DOMString &value, int &exception)
void NamedAttrMapImpl::clearAttributes()
{
if (attrs) {
- uint i;
- for (i = 0; i < len; i++) {
+ for (unsigned i = 0; i < len; i++) {
if (attrs[i]->m_impl)
attrs[i]->m_impl->m_element = 0;
attrs[i]->deref();
// ------------------------------- Styled Element and Mapped Attribute Implementation
-CSSMappedAttributeDeclarationImpl::~CSSMappedAttributeDeclarationImpl() {
+CSSMappedAttributeDeclarationImpl::~CSSMappedAttributeDeclarationImpl()
+{
if (m_entryType != ePersistent)
StyledElementImpl::removeMappedAttributeDecl(m_entryType, m_attrName, m_attrValue);
}
AttributeImpl* MappedAttributeImpl::clone(bool preserveDecl) const
{
- return new MappedAttributeImpl(m_name, m_value, preserveDecl ? m_styleDecl.get() : 0);
+ return new MappedAttributeImpl(name(), value(), preserveDecl ? m_styleDecl.get() : 0);
}
NamedMappedAttrMapImpl::NamedMappedAttrMapImpl(ElementImpl *e)
* (C) 1999 Antti Koivisto (koivisto@kde.org)
* (C) 2001 Peter Kelly (pmk@post.com)
* (C) 2001 Dirk Mueller (mueller@kde.org)
- * Copyright (C) 2003 Apple Computer, Inc.
+ * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
#include "NamedNodeMapImpl.h"
#include "ContainerNodeImpl.h"
#include "StringImpl.h"
-#include "Shared.h"
-#include "css/css_valueimpl.h"
+#include "css_valueimpl.h"
#include "dom_qname.h"
+#include "dom_atomicstringlist.h"
-#ifdef __OBJC__
+#if __OBJC__
#define id id_AVOID_KEYWORD
#endif
-#include "dom_atomicstringlist.h"
-
namespace khtml {
class CSSStyleSelector;
}
namespace DOM {
-class AtomicStringList;
-class DocumentImpl;
class CSSStyleDeclarationImpl;
class ElementImpl;
class NamedAttrMapImpl;
// the actual Attr (AttrImpl) with its value as textchild
// is only allocated on demand by the DOM bindings.
// Any use of AttrImpl inside khtml should be avoided.
- class AttributeImpl : public Shared<AttributeImpl>
-{
+class AttributeImpl : public Shared<AttributeImpl> {
friend class NamedAttrMapImpl;
friend class ElementImpl;
friend class AttrImpl;
: m_name(nullAtom, name, nullAtom), m_value(value), m_impl(0)
{}
- virtual ~AttributeImpl() {}
+ virtual ~AttributeImpl() { }
const AtomicString& value() const { return m_value; }
const AtomicString& prefix() const { return m_name.prefix(); }
void setValue(const AtomicString& value) { m_value = value; }
void setPrefix(const AtomicString& prefix) { m_name.setPrefix(prefix); }
-protected:
QualifiedName m_name;
AtomicString m_value;
AttrImpl* m_impl;
// is to dynamically allocate a textchild and store the
// resulting nodevalue in the AttributeImpl upon
// destruction. however, this is not yet implemented.
-class AttrImpl : public ContainerNodeImpl
-{
- friend class ElementImpl;
+class AttrImpl : public ContainerNodeImpl {
friend class NamedAttrMapImpl;
public:
- AttrImpl(ElementImpl* element, DocumentImpl* doc, AttributeImpl* a);
+ AttrImpl(ElementImpl*, DocumentImpl*, AttributeImpl*);
~AttrImpl();
- // Call this after calling the constructor so the
- // AttrImpl node isn't floating when we append the text node
+ // Call this after calling the constructor so the
+ // AttrImpl node isn't floating when we append the text node.
void createTextChild();
// DOM methods & attributes for Attr
- DOMString name() const;
+ DOMString name() const { return qualifiedName().toString(); }
bool specified() const { return m_specified; }
ElementImpl* ownerElement() const { return m_element; }
- AttributeImpl* attrImpl() const { return m_attribute; }
- DOMString value() const;
- void setValue( const DOMString &v, int &exceptioncode );
+ DOMString value() const { return m_attribute->value(); }
+ void setValue(const DOMString&, ExceptionCode&);
- // DOM methods overridden from parent classes
+ // DOM methods overridden from parent classes
virtual DOMString nodeName() const;
virtual unsigned short nodeType() const;
virtual const AtomicString& localName() const;
virtual const AtomicString& namespaceURI() const;
virtual const AtomicString& prefix() const;
- virtual void setPrefix(const AtomicString &_prefix, int &exceptioncode);
+ virtual void setPrefix(const AtomicString&, ExceptionCode&);
virtual DOMString nodeValue() const;
- virtual void setNodeValue( const DOMString &, int &exceptioncode );
+ virtual void setNodeValue(const DOMString&, ExceptionCode&);
virtual PassRefPtr<NodeImpl> cloneNode(bool deep);
// Other methods (not part of DOM)
virtual bool isAttributeNode() const { return true; }
- virtual bool childAllowed( NodeImpl *newChild );
- virtual bool childTypeAllowed( unsigned short type );
+ virtual bool childTypeAllowed(unsigned short type);
virtual void childrenChanged();
virtual DOMString toString() const;
+ AttributeImpl* attrImpl() const { return m_attribute.get(); }
+ const QualifiedName& qualifiedName() const { return m_attribute->name(); }
+
// An extension to get presentational information for attributes.
CSSStyleDeclarationImpl* style() { return m_attribute->style(); }
-
-protected:
+
+private:
ElementImpl* m_element;
- AttributeImpl* m_attribute;
+ RefPtr<AttributeImpl> m_attribute;
int m_ignoreChildrenChanged;
};
-
-class ElementImpl : public ContainerNodeImpl
-{
+class ElementImpl : public ContainerNodeImpl {
friend class DocumentImpl;
friend class NamedAttrMapImpl;
friend class AttrImpl;
friend class NodeImpl;
- friend class khtml::CSSStyleSelector;
+ friend class CSSStyleSelector;
public:
ElementImpl(const QualifiedName& tagName, DocumentImpl *doc);
~ElementImpl();
virtual QString state() { return QString::null; }
virtual void attach();
- virtual khtml::RenderStyle *styleForRenderer(khtml::RenderObject *parent);
- virtual khtml::RenderObject *createRenderer(RenderArena *, khtml::RenderStyle *);
+ virtual RenderStyle *styleForRenderer(RenderObject *parent);
+ virtual RenderObject *createRenderer(RenderArena *, RenderStyle *);
virtual void recalcStyle( StyleChange = NoChange );
virtual void mouseEventHandler( MouseEvent * /*ev*/, bool /*inside*/ ) {};
void dispatchAttrRemovalEvent(AttributeImpl *attr);
void dispatchAttrAdditionEvent(AttributeImpl *attr);
- virtual void accessKeyAction(bool sendToAnyEvent) { };
+ virtual void accessKeyAction(bool sendToAnyEvent) { }
virtual DOMString toString() const;
virtual void focus();
void blur();
-#ifndef NDEBUG
+#if !NDEBUG
virtual void dump(QTextStream *stream, QString ind = "") const;
-#endif
-
-#ifndef NDEBUG
virtual void formatForDebugger(char *buffer, unsigned length) const;
#endif
};
// the map of attributes of an element
-class NamedAttrMapImpl : public NamedNodeMapImpl
-{
+class NamedAttrMapImpl : public NamedNodeMapImpl {
friend class ElementImpl;
public:
NamedAttrMapImpl(ElementImpl *e);
virtual void clearAttributes();
void detachFromElement();
-protected:
ElementImpl *element;
AttributeImpl **attrs;
uint len;
enum MappedAttributeEntry { eNone, eUniversal, ePersistent, eReplaced, eBlock, eHR, eUnorderedList, eListItem,
eTable, eCell, eCaption, eBDO, ePre, eLastEntry };
-class CSSMappedAttributeDeclarationImpl : public CSSMutableStyleDeclarationImpl
-{
+class CSSMappedAttributeDeclarationImpl : public CSSMutableStyleDeclarationImpl {
public:
CSSMappedAttributeDeclarationImpl(CSSRuleImpl *parentRule)
: CSSMutableStyleDeclarationImpl(parentRule), m_entryType(eNone), m_attrName(anyQName())
void addCSSLength(MappedAttributeImpl* attr, int id, const DOMString &value);
void addCSSProperty(MappedAttributeImpl* attr, int id, const DOMString &value);
void addCSSProperty(MappedAttributeImpl* attr, int id, int value);
- void addCSSStringProperty(MappedAttributeImpl* attr, int id, const DOMString &value, DOM::CSSPrimitiveValue::UnitTypes = DOM::CSSPrimitiveValue::CSS_STRING);
+ void addCSSStringProperty(MappedAttributeImpl* attr, int id, const DOMString &value, CSSPrimitiveValue::UnitTypes = CSSPrimitiveValue::CSS_STRING);
void addCSSImageProperty(MappedAttributeImpl* attr, int id, const DOMString &URL);
void addCSSColor(MappedAttributeImpl* attr, int id, const DOMString &c);
void createMappedDecl(MappedAttributeImpl* attr);
mutable bool m_synchronizingStyleAttribute : 1;
};
-}; //namespace
+} //namespace
#undef id
/*
- * Copyright (C) 2004 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
#include "config.h"
#include "dom_position.h"
-#include <QString.h>
-
+#include "DocumentImpl.h"
+#include "InlineTextBox.h"
+#include "KWQLogging.h"
+#include "QString.h"
+#include "RenderBlock.h"
#include "css_computedstyle.h"
#include "css_valueimpl.h"
-#include "dom_elementimpl.h"
#include "dom2_range.h"
#include "dom2_rangeimpl.h"
#include "dom2_viewsimpl.h"
+#include "dom_elementimpl.h"
#include "helper.h"
#include "htmlediting.h"
-#include "text_affinity.h"
-#include "visible_position.h"
-#include "visible_units.h"
-#include "RenderBlock.h"
+#include "htmlnames.h"
#include "render_flow.h"
#include "render_line.h"
#include "render_style.h"
-#include "InlineTextBox.h"
+#include "text_affinity.h"
+#include "visible_position.h"
#include "visible_text.h"
-#include "htmlnames.h"
-
+#include "visible_units.h"
#include <kxmlcore/Assertions.h>
-#include "KWQLogging.h"
-
-using khtml::EAffinity;
-using khtml::InlineBox;
-using khtml::InlineTextBox;
-using khtml::isAtomicNode;
-using khtml::isCollapsibleWhitespace;
-using khtml::maxDeepOffset;
-using khtml::RenderBlock;
-using khtml::RenderFlow;
-using khtml::RenderObject;
-using khtml::RenderText;
-using khtml::RootInlineBox;
-using khtml::VISIBLE;
-using khtml::VisiblePosition;
-
-namespace DOM {
+
+namespace WebCore {
using namespace HTMLNames;
fprintf(stderr, "Position [%s]: %s [%p] at %d\n", msg, node()->nodeName().qstring().latin1(), node(), offset());
}
-#ifndef NDEBUG
-#define FormatBufferSize 1024
+#if !NDEBUG
+
void Position::formatForDebugger(char *buffer, unsigned length) const
{
- DOMString result;
- DOMString s;
+ String result;
if (isNull()) {
result = "<null>";
- }
- else {
- char s[FormatBufferSize];
+ } else {
+ char s[1024];
result += "offset ";
result += QString::number(m_offset);
result += " of ";
- m_node->formatForDebugger(s, FormatBufferSize);
+ m_node->formatForDebugger(s, sizeof(s));
result += s;
}
strncpy(buffer, result.qstring().latin1(), length - 1);
}
-#undef FormatBufferSize
void Position::showTree() const
{
if (pos)
pos->showTree();
}
-#endif
+#endif
Position startPosition(const RangeImpl *r)
{
return Position(r->endContainer(exceptionCode), r->endOffset(exceptionCode));
}
-} // namespace DOM
+} // namespace WebCore
#include "CachedXSLStyleSheet.h"
#include "DocLoader.h"
#include "DocumentImpl.h"
-#include "css/css_stylesheetimpl.h"
-#include "dom/dom_exception.h"
-#include "dom_node.h"
#include "StringImpl.h"
+#include "css_stylesheetimpl.h"
+#include "dom_exception.h"
+#include "dom_node.h"
#include "xml_tokenizer.h"
-#ifdef KHTML_XSLT
+#if KHTML_XSLT
#include "xsl_stylesheetimpl.h"
#endif
PassRefPtr<NodeImpl> EntityReferenceImpl::cloneNode(bool deep)
{
- PassRefPtr<EntityReferenceImpl> clone = new EntityReferenceImpl(getDocument(), m_entityName.get());
+ RefPtr<EntityReferenceImpl> clone = new EntityReferenceImpl(getDocument(), m_entityName.get());
// ### make sure children are readonly
// ### since we are a reference, should we clone children anyway (even if not deep?)
if (deep)
cloneChildNodes(clone.get());
- return clone;
+ return clone.release();
}
// DOM Section 1.1.1
ProcessingInstructionImpl::ProcessingInstructionImpl(DocumentImpl* doc)
: ContainerNodeImpl(doc), m_cachedSheet(0), m_loading(false)
{
-#ifdef KHTML_XSLT
+#if KHTML_XSLT
m_isXSL = false;
#endif
}
ProcessingInstructionImpl::ProcessingInstructionImpl(DocumentImpl* doc, const DOMString& target, const DOMString& data)
: ContainerNodeImpl(doc), m_target(target.impl()), m_data(data.impl()), m_cachedSheet(0), m_loading(false)
{
-#ifdef KHTML_XSLT
+#if KHTML_XSLT
m_isXSL = false;
#endif
}
type = i->second;
bool isCSS = type.isEmpty() || type == "text/css";
-#ifdef KHTML_XSLT
+#if KHTML_XSLT
m_isXSL = (type == "text/xml" || type == "text/xsl" || type == "application/xml" ||
type == "application/xhtml+xml" || type == "application/rss+xml" || type == "application/atom=xml");
if (!isCSS && !m_isXSL)
#endif
return true;
-#ifdef KHTML_XSLT
+#if KHTML_XSLT
if (m_isXSL)
getDocument()->tokenizer()->setTransformSource(getDocument());
#endif
if (href.length() > 1) {
if (href[0] == '#') {
m_localHref = href.substring(1).impl();
-#ifdef KHTML_XSLT
+#if KHTML_XSLT
// We need to make a synthetic XSLStyleSheetImpl that is embedded. It needs to be able
// to kick off import/include loads that can hang off some parent sheet.
if (m_isXSL) {
- PassRefPtr<XSLStyleSheetImpl> localSheet = new XSLStyleSheetImpl(this, m_localHref.get(), true);
+ RefPtr<XSLStyleSheetImpl> localSheet = new XSLStyleSheetImpl(this, m_localHref.get(), true);
localSheet->setDocument((xmlDocPtr)getDocument()->transformSource());
localSheet->loadChildSheets();
- m_sheet = localSheet;
+ m_sheet = localSheet.release();
m_loading = false;
}
return !m_isXSL;
m_loading = true;
getDocument()->addPendingSheet();
if (m_cachedSheet) m_cachedSheet->deref(this);
-#ifdef KHTML_XSLT
+#if KHTML_XSLT
if (m_isXSL)
m_cachedSheet = getDocument()->docLoader()->requestXSLStyleSheet(getDocument()->completeURL(href));
else
m_cachedSheet = getDocument()->docLoader()->requestStyleSheet(getDocument()->completeURL(href), QString::null);
if (m_cachedSheet)
m_cachedSheet->ref( this );
-#ifdef KHTML_XSLT
+#if KHTML_XSLT
return !m_isXSL;
#endif
}
void ProcessingInstructionImpl::setStyleSheet(const DOMString &url, const DOMString &sheet)
{
-#ifdef KHTML_XSLT
+#if KHTML_XSLT
if (m_isXSL)
m_sheet = new XSLStyleSheetImpl(this, url);
else
/*
* This file is part of the KDE libraries
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
- * Copyright (C) 2003 Apple Computer, Inc.
+ * Copyright (C) 2003, 2006 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
#include "config.h"
#include "kjs_range.h"
-#include <kdebug.h>
-#include "dom/dom2_range.h"
#include "DocumentFragmentImpl.h"
+#include "DocumentImpl.h"
+#include "dom2_range.h"
#include "dom2_rangeimpl.h"
-using DOM::DOMString;
-using DOM::Range;
-using DOM::RangeImpl;
+using WebCore::String;
+using WebCore::Range;
+using WebCore::RangeImpl;
#include "kjs_range.lut.h"
case CommonAncestorContainer:
return getDOMNode(exec, range.commonAncestorContainer(exception));
default:
- kdWarning() << "Unhandled token in DOMRange::getValueProperty : " << token << endl;
- return NULL;
+ return 0;
}
}
range.surroundContents(toNode(args[0]), exception);
break;
case DOMRange::CloneRange:
- result = getDOMRange(exec, range.cloneRange(exception));
+ result = getDOMRange(exec, range.cloneRange(exception).get());
break;
case DOMRange::ToString:
result = jsStringOrNull(range.toString(exception));
}
int exceptionCode = 0;
- PassRefPtr<RangeImpl> result(new RangeImpl(s.node()->getDocument()));
+ RefPtr<RangeImpl> result(new RangeImpl(s.node()->getDocument()));
result->setStart(s.node(), s.offset(), exceptionCode);
if (exceptionCode) {
ERROR("Exception setting Range start from Selection: %d", exceptionCode);
ERROR("Exception setting Range end from Selection: %d", exceptionCode);
return 0;
}
- return result;
+ return result.release();
}
bool Selection::expandUsingGranularity(ETextGranularity granularity)
void BreakBlockquoteCommand::doApply()
{
- DOM::ElementImpl *breakNode;
QPtrList<DOM::NodeImpl> ancestors;
Selection selection = endingSelection();
return;
// Insert a break after the top blockquote.
- breakNode = createBreakElement(document());
- insertNodeAfter(breakNode, topBlockquote);
+ RefPtr<ElementImpl> breakNode = createBreakElement(document());
+ insertNodeAfter(breakNode.get(), topBlockquote);
if (!isLastVisiblePositionInNode(VisiblePosition(pos, affinity), topBlockquote)) {
// Insert a clone of the top blockquote after the break.
RefPtr<NodeImpl> clonedBlockquote = topBlockquote->cloneNode(false);
- insertNodeAfter(clonedBlockquote.get(), breakNode);
+ insertNodeAfter(clonedBlockquote.get(), breakNode.get());
// Clone startNode's ancestors into the cloned blockquote.
// On exiting this loop, clonedAncestor is the lowest ancestor
}
// Put the selection right before the break.
- setEndingSelection(Position(breakNode, 0), DOWNSTREAM);
+ setEndingSelection(Position(breakNode.get(), 0), DOWNSTREAM);
rebalanceWhitespace();
}
// Should assert isBlockFlow || isInlineFlow when deletion improves. See 4244964.
ASSERT(node->renderer());
- NodeImpl *placeholder = createBlockPlaceholderElement(document());
- appendNode(placeholder, node);
- return placeholder;
+ RefPtr<NodeImpl> placeholder = createBlockPlaceholderElement(document());
+ appendNode(placeholder.get(), node);
+ return placeholder.get();
}
NodeImpl *CompositeEditCommand::insertBlockPlaceholder(const Position &pos)
// Should assert isBlockFlow || isInlineFlow when deletion improves. See 4244964.
ASSERT(pos.node()->renderer());
- NodeImpl *placeholder = createBlockPlaceholderElement(document());
- insertNodeAt(placeholder, pos.node(), pos.offset());
- return placeholder;
+ RefPtr<NodeImpl> placeholder = createBlockPlaceholderElement(document());
+ insertNodeAt(placeholder.get(), pos.node(), pos.offset());
+ return placeholder.get();
}
NodeImpl *CompositeEditCommand::addBlockPlaceholderIfNeeded(NodeImpl *node)
}
}
- NodeImpl *newBlock = createDefaultParagraphElement(document());
+ RefPtr<NodeImpl> newBlock = createDefaultParagraphElement(document());
NodeImpl *moveNode = paragraphStart.node();
if (paragraphStart.offset() >= paragraphStart.node()->caretMaxOffset())
moveNode = moveNode->traverseNextNode();
NodeImpl *endNode = end.node();
- insertNodeAt(newBlock, paragraphStart.node(), paragraphStart.offset());
+ insertNodeAt(newBlock.get(), paragraphStart.node(), paragraphStart.offset());
while (moveNode && !moveNode->isBlockFlow()) {
NodeImpl *next = moveNode->traverseNextSibling();
removeNode(moveNode);
- appendNode(moveNode, newBlock);
+ appendNode(moveNode, newBlock.get());
if (moveNode == endNode)
break;
moveNode = next;
}
}
-ElementImpl *createBlockPlaceholderElement(DocumentImpl *document)
+PassRefPtr<ElementImpl> createBlockPlaceholderElement(DocumentImpl* document)
{
int exceptionCode = 0;
- ElementImpl *breakNode = document->createElementNS(xhtmlNamespaceURI, "br", exceptionCode);
+ RefPtr<ElementImpl> breakNode = document->createElementNS(xhtmlNamespaceURI, "br", exceptionCode);
ASSERT(exceptionCode == 0);
breakNode->setAttribute(classAttr, blockPlaceholderClassString());
- return breakNode;
+ return breakNode.release();
}
static const DOMString &blockPlaceholderClassString()
if ((!afterEnd.isNull() && !inSameBlock(afterEnd, visibleEnd) && !inSameBlock(afterEnd, visibleStart)) ||
(m_downstreamEnd == m_selectionToDelete.end() && isEndOfParagraph(visibleEnd) && !m_downstreamEnd.node()->hasTagName(brTag))) {
- NodeImpl *block = createDefaultParagraphElement(document());
- insertNodeBefore(block, m_upstreamStart.node());
- addBlockPlaceholderIfNeeded(block);
- m_endingPosition = Position(block, 0);
+ RefPtr<NodeImpl> block = createDefaultParagraphElement(document());
+ insertNodeBefore(block.get(), m_upstreamStart.node());
+ addBlockPlaceholderIfNeeded(block.get());
+ m_endingPosition = Position(block.get(), 0);
}
}
}
removeNode(startBlock);
updateLayout();
if (refNode->renderer() && refNode->renderer()->inlineBox() && refNode->renderer()->inlineBox()->nextOnLineExists()) {
- insertNodeAfter(createBreakElement(document()), refNode);
+ insertNodeAfter(createBreakElement(document()).get(), refNode);
}
}
}
#include "config.h"
#include "html_interchange.h"
-#include <QString.h>
+#include "DocumentImpl.h"
+#include "QString.h"
#include "visible_text.h"
using khtml::isCollapsibleWhitespace;
ASSERT(node->isTextNode());
TextImpl *textNode = static_cast<TextImpl *>(node);
- DOMString text = textNode->data();
+ String text = textNode->data();
ASSERT(length <= text.length() && start + length <= text.length());
QString substring = text.substring(start, length).qstring();
substring.replace(end, 1, nbsp);
text.remove(start, length);
- text.insert(DOMString(substring), start);
+ text.insert(String(substring), start);
}
bool isTableStructureNode(const NodeImpl *node)
return (r && (r->isTableCell() || r->isTableRow() || r->isTableSection() || r->isTableCol()));
}
-DOMString &nonBreakingSpaceString()
+const String& nonBreakingSpaceString()
{
- static DOMString nonBreakingSpaceString = QString(QChar(NON_BREAKING_SPACE));
+ static String nonBreakingSpaceString = QString(QChar(NON_BREAKING_SPACE));
return nonBreakingSpaceString;
}
-void derefNodesInList(const QPtrList<NodeImpl>& list)
-{
- for (QPtrListIterator<NodeImpl> it(list); it.current(); ++it)
- it.current()->deref();
-}
-
// FIXME: Why use this instead of maxDeepOffset???
static int maxRangeOffset(NodeImpl *n)
{
return result;
}
-ElementImpl *createDefaultParagraphElement(DocumentImpl *document)
+PassRefPtr<ElementImpl> createDefaultParagraphElement(DocumentImpl *document)
{
- // We would need this margin-zeroing code back if we ever return to using <p> elements for default paragraphs.
- // static const DOMString defaultParagraphStyle("margin-top: 0; margin-bottom: 0");
int exceptionCode = 0;
ElementImpl *element = document->createElementNS(xhtmlNamespaceURI, "div", exceptionCode);
ASSERT(exceptionCode == 0);
return element;
}
-ElementImpl *createBreakElement(DocumentImpl *document)
+PassRefPtr<ElementImpl> createBreakElement(DocumentImpl *document)
{
int exceptionCode = 0;
ElementImpl *breakNode = document->createElementNS(xhtmlNamespaceURI, "br", exceptionCode);
return Position(node->parentNode(), node->nodeIndex());
}
-ElementImpl *createTabSpanElement(DocumentImpl *document, NodeImpl *tabTextNode)
+PassRefPtr<ElementImpl> createTabSpanElement(DocumentImpl* document, PassRefPtr<NodeImpl> tabTextNode)
{
// make the span to hold the tab
int exceptionCode = 0;
- ElementImpl *spanElement = document->createElementNS(xhtmlNamespaceURI, "span", exceptionCode);
+ RefPtr<ElementImpl> spanElement = document->createElementNS(xhtmlNamespaceURI, "span", exceptionCode);
assert(exceptionCode == 0);
spanElement->setAttribute(classAttr, AppleTabSpanClass);
spanElement->setAttribute(styleAttr, "white-space:pre");
spanElement->appendChild(tabTextNode, exceptionCode);
assert(exceptionCode == 0);
- return spanElement;
+ return spanElement.release();
+}
+
+PassRefPtr<ElementImpl> createTabSpanElement(DocumentImpl* document, const String& tabText)
+{
+ return createTabSpanElement(document, document->createTextNode(tabText));
}
-ElementImpl *createTabSpanElement(DocumentImpl *document, QString *tabText)
+PassRefPtr<ElementImpl> createTabSpanElement(DocumentImpl* document)
{
- return createTabSpanElement(document, document->createTextNode(*tabText));
+ return createTabSpanElement(document, PassRefPtr<NodeImpl>());
}
bool isNodeRendered(const NodeImpl *node)
#ifndef htmlediting_h
#define htmlediting_h
-#include <qptrlist.h>
-
-class QString;
+namespace KXMLCore {
+ template <typename T> class PassRefPtr;
+}
+using KXMLCore::PassRefPtr;
namespace WebCore {
-class DOMString;
class DocumentImpl;
class ElementImpl;
class NodeImpl;
class Position;
+class String;
class VisiblePosition;
const unsigned short NON_BREAKING_SPACE = 0xa0;
-Position rangeCompliantEquivalent(const Position& pos);
-Position rangeCompliantEquivalent(const VisiblePosition& vpos);
-int maxDeepOffset(const NodeImpl* node);
-bool isAtomicNode(const NodeImpl* node);
-bool editingIgnoresContent(const NodeImpl* node);
+Position rangeCompliantEquivalent(const Position&);
+Position rangeCompliantEquivalent(const VisiblePosition&);
+int maxDeepOffset(const NodeImpl*);
+bool isAtomicNode(const NodeImpl*);
+bool editingIgnoresContent(const NodeImpl*);
void rebalanceWhitespaceInTextNode(NodeImpl*, unsigned start, unsigned length);
-DOMString& nonBreakingSpaceString();
-void derefNodesInList(const QPtrList<NodeImpl>&);
+const String& nonBreakingSpaceString();
//------------------------------------------------------------------------------------------
bool isSpecialElement(const NodeImpl*);
-ElementImpl* createDefaultParagraphElement(DocumentImpl*);
-ElementImpl* createBreakElement(DocumentImpl*);
+PassRefPtr<ElementImpl> createDefaultParagraphElement(DocumentImpl*);
+PassRefPtr<ElementImpl> createBreakElement(DocumentImpl*);
bool isTabSpanNode(const NodeImpl*);
bool isTabSpanTextNode(const NodeImpl*);
NodeImpl* tabSpanNode(const NodeImpl*);
Position positionBeforeTabSpan(const Position&);
-ElementImpl* createTabSpanElement(DocumentImpl*, NodeImpl* tabTextNode = 0);
-ElementImpl* createTabSpanElement(DocumentImpl*, QString* tabText);
+PassRefPtr<ElementImpl> createTabSpanElement(DocumentImpl*);
+PassRefPtr<ElementImpl> createTabSpanElement(DocumentImpl*, PassRefPtr<NodeImpl> tabTextNode);
+PassRefPtr<ElementImpl> createTabSpanElement(DocumentImpl*, const String& tabText);
bool isNodeRendered(const NodeImpl*);
bool isMailBlockquote(const NodeImpl*);
//------------------------------------------------------------------------------------------
bool isTableStructureNode(const NodeImpl*);
-ElementImpl *createBlockPlaceholderElement(DocumentImpl*);
+PassRefPtr<ElementImpl> createBlockPlaceholderElement(DocumentImpl*);
-bool isFirstVisiblePositionInSpecialElement(const Position& pos);
-Position positionBeforeContainingSpecialElement(const Position& pos, NodeImpl** containingSpecialElement=0);
-bool isLastVisiblePositionInSpecialElement(const Position& pos);
-Position positionAfterContainingSpecialElement(const Position& pos, NodeImpl** containingSpecialElement=0);
-Position positionOutsideContainingSpecialElement(const Position &pos, NodeImpl** containingSpecialElement=0);
+bool isFirstVisiblePositionInSpecialElement(const Position&);
+Position positionBeforeContainingSpecialElement(const Position&, NodeImpl** containingSpecialElement=0);
+bool isLastVisiblePositionInSpecialElement(const Position&);
+Position positionAfterContainingSpecialElement(const Position&, NodeImpl** containingSpecialElement=0);
+Position positionOutsideContainingSpecialElement(const Position&, NodeImpl** containingSpecialElement=0);
bool isListElement(NodeImpl* n);
bool isTableElement(NodeImpl* n);
-bool isFirstVisiblePositionAfterTableElement(const Position &pos);
-Position positionBeforePrecedingTableElement(const Position &pos);
-Position positionAvoidingSpecialElementBoundary(const Position &pos);
+bool isFirstVisiblePositionAfterTableElement(const Position&);
+Position positionBeforePrecedingTableElement(const Position&);
+Position positionAvoidingSpecialElementBoundary(const Position&);
}
deleteSelection();
Selection selection = endingSelection();
- ElementImpl *breakNode = createBreakElement(document());
- NodeImpl *nodeToInsert = breakNode;
+ RefPtr<ElementImpl> breakNode = createBreakElement(document());
+ NodeImpl* nodeToInsert = breakNode.get();
Position pos(selection.start().upstream());
setEndingSelection(Selection(Position(next, 0), DOWNSTREAM));
else if (!document()->inStrictMode()) {
// Insert an "extra" BR at the end of the block.
- ElementImpl *extraBreakNode = createBreakElement(document());
- insertNodeAfter(extraBreakNode, nodeToInsert);
- setEndingSelection(Position(extraBreakNode, 0), DOWNSTREAM);
+ RefPtr<ElementImpl> extraBreakNode = createBreakElement(document());
+ insertNodeAfter(extraBreakNode.get(), nodeToInsert);
+ setEndingSelection(Position(extraBreakNode.get(), 0), DOWNSTREAM);
}
}
}
/*
- * Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
#include "config.h"
#include "insert_paragraph_separator_command.h"
-#include "htmlediting.h"
-#include "visible_position.h"
-#include "visible_units.h"
-
-#include "css/css_computedstyle.h"
-#include "css/css_valueimpl.h"
-#include "htmlnames.h"
#include "DocumentImpl.h"
+#include "KWQLogging.h"
+#include "css_computedstyle.h"
#include "dom_elementimpl.h"
#include "dom_textimpl.h"
-
+#include "htmlediting.h"
+#include "htmlnames.h"
+#include "visible_position.h"
+#include "visible_units.h"
#include <kxmlcore/Assertions.h>
-#include "KWQLogging.h"
-
-using namespace DOM::HTMLNames;
-using DOM::CSSComputedStyleDeclarationImpl;
-using DOM::DocumentImpl;
-using DOM::ElementImpl;
-using DOM::NodeImpl;
-using DOM::Position;
-using DOM::TextImpl;
+namespace WebCore {
-namespace khtml {
+using namespace HTMLNames;
InsertParagraphSeparatorCommand::InsertParagraphSeparatorCommand(DocumentImpl *document)
: CompositeEditCommand(document)
{
}
-InsertParagraphSeparatorCommand::~InsertParagraphSeparatorCommand()
-{
- derefNodesInList(clonedNodes);
-}
-
bool InsertParagraphSeparatorCommand::preservesTypingStyle() const
{
return true;
}
-ElementImpl *InsertParagraphSeparatorCommand::createParagraphElement()
-{
- ElementImpl *element = createDefaultParagraphElement(document());
- element->ref();
- clonedNodes.append(element);
- return element;
-}
-
void InsertParagraphSeparatorCommand::calculateStyleBeforeInsertion(const Position &pos)
{
// It is only important to set a style to apply later if we're at the boundaries of
bool startBlockIsRoot = startBlock == startBlock->rootEditableElement();
// This is the block that is going to be inserted.
- RefPtr<NodeImpl> blockToInsert = startBlockIsRoot ? createParagraphElement() : startBlock->cloneNode(false);
+ RefPtr<NodeImpl> blockToInsert = startBlockIsRoot
+ ? static_pointer_cast<NodeImpl>(createDefaultParagraphElement(document()))
+ : startBlock->cloneNode(false);
//---------------------------------------------------------------------
// Handle empty block case.
if (isFirstInBlock && isLastInBlock) {
LOG(Editing, "insert paragraph separator: empty block case");
if (startBlockIsRoot) {
- NodeImpl *extraBlock = createParagraphElement();
- appendNode(extraBlock, startBlock);
- appendBlockPlaceholder(extraBlock);
+ RefPtr<NodeImpl> extraBlock = createDefaultParagraphElement(document());
+ appendNode(extraBlock.get(), startBlock);
+ appendBlockPlaceholder(extraBlock.get());
appendNode(blockToInsert.get(), startBlock);
}
else {
if (!document()->inStrictMode()) {
Position upstreamPos = pos.upstream();
if (upstreamPos.node()->hasTagName(brTag))
- insertNodeAfter(createBreakElement(document()), upstreamPos.node());
+ insertNodeAfter(createBreakElement(document()).get(), upstreamPos.node());
}
// Move downstream. Typing style code will take care of carrying along the
startNode = pos.node();
// Build up list of ancestors in between the start node and the start block.
+ QPtrList<NodeImpl> ancestors;
if (startNode != startBlock) {
for (NodeImpl *n = startNode->parentNode(); n && n != startBlock; n = n->parentNode())
ancestors.prepend(n);
}
// Make clones of ancestors in between the start node and the start block.
- NodeImpl *parent = blockToInsert.get();
+ RefPtr<NodeImpl> parent = blockToInsert;
for (QPtrListIterator<NodeImpl> it(ancestors); it.current(); ++it) {
RefPtr<NodeImpl> child = it.current()->cloneNode(false); // shallow clone
- child->ref();
- clonedNodes.append(child.get());
- appendNode(child.get(), parent);
- parent = child.get();
+ appendNode(child.get(), parent.get());
+ parent = child.release();
}
// Insert a block placeholder if the next visible position is in a different paragraph,
while (n && n != blockToInsert) {
NodeImpl *next = n->nextSibling();
removeNode(n);
- appendNode(n, parent);
+ appendNode(n, parent.get());
n = next;
}
}
while (n && n != blockToInsert) {
NodeImpl *next = n->nextSibling();
removeNode(n);
- appendNode(n, parent);
+ appendNode(n, parent.get());
n = next;
}
leftParent = leftParent->parentNode();
applyStyleAfterInsertion();
}
-} // namespace khtml
+} // namespace WebCore
/*
- * Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef __insert_paragraph_separator_command_h__
-#define __insert_paragraph_separator_command_h__
+#ifndef insert_paragraph_separator_command_h__
+#define insert_paragraph_separator_command_h__
#include "composite_edit_command.h"
-#include "qptrlist.h"
-namespace khtml {
+namespace WebCore {
-class InsertParagraphSeparatorCommand : public CompositeEditCommand
-{
+class InsertParagraphSeparatorCommand : public CompositeEditCommand {
public:
- InsertParagraphSeparatorCommand(DOM::DocumentImpl *document);
- virtual ~InsertParagraphSeparatorCommand();
+ InsertParagraphSeparatorCommand(DocumentImpl*);
virtual void doApply();
private:
- DOM::ElementImpl *createParagraphElement();
- void calculateStyleBeforeInsertion(const DOM::Position &);
+ void calculateStyleBeforeInsertion(const Position&);
void applyStyleAfterInsertion();
virtual bool preservesTypingStyle() const;
- QPtrList<DOM::NodeImpl> ancestors;
- QPtrList<DOM::NodeImpl> clonedNodes;
- RefPtr<DOM::CSSMutableStyleDeclarationImpl> m_style;
+ RefPtr<CSSMutableStyleDeclarationImpl> m_style;
};
-} // namespace khtml
+}
-#endif // __insert_paragraph_separator_command_h__
+#endif
}
// create new tab span
- DOM::ElementImpl * spanNode = createTabSpanElement(document());
+ RefPtr<ElementImpl> spanNode = createTabSpanElement(document());
// place it
if (!node->isTextNode()) {
- insertNodeAt(spanNode, node, offset);
+ insertNodeAt(spanNode.get(), node, offset);
} else {
TextImpl *textNode = static_cast<TextImpl *>(node);
if (offset >= textNode->length()) {
- insertNodeAfter(spanNode, textNode);
+ insertNodeAfter(spanNode.get(), textNode);
} else {
// split node to make room for the span
// NOTE: splitTextNode uses textNode for the
// insert the span before it.
if (offset > 0)
splitTextNode(textNode, offset);
- insertNodeBefore(spanNode, textNode);
+ insertNodeBefore(spanNode.get(), textNode);
}
}
// FIXME: What if the document element is not an HTML element?
HTMLElementImpl *element = static_cast<HTMLElementImpl *>(document->documentElement());
- PassRefPtr<DocumentFragmentImpl> fragment = element->createContextualFragment(markup);
+ RefPtr<DocumentFragmentImpl> fragment = element->createContextualFragment(markup);
ASSERT(fragment);
if (!baseURL.isEmpty() && baseURL != document->baseURL())
completeURLs(fragment.get(), baseURL);
- return fragment;
+ return fragment.release();
}
QString createMarkup(const DOM::NodeImpl *node, EChildrenOnly includeChildren,
{
int exceptionCode = 0;
if (string.isEmpty()) {
- NodeImpl *placeHolder = createBlockPlaceholderElement(document);
- paragraph->appendChild(placeHolder, exceptionCode);
+ paragraph->appendChild(createBlockPlaceholderElement(document), exceptionCode);
ASSERT(exceptionCode == 0);
return;
}
// append the non-tab textual part
if (!s.isEmpty()) {
if (tabText != "") {
- paragraph->appendChild(createTabSpanElement(document, &tabText), exceptionCode);
+ paragraph->appendChild(createTabSpanElement(document, tabText), exceptionCode);
ASSERT(exceptionCode == 0);
tabText = "";
}
if (!tabList.isEmpty()) {
tabText += '\t';
} else if (tabText != "") {
- paragraph->appendChild(createTabSpanElement(document, &tabText), exceptionCode);
+ paragraph->appendChild(createTabSpanElement(document, tabText), exceptionCode);
ASSERT(exceptionCode == 0);
}
}
if (!document)
return 0;
- PassRefPtr<DocumentFragmentImpl> fragment = document->createDocumentFragment();
+ RefPtr<DocumentFragmentImpl> fragment = document->createDocumentFragment();
if (!text.isEmpty()) {
QString string = text;
ASSERT(exceptionCode == 0);
}
}
- return fragment;
+ return fragment.release();
}
PassRefPtr<DocumentFragmentImpl> createFragmentFromNodeList(DocumentImpl *document, const QPtrList<NodeImpl> &nodeList)
if (!document)
return 0;
- PassRefPtr<DocumentFragmentImpl> fragment = document->createDocumentFragment();
-
- RefPtr<ElementImpl> element;
+ RefPtr<DocumentFragmentImpl> fragment = document->createDocumentFragment();
+
int exceptionCode = 0;
for (QPtrListIterator<NodeImpl> i(nodeList); i.current(); ++i) {
- element = createDefaultParagraphElement(document);
+ RefPtr<ElementImpl> element = createDefaultParagraphElement(document);
element->appendChild(i.current(), exceptionCode);
ASSERT(exceptionCode == 0);
- fragment->appendChild(element.get(), exceptionCode);
+ fragment->appendChild(element.release(), exceptionCode);
ASSERT(exceptionCode == 0);
}
- return fragment;
+
+ return fragment.release();
}
}
/*
- * Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
#include "config.h"
#include "rebalance_whitespace_command.h"
+#include "DocumentImpl.h"
+#include "dom_textimpl.h"
#include "htmlediting.h"
#include "visible_text.h"
-#include "dom_textimpl.h"
-
#include <kxmlcore/Assertions.h>
-using DOM::DOMString;
-using DOM::DocumentImpl;
-using DOM::Position;
-using DOM::TextImpl;
-
-namespace khtml {
+namespace WebCore {
RebalanceWhitespaceCommand::RebalanceWhitespaceCommand(DocumentImpl *document, const Position &pos)
: EditCommand(document), m_position(pos), m_upstreamOffset(InvalidOffset)
if (newlineAtEndNode)
removeNode(newlineAtEndNode);
- PassRefPtr<NodeImpl> holder = insertFragmentForTestRendering();
+ RefPtr<NodeImpl> holder = insertFragmentForTestRendering();
if (!m_matchStyle)
computeStylesUsingTestRendering(holder.get());
removeUnrenderedNodesUsingTestRendering(holder.get());
if (!body)
return 0;
- PassRefPtr<ElementImpl> holder = createDefaultParagraphElement(m_document.get());
+ RefPtr<ElementImpl> holder = createDefaultParagraphElement(m_document.get());
int exceptionCode = 0;
holder->appendChild(m_fragment.get(), exceptionCode);
m_document->updateLayoutIgnorePendingStylesheets();
- return holder;
+ return holder.release();
}
void ReplacementFragment::restoreTestRenderingNodesToFragment(NodeImpl *holder)
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.get());
+ insertNodeBefore(createBreakElement(document()).get(), m_lastNodeInserted.get());
}
}
}
PassRefPtr<RangeImpl> CharacterIterator::range() const
{
- PassRefPtr<RangeImpl> r = m_textIterator.range();
+ RefPtr<RangeImpl> r = m_textIterator.range();
if (!m_textIterator.atEnd()) {
if (m_textIterator.length() <= 1) {
assert(m_runOffset == 0);
r->setEnd(n, offset + 1, exception);
}
}
- return r;
+ return r.release();
}
void CharacterIterator::advance(int count)
// Once we fix those, we can remove this check.
if (s.isEmpty() || s.find('\n') != -1) {
int exception = 0;
- RangeImpl *result = r->cloneRange(exception);
+ RefPtr<RangeImpl> result = r->cloneRange(exception);
result->collapse(forward, exception);
- return result;
+ return result.release();
}
CircularSearchBuffer buffer(s, caseSensitive);
done:
int exception = 0;
- RangeImpl *result = r->cloneRange(exception);
+ RefPtr<RangeImpl> result = r->cloneRange(exception);
if (!found) {
result->collapse(!forward, exception);
} else {
it.advance(buffer.length() - 1);
result->setEnd(it.range()->endContainer(exception), it.range()->endOffset(exception), exception);
}
- return result;
+ return result.release();
}
}
PassRefPtr<NodeImpl> HTMLElementImpl::cloneNode(bool deep)
{
- PassRefPtr<HTMLElementImpl> clone = HTMLElementFactory::createHTMLElement(m_tagName.localName(), getDocument(), 0, false);
+ RefPtr<HTMLElementImpl> clone = HTMLElementFactory::createHTMLElement(m_tagName.localName(), getDocument(), 0, false);
if (!clone)
return 0;
if (deep)
cloneChildNodes(clone.get());
- return clone;
+ return clone.release();
}
bool HTMLElementImpl::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
blockElem->parentNode()->removeChild(blockElem, exceptionCode);
// Step 2: Clone |residualElem|.
- PassRefPtr<NodeImpl> newNode = residualElem->cloneNode(false); // Shallow clone. We don't pick up the same kids.
+ RefPtr<NodeImpl> newNode = residualElem->cloneNode(false); // Shallow clone. We don't pick up the same kids.
// Step 3: Place |blockElem|'s children under |newNode|. Remove all of the children of |blockElem|
// before we've put |newElem| into the document. That way we'll only do one attachment of all
// Step 4: Place |newNode| under |blockElem|. |blockElem| is still out of the document, so no
// attachment can occur yet.
- blockElem->appendChild(newNode, exceptionCode);
+ blockElem->appendChild(newNode.release(), exceptionCode);
// Step 5: Reparent |blockElem|. Now the full attachment of the fixed up tree takes place.
if (isBlockStillInTree)
#if SVG_SUPPORT
#include <qregexp.h>
#include <qstringlist.h>
-#include <kxmlcore/PassRefPtr.h>
+#include <kxmlcore/RefPtr.h>
#include <kdom/core/AttrImpl.h>
if (subtransform[0].startsWith(";") || subtransform[0].startsWith(","))
subtransform[0] = subtransform[0].right(subtransform[0].length() - 1);
- PassRefPtr<SVGTransformImpl> t(new SVGTransformImpl());
+ RefPtr<SVGTransformImpl> t(new SVGTransformImpl());
if (subtransform[0] == "rotate") {
if (params.count() == 3)
if (t->type() == SVG_TRANSFORM_UNKNOWN)
break; // failed to parse a valid transform, abort.
- list->appendItem(t.release());
+ list->appendItem(t.release().release());
}
}
QString trans = QString::fromLatin1("translate(%1, %2)").arg(_x).arg(_y);
if(target->hasTagName(SVGNames::symbolTag))
{
- SVGElementImpl *dummy = new SVGSVGElementImpl(SVGNames::svgTag, getDocument());
+ RefPtr<SVGElementImpl> dummy = new SVGSVGElementImpl(SVGNames::svgTag, getDocument());
if(_w > 0)
dummy->setAttribute(SVGNames::widthAttr, wString.impl());
if(_h > 0)
const KDOM::AtomicString& symbolViewBox = symbol->getAttribute(SVGNames::viewBoxAttr);
dummy->setAttribute(SVGNames::viewBoxAttr, symbolViewBox);
}
- target->cloneChildNodes(dummy);
+ target->cloneChildNodes(dummy.get());
- SVGElementImpl *dummy2 = new SVGDummyElementImpl(SVGNames::gTag, getDocument());
+ RefPtr<SVGElementImpl> dummy2 = new SVGDummyElementImpl(SVGNames::gTag, getDocument());
dummy2->setAttribute(SVGNames::transformAttr, KDOM::DOMString(trans));
appendChild(dummy2, exceptioncode);
}
else if(target->hasTagName(SVGNames::svgTag))
{
- SVGDummyElementImpl *dummy = new SVGDummyElementImpl(SVGNames::gTag, getDocument());
+ RefPtr<SVGDummyElementImpl> dummy = new SVGDummyElementImpl(SVGNames::gTag, getDocument());
dummy->setAttribute(SVGNames::transformAttr, KDOM::DOMString(trans));
- PassRefPtr<SVGElementImpl> root = static_pointer_cast<SVGElementImpl>(target->cloneNode(true));
+ RefPtr<SVGElementImpl> root = static_pointer_cast<SVGElementImpl>(target->cloneNode(true));
if(hasAttribute(SVGNames::widthAttr))
root->setAttribute(SVGNames::widthAttr, wString.impl());
root->setAttribute(SVGNames::heightAttr, hString.impl());
appendChild(dummy, exceptioncode);
- dummy->appendChild(root, exceptioncode);
+ dummy->appendChild(root.release(), exceptioncode);
}
else
{
- SVGDummyElementImpl *dummy = new SVGDummyElementImpl(SVGNames::gTag, getDocument());
+ RefPtr<SVGDummyElementImpl> dummy = new SVGDummyElementImpl(SVGNames::gTag, getDocument());
dummy->setAttribute(SVGNames::transformAttr, trans);
- PassRefPtr<KDOM::NodeImpl> root = target->cloneNode(true);
+ RefPtr<KDOM::NodeImpl> root = target->cloneNode(true);
appendChild(dummy, exceptioncode);
- dummy->appendChild(root, exceptioncode);
+ dummy->appendChild(root.release(), exceptioncode);
}
SVGElementImpl::closeRenderer();