Bug 1160014 part 2 - Move some procedures in nsBaseWidget::MakeFullScreen to individual methods. r=roc
authorXidorn Quan <quanxunzhen@gmail.com>
Mon, 13 Jul 2015 20:44:36 +1000
changeset 252605 9110eb085b13f684d5ee5a88f1167701c943422f
parent 252604 5e2d116989a55b3db96e88864ea1fc89fd56a235
child 252606 0f941c54cf02683026e39d17ead1861fe89017b9
push id29038
push userkwierso@gmail.com
push dateMon, 13 Jul 2015 22:55:49 +0000
treeherdermozilla-central@c68d02e758f0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1160014
milestone42.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 1160014 part 2 - Move some procedures in nsBaseWidget::MakeFullScreen to individual methods. r=roc The two new methods will be reused by code in later patches.
widget/nsBaseWidget.cpp
widget/nsBaseWidget.h
--- a/widget/nsBaseWidget.cpp
+++ b/widget/nsBaseWidget.cpp
@@ -787,47 +787,29 @@ nsBaseWidget::PerformFullscreenTransitio
 //-------------------------------------------------------------------------
 NS_IMETHODIMP nsBaseWidget::MakeFullScreen(bool aFullScreen, nsIScreen* aScreen)
 {
   HideWindowChrome(aFullScreen);
 
   if (aFullScreen) {
     if (!mOriginalBounds)
       mOriginalBounds = new nsIntRect();
-    GetScreenBounds(*mOriginalBounds);
-    // convert dev pix to display pix for window manipulation
-    CSSToLayoutDeviceScale scale = GetDefaultScale();
-    mOriginalBounds->x = NSToIntRound(mOriginalBounds->x / scale.scale);
-    mOriginalBounds->y = NSToIntRound(mOriginalBounds->y / scale.scale);
-    mOriginalBounds->width = NSToIntRound(mOriginalBounds->width / scale.scale);
-    mOriginalBounds->height = NSToIntRound(mOriginalBounds->height / scale.scale);
+    *mOriginalBounds = GetScaledScreenBounds();
 
     // Move to top-left corner of screen and size to the screen dimensions
-    nsCOMPtr<nsIScreenManager> screenManager;
-    screenManager = do_GetService("@mozilla.org/gfx/screenmanager;1");
-    NS_ASSERTION(screenManager, "Unable to grab screenManager.");
-    if (screenManager) {
-      nsCOMPtr<nsIScreen> screen = aScreen;
-      if (!screen) {
-        // no screen was passed in, use the one that the window is on
-        screenManager->ScreenForRect(mOriginalBounds->x,
-                                     mOriginalBounds->y,
-                                     mOriginalBounds->width,
-                                     mOriginalBounds->height,
-                                     getter_AddRefs(screen));
-      }
-
-      if (screen) {
-        int32_t left, top, width, height;
-        if (NS_SUCCEEDED(screen->GetRectDisplayPix(&left, &top, &width, &height))) {
-          Resize(left, top, width, height, true);
-        }
+    nsCOMPtr<nsIScreen> screen = aScreen;
+    if (!screen) {
+      screen = GetWidgetScreen();
+    }
+    if (screen) {
+      int32_t left, top, width, height;
+      if (NS_SUCCEEDED(screen->GetRectDisplayPix(&left, &top, &width, &height))) {
+        Resize(left, top, width, height, true);
       }
     }
-
   } else if (mOriginalBounds) {
     Resize(mOriginalBounds->x, mOriginalBounds->y, mOriginalBounds->width,
            mOriginalBounds->height, true);
   }
 
   return NS_OK;
 }
 
@@ -1753,16 +1735,46 @@ nsBaseWidget::GetRootAccessible()
     return accService->GetRootDocumentAccessible(presShell, nsContentUtils::IsSafeToRunScript());
   }
 
   return nullptr;
 }
 
 #endif // ACCESSIBILITY
 
+nsIntRect
+nsBaseWidget::GetScaledScreenBounds()
+{
+  nsIntRect bounds;
+  GetScreenBounds(bounds);
+  CSSToLayoutDeviceScale scale = GetDefaultScale();
+  bounds.x = NSToIntRound(bounds.x / scale.scale);
+  bounds.y = NSToIntRound(bounds.y / scale.scale);
+  bounds.width = NSToIntRound(bounds.width / scale.scale);
+  bounds.height = NSToIntRound(bounds.height / scale.scale);
+  return bounds;
+}
+
+already_AddRefed<nsIScreen>
+nsBaseWidget::GetWidgetScreen()
+{
+  nsCOMPtr<nsIScreenManager> screenManager;
+  screenManager = do_GetService("@mozilla.org/gfx/screenmanager;1");
+  if (!screenManager) {
+    return nullptr;
+  }
+
+  nsIntRect bounds = GetScaledScreenBounds();
+  nsCOMPtr<nsIScreen> screen;
+  screenManager->ScreenForRect(bounds.x, bounds.y,
+                               bounds.width, bounds.height,
+                               getter_AddRefs(screen));
+  return screen.forget();
+}
+
 nsresult
 nsIWidget::SynthesizeNativeTouchTap(nsIntPoint aPointerScreenPoint, bool aLongTap,
                                     nsIObserver* aObserver)
 {
   AutoObserverNotifier notifier(aObserver, "touchtap");
 
   if (sPointerIdCounter > TOUCH_INJECT_MAX_POINTS) {
     sPointerIdCounter = 0;
--- a/widget/nsBaseWidget.h
+++ b/widget/nsBaseWidget.h
@@ -279,16 +279,23 @@ public:
   nsPopupLevel PopupLevel() { return mPopupLevel; }
 
   virtual mozilla::LayoutDeviceIntSize
   ClientToWindowSize(const mozilla::LayoutDeviceIntSize& aClientSize) override
   {
     return aClientSize;
   }
 
+  // return the widget's outside dimensions
+  // in global coordinates in display pixel.
+  nsIntRect GetScaledScreenBounds();
+
+  // return the screen the widget is in.
+  already_AddRefed<nsIScreen> GetWidgetScreen();
+
   // return true if this is a popup widget with a native titlebar
   bool IsPopupWithTitleBar() const
   {
     return (mWindowType == eWindowType_popup && 
             mBorderStyle != eBorderStyle_default &&
             mBorderStyle & eBorderStyle_title);
   }