1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2/* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6#import <UIKit/UIScreen.h> 7 8#include "gfxPoint.h" 9#include "nsScreenManager.h" 10#include "nsAppShell.h" 11 12static LayoutDeviceIntRect gScreenBounds; 13static bool gScreenBoundsSet = false; 14 15UIKitScreen::UIKitScreen(UIScreen* aScreen) { mScreen = [aScreen retain]; } 16 17NS_IMETHODIMP 18UIKitScreen::GetRect(int32_t* outX, int32_t* outY, int32_t* outWidth, int32_t* outHeight) { 19 return GetRectDisplayPix(outX, outY, outWidth, outHeight); 20} 21 22NS_IMETHODIMP 23UIKitScreen::GetAvailRect(int32_t* outX, int32_t* outY, int32_t* outWidth, int32_t* outHeight) { 24 return GetAvailRectDisplayPix(outX, outY, outWidth, outHeight); 25} 26 27NS_IMETHODIMP 28UIKitScreen::GetRectDisplayPix(int32_t* outX, int32_t* outY, int32_t* outWidth, 29 int32_t* outHeight) { 30 nsIntRect rect = UIKitScreenManager::GetBounds(); 31 *outX = rect.x; 32 *outY = rect.y; 33 *outWidth = rect.width; 34 *outHeight = rect.height; 35 36 return NS_OK; 37} 38 39NS_IMETHODIMP 40UIKitScreen::GetAvailRectDisplayPix(int32_t* outX, int32_t* outY, int32_t* outWidth, 41 int32_t* outHeight) { 42 CGRect rect = [mScreen applicationFrame]; 43 CGFloat scale = [mScreen scale]; 44 45 *outX = rect.origin.x * scale; 46 *outY = rect.origin.y * scale; 47 *outWidth = rect.size.width * scale; 48 *outHeight = rect.size.height * scale; 49 50 return NS_OK; 51} 52 53NS_IMETHODIMP 54UIKitScreen::GetPixelDepth(int32_t* aPixelDepth) { 55 // Close enough. 56 *aPixelDepth = 24; 57 return NS_OK; 58} 59 60NS_IMETHODIMP 61UIKitScreen::GetColorDepth(int32_t* aColorDepth) { return GetPixelDepth(aColorDepth); } 62 63NS_IMETHODIMP 64UIKitScreen::GetContentsScaleFactor(double* aContentsScaleFactor) { 65 *aContentsScaleFactor = [mScreen scale]; 66 return NS_OK; 67} 68 69NS_IMPL_ISUPPORTS(UIKitScreenManager, nsIScreenManager) 70 71UIKitScreenManager::UIKitScreenManager() : mScreen(new UIKitScreen([UIScreen mainScreen])) {} 72 73LayoutDeviceIntRect UIKitScreenManager::GetBounds() { 74 if (!gScreenBoundsSet) { 75 CGRect rect = [[UIScreen mainScreen] bounds]; 76 CGFloat scale = [[UIScreen mainScreen] scale]; 77 gScreenBounds.x = rect.origin.x * scale; 78 gScreenBounds.y = rect.origin.y * scale; 79 gScreenBounds.width = rect.size.width * scale; 80 gScreenBounds.height = rect.size.height * scale; 81 gScreenBoundsSet = true; 82 } 83 printf("UIKitScreenManager::GetBounds: %d %d %d %d\n", gScreenBounds.x, gScreenBounds.y, 84 gScreenBounds.width, gScreenBounds.height); 85 return gScreenBounds; 86} 87 88NS_IMETHODIMP 89UIKitScreenManager::GetPrimaryScreen(nsIScreen** outScreen) { 90 NS_IF_ADDREF(*outScreen = mScreen.get()); 91 return NS_OK; 92} 93 94NS_IMETHODIMP 95UIKitScreenManager::ScreenForRect(int32_t inLeft, int32_t inTop, int32_t inWidth, int32_t inHeight, 96 nsIScreen** outScreen) { 97 return GetPrimaryScreen(outScreen); 98} 99