Initial checkin of Java Util classes and the Java Wrapper to WebShell

Util docs:  http://www.mozilla.org/projects/blackwood/java-util/
Java Wrapper to WebShell docs: http://www.mozilla.org/projects/blackwood/webclient/


git-svn-id: svn://10.0.0.236/trunk@41569 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
edburns%acm.org
1999-07-30 01:03:12 +00:00
parent cab1eacb84
commit 186006f8a6
34 changed files with 6956 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
#!nmake
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
#
# The Initial Developer of the Original Code is Sun Microsystems,
# Inc. Portions created by Sun are Copyright (C) 1999 Sun
# Microsystems, Inc. All Rights Reserved.
IGNORE_MANIFEST=1
#//------------------------------------------------------------------------
#//
#// Makefile to build the java portion of the java wrapper to mozilla
#//
#//------------------------------------------------------------------------
#//------------------------------------------------------------------------
#//
#// Specify the depth of the current directory relative to the
#// root of NS
#//
#//------------------------------------------------------------------------
DEPTH= ..\..\..
# PENDING(edburns): find out where this should really get defined
JAVA_OR_NSJVM=1
NO_CAFE=1
include <$(DEPTH)\config\config.mak>
JAR_WEBCLIENT_CLASSES = org\mozilla\webclient \
org\mozilla\webclient\test
!ifdef JAVA_OR_NSJVM
JDIRS = $(JAR_WEBCLIENT_CLASSES)
!endif
WEBCLIENT_JAR_NAME=webclient(VERSION_NUMBER).jar
JAVAC_PROG=$(JDKHOME)\bin\javac
export::
@echo +++ Checking that org.mozilla.util classes have been built...
if not exist $(MOZ_SRC)\mozilla\dist\classes\org\mozilla\util\Assert.class \
stopbuild.exe
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,39 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is RaptorCanvas
*
* The Initial Developer of the Original Code is Kirk Baker <kbaker@eb.com> and * Ian Wilkinson <iw@ennoble.com
*/
package org.mozilla.webclient;
// BrowserControl.java
/**
*
* <B>BrowserControl</B> simply declares the composition of the core and extended
* interfaces.
*
* @version $Id: BrowserControl.java,v 1.1 1999-07-30 01:03:03 edburns%acm.org Exp $
*
* @see org.mozilla.webclient.BrowserControlCore
* @see org.mozilla.webclient.BrowserControlExtended
*
*/
public interface BrowserControl extends BrowserControlCore, BrowserControlExtended
{
} // end of interface BrowserControl

View File

