Commit 47dd0e7b authored by eric@webkit.org's avatar eric@webkit.org
Browse files

2009-07-30 Eric Seidel <eric@webkit.org>

        Reviewed by Adam Barth.

        Re-organize position creation functions in preparation for adding more
        https://bugs.webkit.org/show_bug.cgi?id=25494

        Make position functions inline to avoid ref-churn.
        Remove startPosition/endPosition as they were only used in one place.

        No functional changes, thus no tests.

        * dom/Position.cpp:
        * dom/Position.h:
        (WebCore::positionBeforeNode):
        (WebCore::positionAfterNode):
        * editing/SelectionController.cpp:
        (WebCore::SelectionController::moveTo):
        * editing/TypingCommand.cpp:
        * editing/htmlediting.cpp:
        * editing/htmlediting.h:
        (WebCore::firstDeepEditingPositionForNode):
        (WebCore::lastDeepEditingPositionForNode):
        * rendering/RenderObject.cpp:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@48233 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 597bf70e
2009-07-30 Eric Seidel <eric@webkit.org>
Reviewed by Adam Barth.
Re-organize position creation functions in preparation for adding more
https://bugs.webkit.org/show_bug.cgi?id=25494
Make position functions inline to avoid ref-churn.
Remove startPosition/endPosition as they were only used in one place.
No functional changes, thus no tests.
* dom/Position.cpp:
* dom/Position.h:
(WebCore::positionBeforeNode):
(WebCore::positionAfterNode):
* editing/SelectionController.cpp:
(WebCore::SelectionController::moveTo):
* editing/TypingCommand.cpp:
* editing/htmlediting.cpp:
* editing/htmlediting.h:
(WebCore::firstDeepEditingPositionForNode):
(WebCore::lastDeepEditingPositionForNode):
* rendering/RenderObject.cpp:
2009-09-09 Kevin Watters <kevinwatters@gmail.com>
 
Reviewed by Kevin Ollivier.
......@@ -1115,28 +1115,7 @@ void Position::showTreeForThis() const
#endif
Position startPosition(const Range* r)
{
return r ? r->startPosition() : Position();
}
Position endPosition(const Range* r)
{
return r ? r->endPosition() : Position();
}
// NOTE: first/lastDeepEditingPositionForNode can return "editing positions" (like [img, 0])
// for elements which editing "ignores". the rest of the editing code will treat [img, 0]
// as "the last position before the img"
Position firstDeepEditingPositionForNode(Node* node)
{
return Position(node, 0);
}
Position lastDeepEditingPositionForNode(Node* node)
{
return Position(node, lastOffsetForEditing(node));
}
} // namespace WebCore
......
......@@ -28,6 +28,7 @@
#include "TextAffinity.h"
#include "TextDirection.h"
#include "Node.h" // for position creation functions
#include <wtf/Assertions.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefPtr.h>
......@@ -188,14 +189,24 @@ inline bool operator!=(const Position& a, const Position& b)
return !(a == b);
}
Position startPosition(const Range*);
Position endPosition(const Range*);
// We define position creation functions to make callsites more readable.
// These are inline to prevent ref-churn when returning a Position object.
// If we ever add a PassPosition we can make these non-inline.
// NOTE: first/lastDeepEditingPositionForNode can return "editing positions" (like [img, 0])
// for elements which editing "ignores". the rest of the editing code will treat [img, 0]
// as "the last position before the img"
Position firstDeepEditingPositionForNode(Node*);
Position lastDeepEditingPositionForNode(Node*);
inline Position positionBeforeNode(const Node* node)
{
// FIXME: This should ASSERT(node->parentNode())
// At least one caller currently hits this ASSERT though, which indicates
// that the caller is trying to make a position relative to a disconnected node (which is likely an error)
// Specifically, editing/deleting/delete-ligature-001.html crashes with ASSERT(node->parentNode())
return Position(node->parentNode(), node->nodeIndex(), Position::PositionIsOffsetInAnchor);
}
inline Position positionAfterNode(const Node* node)
{
ASSERT(node->parentNode());
return Position(node->parentNode(), node->nodeIndex() + 1, Position::PositionIsOffsetInAnchor);
}
} // namespace WebCore
......
......@@ -90,7 +90,8 @@ void SelectionController::moveTo(const Position &pos, EAffinity affinity, bool u
void SelectionController::moveTo(const Range *r, EAffinity affinity, bool userTriggered)
{
setSelection(VisibleSelection(startPosition(r), endPosition(r), affinity), true, true, userTriggered);
VisibleSelection selection = r ? VisibleSelection(r->startPosition(), r->endPosition(), affinity) : VisibleSelection(Position(), Position(), affinity);
setSelection(selection, true, true, userTriggered);
}
void SelectionController::moveTo(const Position &base, const Position &extent, EAffinity affinity, bool userTriggered)
......
......@@ -578,20 +578,6 @@ Node* isLastPositionBeforeTable(const VisiblePosition& visiblePosition)
return 0;
}
Position positionBeforeNode(const Node* node)
{
ASSERT(node);
// FIXME: Should ASSERT(node->parentNode()) but doing so results in editing/deleting/delete-ligature-001.html crashing
return Position(node->parentNode(), node->nodeIndex());
}
Position positionAfterNode(const Node* node)
{
ASSERT(node);
// FIXME: Should ASSERT(node->parentNode()) but doing so results in editing/deleting/delete-ligature-001.html crashing
return Position(node->parentNode(), node->nodeIndex() + 1);
}
// Returns the visible position at the beginning of a node
VisiblePosition visiblePositionBeforeNode(Node* node)
{
......
......@@ -29,6 +29,7 @@
#include <wtf/Forward.h>
#include "HTMLNames.h"
#include "ExceptionCode.h"
#include "Position.h"
namespace WebCore {
......@@ -70,8 +71,27 @@ const String& nonBreakingSpaceString();
//------------------------------------------------------------------------------------------
Position positionBeforeNode(const Node*);
Position positionAfterNode(const Node*);
// Position creation functions are inline to prevent ref-churn.
// Other Position creation functions are in Position.h
// but these depend on lastOffsetForEditing which is defined in htmlediting.h.
// NOTE: first/lastDeepEditingPositionForNode return legacy editing positions (like [img, 0])
// for elements which editing ignores. The rest of the editing code will treat [img, 0]
// as "the last position before the img".
// New code should use the creation functions in Position.h instead.
inline Position firstDeepEditingPositionForNode(Node* anchorNode)
{
ASSERT(anchorNode);
return Position(anchorNode, 0);
}
inline Position lastDeepEditingPositionForNode(Node* anchorNode)
{
ASSERT(anchorNode);
return Position(anchorNode, lastOffsetForEditing(anchorNode));
}
VisiblePosition visiblePositionBeforeNode(Node*);
VisiblePosition visiblePositionAfterNode(Node*);
PassRefPtr<Range> createRange(PassRefPtr<Document>, const VisiblePosition& start, const VisiblePosition& end, ExceptionCode&);
......
......@@ -47,6 +47,7 @@
#include "RenderTheme.h"
#include "RenderView.h"
#include "TransformState.h"
#include "htmlediting.h"
#include <algorithm>
#include <stdio.h>
#include <wtf/RefCountedLeakCounter.h>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment