diff --git a/dom/base/Selection.cpp b/dom/base/Selection.cpp index f0f6367c6c8e..744a15f39b39 100644 --- a/dom/base/Selection.cpp +++ b/dom/base/Selection.cpp @@ -2865,6 +2865,8 @@ nsIFrame* Selection::GetSelectionEndPointGeometry(SelectionRegion aRegion, content, nodeOffset, mFrameSelection->GetHint(), &frameOffset); if (!frame) return nullptr; + nsFrameSelection::AdjustFrameForLineStart(frame, frameOffset); + // Figure out what node type we have, then get the // appropriate rect for it's nodeOffset. bool isText = node->IsText(); diff --git a/layout/base/nsCaret.cpp b/layout/base/nsCaret.cpp index 989ae08b918c..60c734266773 100644 --- a/layout/base/nsCaret.cpp +++ b/layout/base/nsCaret.cpp @@ -81,32 +81,6 @@ static nsLineBox* FindContainingLine(nsIFrame* aFrame) { return nullptr; } -static bool AdjustCaretFrameForLineStart(nsIFrame*& aFrame, - int32_t& aFrameOffset, - nsFrameSelection& aFrameSelection) { - if (!aFrame->HasSignificantTerminalNewline()) { - return false; - } - - int32_t start; - int32_t end; - aFrame->GetOffsets(start, end); - if (aFrameOffset != end) { - return false; - } - - nsIFrame* nextSibling = aFrame->GetNextSibling(); - if (!nextSibling) { - return false; - } - - aFrame = nextSibling; - aFrame->GetOffsets(start, end); - aFrameOffset = start; - aFrameSelection.SetHint(CARET_ASSOCIATE_AFTER); - return true; -} - static void AdjustCaretFrameForLineEnd(nsIFrame** aFrame, int32_t* aOffset) { nsLineBox* line = FindContainingLine(*aFrame); if (!line) { @@ -664,16 +638,15 @@ nsIFrame* nsCaret::GetCaretFrameForNodeOffset( *aReturnUnadjustedFrame = theFrame; } - // if theFrame is a text frame with a significant terminal character, use the - // next frame instead - if (!AdjustCaretFrameForLineStart(theFrame, theFrameOffset, - *aFrameSelection)) { + if (nsFrameSelection::AdjustFrameForLineStart(theFrame, theFrameOffset)) { + aFrameSelection->SetHint(CARET_ASSOCIATE_AFTER); + } else { // if theFrame is after a text frame that's logically at the end of the line // (e.g. if theFrame is a
frame), then put the caret at the end of // that text frame instead. This way, the caret will be positioned as if // trailing whitespace was not trimmed. AdjustCaretFrameForLineEnd(&theFrame, &theFrameOffset); - }; + } // Mamdouh : modification of the caret to work at rtl and ltr with Bidi // diff --git a/layout/base/tests/mochitest.ini b/layout/base/tests/mochitest.ini index 25d81ffce311..b3cebc30832f 100644 --- a/layout/base/tests/mochitest.ini +++ b/layout/base/tests/mochitest.ini @@ -143,6 +143,7 @@ support-files = bug1226904.html support-files = bug1448730.html [test_bug1515822.html] [test_bug1550869_video.html] +[test_bug1714640.html] [test_dynamic_toolbar_max_height.html] support-files = file_dynamic_toolbar_max_height.html [test_emulateMedium.html] diff --git a/layout/base/tests/test_bug1714640.html b/layout/base/tests/test_bug1714640.html new file mode 100644 index 000000000000..3e2de0df127a --- /dev/null +++ b/layout/base/tests/test_bug1714640.html @@ -0,0 +1,36 @@ + + +Bug NNN + + + +
ABC
+
+
+
+
+
+
+ diff --git a/layout/generic/nsFrameSelection.cpp b/layout/generic/nsFrameSelection.cpp index d02f6f3a0e22..8fa10577af54 100644 --- a/layout/generic/nsFrameSelection.cpp +++ b/layout/generic/nsFrameSelection.cpp @@ -1605,6 +1605,30 @@ static bool IsDisplayContents(const nsIContent* aContent) { return aContent->IsElement() && aContent->AsElement()->IsDisplayContents(); } +bool nsFrameSelection::AdjustFrameForLineStart(nsIFrame*& aFrame, + int32_t& aFrameOffset) { + if (!aFrame->HasSignificantTerminalNewline()) { + return false; + } + + int32_t start; + int32_t end; + aFrame->GetOffsets(start, end); + if (aFrameOffset != end) { + return false; + } + + nsIFrame* nextSibling = aFrame->GetNextSibling(); + if (!nextSibling) { + return false; + } + + aFrame = nextSibling; + aFrame->GetOffsets(start, end); + aFrameOffset = start; + return true; +} + // static nsIFrame* nsFrameSelection::GetFrameForNodeOffset(nsIContent* aNode, int32_t aOffset, diff --git a/layout/generic/nsFrameSelection.h b/layout/generic/nsFrameSelection.h index 451207c7c010..dc1f13b928c4 100644 --- a/layout/generic/nsFrameSelection.h +++ b/layout/generic/nsFrameSelection.h @@ -428,6 +428,8 @@ class nsFrameSelection final { bool IsValidSelectionPoint(nsINode* aNode) const; + static bool AdjustFrameForLineStart(nsIFrame*& aFrame, int32_t& aFrameOffset); + /** * Given a node and its child offset, return the nsIFrame and the offset into * that frame.