|
1 /* |
|
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions |
|
6 * are met: |
|
7 * 1. Redistributions of source code must retain the above copyright |
|
8 * notice, this list of conditions and the following disclaimer. |
|
9 * 2. Redistributions in binary form must reproduce the above copyright |
|
10 * notice, this list of conditions and the following disclaimer in the |
|
11 * documentation and/or other materials provided with the distribution. |
|
12 * |
|
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
|
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
|
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
24 */ |
|
25 |
|
26 #import "config.h" |
|
27 #import "PlatformScreen.h" |
|
28 |
|
29 #import "FloatRect.h" |
|
30 #import "Frame.h" |
|
31 #import "FrameView.h" |
|
32 #import "Page.h" |
|
33 |
|
34 namespace WebCore { |
|
35 |
|
36 int screenDepth(Widget*) |
|
37 { |
|
38 return NSBitsPerPixelFromDepth([[NSScreen deepestScreen] depth]); |
|
39 } |
|
40 |
|
41 int screenDepthPerComponent(Widget*) |
|
42 { |
|
43 return NSBitsPerSampleFromDepth([[NSScreen deepestScreen] depth]); |
|
44 } |
|
45 |
|
46 bool screenIsMonochrome(Widget*) |
|
47 { |
|
48 return false; |
|
49 } |
|
50 |
|
51 // These functions scale between screen and page coordinates because JavaScript/DOM operations |
|
52 // assume that the screen and the page share the same coordinate system. |
|
53 |
|
54 FloatRect screenRect(Widget* widget) |
|
55 { |
|
56 NSWindow *window = widget ? [widget->platformWidget() window] : nil; |
|
57 return toUserSpace([screenForWindow(window) frame], window); |
|
58 } |
|
59 |
|
60 FloatRect screenAvailableRect(Widget* widget) |
|
61 { |
|
62 NSWindow *window = widget ? [widget->platformWidget() window] : nil; |
|
63 return toUserSpace([screenForWindow(window) visibleFrame], window); |
|
64 } |
|
65 |
|
66 NSScreen *screenForWindow(NSWindow *window) |
|
67 { |
|
68 NSScreen *screen = [window screen]; // nil if the window is off-screen |
|
69 if (screen) |
|
70 return screen; |
|
71 |
|
72 NSArray *screens = [NSScreen screens]; |
|
73 if ([screens count] > 0) |
|
74 return [screens objectAtIndex:0]; // screen containing the menubar |
|
75 |
|
76 return nil; |
|
77 } |
|
78 |
|
79 FloatRect toUserSpace(const NSRect& rect, NSWindow *destination) |
|
80 { |
|
81 FloatRect userRect = rect; |
|
82 userRect.setY(NSMaxY([screenForWindow(destination) frame]) - (userRect.y() + userRect.height())); // flip |
|
83 if (destination) |
|
84 userRect.scale(1 / [destination userSpaceScaleFactor]); // scale down |
|
85 return userRect; |
|
86 } |
|
87 |
|
88 NSRect toDeviceSpace(const FloatRect& rect, NSWindow *source) |
|
89 { |
|
90 FloatRect deviceRect = rect; |
|
91 if (source) |
|
92 deviceRect.scale([source userSpaceScaleFactor]); // scale up |
|
93 deviceRect.setY(NSMaxY([screenForWindow(source) frame]) - (deviceRect.y() + deviceRect.height())); // flip |
|
94 return deviceRect; |
|
95 } |
|
96 |
|
97 NSPoint flipScreenPoint(const NSPoint& screenPoint, NSScreen *screen) |
|
98 { |
|
99 NSPoint flippedPoint = screenPoint; |
|
100 flippedPoint.y = NSMaxY([screen frame]) - flippedPoint.y; |
|
101 return flippedPoint; |
|
102 } |
|
103 |
|
104 } // namespace WebCore |