| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of html; | 5 part of html; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * An object representing the top-level context object for web scripting. | 8 * An object representing the top-level context object for web scripting. |
| 9 * | 9 * |
| 10 * In a web browser, a [Window] object represents the actual browser window. | 10 * In a web browser, a [Window] object represents the actual browser window. |
| 11 * In a multi-tabbed browser, each tab has its own [Window] object. A [Window] | 11 * In a multi-tabbed browser, each tab has its own [Window] object. A [Window] |
| 12 * is the container that displays a [Document]'s content. All web scripting | 12 * is the container that displays a [Document]'s content. All web scripting |
| 13 * happens within the context of a [Window] object. | 13 * happens within the context of a [Window] object. |
| 14 * | 14 * |
| 15 * **Note:** This class represents any window, whereas [LocalWindow] is | 15 * **Note:** This class represents any window, whereas [Window] is |
| 16 * used to access the properties and content of the current window. | 16 * used to access the properties and content of the current window. |
| 17 * | 17 * |
| 18 * See also: | 18 * See also: |
| 19 * | 19 * |
| 20 * * [DOM Window](https://developer.mozilla.org/en-US/docs/DOM/window) from MDN. | 20 * * [DOM Window](https://developer.mozilla.org/en-US/docs/DOM/window) from MDN. |
| 21 * * [Window](http://www.w3.org/TR/Window/) from the W3C. | 21 * * [Window](http://www.w3.org/TR/Window/) from the W3C. |
| 22 */ | 22 */ |
| 23 abstract class Window { | 23 abstract class WindowBase { |
| 24 // Fields. | 24 // Fields. |
| 25 | 25 |
| 26 /** | 26 /** |
| 27 * The current location of this window. | 27 * The current location of this window. |
| 28 * | 28 * |
| 29 * Location currentLocation = window.location; | 29 * Location currentLocation = window.location; |
| 30 * print(currentLocation.href); // 'http://www.example.com:80/' | 30 * print(currentLocation.href); // 'http://www.example.com:80/' |
| 31 */ | 31 */ |
| 32 Location get location; | 32 LocationBase get location; |
| 33 History get history; | 33 HistoryBase get history; |
| 34 | 34 |
| 35 /** | 35 /** |
| 36 * Indicates whether this window has been closed. | 36 * Indicates whether this window has been closed. |
| 37 * | 37 * |
| 38 * print(window.closed); // 'false' | 38 * print(window.closed); // 'false' |
| 39 * window.close(); | 39 * window.close(); |
| 40 * print(window.closed); // 'true' | 40 * print(window.closed); // 'true' |
| 41 */ | 41 */ |
| 42 bool get closed; | 42 bool get closed; |
| 43 | 43 |
| 44 /** | 44 /** |
| 45 * A reference to the window that opened this one. | 45 * A reference to the window that opened this one. |
| 46 * | 46 * |
| 47 * Window thisWindow = window; | 47 * Window thisWindow = window; |
| 48 * Window otherWindow = thisWindow.open('http://www.example.com/', 'foo'); | 48 * WindowBase otherWindow = thisWindow.open('http://www.example.com/', 'fo
o'); |
| 49 * print(otherWindow.opener == thisWindow); // 'true' | 49 * print(otherWindow.opener == thisWindow); // 'true' |
| 50 */ | 50 */ |
| 51 Window get opener; | 51 WindowBase get opener; |
| 52 | 52 |
| 53 /** | 53 /** |
| 54 * A reference to the parent of this window. | 54 * A reference to the parent of this window. |
| 55 * | 55 * |
| 56 * If this [Window] has no parent, [parent] will return a reference to | 56 * If this [WindowBase] has no parent, [parent] will return a reference to |
| 57 * the [Window] itself. | 57 * the [WindowBase] itself. |
| 58 * | 58 * |
| 59 * IFrameElement myIFrame = new IFrameElement(); | 59 * IFrameElement myIFrame = new IFrameElement(); |
| 60 * window.document.body.elements.add(myIFrame); | 60 * window.document.body.elements.add(myIFrame); |
| 61 * print(myIframe.contentWindow.parent == window) // 'true' | 61 * print(myIframe.contentWindow.parent == window) // 'true' |
| 62 * | 62 * |
| 63 * print(window.parent == window) // 'true' | 63 * print(window.parent == window) // 'true' |
| 64 */ | 64 */ |
| 65 Window get parent; | 65 WindowBase get parent; |
| 66 | 66 |
| 67 /** | 67 /** |
| 68 * A reference to the topmost window in the window hierarchy. | 68 * A reference to the topmost window in the window hierarchy. |
| 69 * | 69 * |
| 70 * If this [Window] is the topmost [Window], [top] will return a reference to | 70 * If this [WindowBase] is the topmost [WindowBase], [top] will return a |
| 71 * the [Window] itself. | 71 * reference to the [WindowBase] itself. |
| 72 * | 72 * |
| 73 * // Add an IFrame to the current window. | 73 * // Add an IFrame to the current window. |
| 74 * IFrameElement myIFrame = new IFrameElement(); | 74 * IFrameElement myIFrame = new IFrameElement(); |
| 75 * window.document.body.elements.add(myIFrame); | 75 * window.document.body.elements.add(myIFrame); |
| 76 * | 76 * |
| 77 * // Add an IFrame inside of the other IFrame. | 77 * // Add an IFrame inside of the other IFrame. |
| 78 * IFrameElement innerIFrame = new IFrameElement(); | 78 * IFrameElement innerIFrame = new IFrameElement(); |
| 79 * myIFrame.elements.add(innerIFrame); | 79 * myIFrame.elements.add(innerIFrame); |
| 80 * | 80 * |
| 81 * print(myIframe.contentWindow.top == window) // 'true' | 81 * print(myIframe.contentWindow.top == window) // 'true' |
| 82 * print(innerIFrame.contentWindow.top == window) // 'true' | 82 * print(innerIFrame.contentWindow.top == window) // 'true' |
| 83 * | 83 * |
| 84 * print(window.top == window) // 'true' | 84 * print(window.top == window) // 'true' |
| 85 */ | 85 */ |
| 86 Window get top; | 86 WindowBase get top; |
| 87 | 87 |
| 88 // Methods. | 88 // Methods. |
| 89 /** | 89 /** |
| 90 * Closes the window. | 90 * Closes the window. |
| 91 * | 91 * |
| 92 * This method should only succeed if the [Window] object is | 92 * This method should only succeed if the [WindowBase] object is |
| 93 * **script-closeable** and the window calling [close] is allowed to navigate | 93 * **script-closeable** and the window calling [close] is allowed to navigate |
| 94 * the window. | 94 * the window. |
| 95 * | 95 * |
| 96 * A window is script-closeable if it is either a window | 96 * A window is script-closeable if it is either a window |
| 97 * that was opened by another window, or if it is a window with only one | 97 * that was opened by another window, or if it is a window with only one |
| 98 * document in its history. | 98 * document in its history. |
| 99 * | 99 * |
| 100 * A window might not be allowed to navigate, and therefore close, another | 100 * A window might not be allowed to navigate, and therefore close, another |
| 101 * window due to browser security features. | 101 * window due to browser security features. |
| 102 * | 102 * |
| 103 * var other = window.open('http://www.example.com', 'foo'); | 103 * var other = window.open('http://www.example.com', 'foo'); |
| 104 * // Closes other window, as it is script-closeable. | 104 * // Closes other window, as it is script-closeable. |
| 105 * other.close(); | 105 * other.close(); |
| 106 * print(other.closed()); // 'true' | 106 * print(other.closed()); // 'true' |
| 107 * | 107 * |
| 108 * window.location('http://www.mysite.com', 'foo'); | 108 * window.location('http://www.mysite.com', 'foo'); |
| 109 * // Does not close this window, as the history has changed. | 109 * // Does not close this window, as the history has changed. |
| 110 * window.close(); | 110 * window.close(); |
| 111 * print(window.closed()); // 'false' | 111 * print(window.closed()); // 'false' |
| 112 * | 112 * |
| 113 * See also: | 113 * See also: |
| 114 * | 114 * |
| 115 * * [Window close discussion](http://www.w3.org/TR/html5/browsers.html#dom-wi
ndow-close) from the W3C | 115 * * [Window close discussion](http://www.w3.org/TR/html5/browsers.html#dom-wi
ndow-close) from the W3C |
| 116 */ | 116 */ |
| 117 void close(); | 117 void close(); |
| 118 void postMessage(var message, String targetOrigin, [List messagePorts]); | 118 void postMessage(var message, String targetOrigin, [List messagePorts]); |
| 119 } | 119 } |
| 120 | 120 |
| 121 abstract class Location { | 121 abstract class LocationBase { |
| 122 void set href(String val); | 122 void set href(String val); |
| 123 } | 123 } |
| 124 | 124 |
| 125 abstract class History { | 125 abstract class HistoryBase { |
| 126 void back(); | 126 void back(); |
| 127 void forward(); | 127 void forward(); |
| 128 void go(int distance); | 128 void go(int distance); |
| 129 } | 129 } |
| OLD | NEW |