Bug 145320, support hover in xul trees, r+sr=neil
authorenndeakin@sympatico.ca
Thu, 23 Aug 2007 08:57:54 -0700
changeset 5201 e1ea4f08cbb611f2376b11213ff8a8d3ebc235cd
parent 5200 6db45429c27c385f5e6341c1f6cd2d41554146bc
child 5202 675a18267991f45adeff60b647376a0045686ca7
push id1
push userbsmedberg@mozilla.com
push dateThu, 20 Mar 2008 16:49:24 +0000
treeherdermozilla-central@61007906a1f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs145320
milestone1.9a8pre
Bug 145320, support hover in xul trees, r+sr=neil
content/base/src/nsGkAtomList.h
layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
layout/xul/base/src/tree/src/nsTreeBodyFrame.h
--- a/content/base/src/nsGkAtomList.h
+++ b/content/base/src/nsGkAtomList.h
@@ -379,16 +379,17 @@ GK_ATOM(hasSameNode, "has-same-node")
 GK_ATOM(hbox, "hbox")
 GK_ATOM(head, "head")
 GK_ATOM(headers, "headers")
 GK_ATOM(height, "height")
 GK_ATOM(hidden, "hidden")
 GK_ATOM(hidechrome, "hidechrome")
 GK_ATOM(highest, "highest")
 GK_ATOM(horizontal, "horizontal")
+GK_ATOM(hover, "hover")
 GK_ATOM(hr, "hr")
 GK_ATOM(href, "href")
 GK_ATOM(hreflang, "hreflang")
 GK_ATOM(hspace, "hspace")
 GK_ATOM(html, "html")
 GK_ATOM(htmlBaseHref, "html-base-href")
 GK_ATOM(htmlBaseTarget, "html-base-target")
 GK_ATOM(httpEquiv, "http-equiv")
--- a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
+++ b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
@@ -155,16 +155,17 @@ nsTreeBodyFrame::nsTreeBodyFrame(nsIPres
  mStringWidth(-1),
  mFocused(PR_FALSE),
  mHasFixedRowCount(PR_FALSE),
  mVerticalOverflow(PR_FALSE),
  mHorizontalOverflow(PR_FALSE),
  mReflowCallbackPosted(PR_FALSE),
  mUpdateBatchNest(0),
  mRowCount(0),
+ mMouseOverRow(-1),
  mSlots(nsnull)
 {
   mColumns = new nsTreeColumns(nsnull);
   NS_NewISupportsArray(getter_AddRefs(mScratchArray));
 }
 
 // Destructor
 nsTreeBodyFrame::~nsTreeBodyFrame()
@@ -1893,19 +1894,22 @@ nsTreeBodyFrame::PrefillPropertyArray(PR
   if (sorted)
     mScratchArray->AppendElement(nsGkAtoms::sorted);
 
   // drag session
   if (mSlots && mSlots->mDragSession)
     mScratchArray->AppendElement(nsGkAtoms::dragSession);
 
   if (aRowIndex != -1) {
+    if (aRowIndex == mMouseOverRow)
+      mScratchArray->AppendElement(nsGkAtoms::hover);
+  
     nsCOMPtr<nsITreeSelection> selection;
     mView->GetSelection(getter_AddRefs(selection));
-  
+
     if (selection) {
       // selected
       PRBool isSelected;
       selection->IsSelected(aRowIndex, &isSelected);
       if (isSelected)
         mScratchArray->AppendElement(nsGkAtoms::selected);
 
       // current
@@ -2478,17 +2482,37 @@ nsTreeBodyFrame::GetCursor(const nsPoint
   return nsLeafBoxFrame::GetCursor(aPoint, aCursor);
 }
 
 NS_IMETHODIMP
 nsTreeBodyFrame::HandleEvent(nsPresContext* aPresContext,
                              nsGUIEvent* aEvent,
                              nsEventStatus* aEventStatus)
 {
-  if (aEvent->message == NS_DRAGDROP_ENTER) {
+  if (aEvent->message == NS_MOUSE_ENTER_SYNTH || aEvent->message == NS_MOUSE_MOVE) {
+    nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this);
+    PRInt32 xTwips = pt.x - mInnerBox.x;
+    PRInt32 yTwips = pt.y - mInnerBox.y;
+    PRInt32 newrow = GetRowAt(xTwips, yTwips);
+    if (mMouseOverRow != newrow) {
+      // redraw the old and the new row
+      if (mMouseOverRow != -1)
+        InvalidateRow(mMouseOverRow);
+      mMouseOverRow = newrow;
+      if (mMouseOverRow != -1)
+        InvalidateRow(mMouseOverRow);
+    }
+  }
+  else if (aEvent->message == NS_MOUSE_EXIT_SYNTH) {
+    if (mMouseOverRow != -1) {
+      InvalidateRow(mMouseOverRow);
+      mMouseOverRow = -1;
+    }
+  }
+  else if (aEvent->message == NS_DRAGDROP_ENTER) {
     if (!mSlots)
       mSlots = new Slots();
 
     // Cache several things we'll need throughout the course of our work. These
     // will all get released on a drag exit.
 
     if (mSlots->mTimer) {
       mSlots->mTimer->Cancel();
--- a/layout/xul/base/src/tree/src/nsTreeBodyFrame.h
+++ b/layout/xul/base/src/tree/src/nsTreeBodyFrame.h
@@ -470,16 +470,19 @@ protected: // Data Members
 
   PRPackedBool mReflowCallbackPosted;
 
   PRInt32 mUpdateBatchNest;
 
   // Cached row count.
   PRInt32 mRowCount;
 
+  // The row the mouse is hovering over.
+  PRInt32 mMouseOverRow;
+
   class Slots {
     public:
       Slots()
         : mValueArray(~PRInt32(0)) {
       }
 
       ~Slots() {
         if (mTimer)