Platform Windows Support

69 views
Skip to first unread message

Francisco Tolmasky

unread,
Jul 27, 2009, 3:25:55 PM7/27/09
to Cappuccino & Objective-J
I've just pushed the beginnings of "platform windows" support to the
master branch. Platform windows are "real" windows, in other words,
"browser windows" as opposed to CPWindows. Prior to this change,
Cappuccino could only run in one window, and if you wanted another
window you would have to do so through the traditional window.open API
and load an entire new Cappuccino app in it. This had a number of
problems:

1. For starters, it is slow to load a whole new instance of the app in
the new window.
2. The new window had its own "context", meaning it had its own
separate copy of globals like CPApp, etc. Essentially, you really were
running TWO separate Cappuccino apps, not one with 2 windows.
3. If you closed this window, you could not open it again, and would
have to load the whole app again.

This (partially now and better soon) no longer be the case with the
introduction of CPPlatformWindow. Normally, you will never deal with
them directly, but CPWindows now exist within a CPPlatformWindow,
which is accessible as so:

[myWindow platformWindow]; // This will be [CPPlatformWindow
primaryPlatformWindow] normally

But you can now create new platform windows as well:

var anotherPlatformWindow = [[CPPlatformWindow alloc]
initWithContentRect:CGRectMake(100.0, 100.0, 500.0, 500.0)];

[anotherPlatformWindow orderFront:self];

[myWindow setPlatformWindow:anotherPlatformWindow];
[myWindow orderFront:self]; // This will be in the new window now.

The important thing about platform windows is that their "code" still
runs in the first window. That means you can make views and objects in
the first window and treat the CPWindow just like any other CPWindow
that exists inside the browser:

var myView = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0,
100.0)];
[myView setBackgroundColor:[CPColor redColor]];
[myWindow addSubview:myView]; // view created in first window put in
second window.

Similarly, you can close platform windows and open them again without
needing to create a new DOMWindow object like in traditional
javascript:

[anotherPlatformWindow orderOut:self];
[anotherPlatformWindow orderFront:self];

vs.

window.close();
window // stale object, cant open it again.

There is still a fair deal of work left here, but it is now at the
point where it works as well as it did before. One important thing to
note is that the introduction of CPPlatformWindows deprecate the old
CPDOMWindowBridge class which expected there to only ever be one
window. This is the only place you may find conflicts in your code (if
you use something like [[CPDOMWindowBridge sharedWindowBridge]
contentBounds] or somesuch), but these methods have parallel
implementations in CPPlatformWindow.

Thanks,

Francisco


Brad Hutchins

unread,
Jul 27, 2009, 3:34:30 PM7/27/09
to objec...@googlegroups.com
Sweet...

Timothy Perrett

unread,
Jul 27, 2009, 7:15:07 PM7/27/09
to Cappuccino & Objective-J
Wow this is freaking awesome... congrats Francisco

Cheers, Tim

Brad Hutchins

unread,
Jul 27, 2009, 7:17:13 PM7/27/09
to objec...@googlegroups.com
Oh any expectations of things breaking in Snow Leopard.  You would not expect it, but just wanted to know if anyone knew something I didn't about Cap and SL?

Chandler Kent

unread,
Jul 28, 2009, 12:51:51 PM7/28/09
to Cappuccino & Objective-J
Does this mean we will lose the look of Cappuccino windows for
Platform Windows?

Ross Boucher

unread,
Jul 28, 2009, 12:54:15 PM7/28/09
to objec...@googlegroups.com
It's not possible, from the browser, to get rid of a window's chrome.
So, yes, in the browser, "platform windows" will have to use the
"platform" chrome, rather than the Cappuccino chrome. This is a small
price to pay, I think, for a supremely cool feature.

Roberto Saccon

unread,
Jul 28, 2009, 1:30:23 PM7/28/09
to Cappuccino & Objective-J
I great use-case for platform windows I can immediately think of is a
fullscreen (well, mostly fullscreen at least) mode, e.g. for
slideshows or any kind of previews.

Jérôme Denanot

unread,
Jul 29, 2009, 9:23:18 AM7/29/09
to objec...@googlegroups.com
That really's great, nice work !

2009/7/28 Roberto Saccon <rsa...@gmail.com>
Reply all
Reply to author
Forward
0 new messages