+2005-05-12 Darin Adler <darin@apple.com>
+
+ Reviewed by Chris Blumenberg.
+
+ - more "getting off the C++ DOM wrappers" changes
+ This pass involves replacing uses of DOM::Range with use of DOM::RangeImpl
+ plus some more use of DOM::DocumentImpl instead of DOM::Document.
+
+ * khtml/dom/dom2_range.cpp:
+ * khtml/dom/dom2_range.h:
+ * khtml/ecma/kjs_window.cpp:
+ (KJS::Window::get):
+ (KJS::WindowFunc::tryCall):
+ (KJS::Window::updateLayout):
+ (KJS::ScheduledAction::execute):
+ (KJS::Selection::toString):
+ * khtml/ecma/xmlhttprequest.cpp:
+ (KJS::XMLHttpRequestProtoFunc::tryCall):
+ * khtml/editing/htmlediting.cpp:
+ (khtml::InsertLineBreakCommand::doApply):
+ * khtml/editing/selection.cpp:
+ (khtml::Selection::Selection):
+ (khtml::Selection::moveTo):
+ (khtml::Selection::toRange):
+ * khtml/editing/selection.h:
+ * khtml/editing/visible_position.cpp:
+ (khtml::makeRange):
+ (khtml::startVisiblePosition):
+ (khtml::endVisiblePosition):
+ (khtml::setStart):
+ (khtml::setEnd):
+ * khtml/editing/visible_position.h:
+ * khtml/editing/visible_range.h:
+ * khtml/editing/visible_text.cpp:
+ (khtml::TextIterator::TextIterator):
+ (khtml::TextIterator::range):
+ (khtml::SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator):
+ (khtml::SimplifiedBackwardsTextIterator::range):
+ (khtml::CharacterIterator::CharacterIterator):
+ (khtml::CharacterIterator::range):
+ (khtml::WordAwareIterator::WordAwareIterator):
+ (khtml::WordAwareIterator::advance):
+ (khtml::TextIterator::rangeLength):
+ (khtml::TextIterator::rangeFromLocationAndLength):
+ (khtml::plainText):
+ (khtml::findPlainText):
+ * khtml/editing/visible_text.h:
+ (khtml::WordAwareIterator::range):
+ * khtml/editing/visible_units.cpp:
+ (khtml::previousBoundary):
+ (khtml::nextBoundary):
+ * khtml/html/html_elementimpl.cpp:
+ (HTMLElementImpl::innerText):
+ * khtml/html/htmltokenizer.cpp:
+ (khtml::HTMLTokenizer::scriptExecution):
+ * khtml/khtml_part.cpp:
+ (KHTMLPart::text):
+ (KHTMLPart::selectedText):
+ (KHTMLPart::shouldBeginEditing):
+ (KHTMLPart::shouldEndEditing):
+ (KHTMLPart::selectionComputedStyle):
+ * khtml/khtml_part.h:
+ * khtml/khtmlview.h:
+ * khtml/rendering/render_text.cpp:
+ (InlineTextBox::paint):
+ * khtml/xml/dom2_rangeimpl.cpp:
+ (DOM::operator==):
+ (DOM::rangeOfContents):
+ * khtml/xml/dom2_rangeimpl.h:
+ (DOM::operator!=):
+ * khtml/xml/dom_docimpl.cpp:
+ (DocumentImpl::relinquishesEditingFocus):
+ (DocumentImpl::acceptsEditingFocus):
+ (DocumentImpl::addMarker):
+ (DocumentImpl::removeMarker):
+ * khtml/xml/dom_docimpl.h:
+ * khtml/xml/dom_position.cpp:
+ (DOM::startPosition):
+ * khtml/xml/dom_position.h:
+ * kwq/DOMHTML.mm:
+ (-[DOMHTMLLinkElement href]):
+ (-[DOMHTMLBaseElement href]):
+ (-[DOMHTMLInputElement src]):
+ (-[DOMHTMLAnchorElement href]):
+ (-[DOMHTMLImageElement src]):
+ (-[DOMHTMLAreaElement href]):
+ * kwq/KWQAccObject.mm:
+ (-[KWQAccObject textUnderElement]):
+ (-[KWQAccObject value]):
+ (-[KWQAccObject doAXStringForTextMarkerRange:]):
+ (-[KWQAccObject doAXAttributedStringForTextMarkerRange:]):
+ * kwq/KWQKHTMLPart.h:
+ (KWQKHTMLPart::markedTextRange):
+ * kwq/KWQKHTMLPart.mm:
+ (KWQKHTMLPart::findString):
+ (KWQKHTMLPart::advanceToNextMisspelling):
+ (KWQKHTMLPart::fontForSelection):
+ (KWQKHTMLPart::markMisspellings):
+ (KWQKHTMLPart::respondToChangedSelection):
+ (KWQKHTMLPart::shouldBeginEditing):
+ (KWQKHTMLPart::shouldEndEditing):
+ (convertAttributesToUnderlines):
+ (KWQKHTMLPart::setMarkedTextRange):
+ * kwq/WebCoreBridge.mm:
+ (-[WebCoreBridge elementAtPoint:]):
+ (-[WebCoreBridge rangeByExpandingSelectionWithGranularity:]):
+ (-[WebCoreBridge rangeByAlteringCurrentSelection:direction:granularity:]):
+ (-[WebCoreBridge rangeByAlteringCurrentSelection:verticalDistance:]):
+ (-[WebCoreBridge selectedDOMRange]):
+ (-[WebCoreBridge convertToNSRange:DOM::]):
+ (-[WebCoreBridge convertToDOMRange:]):
+ (-[WebCoreBridge convertToObjCDOMRange:]):
+ (-[WebCoreBridge selectNSRange:]):
+ (-[WebCoreBridge selectedNSRange]):
+ (-[WebCoreBridge markDOMRange]):
+ (-[WebCoreBridge markedTextDOMRange]):
+ (-[WebCoreBridge markedTextNSRange]):
+ (-[WebCoreBridge replaceMarkedTextWithText:]):
+ (-[WebCoreBridge smartDeleteRangeForProposedRange:]):
+ (-[WebCoreBridge dragCaretDOMRange]):
+ (-[WebCoreBridge editableDOMRangeForPoint:]):
+ (-[WebCoreBridge rangeOfCharactersAroundCaret]):
+
2005-05-13 Maciej Stachowiak <mjs@apple.com>
Reviewed by Dave.
throw DOMException(exceptioncode);
}
-bool operator==(const Range &a, const Range &b)
-{
- RangeImpl *ai = a.handle();
- RangeImpl *bi = b.handle();
- if (ai == bi)
- return true;
- if (!ai || !bi)
- return false;
- bool ad = ai->isDetached();
- bool bd = bi->isDetached();
- if (ad && bd)
- return true;
- if (ad || bd)
- return false;
- return a.startContainer() == b.startContainer()
- && a.endContainer() == b.endContainer()
- && a.startOffset() == b.startOffset()
- && a.endOffset() == b.endOffset();
-}
-
}
void throwException(int exceptioncode) const;
};
-bool operator==(const Range &, const Range &);
-inline bool operator!=(const Range &a, const Range &b) { return !(a == b); }
-
// Used determine how to interpret the offsets used in DOM Ranges.
inline bool offsetInCharacters(unsigned short type)
{
#include "editing/htmlediting.h"
#include "editing/selection.h"
#include "xml/dom2_eventsimpl.h"
+#include "xml/dom2_rangeimpl.h"
#include "xml/dom_docimpl.h"
#include "xml/dom_elementimpl.h"
#include "xml/dom_position.h"
case Document:
if (isSafeScript(exec))
{
- if (m_part->document().isNull()) {
+ if (!m_part->xmlDocImpl()) {
#if APPLE_CHANGES
KWQ(m_part)->createEmptyDocument();
#endif
khtmlpart->setOpener(part);
khtmlpart->setOpenedByJS(true);
- if (khtmlpart->document().isNull()) {
+ if (!khtmlpart->xmlDocImpl()) {
DocumentImpl *oldDoc = part->xmlDocImpl();
if (oldDoc && oldDoc->baseURL() != 0)
khtmlpart->begin(oldDoc->baseURL());
return Undefined();
JSEventListener *listener = Window::retrieveActive(exec)->getJSEventListener(args[1]);
if (listener) {
- DOM::DocumentImpl* docimpl = static_cast<DOM::DocumentImpl *>(part->document().handle());
+ DocumentImpl* docimpl = part->xmlDocImpl();
if (docimpl)
docimpl->addWindowEventListener(DOM::EventImpl::typeToId(args[0].toString(exec).string()),listener,args[2].toBoolean(exec));
}
return Undefined();
JSEventListener *listener = Window::retrieveActive(exec)->getJSEventListener(args[1]);
if (listener) {
- DOM::DocumentImpl* docimpl = static_cast<DOM::DocumentImpl *>(part->document().handle());
+ DocumentImpl* docimpl = part->xmlDocImpl();
if (docimpl)
docimpl->removeWindowEventListener(DOM::EventImpl::typeToId(args[0].toString(exec).string()),listener,args[2].toBoolean(exec));
}
void Window::updateLayout() const
{
- DOM::DocumentImpl* docimpl = static_cast<DOM::DocumentImpl *>(m_part->document().handle());
+ DOM::DocumentImpl* docimpl = m_part->xmlDocImpl();
if (docimpl)
docimpl->updateLayoutIgnorePendingStylesheets();
}
}
// Update our document's rendering following the execution of the timeout callback.
- DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl*>(window->m_part->document().handle());
- doc->updateRendering();
+ if (DocumentImpl *doc = window->m_part->xmlDocImpl())
+ doc->updateRendering();
interpreter->setProcessingTimerCallback(false);
}
{
if (!m_part->selection().isRange())
return UString("");
- return UString(m_part->selection().toRange().toString());
+ int exception = 0;
+ return UString(m_part->selection().toRange()->toString(exception));
}
Value SelectionFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
}
QString method = args[0].toString(exec).qstring();
- KURL url = KURL(Window::retrieveActive(exec)->part()->document().completeURL(args[1].toString(exec).qstring()).string());
+ KURL url = KURL(Window::retrieveActive(exec)->part()->xmlDocImpl()->completeURL(args[1].toString(exec).qstring()));
bool async = true;
if (args.size() >= 3) {
validate();
}
-Selection::Selection(const Range &r, EAffinity baseAffinity, EAffinity extentAffinity)
+Selection::Selection(const RangeImpl *r, EAffinity baseAffinity, EAffinity extentAffinity)
: m_base(startPosition(r)), m_extent(endPosition(r))
{
init(baseAffinity);
validate();
}
-void Selection::moveTo(const Range &r, EAffinity baseAffinity, EAffinity extentAffinity)
+void Selection::moveTo(const RangeImpl *r, EAffinity baseAffinity, EAffinity extentAffinity)
{
// FIXME: use extentAffinity
m_affinity = baseAffinity;
m_needsLayout = flag;
}
-Range Selection::toRange() const
+SharedPtr<RangeImpl> Selection::toRange() const
{
if (isNone())
- return Range();
+ return SharedPtr<RangeImpl>();
// Make sure we have an updated layout since this function is called
// in the course of running edit commands which modify the DOM.
e = e.equivalentRangeCompliantPosition();
}
- // Use this roundabout way of creating the Range in order to have defined behavior
- // when there is a DOM exception.
int exceptionCode = 0;
- Range result(s.node()->getDocument());
- RangeImpl *handle = result.handle();
- ASSERT(handle);
- handle->setStart(s.node(), s.offset(), exceptionCode);
+ SharedPtr<RangeImpl> result(new RangeImpl(s.node()->docPtr()));
+ result->setStart(s.node(), s.offset(), exceptionCode);
if (exceptionCode) {
ERROR("Exception setting Range start from Selection: %d", exceptionCode);
- return Range();
+ return SharedPtr<RangeImpl>();
}
- handle->setEnd(e.node(), e.offset(), exceptionCode);
+ result->setEnd(e.node(), e.offset(), exceptionCode);
if (exceptionCode) {
ERROR("Exception setting Range end from Selection: %d", exceptionCode);
- return Range();
+ return SharedPtr<RangeImpl>();
}
return result;
}
#include <qrect.h>
#include "xml/dom_position.h"
#include "text_granularity.h"
+#include "misc/shared.h"
class KHTMLPart;
class QPainter;
// but that would be the desired affinity"
#define SEL_PREFER_UPSTREAM_AFFINITY DOWNSTREAM
- typedef DOM::Range Range;
typedef DOM::Position Position;
+ typedef DOM::RangeImpl RangeImpl;
Selection();
- Selection(const Range &, EAffinity baseAffinity, EAffinity extentAffinity);
+ Selection(const RangeImpl *, EAffinity baseAffinity, EAffinity extentAffinity);
Selection(const VisiblePosition &);
Selection(const VisiblePosition &, const VisiblePosition &);
Selection(const Position &, EAffinity affinity);
Selection &operator=(const Selection &o);
Selection &operator=(const VisiblePosition &r) { moveTo(r); return *this; }
- void moveTo(const Range &, EAffinity baseAffinity, EAffinity extentAffinity);
+ void moveTo(const RangeImpl *, EAffinity baseAffinity, EAffinity extentAffinity);
void moveTo(const VisiblePosition &);
void moveTo(const VisiblePosition &, const VisiblePosition &);
void moveTo(const Position &, EAffinity);
bool isRange() const { return state() == RANGE; }
bool isCaretOrRange() const { return state() != NONE; }
- Range toRange() const;
+ SharedPtr<DOM::RangeImpl> toRange() const;
void debugPosition() const;
void debugRenderer(khtml::RenderObject *r, bool selected) const;
using DOM::NodeImpl;
using DOM::NodeListImpl;
using DOM::Position;
-using DOM::Range;
using DOM::RangeImpl;
using DOM::TextImpl;
using DOM::TreeWalkerImpl;
Selection selectionBeforeStyle = endingSelection();
DOM::RangeImpl *rangeAroundNode = document()->createRange();
- int exception;
+ int exception = 0;
rangeAroundNode->selectNode(nodeToInsert, exception);
// affinity is not really important since this is a temp selection
validate();
}
-Selection::Selection(const Range &r, EAffinity baseAffinity, EAffinity extentAffinity)
+Selection::Selection(const RangeImpl *r, EAffinity baseAffinity, EAffinity extentAffinity)
: m_base(startPosition(r)), m_extent(endPosition(r))
{
init(baseAffinity);
validate();
}
-void Selection::moveTo(const Range &r, EAffinity baseAffinity, EAffinity extentAffinity)
+void Selection::moveTo(const RangeImpl *r, EAffinity baseAffinity, EAffinity extentAffinity)
{
// FIXME: use extentAffinity
m_affinity = baseAffinity;
m_needsLayout = flag;
}
-Range Selection::toRange() const
+SharedPtr<RangeImpl> Selection::toRange() const
{
if (isNone())
- return Range();
+ return SharedPtr<RangeImpl>();
// Make sure we have an updated layout since this function is called
// in the course of running edit commands which modify the DOM.
e = e.equivalentRangeCompliantPosition();
}
- // Use this roundabout way of creating the Range in order to have defined behavior
- // when there is a DOM exception.
int exceptionCode = 0;
- Range result(s.node()->getDocument());
- RangeImpl *handle = result.handle();
- ASSERT(handle);
- handle->setStart(s.node(), s.offset(), exceptionCode);
+ SharedPtr<RangeImpl> result(new RangeImpl(s.node()->docPtr()));
+ result->setStart(s.node(), s.offset(), exceptionCode);
if (exceptionCode) {
ERROR("Exception setting Range start from Selection: %d", exceptionCode);
- return Range();
+ return SharedPtr<RangeImpl>();
}
- handle->setEnd(e.node(), e.offset(), exceptionCode);
+ result->setEnd(e.node(), e.offset(), exceptionCode);
if (exceptionCode) {
ERROR("Exception setting Range end from Selection: %d", exceptionCode);
- return Range();
+ return SharedPtr<RangeImpl>();
}
return result;
}
#include <qrect.h>
#include "xml/dom_position.h"
#include "text_granularity.h"
+#include "misc/shared.h"
class KHTMLPart;
class QPainter;
// but that would be the desired affinity"
#define SEL_PREFER_UPSTREAM_AFFINITY DOWNSTREAM
- typedef DOM::Range Range;
typedef DOM::Position Position;
+ typedef DOM::RangeImpl RangeImpl;
Selection();
- Selection(const Range &, EAffinity baseAffinity, EAffinity extentAffinity);
+ Selection(const RangeImpl *, EAffinity baseAffinity, EAffinity extentAffinity);
Selection(const VisiblePosition &);
Selection(const VisiblePosition &, const VisiblePosition &);
Selection(const Position &, EAffinity affinity);
Selection &operator=(const Selection &o);
Selection &operator=(const VisiblePosition &r) { moveTo(r); return *this; }
- void moveTo(const Range &, EAffinity baseAffinity, EAffinity extentAffinity);
+ void moveTo(const RangeImpl *, EAffinity baseAffinity, EAffinity extentAffinity);
void moveTo(const VisiblePosition &);
void moveTo(const VisiblePosition &, const VisiblePosition &);
void moveTo(const Position &, EAffinity);
bool isRange() const { return state() == RANGE; }
bool isCaretOrRange() const { return state() != NONE; }
- Range toRange() const;
+ SharedPtr<DOM::RangeImpl> toRange() const;
void debugPosition() const;
void debugRenderer(khtml::RenderObject *r, bool selected) const;
}
#endif
-Range makeRange(const VisiblePosition &start, const VisiblePosition &end)
+SharedPtr<RangeImpl> makeRange(const VisiblePosition &start, const VisiblePosition &end)
{
Position s = start.position();
Position e = end.position();
- return Range(s.node(), s.offset(), e.node(), e.offset());
+ return SharedPtr<RangeImpl>(new RangeImpl(s.node()->docPtr(), s.node(), s.offset(), e.node(), e.offset()));
}
-VisiblePosition startVisiblePosition(const Range &r, EAffinity affinity)
+VisiblePosition startVisiblePosition(const RangeImpl *r, EAffinity affinity)
{
- return VisiblePosition(r.startContainer().handle(), r.startOffset(), affinity);
+ int exception = 0;
+ return VisiblePosition(r->startContainer(exception), r->startOffset(exception), affinity);
}
-VisiblePosition endVisiblePosition(const Range &r, EAffinity affinity)
+VisiblePosition endVisiblePosition(const RangeImpl *r, EAffinity affinity)
{
- return VisiblePosition(r.endContainer().handle(), r.endOffset(), affinity);
+ int exception = 0;
+ return VisiblePosition(r->endContainer(exception), r->endOffset(exception), affinity);
}
-bool setStart(Range &r, const VisiblePosition &c)
+bool setStart(RangeImpl *r, const VisiblePosition &c)
{
- RangeImpl *ri = r.handle();
- if (!ri)
+ if (!r)
return false;
Position p = c.position();
int code = 0;
- ri->setStart(p.node(), p.offset(), code);
+ r->setStart(p.node(), p.offset(), code);
return code == 0;
}
-bool setEnd(Range &r, const VisiblePosition &c)
+bool setEnd(RangeImpl *r, const VisiblePosition &c)
{
- RangeImpl *ri = r.handle();
- if (!ri)
+ if (!r)
return false;
Position p = c.position();
int code = 0;
- ri->setEnd(p.node(), p.offset(), code);
+ r->setEnd(p.node(), p.offset(), code);
return code == 0;
}
#include "xml/dom_position.h"
#include "text_affinity.h"
+#include "misc/shared.h"
namespace DOM {
class NodeImpl;
- class Range;
class RangeImpl;
}
return !(a == b);
}
-DOM::Range makeRange(const VisiblePosition &start, const VisiblePosition &end);
-bool setStart(DOM::Range &, const VisiblePosition &start);
+khtml::SharedPtr<DOM::RangeImpl> makeRange(const VisiblePosition &start, const VisiblePosition &end);
bool setStart(DOM::RangeImpl *, const VisiblePosition &start);
-bool setEnd(DOM::Range &, const VisiblePosition &start);
bool setEnd(DOM::RangeImpl *, const VisiblePosition &start);
-VisiblePosition startVisiblePosition(const DOM::Range &, EAffinity);
VisiblePosition startVisiblePosition(const DOM::RangeImpl *, EAffinity);
-VisiblePosition endVisiblePosition(const DOM::Range &, EAffinity);
VisiblePosition endVisiblePosition(const DOM::RangeImpl *, EAffinity);
void setAffinityUsingLinePosition(VisiblePosition &);
public:
typedef DOM::NodeImpl NodeImpl;
typedef DOM::Position Position;
- typedef DOM::Range Range;
+ typedef DOM::RangeImpl RangeImpl;
VisibleRange() { }
VisibleRange(NodeImpl *startContainer, long startOffset, NodeImpl *endContainer, long endOffset);
VisibleRange(const VisiblePosition &);
VisibleRange(const VisiblePosition &, const VisiblePosition &);
- VisibleRange(const Range &);
+ VisibleRange(const RangeImpl *);
VisibleRange(const Position &);
VisibleRange(const Position &, const Position &);
VisibleRange &operator=(const VisiblePosition &);
- VisibleRange &operator=(const Range &);
+ VisibleRange &operator=(const RangeImpl *);
VisibleRange &operator=(const Position &);
VisiblePosition start() const { return m_start; }
VisiblePosition end() const { return m_end; }
- Range range() const;
+ SharedPtr<RangeImpl> range() const;
void clear() { m_start.clear(); m_end.clear(); }
#include "xml/dom_position.h"
#include "xml/dom2_rangeimpl.h"
+using DOM::DocumentImpl;
using DOM::DOMString;
using DOM::Node;
using DOM::NodeImpl;
using DOM::offsetInCharacters;
-using DOM::Range;
using DOM::RangeImpl;
// FIXME: These classes should probably use the render tree and not the DOM tree, since elements could
{
}
-TextIterator::TextIterator(const Range &r, IteratorKind kind) : m_endContainer(0), m_endOffset(0), m_positionNode(0)
+TextIterator::TextIterator(const RangeImpl *r, IteratorKind kind) : m_endContainer(0), m_endOffset(0), m_positionNode(0)
{
- const RangeImpl *ri = r.handle();
- if (!ri)
+ if (!r)
return;
int exceptionCode = 0;
// get and validate the range endpoints
- NodeImpl *startContainer = ri->startContainer(exceptionCode);
- long startOffset = ri->startOffset(exceptionCode);
- NodeImpl *endContainer = ri->endContainer(exceptionCode);
- long endOffset = ri->endOffset(exceptionCode);
+ NodeImpl *startContainer = r->startContainer(exceptionCode);
+ long startOffset = r->startOffset(exceptionCode);
+ NodeImpl *endContainer = r->endContainer(exceptionCode);
+ long endOffset = r->endOffset(exceptionCode);
if (exceptionCode != 0)
return;
m_endOffset = endOffset;
// set up the current node for processing
- m_node = ri->startNode();
+ m_node = r->startNode();
if (m_node == 0)
return;
m_offset = m_node == startContainer ? startOffset : 0;
m_handledChildren = false;
// calculate first out of bounds node
- m_pastEndNode = ri->pastEndNode();
+ m_pastEndNode = r->pastEndNode();
// initialize node processing state
m_needAnotherNewline = false;
m_lastCharacter = c;
}
-Range TextIterator::range() const
+SharedPtr<RangeImpl> TextIterator::range() const
{
// use the current run information, if we have it
if (m_positionNode) {
m_positionEndOffset += index;
m_positionOffsetBaseNode = 0;
}
- return Range(m_positionNode, m_positionStartOffset, m_positionNode, m_positionEndOffset);
+ return SharedPtr<RangeImpl>(new RangeImpl(m_positionNode->docPtr(),
+ m_positionNode, m_positionStartOffset, m_positionNode, m_positionEndOffset));
}
// otherwise, return the end of the overall range we were given
if (m_endContainer)
- return Range(m_endContainer, m_endOffset, m_endContainer, m_endOffset);
+ return SharedPtr<RangeImpl>(new RangeImpl(m_endContainer->docPtr(),
+ m_endContainer, m_endOffset, m_endContainer, m_endOffset));
- return Range();
+ return SharedPtr<RangeImpl>();
}
SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator() : m_positionNode(0)
{
}
-SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator(const Range &r)
+SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator(const RangeImpl *r)
{
- if (r.isNull()) {
- m_positionNode = 0;
+ m_positionNode = 0;
+
+ if (!r)
return;
- }
- NodeImpl *startNode = r.startContainer().handle();
- NodeImpl *endNode = r.endContainer().handle();
- long startOffset = r.startOffset();
- long endOffset = r.endOffset();
+ int exception = 0;
+ NodeImpl *startNode = r->startContainer(exception);
+ if (exception)
+ return;
+ NodeImpl *endNode = r->endContainer(exception);
+ if (exception)
+ return;
+ long startOffset = r->startOffset(exception);
+ if (exception)
+ return;
+ long endOffset = r->endOffset(exception);
+ if (exception)
+ return;
if (!offsetInCharacters(startNode->nodeType())) {
if (startOffset >= 0 && startOffset < static_cast<long>(startNode->childNodeCount())) {
}
}
-Range SimplifiedBackwardsTextIterator::range() const
+SharedPtr<RangeImpl> SimplifiedBackwardsTextIterator::range() const
{
if (m_positionNode) {
- return Range(m_positionNode, m_positionStartOffset, m_positionNode, m_positionEndOffset);
+ return SharedPtr<RangeImpl>(new RangeImpl(m_positionNode->docPtr(), m_positionNode, m_positionStartOffset, m_positionNode, m_positionEndOffset));
} else {
- return Range(m_startNode, m_startOffset, m_startNode, m_startOffset);
+ return SharedPtr<RangeImpl>(new RangeImpl(m_startNode->docPtr(), m_startNode, m_startOffset, m_startNode, m_startOffset));
}
}
{
}
-CharacterIterator::CharacterIterator(const Range &r)
+CharacterIterator::CharacterIterator(const RangeImpl *r)
: m_offset(0), m_runOffset(0), m_atBreak(true), m_textIterator(r, RUNFINDER)
{
while (!atEnd() && m_textIterator.length() == 0) {
}
}
-Range CharacterIterator::range() const
+SharedPtr<RangeImpl> CharacterIterator::range() const
{
- Range r = m_textIterator.range();
+ SharedPtr<RangeImpl> r = m_textIterator.range();
if (!m_textIterator.atEnd()) {
if (m_textIterator.length() <= 1) {
assert(m_runOffset == 0);
} else {
- Node n = r.startContainer();
- assert(n == r.endContainer());
- long offset = r.startOffset() + m_runOffset;
- r.setStart(n, offset);
- r.setEnd(n, offset + 1);
+ int exception = 0;
+ NodeImpl *n = r->startContainer(exception);
+ assert(n == r->endContainer(exception));
+ long offset = r->startOffset(exception) + m_runOffset;
+ r->setStart(n, offset, exception);
+ r->setEnd(n, offset + 1, exception);
}
}
return r;
{
}
-WordAwareIterator::WordAwareIterator(const Range &r)
+WordAwareIterator::WordAwareIterator(const RangeImpl *r)
: m_previousText(0), m_didLookAhead(false), m_textIterator(r)
{
m_didLookAhead = true; // so we consider the first chunk from the text iterator
m_previousText = 0;
}
m_buffer.append(m_textIterator.characters(), m_textIterator.length());
- m_range.setEnd(m_textIterator.range().endContainer(), m_textIterator.range().endOffset());
+ int exception = 0;
+ m_range->setEnd(m_textIterator.range()->endContainer(exception),
+ m_textIterator.range()->endOffset(exception), exception);
}
}
&& memcmp(m_buffer, m_target.unicode() + tailSpace, headSpace * sizeof(QChar)) == 0;
}
-long TextIterator::rangeLength(const Range &r)
+long TextIterator::rangeLength(const RangeImpl *r)
{
// Allocate string at the right size, rather than building it up by successive append calls.
long length = 0;
return length;
}
-void TextIterator::setRangeFromLocationAndLength (const Range &range, Range &resultRange, long rangeLocation, long rangeLength)
+RangeImpl *TextIterator::rangeFromLocationAndLength(DocumentImpl *doc, long rangeLocation, long rangeLength)
{
+ RangeImpl *resultRange = doc->createRange();
+
long docTextPosition = 0;
long rangeEnd = rangeLocation + rangeLength;
- for (TextIterator it(range); !it.atEnd(); it.advance()) {
+ for (TextIterator it(rangeOfContents(doc).get()); !it.atEnd(); it.advance()) {
long len = it.length();
if (rangeLocation >= docTextPosition && rangeLocation <= docTextPosition + len) {
- Range textRunRange = it.range();
- if (textRunRange.startContainer().handle()->isTextNode()) {
+ SharedPtr<RangeImpl> textRunRange = it.range();
+ int exception = 0;
+ if (textRunRange->startContainer(exception)->isTextNode()) {
long offset = rangeLocation - docTextPosition;
- resultRange.setStart(textRunRange.startContainer(), offset + textRunRange.startOffset());
+ resultRange->setStart(textRunRange->startContainer(exception), offset + textRunRange->startOffset(exception), exception);
} else {
if (rangeLocation == docTextPosition) {
- resultRange.setStart(textRunRange.startContainer(), textRunRange.startOffset());
+ resultRange->setStart(textRunRange->startContainer(exception), textRunRange->startOffset(exception), exception);
} else {
- resultRange.setStart(textRunRange.endContainer(), textRunRange.endOffset());
+ resultRange->setStart(textRunRange->endContainer(exception), textRunRange->endOffset(exception), exception);
}
}
}
if (rangeEnd >= docTextPosition && rangeEnd <= docTextPosition + len) {
- Range textRunRange = it.range();
- if (textRunRange.startContainer().handle()->isTextNode()) {
+ SharedPtr<RangeImpl> textRunRange = it.range();
+ int exception = 0;
+ if (textRunRange->startContainer(exception)->isTextNode()) {
long offset = rangeEnd - docTextPosition;
- resultRange.setEnd(textRunRange.startContainer(), offset + textRunRange.startOffset());
+ resultRange->setEnd(textRunRange->startContainer(exception), offset + textRunRange->startOffset(exception), exception);
} else {
if (rangeEnd == docTextPosition) {
- resultRange.setEnd(textRunRange.startContainer(), textRunRange.startOffset());
+ resultRange->setEnd(textRunRange->startContainer(exception), textRunRange->startOffset(exception), exception);
} else {
- resultRange.setEnd(textRunRange.endContainer(), textRunRange.endOffset());
+ resultRange->setEnd(textRunRange->endContainer(exception), textRunRange->endOffset(exception), exception);
}
}
if ( !(rangeLength == 0 && rangeEnd == docTextPosition + len) ) {
}
docTextPosition += it.length();
}
+
+ return resultRange;
}
-QString plainText(const Range &r)
+QString plainText(const RangeImpl *r)
{
// Allocate string at the right size, rather than building it up by successive append calls.
long length = 0;
return result;
}
-Range findPlainText(const Range &r, const QString &s, bool forward, bool caseSensitive)
+SharedPtr<RangeImpl> findPlainText(const RangeImpl *r, const QString &s, bool forward, bool caseSensitive)
{
// FIXME: Can we do Boyer-Moore or equivalent instead for speed?
// FIXME: This code does not allow \n at the moment because of issues with <br>.
// Once we fix those, we can remove this check.
if (s.isEmpty() || s.find('\n') != -1) {
- Range result = r;
- result.collapse(forward);
- return result;
+ int exception = 0;
+ RangeImpl *result = r->cloneRange(exception);
+ result->collapse(forward, exception);
+ return SharedPtr<RangeImpl>(result);
}
CircularSearchBuffer buffer(s, caseSensitive);
}
done:
- Range result = r;
+ int exception = 0;
+ RangeImpl *result = r->cloneRange(exception);
if (!found) {
- result.collapse(!forward);
+ result->collapse(!forward, exception);
} else {
CharacterIterator it(r);
it.advance(rangeEnd.characterOffset() - buffer.length());
- result.setStart(it.range().startContainer(), it.range().startOffset());
+ result->setStart(it.range()->startContainer(exception), it.range()->startOffset(exception), exception);
it.advance(buffer.length() - 1);
- result.setEnd(it.range().endContainer(), it.range().endOffset());
+ result->setEnd(it.range()->endContainer(exception), it.range()->endOffset(exception), exception);
}
- return result;
+ return SharedPtr<RangeImpl>(result);
}
}
#ifndef KHTML_EDITING_VISIBLE_TEXT_H
#define KHTML_EDITING_VISIBLE_TEXT_H
-#include "dom/dom2_range.h"
+#include "xml/dom2_rangeimpl.h"
namespace khtml {
}
}
-QString plainText(const DOM::Range &);
-DOM::Range findPlainText(const DOM::Range &, const QString &, bool forward, bool caseSensitive);
+QString plainText(const DOM::RangeImpl *);
+SharedPtr<DOM::RangeImpl> 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
{
public:
TextIterator();
- explicit TextIterator(const DOM::Range &, IteratorKind kind = CONTENT );
+ explicit TextIterator(const DOM::RangeImpl *, IteratorKind kind = CONTENT );
bool atEnd() const { return !m_positionNode; }
void advance();
long length() const { return m_textLength; }
const QChar *characters() const { return m_textCharacters; }
- DOM::Range range() const;
+ SharedPtr<DOM::RangeImpl> range() const;
- static long TextIterator::rangeLength(const DOM::Range &r);
- static void TextIterator::setRangeFromLocationAndLength (const DOM::Range &range, DOM::Range &resultRange, long rangeLocation, long rangeLength);
+ static long TextIterator::rangeLength(const DOM::RangeImpl *r);
+ static DOM::RangeImpl *TextIterator::rangeFromLocationAndLength(DOM::DocumentImpl *doc, long rangeLocation, long rangeLength);
private:
void exitNode();
{
public:
SimplifiedBackwardsTextIterator();
- explicit SimplifiedBackwardsTextIterator(const DOM::Range &);
+ explicit SimplifiedBackwardsTextIterator(const DOM::RangeImpl *);
bool atEnd() const { return !m_positionNode; }
void advance();
long length() const { return m_textLength; }
const QChar *characters() const { return m_textCharacters; }
- DOM::Range range() const;
+ SharedPtr<DOM::RangeImpl> range() const;
private:
void exitNode();
class CharacterIterator {
public:
CharacterIterator();
- explicit CharacterIterator(const DOM::Range &r);
+ explicit CharacterIterator(const DOM::RangeImpl *r);
void advance(long numCharacters);
QString string(long numChars);
long characterOffset() const { return m_offset; }
- DOM::Range range() const;
+ SharedPtr<DOM::RangeImpl> range() const;
private:
long m_offset;
class WordAwareIterator {
public:
WordAwareIterator();
- explicit WordAwareIterator(const DOM::Range &r);
+ explicit WordAwareIterator(const DOM::RangeImpl *r);
bool atEnd() const { return !m_didLookAhead && m_textIterator.atEnd(); }
void advance();
const QChar *characters() const;
// Range of the text we're currently returning
- DOM::Range range() const { return m_range; }
+ SharedPtr<DOM::RangeImpl> range() const { return m_range; }
private:
// text from the previous chunk from the textIterator
// Did we have to look ahead in the textIterator to confirm the current chunk?
bool m_didLookAhead;
- DOM::Range m_range;
+ SharedPtr<DOM::RangeImpl> m_range;
TextIterator m_textIterator;
};
using DOM::ElementImpl;
using DOM::NodeImpl;
using DOM::Position;
-using DOM::Range;
+using DOM::RangeImpl;
namespace khtml {
boundary = boundary->parentNode();
}
- Range searchRange(d);
- searchRange.setStartBefore(boundary);
+ SharedPtr<RangeImpl> searchRange(d->createRange());
+ int exception = 0;
+ searchRange->setStartBefore(boundary, exception);
Position end(pos.equivalentRangeCompliantPosition());
- searchRange.setEnd(end.node(), end.offset());
- SimplifiedBackwardsTextIterator it(searchRange);
+ searchRange->setEnd(end.node(), end.offset(), exception);
+ SimplifiedBackwardsTextIterator it(searchRange.get());
QString string;
unsigned next = 0;
while (!it.atEnd() && it.length() > 0) {
}
if (it.atEnd() && next == 0) {
- Range range(it.range());
- pos = Position(range.startContainer().handle(), range.startOffset());
+ SharedPtr<RangeImpl> range(it.range());
+ pos = Position(range->startContainer(exception), range->startOffset(exception));
}
else if (!it.atEnd() && it.length() == 0) {
// Got a zero-length chunk.
chars[1] = ' ';
string.prepend(chars, 2);
unsigned pastImage = searchFunction(string.unicode(), string.length());
- Range range(it.range());
+ SharedPtr<RangeImpl> range(it.range());
if (pastImage == 0)
- pos = Position(range.startContainer().handle(), range.startOffset());
+ pos = Position(range->startContainer(exception), range->startOffset(exception));
else
- pos = Position(range.endContainer().handle(), range.endOffset());
+ pos = Position(range->endContainer(exception), range->endOffset(exception));
}
else if (next != 0) {
// The simpler iterator used in this function, as compared to the one used in
// nextWordPosition(), gives us results we can use directly without having to
// iterate again to translate the next value into a DOM position.
- NodeImpl *node = it.range().startContainer().handle();
+ NodeImpl *node = it.range()->startContainer(exception);
if (node->isTextNode() || (node->renderer() && node->renderer()->isBR())) {
// The next variable contains a usable index into a text node
pos = Position(node, next);
else {
// If we are not in a text node, we ended on a node boundary, so the
// range start offset should be used.
- pos = Position(node, it.range().startOffset());
+ pos = Position(node, it.range()->startOffset(exception));
}
}
boundary = boundary->parentNode();
}
- Range searchRange(d);
+ SharedPtr<RangeImpl> searchRange(d->createRange());
Position start(pos.equivalentRangeCompliantPosition());
- searchRange.setStart(start.node(), start.offset());
- searchRange.setEndAfter(boundary);
- TextIterator it(searchRange, RUNFINDER);
+ int exception = 0;
+ searchRange->setStart(start.node(), start.offset(), exception);
+ searchRange->setEndAfter(boundary, exception);
+ TextIterator it(searchRange.get(), RUNFINDER);
QString string;
unsigned next = 0;
while (!it.atEnd() && it.length() > 0) {
}
if (it.atEnd() && next == string.length()) {
- Range range(it.range());
- pos = Position(range.startContainer().handle(), range.startOffset());
+ SharedPtr<RangeImpl> range(it.range());
+ int exception = 0;
+ pos = Position(range->startContainer(exception), range->startOffset(exception));
}
else if (!it.atEnd() && it.length() == 0) {
// Got a zero-length chunk.
chars[1] = 'X';
string.append(chars, 2);
unsigned pastImage = searchFunction(string.unicode(), string.length());
- Range range(it.range());
+ SharedPtr<RangeImpl> range(it.range());
+ int exception = 0;
if (next != pastImage)
- pos = Position(range.endContainer().handle(), range.endOffset());
+ pos = Position(range->endContainer(exception), range->endOffset(exception));
else
- pos = Position(range.startContainer().handle(), range.startOffset());
+ pos = Position(range->startContainer(exception), range->startOffset(exception));
}
else if (next != 0) {
// Use the character iterator to translate the next value into a DOM position.
- CharacterIterator charIt(searchRange);
+ CharacterIterator charIt(searchRange.get());
charIt.advance(next - 1);
- pos = Position(charIt.range().endContainer().handle(), charIt.range().endOffset());
+ pos = Position(charIt.range()->endContainer(exception), charIt.range()->endOffset(exception));
}
return VisiblePosition(pos, UPSTREAM);
}
{
// We need to update layout, since plainText uses line boxes in the render tree.
getDocument()->updateLayout();
- return plainText(Range(const_cast<HTMLElementImpl *>(this), 0,
- const_cast<HTMLElementImpl *>(this), childNodeCount()));
+ return plainText(rangeOfContents(const_cast<HTMLElementImpl *>(this)).get());
}
DOMString HTMLElementImpl::outerText() const
script = false;
QString url;
if (scriptURL.isNull())
- url = static_cast<DocumentImpl*>(view->part()->document().handle())->URL();
+ url = view->part()->xmlDocImpl()->URL();
else
url = scriptURL;
#endif // APPLE_CHANGES
+#if !KHTML_NO_CPLUSPLUS_DOM
+
QString KHTMLPart::text(const DOM::Range &r) const
{
- return plainText(r);
+ return plainText(r.handle());
}
+#endif
+
QString KHTMLPart::selectedText() const
{
- return text(selection().toRange());
+ return plainText(selection().toRange().get());
}
bool KHTMLPart::hasSelection() const
selectFrameElementInParentIfFullySelected();
}
-bool KHTMLPart::shouldBeginEditing(const Range &range) const
+bool KHTMLPart::shouldBeginEditing(const RangeImpl *range) const
{
return true;
}
-bool KHTMLPart::shouldEndEditing(const Range &range) const
+bool KHTMLPart::shouldEndEditing(const RangeImpl *range) const
{
return true;
}
if (d->m_selection.isNone())
return 0;
- Range range(d->m_selection.toRange());
- Position pos = range.handle()->editingStartPosition();
+ SharedPtr<RangeImpl> range(d->m_selection.toRange());
+ Position pos = range->editingStartPosition();
ElementImpl *elem = pos.element();
if (!elem)
class Node;
class NodeImpl;
class Range;
+ class RangeImpl;
}
namespace khtml
*/
int xPosForVerticalArrowNavigation() const;
+#if !KHTML_NO_CPLUSPLUS_DOM
/**
* Returns the text for a part of the document.
*/
QString text(const DOM::Range &) const;
+#endif
/**
* Has the user selected anything?
/**
* Returns whether editing should end in the given range
*/
- virtual bool shouldBeginEditing(const DOM::Range &) const;
+ virtual bool shouldBeginEditing(const DOM::RangeImpl *) const;
/**
* Returns whether editing should end in the given range
*/
- virtual bool shouldEndEditing(const DOM::Range &) const;
+ virtual bool shouldEndEditing(const DOM::RangeImpl *) const;
/**
* Returns the contentEditable "override" value for the part
class HTMLGenericFormElementImpl;
class HTMLFormElementImpl;
class HTMLAnchorElementImpl;
- class Range;
class NodeImpl;
class CSSProperty;
};
//#define DEBUG_LAYOUT
//#define BIDI_DEBUG
+#include "rendering/render_text.h"
+
#include "rendering/render_canvas.h"
#include "rendering/render_object.h"
-#include "rendering/render_text.h"
#include "rendering/break_lines.h"
-#include "dom/dom2_range.h"
+#include "xml/dom2_rangeimpl.h"
#include "xml/dom_nodeimpl.h"
#include "xml/dom_docimpl.h"
#include "xml/dom_position.h"
return;
// Determine whether or not we have marked text.
- Range markedTextRange = KWQ(object()->document()->part())->markedTextRange();
- bool haveMarkedText = markedTextRange.handle() != 0 && markedTextRange.startContainer() == object()->node();
+ RangeImpl *markedTextRange = KWQ(object()->document()->part())->markedTextRange();
+ int exception = 0;
+ bool haveMarkedText = markedTextRange && markedTextRange->startContainer(exception) == object()->node();
bool markedTextUsesUnderlines = KWQ(object()->document()->part())->markedTextUsesUnderlines();
-
// Set our font.
RenderStyle* styleToUse = object()->style(m_firstLine);
int d = styleToUse->textDecorationsInEffect();
// and marked text.
if ((haveSelection || haveMarkedText) && !markedTextUsesUnderlines && i.phase != PaintActionSelection && !isPrinting) {
if (haveMarkedText)
- paintMarkedTextBackground(i.p, tx, ty, styleToUse, font, markedTextRange.startOffset(), markedTextRange.endOffset());
+ paintMarkedTextBackground(i.p, tx, ty, styleToUse, font, markedTextRange->startOffset(exception), markedTextRange->endOffset(exception));
if (haveSelection)
paintSelection(i.p, tx, ty, styleToUse, font);
#undef FormatBufferSize
#endif
+bool operator==(const RangeImpl &a, const RangeImpl &b)
+{
+ if (&a == &b)
+ return true;
+ // Not strictly legal C++, but in practice this can happen, and works fine with GCC.
+ if (!&a || !&b)
+ return false;
+ bool ad = a.isDetached();
+ bool bd = b.isDetached();
+ if (ad && bd)
+ return true;
+ if (ad || bd)
+ return false;
+ int exception = 0;
+ return a.startContainer(exception) == b.startContainer(exception)
+ && a.endContainer(exception) == b.endContainer(exception)
+ && a.startOffset(exception) == b.startOffset(exception)
+ && a.endOffset(exception) == b.endOffset(exception);
+}
+
+SharedPtr<RangeImpl> rangeOfContents(NodeImpl *node)
+{
+ RangeImpl *range = new RangeImpl(node->docPtr());
+ int exception = 0;
+ range->selectNodeContents(node, exception);
+ return SharedPtr<RangeImpl>(range);
+}
+
}
bool containedByReadOnly() const;
};
+khtml::SharedPtr<RangeImpl> rangeOfContents(NodeImpl *node);
+
+bool operator==(const RangeImpl &, const RangeImpl &);
+inline bool operator!=(const RangeImpl &a, const RangeImpl &b) { return !(a == b); }
+
} // namespace
#endif
assert(node);
assert(node->isContentEditable());
- NodeImpl *rootImpl = node->rootEditableElement();
- if (!part() || !rootImpl)
+ NodeImpl *root = node->rootEditableElement();
+ if (!part() || !root)
return false;
- Node root(rootImpl);
- Range range(root, 0, root, rootImpl->childNodeCount());
- return part()->shouldEndEditing(range);
+ return part()->shouldEndEditing(rangeOfContents(root).get());
}
bool DocumentImpl::acceptsEditingFocus(NodeImpl *node)
assert(node);
assert(node->isContentEditable());
- NodeImpl *rootImpl = node->rootEditableElement();
- if (!part() || !rootImpl)
+ NodeImpl *root = node->rootEditableElement();
+ if (!part() || !root)
return false;
- Node root(rootImpl);
- Range range(root, 0, root, rootImpl->childNodeCount());
- return part()->shouldBeginEditing(range);
+ return part()->shouldBeginEditing(rangeOfContents(root).get());
}
const QValueList<DashboardRegionValue> & DocumentImpl::dashboardRegions() const
// ----------------------------------------------------------------------------
-void DocumentImpl::addMarker(Range range, DocumentMarker::MarkerType type)
+void DocumentImpl::addMarker(RangeImpl *range, DocumentMarker::MarkerType type)
{
// Use a TextIterator to visit the potentially multiple nodes the range covers.
for (TextIterator markedText(range); !markedText.atEnd(); markedText.advance()) {
- Range textPiece = markedText.range();
- DocumentMarker marker = {type, textPiece.startOffset(), textPiece.endOffset()};
- addMarker(textPiece.startContainer().handle(), marker);
+ SharedPtr<RangeImpl> textPiece = markedText.range();
+ int exception = 0;
+ DocumentMarker marker = {type, textPiece->startOffset(exception), textPiece->endOffset(exception)};
+ addMarker(textPiece->startContainer(exception), marker);
}
}
-void DocumentImpl::removeMarker(Range range, DocumentMarker::MarkerType type)
+void DocumentImpl::removeMarker(RangeImpl *range, DocumentMarker::MarkerType type)
{
// Use a TextIterator to visit the potentially multiple nodes the range covers.
for (TextIterator markedText(range); !markedText.atEnd(); markedText.advance()) {
- Range textPiece = markedText.range();
- DocumentMarker marker = {type, textPiece.startOffset(), textPiece.endOffset()};
- removeMarker(textPiece.startContainer().handle(), marker);
+ SharedPtr<RangeImpl> textPiece = markedText.range();
+ int exception = 0;
+ DocumentMarker marker = {type, textPiece->startOffset(exception), textPiece->endOffset(exception)};
+ removeMarker(textPiece->startContainer(exception), marker);
}
}
class NodeIteratorImpl;
class NodeListImpl;
class ProcessingInstructionImpl;
- class Range;
class RangeImpl;
class RegisteredEventListener;
class StyleSheetImpl;
bool queryCommandSupported(const DOMString &command);
DOMString queryCommandValue(const DOMString &command);
- void addMarker(Range range, DocumentMarker::MarkerType type);
- void removeMarker(Range range, DocumentMarker::MarkerType type);
+ void addMarker(RangeImpl *range, DocumentMarker::MarkerType type);
+ void removeMarker(RangeImpl *range, DocumentMarker::MarkerType type);
void addMarker(NodeImpl *node, DocumentMarker marker);
void removeMarker(NodeImpl *node, DocumentMarker marker);
void removeAllMarkers(NodeImpl *node, ulong startOffset, long length);
#endif
-Position startPosition(const Range &r)
-{
- if (r.isNull() || r.isDetached())
- return Position();
- return Position(r.startContainer().handle(), r.startOffset());
-}
-
Position startPosition(const RangeImpl *r)
{
if (!r || r->isDetached())
return Position(r->startContainer(exceptionCode), r->startOffset(exceptionCode));
}
-Position endPosition(const Range &r)
-{
- if (r.isNull() || r.isDetached())
- return Position();
- return Position(r.endContainer().handle(), r.endOffset());
-}
-
Position endPosition(const RangeImpl *r)
{
if (!r || r->isDetached())
class CSSComputedStyleDeclarationImpl;
class ElementImpl;
class NodeImpl;
-class Range;
class RangeImpl;
enum EUsingComposedCharacters { NotUsingComposedCharacters = false, UsingComposedCharacters = true };
return !(a == b);
}
-Position startPosition(const Range &);
Position startPosition(const RangeImpl *);
-Position endPosition(const Range &);
Position endPosition(const RangeImpl *);
} // namespace DOM
- (NSString *)href
{
- DOMString s = [self _linkElementImpl]->getAttribute(ATTR_HREF);
- if (!s.isNull()) {
- Document doc([self _linkElementImpl]->getDocument());
- s = doc.completeURL(s);
- }
- return s;
+ return [self _linkElementImpl]->href();
}
- (void)setHref:(NSString *)href
- (NSString *)href
{
- DOMString s = [self _baseElementImpl]->getAttribute(ATTR_HREF);
- if (!s.isNull()) {
- Document doc([self _baseElementImpl]->getDocument());
- s = doc.completeURL(s);
- }
- return s;
+ return [self _baseElementImpl]->href();
}
- (void)setHref:(NSString *)href
- (NSString *)src
{
- DOMString s = [self _inputElementImpl]->getAttribute(ATTR_SRC);
- if (!s.isNull()) {
- Document doc([self _inputElementImpl]->getDocument());
- s = doc.completeURL(s);
- }
- return s;
+ return [self _inputElementImpl]->src();
}
- (void)setSrc:(NSString *)src
- (NSString *)href
{
- DOMString s = [self _anchorElementImpl]->getAttribute(ATTR_HREF);
- if (!s.isNull()) {
- Document doc([self _anchorElementImpl]->getDocument());
- s = doc.completeURL(s);
- }
- return s;
+ return [self _anchorElementImpl]->href();
}
- (void)setHref:(NSString *)href
- (NSString *)src
{
- DOMString s = [self _imageElementImpl]->getAttribute(ATTR_SRC);
- if (!s.isNull()) {
- Document doc([self _imageElementImpl]->getDocument());
- s = doc.completeURL(s);
- }
- return s;
+ return [self _imageElementImpl]->src();
}
- (void)setSrc:(NSString *)src
- (NSString *)href
{
- DOMString s = [self _areaElementImpl]->getAttribute(ATTR_HREF);
- if (!s.isNull()) {
- Document doc([self _areaElementImpl]->getDocument());
- s = doc.completeURL(s);
- }
- return s;
+ return [self _areaElementImpl]->href();
}
- (void)setHref:(NSString *)href
using DOM::Node;
using DOM::NodeImpl;
using DOM::Position;
-using DOM::Range;
using khtml::EAffinity;
using khtml::EVerticalAlign;
KHTMLPart* p = d->part();
if (p) {
// catch stale KWQAccObject (see <rdar://problem/3960196>)
- if (p->document().handle() != d)
+ if (p->xmlDocImpl() != d)
return nil;
-
- Range r(p->document());
- if (m_renderer->isText()) {
- r.setStartBefore(e);
- r.setEndAfter(e);
- return p->text(r).getNSString();
- }
- if (e->firstChild()) {
- r.setStartBefore(e->firstChild());
- r.setEndAfter(e->lastChild());
- return p->text(r).getNSString();
- }
+ return plainText(rangeOfContents(e).get()).getNSString();
}
}
if (startVisiblePosition.isNull() || endVisiblePosition.isNull())
return nil;
- QString qString = plainText(makeRange(startVisiblePosition, endVisiblePosition));
+ QString qString = plainText(makeRange(startVisiblePosition, endVisiblePosition).get());
// transform it to a CFString and return that
return (id)qString.getCFString();
return nil;
// get the visible text in the range
- QString qString = plainText(makeRange(startVisiblePosition, endVisiblePosition));
+ QString qString = plainText(makeRange(startVisiblePosition, endVisiblePosition).get());
// transform it to a CFString and return that
return (id)qString.getCFString();
// iterate over the range to build the AX attributed string
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] init];
- TextIterator it(makeRange(startVisiblePosition, endVisiblePosition));
+ TextIterator it(makeRange(startVisiblePosition, endVisiblePosition).get());
while (!it.atEnd()) {
// locate the node for this range
- Node node = it.range().startContainer();
- ASSERT(node == it.range().endContainer());
- NodeImpl *nodeImpl = node.handle();
+ int exception = 0;
+ NodeImpl *nodeImpl = it.range()->startContainer(exception);
+ ASSERT(nodeImpl == it.range()->endContainer(exception));
// non-zero length means textual node, zero length means replaced node (AKA "attachments" in AX)
if (it.length() != 0) {
AXAttributedStringAppendText (attrString, nodeImpl, it.characters(), it.length());
} else {
- AXAttributedStringAppendReplaced (attrString, nodeImpl->childNode(it.range().startOffset()));
+ AXAttributedStringAppendReplaced (attrString, nodeImpl->childNode(it.range()->startOffset(exception)));
}
it.advance();
#import "khtml_part.h"
#import "dom_nodeimpl.h"
-#import "dom2_range.h"
#import "WebCoreKeyboardAccess.h"
void respondToChangedSelection(const khtml::Selection &oldSelection, bool closeTyping);
void respondToChangedContents();
virtual bool isContentEditable() const;
- virtual bool shouldBeginEditing(const DOM::Range &) const;
- virtual bool shouldEndEditing(const DOM::Range &) const;
+ virtual bool shouldBeginEditing(const DOM::RangeImpl *) const;
+ virtual bool shouldEndEditing(const DOM::RangeImpl *) const;
KJS::Bindings::RootObject *executionContextForDOM();
KJS::Bindings::RootObject *bindingRootObject();
bool thick;
};
- void setMarkedTextRange(const DOM::Range &, NSArray *attributes, NSArray *ranges);
- DOM::Range markedTextRange() const;
+ void setMarkedTextRange(const DOM::RangeImpl *, NSArray *attributes, NSArray *ranges);
+ DOM::RangeImpl *markedTextRange() const { return m_markedTextRange.get(); }
bool markedTextUsesUnderlines() const;
QValueList<MarkedTextUnderline> markedTextUnderlines() const;
mutable khtml::SharedPtr<DOM::NodeImpl> _elementToDraw;
- DOM::Range m_markedTextRange;
+ khtml::SharedPtr<DOM::RangeImpl> m_markedTextRange;
bool m_markedTextUsesUnderlines;
QValueList<MarkedTextUnderline> m_markedTextUnderlines;
using khtml::setEnd;
using khtml::setStart;
using khtml::ShadowData;
+using khtml::SharedPtr;
using khtml::startOfWord;
using khtml::startVisiblePosition;
using khtml::StyleDashboardRegion;
}
// Start on the correct edge of the selection, search to edge of document.
- Range searchRange(xmlDocImpl());
- searchRange.selectNodeContents(xmlDocImpl());
+ SharedPtr<RangeImpl> searchRange(rangeOfContents(xmlDocImpl()));
if (selectionStart()) {
if (forward) {
- setStart(searchRange, VisiblePosition(findInSelection ? selection().start() : selection().end(), selection().endAffinity()));
+ setStart(searchRange.get(), VisiblePosition(findInSelection ? selection().start() : selection().end(), selection().endAffinity()));
} else {
- setEnd(searchRange, VisiblePosition(findInSelection ? selection().end() : selection().start(), selection().startAffinity()));
+ setEnd(searchRange.get(), VisiblePosition(findInSelection ? selection().end() : selection().start(), selection().startAffinity()));
}
}
// Do the search once, then do it a second time to handle wrapped search.
// Searches some or all of document twice in the failure case, but that's probably OK.
- Range resultRange = findPlainText(searchRange, target, forward, caseFlag);
- if (resultRange.collapsed() && wrapFlag) {
- searchRange.selectNodeContents(xmlDocImpl());
- resultRange = findPlainText(searchRange, target, forward, caseFlag);
+ SharedPtr<RangeImpl> resultRange(findPlainText(searchRange.get(), target, forward, caseFlag));
+ int exception = 0;
+ if (resultRange->collapsed(exception) && wrapFlag) {
+ searchRange = rangeOfContents(xmlDocImpl());
+ resultRange = findPlainText(searchRange.get(), target, forward, caseFlag);
// If we got back to the same place we started, that doesn't count as success.
- if (resultRange == selection().toRange()) {
+ if (*resultRange == *selection().toRange()) {
return false;
}
}
- if (resultRange.collapsed()) {
+ if (resultRange->collapsed(exception)) {
return false;
}
- setSelection(Selection(resultRange, DOWNSTREAM, khtml::SEL_PREFER_UPSTREAM_AFFINITY));
+ setSelection(Selection(resultRange.get(), DOWNSTREAM, khtml::SEL_PREFER_UPSTREAM_AFFINITY));
jumpToSelection();
return true;
}
QString KWQKHTMLPart::advanceToNextMisspelling(bool startBeforeSelection)
{
+ int exception = 0;
+
// The basic approach is to search in two phases - from the selection end to the end of the doc, and
// then we wrap and search from the doc start to (approximately) where we started.
// Start at the end of the selection, search to edge of document. Starting at the selection end makes
// repeated "check spelling" commands work.
- Range searchRange(xmlDocImpl());
- searchRange.selectNodeContents(xmlDocImpl());
+ SharedPtr<RangeImpl> searchRange(rangeOfContents(xmlDocImpl()));
bool startedWithSelection = false;
if (selectionStart()) {
startedWithSelection = true;
VisiblePosition start(selection().start(), selection().startAffinity());
// We match AppKit's rule: Start 1 character before the selection.
VisiblePosition oneBeforeStart = start.previous();
- setStart(searchRange, oneBeforeStart.isNotNull() ? oneBeforeStart : start);
+ setStart(searchRange.get(), oneBeforeStart.isNotNull() ? oneBeforeStart : start);
} else {
- setStart(searchRange, VisiblePosition(selection().end(), selection().endAffinity()));
+ setStart(searchRange.get(), VisiblePosition(selection().end(), selection().endAffinity()));
}
}
// If we're not in an editable node, try to find one, make that our range to work in
- NodeImpl *editableNodeImpl = searchRange.startContainer().handle();
+ NodeImpl *editableNodeImpl = searchRange->startContainer(exception);
if (!editableNodeImpl->isContentEditable()) {
editableNodeImpl = editableNodeImpl->nextEditable();
if (!editableNodeImpl) {
return QString();
}
- searchRange.setStartBefore(editableNodeImpl);
+ searchRange->setStartBefore(editableNodeImpl, exception);
startedWithSelection = false; // won't need to wrap
}
// topNode defines the whole range we want to operate on
NodeImpl *topNode = editableNodeImpl->rootEditableElement();
- searchRange.setEndAfter(topNode);
+ searchRange->setEndAfter(topNode, exception);
// Make sure start of searchRange is not in the middle of a word. Jumping back a char and then
// forward by a word happens to do the trick.
if (startedWithSelection) {
- VisiblePosition oneBeforeStart = startVisiblePosition(searchRange, DOWNSTREAM).previous();
+ VisiblePosition oneBeforeStart = startVisiblePosition(searchRange.get(), DOWNSTREAM).previous();
if (oneBeforeStart.isNotNull()) {
- setStart(searchRange, endOfWord(oneBeforeStart));
+ setStart(searchRange.get(), endOfWord(oneBeforeStart));
} // else we were already at the start of the editable node
}
- if (searchRange.collapsed()) {
+ if (searchRange->collapsed(exception)) {
return QString(); // nothing to search in
}
NSSpellChecker *checker = [NSSpellChecker sharedSpellChecker];
- WordAwareIterator it(searchRange);
+ WordAwareIterator it(searchRange.get());
bool wrapped = false;
// We go to the end of our first range instead of the start of it, just to be sure
// we don't get foiled by any word boundary problems at the start. It means we might
// do a tiny bit more searching.
- NodeImpl *searchEndAfterWrapNode = it.range().endContainer().handle();
- long searchEndAfterWrapOffset = it.range().endOffset();
+ NodeImpl *searchEndAfterWrapNode = it.range()->endContainer(exception);
+ long searchEndAfterWrapOffset = it.range()->endOffset(exception);
while (1) {
if (!it.atEnd()) { // we may be starting at the end of the doc, and already by atEnd
if (misspelling.length > 0) {
// Build up result range and string. Note the misspelling may span many text nodes,
// but the CharIterator insulates us from this complexity
- Range misspellingRange(xmlDocImpl());
- CharacterIterator chars(it.range());
+ SharedPtr<RangeImpl> misspellingRange(rangeOfContents(xmlDocImpl()));
+ CharacterIterator chars(it.range().get());
chars.advance(misspelling.location);
- misspellingRange.setStart(chars.range().startContainer(), chars.range().startOffset());
+ misspellingRange->setStart(chars.range()->startContainer(exception), chars.range()->startOffset(exception), exception);
QString result = chars.string(misspelling.length);
- misspellingRange.setEnd(chars.range().startContainer(), chars.range().startOffset());
+ misspellingRange->setEnd(chars.range()->startContainer(exception), chars.range()->startOffset(exception), exception);
- setSelection(Selection(misspellingRange, DOWNSTREAM, khtml::SEL_PREFER_UPSTREAM_AFFINITY));
+ setSelection(Selection(misspellingRange.get(), DOWNSTREAM, khtml::SEL_PREFER_UPSTREAM_AFFINITY));
jumpToSelection();
// Mark misspelling in document.
- xmlDocImpl()->addMarker(misspellingRange, DocumentMarker::Spelling);
+ xmlDocImpl()->addMarker(misspellingRange.get(), DocumentMarker::Spelling);
return result;
}
}
} else {
// we've gone from the selection to the end of doc, now wrap around
wrapped = YES;
- searchRange.setStartBefore(topNode);
+ searchRange->setStartBefore(topNode, exception);
// going until the end of the very first chunk we tested is far enough
- searchRange.setEnd(searchEndAfterWrapNode, searchEndAfterWrapOffset);
- it = WordAwareIterator(searchRange);
+ searchRange->setEnd(searchEndAfterWrapNode, searchEndAfterWrapOffset, exception);
+ it = WordAwareIterator(searchRange.get());
}
}
}
NSFont *font = nil;
- Range r = d->m_selection.toRange();
- RangeImpl *range = r.handle();
+ SharedPtr<RangeImpl> range = d->m_selection.toRange();
NodeImpl *startNode = range->editingStartPosition().node();
if (startNode != nil) {
NodeImpl *pastEnd = range->pastEndNode();
if (![_bridge isContinuousSpellCheckingEnabled])
return;
- Range searchRange(selection.toRange());
- if (searchRange.isNull() || searchRange.isDetached())
+ SharedPtr<RangeImpl> searchRange(selection.toRange());
+ if (searchRange.get() || searchRange->isDetached())
return;
// If we're not in an editable node, bail.
- NodeImpl *editableNodeImpl = searchRange.startContainer().handle();
+ int exception = 0;
+ NodeImpl *editableNodeImpl = searchRange->startContainer(exception);
if (!editableNodeImpl->isContentEditable())
return;
NSSpellChecker *checker = [NSSpellChecker sharedSpellChecker];
- WordAwareIterator it(searchRange);
+ WordAwareIterator it(searchRange.get());
while (!it.atEnd()) { // we may be starting at the end of the doc, and already by atEnd
const QChar *chars = it.characters();
else {
// Build up result range and string. Note the misspelling may span many text nodes,
// but the CharIterator insulates us from this complexity
- Range misspellingRange(xmlDocImpl());
- CharacterIterator chars(it.range());
+ SharedPtr<RangeImpl> misspellingRange(rangeOfContents(xmlDocImpl()));
+ CharacterIterator chars(it.range().get());
chars.advance(misspelling.location);
- misspellingRange.setStart(chars.range().startContainer(), chars.range().startOffset());
+ misspellingRange->setStart(chars.range()->startContainer(exception), chars.range()->startOffset(exception), exception);
chars.advance(misspelling.length);
- misspellingRange.setEnd(chars.range().startContainer(), chars.range().startOffset());
+ misspellingRange->setEnd(chars.range()->startContainer(exception), chars.range()->startOffset(exception), exception);
// Mark misspelling in document.
- xmlDocImpl()->addMarker(misspellingRange, DocumentMarker::Spelling);
+ xmlDocImpl()->addMarker(misspellingRange.get(), DocumentMarker::Spelling);
startIndex = misspelling.location + misspelling.length;
}
}
// This only erases a marker in the first word of the selection.
// Perhaps peculiar, but it matches AppKit.
- xmlDocImpl()->removeMarker(newAdjacentWords.toRange(), DocumentMarker::Spelling);
+ xmlDocImpl()->removeMarker(newAdjacentWords.toRange().get(), DocumentMarker::Spelling);
}
} else {
// When continuous spell checking is off, no markers appear after the selection changes.
return KHTMLPart::isContentEditable() || [_bridge isEditable];
}
-bool KWQKHTMLPart::shouldBeginEditing(const Range &range) const
+bool KWQKHTMLPart::shouldBeginEditing(const RangeImpl *range) const
{
- ASSERT(!range.isNull());
- return [_bridge shouldBeginEditing:[DOMRange _rangeWithImpl:range.handle()]];
+ ASSERT(range);
+ return [_bridge shouldBeginEditing:[DOMRange _rangeWithImpl:const_cast<RangeImpl *>(range)]];
}
-bool KWQKHTMLPart::shouldEndEditing(const Range &range) const
+bool KWQKHTMLPart::shouldEndEditing(const RangeImpl *range) const
{
- ASSERT(!range.isNull());
- return [_bridge shouldEndEditing:[DOMRange _rangeWithImpl:range.handle()]];
+ ASSERT(range);
+ return [_bridge shouldEndEditing:[DOMRange _rangeWithImpl:const_cast<RangeImpl *>(range)]];
}
-DOM::Range KWQKHTMLPart::markedTextRange() const
-{
- return m_markedTextRange;
-}
-
-static QValueList<KWQKHTMLPart::MarkedTextUnderline> convertAttributesToUnderlines(const DOM::Range &markedTextRange, NSArray *attributes, NSArray *ranges)
+static QValueList<KWQKHTMLPart::MarkedTextUnderline> convertAttributesToUnderlines(const DOM::RangeImpl *markedTextRange, NSArray *attributes, NSArray *ranges)
{
QValueList<KWQKHTMLPart::MarkedTextUnderline> result;
- int baseOffset = markedTextRange.startOffset();
+ int exception = 0;
+ int baseOffset = markedTextRange->startOffset(exception);
unsigned length = [attributes count];
ASSERT([ranges count] == length);
return result;
}
-void KWQKHTMLPart::setMarkedTextRange(const DOM::Range &range, NSArray *attributes, NSArray *ranges)
+void KWQKHTMLPart::setMarkedTextRange(const DOM::RangeImpl *range, NSArray *attributes, NSArray *ranges)
{
- ASSERT(!range.handle() || range.startContainer() == range.endContainer());
- ASSERT(!range.handle() || range.collapsed() || range.startContainer().nodeType() == Node::TEXT_NODE);
+ int exception = 0;
+
+ ASSERT(!range || range->startContainer(exception) == range->endContainer(exception));
+ ASSERT(!range || range->collapsed(exception) || range->startContainer(exception)->nodeType() == Node::TEXT_NODE);
if (attributes == nil) {
m_markedTextUsesUnderlines = false;
m_markedTextUnderlines = convertAttributesToUnderlines(range, attributes, ranges);
}
- if (m_markedTextRange.handle() && xmlDocImpl()
- && m_markedTextRange.startContainer().handle()->renderer()) {
- m_markedTextRange.startContainer().handle()->renderer()->repaint();
+ if (m_markedTextRange.get() && xmlDocImpl() && m_markedTextRange->startContainer(exception)->renderer()) {
+ m_markedTextRange->startContainer(exception)->renderer()->repaint();
}
- if ( range.handle() && range.collapsed() ) {
- m_markedTextRange = DOM::Range(0);
+ if ( range && range->collapsed(exception) ) {
+ m_markedTextRange.reset();
} else {
- m_markedTextRange = range;
+ m_markedTextRange.reset(const_cast<RangeImpl *>(range));
}
- if (m_markedTextRange.handle() && xmlDocImpl()
- && m_markedTextRange.startContainer().handle()->renderer()) {
- m_markedTextRange.startContainer().handle()->renderer()->repaint();
+ if (m_markedTextRange.get() && xmlDocImpl() && m_markedTextRange->startContainer(exception)->renderer()) {
+ m_markedTextRange->startContainer(exception)->renderer()->repaint();
}
}
using DOM::HTMLInputElementImpl;
using DOM::NodeImpl;
using DOM::Position;
-using DOM::Range;
+using DOM::RangeImpl;
using khtml::ChildrenOnly;
using khtml::createMarkup;
using khtml::RenderWidget;
using khtml::ReplaceSelectionCommand;
using khtml::Selection;
+using khtml::SharedPtr;
using khtml::setAffinityUsingLinePosition;
using khtml::Tokenizer;
using khtml::TextIterator;
const AtomicString& link = e->getAttribute(ATTR_HREF);
if (!link.isNull()) {
- if (e->firstChild()) {
- Range r(doc);
- r.setStartBefore(e->firstChild());
- r.setEndAfter(e->lastChild());
- QString t = _part->text(r);
- if (!t.isEmpty()) {
- [element setObject:t.getNSString() forKey:WebCoreElementLinkLabelKey];
- }
+ QString t = plainText(rangeOfContents(e).get());
+ if (!t.isEmpty()) {
+ [element setObject:t.getNSString() forKey:WebCoreElementLinkLabelKey];
}
QString URLString = parseURL(link).string();
[element setObject:doc->completeURL(URLString).getNSString() forKey:WebCoreElementLinkURLKey];
// NOTE: The enums *must* match the very similar ones declared in ktml_selection.h
Selection selection(_part->selection());
selection.expandUsingGranularity(static_cast<ETextGranularity>(granularity));
- return [DOMRange _rangeWithImpl:selection.toRange().handle()];
+ return [DOMRange _rangeWithImpl:selection.toRange().get()];
}
- (DOMRange *)rangeByAlteringCurrentSelection:(WebSelectionAlteration)alteration direction:(WebSelectionDirection)direction granularity:(WebSelectionGranularity)granularity
selection.modify(static_cast<Selection::EAlter>(alteration),
static_cast<Selection::EDirection>(direction),
static_cast<ETextGranularity>(granularity));
- return [DOMRange _rangeWithImpl:selection.toRange().handle()];
+ return [DOMRange _rangeWithImpl:selection.toRange().get()];
}
- (void)alterCurrentSelection:(WebSelectionAlteration)alteration direction:(WebSelectionDirection)direction granularity:(WebSelectionGranularity)granularity
Selection selection(_part->selection());
selection.modify(static_cast<Selection::EAlter>(alteration), static_cast<int>(verticalDistance));
- return [DOMRange _rangeWithImpl:selection.toRange().handle()];
+ return [DOMRange _rangeWithImpl:selection.toRange().get()];
}
- (void)alterCurrentSelection:(WebSelectionAlteration)alteration verticalDistance:(float)verticalDistance
- (DOMRange *)selectedDOMRange
{
- return [DOMRange _rangeWithImpl:_part->selection().toRange().handle()];
+ return [DOMRange _rangeWithImpl:_part->selection().toRange().get()];
}
-- (NSRange)convertToNSRange:(DOM::RangeImpl *)drange
+- (NSRange)convertToNSRange:(DOM::RangeImpl *)range
{
- if (!drange) {
+ if (!range || range->isDetached()) {
return NSMakeRange(NSNotFound, 0);
}
- Range toStartRange, toEndRange;
- Range actualRange = Range(drange);
- long startPosition, endPosition;
+ SharedPtr<RangeImpl> fromStartRange(_part->xmlDocImpl()->createRange());
+ int exception = 0;
+
+ fromStartRange->setEnd(range->startContainer(exception), range->startOffset(exception), exception);
+ long startPosition = TextIterator::rangeLength(fromStartRange.get());
+
+ fromStartRange->setEnd(range->endContainer(exception), range->endOffset(exception), exception);
+ long endPosition = TextIterator::rangeLength(fromStartRange.get());
- toStartRange = Range (_part->xmlDocImpl()->createRange());
- toStartRange.setEnd (actualRange.startContainer(), actualRange.startOffset());
- toEndRange = Range (_part->xmlDocImpl()->createRange());
- toEndRange.setEnd (actualRange.endContainer(), actualRange.endOffset());
-
- startPosition = TextIterator::rangeLength (toStartRange);
- endPosition = TextIterator::rangeLength (toEndRange);
-
return NSMakeRange(startPosition, endPosition - startPosition);
}
-- (DOM::Range)convertToDOMRange:(NSRange)nsrange
+- (RangeImpl *)convertToDOMRange:(NSRange)nsrange
{
- // Set the range to cover the entire document. This assumes that the start
- // and end node of the range are the document node.
- DOM::Range docRange = Range (_part->xmlDocImpl()->createRange());
- docRange.setEnd (docRange.endContainer(), docRange.endContainer().handle()->childNodeCount());
-
- DOM::Range resultRange = Range (_part->xmlDocImpl()->createRange());
- TextIterator::setRangeFromLocationAndLength (docRange, resultRange, nsrange.location, nsrange.length);
-
- return resultRange;
+ return TextIterator::rangeFromLocationAndLength(_part->xmlDocImpl(), nsrange.location, nsrange.length);
}
- (DOMRange *)convertToObjCDOMRange:(NSRange)nsrange
{
- return [DOMRange _rangeWithImpl:[self convertToDOMRange:nsrange].handle()];
+ return [DOMRange _rangeWithImpl:[self convertToDOMRange:nsrange]];
}
- (void)selectNSRange:(NSRange)range
{
- DOM::Range replaceRange = [self convertToDOMRange:range];
- _part->setSelection(Selection(replaceRange.handle(), khtml::SEL_DEFAULT_AFFINITY, khtml::SEL_DEFAULT_AFFINITY));
+ _part->setSelection(Selection([self convertToDOMRange:range], khtml::SEL_DEFAULT_AFFINITY, khtml::SEL_DEFAULT_AFFINITY));
}
- (NSRange)selectedNSRange
{
- return [self convertToNSRange:_part->selection().toRange().handle()];
+ return [self convertToNSRange:_part->selection().toRange().get()];
}
- (NSSelectionAffinity)selectionAffinity
- (DOMRange *)markDOMRange
{
- return [DOMRange _rangeWithImpl:_part->mark().toRange().handle()];
+ return [DOMRange _rangeWithImpl:_part->mark().toRange().get()];
}
- (void)setMarkedTextDOMRange:(DOMRange *)range customAttributes:(NSArray *)attributes ranges:(NSArray *)ranges
- (DOMRange *)markedTextDOMRange
{
- return [DOMRange _rangeWithImpl:_part->markedTextRange().handle()];
+ return [DOMRange _rangeWithImpl:_part->markedTextRange()];
}
- (NSRange)markedTextNSRange
{
- return [self convertToNSRange:_part->markedTextRange().handle()];
+ return [self convertToNSRange:_part->markedTextRange()];
}
- (void)replaceMarkedTextWithText:(NSString *)text
if (!partHasSelection(self))
return;
- Range markedTextRange = _part->markedTextRange();
- if (!markedTextRange.isNull() && !markedTextRange.collapsed())
+ int exception = 0;
+
+ RangeImpl *markedTextRange = _part->markedTextRange();
+ if (markedTextRange && !markedTextRange->collapsed(exception))
TypingCommand::deleteKeyPressed(_part->xmlDocImpl(), NO);
if ([text length] > 0)
if (newEnd.isNull())
newEnd = end;
- return [DOMRange _rangeWithImpl:Range(newStart.node(), newStart.offset(), newEnd.node(), newEnd.offset()).handle()];
+ RangeImpl *range = _part->xmlDocImpl()->createRange();
+ int exception = 0;
+ range->setStart(newStart.node(), newStart.offset(), exception);
+ range->setEnd(newStart.node(), newStart.offset(), exception);
+ return [DOMRange _rangeWithImpl:range];
}
// Determines whether whitespace needs to be added around aString to preserve proper spacing and
- (DOMRange *)dragCaretDOMRange
{
- return [DOMRange _rangeWithImpl:_part->dragCaret().toRange().handle()];
+ return [DOMRange _rangeWithImpl:_part->dragCaret().toRange().get()];
}
- (DOMRange *)editableDOMRangeForPoint:(NSPoint)point
{
VisiblePosition position = [self _visiblePositionForPoint:point];
- return position.isNull() ? nil : [DOMRange _rangeWithImpl:Selection(position).toRange().handle()];
+ return position.isNull() ? nil : [DOMRange _rangeWithImpl:Selection(position).toRange().get()];
}
- (void)deleteSelectionWithSmartDelete:(BOOL)smartDelete
if (caret == next || caret == previous)
return nil;
- return [DOMRange _rangeWithImpl:makeRange(previous, next).handle()];
+ return [DOMRange _rangeWithImpl:makeRange(previous, next).get()];
}
- (NSMutableDictionary *)dashboardRegions