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.

--HG--
extra : source : 45aad13e8c5f7e4745344e61ba58b0acdfb0d054
This commit is contained in:
Xidorn Quan 2015-07-11 10:08:59 +10:00
Родитель 09d4d46e81
Коммит c9dc71d8c7
2 изменённых файлов: 46 добавлений и 27 удалений

Просмотреть файл

@ -792,37 +792,19 @@ NS_IMETHODIMP nsBaseWidget::MakeFullScreen(bool aFullScreen, nsIScreen* aScreen)
if (aFullScreen) { if (aFullScreen) {
if (!mOriginalBounds) if (!mOriginalBounds)
mOriginalBounds = new nsIntRect(); mOriginalBounds = new nsIntRect();
GetScreenBounds(*mOriginalBounds); *mOriginalBounds = GetScaledScreenBounds();
// 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);
// Move to top-left corner of screen and size to the screen dimensions // Move to top-left corner of screen and size to the screen dimensions
nsCOMPtr<nsIScreenManager> screenManager; nsCOMPtr<nsIScreen> screen = aScreen;
screenManager = do_GetService("@mozilla.org/gfx/screenmanager;1"); if (!screen) {
NS_ASSERTION(screenManager, "Unable to grab screenManager."); screen = GetWidgetScreen();
if (screenManager) { }
nsCOMPtr<nsIScreen> screen = aScreen; if (screen) {
if (!screen) { int32_t left, top, width, height;
// no screen was passed in, use the one that the window is on if (NS_SUCCEEDED(screen->GetRectDisplayPix(&left, &top, &width, &height))) {
screenManager->ScreenForRect(mOriginalBounds->x, Resize(left, top, width, height, true);
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);
}
} }
} }
} else if (mOriginalBounds) { } else if (mOriginalBounds) {
Resize(mOriginalBounds->x, mOriginalBounds->y, mOriginalBounds->width, Resize(mOriginalBounds->x, mOriginalBounds->y, mOriginalBounds->width,
mOriginalBounds->height, true); mOriginalBounds->height, true);
@ -1758,6 +1740,36 @@ nsBaseWidget::GetRootAccessible()
#endif // ACCESSIBILITY #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 nsresult
nsIWidget::SynthesizeNativeTouchTap(nsIntPoint aPointerScreenPoint, bool aLongTap, nsIWidget::SynthesizeNativeTouchTap(nsIntPoint aPointerScreenPoint, bool aLongTap,
nsIObserver* aObserver) nsIObserver* aObserver)

Просмотреть файл

@ -283,6 +283,13 @@ public:
return aClientSize; 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 // return true if this is a popup widget with a native titlebar
bool IsPopupWithTitleBar() const bool IsPopupWithTitleBar() const
{ {