API  1.0.0
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  int _firstMouseDownButton;
57  CGPoint _lastMouseEventLocation;
58  CPWindow _mouseDownWindow;
59  CPTimeInterval _lastMouseUp;
60  CPTimeInterval _lastMouseDown;
61 
62  Object _charCodes;
63  unsigned _keyCode;
64  unsigned _lastKey;
65  BOOL _capsLockActive;
66 
67  BOOL _DOMEventMode;
68 
69  CPPlatformPasteboard _platformPasteboard;
70 
71  CPString _overriddenEventType;
72 
73  CPWindow _currentKeyWindow;
74  CPWindow _previousKeyWindow;
75 
76  CPWindow _currentMainWindow;
77  CPWindow _previousMainWindow;
78 #endif
79 }
80 
81 + (CPSet)visiblePlatformWindows
82 {
83  return [CPSet set];
84 }
85 
86 + (BOOL)supportsMultipleInstances
87 {
88 #if PLATFORM(DOM)
90 #else
91  return NO;
92 #endif
93 }
94 
95 + (CPPlatformWindow)primaryPlatformWindow
96 {
97  return PrimaryPlatformWindow;
98 }
99 
100 + (void)setPrimaryPlatformWindow:(CPPlatformWindow)aPlatformWindow
101 {
102  PrimaryPlatformWindow = aPlatformWindow;
103 }
104 
105 - (id)initWithContentRect:(CGRect)aRect
106 {
107  self = [super init];
108 
109  if (self)
110  {
111  _contentRect = CGRectMakeCopy(aRect);
112 
113 #if PLATFORM(DOM)
114  _windowLevels = [];
115  _windowLayers = @{};
116 
117  _charCodes = {};
118 
119  _platformPasteboard = [CPPlatformPasteboard new];
120 #endif
121  }
122 
123  return self;
124 }
125 
126 - (id)initWithWindow:(CPWindow)aWindow
127 {
128  self = [self initWithContentRect:CGRectMakeCopy([aWindow frame])];
129 
130  _hasInitializeInstanceWithWindow = YES;
131  [aWindow setPlatformWindow:self];
132  [aWindow setFullPlatformWindow:YES];
133 
134  return self;
135 }
136 
137 - (id)init
138 {
139  return [self initWithContentRect:CGRectMake(0.0, 0.0, 400.0, 500.0)];
140 }
141 
142 - (CGRect)contentRect
143 {
144  return CGRectMakeCopy(_contentRect);
145 }
146 
147 - (CGRect)contentBounds
148 {
149  var contentBounds = [self contentRect];
150 
151  contentBounds.origin = CGPointMakeZero();
152 
153  return contentBounds;
154 }
155 
156 - (CGRect)visibleFrame
157 {
158  var frame = [self contentBounds];
159 
160  frame.origin = CGPointMakeZero();
161 
162  if ([CPMenu menuBarVisible] && [CPPlatformWindow primaryPlatformWindow] === self)
163  {
164  var menuBarHeight = [[CPApp mainMenu] menuBarHeight];
165 
166  frame.origin.y += menuBarHeight;
167  frame.size.height -= menuBarHeight;
168  }
169 
170  return frame;
171 }
172 
173 - (CGRect)usableContentFrame
174 {
175  return [self visibleFrame];
176 }
177 
178 - (void)setContentRect:(CGRect)aRect
179 {
180  if (!aRect || CGRectEqualToRect(_contentRect, aRect))
181  return;
182 
183  _contentRect = CGRectMakeCopy(aRect);
184 
185 #if PLATFORM(DOM)
186  [self updateNativeContentRect];
187 #endif
188 }
189 
190 - (void)updateFromNativeContentRect
191 {
192  [self setContentRect:[self nativeContentRect]];
193 }
194 
195 - (CGPoint)convertBaseToScreen:(CGPoint)aPoint
196 {
197  var contentRect = [self contentRect];
198 
199  return CGPointMake(aPoint.x + CGRectGetMinX(contentRect), aPoint.y + CGRectGetMinY(contentRect));
200 }
201 
202 - (CGPoint)convertScreenToBase:(CGPoint)aPoint
203 {
204  var contentRect = [self contentRect];
205 
206  return CGPointMake(aPoint.x - CGRectGetMinX(contentRect), aPoint.y - CGRectGetMinY(contentRect));
207 }
208 
209 - (BOOL)isVisible
210 {
211 #if PLATFORM(DOM)
212  return _DOMWindow !== NULL && _DOMWindow !== undefined;
213 #else
214  return NO;
215 #endif
216 }
217 
218 - (void)deminiaturize:(id)sender
219 {
220 }
221 
222 - (void)miniaturize:(id)sender
223 {
224 }
225 
226 - (void)moveWindow:(CPWindow)aWindow fromLevel:(int)fromLevel toLevel:(int)toLevel
227 {
228 #if PLATFORM(DOM)
229  if (!aWindow._isVisible)
230  return;
231 
232  var fromLayer = [self layerAtLevel:fromLevel create:NO],
233  toLayer = [self layerAtLevel:toLevel create:YES];
234 
235  [fromLayer removeWindow:aWindow];
236  [toLayer insertWindow:aWindow atIndex:CPNotFound];
237 #endif
238 }
239 
240 - (void)setLevel:(CPInteger)aLevel
241 {
242  _level = aLevel;
243 }
244 
245 - (void)setHasShadow:(BOOL)shouldHaveShadow
246 {
247  _hasShadow = shouldHaveShadow;
248 }
249 
250 - (void)setShadowStyle:(int)aStyle
251 {
252  _shadowStyle = aStyle;
253 }
254 
255 - (BOOL)supportsFullPlatformWindows
256 {
257  return [CPPlatform isBrowser];
258 }
259 
260 - (void)_setTitle:(CPString)aTitle window:(CPWindow)aWindow
261 {
262  _title = aTitle;
263 
264 #if PLATFORM(DOM)
265  if (_DOMWindow &&
266  _DOMWindow.document &&
267  ([aWindow isFullPlatformWindow]))
268  {
269  _DOMWindow.document.title = _title;
270  }
271 #endif
272 }
273 
274 - (CPString)title
275 {
276  return _title;
277 }
278 
279 - (BOOL)_canUpdateContentRect
280 {
281  // We only update the contentRect with the frame of the bridgeless window if we have initialized the platform with the method initWithWindow:
282  return _shouldUpdateContentRect && _hasInitializeInstanceWithWindow;
283 }
284 
285 - (BOOL)_hasInitializeInstanceWithWindow
286 {
287  return _hasInitializeInstanceWithWindow;
288 }
289 
290 - (void)_setShouldUpdateContentRect:(BOOL)aBoolean
291 {
292  _shouldUpdateContentRect = aBoolean;
293 }
294 
295 @end
296 
297 #if PLATFORM(BROWSER)
298 #endif
Definition: CPMenu.h:2
global CPApp typedef DOMWindow var PrimaryPlatformWindow
id init()
Definition: CALayer.j:126
CGRect frame
id initWithContentRect:(CGRect aRect)
void setPlatformWindow:(CPPlatformWindow aPlatformWindow)
Definition: CPWindow.j:399
A mutable key-value pair collection.
Definition: CPDictionary.h:2
An immutable string (collection of characters).
Definition: CPString.h:2
CPInternetExplorerBrowserEngine
void setContentRect:(CGRect aRect)
CGRect frame()
Definition: CPWindow.j:669
id init()
Definition: CPObject.j:145
void setFullPlatformWindow:(BOOL shouldBeFullPlatformWindow)
Definition: CPWindow.j:566
function CPBrowserIsEngine(anEngine)
BOOL isBrowser()
Definition: CPPlatform.j:33