Bug 583255, don't involve views in tree offset computation, fixes inspector mouse events, r=roc,a=dbaron
authorNeil Deakin <neil@mozilla.com>
Mon, 09 Aug 2010 12:15:39 -0400
changeset 49215 28ce6a3df8de64ba136289f165ea27bdb5b19a7c
parent 49214 0f703f93e16aab3f55fb4fc5a7541ba58f628825
child 49216 10e893c36559082f66627e2846a47f9da11b34bd
push id14947
push userneil@mozilla.com
push dateMon, 09 Aug 2010 16:16:37 +0000
treeherdermozilla-central@10e893c36559 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, dbaron
bugs583255
milestone2.0b4pre
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 583255, don't involve views in tree offset computation, fixes inspector mouse events, r=roc,a=dbaron
layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
layout/xul/base/src/tree/src/nsTreeBodyFrame.h
toolkit/content/tests/chrome/window_panel.xul
--- a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
+++ b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
@@ -1009,88 +1009,70 @@ nsTreeBodyFrame::InvalidateScrollbars(co
   
     pageStr.Truncate();
     pageStr.AppendInt(nsPresContext::CSSPixelsToAppUnits(16));
     aParts.mHScrollbarContent->
       SetAttr(kNameSpaceID_None, nsGkAtoms::increment, pageStr, PR_TRUE);
   }
 }
 
