Bug 1026431 - Determine tilt mode by next character of startFrame and previous character of endFrame. r=roc
authorMorris Tseng <mtseng@mozilla.com>
Tue, 15 Jul 2014 22:44:00 +0200
changeset 216780 c7494103b4c7c01548243a743168b6f3e1c1d553
parent 216779 ea66bf9982ffd35f43b5517ce7fe9651577aa943
child 216781 3a0e9a83d8c590686ec865b248c903fd009a2f2d
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1026431
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1026431 - Determine tilt mode by next character of startFrame and previous character of endFrame. r=roc
layout/base/SelectionCarets.cpp
--- a/layout/base/SelectionCarets.cpp
+++ b/layout/base/SelectionCarets.cpp
@@ -453,31 +453,48 @@ SelectionCarets::UpdateSelectionCarets()
   nsLayoutUtils::TransformRect(rootFrame, canvasFrame, collector.mLastRect);
 
   SetStartFramePos(collector.mFirstRect.BottomLeft());
   SetEndFramePos(collector.mLastRect.BottomRight());
   SetVisibility(true);
 
   // If range select only one character, append tilt class name to it.
   bool isTilt = false;
-  if (startFrame) {
-    nsPeekOffsetStruct pos(eSelectCluster,
-                           eDirNext,
-                           startOffset,
-                           0,
-                           false,
-                           true,  //limit on scrolled views
-                           false,
-                           false);
-    startFrame->PeekOffset(&pos);
-    nsCOMPtr<nsIContent> endContent = do_QueryInterface(range->GetEndParent());
-    if ((pos.mResultContent &&
-         nsLayoutUtils::CompareTreePosition(pos.mResultContent, endContent) > 0) ||
-        (pos.mResultContent == endContent &&
-         pos.mContentOffset >= range->EndOffset())) {
+  if (startFrame && endFrame) {
+    // In this case <textarea>abc</textarea> and we select 'c' character,
+    // EndContent would be HTMLDivElement and mResultContent which get by
+    // calling startFrame->PeekOffset() with selecting next cluster would be
+    // TextNode. Although the position is same, nsContentUtils::ComparePoints
+    // still shows HTMLDivElement is after TextNode. So that we cannot use
+    // EndContent or StartContent to compare with result of PeekOffset().
+    // So we compare between next charater of startFrame and previous character
+    // of endFrame.
+    nsPeekOffsetStruct posNext(eSelectCluster,
+                               eDirNext,
+                               startOffset,
+                               0,
+                               false,
+                               true,  //limit on scrolled views
+                               false,
+                               false);
+
+    nsPeekOffsetStruct posPrev(eSelectCluster,
+                               eDirPrevious,
+                               endOffset,
+                               0,
+                               false,
+                               true,  //limit on scrolled views
+                               false,
+                               false);
+    startFrame->PeekOffset(&posNext);
+    endFrame->PeekOffset(&posPrev);
+
+    if (posNext.mResultContent && posPrev.mResultContent &&
+        nsContentUtils::ComparePoints(posNext.mResultContent, posNext.mContentOffset,
+                                      posPrev.mResultContent, posPrev.mContentOffset) > 0) {
       isTilt = true;
     }
   }
 
   SetCaretDirection(mPresShell->GetSelectionCaretsStartElement(), startFrameIsRTL);
   SetCaretDirection(mPresShell->GetSelectionCaretsEndElement(), !endFrameIsRTL);
   SetTilted(isTilt);
 }