Commit 1aa7e2db authored by eric@webkit.org's avatar eric@webkit.org

Reviewed by Justin Garcia.

        Clean up DOMSelection to use some helper functions
        making the code smaller, and less error-prone.
        https://bugs.webkit.org/show_bug.cgi?id=19221

        I tried moving DOMSelection off of rangeCompliantEquivalent
        but failed.  VisibleSelection holds positions like (table, 1) to mean
        "after the table".

        * page/DOMSelection.cpp:
        (WebCore::DOMSelection::visibleSelection):
        (WebCore::anchorPosition):
        (WebCore::focusPosition):
        (WebCore::basePosition):
        (WebCore::extentPosition):
        (WebCore::DOMSelection::anchorNode):
        (WebCore::DOMSelection::anchorOffset):
        (WebCore::DOMSelection::focusNode):
        (WebCore::DOMSelection::focusOffset):
        (WebCore::DOMSelection::baseNode):
        (WebCore::DOMSelection::baseOffset):
        (WebCore::DOMSelection::extentNode):
        (WebCore::DOMSelection::extentOffset):
        * page/DOMSelection.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@41657 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 73586828
2009-02-26 Eric Seidel <eric@webkit.org>
Reviewed by Justin Garcia.
Add more logging to this test to make it
easier to debug when it breaks.
* editing/selection/click-before-and-after-table.html:
2009-03-12 Aaron Boodman <aa@chromium.org>
Reviewed by Dave Hyatt.
......
......@@ -19,9 +19,10 @@ function log(message) {
console.appendChild(li);
li.appendChild(text);
}
if (!window.layoutTestController)
if (!window.layoutTestController) {
log("This test uses the eventSender to do mouse clicks. To run it manually, click after the table, the caret should appear there (and not inside the table). Then click inside the table. The caret should appear inside it.");
else {
document.body.addEventListener("click", function() { var s = window.getSelection(); log("click @ " + event.clientX + ", " + event.clientY + " caret at: " + s.anchorNode + ", " + s.anchorOffset); }, true);
} else {
window.layoutTestController.dumpAsText();
var s, x, y, e, top, bottom, left, right;
table = document.getElementById("table");
......@@ -38,7 +39,7 @@ else {
eventSender.mouseUp();
s = window.getSelection();
if (!(s.anchorNode == document.body && s.anchorOffset == 1))
log("Failure: Clicking after the table didn't put the caret after it.");
log("Failure: Clicking @ " + x + ", " + y + " after the table didn't put the caret after it. Instead: " + s.anchorNode + ", " + s.anchorOffset);
x = right - 5;
y = (top + bottom) / 2;
......@@ -48,7 +49,7 @@ else {
eventSender.mouseUp();
s = window.getSelection();
if (s.anchorNode == document.body)
log("Failure: Clicking inside the table put the caret before or after it.");
log("Failure: Clicking @ " + x + ", " + y + " inside the table put the caret before or after it. Instead: " + s.anchorNode + ", " + s.anchorOffset);
x = left - 5;
y = (top + bottom) / 2;
......@@ -59,7 +60,7 @@ else {
s = window.getSelection();
if (s.anchorNode != table || s.anchorOffset != 0)
if (!(s.anchorNode == document.body && s.anchorOffset == 0))
log("Failure: Clicking before the table should be the caret before it.");
log("Failure: Clicking @ " + x + ", " + y + " before the table should be the caret before it. Instead: " + s.anchorNode + ", " + s.anchorOffset);
x = left + 5;
y = (top + bottom) / 2;
......@@ -69,7 +70,7 @@ else {
eventSender.mouseUp();
s = window.getSelection();
if (s.anchorNode == document.body)
log("Failure: Clicking inside the table put the caret before or after it.");
log("Failure: Clicking @ " + x + ", " + y + " inside the table put the caret before or after it. Instead: " + s.anchorNode + ", " + s.anchorOffset);
}
</script>
</body>
\ No newline at end of file
</body>
2009-02-26 Eric Seidel <eric@webkit.org>
Reviewed by Justin Garcia.
Clean up DOMSelection to use some helper functions
making the code smaller, and less error-prone.
https://bugs.webkit.org/show_bug.cgi?id=19221
I tried moving DOMSelection off of rangeCompliantEquivalent
but failed. VisibleSelection holds positions like (table, 1) to mean
"after the table".
* page/DOMSelection.cpp:
(WebCore::DOMSelection::visibleSelection):
(WebCore::anchorPosition):
(WebCore::focusPosition):
(WebCore::basePosition):
(WebCore::extentPosition):
(WebCore::DOMSelection::anchorNode):
(WebCore::DOMSelection::anchorOffset):
(WebCore::DOMSelection::focusNode):
(WebCore::DOMSelection::focusOffset):
(WebCore::DOMSelection::baseNode):
(WebCore::DOMSelection::baseOffset):
(WebCore::DOMSelection::extentNode):
(WebCore::DOMSelection::extentOffset):
* page/DOMSelection.h:
2009-03-12 Dmitry Titov <dimich@chromium.org>
Reviewed by Dimitri Glazkov.
......@@ -56,76 +56,89 @@ void DOMSelection::disconnectFrame()
m_frame = 0;
}
Node* DOMSelection::anchorNode() const
const VisibleSelection& DOMSelection::visibleSelection() const
{
if (!m_frame)
return 0;
ASSERT(m_frame);
return m_frame->selection()->selection();
}
const VisibleSelection& selection = m_frame->selection()->selection();
static Position anchorPosition(const VisibleSelection& selection)
{
Position anchor = selection.isBaseFirst() ? selection.start() : selection.end();
anchor = rangeCompliantEquivalent(anchor);
return anchor.node();
return rangeCompliantEquivalent(anchor);
}
Node* DOMSelection::baseNode() const
static Position focusPosition(const VisibleSelection& selection)
{
Position focus = selection.isBaseFirst() ? selection.end() : selection.start();
return rangeCompliantEquivalent(focus);
}
static Position basePosition(const VisibleSelection& selection)
{
return rangeCompliantEquivalent(selection.base());
}
static Position extentPosition(const VisibleSelection& selection)
{
return rangeCompliantEquivalent(selection.extent());
}
Node* DOMSelection::anchorNode() const
{
if (!m_frame)
return 0;
return rangeCompliantEquivalent(m_frame->selection()->selection().base()).node();
return anchorPosition(visibleSelection()).node();
}
int DOMSelection::anchorOffset() const
{
if (!m_frame)
return 0;
const VisibleSelection& selection = m_frame->selection()->selection();
Position anchor = selection.isBaseFirst() ? selection.start() : selection.end();
anchor = rangeCompliantEquivalent(anchor);
return anchor.m_offset;
return anchorPosition(visibleSelection()).m_offset;
}
int DOMSelection::baseOffset() const
Node* DOMSelection::focusNode() const
{
if (!m_frame)
return 0;
return rangeCompliantEquivalent(m_frame->selection()->selection().base()).m_offset;
return focusPosition(visibleSelection()).node();
}
Node* DOMSelection::focusNode() const
int DOMSelection::focusOffset() const
{
if (!m_frame)
return 0;
const VisibleSelection& selection = m_frame->selection()->selection();
Position focus = selection.isBaseFirst() ? selection.end() : selection.start();
focus = rangeCompliantEquivalent(focus);
return focus.node();
return focusPosition(visibleSelection()).m_offset;
}
Node* DOMSelection::extentNode() const
Node* DOMSelection::baseNode() const
{
if (!m_frame)
return 0;
return rangeCompliantEquivalent(m_frame->selection()->selection().extent()).node();
return basePosition(visibleSelection()).node();
}
int DOMSelection::focusOffset() const
int DOMSelection::baseOffset() const
{
if (!m_frame)
return 0;
return basePosition(visibleSelection()).m_offset;
}
const VisibleSelection& selection = m_frame->selection()->selection();
Position focus = selection.isBaseFirst() ? selection.end() : selection.start();
focus = rangeCompliantEquivalent(focus);
return focus.m_offset;
Node* DOMSelection::extentNode() const
{
if (!m_frame)
return 0;
return extentPosition(visibleSelection()).node();
}
int DOMSelection::extentOffset() const
{
if (!m_frame)
return 0;
return rangeCompliantEquivalent(m_frame->selection()->selection().extent()).m_offset;
return extentPosition(visibleSelection()).m_offset;
}
bool DOMSelection::isCollapsed() const
......
......@@ -40,6 +40,7 @@ namespace WebCore {
class Range;
class Node;
class String;
class VisibleSelection;
typedef int ExceptionCode;
......@@ -91,7 +92,10 @@ namespace WebCore {
private:
DOMSelection(Frame*);
// Convenience method for accessors, does not NULL check m_frame.
const VisibleSelection& visibleSelection() const;
Frame* m_frame;
};
......
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