-// Takes client x/y in pixels, converts them to twips, and massages them to be
-// in our coordinate system.
-void
-nsTreeBodyFrame::AdjustClientCoordsToBoxCoordSpace(PRInt32 aX, PRInt32 aY,
-                                                   nscoord* aResultX,
-                                                   nscoord* aResultY)
+// Takes client x/y in pixels, converts them to appunits, and converts into
+// values relative to this nsTreeBodyFrame frame.
+nsPoint
+nsTreeBodyFrame::AdjustClientCoordsToBoxCoordSpace(PRInt32 aX, PRInt32 aY)
 {
-  nsPresContext* presContext = PresContext();
-
   nsPoint point(nsPresContext::CSSPixelsToAppUnits(aX),
                 nsPresContext::CSSPixelsToAppUnits(aY));
 
-  // Now get our client offset, in twips, and subtract if from the
-  // point to get it in our coordinates
-  nsPoint clientOffset;
-  nsIView* closestView = GetClosestView(&clientOffset);
-  point -= clientOffset;
-
-  nsIView* rootView;
-  presContext->GetPresShell()->GetViewManager()->GetRootView(rootView);
-  NS_ASSERTION(closestView && rootView, "No view?");
-  point -= closestView->GetOffsetTo(rootView);
+  nsPresContext* presContext = PresContext();
+  point -= GetOffsetTo(presContext->GetPresShell()->GetRootFrame());
 
   // Adjust by the inner box coords, so that we're in the inner box's
   // coordinate space.
   point -= mInnerBox.TopLeft();
-
-  *aResultX = point.x;
-  *aResultY = point.y;
+  return point;
 } // AdjustClientCoordsToBoxCoordSpace
 
 nsresult
 nsTreeBodyFrame::GetRowAt(PRInt32 aX, PRInt32 aY, PRInt32* _retval)
 {
   if (!mView)
     return NS_OK;
 
-  nscoord x;
-  nscoord y;
-  AdjustClientCoordsToBoxCoordSpace(aX, aY, &x, &y);
+  nsPoint point = AdjustClientCoordsToBoxCoordSpace(aX, aY);
 
   // Check if the coordinates are above our visible space.
-  if (y < 0) {
+  if (point.y < 0) {
     *_retval = -1;
     return NS_OK;
   }
 
-  *_retval = GetRowAt(x, y);
+  *_retval = GetRowAt(point.x, point.y);
 
   return NS_OK;
 }
 
 nsresult
 nsTreeBodyFrame::GetCellAt(PRInt32 aX, PRInt32 aY, PRInt32* aRow, nsITreeColumn** aCol,
                            nsACString& aChildElt)
 {
   if (!mView)
     return NS_OK;
 
-  nscoord x;
-  nscoord y;
-  AdjustClientCoordsToBoxCoordSpace(aX, aY, &x, &y);
+  nsPoint point = AdjustClientCoordsToBoxCoordSpace(aX, aY);
 
   // Check if the coordinates are above our visible space.
-  if (y < 0) {
+  if (point.y < 0) {
     *aRow = -1;
     return NS_OK;
   }
 
   nsTreeColumn* col;
   nsIAtom* child;
-  GetCellAt(x, y, aRow, &col, &child);
+  GetCellAt(point.x, point.y, aRow, &col, &child);
 
   if (col) {
     NS_ADDREF(*aCol = col);
     if (child == nsCSSAnonBoxes::moztreecell)
       aChildElt.AssignLiteral("cell");
     else if (child == nsCSSAnonBoxes::moztreetwisty)
       aChildElt.AssignLiteral("twisty");
     else if (child == nsCSSAnonBoxes::moztreeimage)
--- a/layout/xul/base/src/tree/src/nsTreeBodyFrame.h
+++ b/layout/xul/base/src/tree/src/nsTreeBodyFrame.h
@@ -378,19 +378,18 @@ protected:
 
   // Our internal scroll method, used by all the public scroll methods.
   nsresult ScrollInternal(const ScrollParts& aParts, PRInt32 aRow);
   nsresult ScrollToRowInternal(const ScrollParts& aParts, PRInt32 aRow);
   nsresult ScrollToColumnInternal(const ScrollParts& aParts, nsITreeColumn* aCol);
   nsresult ScrollHorzInternal(const ScrollParts& aParts, PRInt32 aPosition);
   nsresult EnsureRowIsVisibleInternal(const ScrollParts& aParts, PRInt32 aRow);
   
-  // Convert client pixels into twips in our coordinate space.
-  void AdjustClientCoordsToBoxCoordSpace(PRInt32 aX, PRInt32 aY,
-                                         nscoord* aResultX, nscoord* aResultY);
+  // Convert client pixels into appunits in our coordinate space.
+  nsPoint AdjustClientCoordsToBoxCoordSpace(PRInt32 aX, PRInt32 aY);
 
   // Convert a border style into line style.
   nsLineStyle ConvertBorderStyleToLineStyle(PRUint8 aBorderStyle);
 
   // Cache the box object
   void EnsureBoxObject();
 
   void EnsureView();
--- a/toolkit/content/tests/chrome/window_panel.xul
+++ b/toolkit/content/tests/chrome/window_panel.xul
@@ -8,16 +8,32 @@
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <script type="application/javascript" 
           src="chrome://mochikit/content/MochiKit/packed.js"/>
   <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
   <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
 
+<tree id="tree" seltype="single" width="100" height="100">
+  <treecols>
+    <treecol flex="1"/>
+    <treecol flex="1"/>
+  </treecols>
+  <treechildren id="treechildren">
+    <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem>
+    <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem>
+    <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem>
+    <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem>
+    <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem>
+    <treeitem><treerow><treecell label="One"/><treecell label="Two"/></treerow></treeitem>
+  </treechildren>
+</tree>
+
+
   <!-- test results are displayed in the html:body -->
   <body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/>
 
   <!-- test code goes here -->
   <script type="application/javascript"><![CDATA[
 
 SimpleTest.waitForExplicitFinish();
 
@@ -28,16 +44,18 @@ function ok(condition, message) {
 }
 
 function is(left, right, message) {
   window.opener.wrappedJSObject.SimpleTest.is(left, right, message);
 }
 
 function test_panels()
 {
+  checkTreeCoords();
+
   addEventListener("popupshown", popupShown, false);
   addEventListener("popuphidden", nextTest, false);
   nextTest();
 }
 
 function nextTest()
 {
   if (!tests.length) {
@@ -79,16 +97,30 @@ function createPanel(attrs)
   button.label = "OK";
   button.width = 120;
   button.height = 40;
   button.setAttribute("style", "-moz-appearance: none; border: 0; margin: 0;");
   panel.setAttribute("style", "-moz-appearance: none; border: 0; margin: 0;");
   return document.documentElement.appendChild(panel);
 }
 
+function checkTreeCoords()
+{
+  var tree = $("tree");
+  var treechildren = $("treechildren");
+  tree.currentIndex = 0;
+  tree.treeBoxObject.scrollToRow(0);
+  synthesizeMouse(treechildren, 10, tree.treeBoxObject.rowHeight + 2, { });
+  is(tree.currentIndex, 1, "tree selection");
+
+  tree.treeBoxObject.scrollToRow(2);
+  synthesizeMouse(treechildren, 10, tree.treeBoxObject.rowHeight + 2, { });
+  is(tree.currentIndex, 3, "tree selection after scroll");
+}
+
 var tests = [
   {
     testname: "normal panel",
     attrs: { },
     test: function(panel) {
       panel.openPopupAtScreen(200, 210);
     },
     result: function(testname, panel) {
@@ -139,16 +171,21 @@ var tests = [
         is(event.originalTarget, panel.firstChild, "popup target");
         gotMouseEvent = true;
       }
 
       panel.addEventListener("mousemove", mouseMoved, true);
       synthesizeMouse(panel, 10, 10, { type: "mousemove" });
       ok(gotMouseEvent, "mouse event on panel");      
       panel.removeEventListener("mousemove", mouseMoved, true);
+
+      var tree = $("tree");
+      tree.currentIndex = 0;
+      panel.appendChild(tree);
+      checkTreeCoords();
     }
   }
 ];
 
 window.opener.wrappedJSObject.SimpleTest.waitForFocus(test_panels, window);
 
 ]]>
 </script>