From 1389045233b944606421719b70fbb8529127933d Mon Sep 17 00:00:00 2001 From: "aaronleventhal%moonset.net" Date: Mon, 4 Apr 2005 18:11:14 +0000 Subject: [PATCH] Bug 265203. When caret is at end of one link, focus displays to next link. r=ginn.chen, sr=bryner git-svn-id: svn://10.0.0.236/trunk@171577 18797224-902f-48f8-a5cc-f745e15eee43 --- .../events/src/nsEventStateManager.cpp | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index ae7dcd9adc4..be9ac3daaa8 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -4489,7 +4489,6 @@ nsEventStateManager::GetDocSelectionLocation(nsIContent **aStartContent, domNode->GetNodeType(&nodeType); if (nodeType == nsIDOMNode::TEXT_NODE) { - nsCOMPtr origStartContent(startContent); nsAutoString nodeValue; domNode->GetNodeValue(nodeValue); @@ -4509,24 +4508,43 @@ nsEventStateManager::GetDocSelectionLocation(nsIContent **aStartContent, mPresContext, startFrame); NS_ENSURE_SUCCESS(rv, rv); + nsIFrame *newCaretFrame = nsnull; + nsCOMPtr newCaretContent = startContent; + PRBool endOfSelectionInStartNode(startContent == endContent); do { - // Get the next logical frame, and set the start of - // focusable elements. Search for focusable elements from there. - // Continue getting next frame until the primary node for the frame + // Continue getting the next frame until the primary content for the frame // we are on changes - we don't want to be stuck in the same place frameTraversal->Next(); nsISupports* currentItem; frameTraversal->CurrentItem(¤tItem); - startFrame = NS_STATIC_CAST(nsIFrame*, currentItem); - if (startFrame) { - PRBool endEqualsStart(startContent == endContent); - startContent = startFrame->GetContent(); - if (endEqualsStart) - endContent = startContent; + if (nsnull == (newCaretFrame = NS_STATIC_CAST(nsIFrame*, currentItem))) { + break; + } + newCaretContent = newCaretFrame->GetContent(); + } while (!newCaretContent || newCaretContent == startContent); + + if (newCaretFrame && newCaretContent) { + // If the caret is exactly at the same position of the new frame, + // then we can use the newCaretFrame and newCaretContent for our position + nsCOMPtr caret; + shell->GetCaret(getter_AddRefs(caret)); + nsRect caretRect; + nsIView *caretView; + caret->GetCaretCoordinates(nsICaret::eClosestViewCoordinates, + domSelection, &caretRect, + &isCollapsed, &caretView); + nsPoint framePt; + nsIView *frameClosestView = newCaretFrame->GetClosestView(&framePt); + if (caretView == frameClosestView && caretRect.y == framePt.y && + caretRect.x == framePt.x) { + // The caret is at the start of the new element. + startFrame = newCaretFrame; + startContent = newCaretContent; + if (endOfSelectionInStartNode) { + endContent = newCaretContent; // Ensure end of selection is not before start + } } - else break; } - while (startContent == origStartContent); } } }