@@ -0,0 +1,240 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is RaptorCanvas
*
* The Initial Developer of the Original Code is Kirk Baker <kbaker@eb.com> and * Ian Wilkinson <iw@ennoble.com
*/
package org.mozilla.webclient;
// BrowserControlCanvas.java
import org.mozilla.util.Assert;
import org.mozilla.util.Log;
import org.mozilla.util.ParameterCheck;
import java.awt.*;
/**
*
* BrowserControlCanvas is the principal class for embedding
* the Mozilla WebShell into the Java framework.
* This component represents the proxy for the native
* WebShell class as provided by the nsIWebShell
* interface.
*
* @see org.mozilla.webclient.BrowserControl
*
* @author Kirk Baker
* @author Ian Wilkinson
* <P>
* <B>Lifetime And Scope</B> <P>
* See concrete subclasses for scope info.
* @version $Id: BrowserControlCanvas.java,v 1.1 1999-07-30 01:03:04 edburns%acm.org Exp $
* @see org.mozilla.webclient.Win32BrowserControlCanvas
*/
import java.awt.*;
import java.awt.Canvas;
import java.awt.event.*;
import sun.awt.*;
public abstract class BrowserControlCanvas extends Canvas
{
//
// Class Variables
//
private static int webShellCount = 0;
//
// Instance Variables
//
// Attribute Instance Variables
private boolean initializeOK;
private boolean boundsValid;
private boolean hasFocus;
// Relationship Instance Variables
private BrowserControl webShell;
private int nativeWindow;
private Rectangle windowRelativeBounds;
// PENDING(edburns): Is this needed: // private BrowserControlIdleThread idleThread;
//
// Constructors and Initializers
//
/**
* Initialize the BrowserControlMozillaShim. For now,
* this initializes the Mozilla registry.
*/
public BrowserControlCanvas ()
{
nativeWindow = 0;
webShell = null;
initializeOK = false;
boundsValid = false;
hasFocus = false;
try {
BrowserControlMozillaShim.initialize();
} catch (Exception e) {
System.out.println(e.toString());
}
} // BrowserControlCanvas() ctor
/**
* Obtain the native window handle for this component's
* peer.
*/
abstract protected int getWindow(DrawingSurfaceInfo dsi);
//
// Methods from Canvas
//
/**
* Instantiate the Mozilla WebShell container.
*/
public void addNotify ()
{
super.addNotify();
DrawingSurface ds = (DrawingSurface)this.getPeer();
DrawingSurfaceInfo dsi = ds.getDrawingSurfaceInfo();
windowRelativeBounds = new Rectangle();
// We must lock() the DrawingSurfaceInfo before
// accessing its native window handle.
dsi.lock();
nativeWindow = getWindow(dsi);
try {
Rectangle r = new Rectangle(getBoundsRelativeToWindow());
webShell = new BrowserControlImpl(nativeWindow, r);
} catch (Exception e) {
dsi.unlock();
System.out.println(e.toString());
return;
}
dsi.unlock();
initializeOK = true;
webShellCount++;
/*
requestFocus();
*/
} // addNotify()
public BrowserControl getWebShell ()
{
return webShell;
} // getWebShell()
protected Point getEventCoordsLocalToWindow(MouseEvent evt)
{
Rectangle localBounds = getBoundsRelativeToWindow();
int windowLocalX = evt.getX() + localBounds.x;
int windowLocalY = evt.getY() + localBounds.y;
return new Point(windowLocalX, windowLocalY);
} // getEventCoordsLocalToWindow()
protected Rectangle getWindowBounds ()
{// Throw an Exception?
Container parent = getParent();
if (parent != null) {
do {
// if the parent is a window, then return its bounds
if (parent instanceof Window == true) {
return parent.getBounds();
}
parent = parent.getParent();
} while (parent != null);
}
return new Rectangle();
} // getWindowBounds()
protected Rectangle getBoundsRelativeToWindow ()
{
if (boundsValid) {
return windowRelativeBounds;
}
Container parent = getParent();
Point ourLoc = getLocation();
Rectangle ourBounds = getBounds();
if (parent != null) {
do {
// if the parent is a window, then don't adjust to its offset
// and look no further
if (parent instanceof Window == true) {
break;
}
Point parentLoc = parent.getLocation();
ourLoc.translate(-parentLoc.x, -parentLoc.y);
parent = parent.getParent();
} while (parent != null);
}
windowRelativeBounds.setBounds(-ourLoc.x, -ourLoc.y, ourBounds.width, ourBounds.height);
boundsValid = true;
return windowRelativeBounds;
} // getBoundsRelativeToWindow()
public void setBounds(int x, int y, int w, int h)
{
super.setBounds(x, y, w, h);
if (webShell != null) {
System.out.println("in BrowserControlCanvas setBounds: x = " + x + " y = " + y + " w = " + w + " h = " + h);
try {
webShell.setBounds(new Rectangle(0, 0, w - 1, h - 1));
}
catch(Exception ex) {
}
}
}
public void setBounds(Rectangle rect)
{
super.setBounds(rect);
}
} // class BrowserControlCanvas
// EOF

View File

