|
Removed
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2006, 2010 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.pde.internal.ui.editor.contentassist.display; |
| 12 |
|
| 13 |
import java.io.IOException; |
| 14 |
import java.io.StringReader; |
| 15 |
import java.util.Iterator; |
| 16 |
import org.eclipse.core.runtime.ListenerList; |
| 17 |
import org.eclipse.jface.text.*; |
| 18 |
import org.eclipse.pde.internal.ui.PDEPlugin; |
| 19 |
import org.eclipse.pde.internal.ui.editor.text.HTMLPrinter; |
| 20 |
import org.eclipse.swt.SWT; |
| 21 |
import org.eclipse.swt.SWTError; |
| 22 |
import org.eclipse.swt.browser.*; |
| 23 |
import org.eclipse.swt.custom.StyleRange; |
| 24 |
import org.eclipse.swt.events.*; |
| 25 |
import org.eclipse.swt.graphics.*; |
| 26 |
import org.eclipse.swt.layout.GridData; |
| 27 |
import org.eclipse.swt.layout.GridLayout; |
| 28 |
import org.eclipse.swt.widgets.*; |
| 29 |
|
| 30 |
/** |
| 31 |
* Displays textual information in a {@link org.eclipse.swt.browser.Browser} |
| 32 |
* widget. |
| 33 |
* |
| 34 |
* <p> |
| 35 |
* This class may be instantiated; it is not intended to be subclassed. |
| 36 |
* </p> |
| 37 |
* <p> |
| 38 |
* Current problems: |
| 39 |
* - the size computation is too small |
| 40 |
* - focusLost event is not sent (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=84532) |
| 41 |
* </p> |
| 42 |
* |
| 43 |
* @since 3.1 |
| 44 |
*/ |
| 45 |
public class BrowserInformationControl implements IInformationControl, IInformationControlExtension, IInformationControlExtension3, DisposeListener { |
| 46 |
|
| 47 |
/** |
| 48 |
* Tells whether the SWT Browser widget and hence this information |
| 49 |
* control is available. |
| 50 |
* |
| 51 |
* @param parent the parent component used for checking or <code>null</code> if none |
| 52 |
* @return <code>true</code> if this control is available |
| 53 |
*/ |
| 54 |
public static boolean isAvailable(Composite parent) { |
| 55 |
if (!fgAvailabilityChecked) { |
| 56 |
try { |
| 57 |
if (parent == null) |
| 58 |
parent = PDEPlugin.getActiveWorkbenchShell(); |
| 59 |
if (parent == null) |
| 60 |
return false; // don't store this value - try again later |
| 61 |
|
| 62 |
Browser browser = new Browser(parent, SWT.NONE); |
| 63 |
browser.dispose(); |
| 64 |
fgIsAvailable = true; |
| 65 |
} catch (SWTError er) { |
| 66 |
fgIsAvailable = false; |
| 67 |
} finally { |
| 68 |
fgAvailabilityChecked = true; |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
return fgIsAvailable; |
| 73 |
} |
| 74 |
|
| 75 |
/** Border thickness in pixels. */ |
| 76 |
private static final int BORDER = 1; |
| 77 |
|
| 78 |
/** |
| 79 |
* Minimal size constraints. |
| 80 |
* @since 3.2 |
| 81 |
*/ |
| 82 |
private static final int MIN_WIDTH = 80; |
| 83 |
private static final int MIN_HEIGHT = 80; |
| 84 |
|
| 85 |
/** |
| 86 |
* Availability checking cache. |
| 87 |
*/ |
| 88 |
private static boolean fgIsAvailable = false; |
| 89 |
private static boolean fgAvailabilityChecked = false; |
| 90 |
|
| 91 |
/** The control's shell */ |
| 92 |
private Shell fShell; |
| 93 |
/** The control's browser widget */ |
| 94 |
private Browser fBrowser; |
| 95 |
/** Tells whether the browser has content */ |
| 96 |
private boolean fBrowserHasContent; |
| 97 |
/** The control width constraint */ |
| 98 |
private int fMaxWidth = -1; |
| 99 |
/** The control height constraint */ |
| 100 |
private int fMaxHeight = -1; |
| 101 |
private Font fStatusTextFont; |
| 102 |
private Label fStatusTextField; |
| 103 |
private String fStatusFieldText; |
| 104 |
private boolean fHideScrollBars; |
| 105 |
private Listener fDeactivateListener; |
| 106 |
private ListenerList fFocusListeners = new ListenerList(); |
| 107 |
private Label fSeparator; |
| 108 |
private String fInputText; |
| 109 |
private TextLayout fTextLayout; |
| 110 |
|
| 111 |
private TextStyle fBoldStyle; |
| 112 |
|
| 113 |
/** |
| 114 |
* Creates a default information control with the given shell as parent. The given |
| 115 |
* information presenter is used to process the information to be displayed. The given |
| 116 |
* styles are applied to the created styled text widget. |
| 117 |
* |
| 118 |
* @param parent the parent shell |
| 119 |
* @param shellStyle the additional styles for the shell |
| 120 |
* @param style the additional styles for the styled text widget |
| 121 |
*/ |
| 122 |
public BrowserInformationControl(Shell parent, int shellStyle, int style) { |
| 123 |
this(parent, shellStyle, style, null); |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* Creates a default information control with the given shell as parent. The given |
| 128 |
* information presenter is used to process the information to be displayed. The given |
| 129 |
* styles are applied to the created styled text widget. |
| 130 |
* |
| 131 |
* @param parent the parent shell |
| 132 |
* @param shellStyle the additional styles for the shell |
| 133 |
* @param style the additional styles for the styled text widget |
| 134 |
* @param statusFieldText the text to be used in the optional status field |
| 135 |
* or <code>null</code> if the status field should be hidden |
| 136 |
*/ |
| 137 |
public BrowserInformationControl(Shell parent, int shellStyle, int style, String statusFieldText) { |
| 138 |
fStatusFieldText = statusFieldText; |
| 139 |
|
| 140 |
fShell = new Shell(parent, SWT.NO_FOCUS | SWT.ON_TOP | shellStyle); |
| 141 |
Display display = fShell.getDisplay(); |
| 142 |
fShell.setBackground(display.getSystemColor(SWT.COLOR_BLACK)); |
| 143 |
|
| 144 |
Composite composite = fShell; |
| 145 |
GridLayout layout = new GridLayout(1, false); |
| 146 |
int border = ((shellStyle & SWT.NO_TRIM) == 0) ? 0 : BORDER; |
| 147 |
layout.marginHeight = border; |
| 148 |
layout.marginWidth = border; |
| 149 |
composite.setLayout(layout); |
| 150 |
|
| 151 |
if (statusFieldText != null) { |
| 152 |
composite = new Composite(composite, SWT.NONE); |
| 153 |
layout = new GridLayout(1, false); |
| 154 |
layout.marginHeight = 0; |
| 155 |
layout.marginWidth = 0; |
| 156 |
layout.verticalSpacing = 1; |
| 157 |
layout.horizontalSpacing = 1; |
| 158 |
composite.setLayout(layout); |
| 159 |
|
| 160 |
GridData gd = new GridData(GridData.FILL_BOTH); |
| 161 |
composite.setLayoutData(gd); |
| 162 |
|
| 163 |
composite.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); |
| 164 |
composite.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); |
| 165 |
} |
| 166 |
|
| 167 |
// Browser field |
| 168 |
fBrowser = new Browser(composite, SWT.NONE); |
| 169 |
|
| 170 |
// Disable javascript for security reasons, see bug 265808 |
| 171 |
fBrowser.setJavascriptEnabled(false); |
| 172 |
|
| 173 |
fHideScrollBars = (style & SWT.V_SCROLL) == 0 && (style & SWT.H_SCROLL) == 0; |
| 174 |
|
| 175 |
GridData gd = new GridData(GridData.BEGINNING | GridData.FILL_BOTH); |
| 176 |
fBrowser.setLayoutData(gd); |
| 177 |
|
| 178 |
fBrowser.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); |
| 179 |
fBrowser.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); |
| 180 |
|
| 181 |
/* |
| 182 |
* XXX revisit when the Browser support is better |
| 183 |
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=107629. Choosing a link to a |
| 184 |
* non-available target will show an error dialog behind the ON_TOP shell that seemingly |
| 185 |
* blocks the workbench. Disable links completely for now. |
| 186 |
*/ |
| 187 |
fBrowser.addLocationListener(new LocationAdapter() { |
| 188 |
/* |
| 189 |
* @see org.eclipse.swt.browser.LocationAdapter#changing(org.eclipse.swt.browser.LocationEvent) |
| 190 |
*/ |
| 191 |
public void changing(LocationEvent event) { |
| 192 |
String location = event.location; |
| 193 |
if (!"about:blank".equals(location)) //$NON-NLS-1$ |
| 194 |
event.doit = false; |
| 195 |
} |
| 196 |
}); |
| 197 |
|
| 198 |
// Replace browser's built-in context menu with none |
| 199 |
fBrowser.setMenu(new Menu(fShell, SWT.NONE)); |
| 200 |
|
| 201 |
// Status field |
| 202 |
if (statusFieldText != null) { |
| 203 |
|
| 204 |
fSeparator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.LINE_DOT); |
| 205 |
fSeparator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 206 |
|
| 207 |
// Status field label |
| 208 |
fStatusTextField = new Label(composite, SWT.RIGHT); |
| 209 |
fStatusTextField.setText(statusFieldText); |
| 210 |
Font font = fStatusTextField.getFont(); |
| 211 |
FontData[] fontDatas = font.getFontData(); |
| 212 |
for (int i = 0; i < fontDatas.length; i++) |
| 213 |
fontDatas[i].setHeight(fontDatas[i].getHeight() * 9 / 10); |
| 214 |
fStatusTextFont = new Font(fStatusTextField.getDisplay(), fontDatas); |
| 215 |
fStatusTextField.setFont(fStatusTextFont); |
| 216 |
gd = new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING); |
| 217 |
fStatusTextField.setLayoutData(gd); |
| 218 |
|
| 219 |
fStatusTextField.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW)); |
| 220 |
|
| 221 |
fStatusTextField.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); |
| 222 |
} |
| 223 |
|
| 224 |
addDisposeListener(this); |
| 225 |
createTextLayout(); |
| 226 |
} |
| 227 |
|
| 228 |
/** |
| 229 |
* Creates a default information control with the given shell as parent. The given |
| 230 |
* information presenter is used to process the information to be displayed. The given |
| 231 |
* styles are applied to the created styled text widget. |
| 232 |
* |
| 233 |
* @param parent the parent shell |
| 234 |
* @param style the additional styles for the browser widget |
| 235 |
*/ |
| 236 |
public BrowserInformationControl(Shell parent, int style) { |
| 237 |
this(parent, SWT.TOOL | SWT.NO_TRIM, style); |
| 238 |
} |
| 239 |
|
| 240 |
/** |
| 241 |
* Creates a default information control with the given shell as parent. |
| 242 |
* No information presenter is used to process the information |
| 243 |
* to be displayed. No additional styles are applied to the styled text widget. |
| 244 |
* |
| 245 |
* @param parent the parent shell |
| 246 |
*/ |
| 247 |
public BrowserInformationControl(Shell parent) { |
| 248 |
this(parent, SWT.NONE); |
| 249 |
} |
| 250 |
|
| 251 |
/* |
| 252 |
* @see IInformationControl#setInformation(String) |
| 253 |
*/ |
| 254 |
public void setInformation(String content) { |
| 255 |
fBrowserHasContent = content != null && content.length() > 0; |
| 256 |
|
| 257 |
if (!fBrowserHasContent) |
| 258 |
content = "<html><body ></html>"; //$NON-NLS-1$ |
| 259 |
|
| 260 |
fInputText = content; |
| 261 |
|
| 262 |
int shellStyle = fShell.getStyle(); |
| 263 |
boolean RTL = (shellStyle & SWT.RIGHT_TO_LEFT) != 0; |
| 264 |
|
| 265 |
String[] styles = null; |
| 266 |
if (RTL && !fHideScrollBars) |
| 267 |
styles = new String[] {"direction:rtl;", "word-wrap:break-word;"}; //$NON-NLS-1$ //$NON-NLS-2$ |
| 268 |
else if (RTL && fHideScrollBars) |
| 269 |
styles = new String[] {"direction:rtl;", "overflow:hidden;", "word-wrap:break-word;"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 270 |
else if (fHideScrollBars && true) |
| 271 |
styles = new String[] {"overflow:hidden;", "word-wrap: break-word;"}; //$NON-NLS-1$ //$NON-NLS-2$ |
| 272 |
|
| 273 |
if (styles != null) { |
| 274 |
StringBuffer buffer = new StringBuffer(content); |
| 275 |
HTMLPrinter.insertStyles(buffer, styles); |
| 276 |
content = buffer.toString(); |
| 277 |
} |
| 278 |
|
| 279 |
fBrowser.setText(content); |
| 280 |
|
| 281 |
} |
| 282 |
|
| 283 |
/* |
| 284 |
* @see org.eclipse.jdt.internal.ui.text.IInformationControlExtension4#setStatusText(java.lang.String) |
| 285 |
* @since 3.2 |
| 286 |
*/ |
| 287 |
public void setStatusText(String statusFieldText) { |
| 288 |
fStatusFieldText = statusFieldText; |
| 289 |
} |
| 290 |
|
| 291 |
/* |
| 292 |
* @see IInformationControl#setVisible(boolean) |
| 293 |
*/ |
| 294 |
public void setVisible(boolean visible) { |
| 295 |
if (fShell.isVisible() == visible) |
| 296 |
return; |
| 297 |
|
| 298 |
if (visible) { |
| 299 |
if (fStatusTextField != null) { |
| 300 |
boolean state = fStatusFieldText != null; |
| 301 |
if (state) |
| 302 |
fStatusTextField.setText(fStatusFieldText); |
| 303 |
fStatusTextField.setVisible(state); |
| 304 |
fSeparator.setVisible(state); |
| 305 |
} |
| 306 |
} |
| 307 |
|
| 308 |
fShell.setVisible(visible); |
| 309 |
if (!visible) |
| 310 |
setInformation(""); //$NON-NLS-1$ |
| 311 |
} |
| 312 |
|
| 313 |
/** |
| 314 |
* Creates and initializes the text layout used |
| 315 |
* to compute the size hint. |
| 316 |
* |
| 317 |
* @since 3.2 |
| 318 |
*/ |
| 319 |
private void createTextLayout() { |
| 320 |
fTextLayout = new TextLayout(fBrowser.getDisplay()); |
| 321 |
|
| 322 |
// Initialize fonts |
| 323 |
Font font = fBrowser.getFont(); |
| 324 |
fTextLayout.setFont(font); |
| 325 |
fTextLayout.setWidth(-1); |
| 326 |
FontData[] fontData = font.getFontData(); |
| 327 |
for (int i = 0; i < fontData.length; i++) |
| 328 |
fontData[i].setStyle(SWT.BOLD); |
| 329 |
font = new Font(fShell.getDisplay(), fontData); |
| 330 |
fBoldStyle = new TextStyle(font, null, null); |
| 331 |
|
| 332 |
// Compute and set tab width |
| 333 |
fTextLayout.setText(" "); //$NON-NLS-1$ |
| 334 |
int tabWidth = fTextLayout.getBounds().width; |
| 335 |
fTextLayout.setTabs(new int[] {tabWidth}); |
| 336 |
|
| 337 |
fTextLayout.setText(""); //$NON-NLS-1$ |
| 338 |
} |
| 339 |
|
| 340 |
/* |
| 341 |
* @see IInformationControl#dispose() |
| 342 |
*/ |
| 343 |
public void dispose() { |
| 344 |
if (fTextLayout != null) { |
| 345 |
fTextLayout.dispose(); |
| 346 |
fTextLayout = null; |
| 347 |
} |
| 348 |
fBoldStyle.font.dispose(); |
| 349 |
fBoldStyle = null; |
| 350 |
if (fShell != null && !fShell.isDisposed()) |
| 351 |
fShell.dispose(); |
| 352 |
else |
| 353 |
widgetDisposed(null); |
| 354 |
} |
| 355 |
|
| 356 |
/* |
| 357 |
* @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent) |
| 358 |
*/ |
| 359 |
public void widgetDisposed(DisposeEvent event) { |
| 360 |
if (fTextLayout != null) { |
| 361 |
fTextLayout.dispose(); |
| 362 |
fTextLayout = null; |
| 363 |
} |
| 364 |
|
| 365 |
if (fStatusTextFont != null && !fStatusTextFont.isDisposed()) |
| 366 |
fStatusTextFont.dispose(); |
| 367 |
|
| 368 |
fShell = null; |
| 369 |
fBrowser = null; |
| 370 |
fStatusTextFont = null; |
| 371 |
} |
| 372 |
|
| 373 |
/* |
| 374 |
* @see IInformationControl#setSize(int, int) |
| 375 |
*/ |
| 376 |
public void setSize(int width, int height) { |
| 377 |
fShell.setSize(Math.min(width, fMaxWidth), Math.min(height, fMaxHeight)); |
| 378 |
} |
| 379 |
|
| 380 |
/* |
| 381 |
* @see IInformationControl#setLocation(Point) |
| 382 |
*/ |
| 383 |
public void setLocation(Point location) { |
| 384 |
fShell.setLocation(location); |
| 385 |
} |
| 386 |
|
| 387 |
/* |
| 388 |
* @see IInformationControl#setSizeConstraints(int, int) |
| 389 |
*/ |
| 390 |
public void setSizeConstraints(int maxWidth, int maxHeight) { |
| 391 |
fMaxWidth = maxWidth; |
| 392 |
fMaxHeight = maxHeight; |
| 393 |
} |
| 394 |
|
| 395 |
/* |
| 396 |
* @see IInformationControl#computeSizeHint() |
| 397 |
*/ |
| 398 |
public Point computeSizeHint() { |
| 399 |
TextPresentation presentation = new TextPresentation(); |
| 400 |
HTML2TextReader reader = new HTML2TextReader(new StringReader(fInputText), presentation); |
| 401 |
String text; |
| 402 |
try { |
| 403 |
text = reader.getString(); |
| 404 |
} catch (IOException e) { |
| 405 |
text = ""; //$NON-NLS-1$ |
| 406 |
} |
| 407 |
|
| 408 |
fTextLayout.setText(text); |
| 409 |
Iterator iter = presentation.getAllStyleRangeIterator(); |
| 410 |
while (iter.hasNext()) { |
| 411 |
StyleRange sr = (StyleRange) iter.next(); |
| 412 |
if (sr.fontStyle == SWT.BOLD) |
| 413 |
fTextLayout.setStyle(fBoldStyle, sr.start, sr.start + sr.length - 1); |
| 414 |
} |
| 415 |
Rectangle bounds = fTextLayout.getBounds(); |
| 416 |
int width = bounds.width; |
| 417 |
int height = bounds.height; |
| 418 |
|
| 419 |
width += 15; |
| 420 |
height += 25; |
| 421 |
|
| 422 |
if (fStatusFieldText != null && fSeparator != null) { |
| 423 |
fTextLayout.setText(fStatusFieldText); |
| 424 |
Rectangle statusBounds = fTextLayout.getBounds(); |
| 425 |
Rectangle separatorBounds = fSeparator.getBounds(); |
| 426 |
width = Math.max(width, statusBounds.width); |
| 427 |
height = height + statusBounds.height + separatorBounds.height; |
| 428 |
} |
| 429 |
|
| 430 |
// Apply size constraints |
| 431 |
if (fMaxWidth != SWT.DEFAULT) |
| 432 |
width = Math.min(fMaxWidth, width); |
| 433 |
if (fMaxHeight != SWT.DEFAULT) |
| 434 |
height = Math.min(fMaxHeight, height); |
| 435 |
|
| 436 |
// Ensure minimal size |
| 437 |
width = Math.max(MIN_WIDTH, width); |
| 438 |
height = Math.max(MIN_HEIGHT, height); |
| 439 |
|
| 440 |
return new Point(width, height); |
| 441 |
} |
| 442 |
|
| 443 |
/* |
| 444 |
* @see org.eclipse.jface.text.IInformationControlExtension3#computeTrim() |
| 445 |
*/ |
| 446 |
public Rectangle computeTrim() { |
| 447 |
return fShell.computeTrim(0, 0, 0, 0); |
| 448 |
} |
| 449 |
|
| 450 |
/* |
| 451 |
* @see org.eclipse.jface.text.IInformationControlExtension3#getBounds() |
| 452 |
*/ |
| 453 |
public Rectangle getBounds() { |
| 454 |
return fShell.getBounds(); |
| 455 |
} |
| 456 |
|
| 457 |
/* |
| 458 |
* @see org.eclipse.jface.text.IInformationControlExtension3#restoresLocation() |
| 459 |
*/ |
| 460 |
public boolean restoresLocation() { |
| 461 |
return false; |
| 462 |
} |
| 463 |
|
| 464 |
/* |
| 465 |
* @see org.eclipse.jface.text.IInformationControlExtension3#restoresSize() |
| 466 |
*/ |
| 467 |
public boolean restoresSize() { |
| 468 |
return false; |
| 469 |
} |
| 470 |
|
| 471 |
/* |
| 472 |
* @see IInformationControl#addDisposeListener(DisposeListener) |
| 473 |
*/ |
| 474 |
public void addDisposeListener(DisposeListener listener) { |
| 475 |
fShell.addDisposeListener(listener); |
| 476 |
} |
| 477 |
|
| 478 |
/* |
| 479 |
* @see IInformationControl#removeDisposeListener(DisposeListener) |
| 480 |
*/ |
| 481 |
public void removeDisposeListener(DisposeListener listener) { |
| 482 |
fShell.removeDisposeListener(listener); |
| 483 |
} |
| 484 |
|
| 485 |
/* |
| 486 |
* @see IInformationControl#setForegroundColor(Color) |
| 487 |
*/ |
| 488 |
public void setForegroundColor(Color foreground) { |
| 489 |
fBrowser.setForeground(foreground); |
| 490 |
} |
| 491 |
|
| 492 |
/* |
| 493 |
* @see IInformationControl#setBackgroundColor(Color) |
| 494 |
*/ |
| 495 |
public void setBackgroundColor(Color background) { |
| 496 |
fBrowser.setBackground(background); |
| 497 |
} |
| 498 |
|
| 499 |
/* |
| 500 |
* @see IInformationControl#isFocusControl() |
| 501 |
*/ |
| 502 |
public boolean isFocusControl() { |
| 503 |
return fBrowser.isFocusControl(); |
| 504 |
} |
| 505 |
|
| 506 |
/* |
| 507 |
* @see IInformationControl#setFocus() |
| 508 |
*/ |
| 509 |
public void setFocus() { |
| 510 |
fShell.forceFocus(); |
| 511 |
fBrowser.setFocus(); |
| 512 |
} |
| 513 |
|
| 514 |
/* |
| 515 |
* @see IInformationControl#addFocusListener(FocusListener) |
| 516 |
*/ |
| 517 |
public void addFocusListener(final FocusListener listener) { |
| 518 |
fBrowser.addFocusListener(listener); |
| 519 |
|
| 520 |
/* |
| 521 |
* FIXME: This is a workaround for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=84532 |
| 522 |
* (Browser widget does not send focusLost event) |
| 523 |
*/ |
| 524 |
if (fFocusListeners.isEmpty()) { |
| 525 |
fDeactivateListener = new Listener() { |
| 526 |
public void handleEvent(Event event) { |
| 527 |
Object[] listeners = fFocusListeners.getListeners(); |
| 528 |
for (int i = 0; i < listeners.length; i++) |
| 529 |
((FocusListener) listeners[i]).focusLost(new FocusEvent(event)); |
| 530 |
} |
| 531 |
}; |
| 532 |
fBrowser.getShell().addListener(SWT.Deactivate, fDeactivateListener); |
| 533 |
} |
| 534 |
fFocusListeners.add(listener); |
| 535 |
} |
| 536 |
|
| 537 |
/* |
| 538 |
* @see IInformationControl#removeFocusListener(FocusListener) |
| 539 |
*/ |
| 540 |
public void removeFocusListener(FocusListener listener) { |
| 541 |
fBrowser.removeFocusListener(listener); |
| 542 |
|
| 543 |
/* |
| 544 |
* FIXME: This is a workaround for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=84532 |
| 545 |
* (Browser widget does not send focusLost event) |
| 546 |
*/ |
| 547 |
fFocusListeners.remove(listener); |
| 548 |
if (fFocusListeners.isEmpty()) { |
| 549 |
fBrowser.getShell().removeListener(SWT.Deactivate, fDeactivateListener); |
| 550 |
fDeactivateListener = null; |
| 551 |
} |
| 552 |
} |
| 553 |
|
| 554 |
/* |
| 555 |
* @see IInformationControlExtension#hasContents() |
| 556 |
*/ |
| 557 |
public boolean hasContents() { |
| 558 |
return fBrowserHasContent; |
| 559 |
} |
| 560 |
} |