diff --git a/widget/nsBaseWidget.cpp b/widget/nsBaseWidget.cpp index db6a6bd670db..e8ae12c2441a 100644 --- a/widget/nsBaseWidget.cpp +++ b/widget/nsBaseWidget.cpp @@ -792,37 +792,19 @@ NS_IMETHODIMP nsBaseWidget::MakeFullScreen(bool aFullScreen, nsIScreen* aScreen) 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 screenManager; - screenManager = do_GetService("@mozilla.org/gfx/screenmanager;1"); - NS_ASSERTION(screenManager, "Unable to grab screenManager."); - if (screenManager) { - nsCOMPtr 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 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); @@ -1758,6 +1740,36 @@ nsBaseWidget::GetRootAccessible() #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 +nsBaseWidget::GetWidgetScreen() +{ + nsCOMPtr screenManager; + screenManager = do_GetService("@mozilla.org/gfx/screenmanager;1"); + if (!screenManager) { + return nullptr; + } + + nsIntRect bounds = GetScaledScreenBounds(); + nsCOMPtr 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) diff --git a/widget/nsBaseWidget.h b/widget/nsBaseWidget.h index 20b833f55ebd..aa53880aaff3 100644 --- a/widget/nsBaseWidget.h +++ b/widget/nsBaseWidget.h @@ -284,6 +284,13 @@ public: 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 GetWidgetScreen(); + // return true if this is a popup widget with a native titlebar bool IsPopupWithTitleBar() const {