@@ -0,0 +1,119 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are Copyright (C) 1997, 1998, 1999 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.mozilla.webclient;
// BrowserControlCanvasFactory.java
import org.mozilla.util.Assert;
import org.mozilla.util.Log;
import org.mozilla.util.ParameterCheck;
/**
*
* <B>BrowserControlCanvasFactory</B> creates concrete instances of BrowserControlCanvas
* <B>Lifetime And Scope</B> <P>
* This is a static class, it is neven instantiated.
*
* @version $Id: BrowserControlCanvasFactory.java,v 1.1 1999-07-30 01:03:04 edburns%acm.org Exp $
*
* @see org.mozilla.webclient.test.EmbeddedMozilla
*/
public class BrowserControlCanvasFactory extends Object
{
//
// Protected Constants
//
//
// Class Variables
//
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public BrowserControlCanvasFactory()
{
Assert.assert(false, "This class shouldn't be constructed.");
}
//
// Class methods
//
public static BrowserControlCanvas newBrowserControlCanvas()
{
BrowserControlCanvas result = null;
// PENDING(edburns): do some magic to determine the right kind of
// BrowserControlCanvas to instantiate
Class browserControlCanvasClass = null;
String className = "org.mozilla.webclient.Win32BrowserControlCanvas";
try {
if (null != (browserControlCanvasClass = Class.forName(className))) {
result = (BrowserControlCanvas) browserControlCanvasClass.newInstance();
}
}
catch (Exception e) {
System.out.println(e.getMessage());
}
return result;
}
//
// General Methods
//
// ----UNIT_TEST_START
//
// Test methods
//
public static void main(String [] args)
{
Assert.setEnabled(true);
Log.setApplicationName("BrowserControlCanvasFactory");
Log.setApplicationVersion("0.0");
Log.setApplicationVersionDate("$Id: BrowserControlCanvasFactory.java,v 1.1 1999-07-30 01:03:04 edburns%acm.org Exp $");
BrowserControlCanvas canvas = BrowserControlCanvasFactory.newBrowserControlCanvas();
Assert.assert(null != canvas);
}
// ----UNIT_TEST_END
} // end of class BrowserControlCanvasFactory

View File

@@ -0,0 +1,52 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is RaptorCanvas
*
* The Initial Developer of the Original Code is Kirk Baker <kbaker@eb.com> and * Ian Wilkinson <iw@ennoble.com
*/
package org.mozilla.webclient;
// BrowserControlCore.java
/**
*
* <B>BrowserControlCore</B> Defines the core methods for browsing
*
* @version $Id: BrowserControlCore.java,v 1.1 1999-07-30 01:03:04 edburns%acm.org Exp $
*
* @see org.mozilla.webclient.BrowserControlExtended
* @see org.mozilla.webclient.BrowserControl
*
*/
public interface BrowserControlCore
{
public void loadURL(String urlString) throws Exception;
public void stop() throws Exception;
public boolean canBack() throws Exception;
public boolean canForward() throws Exception;
public boolean back() throws Exception;
public boolean forward() throws Exception;
public int getNativeWebShell();
} // end of interface BrowserControlCore

View File

@@ -0,0 +1,62 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is RaptorCanvas
*
* The Initial Developer of the Original Code is Kirk Baker <kbaker@eb.com> and * Ian Wilkinson <iw@ennoble.com
*/
package org.mozilla.webclient;
// BrowserControlExtended.java
import java.awt.Rectangle;
/**
*
* <B>BrowserControlExtended</B> defines the interface for extended browser
* functionality
*
* @version $Id: BrowserControlExtended.java,v 1.1 1999-07-30 01:03:05 edburns%acm.org Exp $
*
* @see org.mozilla.webclient.BrowserControlCore
* */
public interface BrowserControlExtended
{
public void show () throws Exception;
public void hide () throws Exception;
public void setBounds (Rectangle bounds) throws Exception;
public void moveTo (int x, int y) throws Exception;
public void setFocus () throws Exception;
public void removeFocus () throws Exception;
public void repaint (boolean forceRepaint) throws Exception;
public boolean goTo (int historyIndex) throws Exception;
public int getHistoryLength () throws Exception;
public int getHistoryIndex () throws Exception;
public String getURL (int historyIndex) throws Exception;
} // end of interface BrowserControlExtended

View File

