follow-on to selectedText change
Darin Adler
darin at apple.com
Tue Oct 7 11:32:00 CEST 2003
I had to do some more work to make selectedText() still work right in
the case of no selection. I decided to make selection() return a null
DOM::Range rather than raising an exception when there is no selection.
-------------- next part --------------
Index: ChangeLog
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/ChangeLog,v
retrieving revision 1.2061
diff -p -u -u -p -r1.2061 ChangeLog
--- ChangeLog 2003/10/07 15:49:30 1.2061
+++ ChangeLog 2003/10/07 17:30:41
@@ -1,5 +1,16 @@
2003-10-07 Darin Adler <darin at apple.com>
+ Reviewed by Chris.
+
+ - fixed some exceptions I was seeing with my recent text change
+
+ * khtml/khtml_part.cpp:
+ (KHTMLPart::text): Return an empty string for a null range rather than raising an exception.
+ (KHTMLPart::selection): Return a null range rather than raising an exception if there is
+ no selection.
+
+2003-10-07 Darin Adler <darin at apple.com>
+
Reviewed by Dave.
- removed code that mutates \n into a space so we can pass more W3C DOM Level 1 Core tests
Index: khtml/khtml_part.cpp
===================================================================
RCS file: /local/home/cvs/Labyrinth/WebCore/khtml/khtml_part.cpp,v
retrieving revision 1.154
diff -p -u -u -p -r1.154 khtml/khtml_part.cpp
--- khtml/khtml_part.cpp 2003/10/07 00:01:43 1.154
+++ khtml/khtml_part.cpp 2003/10/07 17:30:44
@@ -2218,10 +2218,14 @@ bool KHTMLPart::findTextNext( const QStr
QString KHTMLPart::text(const DOM::Range &r) const
{
- // FIXME: This whole function should use the render tree and not the DOM tree, since elements could
- // be hidden using CSS, or additional generated content could be added. For now, we just make sure
- // text objects walk their renderers' InlineTextBox objects, so that we at least get the whitespace
- // stripped out properly and obey CSS visibility for text runs.
+ // FIXME: This whole function should use the render tree and not the DOM tree, since elements could
+ // be hidden using CSS, or additional generated content could be added. For now, we just make sure
+ // text objects walk their renderers' InlineTextBox objects, so that we at least get the whitespace
+ // stripped out properly and obey CSS visibility for text runs.
+
+ if (r.isNull())
+ return QString();
+
bool hasNewLine = true;
bool addedSpace = true;
QString text;
@@ -2391,8 +2395,10 @@ bool KHTMLPart::hasSelection() const
DOM::Range KHTMLPart::selection() const
{
DOM::Range r = document().createRange();
- r.setStart( d->m_selectionStart, d->m_startOffset );
- r.setEnd( d->m_selectionEnd, d->m_endOffset );
+ if (hasSelection()) {
+ r.setStart( d->m_selectionStart, d->m_startOffset );
+ r.setEnd( d->m_selectionEnd, d->m_endOffset );
+ }
return r;
}
-------------- next part --------------
-- Darin
More information about the Khtml-devel
mailing list