1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * Travis Bogard <travis@netscape.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
41 #include "nsIDocShell.h"
42 #include "nsIDeviceContext.h"
43 #include "nsPresContext.h"
45 #include "nsDOMClassInfo.h"
46 #include "nsIInterfaceRequestorUtils.h"
47 #include "nsLayoutUtils.h"
50 // Screen class implementation
52 nsScreen::nsScreen(nsIDocShell
* aDocShell
)
53 : mDocShell(aDocShell
)
62 DOMCI_DATA(Screen
, nsScreen
)
64 // QueryInterface implementation for nsScreen
65 NS_INTERFACE_MAP_BEGIN(nsScreen
)
66 NS_INTERFACE_MAP_ENTRY(nsISupports
)
67 NS_INTERFACE_MAP_ENTRY(nsIDOMScreen
)
68 NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Screen
)
72 NS_IMPL_ADDREF(nsScreen
)
73 NS_IMPL_RELEASE(nsScreen
)
77 nsScreen::SetDocShell(nsIDocShell
* aDocShell
)
79 mDocShell
= aDocShell
; // Weak Reference
84 nsScreen::GetTop(PRInt32
* aTop
)
87 nsresult rv
= GetRect(rect
);
96 nsScreen::GetLeft(PRInt32
* aLeft
)
99 nsresult rv
= GetRect(rect
);
108 nsScreen::GetWidth(PRInt32
* aWidth
)
111 nsresult rv
= GetRect(rect
);
113 *aWidth
= rect
.width
;
119 nsScreen::GetHeight(PRInt32
* aHeight
)
122 nsresult rv
= GetRect(rect
);
124 *aHeight
= rect
.height
;
130 nsScreen::GetPixelDepth(PRInt32
* aPixelDepth
)
132 nsIDeviceContext
* context
= GetDeviceContext();
137 return NS_ERROR_FAILURE
;
141 context
->GetDepth(depth
);
143 *aPixelDepth
= depth
;
149 nsScreen::GetColorDepth(PRInt32
* aColorDepth
)
151 return GetPixelDepth(aColorDepth
);
155 nsScreen::GetAvailWidth(PRInt32
* aAvailWidth
)
158 nsresult rv
= GetAvailRect(rect
);
160 *aAvailWidth
= rect
.width
;
166 nsScreen::GetAvailHeight(PRInt32
* aAvailHeight
)
169 nsresult rv
= GetAvailRect(rect
);
171 *aAvailHeight
= rect
.height
;
177 nsScreen::GetAvailLeft(PRInt32
* aAvailLeft
)
180 nsresult rv
= GetAvailRect(rect
);
182 *aAvailLeft
= rect
.x
;
188 nsScreen::GetAvailTop(PRInt32
* aAvailTop
)
191 nsresult rv
= GetAvailRect(rect
);
199 nsScreen::GetDeviceContext()
201 return nsLayoutUtils::GetDeviceContextForScreenInfo(mDocShell
);
205 nsScreen::GetRect(nsRect
& aRect
)
207 nsIDeviceContext
*context
= GetDeviceContext();
210 return NS_ERROR_FAILURE
;
213 context
->GetRect(aRect
);
215 aRect
.x
= nsPresContext::AppUnitsToIntCSSPixels(aRect
.x
);
216 aRect
.y
= nsPresContext::AppUnitsToIntCSSPixels(aRect
.y
);
217 aRect
.height
= nsPresContext::AppUnitsToIntCSSPixels(aRect
.height
);
218 aRect
.width
= nsPresContext::AppUnitsToIntCSSPixels(aRect
.width
);
224 nsScreen::GetAvailRect(nsRect
& aRect
)
226 nsIDeviceContext
*context
= GetDeviceContext();
229 return NS_ERROR_FAILURE
;
232 context
->GetClientRect(aRect
);
234 aRect
.x
= nsPresContext::AppUnitsToIntCSSPixels(aRect
.x
);
235 aRect
.y
= nsPresContext::AppUnitsToIntCSSPixels(aRect
.y
);
236 aRect
.height
= nsPresContext::AppUnitsToIntCSSPixels(aRect
.height
);
237 aRect
.width
= nsPresContext::AppUnitsToIntCSSPixels(aRect
.width
);