@@ -0,0 +1,245 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is RaptorCanvas
*
* The Initial Developer of the Original Code is Kirk Baker <kbaker@eb.com> and * Ian Wilkinson <iw@ennoble.com
*/
package org.mozilla.webclient;
// BrowserControlImpl.java
import org.mozilla.util.Assert;
import org.mozilla.util.Log;
import org.mozilla.util.ParameterCheck;
import java.awt.Rectangle;
/**
*
* <B>BrowserControlImpl</B> provides the implementation for BrowserControl
*
* <B>Lifetime And Scope</B> <P>
*
* @version $Id: BrowserControlImpl.java,v 1.1 1999-07-30 01:03:05 edburns%acm.org Exp $
*
* @see org.mozilla.webclient.BrowserControl
*
*/
public class BrowserControlImpl extends Object implements BrowserControl
{
//
// Protected Constants
//
//
// Class Variables
//
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
/**
* a handle to the actual mozilla webShell
*/
private int nativeWebShell;
//
// Constructors and Initializers
//
public BrowserControlImpl(int windowPtr, Rectangle bounds) throws Exception
{
nativeWebShell = BrowserControlMozillaShim.webShellCreate(windowPtr, bounds);
}
//
// Class methods
//
//
// General Methods
//
//
// Methods from BrowserControl
//
public void loadURL(String urlString) throws Exception
{
BrowserControlMozillaShim.webShellLoadURL(nativeWebShell, urlString);
}
public void stop() throws Exception
{
BrowserControlMozillaShim.webShellStop(nativeWebShell);
}
public void show () throws Exception
{
BrowserControlMozillaShim.webShellShow(nativeWebShell);
}
public void hide () throws Exception
{
BrowserControlMozillaShim.webShellHide(nativeWebShell);
}
public void setBounds (Rectangle bounds) throws Exception
{
BrowserControlMozillaShim.webShellSetBounds(nativeWebShell, bounds);
}
public void moveTo (int x, int y) throws Exception
{
BrowserControlMozillaShim.webShellMoveTo(nativeWebShell, x, y);
}
/**
*
*/
public void setFocus () throws Exception
{
BrowserControlMozillaShim.webShellSetFocus(nativeWebShell);
}
/**
*
*/
public void removeFocus () throws Exception
{
BrowserControlMozillaShim.webShellRemoveFocus(nativeWebShell);
}
/**
*
*/
public void repaint (boolean forceRepaint) throws Exception
{
BrowserControlMozillaShim.webShellRepaint(nativeWebShell, forceRepaint);
}
/**
*
*/
public boolean canBack () throws Exception
{
return BrowserControlMozillaShim.webShellCanBack(nativeWebShell);
}
/**
*
*/
public boolean canForward () throws Exception
{
return BrowserControlMozillaShim.webShellCanForward(nativeWebShell);
}
/**
*
*/
public boolean back () throws Exception
{
return BrowserControlMozillaShim.webShellBack(nativeWebShell);
}
/**
*
*/
public boolean forward () throws Exception
{
return BrowserControlMozillaShim.webShellForward(nativeWebShell);
}
/**
*
*/
public boolean goTo (int historyIndex) throws Exception
{
return BrowserControlMozillaShim.webShellGoTo(nativeWebShell, historyIndex);
}
/**
*
*/
public int getHistoryLength () throws Exception
{
return BrowserControlMozillaShim.webShellGetHistoryLength(nativeWebShell);
}
/**
*
*/
public int getHistoryIndex () throws Exception
{
return BrowserControlMozillaShim.webShellGetHistoryIndex(nativeWebShell);
}
/**
*
*/
public String getURL (int historyIndex) throws Exception
{
return BrowserControlMozillaShim.webShellGetURL(nativeWebShell, historyIndex);
}
/**
*
*/
public int getNativeWebShell ()
{
return nativeWebShell;
}
/**
*
*/
public void finalize ()
{
try {
BrowserControlMozillaShim.webShellDelete(nativeWebShell);
}
catch (Exception ex) {
System.out.println(ex.toString());
}
nativeWebShell = 0;
}
// ----UNIT_TEST_START
//
// Test methods
//
public static void main(String [] args)
{
Assert.setEnabled(true);
// BrowserControlImpl me = new BrowserControlImpl();
Log.setApplicationName("BrowserControlImpl");
Log.setApplicationVersion("0.0");
Log.setApplicationVersionDate("$Id: BrowserControlImpl.java,v 1.1 1999-07-30 01:03:05 edburns%acm.org Exp $");
}
// ----UNIT_TEST_END
} // end of class BrowserControlImpl

View File

