Reviewed by Kevin.
authormjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 May 2005 04:40:49 +0000 (04:40 +0000)
committermjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 May 2005 04:40:49 +0000 (04:40 +0000)
- remove more isFirst/isLast functions and use isStart/isEnd verions instead

        * khtml/editing/htmlediting.cpp:
        (khtml::DeleteSelectionCommand::initializePositionData):
        (khtml::InsertParagraphSeparatorCommand::calculateStyleBeforeInsertion):
        (khtml::InsertTextCommand::input):
        (khtml::ReplaceSelectionCommand::doApply):
        (khtml::ReplaceSelectionCommand::removeLinePlaceholderIfNeeded):
        * khtml/editing/visible_position.cpp:
        (khtml::VisiblePosition::previous):
        (khtml::setAffinityUsingLinePosition):
        (khtml::isFirstVisiblePositionInNode):
        * khtml/editing/visible_position.h:
        * khtml/editing/visible_units.cpp:
        (khtml::endOfLine):
        (khtml::previousLinePosition):
        * khtml/xml/dom_position.cpp:
        (DOM::Position::previousCharacterPosition):
        (DOM::Position::nextCharacterPosition):
        * kwq/WebCoreBridge.mm:
        (-[WebCoreBridge smartInsertForString:replacingRange:beforeString:afterString:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@9149 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog-2005-08-23
WebCore/khtml/editing/htmlediting.cpp
WebCore/khtml/editing/visible_position.cpp
WebCore/khtml/editing/visible_position.h
WebCore/khtml/editing/visible_units.cpp
WebCore/khtml/xml/dom_position.cpp
WebCore/kwq/WebCoreBridge.mm

index b5a7ff527744a827f920c256d60e9b9eb8ffc7ab..f60399d3ea3ce9e962315b3bfbb1eaacdf071593 100644 (file)
@@ -1,3 +1,29 @@
+2005-05-09  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Kevin.
+
+       - remove more isFirst/isLast functions and use isStart/isEnd verions instead
+
+        * khtml/editing/htmlediting.cpp:
+        (khtml::DeleteSelectionCommand::initializePositionData):
+        (khtml::InsertParagraphSeparatorCommand::calculateStyleBeforeInsertion):
+        (khtml::InsertTextCommand::input):
+        (khtml::ReplaceSelectionCommand::doApply):
+        (khtml::ReplaceSelectionCommand::removeLinePlaceholderIfNeeded):
+        * khtml/editing/visible_position.cpp:
+        (khtml::VisiblePosition::previous):
+        (khtml::setAffinityUsingLinePosition):
+        (khtml::isFirstVisiblePositionInNode):
+        * khtml/editing/visible_position.h:
+        * khtml/editing/visible_units.cpp:
+        (khtml::endOfLine):
+        (khtml::previousLinePosition):
+        * khtml/xml/dom_position.cpp:
+        (DOM::Position::previousCharacterPosition):
+        (DOM::Position::nextCharacterPosition):
+        * kwq/WebCoreBridge.mm:
+        (-[WebCoreBridge smartInsertForString:replacingRange:beforeString:afterString:]):
+
 2005-05-09  Maciej Stachowiak  <mjs@apple.com>
 
         Reviewed by Kevin.
index 1fa5b2ef6eb09128e43c5b7710b63c7a3b256307..23a23589cb2a50dc02d9ff8f631adc132459ff1b 100644 (file)
@@ -2652,7 +2652,7 @@ void DeleteSelectionCommand::initializePositionData()
     // This is one of the tests that determines if block merging of content needs to be done.
     //
     VisiblePosition visibleEnd(end, m_selectionToDelete.endAffinity());
-    if (isFirstVisiblePositionInParagraph(visibleEnd) || isLastVisiblePositionInParagraph(visibleEnd)) {
+    if (isStartOfParagraph(visibleEnd) || isEndOfParagraph(visibleEnd)) {
         Position previousLineStart = previousLinePosition(visibleEnd, 0).deepEquivalent();
         if (previousLineStart.isNull() || RangeImpl::compareBoundaryPoints(previousLineStart, m_downstreamStart) >= 0)
             m_mergeBlocksAfterDelete = false;
@@ -3455,7 +3455,7 @@ void InsertParagraphSeparatorCommand::calculateStyleBeforeInsertion(const Positi
     // a paragraph. Otherwise, content that is moved as part of the work of the command
     // will lend their styles to the new paragraph without any extra work needed.
     VisiblePosition visiblePos(pos, VP_DEFAULT_AFFINITY);
-    if (!isFirstVisiblePositionInParagraph(visiblePos) && !isLastVisiblePositionInParagraph(visiblePos))
+    if (!isStartOfParagraph(visiblePos) && !isEndOfParagraph(visiblePos))
         return;
     
     if (m_style)
@@ -3896,7 +3896,7 @@ void InsertTextCommand::input(const DOMString &text, bool selectInsertedText)
     assert(text.find('\n') == -1);
 
     Selection selection = endingSelection();
-    bool adjustDownstream = isFirstVisiblePositionOnLine(VisiblePosition(selection.start().downstream(), DOWNSTREAM));
+    bool adjustDownstream = isStartOfLine(VisiblePosition(selection.start().downstream(), DOWNSTREAM));
 
     // Delete the current selection, or collapse whitespace, as needed
     if (selection.isRange())
@@ -4895,7 +4895,7 @@ void ReplaceSelectionCommand::doApply()
         downstream = positionOutsideContainingSpecialElement(downstream);
         if (downstream.node()->id() == ID_BR && downstream.offset() == 0 && 
             m_fragment.hasInterchangeNewlineAtEnd() &&
-            isFirstVisiblePositionOnLine(VisiblePosition(downstream, VP_DEFAULT_AFFINITY)))
+            isStartOfLine(VisiblePosition(downstream, VP_DEFAULT_AFFINITY)))
             linePlaceholder = downstream.node();
     }
     
@@ -4907,14 +4907,14 @@ void ReplaceSelectionCommand::doApply()
     if (m_smartReplace) {
         VisiblePosition visiblePos = VisiblePosition(startPos, VP_DEFAULT_AFFINITY);
         assert(visiblePos.isNotNull());
-        addLeadingSpace = startPos.leadingWhitespacePosition(VP_DEFAULT_AFFINITY, true).isNull() && !isFirstVisiblePositionOnLine(visiblePos);
+        addLeadingSpace = startPos.leadingWhitespacePosition(VP_DEFAULT_AFFINITY, true).isNull() && !isStartOfLine(visiblePos);
         if (addLeadingSpace) {
             QChar previousChar = visiblePos.previous().character();
             if (!previousChar.isNull()) {
                 addLeadingSpace = !part->isCharacterSmartReplaceExempt(previousChar, true);
             }
         }
-        addTrailingSpace = startPos.trailingWhitespacePosition(VP_DEFAULT_AFFINITY, true).isNull() && !isLastVisiblePositionOnLine(visiblePos);
+        addTrailingSpace = startPos.trailingWhitespacePosition(VP_DEFAULT_AFFINITY, true).isNull() && !isEndOfLine(visiblePos);
         if (addTrailingSpace) {
             QChar thisChar = visiblePos.character();
             if (!thisChar.isNull()) {
@@ -5124,7 +5124,7 @@ void ReplaceSelectionCommand::removeLinePlaceholderIfNeeded(NodeImpl *linePlaceh
     if (linePlaceholder->inDocument()) {
         VisiblePosition placeholderPos(linePlaceholder, linePlaceholder->renderer()->caretMinOffset(), DOWNSTREAM);
         if (placeholderPos.next().isNull() ||
-            !(isFirstVisiblePositionOnLine(placeholderPos) && isLastVisiblePositionOnLine(placeholderPos))) {
+            !(isStartOfLine(placeholderPos) && isEndOfLine(placeholderPos))) {
             NodeImpl *block = linePlaceholder->enclosingBlockFlowElement();
             removeNode(linePlaceholder);
             document()->updateLayout();
index 68635da563cea707b2dbdaf2d1b93797ef9f4b6b..fdc9fd1085549fefc119523b288219b3d365dfd8 100644 (file)
@@ -177,7 +177,7 @@ VisiblePosition VisiblePosition::previous() const
     if (result.isNotNull() && m_affinity == UPSTREAM) {
         VisiblePosition temp = result;
         temp.setAffinity(UPSTREAM);
-        ASSERT(!visiblePositionsOnDifferentLines(temp, result));
+        ASSERT(inSameLine(temp, result));
     }
 #endif
     return result;
@@ -444,7 +444,7 @@ void setAffinityUsingLinePosition(VisiblePosition &pos)
     if (pos.isNotNull() && pos.affinity() == UPSTREAM) {
         VisiblePosition temp(pos);
         temp.setAffinity(DOWNSTREAM);
-        if (!visiblePositionsOnDifferentLines(temp, pos))
+        if (inSameLine(temp, pos))
             pos.setAffinity(DOWNSTREAM);
     }
 }
@@ -457,90 +457,6 @@ DOM::NodeImpl *enclosingBlockFlowElement(const VisiblePosition &vp)
     return vp.position().node()->enclosingBlockFlowElement();
 }
 
-bool visiblePositionsOnDifferentLines(const VisiblePosition &pos1, const VisiblePosition &pos2)
-{
-    if (pos1.isNull() || pos2.isNull())
-        return false;
-    if (pos1 == pos2)
-        return false;
-    
-    Position p1 = pos1.deepEquivalent();
-    Position p2 = pos2.deepEquivalent();
-    RenderObject *r1 = p1.node()->renderer();
-    RenderObject *r2 = p2.node()->renderer();
-    if (r1->isBlockFlow() || r2->isBlockFlow())
-        return r1 == r2 ? false : true;
-    InlineBox *b1 = r1 ? r1->inlineBox(p1.offset(), pos1.affinity()) : 0;
-    InlineBox *b2 = r2 ? r2->inlineBox(p2.offset(), pos2.affinity()) : 0;
-    return (b1 && b2 && b1->root() != b2->root());
-}
-
-enum EBlockRelationship { 
-    NoBlockRelationship, 
-    SameBlockRelationship, 
-    PeerBlockRelationship, 
-    AncestorBlockRelationship, 
-    DescendantBlockRelationship, 
-    OtherBlockRelationship 
-};
-
-static EBlockRelationship blockRelationship(const VisiblePosition &pos1, const VisiblePosition &pos2)
-{
-    if (pos1.isNull() || pos2.isNull())
-        return NoBlockRelationship;
-    if (pos1 == pos2)
-        return SameBlockRelationship;
-
-    Position p1 = pos1.deepEquivalent();
-    Position p2 = pos2.deepEquivalent();
-    NodeImpl *b1 = p1.node()->enclosingBlockFlowElement();
-    NodeImpl *b2 = p2.node()->enclosingBlockFlowElement();
-    if (!b1 || !b2)
-        return NoBlockRelationship;
-    if (b1 == b2) 
-        return SameBlockRelationship;
-    if (b1->parentNode() == b2->parentNode())
-        return PeerBlockRelationship;
-    if (b2->isAncestor(b1))
-        return AncestorBlockRelationship;
-    if (b1->isAncestor(b2))
-        return DescendantBlockRelationship;
-    return OtherBlockRelationship;
-}
-
-bool visiblePositionsInDifferentBlocks(const VisiblePosition &pos1, const VisiblePosition &pos2)
-{
-    switch (blockRelationship(pos1, pos2)) {
-        case NoBlockRelationship:
-        case SameBlockRelationship:
-            return false;
-        case PeerBlockRelationship:
-        case AncestorBlockRelationship:
-        case DescendantBlockRelationship:
-        case OtherBlockRelationship:
-            return true;
-    }
-    ASSERT_NOT_REACHED();
-    return false;
-}
-
-bool isFirstVisiblePositionOnLine(const VisiblePosition &pos)
-{
-    if (pos.isNull())
-        return false;
-        
-    VisiblePosition previous = pos.previous();
-    return previous.isNull() || visiblePositionsOnDifferentLines(pos, previous);
-}
-
-bool isFirstVisiblePositionInParagraph(const VisiblePosition &pos)
-{
-    if (pos.isNull())
-        return false;
-
-    return pos.deepEquivalent().upstream().node()->id() == ID_BR || isStartOfBlock(pos);
-}
-
 bool isFirstVisiblePositionInNode(const VisiblePosition &pos, const NodeImpl *node)
 {
     if (pos.isNull())
@@ -550,23 +466,6 @@ bool isFirstVisiblePositionInNode(const VisiblePosition &pos, const NodeImpl *no
     return previous.isNull() || !previous.deepEquivalent().node()->isAncestor(node);
 }
 
-bool isLastVisiblePositionOnLine(const VisiblePosition &pos)
-{
-    if (pos.isNull())
-        return false;
-        
-    VisiblePosition next = pos.next();
-    return next.isNull() || visiblePositionsOnDifferentLines(pos, next);
-}
-
-bool isLastVisiblePositionInParagraph(const VisiblePosition &pos)
-{
-    if (pos.isNull())
-        return false;
-
-    return pos.deepEquivalent().downstream().node()->id() == ID_BR || isEndOfBlock(pos);
-}
-
 bool isLastVisiblePositionInNode(const VisiblePosition &pos, const NodeImpl *node)
 {
     if (pos.isNull())
index d6ba961481557ded0937753a31f5dd2c6c2e7312..f4823098a3761dbfe91f07c70c68cfb4bac7fc29 100644 (file)
@@ -133,13 +133,7 @@ void setAffinityUsingLinePosition(VisiblePosition &);
 
 DOM::NodeImpl *enclosingBlockFlowElement(const VisiblePosition &);
 
-bool visiblePositionsOnDifferentLines(const VisiblePosition &, const VisiblePosition &);
-bool visiblePositionsInDifferentBlocks(const VisiblePosition &, const VisiblePosition &);
-bool isFirstVisiblePositionOnLine(const VisiblePosition &);
-bool isFirstVisiblePositionInParagraph(const VisiblePosition &);
 bool isFirstVisiblePositionInNode(const VisiblePosition &, const DOM::NodeImpl *);
-bool isLastVisiblePositionOnLine(const VisiblePosition &);
-bool isLastVisiblePositionInParagraph(const VisiblePosition &);
 bool isLastVisiblePositionInNode(const VisiblePosition &, const DOM::NodeImpl *);
 
 } // namespace khtml
index dffa5499c375e24bf0f7433ceb01d05a5ae21148..db1a0fa9535330113d2851b7d9e9b708684c46c4 100644 (file)
@@ -339,7 +339,7 @@ VisiblePosition endOfLine(const VisiblePosition &c, EIncludeLineBreak includeLin
     VisiblePosition result = VisiblePosition(endNode, endOffset, DOWNSTREAM);
     VisiblePosition temp = result;
     temp.setAffinity(UPSTREAM);
-    if (visiblePositionsOnDifferentLines(temp, result))
+    if (!inSameLine(temp, result))
         result.setAffinity(UPSTREAM);
     
     return result;
@@ -410,7 +410,7 @@ VisiblePosition previousLinePosition(const VisiblePosition &c, int x)
                 // (whereupon the next VP is returned, which could be
                 // back on c's line)
                 VisiblePosition c2 = VisiblePosition(pos, DOWNSTREAM);
-                if (visiblePositionsOnDifferentLines(c, c2))
+                if (!inSameLine(c, c2))
                     return c2;
             }
             n = n->previousEditable();
@@ -696,7 +696,6 @@ VisiblePosition startOfBlock(const VisiblePosition &c)
     return VisiblePosition(Position(startNode->enclosingBlockFlowElement(), 0), DOWNSTREAM);
 }
 
-// written, but not yet tested
 VisiblePosition endOfBlock(const VisiblePosition &c)
 {
     Position p = c.deepEquivalent();
index 9883072dc9109a9fe580b509acc0ff088d0902aa..d4fefa2791fe801752e0bdfeaae9eb0152fe83bd 100644 (file)
@@ -38,6 +38,7 @@
 #include "htmltags.h"
 #include "text_affinity.h"
 #include "visible_position.h"
+#include "visible_units.h"
 #include "rendering/render_block.h"
 #include "rendering/render_flow.h"
 #include "rendering/render_line.h"
@@ -267,7 +268,7 @@ Position Position::previousCharacterPosition(EAffinity affinity) const
 
     NodeImpl *fromRootEditableElement = node()->rootEditableElement();
 
-    bool atStartOfLine = isFirstVisiblePositionOnLine(VisiblePosition(*this, affinity));
+    bool atStartOfLine = isStartOfLine(VisiblePosition(*this, affinity));
     bool rendered = inRenderedContent();
     
     Position currentPos = *this;
@@ -295,7 +296,7 @@ Position Position::nextCharacterPosition(EAffinity affinity) const
 
     NodeImpl *fromRootEditableElement = node()->rootEditableElement();
 
-    bool atEndOfLine = isLastVisiblePositionOnLine(VisiblePosition(*this, affinity));
+    bool atEndOfLine = isEndOfLine(VisiblePosition(*this, affinity));
     bool rendered = inRenderedContent();
     
     Position currentPos = *this;
index bb398fa2d629df71921fea50742aae93026135e0..18631064467325eca909a434ccf85d3b4ef54b7e 100644 (file)
@@ -1795,7 +1795,7 @@ static HTMLFormElementImpl *formElementFromDOMElement(DOMElement *element)
     if (startVisiblePos.isNull() || endVisiblePos.isNull())
         return;
 
-    bool addLeadingSpace = startPos.leadingWhitespacePosition(khtml::VP_DEFAULT_AFFINITY, true).isNull() && !isFirstVisiblePositionInParagraph(startVisiblePos);
+    bool addLeadingSpace = startPos.leadingWhitespacePosition(khtml::VP_DEFAULT_AFFINITY, true).isNull() && !isStartOfParagraph(startVisiblePos);
     if (addLeadingSpace) {
         QChar previousChar = startVisiblePos.previous().character();
         if (!previousChar.isNull()) {
@@ -1803,7 +1803,7 @@ static HTMLFormElementImpl *formElementFromDOMElement(DOMElement *element)
         }
     }
     
-    bool addTrailingSpace = endPos.trailingWhitespacePosition(khtml::VP_DEFAULT_AFFINITY, true).isNull() && !isLastVisiblePositionInParagraph(endVisiblePos);
+    bool addTrailingSpace = endPos.trailingWhitespacePosition(khtml::VP_DEFAULT_AFFINITY, true).isNull() && !isEndOfParagraph(endVisiblePos);
     if (addTrailingSpace) {
         QChar thisChar = endVisiblePos.character();
         if (!thisChar.isNull()) {