public class WindowsWebView extends AbstractWebView
WebView
implementation for Windows. This implementation uses the Window's native web browser control and the
MSHTML library to render a web page and create an OpenGL texture from the web browser window.
Modifier and Type | Class and Description |
---|---|
protected class |
WindowsWebView.WindowsWebViewTexture |
Modifier and Type | Field and Description |
---|---|
protected java.awt.Color |
backgroundColor |
protected boolean |
disposed
Flag to the indicate that the WebView has been disposed.
|
protected static java.util.concurrent.atomic.AtomicInteger |
instances
Count of the number of active (non-disposed) WebView instances.
|
protected long |
observerPtr
The address of the native NotificationAdapter object.
|
protected static long |
webViewMessageLoop
Identifier for the message loop in native code.
|
protected static java.lang.Thread |
webViewUI
Thread to run web view message loop.
|
protected static java.lang.Object |
webViewUILock
Lock to protect creation of the web view message loop thread.
|
protected long |
webViewWindowPtr
The address of the native WindowsWebView object.
|
active, frameSize, textureRep
Constructor and Description |
---|
WindowsWebView(java.awt.Dimension frameSize)
Create a new WebView.
|
Modifier and Type | Method and Description |
---|---|
protected java.awt.event.MouseEvent |
convertToWindows(java.awt.event.MouseEvent e)
Converts the specified mouse event's screen point from WebView coordinates to Windows coordinates, and returns a
new event who's screen point is in Windows coordinates, with the origin at the upper left corner of the WebView
window.
|
protected WWTexture |
createTextureRepresentation(DrawContext dc)
Create a texture representation of the WebView.
|
void |
dispose()
Disposes of any internal resources allocated by the object.
|
protected void |
doSetFrameSize(java.awt.Dimension size) |
protected void |
ensureMessageLoopRunning()
Ensure that the message loop thread is running.
|
java.awt.Color |
getBackgroundColor()
Indicates the current WebView background color.
|
java.awt.Dimension |
getContentSize()
Returns the size in pixels of this WebView's current content.
|
java.net.URL |
getContentURL()
Returns the URL of this WebView's current content, or
null if the current content is the HTML string
specified by setHTMLString . |
java.lang.Iterable<AVList> |
getLinks()
Returns an iterable of
AVList elements describing this WebView's visible links. |
java.awt.Dimension |
getMinContentSize()
Returns the minimum size in pixels of this WebView's content area.
|
void |
goBack()
Navigate the WebView to the previous page in the browsing history.
|
void |
goForward()
Navigate the WebView to the next page in the browsing history.
|
protected void |
handleWebViewCreationError()
This method is called by the constructor if an exception is thrown creating the WebView.
|
void |
sendEvent(java.awt.event.InputEvent event)
Sends the specified input event to the WebView.
|
void |
setActive(boolean active)
Called when this WebView is activated or deactivated.
|
void |
setBackgroundColor(java.awt.Color color)
Specifies a background color for the WebView.
|
void |
setHTMLString(java.lang.String htmlString)
Specifies this
WebView's HTML content as a string. |
void |
setHTMLString(java.lang.String htmlString,
java.net.URL baseURL)
Specifies this
WebView's HTML content as a string. |
void |
setHTMLString(java.lang.String htmlString,
WebResourceResolver resourceResolver)
Specifies this
WebView's HTML content as a string. |
void |
setMinContentSize(java.awt.Dimension size)
Specifies the minimum size in pixels of this WebView content area.
|
protected void |
stopMessageLoopIfNoInstances()
Terminate the message loop thread if there are no active (non-disposed) WebView instances.
|
finalize, getFrameSize, getTextureRepresentation, isActive, propertyChange, setFrameSize
onMessage
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getBooleanValue, getBooleanValue, getChangeSupport, getDoubleValue, getDoubleValue, getEntries, getIntegerValue, getIntegerValue, getLongValue, getLongValue, getRestorableStateForAVPair, getStringValue, getStringValue, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getEntries, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
protected java.awt.Color backgroundColor
protected boolean disposed
protected static java.util.concurrent.atomic.AtomicInteger instances
protected long observerPtr
protected static long webViewMessageLoop
protected static java.lang.Thread webViewUI
protected static final java.lang.Object webViewUILock
protected long webViewWindowPtr
public WindowsWebView(java.awt.Dimension frameSize)
frameSize
- The size of the WebView rectangle.java.lang.UnsupportedOperationException
- if this class is instantiated on a non-Windows operating system.WWRuntimeException
- if creating the native web browser window fails for any reason. For
example, because the process has run out of User Object handles (see
documentation above).protected java.awt.event.MouseEvent convertToWindows(java.awt.event.MouseEvent e)
e
- The event to convert.protected WWTexture createTextureRepresentation(DrawContext dc)
createTextureRepresentation
in class AbstractWebView
dc
- draw context.public void dispose()
protected void doSetFrameSize(java.awt.Dimension size)
doSetFrameSize
in class AbstractWebView
protected void ensureMessageLoopRunning()
public java.awt.Color getBackgroundColor()
null
if no color has been set.public java.awt.Dimension getContentSize()
null
if the size of this
WebView's current content is unknown, either because it has not finished loading or because its size cannot be
determined. This WebView attempts to determine its current content's size each time an HTML frame is loaded and
its layout is performed. If the content is plain text or has no HTML frames, this WebView determines its content
size after the text is loaded.
The returned size changes as this WebView navigates to new content or navigates within its history, and always
reflects the size of the current content. The returned size is limited by this WebView's minimum content size.
See WebView.getMinContentSize()
for more information on how the minimum content size is used.minContentSize
, or null
if this
WebView's content size is unknown.WebView.getMinContentSize()
public java.net.URL getContentURL()
null
if the current content is the HTML string
specified by setHTMLString
. The returned URL changes as this WebView navigates to new content or
navigates within its history, and always reflects the URL of the current content.null
if the current content is the HTML string
specified by setHTMLString
.public java.lang.Iterable<AVList> getLinks()
AVList
elements describing this WebView's
visible links. The
returned iterable has no elements if this WebView
has no links, or if none of the links are
currently in the WebView's
visible area. Each AVList
describes the parameters for one
link as follows:
AVKey.URL
- a String
containing the link's destination.AVKey.MIME_TYPE
- a String
mime type describing the content type of the link's
destination.AVKey.TARGET
- the link's target frame, one of the following: _blank,
_self, _parent, _top
. See the W3C
documentation on frame target names.AVKey.BOUNDS
- a java.awt.Rectangle
representing the link's bounding rectangle.AVKey.RECTANGLES
- an array of one or more
java.awt.Rectangle
instances representing the link's separate pickable rectangles.WebView
's local coordinate system, and are clipped to the
WebView's
visible area. The WebView
's coordinate system has its origin in the lower
left corner with the X-axis pointing right and the Y-axis pointing up. Multi-line links are represented as one
AVList
with multiple pickable rectangles.Iterable
of AVList
parameters describing this WebView's
visible
links.public java.awt.Dimension getMinContentSize()
public void goBack()
public void goForward()
protected void handleWebViewCreationError()
public void sendEvent(java.awt.event.InputEvent event)
KeyEvent
, MouseEvent
, and MouseWheelEvent
.
The screen coordinates for a MouseEvent
must be transformed into the WebView's local coordinate
system, which has its origin in the lower left corner with the X-axis pointing right and the Y-axis pointing up.
This does nothing if the specified event is null
.
Users of the WebView must call WebView.setActive(boolean)
before sending input events to the WebView. The WebView can be
activated and deactivated any number of times. For example, a controller might call setActive(true)
when the mouse enters the WebView texture, and call setActive(false)
when the mouse exits the
texture.event
- the event to send.WebView.setActive(boolean)
public void setActive(boolean active)
setActive
in interface WebView
setActive
in class AbstractWebView
active
- true
if this WebView is being activated. false
if this WebView is being
deactivated.WebView.sendEvent(java.awt.event.InputEvent)
public void setBackgroundColor(java.awt.Color color)
color
- Color to apply to the background.public void setHTMLString(java.lang.String htmlString)
WebView's
HTML content as a string. The specified htmlString
may be one
of the following:
null
htmlString
is null
or empty. If the
htmlString
contains relative paths, they are not resolved and are interpreted as unresolved
references.
If the application sends input events to the WebView, the user may navigate away from the specified HTML content
by interacting with links or buttons in the content.htmlString
- the WebView's HTML text content, or null
to display an empty
WebView
.public void setHTMLString(java.lang.String htmlString, java.net.URL baseURL)
WebView's
HTML content as a string. The specified htmlString
may be one
of the following:
null
htmlString
is null
or empty. The baseURL
is used to resolve relative paths in the specified htmlString
. If the baseURL
is
null
, relative paths are not resolved and are interpreted as unresolved references.
If the application sends input events to the WebView, the user may navigate away from the specified HTML content
by interacting with links or buttons in the content. Once the user navigates away from the content specified
here, the htmlString
and baseURL
are no longer used.htmlString
- the WebView's HTML text content, or null
to display an empty
WebView
.baseURL
- the URL
used to resolve relative paths in the htmlString
, or
null
to indicate that relative paths should be interpreted as unresolved
references.public void setHTMLString(java.lang.String htmlString, WebResourceResolver resourceResolver)
WebView's
HTML content as a string. The specified htmlString
may be one
of the following:
null
htmlString
is null
or empty. The
WebResourceResolver
is used to resolve relative paths in the specified htmlString
. If
the WebResourceResolver
is null
, relative paths are not resolved and are interpreted as
unresolved references.
If the application sends input events to the WebView, the user may navigate away from the specified HTML content
by interacting with links or buttons in the content. Once the user navigates away from the content specified
here, the htmlString
and resourceResolver
are no longer used.htmlString
- the WebView's HTML text content, or null
to display an empty
WebView
.resourceResolver
- the WebResourceResolver
used to resolve relative paths in the
htmlString
, or null
to indicate that relative paths should be
interpreted as unresolved references.public void setMinContentSize(java.awt.Dimension size)
WebView.getMinContentSize()
for more
information on how this value is interpreted.size
- Minimum size of the WebView content area.protected void stopMessageLoopIfNoInstances()