@@ -0,0 +1,572 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is RaptorCanvas
*
* The Initial Developer of the Original Code is Kirk Baker <kbaker@eb.com> and * Ian Wilkinson <iw@ennoble.com
*/
package org.mozilla.webclient;
// MWebShellMozillaShim.java
import org.mozilla.util.Assert;
import org.mozilla.util.Log;
import org.mozilla.util.ParameterCheck;
import java.awt.*;
/**
*
* <B>MWebShellMozillaShim</B> is a class with native methods that
* provides the glue between MWebShell and nsIWebShell. <P>
* WAS: instance <P>
* <B>Lifetime And Scope</B> <P>
* There is one instance of this class and all of the exposed methods
* are static.
* @version $Id: BrowserControlMozillaShim.java,v 1.1 1999-07-30 01:03:05 edburns%acm.org Exp $
*
* @see org.mozilla.webclient.BrowserControlImpl
*
*/
public class BrowserControlMozillaShim extends Object
{
//
// Protected Constants
//
//
// Class Variables
//
private static boolean initialized = false;
private static BrowserControlMozillaShim instance = null;
private static Object lock = null;
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public BrowserControlMozillaShim()
{
super();
lock = new Object();
}
//
// Class methods
//
public static void initialize () throws Exception
{
if (!initialized) {
instance = new BrowserControlMozillaShim();
try {
System.loadLibrary("webclient");
}
catch (java.lang.UnsatisfiedLinkError e) {
throw new Exception("Unable to open native webclient library");
}
instance.nativeInitialize();
initialized = true;
}
}
public static void terminate () throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeTerminate();
initialized = false;
}
}
}
public static void processEvents(int theWebShell)
{
synchronized(lock) {
if (initialized) {
instance.nativeProcessEvents(theWebShell);
}
}
}
//
// Window events
//
public static void sendKeyDownEvent (int widgetPtr,
char keyChar, int keyCode,
int modifiers, int eventTime)
{
synchronized(lock) {
if (initialized) {
instance.nativeSendKeyDownEvent(widgetPtr,
keyChar, keyCode, modifiers,
eventTime);
}
}
}
public static void sendKeyUpEvent (int widgetPtr,
char keyChar, int keyCode,
int modifiers, int eventTime)
{
synchronized(lock) {
if (initialized) {
instance.nativeSendKeyUpEvent(widgetPtr, keyChar,
keyCode, modifiers, eventTime);
}
}
}
public static void sendMouseEvent (int windowPtr, int widgetPtr,
int widgetX, int widgetY,
int windowX, int windowY,
int mouseMessage, int numClicks,
int modifiers, int eventTime)
{
synchronized(lock) {
if (initialized) {
instance.nativeSendMouseEvent(windowPtr, widgetPtr,
widgetX, widgetY,
windowX, windowY,
mouseMessage, numClicks,
modifiers, eventTime);
}
}
}
public static void idleEvent (int windowPtr)
{
synchronized(lock) {
if (initialized) {
instance.nativeIdleEvent(windowPtr, 0);
}
}
}
public static void updateEvent (int windowPtr)
{
synchronized(lock) {
if (initialized) {
instance.nativeUpdateEvent(windowPtr, 0);
}
}
}
//
// Widget methods
//
public static int widgetCreate (int windowPtr,
Rectangle bounds) throws Exception
{
synchronized(lock) {
if (initialized) {
return(instance.nativeWidgetCreate(windowPtr,
bounds.x, bounds.y,
bounds.width + 1, bounds.height + 1));
} else {
return 0;
}
}
}
public static void widgetDelete (int widgetPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeWidgetDelete(widgetPtr);
}
}
}
public static void widgetResize (int widgetPtr, Rectangle bounds,
boolean repaint)
{
synchronized(lock) {
if (initialized) {
instance.nativeWidgetResize(widgetPtr, bounds.x, bounds.y, bounds.width + 1, bounds.height + 1, repaint);
}
}
}
public static void widgetResize (int widgetPtr, int width,
int height, boolean repaint)
{
synchronized(lock) {
if (initialized) {
instance.nativeWidgetResize(widgetPtr, 0, 0, width + 1, height + 1, repaint);
}
}
}
public static void widgetEnable (int widgetPtr, boolean enable)
{
synchronized(lock) {
if (initialized) {
instance.nativeWidgetEnable(widgetPtr, enable);
}
}
}
public static void widgetShow (int widgetPtr, boolean show)
{
synchronized(lock) {
if (initialized) {
instance.nativeWidgetShow(widgetPtr, show);
}
}
}
public static void widgetInvalidate (int widgetPtr, boolean isSynchronous)
{
synchronized(lock) {
if (initialized) {
instance.nativeWidgetInvalidate(widgetPtr, isSynchronous);
}
}
}
public static void widgetUpdate (int widgetPtr)
{
synchronized(lock) {
if (initialized) {
instance.nativeWidgetUpdate(widgetPtr);
}
}
}
//
// WebShell methods
//
public static int webShellCreate (int windowPtr,
Rectangle bounds) throws Exception
{
synchronized(lock) {
if (initialized) {
return(instance.nativeWebShellCreate(windowPtr, bounds.x, bounds.y, bounds.width + 1, bounds.height + 1));
}
else {
throw new Exception("Error: unable to create native nsIWebShell");
}
}
}
public static void webShellDelete (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeWebShellDelete(webShellPtr);
}
}
}
public static void webShellLoadURL (int webShellPtr,
String urlString) throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeWebShellLoadURL(webShellPtr, urlString);
}
}
}
public static void webShellStop (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeWebShellStop(webShellPtr);
}
}
}
public static void webShellShow (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeWebShellShow(webShellPtr);
}
}
}
public static void webShellHide (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeWebShellHide(webShellPtr);
}
}
}
public static void webShellSetBounds (int webShellPtr,
Rectangle bounds) throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeWebShellSetBounds(webShellPtr, bounds.x, bounds.y, bounds.width + 1, bounds.height + 1);
}
}
}
public static void webShellMoveTo (int webShellPtr,
int x, int y) throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeWebShellMoveTo(webShellPtr, x, y);
}
}
}
public static void webShellSetFocus (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeWebShellSetFocus(webShellPtr);
}
}
}
public static void webShellRemoveFocus (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeWebShellRemoveFocus(webShellPtr);
}
}
}
public static void webShellRepaint (int webShellPtr,
boolean forceRepaint) throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeWebShellRepaint(webShellPtr, forceRepaint);
}
}
}
public static boolean webShellCanBack (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
return instance.nativeWebShellCanBack(webShellPtr);
}
else {
throw new Exception("instance is not initialized.");
}
}
}
public static boolean webShellCanForward (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
return instance.nativeWebShellCanForward(webShellPtr);
}
else {
throw new Exception("instance is not initialized.");
}
}
}
public static boolean webShellBack (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
return instance.nativeWebShellBack(webShellPtr);
}
else {
throw new Exception("instance is not initialized.");
}
}
}
public static boolean webShellForward (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
return instance.nativeWebShellForward(webShellPtr);
}
else {
throw new Exception("instance is not initialized.");
}
}
}
public static boolean webShellGoTo (int webShellPtr,
int historyIndex) throws Exception
{
synchronized(lock) {
if (initialized) {
return instance.nativeWebShellGoTo(webShellPtr, historyIndex);
}
else {
throw new Exception("instance is not initialized.");
}
}
}
public static int webShellGetHistoryLength (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
return instance.nativeWebShellGetHistoryLength(webShellPtr);
}
else {
throw new Exception("instance is not initialized.");
}
}
}
public static int webShellGetHistoryIndex (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
return instance.nativeWebShellGetHistoryIndex(webShellPtr);
}
else {
throw new Exception("instance is not initialized.");
}
}
}
public static String webShellGetURL(int webShellPtr,
int historyIndex) throws Exception
{
synchronized(lock) {
if (initialized) {
return instance.nativeWebShellGetURL(webShellPtr, historyIndex);
}
else {
throw new Exception("instance is not initialized.");
}
}
}
//
// Native interfaces
//
private native void nativeInitialize () throws Exception;
private native void nativeTerminate () throws Exception;
//
// Event interfaces
//
private native void nativeSendKeyDownEvent(int widgetPtr, char keyChar, int keyCode, int modifiers, int eventTime);
private native void nativeSendKeyUpEvent(int widgetPtr, char keyChar, int keyCode, int modifiers, int eventTime);
private native void nativeSendMouseEvent(int windowPtr, int widgetPtr,
int widgetX, int widgetY,
int windowX, int windowY,
int mouseMessage, int numClicks,
int modifiers, int eventTime);
private native void nativeProcessEvents(int theWebShell);
private native void nativeIdleEvent (int windowPtr, int eventTime);
private native void nativeUpdateEvent (int windowPtr, int eventTime);
//
// Widget interfaces
//
private native int nativeWidgetCreate (int windowPtr, int x, int y, int width, int height) throws Exception;
private native void nativeWidgetDelete (int widgetPtr) throws Exception;
private native void nativeWidgetResize (int widgetPtr, int x, int y, int width, int height, boolean repaint);
/*
private native void nativeWidgetResize (int widgetPtr, int width, int height, boolean repaint);
*/
private native void nativeWidgetEnable (int widgetPtr, boolean enable);
private native void nativeWidgetShow (int widgetPtr, boolean show);
private native void nativeWidgetInvalidate (int widgetPtr, boolean isSynchronous);
private native void nativeWidgetUpdate (int widgetPtr);
//
// WebShell interface
//
private native int nativeWebShellCreate (int windowPtr,
int x, int y, int width, int height) throws Exception;
private native void nativeWebShellDelete (int webShellPtr) throws Exception;
private native void nativeWebShellLoadURL (int webShellPtr, String urlString) throws Exception;
private native void nativeWebShellStop (int webShellPtr) throws Exception;
private native void nativeWebShellShow (int webShellPtr) throws Exception;
private native void nativeWebShellHide (int webShellPtr) throws Exception;
private native void nativeWebShellSetBounds (int webShellPtr, int x, int y, int width, int height) throws Exception;
private native void nativeWebShellMoveTo (int webShellPtr, int x, int y) throws Exception;
private native void nativeWebShellSetFocus (int webShellPtr) throws Exception;
private native void nativeWebShellRemoveFocus (int webShellPtr) throws Exception;
private native void nativeWebShellRepaint (int webShellPtr, boolean forceRepaint) throws Exception;
private native boolean nativeWebShellCanBack (int webShellPtr) throws Exception;
private native boolean nativeWebShellCanForward (int webShellPtr) throws Exception;
private native boolean nativeWebShellBack (int webShellPtr) throws Exception;
private native boolean nativeWebShellForward (int webShellPtr) throws Exception;
private native boolean nativeWebShellGoTo (int webShellPtr, int aHistoryIndex) throws Exception;
private native int nativeWebShellGetHistoryLength (int webShellPtr) throws Exception;
private native int nativeWebShellGetHistoryIndex (int webShellPtr) throws Exception;
private native String nativeWebShellGetURL (int webShellPtr, int aHistoryIndex) throws Exception;
//
// General Methods
//
// ----UNIT_TEST_START
//
// Test methods
//
public static void main(String [] args)
{
Assert.setEnabled(true);
BrowserControlMozillaShim me = new BrowserControlMozillaShim();
Log.setApplicationName("BrowserControlMozillaShim");
Log.setApplicationVersion("0.0");
Log.setApplicationVersionDate("$Id: BrowserControlMozillaShim.java,v 1.1 1999-07-30 01:03:05 edburns%acm.org Exp $");
}
// ----UNIT_TEST_END
} // end of class BrowserControlMozillaShim

