1 /*******************************************************************************
2 * Copyright (c) 2003, 2009 IBM Corporation and others.
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
9 * SPDX-License-Identifier: EPL-2.0
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.swt.browser;
16 import org.eclipse.swt.events.*;
17 import org.eclipse.swt.graphics.*;
18 import org.eclipse.swt.widgets.*;
21 * A <code>WindowEvent</code> is sent by a {@link Browser} when
22 * a new window needs to be created or when an existing window needs to be
23 * closed. This notification occurs when a javascript command such as
24 * <code>window.open</code> or <code>window.close</code> gets executed by
25 * a <code>Browser</code>.
28 * The following example shows how <code>WindowEvent</code>'s are typically
32 * public static void main(String[] args) {
33 * Display display = new Display();
34 * Shell shell = new Shell(display);
35 * shell.setText("Main Window");
36 * shell.setLayout(new FillLayout());
37 * Browser browser = new Browser(shell, SWT.NONE);
38 * initialize(display, browser);
40 * browser.setUrl("http://www.eclipse.org");
41 * while (!shell.isDisposed()) {
42 * if (!display.readAndDispatch())
48 * static void initialize(final Display display, Browser browser) {
49 * browser.addOpenWindowListener(new OpenWindowListener() {
50 * public void open(WindowEvent event) {
51 * // Certain platforms can provide a default full browser.
52 * // simply return in that case if the application prefers
53 * // the default full browser to the embedded one set below.
54 * if (!event.required) return;
56 * // Embed the new window
57 * Shell shell = new Shell(display);
58 * shell.setText("New Window");
59 * shell.setLayout(new FillLayout());
60 * Browser browser = new Browser(shell, SWT.NONE);
61 * initialize(display, browser);
62 * event.browser = browser;
65 * browser.addVisibilityWindowListener(new VisibilityWindowListener() {
66 * public void hide(WindowEvent event) {
67 * Browser browser = (Browser)event.widget;
68 * Shell shell = browser.getShell();
69 * shell.setVisible(false);
71 * public void show(WindowEvent event) {
72 * Browser browser = (Browser)event.widget;
73 * Shell shell = browser.getShell();
74 * if (event.location != null) shell.setLocation(event.location);
75 * if (event.size != null) {
76 * Point size = event.size;
77 * shell.setSize(shell.computeSize(size.x, size.y));
79 * if (event.addressBar || event.menuBar || event.statusBar || event.toolBar) {
80 * // Create widgets for the address bar, menu bar, status bar and/or tool bar
81 * // leave enough space in the Shell to accommodate a Browser of the size
82 * // given by event.size
87 * browser.addCloseWindowListener(new CloseWindowListener() {
88 * public void close(WindowEvent event) {
89 * Browser browser = (Browser)event.widget;
90 * Shell shell = browser.getShell();
97 * The following notifications are emitted when the user selects a hyperlink that targets a new window
98 * or as the result of a javascript that executes window.open.
100 * <p>Main Browser</p>
102 * <li>User selects a link that opens in a new window or javascript requests a new window</li>
103 * <li>OpenWindowListener.open() notified
105 * <li>Application creates a new Shell and a second Browser inside that Shell</li>
106 * <li>Application registers WindowListener's on that second Browser, such as VisibilityWindowListener</li>
107 * <li>Application returns the second Browser as the host for the new window content</li>
112 * <p>Second Browser</p>
114 * <li>VisibilityWindowListener.show() notified
116 * <li>Application sets navigation tool bar, status bar, menu bar and Shell size
117 * <li>Application makes the Shell hosting the second Browser visible
118 * <li>User now sees the new window
123 * @see CloseWindowListener
124 * @see OpenWindowListener
125 * @see VisibilityWindowListener
126 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
130 public class WindowEvent extends TypedEvent {
133 * Specifies whether the platform requires the user to provide a
134 * <code>Browser</code> to handle the new window.
138 public boolean required;
142 * <code>Browser</code> provided by the application.
144 public Browser browser;
147 * Requested location for the <code>Shell</code> hosting the <code>Browser</code>.
148 * It is <code>null</code> if no location has been requested.
150 public Point location;
153 * Requested <code>Browser</code> size. The client area of the <code>Shell</code>
154 * hosting the <code>Browser</code> should be large enough to accommodate that size.
155 * It is <code>null</code> if no size has been requested.
160 * Specifies whether the <code>Shell</code> hosting the <code>Browser</code> should
161 * display an address bar.
165 public boolean addressBar;
168 * Specifies whether the <code>Shell</code> hosting the <code>Browser</code> should
169 * display a menu bar. Note that this is always <code>true</code> on OS X.
173 public boolean menuBar;
176 * Specifies whether the <code>Shell</code> hosting the <code>Browser</code> should
177 * display a status bar.
181 public boolean statusBar;
184 * Specifies whether the <code>Shell</code> hosting the <code>Browser</code> should
185 * display a tool bar.
189 public boolean toolBar;
191 static final long serialVersionUID = 3617851997387174969L;
194 * Constructs a new instance of this class.
196 * @param widget the widget that fired the event
200 public WindowEvent(Widget widget) {
205 * Returns a string containing a concise, human-readable
206 * description of the receiver.
208 * @return a string representation of the event
211 public String toString() {
212 String string = super.toString ();
213 return string.substring (0, string.length() - 1) // remove trailing '}'
214 + " required=" + required
215 + " browser=" + browser
216 + " location=" + location
218 + " addressBar=" + addressBar
219 + " menuBar=" + menuBar
220 + " statusBar=" + statusBar
221 + " toolBar=" + toolBar