Bug 1088552 - Change downPoint and movePoint from canvasframe's coordinate to rootframe's coordinate. r=roc
authorMorris Tseng <mtseng@mozilla.com>
Tue, 28 Oct 2014 18:25:00 -0400
changeset 212889 a9bbad3912019c39671790a189022cf293d1a34c
parent 212888 2c5d603aa12f6f7e294ee3cac6fc6f6e081f5343
child 212890 80356dd0012db4f727aa0b578bccada552cc96ee
push id51080
push userryanvm@gmail.com
push dateWed, 29 Oct 2014 15:45:02 +0000
treeherdermozilla-inbound@f8b29993a76c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1088552
milestone36.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 1088552 - Change downPoint and movePoint from canvasframe's coordinate to rootframe's coordinate. r=roc
layout/base/SelectionCarets.cpp
layout/base/SelectionCarets.h
--- a/layout/base/SelectionCarets.cpp
+++ b/layout/base/SelectionCarets.cpp
@@ -154,43 +154,43 @@ SelectionCarets::HandleEvent(WidgetEvent
     } else {
       movePoint = touchEvent->touches[0]->mRefPoint;
       nowTouchId = touchEvent->touches[0]->Identifier();
     }
   } else if (mouseEvent) {
     movePoint = LayoutDeviceIntPoint::ToUntyped(mouseEvent->AsGUIEvent()->refPoint);
   }
 