View File

@@ -0,0 +1,60 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is RaptorCanvas
*
* The Initial Developer of the Original Code is Kirk Baker <kbaker@eb.com> and * Ian Wilkinson <iw@ennoble.com
*/
package org.mozilla.webclient;
// Win32BrowserControlCanvas.java
import org.mozilla.util.Assert;
import org.mozilla.util.Log;
import org.mozilla.util.ParameterCheck;
/**
* Win32RaptorCanvas provides a concrete realization
* of the RaptorCanvas.
* <B>Lifetime And Scope</B> <P>
* There is one instance of the BrowserControlCanvas per top level awt Frame.
* @version $Id: Win32BrowserControlCanvas.java,v 1.1 1999-07-30 01:03:06 edburns%acm.org Exp $
*
* @see org.mozilla.webclient.BrowserControlCanvasFactory
*
*/
import sun.awt.*;
import sun.awt.windows.*;
/**
* Win32BrowserControlCanvas provides a concrete realization
* of the RaptorCanvas.
*/
class Win32BrowserControlCanvas extends BrowserControlCanvas {
/**
* Obtain the native window handle for this
* component's peer.
*
* @returns The native window handle.
*/
protected int getWindow(DrawingSurfaceInfo dsi) {
WDrawingSurfaceInfo ds = (WDrawingSurfaceInfo)dsi;
return ds.getHWnd();
}
}

