Bumping manifests a=b2g-bump
[gecko.git] / widget / qt / nsScreenManagerQt.cpp
blob732008028123a120c2f492abf82b69820701ba2b
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include <QGuiApplication>
6 #include <QScreen>
8 #include "nsScreenManagerQt.h"
9 #include "nsScreenQt.h"
11 nsScreenManagerQt::nsScreenManagerQt()
13 mInitialized = false;
14 desktop = 0;
15 screens = 0;
18 nsScreenManagerQt::~nsScreenManagerQt()
20 delete [] screens;
23 // addref, release, QI
24 NS_IMPL_ISUPPORTS(nsScreenManagerQt, nsIScreenManager)
26 void nsScreenManagerQt::init()
28 if (mInitialized)
29 return;
31 nScreens = QGuiApplication::screens().size();
32 screens = new nsCOMPtr<nsIScreen>[nScreens];
34 for (int i = 0; i < nScreens; ++i)
35 screens[i] = new nsScreenQt(i);
36 mInitialized = true;
40 // ScreenForRect
42 // Returns the screen that contains the rectangle. If the rect overlaps
43 // multiple screens, it picks the screen with the greatest area of intersection.
45 // The coordinates are in pixels (not twips) and in screen coordinates.
47 NS_IMETHODIMP
48 nsScreenManagerQt::ScreenForRect(int32_t inLeft, int32_t inTop,
49 int32_t inWidth, int32_t inHeight,
50 nsIScreen **outScreen)
52 if (!mInitialized)
53 init();
55 QRect r(inLeft, inTop, inWidth, inHeight);
56 int best = 0;
57 int area = 0;
58 for (int i = 0; i < nScreens; ++i) {
59 const QRect& rect = QGuiApplication::screens()[i]->geometry();
60 QRect intersection = r&rect;
61 int a = intersection.width()*intersection.height();
62 if (a > area) {
63 best = i;
64 area = a;
68 NS_IF_ADDREF(*outScreen = screens[best]);
69 return NS_OK;
72 NS_IMETHODIMP
73 nsScreenManagerQt::ScreenForId(uint32_t aId, nsIScreen** aOutScreen)
75 if (!mInitialized) {
76 init();
79 if (aId < nScreens) {
80 NS_IF_ADDREF(*aOutScreen = screens[aId]);
81 return NS_OK;
84 return NS_ERROR_FAILURE;
88 // GetPrimaryScreen
90 // The screen with the menubar/taskbar. This shouldn't be needed very
91 // often.
93 NS_IMETHODIMP
94 nsScreenManagerQt::GetPrimaryScreen(nsIScreen **aPrimaryScreen)
96 if (!desktop)
97 init();
99 NS_IF_ADDREF(*aPrimaryScreen = screens[0]);
100 return NS_OK;
104 // GetNumberOfScreens
106 // Returns how many physical screens are available.
108 NS_IMETHODIMP
109 nsScreenManagerQt::GetNumberOfScreens(uint32_t *aNumberOfScreens)
111 if (!desktop)
112 init();
114 *aNumberOfScreens = nScreens;
115 return NS_OK;
118 NS_IMETHODIMP
119 nsScreenManagerQt::GetSystemDefaultScale(float *aDefaultScale)
121 *aDefaultScale = 1.0f;
122 return NS_OK;
125 NS_IMETHODIMP
126 nsScreenManagerQt::ScreenForNativeWidget(void *aWidget, nsIScreen **outScreen)
128 // I don't know how to go from GtkWindow to nsIScreen, especially
129 // given xinerama and stuff, so let's just do this
130 QRect rect(0, 0, 1, 1);
131 return ScreenForRect(rect.x(), rect.y(), rect.width(), rect.height(), outScreen);