-  // Get event coordinate relative to canvas frame
-  nsIFrame* canvasFrame = mPresShell->GetCanvasFrame();
-  if (!canvasFrame) {
+  // Get event coordinate relative to root frame
+  nsIFrame* rootFrame = mPresShell->GetRootFrame();
+  if (!rootFrame) {
     return nsEventStatus_eIgnore;
   }
-  nsPoint ptInCanvas =
-    nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, movePoint, canvasFrame);
+  nsPoint ptInRoot =
+    nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, movePoint, rootFrame);
 
   if (aEvent->message == NS_TOUCH_START ||
       (aEvent->message == NS_MOUSE_BUTTON_DOWN &&
        mouseEvent->button == WidgetMouseEvent::eLeftButton)) {
     // If having a active touch, ignore other touch down event
     if (aEvent->message == NS_TOUCH_START && mActiveTouchId >= 0) {
       return nsEventStatus_eConsumeNoDefault;
     }
 
     mActiveTouchId = nowTouchId;
-    mDownPoint = ptInCanvas;
-    if (IsOnStartFrame(ptInCanvas)) {
+    mDownPoint = ptInRoot;
+    if (IsOnStartFrame(ptInRoot)) {
       mDragMode = START_FRAME;
-      mCaretCenterToDownPointOffsetY = GetCaretYCenterPosition() - ptInCanvas.y;
+      mCaretCenterToDownPointOffsetY = GetCaretYCenterPosition() - ptInRoot.y;
       SetSelectionDirection(false);
       SetSelectionDragState(true);
       return nsEventStatus_eConsumeNoDefault;
-    } else if (IsOnEndFrame(ptInCanvas)) {
+    } else if (IsOnEndFrame(ptInRoot)) {
       mDragMode = END_FRAME;
-      mCaretCenterToDownPointOffsetY = GetCaretYCenterPosition() - ptInCanvas.y;
+      mCaretCenterToDownPointOffsetY = GetCaretYCenterPosition() - ptInRoot.y;
       SetSelectionDirection(true);
       SetSelectionDragState(true);
       return nsEventStatus_eConsumeNoDefault;
     } else {
       mDragMode = NONE;
       mActiveTouchId = -1;
       SetVisibility(false);
       LaunchLongTapDetector();
@@ -207,24 +207,24 @@ SelectionCarets::HandleEvent(WidgetEvent
         mActiveTouchId = -1;
       }
       return nsEventStatus_eConsumeNoDefault;
     }
   } else if (aEvent->message == NS_TOUCH_MOVE ||
              aEvent->message == NS_MOUSE_MOVE) {
     if (mDragMode == START_FRAME || mDragMode == END_FRAME) {
       if (mActiveTouchId == nowTouchId) {
-        ptInCanvas.y += mCaretCenterToDownPointOffsetY;
-        return DragSelection(ptInCanvas);
+        ptInRoot.y += mCaretCenterToDownPointOffsetY;
+        return DragSelection(ptInRoot);
       }
 
       return nsEventStatus_eConsumeNoDefault;
     }
 
-    nsPoint delta = mDownPoint - ptInCanvas;
+    nsPoint delta = mDownPoint - ptInRoot;
     if (NS_hypot(delta.x, delta.y) >
           nsPresContext::AppUnitsPerCSSPixel() * kMoveStartTolerancePx) {
       CancelLongTapDetector();
     }
   } else if (aEvent->message == NS_MOUSE_MOZLONGTAP) {
     if (!mVisible) {
       SELECTIONCARETS_LOG("SelectWord from APZ");
       SelectWord();
@@ -568,18 +568,17 @@ SelectionCarets::UpdateSelectionCarets()
 nsresult
 SelectionCarets::SelectWord()
 {
   if (!mPresShell) {
     return NS_OK;
   }
 
   nsIFrame* rootFrame = mPresShell->GetRootFrame();
-  nsIFrame* canvasFrame = mPresShell->GetCanvasFrame();
-  if (!rootFrame || !canvasFrame) {
+  if (!rootFrame) {
     return NS_OK;
   }
 
   // Find content offsets for mouse down point
   nsIFrame *ptFrame = nsLayoutUtils::GetFrameForPoint(rootFrame, mDownPoint,
     nsLayoutUtils::IGNORE_PAINT_SUPPRESSION | nsLayoutUtils::IGNORE_CROSS_DOC);
   if (!ptFrame) {
     return NS_OK;
@@ -587,17 +586,17 @@ SelectionCarets::SelectWord()
 
   // If frame isn't editable and we don't support non-editable fields, bail
   // out.
   if (!kSupportNonEditableFields && !ptFrame->GetContent()->IsEditable()) {
     return NS_OK;
   }
 
   nsPoint ptInFrame = mDownPoint;
-  nsLayoutUtils::TransformPoint(canvasFrame, ptFrame, ptInFrame);
+  nsLayoutUtils::TransformPoint(rootFrame, ptFrame, ptInFrame);
 
   // If target frame is editable, we should move focus to targe frame. If
   // target frame isn't editable and our focus content is editable, we should
   // clear focus.
   nsFocusManager* fm = nsFocusManager::GetFocusManager();
   nsIContent* editingHost = ptFrame->GetContent()->GetEditingHost();
   if (editingHost) {
     nsCOMPtr<nsIDOMElement> elt = do_QueryInterface(editingHost->GetParent());
@@ -703,35 +702,34 @@ CompareRangeWithContentOffset(nsRange* a
 
   return true;
 }
 
 nsEventStatus
 SelectionCarets::DragSelection(const nsPoint &movePoint)
 {
   nsIFrame* rootFrame = mPresShell->GetRootFrame();
-  nsIFrame* canvasFrame = mPresShell->GetCanvasFrame();
-  if (!rootFrame || !canvasFrame) {
+  if (!rootFrame) {
     return nsEventStatus_eConsumeNoDefault;
   }
 
   // Find out which content we point to
   nsIFrame *ptFrame = nsLayoutUtils::GetFrameForPoint(rootFrame, movePoint,
     nsLayoutUtils::IGNORE_PAINT_SUPPRESSION | nsLayoutUtils::IGNORE_CROSS_DOC);
   if (!ptFrame) {
     return nsEventStatus_eConsumeNoDefault;
   }
 
   nsRefPtr<nsFrameSelection> fs = GetFrameSelection();
 
   nsresult result;
   nsIFrame *newFrame = nullptr;
   nsPoint newPoint;
   nsPoint ptInFrame = movePoint;
-  nsLayoutUtils::TransformPoint(canvasFrame, ptFrame, ptInFrame);
+  nsLayoutUtils::TransformPoint(rootFrame, ptFrame, ptInFrame);
   result = fs->ConstrainFrameAndPointToAnchorSubtree(ptFrame, ptInFrame, &newFrame, newPoint);
   if (NS_FAILED(result) || !newFrame) {
     return nsEventStatus_eConsumeNoDefault;
   }
 
   bool selectable;
   newFrame->IsSelectable(&selectable, nullptr);
   if (!selectable) {
@@ -774,28 +772,28 @@ SelectionCarets::DragSelection(const nsP
   if (!weakScrollable.IsAlive()) {
     return nsEventStatus_eConsumeNoDefault;
   }
 
   // Scroll scrolled frame.
   nsIScrollableFrame *saf = do_QueryFrame(scrollable);
   nsIFrame *capturingFrame = saf->GetScrolledFrame();
   nsPoint ptInScrolled = movePoint;
-  nsLayoutUtils::TransformPoint(canvasFrame, capturingFrame, ptInScrolled);
+  nsLayoutUtils::TransformPoint(rootFrame, capturingFrame, ptInScrolled);
   fs->StartAutoScrollTimer(capturingFrame, ptInScrolled, TouchCaret::sAutoScrollTimerDelay);
   UpdateSelectionCarets();
   return nsEventStatus_eConsumeNoDefault;
 }
 
 nscoord
 SelectionCarets::GetCaretYCenterPosition()
 {
-  nsIFrame* canvasFrame = mPresShell->GetCanvasFrame();
+  nsIFrame* rootFrame = mPresShell->GetRootFrame();
 
-  if (!canvasFrame) {
+  if (!rootFrame) {
     return 0;
   }
 
   nsRefPtr<dom::Selection> selection = GetSelection();
   int32_t rangeCount = selection->GetRangeCount();
   if (rangeCount <= 0) {
     return 0;
   }
@@ -820,17 +818,17 @@ SelectionCarets::GetCaretYCenterPosition
     mDragMode == START_FRAME ? CARET_ASSOCIATE_AFTER : CARET_ASSOCIATE_BEFORE;
   nsIFrame* theFrame =
     fs->GetFrameForNodeOffset(node, nodeOffset, hint, &offset);
 
   if (!theFrame) {
     return 0;
   }
   nsRect frameRect = theFrame->GetRectRelativeToSelf();
-  nsLayoutUtils::TransformRect(theFrame, canvasFrame, frameRect);
+  nsLayoutUtils::TransformRect(theFrame, rootFrame, frameRect);
   return frameRect.Center().y;
 }
 
 void
 SelectionCarets::SetSelectionDragState(bool aState)
 {
   nsRefPtr<nsFrameSelection> fs = GetFrameSelection();
   fs->SetDragState(aState);
@@ -892,26 +890,26 @@ SelectionCarets::IsOnEndFrame(const nsPo
     nsLayoutUtils::ContainsPoint(GetEndFrameRect(), aPosition,
                                  SelectionCaretsInflateSize());
 }
 
 nsRect
 SelectionCarets::GetStartFrameRect()
 {
   dom::Element* element = mPresShell->GetSelectionCaretsStartElement();
-  nsIFrame* canvasFrame = mPresShell->GetCanvasFrame();
-  return nsLayoutUtils::GetRectRelativeToFrame(element, canvasFrame);
+  nsIFrame* rootFrame = mPresShell->GetRootFrame();
+  return nsLayoutUtils::GetRectRelativeToFrame(element, rootFrame);
 }
 
 nsRect
 SelectionCarets::GetEndFrameRect()
 {
   dom::Element* element = mPresShell->GetSelectionCaretsEndElement();
-  nsIFrame* canvasFrame = mPresShell->GetCanvasFrame();
-  return nsLayoutUtils::GetRectRelativeToFrame(element, canvasFrame);
+  nsIFrame* rootFrame = mPresShell->GetRootFrame();
+  return nsLayoutUtils::GetRectRelativeToFrame(element, rootFrame);
 }
 
 nsIContent*
 SelectionCarets::GetFocusedContent()
 {
   nsFocusManager* fm = nsFocusManager::GetFocusManager();
   if (fm) {
     return fm->GetFocusedContent();
--- a/layout/base/SelectionCarets.h
+++ b/layout/base/SelectionCarets.h
@@ -117,17 +117,17 @@ private:
   nsresult SelectWord();
 
   /**
    * Move selection base on current touch/mouse point
    */
   nsEventStatus DragSelection(const nsPoint &movePoint);
 
   /**
-   * Get the vertical center position of selection caret relative to canvas
+   * Get the vertical center position of selection caret relative to root
    * frame.
    */
   nscoord GetCaretYCenterPosition();
 
   /**
    * Simulate drag state when we change the selection range.
    * Hence, the selection change event will fire normally.
    */
@@ -146,31 +146,31 @@ private:
    * In app units.
    */
   void SetEndFramePos(const nsPoint& aPosition);
 
   /**
    * Check if aPosition is on the start or end frame of the
    * selection carets.
    *
-   * @param aPosition should be relative to document's canvas frame
+   * @param aPosition should be relative to document's root frame
    * in app units
    */
   bool IsOnStartFrame(const nsPoint& aPosition);
   bool IsOnEndFrame(const nsPoint& aPosition);
 
   /**
    * Get rect of selection caret's start frame relative
-   * to document's canvas frame, in app units.
+   * to document's root frame, in app units.
    */
   nsRect GetStartFrameRect();
 
   /**
    * Get rect of selection caret's end frame relative
-   * to document's canvas frame, in app units.
+   * to document's root frame, in app units.
    */
   nsRect GetEndFrameRect();
 
   /**
    * Set visibility for start part of selection caret, this function
    * only affects css property of start frame. So it doesn't change
    * mVisible member. When caret overflows element's box we'll hide
    * it by calling this function.