- remove some of the uses of upstream/downstream DoNotStayInBlock
* khtml/editing/markup.cpp:
(khtml::createMarkup): Instead of using upstream to decide if a line break should be
added at the end, use inSameParagraph.
* khtml/editing/selection.cpp:
(khtml::Selection::debugPosition): Remove the code to print upstream and downstream,
the selection endpoints themselves are adequate for debugging and are what we use for
layout tests.
* khtml/xml/dom2_rangeimpl.cpp:
(DOM::RangeImpl::editingStartPosition): Skip a possible paragraph break at the start
of the selection in a more explicit way to avoid DoNotStayInBlock.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@9137
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2005-05-07 Maciej Stachowiak <mjs@apple.com>
+
+ Reviewed by Kevin.
+
+ - remove some of the uses of upstream/downstream DoNotStayInBlock
+
+ * khtml/editing/markup.cpp:
+ (khtml::createMarkup): Instead of using upstream to decide if a line break should be
+ added at the end, use inSameParagraph.
+ * khtml/editing/selection.cpp:
+ (khtml::Selection::debugPosition): Remove the code to print upstream and downstream,
+ the selection endpoints themselves are adequate for debugging and are what we use for
+ layout tests.
+ * khtml/xml/dom2_rangeimpl.cpp:
+ (DOM::RangeImpl::editingStartPosition): Skip a possible paragraph break at the start
+ of the selection in a more explicit way to avoid DoNotStayInBlock.
+
2005-05-07 David Harrison <harrison@apple.com>
Reviewed by John.
using DOM::Range;
using DOM::RangeImpl;
using DOM::StayInBlock;
-using DOM::DoNotStayInBlock;
namespace khtml {
if (m_start == m_end) {
Position pos = m_start;
- Position upstream = pos.upstream(DoNotStayInBlock);
- Position downstream = pos.downstream(DoNotStayInBlock);
- fprintf(stderr, "upstream: %s %p:%ld\n", upstream.node()->nodeName().string().latin1(), upstream.node(), upstream.offset());
fprintf(stderr, "pos: %s %p:%ld\n", pos.node()->nodeName().string().latin1(), pos.node(), pos.offset());
- fprintf(stderr, "downstream: %s %p:%ld\n", downstream.node()->nodeName().string().latin1(), downstream.node(), downstream.offset());
}
else {
Position pos = m_start;
- Position upstream = pos.upstream(DoNotStayInBlock);
- Position downstream = pos.downstream(DoNotStayInBlock);
- fprintf(stderr, "upstream: %s %p:%ld\n", upstream.node()->nodeName().string().latin1(), upstream.node(), upstream.offset());
fprintf(stderr, "start: %s %p:%ld\n", pos.node()->nodeName().string().latin1(), pos.node(), pos.offset());
- fprintf(stderr, "downstream: %s %p:%ld\n", downstream.node()->nodeName().string().latin1(), downstream.node(), downstream.offset());
fprintf(stderr, "-----------------------------------\n");
pos = m_end;
- upstream = pos.upstream(DoNotStayInBlock);
- downstream = pos.downstream(DoNotStayInBlock);
- fprintf(stderr, "upstream: %s %p:%ld\n", upstream.node()->nodeName().string().latin1(), upstream.node(), upstream.offset());
fprintf(stderr, "end: %s %p:%ld\n", pos.node()->nodeName().string().latin1(), pos.node(), pos.offset());
- fprintf(stderr, "downstream: %s %p:%ld\n", downstream.node()->nodeName().string().latin1(), downstream.node(), downstream.offset());
fprintf(stderr, "-----------------------------------\n");
}
}
if (annotate) {
- Position pos(endPosition(range));
- NodeImpl *block = pos.node()->enclosingBlockFlowElement();
- NodeImpl *upstreamBlock = pos.upstream(DOM::DoNotStayInBlock).node()->enclosingBlockFlowElement();
- if (block != upstreamBlock) {
+ if (!inSameBlock(visibleEnd, visibleEnd.previous()))
markups.append(interchangeNewlineString);
- }
}
// Retain the Mail quote level by including all ancestor mail block quotes.
using DOM::Range;
using DOM::RangeImpl;
using DOM::StayInBlock;
-using DOM::DoNotStayInBlock;
namespace khtml {
if (m_start == m_end) {
Position pos = m_start;
- Position upstream = pos.upstream(DoNotStayInBlock);
- Position downstream = pos.downstream(DoNotStayInBlock);
- fprintf(stderr, "upstream: %s %p:%ld\n", upstream.node()->nodeName().string().latin1(), upstream.node(), upstream.offset());
fprintf(stderr, "pos: %s %p:%ld\n", pos.node()->nodeName().string().latin1(), pos.node(), pos.offset());
- fprintf(stderr, "downstream: %s %p:%ld\n", downstream.node()->nodeName().string().latin1(), downstream.node(), downstream.offset());
}
else {
Position pos = m_start;
- Position upstream = pos.upstream(DoNotStayInBlock);
- Position downstream = pos.downstream(DoNotStayInBlock);
- fprintf(stderr, "upstream: %s %p:%ld\n", upstream.node()->nodeName().string().latin1(), upstream.node(), upstream.offset());
fprintf(stderr, "start: %s %p:%ld\n", pos.node()->nodeName().string().latin1(), pos.node(), pos.offset());
- fprintf(stderr, "downstream: %s %p:%ld\n", downstream.node()->nodeName().string().latin1(), downstream.node(), downstream.offset());
fprintf(stderr, "-----------------------------------\n");
pos = m_end;
- upstream = pos.upstream(DoNotStayInBlock);
- downstream = pos.downstream(DoNotStayInBlock);
- fprintf(stderr, "upstream: %s %p:%ld\n", upstream.node()->nodeName().string().latin1(), upstream.node(), upstream.offset());
fprintf(stderr, "end: %s %p:%ld\n", pos.node()->nodeName().string().latin1(), pos.node(), pos.offset());
- fprintf(stderr, "downstream: %s %p:%ld\n", downstream.node()->nodeName().string().latin1(), downstream.node(), downstream.offset());
fprintf(stderr, "-----------------------------------\n");
}
#include "misc/htmltags.h"
#include "editing/markup.h"
#include "editing/visible_position.h"
+#include "editing/visible_units.h"
#include "editing/visible_text.h"
#include "xml/dom_position.h"
using khtml::RenderBlock;
using khtml::RenderObject;
using khtml::VisiblePosition;
-using khtml::UPSTREAM;
+using khtml::DOWNSTREAM;
+using khtml::isEndOfParagraph;
namespace DOM {
Position RangeImpl::editingStartPosition() const
{
- // This function is used to avoid bugs like:
+ // This function is used by range style computations to avoid bugs like:
// <rdar://problem/4017641> REGRESSION (Mail): you can only bold/unbold a selection starting from end of line once
- // The issue here is that calculating the selection using the start of a range sometimes considers nodes that
- // should not be considered. In the case of this bug, we need to move past the offset after the last character
- // in a text node in order to make the right style calculation, so we do not wind up with a false "mixed"
- // style.
+ // 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.
- Position pos(m_startContainer, m_startOffset);
+ VisiblePosition pos(m_startContainer, m_startOffset, VP_DEFAULT_AFFINITY);
if (pos.isNull())
return Position();
-
+
int exceptionCode = 0;
- return collapsed(exceptionCode) ? VisiblePosition(pos, UPSTREAM).deepEquivalent() : pos.downstream(DoNotStayInBlock);
+ // if the selection is a caret, just return the position, since the style
+ // behind us is relevant
+ if (collapsed(exceptionCode))
+ return pos.position();
+
+ // if the selection starts just before a paragraph break, skip over it
+ if (isEndOfParagraph(pos))
+ return pos.next().position().downstream(StayInBlock);
+
+ // otherwise, make sure to be at the start of the first selected node,
+ // instead of possibly at the end of the last node before the selection
+ return pos.position().downstream(StayInBlock);
}
NodeImpl *RangeImpl::pastEndNode() const