Bug 563878. Part 4. Add AppUnitsPerDevPixel convenience function to viewmanager. r=mats
authorTimothy Nikkel <tnikkel@gmail.com>
Sat, 05 Jun 2010 15:29:49 -0500
changeset 43141 fdb1e4bc853db53142b244ddf6e20e9bbab8e636
parent 43140 83d0cd161be2d3cad1e97a1deebab5f248f4bc7d
child 43142 5f2e4510a213a4b80b1bde4f217dde059994f463
child 43143 c1162c2cc26b11ea2684c7659fc6147c1d9b9b17
push idunknown
push userunknown
push dateunknown
reviewersmats
bugs563878
milestone1.9.3a5pre
first release with
nightly win64
fdb1e4bc853d / 3.7a5pre / 20100605160506 / files
nightly linux32
nightly linux64
nightly mac
nightly win32
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly win64
Bug 563878. Part 4. Add AppUnitsPerDevPixel convenience function to viewmanager. r=mats
view/src/nsViewManager.cpp
view/src/nsViewManager.h
--- a/view/src/nsViewManager.cpp
+++ b/view/src/nsViewManager.cpp
@@ -39,17 +39,16 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #define PL_ARENA_CONST_ALIGN_MASK (sizeof(void*)-1)
 #include "plarena.h"
 
 #include "nsAutoPtr.h"
 #include "nsViewManager.h"
-#include "nsIDeviceContext.h"
 #include "nsGfxCIID.h"
 #include "nsView.h"
 #include "nsISupportsArray.h"
 #include "nsCOMPtr.h"
 #include "nsIServiceManager.h"
 #include "nsGUIEvent.h"
 #include "nsIPrefBranch.h"
 #include "nsIPrefService.h"
@@ -647,17 +646,17 @@ nsViewManager::UpdateWidgetArea(nsView *
           UpdateWidgetArea(view, childWidget, damage, aIgnoreWidgetView);
 
           nsIntRect bounds;
           childWidget->GetBounds(bounds);
           nsTArray<nsIntRect> clipRects;
           childWidget->GetWindowClipRegion(&clipRects);
           for (PRUint32 i = 0; i < clipRects.Length(); ++i) {
             nsRect rr = (clipRects[i] + bounds.TopLeft()).
-              ToAppUnits(mContext->AppUnitsPerDevPixel());
+              ToAppUnits(AppUnitsPerDevPixel());
             children.Or(children, rr - aWidgetView->ViewToWidgetOffset()); 
             children.SimplifyInward(20);
           }
         }
       }
     }
   }
 
@@ -747,17 +746,17 @@ NS_IMETHODIMP nsViewManager::DispatchEve
             width = ((nsSizeEvent*)aEvent)->mWinWidth;
             height = ((nsSizeEvent*)aEvent)->mWinHeight;
 
             // The root view may not be set if this is the resize associated with
             // window creation
 
             if (aView == mRootView)
               {
-                PRInt32 p2a = mContext->AppUnitsPerDevPixel();
+                PRInt32 p2a = AppUnitsPerDevPixel();
                 SetWindowDimensions(NSIntPixelsToAppUnits(width, p2a),
                                     NSIntPixelsToAppUnits(height, p2a));
                 *aStatus = nsEventStatus_eConsumeNoDefault;
               }
           }
 
         break;
       }
@@ -954,17 +953,17 @@ NS_IMETHODIMP nsViewManager::DispatchEve
 
         if (NS_IsEventUsingCoordinates(aEvent)) {
           // will dispatch using coordinates. Pretty bogus but it's consistent
           // with what presshell does.
           view = GetDisplayRootFor(baseView);
         }
 
         if (nsnull != view) {
-          PRInt32 p2a = mContext->AppUnitsPerDevPixel();
+          PRInt32 p2a = AppUnitsPerDevPixel();
 
           if ((aEvent->message == NS_MOUSE_MOVE &&
                static_cast<nsMouseEvent*>(aEvent)->reason ==
                  nsMouseEvent::eReal) ||
               aEvent->message == NS_MOUSE_ENTER ||
               aEvent->message == NS_MOUSE_BUTTON_DOWN ||
               aEvent->message == NS_MOUSE_BUTTON_UP) {
             // aEvent->point is relative to the widget, i.e. the view top-left,
@@ -1535,17 +1534,17 @@ nsIntRect nsViewManager::ViewToWidget(ns
   rect.IntersectRect(rect, bounds);
   // account for the view's origin not lining up with the widget's
   rect.x -= bounds.x;
   rect.y -= bounds.y;
 
   rect += aView->ViewToWidgetOffset();
 
   // finally, convert to device coordinates.
-  return rect.ToOutsidePixels(mContext->AppUnitsPerDevPixel());
+  return rect.ToOutsidePixels(AppUnitsPerDevPixel());
 }
 
 NS_IMETHODIMP
 nsViewManager::IsPainting(PRBool& aIsPainting)
 {
   aIsPainting = IsPainting();
   return NS_OK;
 }
@@ -1749,17 +1748,17 @@ nsViewManager::ProcessSynthMouseMoveEven
   nsCOMPtr<nsIViewManager> kungFuDeathGrip(this);
   
 #ifdef DEBUG_MOUSE_LOCATION
   printf("[vm=%p]synthesizing mouse move to (%d,%d)\n",
          this, mMouseLocation.x, mMouseLocation.y);
 #endif
                                                        
   nsPoint pt;
-  PRInt32 p2a = mContext->AppUnitsPerDevPixel();
+  PRInt32 p2a = AppUnitsPerDevPixel();
   pt.x = NSIntPixelsToAppUnits(mMouseLocation.x, p2a);
   pt.y = NSIntPixelsToAppUnits(mMouseLocation.y, p2a);
   // This could be a bit slow (traverses entire view hierarchy)
   // but it's OK to do it once per synthetic mouse event
   nsView* view = FindFloatingViewContaining(mRootView, pt);
   nsIntPoint offset(0, 0);
   nsViewManager *pointVM;
   if (!view) {
--- a/view/src/nsViewManager.h
+++ b/view/src/nsViewManager.h
@@ -43,16 +43,17 @@
 #include "nsITimer.h"
 #include "prtime.h"
 #include "prinrval.h"
 #include "nsVoidArray.h"
 #include "nsThreadUtils.h"
 #include "nsIRegion.h"
 #include "nsView.h"
 #include "nsIViewObserver.h"
+#include "nsIDeviceContext.h"
 
 
 /**
    Invalidation model:
 
    1) Callers call into the view manager and ask it to update a view.
    
    2) The view manager finds the "right" widget for the view, henceforth called
@@ -271,16 +272,22 @@ public: // NOT in nsIViewManager, so pri
 
   PRBool IsRefreshEnabled() { return RootViewManager()->mUpdateBatchCnt == 0; }
 
   nsIViewObserver* GetViewObserver() { return mObserver; }
 
   // Call this when you need to let the viewmanager know that it now has
   // pending updates.
   void PostPendingUpdate() { RootViewManager()->mHasPendingUpdates = PR_TRUE; }
+
+  PRInt32 AppUnitsPerDevPixel() const
+  {
+    return mContext->AppUnitsPerDevPixel();
+  }
+
 private:
   nsCOMPtr<nsIDeviceContext> mContext;
   nsIViewObserver   *mObserver;
   nsIntPoint        mMouseLocation; // device units, relative to mRootView
 
   // The size for a resize that we delayed until the root view becomes
   // visible again.
   nsSize            mDelayedResize;