API  0.9.9
CPPlatformWindow.j
Go to the documentation of this file.
1 /*
2  * CPPlatformWindow.j
3  * AppKit
4  *
5  * Created by Francisco Tolmasky.
6  * Copyright 2010, 280 North, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 
24 
25 @global CPApp
26 
27 @typedef DOMWindow
28 
30 
31 @implementation CPPlatformWindow : CPObject
32 {
33  CGRect _contentRect;
34 
35  CPInteger _level;
36  BOOL _hasShadow;
37  unsigned _shadowStyle;
38  CPString _title;
39  BOOL _shouldUpdateContentRect;
40  BOOL _hasInitializeInstanceWithWindow;
41 
42 #if PLATFORM(DOM)
43  DOMWindow _DOMWindow;
44 
45  DOMElement _DOMBodyElement;
46  DOMElement _DOMFocusElement;
47  DOMElement _DOMEventGuard;
48  DOMElement _DOMScrollingElement;
49  id _hideDOMScrollingElementTimeout;
50 
51  CPArray _windowLevels;
52  CPDictionary _windowLayers;
53 
54  BOOL _mouseIsDown;
55  BOOL _mouseDownIsRightClick;
56  CGPoint _lastMouseEventLocation;
57  CPWindow _mouseDownWindow;
58  CPTimeInterval _lastMouseUp;
59  CPTimeInterval _lastMouseDown;
60 
61  Object _charCodes;
62  unsigned _keyCode;
63  unsigned _lastKey;
64  BOOL _capsLockActive;
65 
66  BOOL _DOMEventMode;
67 
68  CPPlatformPasteboard _platformPasteboard;
69 
70  CPString _overriddenEventType;
71 
72  CPWindow _currentKeyWindow;
73  CPWindow _previousKeyWindow;
74 
75  CPWindow _currentMainWindow;
76  CPWindow _previousMainWindow;
77 #endif
78 }
79 
81 {
82  return [CPSet set];
83 }
84 
86 {
87 #if PLATFORM(DOM)
89 #else
90  return NO;
91 #endif
92 }
93 
95 {
96  return PrimaryPlatformWindow;
97 }
98 
99 + (void)setPrimaryPlatformWindow:(CPPlatformWindow)aPlatformWindow
100 {
101  PrimaryPlatformWindow = aPlatformWindow;
102 }
103 
104 - (id)initWithContentRect:(CGRect)aRect
105 {
106  self = [super init];
107 
108  if (self)
109  {
110  _contentRect = CGRectMakeCopy(aRect);
111 
112 #if PLATFORM(DOM)
113  _windowLevels = [];
114  _windowLayers = @{};
115 
116  _charCodes = {};
117 
118  _platformPasteboard = [CPPlatformPasteboard new];
119 #endif
120  }
121 
122  return self;
123 }
124 
125 - (id)initWithWindow:(CPWindow)aWindow
126 {
127  self = [self initWithContentRect:CGRectMakeCopy([aWindow frame])];
128 
129  _hasInitializeInstanceWithWindow = YES;
130  [aWindow setPlatformWindow:self];
131  [aWindow setFullPlatformWindow:YES];
132 
133  return self;
134 }
135 
136 - (id)init
137 {
138  return [self initWithContentRect:CGRectMake(0.0, 0.0, 400.0, 500.0)];
139 }
140 
141 - (CGRect)contentRect
142 {
143  return CGRectMakeCopy(_contentRect);
144 }
145 
146 - (CGRect)contentBounds
147 {
148  var contentBounds = [self contentRect];
149 
150  contentBounds.origin = CGPointMakeZero();
151 
152  return contentBounds;
153 }
154 
155 - (CGRect)visibleFrame
156 {
157  var frame = [self contentBounds];
158 
159  frame.origin = CGPointMakeZero();
160 
161  if ([CPMenu menuBarVisible] && [CPPlatformWindow primaryPlatformWindow] === self)
162  {
163  var menuBarHeight = [[CPApp mainMenu] menuBarHeight];
164 
165  frame.origin.y += menuBarHeight;
166  frame.size.height -= menuBarHeight;
167  }
168 
169  return frame;
170 }
171 
173 {
174  return [self visibleFrame];
175 }
176 
177 - (void)setContentRect:(CGRect)aRect
178 {
179  if (!aRect || CGRectEqualToRect(_contentRect, aRect))
180  return;
181 
182  _contentRect = CGRectMakeCopy(aRect);
183 
184 #if PLATFORM(DOM)
185  [self updateNativeContentRect];
186 #endif
187 }
188 
190 {
191  [self setContentRect:[self nativeContentRect]];
192 }
193 
194 - (CGPoint)convertBaseToScreen:(CGPoint)aPoint
195 {
196  var contentRect = [self contentRect];
197 
198  return CGPointMake(aPoint.x + CGRectGetMinX(contentRect), aPoint.y + CGRectGetMinY(contentRect));
199 }
200 
201 - (CGPoint)convertScreenToBase:(CGPoint)aPoint
202 {
203  var contentRect = [self contentRect];
204 
205  return CGPointMake(aPoint.x - CGRectGetMinX(contentRect), aPoint.y - CGRectGetMinY(contentRect));
206 }
207 
208 - (BOOL)isVisible
209 {
210 #if PLATFORM(DOM)
211  return _DOMWindow !== NULL && _DOMWindow !== undefined;
212 #else
213  return NO;
214 #endif
215 }
216 
217 - (void)deminiaturize:(id)sender
218 {
219 #if PLATFORM(DOM)
220  if (_DOMWindow && typeof _DOMWindow["cpDeminiaturize"] === "function")
221  _DOMWindow.cpDeminiaturize();
222 #endif
223 }
224 
225 - (void)miniaturize:(id)sender
226 {
227 #if PLATFORM(DOM)
228  if (_DOMWindow && typeof _DOMWindow["cpMiniaturize"] === "function")
229  _DOMWindow.cpMiniaturize();
230 #endif
231 }
232 
233 - (void)moveWindow:(CPWindow)aWindow fromLevel:(int)fromLevel toLevel:(int)toLevel
234 {
235 #if PLATFORM(DOM)
236  if (!aWindow._isVisible)
237  return;
238 
239  var fromLayer = [self layerAtLevel:fromLevel create:NO],
240  toLayer = [self layerAtLevel:toLevel create:YES];
241 
242  [fromLayer removeWindow:aWindow];
243  [toLayer insertWindow:aWindow atIndex:CPNotFound];
244 #endif
245 }
246 
247 - (void)setLevel:(CPInteger)aLevel
248 {
249  _level = aLevel;
250 
251 #if PLATFORM(DOM)
252  if (_DOMWindow && _DOMWindow.cpSetLevel)
253  _DOMWindow.cpSetLevel(aLevel);
254 #endif
255 }
256 
257 - (void)setHasShadow:(BOOL)shouldHaveShadow
258 {
259  _hasShadow = shouldHaveShadow;
260 
261 #if PLATFORM(DOM)
262  if (_DOMWindow && _DOMWindow.cpSetHasShadow)
263  _DOMWindow.cpSetHasShadow(shouldHaveShadow);
264 #endif
265 }
266 
267 - (void)setShadowStyle:(int)aStyle
268 {
269  _shadowStyle = aStyle;
270 
271 #if PLATFORM(DOM)
272  if (_DOMWindow && _DOMWindow.cpSetShadowStyle)
273  _shadowStyle.cpSetShadowStyle(aStyle);
274 #endif
275 }
276 
278 {
279  return [CPPlatform isBrowser];
280 }
281 
282 - (void)_setTitle:(CPString)aTitle window:(CPWindow)aWindow
283 {
284  _title = aTitle;
285 
286 #if PLATFORM(DOM)
287  if (_DOMWindow &&
288  _DOMWindow.document &&
289  ([aWindow isFullPlatformWindow]))
290  {
291  _DOMWindow.document.title = _title;
292  }
293 #endif
294 }
295 
297 {
298  return _title;
299 }
300 
301 - (BOOL)_canUpdateContentRect
302 {
303  // We onyl update the contentRect with the frame of the bridgeless window if we have initialized the platform with the method initWithWindow:
304  return _shouldUpdateContentRect && _hasInitializeInstanceWithWindow;
305 }
306 
307 - (BOOL)_hasInitializeInstanceWithWindow
308 {
309  return _hasInitializeInstanceWithWindow;
310 }
311 
312 - (void)_setShouldUpdateContentRect:(BOOL)aBoolean
313 {
314  _shouldUpdateContentRect = aBoolean;
315 }
316 
317 @end
318 
319 #if PLATFORM(BROWSER)
320 #endif
Definition: CPMenu.h:2
global CPApp typedef DOMWindow var PrimaryPlatformWindow
CGRect frame
id initWithContentRect:(CGRect aRect)
void setPlatformWindow:(CPPlatformWindow aPlatformWindow)
Definition: CPWindow.j:394
void updateFromNativeContentRect()
A mutable key-value pair collection.
Definition: CPDictionary.h:2
CPSet visiblePlatformWindows()
An immutable string (collection of characters).
Definition: CPString.h:2
CPInternetExplorerBrowserEngine
void setContentRect:(CGRect aRect)
CGRect frame()
Definition: CPWindow.j:665
id init()
Definition: CPObject.j:145
void setFullPlatformWindow:(BOOL shouldBeFullPlatformWindow)
Definition: CPWindow.j:561
function CPBrowserIsEngine(anEngine)
BOOL supportsFullPlatformWindows()
BOOL isBrowser()
Definition: CPPlatform.j:33
BOOL supportsMultipleInstances()
CPPlatformWindow primaryPlatformWindow()