View File

@@ -0,0 +1,186 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is RaptorCanvas
*
* The Initial Developer of the Original Code is Kirk Baker <kbaker@eb.com> and * Ian Wilkinson <iw@ennoble.com
*/
package org.mozilla.webclient.test;
/*
* EmbeddedMozilla.java
*/
import java.awt.*;
import java.awt.event.*;
import org.mozilla.webclient.*;
/**
*
* This is a test application for using the BrowserControl.
*
* @version $Id: EmbeddedMozilla.java,v 1.1 1999-07-30 01:03:07 edburns%acm.org Exp $
*
* @see org.mozilla.webclient.BrowserControlCanvasFactory
*/
public class EmbeddedMozilla extends Frame implements ActionListener {
static final int defaultWidth = 640;
static final int defaultHeight = 480;
private TextField urlField;
private BrowserControl browserControl;
private Panel controlPanel;
private Panel buttonsPanel;
public static void main (String[] arg) {
String urlArg =(0 < arg.length) ? arg[0] : "http://www.mozilla.org/";
EmbeddedMozilla gecko =
new EmbeddedMozilla("Embedded Mozilla", urlArg);
} // main()
public EmbeddedMozilla (String title, String url) {
super(title);
System.out.println("constructed with " + url);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
// should close the BrowserControlCanvas
}
public void windowClosed(WindowEvent e) {
System.exit(0);
}
});
setSize(defaultWidth, defaultHeight);
// Create the URL field
urlField = new TextField("", 30);
urlField.addActionListener(this);
// Create the buttons sub panel
buttonsPanel = new Panel();
buttonsPanel.setLayout(new GridBagLayout());
// Add the buttons
makeItem(buttonsPanel, "Back", 0, 0, 1, 1, 0.0, 0.0);
makeItem(buttonsPanel, "Forward", 1, 0, 1, 1, 0.0, 0.0);
makeItem(buttonsPanel, "Stop", 2, 0, 1, 1, 0.0, 0.0);
// Create the control panel
controlPanel = new Panel();
controlPanel.setLayout(new BorderLayout());
// Add the URL field, and the buttons panel
controlPanel.add(urlField, BorderLayout.CENTER);
controlPanel.add(buttonsPanel, BorderLayout.WEST);
// Create the browser
BrowserControlCanvas browser =
BrowserControlCanvasFactory.newBrowserControlCanvas();
browser.setSize(defaultWidth, defaultHeight);
// Add the control panel and the browser
add(controlPanel, BorderLayout.NORTH);
add(browser, BorderLayout.CENTER);
pack();
show();
toFront();
browserControl = browser.getWebShell();
try {
browserControl.loadURL(url);
urlField.setText(url);
}
catch (Exception e) {
System.out.println(e.toString());
}
} // EmbeddedMozilla() ctor
public void actionPerformed (ActionEvent evt) {
String command = evt.getActionCommand();
try {
if (command.equals("Back")) {
if (browserControl.canBack()) {
browserControl.back();
int index = browserControl.getHistoryIndex();
String newURL = browserControl.getURL(index);
System.out.println(newURL);
urlField.setText(newURL);
}
}
else if (command.equals("Forward")) {
if (browserControl.canForward()) {
browserControl.forward();
int index = browserControl.getHistoryIndex();
String newURL = browserControl.getURL(index);
System.out.println(newURL);
urlField.setText(newURL);
}
}
else if (command.equals("Stop")) {
browserControl.stop();
}
else {
browserControl.loadURL(urlField.getText());
}
}
catch (Exception e) {
System.out.println(e.toString());
}
} // actionPerformed()
private void makeItem (Panel p, Object arg, int x, int y, int w, int h, double weightx, double weighty) {
GridBagLayout gbl = (GridBagLayout) p.getLayout();
GridBagConstraints c = new GridBagConstraints();
Component comp;
c.fill = GridBagConstraints.BOTH;
c.gridx = x;
c.gridy = y;
c.gridwidth = w;
c.gridheight = h;
c.weightx = weightx;
c.weighty = weighty;
if (arg instanceof String) {
Button b;
comp = b = new Button((String) arg);
b.addActionListener(this);
p.add(comp);
gbl.setConstraints(comp, c);
}
} // makeItem()
}
// EOF