From 0381a657755e7e490915da5c8042c093728e0368 Mon Sep 17 00:00:00 2001 From: Mats Palmgren Date: Tue, 9 Feb 2010 17:09:59 +0100 Subject: [PATCH] Use GetExtremeCaretPosition() for all editable nodes, not just the doc root. b=512295 r=roc --- layout/base/nsPresShell.cpp | 55 ++------- layout/base/tests/Makefile.in | 10 ++ layout/base/tests/bug106855-1-ref.html | 28 +++++ layout/base/tests/bug106855-1.html | 26 ++++ layout/base/tests/bug106855-2.html | 27 +++++ layout/base/tests/bug482484-ref.html | 18 +++ layout/base/tests/bug482484.html | 23 ++++ layout/base/tests/bug512295-1-ref.html | 25 ++++ layout/base/tests/bug512295-1.html | 31 +++++ layout/base/tests/bug512295-2-ref.html | 25 ++++ layout/base/tests/bug512295-2.html | 31 +++++ .../base/tests/test_reftests_with_caret.html | 112 ++++++++++++++++++ .../tests/SimpleTest/WindowSnapshot.js | 10 +- 13 files changed, 373 insertions(+), 48 deletions(-) create mode 100644 layout/base/tests/bug106855-1-ref.html create mode 100644 layout/base/tests/bug106855-1.html create mode 100644 layout/base/tests/bug106855-2.html create mode 100644 layout/base/tests/bug482484-ref.html create mode 100644 layout/base/tests/bug482484.html create mode 100644 layout/base/tests/bug512295-1-ref.html create mode 100644 layout/base/tests/bug512295-1.html create mode 100644 layout/base/tests/bug512295-2-ref.html create mode 100644 layout/base/tests/bug512295-2.html create mode 100644 layout/base/tests/test_reftests_with_caret.html diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index b49f0c2d8e1..f7bae660207 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -25,7 +25,7 @@ * HÃ¥kan Waara * Dan Rosen * Daniel Glazman - * Mats Palmgren + * Mats Palmgren * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -3023,52 +3023,19 @@ PresShell::CompleteMove(PRBool aForward, PRBool aExtend) { // Beware! This may flush notifications via synchronous // ScrollSelectionIntoView. - - nsIContent* root = mSelection->GetAncestorLimiter(); - nsIDocument* doc; - if (root && (doc = root->GetOwnerDoc()) && doc->GetRootContent() != root) { - // Make the caret be either at the very beginning (0) or the very end of - // root. Only do this when not moving to the beginning or end of the - // document (root is null or root is the documentElement), that's handled - // below by moving to beginning or end of the scrollable view. - nsIContent* node = root; - PRInt32 offset = 0; - nsFrameSelection::HINT hint = nsFrameSelection::HINTLEFT; - if (aForward) { - nsIContent* next = node; - PRUint32 count; - while ((count = next->GetChildCount()) > 0) { - node = next; - offset = count; - next = next->GetChildAt(count - 1); - } - - if (offset > 0 && node->GetChildAt(offset - 1)->Tag() == nsGkAtoms::br) { - --offset; - hint = nsFrameSelection::HINTRIGHT; // for bug 106855 - } - } - - mSelection->HandleClick(node, offset, offset, aExtend, PR_FALSE, hint); - - // HandleClick resets ancestorLimiter, so set it again. - mSelection->SetAncestorLimiter(root); - - // After ScrollSelectionIntoView(), the pending notifications might be - // flushed and PresShell/PresContext/Frames may be dead. See bug 418470. - return - ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL, - nsISelectionController::SELECTION_FOCUS_REGION, - PR_TRUE); - } - - nsIFrame *frame = FrameConstructor()->GetRootElementFrame(); + nsIContent* limiter = mSelection->GetAncestorLimiter(); + nsIFrame* frame = limiter ? limiter->GetPrimaryFrame() + : FrameConstructor()->GetRootElementFrame(); if (!frame) return NS_ERROR_FAILURE; nsPeekOffsetStruct pos = frame->GetExtremeCaretPosition(!aForward); - - mSelection->HandleClick(pos.mResultContent ,pos.mContentOffset ,pos.mContentOffset/*End*/ ,aExtend, PR_FALSE, aForward); - + mSelection->HandleClick(pos.mResultContent, pos.mContentOffset, + pos.mContentOffset, aExtend, PR_FALSE, aForward); + if (limiter) { + // HandleClick resets ancestorLimiter, so set it again. + mSelection->SetAncestorLimiter(limiter); + } + // After ScrollSelectionIntoView(), the pending notifications might be // flushed and PresShell/PresContext/Frames may be dead. See bug 418470. return ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL, diff --git a/layout/base/tests/Makefile.in b/layout/base/tests/Makefile.in index f3cdc68b7a0..589fa682247 100644 --- a/layout/base/tests/Makefile.in +++ b/layout/base/tests/Makefile.in @@ -91,6 +91,16 @@ _TEST_FILES = \ test_bug435293-interaction.html \ test_bug435293-skew.html \ test_bug495648.xul \ + test_reftests_with_caret.html \ + bug106855-1.html \ + bug106855-2.html \ + bug106855-1-ref.html \ + bug482484.html \ + bug482484-ref.html \ + bug512295-1.html \ + bug512295-1-ref.html \ + bug512295-2.html \ + bug512295-2-ref.html \ test_bug514127.html \ test_bug518777.html \ test_flush_on_paint.html \ diff --git a/layout/base/tests/bug106855-1-ref.html b/layout/base/tests/bug106855-1-ref.html new file mode 100644 index 00000000000..fb5c87c6045 --- /dev/null +++ b/layout/base/tests/bug106855-1-ref.html @@ -0,0 +1,28 @@ + + + + + +x
+
+y + + + + diff --git a/layout/base/tests/bug106855-1.html b/layout/base/tests/bug106855-1.html new file mode 100644 index 00000000000..f71c02b7d3f --- /dev/null +++ b/layout/base/tests/bug106855-1.html @@ -0,0 +1,26 @@ + + + + + +x
+
+y + + + diff --git a/layout/base/tests/bug106855-2.html b/layout/base/tests/bug106855-2.html new file mode 100644 index 00000000000..946e4484b0c --- /dev/null +++ b/layout/base/tests/bug106855-2.html @@ -0,0 +1,27 @@ + + + + + +x
+
+y + + + diff --git a/layout/base/tests/bug482484-ref.html b/layout/base/tests/bug482484-ref.html new file mode 100644 index 00000000000..c72f669a395 --- /dev/null +++ b/layout/base/tests/bug482484-ref.html @@ -0,0 +1,18 @@ + + +

ABC

+ + + + diff --git a/layout/base/tests/bug482484.html b/layout/base/tests/bug482484.html new file mode 100644 index 00000000000..e4294133801 --- /dev/null +++ b/layout/base/tests/bug482484.html @@ -0,0 +1,23 @@ + + + + + +

BC

+ + + diff --git a/layout/base/tests/bug512295-1-ref.html b/layout/base/tests/bug512295-1-ref.html new file mode 100644 index 00000000000..b149fb8510b --- /dev/null +++ b/layout/base/tests/bug512295-1-ref.html @@ -0,0 +1,25 @@ + + + + + +
+

A B CD EFG
+ 1234567890

+
+x + + + + diff --git a/layout/base/tests/bug512295-1.html b/layout/base/tests/bug512295-1.html new file mode 100644 index 00000000000..23fae91bfde --- /dev/null +++ b/layout/base/tests/bug512295-1.html @@ -0,0 +1,31 @@ + + + + + +
+

A B CD EFG
+ 1234567890

+
+x + + + diff --git a/layout/base/tests/bug512295-2-ref.html b/layout/base/tests/bug512295-2-ref.html new file mode 100644 index 00000000000..f450adb4d9c --- /dev/null +++ b/layout/base/tests/bug512295-2-ref.html @@ -0,0 +1,25 @@ + + + + + +x +
+

A B CD EFG
+ 1234567890

+
+ + + + diff --git a/layout/base/tests/bug512295-2.html b/layout/base/tests/bug512295-2.html new file mode 100644 index 00000000000..11ad82ed59c --- /dev/null +++ b/layout/base/tests/bug512295-2.html @@ -0,0 +1,31 @@ + + + + + +x +
+

A B CD EFG
+ 1234567890

+
+ + + diff --git a/layout/base/tests/test_reftests_with_caret.html b/layout/base/tests/test_reftests_with_caret.html new file mode 100644 index 00000000000..f043d18fc4d --- /dev/null +++ b/layout/base/tests/test_reftests_with_caret.html @@ -0,0 +1,112 @@ + + + + Reftests with caret drawing + + + + + + + + + + diff --git a/testing/mochitest/tests/SimpleTest/WindowSnapshot.js b/testing/mochitest/tests/SimpleTest/WindowSnapshot.js index 8bd96a0c48d..e55c59bc25f 100644 --- a/testing/mochitest/tests/SimpleTest/WindowSnapshot.js +++ b/testing/mochitest/tests/SimpleTest/WindowSnapshot.js @@ -10,7 +10,7 @@ try { gWindowUtils = null; } -function snapshotWindow(win) { +function snapshotWindow(win, withCaret) { var el = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas"); el.width = win.innerWidth; el.height = win.innerHeight; @@ -18,9 +18,11 @@ function snapshotWindow(win) { // drawWindow requires privileges netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); - el.getContext("2d").drawWindow(win, win.scrollX, win.scrollY, - win.innerWidth, win.innerHeight, - "rgb(255,255,255)"); + var ctx = el.getContext("2d"); + ctx.drawWindow(win, win.scrollX, win.scrollY, + win.innerWidth, win.innerHeight, + "rgb(255,255,255)", + withCaret ? ctx.DRAWWINDOW_DRAW_CARET : 0); return el; }