1 /* ************************************************************************
3 qooxdoo - the new era of web development
8 2004-2007 1&1 Internet AG, Germany, http://www.1and1.org
11 LGPL: http://www.gnu.org/licenses/lgpl.html
12 EPL: http://www.eclipse.org/org/documents/epl-v10.php
13 See the LICENSE file in the project's top-level directory for details.
16 * Sebastian Werner (wpbasti)
17 * Andreas Ecker (ecker)
19 ************************************************************************ */
21 /* ************************************************************************
23 #require(qx.html.Window)
25 ************************************************************************ */
27 qx.OO.defineClass("qx.client.NativeWindow", qx.core.Target,
30 qx.core.Target.call(this);
33 // ************************************************************************
35 // ************************************************************************
37 this._timer = new qx.client.Timer(100);
38 this._timer.addEventListener("interval", this._oninterval, this);
41 // ************************************************************************
43 // ************************************************************************
59 ---------------------------------------------------------------------------
61 ---------------------------------------------------------------------------
65 If the window is open or closed
67 qx.OO.addProperty({ name : "open", type : "boolean", defaultValue : false });
70 The outer width of the window.
72 qx.OO.addProperty({ name : "width", type : "number", defaultValue : 400, impl : "dimension" });
75 The outer height of the window.
77 qx.OO.addProperty({ name : "height", type : "number", defaultValue : 250, impl : "dimension" });
80 The left screen coordinate of the window.
82 qx.OO.addProperty({ name : "left", type : "number", defaultValue : 100, impl : "position" });
85 The top screen coordinate of the window.
87 qx.OO.addProperty({ name : "top", type : "number", defaultValue : 200, impl : "position" });
90 Should be window be modal
92 qx.OO.addProperty({ name : "modal", type : "boolean", defaultValue : false });
95 Should be window be dependent on this application window
97 qx.OO.addProperty({ name : "dependent", type : "boolean", defaultValue : true });
102 qx.OO.addProperty({ name : "url", type : "string" });
107 qx.OO.addProperty({ name : "name", type : "string" });
110 The text of the statusbar
112 qx.OO.addProperty({ name : "status", type : "string", defaultValue : "Ready" });
115 Should the statusbar be shown
117 qx.OO.addProperty({ name : "showStatusbar", type : "boolean", defaultValue : false });
120 Should the menubar be shown
122 qx.OO.addProperty({ name : "showMenubar", type : "boolean", defaultValue : false });
125 Should the location(bar) be shown
127 qx.OO.addProperty({ name : "showLocation", type : "boolean", defaultValue : false });
130 Should the toolbar be shown
132 qx.OO.addProperty({ name : "showToolbar", type : "boolean", defaultValue : false });
135 If the window is resizeable
137 qx.OO.addProperty({ name : "resizeable", type : "boolean", defaultValue : true });
140 If the window is able to scroll and has visible scrollbars if needed
142 qx.OO.addProperty({ name : "allowScrollbars", type : "boolean", defaultValue : true });
147 ---------------------------------------------------------------------------
149 ---------------------------------------------------------------------------
152 qx.Proto._loaded = false;
158 ---------------------------------------------------------------------------
160 ---------------------------------------------------------------------------
163 qx.OO.addPropertyGroup({ name : "location", members : [ "left", "top" ]});
164 qx.OO.addPropertyGroup({ name : "dimension", members : [ "width", "height" ]});
170 ---------------------------------------------------------------------------
172 ---------------------------------------------------------------------------
175 qx.Proto._modifyPosition = function(propValue, propOldValue, propName)
178 http://www.microsoft.com/technet/prodtechnol/winxppro/maintain/sp2brows.mspx
179 Changes to Functionality in Microsoft Windows XP Service Pack 2
180 Part 5: Enhanced Browsing Security
181 URLACTION_FEATURE_WINDOW_RESTRICTIONS
182 Allow script-initiated windows without size or position constraints
186 if (!this.isClosed())
190 this._window.moveTo(this.getLeft(), this.getTop());
194 this.error("Cross-Domain Scripting problem: Could not move window!", ex);
201 qx.Proto._modifyDimension = function(propValue, propOldValue, propName)
204 http://www.microsoft.com/technet/prodtechnol/winxppro/maintain/sp2brows.mspx
205 Changes to Functionality in Microsoft Windows XP Service Pack 2
206 Part 5: Enhanced Browsing Security
207 URLACTION_FEATURE_WINDOW_RESTRICTIONS
208 Allow script-initiated windows without size or position constraints
212 if (!this.isClosed())
216 this._window.resizeTo(this.getWidth(), this.getHeight());
220 this.error("Cross-Domain Scripting problem: Could not resize window!", ex);
227 qx.Proto._modifyName = function(propValue, propOldValue, propName)
229 if (!this.isClosed()) {
230 this._window.name = propValue;
236 qx.Proto._modifyUrl = function(propValue, propOldValue, propName)
238 // String hack needed for old compressor (compile.py)
239 if(!this.isClosed()) {
240 this._window.location.replace(propValue != null ? propValue : ("javascript:/" + "/"));
246 qx.Proto._modifyOpen = function(propValue, propOldValue, propData)
248 propValue ? this._open() : this._close();
258 ---------------------------------------------------------------------------
260 ---------------------------------------------------------------------------
263 qx.Proto.getName = function()
265 if (!this.isClosed())
269 var vName = this._window.name;
273 return this._valueName;
276 if (vName == this._valueName)
282 throw new Error("window name and name property are not identical");
287 return this._valueName;
297 ---------------------------------------------------------------------------
299 ---------------------------------------------------------------------------
302 qx.Proto.isClosed = function()
309 vClosed = this._window.closed;
316 qx.Proto.open = function() {
320 qx.Proto.close = function() {
324 qx.Proto.isLoaded = function() {
335 ---------------------------------------------------------------------------
337 ---------------------------------------------------------------------------
340 qx.Proto._open = function()
346 ------------------------------------------------------------------------------
348 ------------------------------------------------------------------------------
351 if (this.getWidth() != null)
355 vConf.push(this.getWidth());
359 if (this.getHeight() != null)
361 vConf.push("height");
363 vConf.push(this.getHeight());
367 if (this.getLeft() != null)
371 vConf.push(this.getLeft());
375 if (this.getTop() != null)
379 vConf.push(this.getTop());
385 vConf.push("dependent");
387 vConf.push(this.getDependent() ? "yes" : "no");
390 vConf.push("resizable");
392 vConf.push(this.getResizeable() ? "yes" : "no");
395 vConf.push("status");
397 vConf.push(this.getShowStatusbar() ? "yes" : "no");
400 vConf.push("location");
402 vConf.push(this.getShowLocation() ? "yes" : "no");
405 vConf.push("menubar");
407 vConf.push(this.getShowMenubar() ? "yes" : "no");
410 vConf.push("toolbar");
412 vConf.push(this.getShowToolbar() ? "yes" : "no");
415 vConf.push("scrollbars");
417 vConf.push(this.getAllowScrollbars() ? "yes" : "no");
422 vConf.push(this.getModal() ? "yes" : "no");
431 ------------------------------------------------------------------------------
433 ------------------------------------------------------------------------------
436 if (this.getName() != null) {
437 this.setName("qx_NativeWindow" + this.toHashCode());
440 this._window = window.open(this.getUrl(), this.getName(), vConf.join(""));
444 this.error("Window could not be opened. It seems, there is a popup blocker active!");
448 // This try-catch is needed because of cross domain issues (access rights)
451 this._window._native = this;
452 this._window.onload = this._onload;
456 // start timer for close detection
459 // block original document
460 if (this.getModal()) {
461 qx.ui.core.ClientDocument.getInstance().block(this);
466 qx.Proto._close = function()
472 // stop timer for close detection
475 // release window again
476 if (this.getModal()){
477 qx.ui.core.ClientDocument.getInstance().release(this);
480 // finally close window
481 if (!this.isClosed()) {
482 this._window.close();
487 this._window._native = null;
488 this._window.onload = null;
493 this._loaded = false;
495 this.createDispatchEvent("close");
504 ---------------------------------------------------------------------------
506 ---------------------------------------------------------------------------
509 qx.Proto.centerToScreen = function() {
510 return this._centerHelper((screen.width - this.getWidth()) / 2, (screen.height - this.getHeight()) / 2);
513 qx.Proto.centerToScreenArea = function() {
514 return this._centerHelper((screen.availWidth - this.getWidth()) / 2, (screen.availHeight - this.getHeight()) / 2);
517 qx.Proto.centerToOpener = function() {
518 return this._centerHelper(((qx.html.Window.getInnerWidth(window) - this.getWidth()) / 2) + qx.html.Location.getScreenBoxLeft(window.document.body), ((qx.html.Window.getInnerHeight(window) - this.getHeight()) / 2) + qx.html.Location.getScreenBoxTop(window.document.body));
521 qx.Proto._centerHelper = function(l, t)
527 // focus window if opened
528 if (!this.isClosed()) {
539 ---------------------------------------------------------------------------
541 ---------------------------------------------------------------------------
544 qx.Proto.focus = function()
546 if (!this.isClosed()) {
547 this._window.focus();
551 qx.Proto.blur = function()
553 if (!this.isClosed()) {
565 ---------------------------------------------------------------------------
567 ---------------------------------------------------------------------------
570 qx.Proto._oninterval = function(e)
572 if (this.isClosed()) {
575 else if (!this._loaded)
577 // This try-catch is needed because of cross domain issues (access rights)
580 if (this._window.document && this._window.document.readyState == "complete")
583 this.createDispatchEvent("load");
590 qx.Proto._onload = function(e)
592 var obj = this._native;
597 obj.createDispatchEvent("load");
607 ---------------------------------------------------------------------------
609 ---------------------------------------------------------------------------
612 qx.Proto.dispose = function()
614 if (this.getDisposed()) {
618 if (this.getDependent()) {
632 this._window._native = null;
633 this._window.onload = null;
640 return qx.core.Target.prototype.dispose.call(this);