From bcbf08419df9f395b7ecbbf0f697e76dce3b44a1 Mon Sep 17 00:00:00 2001 From: "edburns%acm.org" Date: Thu, 25 May 2000 23:51:51 +0000 Subject: [PATCH] bug: 20659 r=gbarney a=edburns This checkin adds java.awt.event.MouseListener support to webclient for mozilla. The following files are include in this checkin. "A" is new file "M" is modified file. A classes_spec/org/mozilla/webclient/WCMouseEvent.java A classes_spec/org/mozilla/webclient/wrapper_native/WCMouseListenerImpl.java A src_moz/DOMMouseListenerImpl.cpp A src_moz/DOMMouseListenerImpl.h A src_moz/dom_util.cpp A src_moz/dom_util.h M classes_spec/org/mozilla/webclient/EventRegistration.java M classes_spec/org/mozilla/webclient/test/EMWindow.java M classes_spec/org/mozilla/webclient/wrapper_native/EventRegistrationImpl.java M classes_spec/org/mozilla/webclient/wrapper_native/NativeEventThread.java M src_moz/DocumentLoaderObserverImpl.cpp M src_moz/DocumentLoaderObserverImpl.h M src_moz/EventRegistration.cpp M src_moz/EventRegistration.h M src_moz/Makefile.solaris M src_moz/Makefile.win M src_moz/NativeEventThread.cpp M src_moz/NavigationImpl.cpp M src_moz/RDFTreeNode.cpp M src_moz/bal_util.cpp M src_moz/jni_util.cpp M src_moz/jni_util.h M src_moz/jni_util_export.cpp M src_moz/jni_util_export.h A classes_spec/org/mozilla/webclient/WCMouseEvent.java *

This java.awt.event.MouseEvent subclass allows the user to access the * WebclientEvent. This eventData of this WebclientEvent, if non-null, * is a java.util.Properties instance that contains information about * this event.

*

The following are some interesting keys:

* A classes_spec/org/mozilla/webclient/wrapper_native/WCMouseListenerImpl.java * This class wraps the user provided instance of * java.awt.event.MouseListener so it can be installed as a * WebclientEventListener. Note that we implement MouseListener so we * can be detected by the webclient event system. We don't do anything * with these methods here, though. A src_moz/DOMMouseListenerImpl.cpp A src_moz/DOMMouseListenerImpl.h * This class is the shim between the mozilla listener event system for * mouse events and the java MouseListener interface. * For each of the Mouse* methods, we call the appropriate method in java. * See the implementation of MouseOver for an example. * For each mouseEvent, we create a Properties object containing * information about the event. We use methods in dom_util to do this. A src_moz/dom_util.cpp A src_moz/dom_util.h /** * Methods to simplify webclient accessing the mozilla DOM. */ M classes_spec/org/mozilla/webclient/EventRegistration.java Added support for java.awt.event.MouseListener M classes_spec/org/mozilla/webclient/test/EMWindow.java Implemented simle MouseListener M classes_spec/org/mozilla/webclient/wrapper_native/EventRegistrationImpl.java Added support for java.awt.event.MouseListener M classes_spec/org/mozilla/webclient/wrapper_native/NativeEventThread.java Added support for java.awt.event.MouseListener M src_moz/DocumentLoaderObserverImpl.cpp M src_moz/DocumentLoaderObserverImpl.h * We define a local IID to allow the addDocumentLoadListener and * addMouseListener functions in EventRegistration.{h,cpp} to * interrogate the currently installed DocumentLoaderObserver instance * in mozilla. */ #define NS_IDOCLOADEROBSERVERIMPL_IID_STR "fdadb2e0-3028-11d4-8a96-0080c7b9c5ba" #define NS_IDOCLOADEROBSERVERIMPL_IID {0xfdadb2e0, 0x3028, 0x11d4, { 0x8a, 0x96, 0x00, 0x80, 0xc7, 0xb9, 0xc5, 0xba }} /** * This class is the shim between the mozilla listener event system for * document load events and the java DocumentLoadListener interface. * For each of the On* methods, we call the appropriate method in java. * See the implementation of OnEndDocumentLoad for an example. * A DocumentLoaderObserverImpl instance has a "jobject target", which * is the Java object that should ultimately receive the events. This * target will be null if the user just wants to listen for mouse * events. It willl be non-null if the user wants to listen for * DocumentLoad events. * It also hosts a nsIDOMMouseListener instance, which piggybacks on the * nsIDocumentLoaderObserver instance. M src_moz/EventRegistration.cpp M src_moz/EventRegistration.h Add support for MouseListener M src_moz/Makefile.win Added classes for MouseListener and Dom access M src_moz/NativeEventThread.cpp Added support for MouseListener M src_moz/NavigationImpl.cpp Added call to ReleaseStringChars for bal case. M src_moz/RDFTreeNode.cpp Added call to ReleaseStringChars for bal case. M src_moz/bal_util.cpp Added #include "wchar.h" so this file compiles on Solaris. M src_moz/jni_util.cpp Added implementations for util_CreatePropertiesObject, util_DestroyPropertiesObject and util_StoreIntoPropertiesObject. M src_moz/jni_util.h /** * A JNI wrapper to create a java.util.Properties object, or the * equivalent object in the BAL case. */ jobject util_CreatePropertiesObject(JNIEnv *env, jobject reserved_NotUsed); /** * A JNI wrapper to destroy the object from CreatePropertiesObject */ void util_DestroyPropertiesObject(JNIEnv *env, jobject propertiesObject, jobject reserved_NotUsed); /** * A JNI wrapper for storing a name/value pair into the Properties * object created by CreatePropertiesObject */ void util_StoreIntoPropertiesObject(JNIEnv *env, jobject propertiesObject, jobject name, jobject value); M src_moz/jni_util_export.cpp M src_moz/jni_util_export.h Added functions for allowing the BAL user to specify functions for {creating, destroying, setting values into} properties objects. git-svn-id: svn://10.0.0.236/trunk@70879 18797224-902f-48f8-a5cc-f745e15eee43 --- .../mozilla/webclient/EventRegistration.java | 4 + .../org/mozilla/webclient/WCMouseEvent.java | 79 ++++ .../org/mozilla/webclient/test/EMWindow.java | 49 ++- .../wrapper_native/EventRegistrationImpl.java | 39 +- .../wrapper_native/NativeEventThread.java | 13 + .../wrapper_native/WCMouseListenerImpl.java | 188 +++++++++ .../src_moz/DOMMouseListenerImpl.cpp | 385 ++++++++++++++++++ .../webclient/src_moz/DOMMouseListenerImpl.h | 145 +++++++ .../src_moz/DocumentLoaderObserverImpl.cpp | 190 ++++++--- .../src_moz/DocumentLoaderObserverImpl.h | 51 ++- .../webclient/src_moz/EventRegistration.cpp | 112 ++++- .../webclient/src_moz/EventRegistration.h | 20 +- .../java/webclient/src_moz/Makefile.solaris | 5 + mozilla/java/webclient/src_moz/Makefile.win | 3 + .../webclient/src_moz/NativeEventThread.cpp | 5 + .../java/webclient/src_moz/NavigationImpl.cpp | 6 +- .../java/webclient/src_moz/RDFTreeNode.cpp | 2 +- mozilla/java/webclient/src_moz/bal_util.cpp | 2 + mozilla/java/webclient/src_moz/dom_util.cpp | 114 ++++++ mozilla/java/webclient/src_moz/dom_util.h | 77 ++++ mozilla/java/webclient/src_moz/jni_util.cpp | 76 ++++ mozilla/java/webclient/src_moz/jni_util.h | 28 ++ .../webclient/src_moz/jni_util_export.cpp | 31 +- .../java/webclient/src_moz/jni_util_export.h | 104 ++++- 24 files changed, 1638 insertions(+), 90 deletions(-) create mode 100644 mozilla/java/webclient/classes_spec/org/mozilla/webclient/WCMouseEvent.java create mode 100644 mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/WCMouseListenerImpl.java create mode 100644 mozilla/java/webclient/src_moz/DOMMouseListenerImpl.cpp create mode 100644 mozilla/java/webclient/src_moz/DOMMouseListenerImpl.h create mode 100644 mozilla/java/webclient/src_moz/dom_util.cpp create mode 100644 mozilla/java/webclient/src_moz/dom_util.h diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/EventRegistration.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/EventRegistration.java index 2e46c7d4bba..ac477a4b1c2 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/EventRegistration.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/EventRegistration.java @@ -23,6 +23,7 @@ package org.mozilla.webclient; import java.awt.event.WindowListener; +import java.awt.event.MouseListener; public interface EventRegistration { @@ -35,6 +36,9 @@ public interface EventRegistration { public void addDocumentLoadListener(DocumentLoadListener listener); public void removeDocumentLoadListener(DocumentLoadListener listener); +public void addMouseListener(MouseListener listener); +public void removeMouseListener(MouseListener listener); + // public void addDOMListener(DOMListener containerListener); // public void removeDOMListener(DOMListener containerListener); diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/WCMouseEvent.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/WCMouseEvent.java new file mode 100644 index 00000000000..4e58bbd59b4 --- /dev/null +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/WCMouseEvent.java @@ -0,0 +1,79 @@ +/* -*- 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.1 (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 and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Ed Burns + */ + +package org.mozilla.webclient; + +import java.awt.Component; + +/** + + *

This java.awt.event.MouseEvent subclass allows the user to access the + * WebclientEvent. This eventData of this WebclientEvent, if non-null, + * is a java.util.Properties instance that contains information about + * this event.

+ + *

The following are some interesting keys:

+ + * + + */ + +public class WCMouseEvent extends java.awt.event.MouseEvent +{ + +public static final long MOUSE_DOWN_EVENT_MASK = 1; +public static final long MOUSE_UP_EVENT_MASK = 1 << 2; +public static final long MOUSE_CLICK_EVENT_MASK = 1 << 3; +public static final long MOUSE_DOUBLE_CLICK_EVENT_MASK = 1 << 4; +public static final long MOUSE_OVER_EVENT_MASK = 1 << 5; +public static final long MOUSE_OUT_EVENT_MASK = 1 << 6; + +// +// Constructors +// + +private WebclientEvent webclientEvent; + +public WCMouseEvent(Component source, int id, long when, int modifiers, int x, + int y, int clickCount, boolean popupTrigger, + WebclientEvent wcEvent) +{ + // PENDING(edburns): pull out the clickcount and such from the + // Properties object, pass this data on to the constructor. + super(source, id, when, modifiers, x, y, clickCount, popupTrigger); + webclientEvent = wcEvent; +} + +public WebclientEvent getWebclientEvent() +{ + return webclientEvent; +} + +} // end of class WCMouseEvent diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EMWindow.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EMWindow.java index 3b755d2b163..b5c25b193b1 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EMWindow.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EMWindow.java @@ -50,13 +50,13 @@ import org.mozilla.util.Assert; * This is a test application for using the BrowserControl. * - * @version $Id: EMWindow.java,v 1.6 2000-05-23 21:06:41 ashuk%eng.sun.com Exp $ + * @version $Id: EMWindow.java,v 1.7 2000-05-25 23:51:43 edburns%acm.org Exp $ * * @see org.mozilla.webclient.BrowserControlFactory */ -public class EMWindow extends Frame implements DialogClient, ActionListener, DocumentLoadListener { +public class EMWindow extends Frame implements DialogClient, ActionListener, DocumentLoadListener, MouseListener { static final int defaultWidth = 640; static final int defaultHeight = 480; @@ -207,7 +207,7 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc browserControl.queryInterface(BrowserControl.EVENT_REGISTRATION_NAME); System.out.println("debug: edburns: adding DocumentLoadListener"); eventRegistration.addDocumentLoadListener(this); - + eventRegistration.addMouseListener(this); // PENDING(edburns): test code, replace with production code bookmarks = @@ -449,7 +449,7 @@ public void dialogCancelled(Dialog d) { // -// From DocumentLoadListener +// From WebclientEventListener sub-interfaces // /** @@ -473,6 +473,47 @@ public void eventDispatched(WebclientEvent event) } } +// +// From MouseListener +// + +public void mouseClicked(java.awt.event.MouseEvent e) +{ + System.out.println("mouseClicked"); +} + +public void mouseEntered(java.awt.event.MouseEvent e) +{ + System.out.println("mouseEntered"); + if (e instanceof WCMouseEvent) { + WCMouseEvent wcMouseEvent = (WCMouseEvent) e; + Properties eventProps = + (Properties) wcMouseEvent.getWebclientEvent().getEventData(); + if (null == eventProps) { + return; + } + String href = eventProps.getProperty("href"); + if (null != href) { + System.out.println(href); + } + } +} + +public void mouseExited(java.awt.event.MouseEvent e) +{ + System.out.println("mouseExited"); +} + +public void mousePressed(java.awt.event.MouseEvent e) +{ + System.out.println("mousePressed"); +} + +public void mouseReleased(java.awt.event.MouseEvent e) +{ + System.out.println("mouseReleased"); +} + } // EOF diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/EventRegistrationImpl.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/EventRegistrationImpl.java index b7330ca3f78..ac5b2b82c09 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/EventRegistrationImpl.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/EventRegistrationImpl.java @@ -22,6 +22,7 @@ package org.mozilla.webclient.wrapper_native; + import org.mozilla.util.Assert; import org.mozilla.util.Log; import org.mozilla.util.ParameterCheck; @@ -32,8 +33,10 @@ import org.mozilla.webclient.WindowControl; import org.mozilla.webclient.WrapperFactory; import org.mozilla.webclient.DocumentLoadEvent; import org.mozilla.webclient.DocumentLoadListener; +import java.awt.event.MouseListener; import org.mozilla.webclient.WebclientEvent; import org.mozilla.webclient.WebclientEventListener; +import org.mozilla.webclient.UnimplementedException; public class EventRegistrationImpl extends ImplObjectNative implements EventRegistration { @@ -112,6 +115,7 @@ public void addDocumentLoadListener(DocumentLoadListener listener) myFactory.throwExceptionIfNotInitialized(); Assert.assert(-1 != nativeWebShell); Assert.assert(null != nativeEventThread); + ParameterCheck.nonNull(listener); synchronized(myBrowserControl) { nativeEventThread.addListener(listener); @@ -123,10 +127,43 @@ public void removeDocumentLoadListener(DocumentLoadListener listener) myFactory.throwExceptionIfNotInitialized(); Assert.assert(-1 != nativeWebShell); + throw new UnimplementedException("\nUnimplementedException -----\n API Function EventRegistration.removeDocumentLoadListener has not yet been implemented.\n"); + + // synchronized(myBrowserControl) { + // } +} + +public void addMouseListener(MouseListener listener) +{ + myFactory.throwExceptionIfNotInitialized(); + Assert.assert(-1 != nativeWebShell); + Assert.assert(null != nativeEventThread); + ParameterCheck.nonNull(listener); + + // We have to wrap the user provided java.awt.event.MouseListener + // instance in a custom WebclientEventListener subclass that also + // implements java.awt.event.MouseListener. See WCMouseListener for + // more information. + + WCMouseListenerImpl mouseListenerWrapper = + new WCMouseListenerImpl(listener); + synchronized(myBrowserControl) { + nativeEventThread.addListener(mouseListenerWrapper); } } +public void removeMouseListener(MouseListener listener) +{ + myFactory.throwExceptionIfNotInitialized(); + Assert.assert(-1 != nativeWebShell); + + throw new UnimplementedException("\nUnimplementedException -----\n API Function EventRegistration.removeMouseListener has not yet been implemented.\n"); + + // synchronized(myBrowserControl) { + // } +} + // ----VERTIGO_TEST_START // @@ -139,7 +176,7 @@ public static void main(String [] args) Log.setApplicationName("EventRegistrationImpl"); Log.setApplicationVersion("0.0"); - Log.setApplicationVersionDate("$Id: EventRegistrationImpl.java,v 1.3 2000-03-13 18:42:23 edburns%acm.org Exp $"); + Log.setApplicationVersionDate("$Id: EventRegistrationImpl.java,v 1.4 2000-05-25 23:51:43 edburns%acm.org Exp $"); try { org.mozilla.webclient.BrowserControlFactory.setAppData(args[0]); diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NativeEventThread.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NativeEventThread.java index 443f94ff996..37d47fcf3e0 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NativeEventThread.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NativeEventThread.java @@ -34,6 +34,7 @@ import org.mozilla.webclient.BrowserControlCanvas; import org.mozilla.webclient.WindowControl; import org.mozilla.webclient.DocumentLoadEvent; import org.mozilla.webclient.DocumentLoadListener; +import java.awt.event.MouseListener; import org.mozilla.webclient.WebclientEvent; import org.mozilla.webclient.WebclientEventListener; @@ -263,6 +264,18 @@ void nativeEventOccurred(WebclientEventListener target, long eventType, if (target instanceof DocumentLoadListener) { event = new DocumentLoadEvent(this, eventType, eventData); } + else if (target instanceof MouseListener) { + Assert.assert(target instanceof WCMouseListenerImpl); + + // We create a plain vanilla WebclientEvent, which the + // WCMouseListenerImpl target knows how to deal with. + + // Also, the source happens to be the browserControlCanvas + // to satisfy the java.awt.event.MouseEvent's requirement + // that the source be a java.awt.Component subclass. + + event = new WebclientEvent(browserControlCanvas, eventType, eventData); + } // else... // PENDING(edburns): maybe we need to put this in some sort of diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/WCMouseListenerImpl.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/WCMouseListenerImpl.java new file mode 100644 index 00000000000..e7778153e09 --- /dev/null +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/WCMouseListenerImpl.java @@ -0,0 +1,188 @@ +/* -*- 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.1 (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 and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Ed Burns + */ + +package org.mozilla.webclient.wrapper_native; + +import org.mozilla.util.Assert; +import org.mozilla.util.Log; +import org.mozilla.util.ParameterCheck; + +import java.awt.event.MouseListener; +import java.awt.event.MouseEvent; +import java.awt.Component; +import org.mozilla.webclient.WCMouseEvent; +import org.mozilla.webclient.WebclientEvent; +import org.mozilla.webclient.WebclientEventListener; + +/** + + * This class wraps the user provided instance of + * java.awt.event.MouseListener so it can be installed as a + * WebclientEventListener. Note that we implement MouseListener so we + * can be detected by the webclient event system. We don't do anything + * with these methods here, though. + + */ + +public class WCMouseListenerImpl extends Object implements WebclientEventListener, MouseListener +{ +// +// Protected Constants +// + +// +// Class Variables +// + +// +// Instance Variables +// + +// Attribute Instance Variables + +// Relationship Instance Variables + +/** + + * The MouseListener for which I proxy. + + */ + +protected MouseListener mouseListener; + +// +// Constructors and Initializers +// + +WCMouseListenerImpl(MouseListener yourListener) +{ + super(); + // ParameterCheck.nonNull(); + mouseListener = yourListener; +} + +// +// Class methods +// + +// +// General Methods +// + +MouseListener getMouseListener() +{ + return mouseListener; +} + +// +// Methods from WebclientEventListener +// + +/** + + * Here's where we take the WebclientEvent from mozilla, generate an + * appropriate WCMouseEvent instance, and call the + * appropriate listener event. + + */ + +public void eventDispatched(WebclientEvent event) +{ + ParameterCheck.nonNull(event); + WCMouseEvent mouseEvent; + + switch ((int) event.getType()) { + case (int) WCMouseEvent.MOUSE_DOWN_EVENT_MASK: + mouseEvent = + new WCMouseEvent((Component) event.getSource(), + MouseEvent.MOUSE_PRESSED, -1, + -1, -1, -1, -1, false, event); + mouseListener.mousePressed(mouseEvent); + break; + case (int) WCMouseEvent.MOUSE_UP_EVENT_MASK: + mouseEvent = + new WCMouseEvent((Component) event.getSource(), + MouseEvent.MOUSE_RELEASED, -1, + -1, -1, -1, -1, false, event); + mouseListener.mouseReleased(mouseEvent); + break; + case (int) WCMouseEvent.MOUSE_CLICK_EVENT_MASK: + mouseEvent = + new WCMouseEvent((Component) event.getSource(), + MouseEvent.MOUSE_CLICKED, -1, + -1, -1, -1, 1, false, event); + mouseListener.mouseClicked(mouseEvent); + break; + case (int) WCMouseEvent.MOUSE_DOUBLE_CLICK_EVENT_MASK: + mouseEvent = + new WCMouseEvent((Component) event.getSource(), + MouseEvent.MOUSE_CLICKED, -1, + -1, -1, -1, 2, false, event); + mouseListener.mouseClicked(mouseEvent); + break; + case (int) WCMouseEvent.MOUSE_OVER_EVENT_MASK: + mouseEvent = + new WCMouseEvent((Component) event.getSource(), + MouseEvent.MOUSE_ENTERED, -1, + -1, -1, -1, -1, false, event); + mouseListener.mouseEntered(mouseEvent); + break; + case (int) WCMouseEvent.MOUSE_OUT_EVENT_MASK: + mouseEvent = + new WCMouseEvent((Component) event.getSource(), + MouseEvent.MOUSE_EXITED, -1, + -1, -1, -1, -1, false, event); + mouseListener.mouseExited(mouseEvent); + break; + } +} + +// +// From MouseListener +// + +public void mouseClicked(MouseEvent e) +{ + Assert.assert(false, "This method should not be called."); +} + +public void mouseEntered(MouseEvent e) +{ + Assert.assert(false, "This method should not be called."); +} + +public void mouseExited(MouseEvent e) +{ + Assert.assert(false, "This method should not be called."); +} + +public void mousePressed(MouseEvent e) +{ + Assert.assert(false, "This method should not be called."); +} + +public void mouseReleased(MouseEvent e) +{ + Assert.assert(false, "This method should not be called."); +} + +} // end of class WCMouseListenerImpl diff --git a/mozilla/java/webclient/src_moz/DOMMouseListenerImpl.cpp b/mozilla/java/webclient/src_moz/DOMMouseListenerImpl.cpp new file mode 100644 index 00000000000..c0868a37a68 --- /dev/null +++ b/mozilla/java/webclient/src_moz/DOMMouseListenerImpl.cpp @@ -0,0 +1,385 @@ +/* -*- 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.1 (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 and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Ed Burns + * + */ + +#include "DOMMouseListenerImpl.h" + +#include "nsString.h" +#include "nsFileSpec.h" // for nsAutoCString +#include "nsIDOMNamedNodeMap.h" +#include "DOMMouseListenerImpl.h" +#include "jni_util.h" +#include "dom_util.h" +#include "nsActions.h" + +#include "prprf.h" // for PR_snprintf + +#include "prlog.h" // for PR_ASSERT +#include "ns_globals.h" // for prLogModuleInfo and gComponentManager + +static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID); + +// +// Local functions +// + +jlong DOMMouseListenerImpl::maskValues[] = { -1L }; + +char *DOMMouseListenerImpl::maskNames[] = { + "MOUSE_DOWN_EVENT_MASK", + "MOUSE_UP_EVENT_MASK", + "MOUSE_CLICK_EVENT_MASK", + "MOUSE_DOUBLE_CLICK_EVENT_MASK", + "MOUSE_OVER_EVENT_MASK", + "MOUSE_OUT_EVENT_MASK", + nsnull +}; + +NS_IMPL_ADDREF(DOMMouseListenerImpl); +NS_IMPL_RELEASE(DOMMouseListenerImpl); + +DOMMouseListenerImpl::DOMMouseListenerImpl(){ +} + +DOMMouseListenerImpl::DOMMouseListenerImpl(JNIEnv *env, + WebShellInitContext *yourInitContext, + jobject yourTarget) : + mJNIEnv(env), mInitContext(yourInitContext), mTarget(yourTarget) +{ + if (nsnull == gVm) { // declared in jni_util.h + ::util_GetJavaVM(env, &gVm); // save this vm reference away for the callback! + } +#ifndef BAL_INTERFACE + PR_ASSERT(gVm); +#endif + + if (-1 == maskValues[0]) { + util_InitializeEventMaskValuesFromClass("org/mozilla/webclient/WCMouseEvent", + maskNames, maskValues); + } + mRefCnt = 1; // PENDING(edburns): not sure about how right this is to do. +} + +NS_IMETHODIMP DOMMouseListenerImpl::QueryInterface(REFNSIID aIID, void** aInstance) +{ + if (nsnull == aInstance) + return NS_ERROR_NULL_POINTER; + + *aInstance = nsnull; + + + if (aIID.Equals(NS_GET_IID(nsIDOMMouseListener))) { + *aInstance = (void*) ((nsIDOMMouseListener*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + + + return NS_NOINTERFACE; +} + +/* nsIDOMEventListener methods */ + +nsresult DOMMouseListenerImpl::HandleEvent(nsIDOMEvent* aEvent) +{ + return NS_OK; +} + + /* nsIDOMMouseListener methods */ +nsresult DOMMouseListenerImpl::MouseDown(nsIDOMEvent *aMouseEvent) +{ +#if DEBUG_RAPTOR_CANVAS + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, + ("!DOMMouseListenerImpl::MouseDown\n")); + } +#endif + PR_ASSERT(nsnull != aMouseEvent); + + getPropertiesFromEvent(aMouseEvent); + util_SendEventToJava(mInitContext->env, + mInitContext->nativeEventThread, + mTarget, + maskValues[MOUSE_DOWN_EVENT_MASK], + properties); + util_DestroyPropertiesObject(mInitContext->env, properties, nsnull); + return NS_OK; +} + +nsresult DOMMouseListenerImpl::MouseUp(nsIDOMEvent *aMouseEvent) +{ +#if DEBUG_RAPTOR_CANVAS + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, + ("!DOMMouseListenerImpl::MouseUp\n")); + } +#endif + PR_ASSERT(nsnull != aMouseEvent); + + getPropertiesFromEvent(aMouseEvent); + util_SendEventToJava(mInitContext->env, + mInitContext->nativeEventThread, + mTarget, + maskValues[MOUSE_UP_EVENT_MASK], + properties); + util_DestroyPropertiesObject(mInitContext->env, properties, nsnull); + return NS_OK; +} + +nsresult DOMMouseListenerImpl::MouseClick(nsIDOMEvent *aMouseEvent) +{ +#if DEBUG_RAPTOR_CANVAS + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, + ("!DOMMouseListenerImpl::MouseClick\n")); + } +#endif + PR_ASSERT(nsnull != aMouseEvent); + + getPropertiesFromEvent(aMouseEvent); + util_SendEventToJava(mInitContext->env, + mInitContext->nativeEventThread, + mTarget, + maskValues[MOUSE_CLICK_EVENT_MASK], + properties); + util_DestroyPropertiesObject(mInitContext->env, properties, nsnull); + return NS_OK; +} + +nsresult DOMMouseListenerImpl::MouseDblClick(nsIDOMEvent *aMouseEvent) +{ +#if DEBUG_RAPTOR_CANVAS + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, + ("!DOMMouseListenerImpl::MouseDoubleClick\n")); + } +#endif + PR_ASSERT(nsnull != aMouseEvent); + + getPropertiesFromEvent(aMouseEvent); + util_SendEventToJava(mInitContext->env, + mInitContext->nativeEventThread, + mTarget, + maskValues[MOUSE_DOUBLE_CLICK_EVENT_MASK], + properties); + util_DestroyPropertiesObject(mInitContext->env, properties, nsnull); + return NS_OK; +} + +nsresult DOMMouseListenerImpl::MouseOver(nsIDOMEvent *aMouseEvent) +{ +#if DEBUG_RAPTOR_CANVAS + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, + ("!DOMMouseListenerImpl::MouseOver\n")); + } +#endif + PR_ASSERT(nsnull != aMouseEvent); + + getPropertiesFromEvent(aMouseEvent); + util_SendEventToJava(mInitContext->env, + mInitContext->nativeEventThread, + mTarget, + maskValues[MOUSE_OVER_EVENT_MASK], + properties); + util_DestroyPropertiesObject(mInitContext->env, properties, nsnull); + + return NS_OK; +} + +nsresult DOMMouseListenerImpl::MouseOut(nsIDOMEvent *aMouseEvent) +{ +#if DEBUG_RAPTOR_CANVAS + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, + ("!DOMMouseListenerImpl::MouseOut\n")); + } +#endif + PR_ASSERT(nsnull != aMouseEvent); + + getPropertiesFromEvent(aMouseEvent); + util_SendEventToJava(mInitContext->env, + mInitContext->nativeEventThread, + mTarget, + maskValues[MOUSE_OUT_EVENT_MASK], + properties); + util_DestroyPropertiesObject(mInitContext->env, properties, nsnull); + return NS_OK; +} + +jobject JNICALL DOMMouseListenerImpl::getPropertiesFromEvent(nsIDOMEvent *aMouseEvent) +{ + nsCOMPtr currentNode; + nsresult rv = NS_OK;; + + rv = aMouseEvent->GetTarget(getter_AddRefs(currentNode)); + if (NS_FAILED(rv)) { + return properties; + } + if (nsnull == currentNode) { + return properties; + } + inverseDepth = 0; + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2); + + properties = util_CreatePropertiesObject(env, nsnull); + dom_iterateToRoot(currentNode, DOMMouseListenerImpl::takeActionOnNode, + (void *)this); + return properties; +} + +nsresult JNICALL DOMMouseListenerImpl::takeActionOnNode(nsCOMPtr currentNode, + void *myObject) +{ + nsresult rv = NS_OK; + nsString nodeInfo, nodeName, nodeValue, nodeDepth; + jstring jNodeName, jNodeValue; + PRUint32 depth = -1; + DOMMouseListenerImpl *curThis = nsnull; + const PRUint32 depthStrLen = 20; + char depthStr[depthStrLen]; + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2); + + PR_ASSERT(nsnull != myObject); + curThis = (DOMMouseListenerImpl *) myObject; + depth = curThis->inverseDepth++; + + if (!(curThis->properties)) { + return rv; + } + // encode the depth of the node + PR_snprintf(depthStr, depthStrLen, "depthFromLeaf:%d", depth); + nodeDepth = (const char *) depthStr; + + // Store the name and the value of this node + + { + // get the name and prepend the depth + rv = currentNode->GetNodeName(nodeInfo); + if (NS_FAILED(rv)) { + return rv; + } + // nodeName = nodeDepth; + // nodeName += nodeInfo; + nodeName = nodeInfo; + + if (prLogModuleInfo) { + nsAutoCString nodeInfoCStr(nodeName); + PR_LOG(prLogModuleInfo, 3, ("%s", (const char *)nodeInfoCStr)); + } + + rv = currentNode->GetNodeValue(nodeInfo); + if (NS_FAILED(rv)) { + return rv; + } + // nodeValue = nodeDepth; + // nodeValue += nodeInfo; + nodeValue = nodeInfo; + + if (prLogModuleInfo) { + nsAutoCString nodeInfoCStr(nodeValue); + PR_LOG(prLogModuleInfo, 3, ("%s", (const char *)nodeInfoCStr)); + } + + jNodeName = ::util_NewString(env, nodeName.GetUnicode(), + nodeName.Length()); + jNodeValue = ::util_NewString(env, nodeValue.GetUnicode(), + nodeValue.Length()); + + util_StoreIntoPropertiesObject(env, (jobject) curThis->properties, + (jobject) jNodeName, (jobject) jNodeValue); + if (jNodeName) { + ::util_DeleteString(env, jNodeName); + } + if (jNodeValue) { + ::util_DeleteString(env, jNodeValue); + } + } // end of Storing the name and value of this node + + // store any attributes of this node + { + nsCOMPtr nodeMap; + rv = currentNode->GetAttributes(getter_AddRefs(nodeMap)); + if (NS_FAILED(rv) || !nodeMap) { + return rv; + } + PRUint32 length, i; + rv = nodeMap->GetLength(&length); + if (NS_FAILED(rv)) { + return rv; + } + for (i = 0; i < length; i++) { + rv = nodeMap->Item(i, getter_AddRefs(currentNode)); + + if (nsnull == currentNode) { + return rv; + } + + rv = currentNode->GetNodeName(nodeInfo); + if (NS_FAILED(rv)) { + return rv; + } + // nodeName = nodeDepth; + // nodeName += nodeInfo; + nodeName = nodeInfo; + + if (prLogModuleInfo) { + nsAutoCString nodeInfoCStr(nodeName); + PR_LOG(prLogModuleInfo, 3, + ("attribute[%d], %s", i, (const char *)nodeInfoCStr)); + } + + rv = currentNode->GetNodeValue(nodeInfo); + if (NS_FAILED(rv)) { + return rv; + } + // nodeValue = nodeDepth; + // nodeValue += nodeInfo; + nodeValue = nodeInfo; + + if (prLogModuleInfo) { + nsAutoCString nodeInfoCStr(nodeValue); + PR_LOG(prLogModuleInfo, 3, + ("attribute[%d] %s", i,(const char *)nodeInfoCStr)); + } + jNodeName = ::util_NewString(env, nodeName.GetUnicode(), + nodeName.Length()); + jNodeValue = ::util_NewString(env, nodeValue.GetUnicode(), + nodeValue.Length()); + + util_StoreIntoPropertiesObject(env, (jobject) curThis->properties, + (jobject) jNodeName, (jobject) jNodeValue); + if (jNodeName) { + ::util_DeleteString(env, jNodeName); + } + if (jNodeValue) { + ::util_DeleteString(env, jNodeValue); + } + } + } // end of storing the attributes + + return rv; +} + + + + diff --git a/mozilla/java/webclient/src_moz/DOMMouseListenerImpl.h b/mozilla/java/webclient/src_moz/DOMMouseListenerImpl.h new file mode 100644 index 00000000000..72677674e36 --- /dev/null +++ b/mozilla/java/webclient/src_moz/DOMMouseListenerImpl.h @@ -0,0 +1,145 @@ +/* -*- 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.1 (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 and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Ed Burns + * + */ + +#ifndef DOMMouseListenerImpl_h +#define DOMMouseListenerImpl_h + +#include "nsISupports.h" +#include "nsISupportsUtils.h" +#include "nsString.h" +#include "nsIDOMMouseListener.h" +#include "nsIDOMNode.h" + +#include "jni_util.h" + +class nsIURI; + +/** + + * This class is the shim between the mozilla listener event system for + * mouse events and the java MouseListener interface. + * For each of the Mouse* methods, we call the appropriate method in java. + * See the implementation of MouseOver for an example. + + * For each mouseEvent, we create a Properties object containing + * information about the event. We use methods in dom_util to do this. + + */ + +class DOMMouseListenerImpl : public nsIDOMMouseListener { + NS_DECL_ISUPPORTS +public: + +typedef enum { + MOUSE_DOWN_EVENT_MASK = 0, + MOUSE_UP_EVENT_MASK, + MOUSE_CLICK_EVENT_MASK, + MOUSE_DOUBLE_CLICK_EVENT_MASK, + MOUSE_OVER_EVENT_MASK, + MOUSE_OUT_EVENT_MASK, + NUMBER_OF_MASK_NAMES +} EVENT_MASK_NAMES; + + +#ifdef XP_UNIX +static jlong maskValues [NUMBER_OF_MASK_NAMES]; +#else +static jlong maskValues [DOMMouseListenerImpl::EVENT_MASK_NAMES::NUMBER_OF_MASK_NAMES]; +#endif + +static char *maskNames []; + + DOMMouseListenerImpl(JNIEnv *yourJNIEnv, + WebShellInitContext *yourInitContext, + jobject yourTarget); + + DOMMouseListenerImpl(); + + /* nsIDOMEventListener methods */ + nsresult HandleEvent(nsIDOMEvent* aEvent); + + + /* nsIDOMMouseListener methods */ + + nsresult MouseDown(nsIDOMEvent *aMouseEvent); + + nsresult MouseUp(nsIDOMEvent *aMouseEvent); + + nsresult MouseClick(nsIDOMEvent *aMouseEvent); + + nsresult MouseDblClick(nsIDOMEvent *aMouseEvent); + + nsresult MouseOver(nsIDOMEvent *aMouseEvent); + + nsresult MouseOut(nsIDOMEvent *aMouseEvent); + +// +// Local methods +// + +jobject JNICALL getPropertiesFromEvent(nsIDOMEvent *aMouseEvent); + +static nsresult JNICALL takeActionOnNode(nsCOMPtr curNode, + void *yourObject); + +protected: + + JNIEnv *mJNIEnv; + WebShellInitContext *mInitContext; + jobject mTarget; + +// +// The following arguments are used in the takeActionOnNode method. +// + +/** + + * 0 is the leaf depth. That's why we call it the inverse depth. + + */ + + PRInt32 inverseDepth; + +/** + + * The properties table, created during a mouseEvent handler + + */ + + jobject properties; + +/** + + * the nsIDOMEvent in the current event + + */ + + nsCOMPtr currentDOMEvent; + +// +// End of ivars used in takeActionOnNode +// + +}; + +#endif // DOMMouseListenerImpl_h diff --git a/mozilla/java/webclient/src_moz/DocumentLoaderObserverImpl.cpp b/mozilla/java/webclient/src_moz/DocumentLoaderObserverImpl.cpp index 6ac2b7c98b4..008adccd5cf 100644 --- a/mozilla/java/webclient/src_moz/DocumentLoaderObserverImpl.cpp +++ b/mozilla/java/webclient/src_moz/DocumentLoaderObserverImpl.cpp @@ -28,22 +28,15 @@ #include "DocumentLoaderObserverImpl.h" #include "nsString.h" -#include "DocumentLoaderObserverImpl.h" -#include #include "jni_util.h" +#include "dom_util.h" #include "nsActions.h" -#ifdef XP_PC -// PENDING(edburns): take this out -#include "winbase.h" -// end of take this out -#endif +#include "nsIDOMDocument.h" +#include "nsIDOMEventTarget.h" #include "prlog.h" // for PR_ASSERT -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -static NS_DEFINE_IID(kIDocumentLoaderObserverIID, NS_IDOCUMENT_LOADER_OBSERVER_IID); - jlong DocumentLoaderObserverImpl::maskValues[] = { -1L }; char *DocumentLoaderObserverImpl::maskNames[] = { @@ -58,26 +51,21 @@ char *DocumentLoaderObserverImpl::maskNames[] = { nsnull }; - -/************* -NS_IMETHODIMP_(nsrefcnt) DocumentLoaderObserverImpl::AddRef(void) -{ - NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt"); - ++mRefCnt; - return mRefCnt; -} -**************/ +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIDocumentLoaderObserverIID, NS_IDOCUMENT_LOADER_OBSERVER_IID); +static NS_DEFINE_IID(kIDocumentLoaderObserverImplIID, NS_IDOCLOADEROBSERVERIMPL_IID); NS_IMPL_ADDREF(DocumentLoaderObserverImpl); NS_IMPL_RELEASE(DocumentLoaderObserverImpl); -DocumentLoaderObserverImpl::DocumentLoaderObserverImpl(){ +DocumentLoaderObserverImpl::DocumentLoaderObserverImpl() : mRefCnt(1), +mTarget(nsnull), mMouseListener(nsnull) { } DocumentLoaderObserverImpl::DocumentLoaderObserverImpl(JNIEnv *env, - WebShellInitContext *yourInitContext, - jobject yourTarget) : - mJNIEnv(env), mInitContext(yourInitContext), mTarget(yourTarget) + WebShellInitContext *yourInitContext) : + mJNIEnv(env), mInitContext(yourInitContext), mTarget(nsnull), + mMouseListener(nsnull) { if (nsnull == gVm) { // declared in jni_util.h ::util_GetJavaVM(env, &gVm); // save this vm reference away for the callback! @@ -93,24 +81,30 @@ DocumentLoaderObserverImpl::DocumentLoaderObserverImpl(JNIEnv *env, mRefCnt = 1; // PENDING(edburns): not sure about how right this is to do. } -NS_IMETHODIMP DocumentLoaderObserverImpl::QueryInterface(REFNSIID aIID, void** aInstance) +NS_IMETHODIMP DocumentLoaderObserverImpl::QueryInterface(REFNSIID aIID, + void** aInstance) { - if (nsnull == aInstance) - return NS_ERROR_NULL_POINTER; - - *aInstance = nsnull; - - - if (aIID.Equals(kIDocumentLoaderObserverIID)) { - *aInstance = (void*) ((nsIDocumentLoaderObserver*)this); - NS_ADDREF_THIS(); - return NS_OK; - } - - - return NS_NOINTERFACE; + if (nsnull == aInstance) + return NS_ERROR_NULL_POINTER; + + *aInstance = nsnull; + + + if (aIID.Equals(kIDocumentLoaderObserverIID)) { + *aInstance = (void*) ((nsIDocumentLoaderObserver*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + else if (aIID.Equals(kIDocumentLoaderObserverImplIID)) { + *aInstance = (void*) ((DocumentLoaderObserverImpl*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + + return NS_NOINTERFACE; } + /* nsIDocumentLoaderObserver methods */ NS_IMETHODIMP DocumentLoaderObserverImpl::OnStartDocumentLoad(nsIDocumentLoader* loader, nsIURI* aURL, @@ -122,6 +116,11 @@ NS_IMETHODIMP DocumentLoaderObserverImpl::OnStartDocumentLoad(nsIDocumentLoader* ("DocumentLoaderObserverImpl.cpp: OnStartDocumentLoad\n")); } #endif + // If we don't have a target, don't take any action + if (nsnull == mTarget) { + return NS_OK; + } + char *urlStr = nsnull; jobject urlJStr = nsnull; if (nsnull != aURL) { @@ -141,16 +140,9 @@ NS_IMETHODIMP DocumentLoaderObserverImpl::OnStartDocumentLoad(nsIDocumentLoader* mInitContext->nativeEventThread, mTarget, maskValues[START_DOCUMENT_LOAD_EVENT_MASK], urlJStr); -#ifdef BAL_INTERFACE - // This violates my goal of confining all #ifdef BAL_INTERFACE to - // jni_util files, but this is the only part of the code that knows - // that eventData is a jstring. In java, this will get garbage - // collected, but in non-java contexts, it will not. Thus, we have - // to manually de-allocate it. if (urlJStr) { ::util_DeleteStringUTF(mInitContext->env, (jstring) urlJStr); } -#endif return NS_OK; } @@ -165,6 +157,39 @@ NS_IMETHODIMP DocumentLoaderObserverImpl::OnEndDocumentLoad(nsIDocumentLoader* l ("!!DocumentLoaderObserverImpl.cpp: OnEndDocumentLoad\n")); } #endif + // if we have a mouse listener + if (mMouseListener) { + // install the mouse listener into mozilla + + nsCOMPtr doc; + PR_ASSERT(mMouseListener); + + if (nsnull == loader) { + // NOT really ok, but we can't do anything. + return NS_OK; + } + + if (!(doc = dom_getDocumentFromLoader(loader))) { + // NOT really ok, but we can't do anything. + return NS_OK; + } + nsCOMPtr domEventTarget; + nsresult rv; + + rv = doc->QueryInterface(NS_GET_IID(nsIDOMEventTarget), + getter_AddRefs(domEventTarget)); + if (NS_FAILED(rv) || !domEventTarget) { + return NS_OK; + } + nsAutoString eType("mouseover"); + domEventTarget->AddEventListener(eType, mMouseListener, PR_FALSE); + + } // end of "install mouse listener" + + // If we don't have a target, don't take any action + if (nsnull == mTarget) { + return NS_OK; + } util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mTarget, @@ -181,6 +206,11 @@ NS_IMETHODIMP DocumentLoaderObserverImpl::OnStartURLLoad(nsIDocumentLoader* load ("!DocumentLoaderObserverImpl: OnStartURLLoad\n")); } #endif + // If we don't have a target, don't take any action + if (nsnull == mTarget) { + return NS_OK; + } + util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mTarget, maskValues[START_URL_LOAD_EVENT_MASK], nsnull); @@ -198,6 +228,11 @@ NS_IMETHODIMP DocumentLoaderObserverImpl::OnProgressURLLoad(nsIDocumentLoader* l ("!DocumentLoaderObserverImpl: OnProgressURLLoad\n")); } #endif + // If we don't have a target, don't take any action + if (nsnull == mTarget) { + return NS_OK; + } + util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mTarget, maskValues[PROGRESS_URL_LOAD_EVENT_MASK], nsnull); @@ -216,28 +251,26 @@ NS_IMETHODIMP DocumentLoaderObserverImpl::OnStatusURLLoad(nsIDocumentLoader* loa aMsg.GetUnicode())); } #endif + // If we don't have a target, don't take any action + if (nsnull == mTarget) { + return NS_OK; + } + int length = aMsg.Length(); // IMPORTANT: do not use initContext->env here since it comes // from another thread. Use JNU_GetEnv instead. JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2); - jstring statusMessage = ::util_NewString(env, aMsg.GetUnicode(), length); + jstring statusMessage = ::util_NewString(env, (const jchar *) + aMsg.GetUnicode(), length); util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mTarget, maskValues[STATUS_URL_LOAD_EVENT_MASK], (jobject) statusMessage); -#ifdef BAL_INTERFACE - // This violates my goal of confining all #ifdef BAL_INTERFACE to - // jni_util files, but this is the only part of the code that knows - // that eventData is a jstring. In java, this will get garbage - // collected, but in non-java contexts, it will not. Thus, we have - // to manually de-allocate it. if (statusMessage) { ::util_DeleteString(mInitContext->env, statusMessage); } -#endif - return NS_OK; } @@ -251,6 +284,11 @@ NS_IMETHODIMP DocumentLoaderObserverImpl::OnEndURLLoad(nsIDocumentLoader* loader ("!DocumentLoaderObserverImpl: OnEndURLLoad\n")); } #endif + // If we don't have a target, don't take any action + if (nsnull == mTarget) { + return NS_OK; + } + util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mTarget, maskValues[END_URL_LOAD_EVENT_MASK], nsnull); @@ -268,11 +306,55 @@ NS_IMETHODIMP DocumentLoaderObserverImpl::HandleUnknownContentType(nsIDocumentLo ("!DocumentLoaderObserverImpl: HandleUnknownContentType\n")); } #endif + // If we don't have a target, don't take any action + if (nsnull == mTarget) { + return NS_OK; + } + util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mTarget, maskValues[UNKNOWN_CONTENT_EVENT_MASK], nsnull); return NS_OK; } +// +// Methods from DocumentLoaderObserverImpl +// +NS_IMETHODIMP DocumentLoaderObserverImpl::AddMouseListener(nsCOMPtr toAdd) +{ + nsresult rv = NS_ERROR_FAILURE; + if (nsnull == toAdd) { + return rv; + } + + mMouseListener = toAdd; + + return NS_OK; +} + +NS_IMETHODIMP DocumentLoaderObserverImpl::RemoveMouseListener(nsCOMPtr toRemove) +{ + nsresult rv = NS_ERROR_FAILURE; + + return rv; +} + +NS_IMETHODIMP DocumentLoaderObserverImpl::SetTarget(jobject yourTarget) +{ + nsresult rv = NS_OK; + + mTarget = yourTarget; + + return rv; +} + +NS_IMETHODIMP DocumentLoaderObserverImpl::ClearTarget(void) +{ + nsresult rv = NS_OK; + + mTarget = nsnull; + + return rv; +} diff --git a/mozilla/java/webclient/src_moz/DocumentLoaderObserverImpl.h b/mozilla/java/webclient/src_moz/DocumentLoaderObserverImpl.h index 3536e590630..dcc010bd90f 100644 --- a/mozilla/java/webclient/src_moz/DocumentLoaderObserverImpl.h +++ b/mozilla/java/webclient/src_moz/DocumentLoaderObserverImpl.h @@ -32,11 +32,26 @@ #include "nsISupportsUtils.h" #include "nsString.h" #include "nsIDocumentLoaderObserver.h" - -#include "jni_util.h" +#include "nsIDOMMouseListener.h" class nsIURI; +#include "jni_util.h" +#include "nsCOMPtr.h" + +/** + + * We define a local IID to allow the addDocumentLoadListener and + * addMouseListener functions in EventRegistration.{h,cpp} to + * interrogate the currently installed DocumentLoaderObserver instance + * in mozilla. + + */ + +#define NS_IDOCLOADEROBSERVERIMPL_IID_STR "fdadb2e0-3028-11d4-8a96-0080c7b9c5ba" + +#define NS_IDOCLOADEROBSERVERIMPL_IID {0xfdadb2e0, 0x3028, 0x11d4, { 0x8a, 0x96, 0x00, 0x80, 0xc7, 0xb9, 0xc5, 0xba }} + /** * This class is the shim between the mozilla listener event system for @@ -44,6 +59,15 @@ class nsIURI; * For each of the On* methods, we call the appropriate method in java. * See the implementation of OnEndDocumentLoad for an example. + * A DocumentLoaderObserverImpl instance has a "jobject target", which + * is the Java object that should ultimately receive the events. This + * target will be null if the user just wants to listen for mouse + * events. It willl be non-null if the user wants to listen for + * DocumentLoad events. + + * It also hosts a nsIDOMMouseListener instance, which piggybacks on the + * nsIDocumentLoaderObserver instance. + */ class DocumentLoaderObserverImpl : public nsIDocumentLoaderObserver { @@ -72,10 +96,10 @@ static jlong maskValues [DocumentLoaderObserverImpl::EVENT_MASK_NAMES::NUMBER_OF static char *maskNames []; DocumentLoaderObserverImpl(JNIEnv *yourJNIEnv, - WebShellInitContext *yourInitContext, - jobject yourTarget); + WebShellInitContext *yourInitContext); DocumentLoaderObserverImpl(); + virtual ~DocumentLoaderObserverImpl() {}; /* nsIDocumentLoaderObserver methods */ NS_IMETHOD OnStartDocumentLoad(nsIDocumentLoader* loader, @@ -107,11 +131,30 @@ static char *maskNames []; const char *aContentType, const char *aCommand); +// +// Methods for NS_IDOCLOADEROBSERVERIMPL_IID +// + +/** + + * Called in EventRegistration.{h,cpp} addMouseListener. + + */ + + NS_IMETHOD AddMouseListener(nsCOMPtr toAdd); + + NS_IMETHOD RemoveMouseListener(nsCOMPtr toRemove); + + NS_IMETHOD SetTarget(jobject newTarget); + + NS_IMETHOD ClearTarget(void); + protected: JNIEnv *mJNIEnv; WebShellInitContext *mInitContext; jobject mTarget; + nsCOMPtr mMouseListener; }; diff --git a/mozilla/java/webclient/src_moz/EventRegistration.cpp b/mozilla/java/webclient/src_moz/EventRegistration.cpp index b206110300a..e07a9c4c879 100644 --- a/mozilla/java/webclient/src_moz/EventRegistration.cpp +++ b/mozilla/java/webclient/src_moz/EventRegistration.cpp @@ -28,7 +28,11 @@ #include "EventRegistration.h" #include "nsActions.h" +#include "nsCOMPtr.h" #include "DocumentLoaderObserverImpl.h" +#include "DOMMouseListenerImpl.h" + +static NS_DEFINE_IID(kIDocumentLoaderObserverImplIID, NS_IDOCLOADEROBSERVERIMPL_IID); void addDocumentLoadListener(JNIEnv *env, WebShellInitContext *initContext, jobject listener) @@ -39,19 +43,101 @@ void addDocumentLoadListener(JNIEnv *env, WebShellInitContext *initContext, } if (initContext->initComplete) { - // Assert (nsnull != initContext->nativeEventThread) + + + PR_ASSERT(initContext->nativeEventThread); + nsresult rv; + nsCOMPtr curObserver; + nsCOMPtr myListener = nsnull; - // create the c++ "peer" for the DocumentLoadListener, which is an - // nsIDocumentLoaderObserver. - DocumentLoaderObserverImpl *observerImpl = - new DocumentLoaderObserverImpl(env, initContext, listener); - - wsAddDocLoaderObserverEvent *actionEvent = - new wsAddDocLoaderObserverEvent(initContext->docShell, - observerImpl); - - PLEvent * event = (PLEvent*) *actionEvent; - - ::util_PostEvent(initContext, event); + PR_ASSERT(nsnull != initContext->docShell); + + // tricky logic to accomodate "piggybacking" a mouseListener. + + // See if there already is a DocListener + rv = initContext->docShell->GetDocLoaderObserver(getter_AddRefs(curObserver)); + if (NS_FAILED(rv) || !curObserver) { + // if there is no listener, we need to create and add it now + + // create the c++ "peer" for the DocumentLoadListener, which is an + // nsIDocumentLoaderObserver. + curObserver = new DocumentLoaderObserverImpl(env, initContext); + if (nsnull == curObserver) { + return; + } + + wsAddDocLoaderObserverEvent *actionEvent = + new wsAddDocLoaderObserverEvent(initContext->docShell, + curObserver); + + PLEvent * event = (PLEvent*) *actionEvent; + + ::util_PostSynchronousEvent(initContext, event); + } + + if (curObserver) { + // if we have an observer (either just created, or from mozilla), + // install the target. + + rv = curObserver->QueryInterface(kIDocumentLoaderObserverImplIID, + getter_AddRefs(myListener)); + if (NS_SUCCEEDED(rv) && myListener) { + myListener->SetTarget(listener); + } + } + } +} + +void addMouseListener(JNIEnv *env, WebShellInitContext *initContext, + jobject listener) +{ + if (initContext == nsnull) { + ::util_ThrowExceptionToJava(env, "Exception: null initContext passed toaddDocumentLoadListener"); + return; + } + + if (initContext->initComplete) { + nsresult rv; + nsCOMPtr curObserver; + nsCOMPtr myListener = nsnull; + + PR_ASSERT(nsnull != initContext->docShell); + + // See if there already is a DocListener + rv = initContext->docShell->GetDocLoaderObserver(getter_AddRefs(curObserver)); + if (NS_SUCCEEDED(rv) && curObserver) { + + // if so, se if it's something we added + rv = curObserver->QueryInterface(kIDocumentLoaderObserverImplIID, + getter_AddRefs(myListener)); + } + else { + + // if not, we need to create a listener + myListener = new DocumentLoaderObserverImpl(env, initContext); + // note that we don't call setTarget, since this + // DocumentLoaderObserver is just for getting mouse events + + // install our listener into mozilla + wsAddDocLoaderObserverEvent *actionEvent = + new wsAddDocLoaderObserverEvent(initContext->docShell, + myListener); + + PLEvent * event = (PLEvent*) *actionEvent; + + ::util_PostSynchronousEvent(initContext, event); + } + + if (nsnull == myListener) { + // either the new failed, or the currently installed listener + // wasn't installed by us. Either way, do nothing. + return; + } + // we have a listener + + nsCOMPtr mouseListener = + new DOMMouseListenerImpl(env, initContext, listener); + + myListener->AddMouseListener(mouseListener); } } diff --git a/mozilla/java/webclient/src_moz/EventRegistration.h b/mozilla/java/webclient/src_moz/EventRegistration.h index 728890b33da..08385a8ced2 100644 --- a/mozilla/java/webclient/src_moz/EventRegistration.h +++ b/mozilla/java/webclient/src_moz/EventRegistration.h @@ -51,6 +51,24 @@ */ void addDocumentLoadListener(JNIEnv *env, WebShellInitContext *initContext, - jobject listener); + jobject listener); + +/** + + * This function creates an instance of DOMMouseListenerImpl, + * which is the shim between the mozilla nsIDOMMouseListener class + * and the Java MouseListener interface. See + * DocumentLoaderObserverImpl.h + + * PENDING(): implement removeMouseListener + + * PENDING(): implement the ability to have multiple listener instances + * per listener types, all of which get notified. + + */ + +void addMouseListener(JNIEnv *env, WebShellInitContext *initContext, + jobject listener); + #endif diff --git a/mozilla/java/webclient/src_moz/Makefile.solaris b/mozilla/java/webclient/src_moz/Makefile.solaris index a4b42749b51..3534acd58ab 100755 --- a/mozilla/java/webclient/src_moz/Makefile.solaris +++ b/mozilla/java/webclient/src_moz/Makefile.solaris @@ -8,6 +8,8 @@ DLLNAMESTUB = libwebclientstub.so MOZILLA_TOP = ../../.. DIST = ${MOZILLA_TOP}/dist LIBDIR = ${DIST}/lib +#CC = gcc -g -fno-rtti -fno-exceptions -pedantic -Wno-long-long +#MKSHLIB = c++ -G CC = CC -pic MKSHLIB = CC -G # WARNING: YOU NEED TO RUN 'gtk-config --cflags' and stick it in here @@ -115,6 +117,9 @@ jni_util.o: jni_util.cpp jni_util_export.o: jni_util_export.cpp ${CC} ${DEFINES} ${INCLUDE} -c jni_util_export.cpp +bal_util.o: bal_util.cpp + ${CC} ${DEFINES} ${INCLUDE} -c bal_util.cpp + rdf_util.o: rdf_util.cpp ${CC} ${DEFINES} ${INCLUDE} -c rdf_util.cpp diff --git a/mozilla/java/webclient/src_moz/Makefile.win b/mozilla/java/webclient/src_moz/Makefile.win index 5894bdd19fe..d3c7715a3b2 100644 --- a/mozilla/java/webclient/src_moz/Makefile.win +++ b/mozilla/java/webclient/src_moz/Makefile.win @@ -32,10 +32,12 @@ OBJS = \ .\$(OBJDIR)\jni_util.obj \ .\$(OBJDIR)\jni_util_export.obj \ .\$(OBJDIR)\rdf_util.obj \ + .\$(OBJDIR)\dom_util.obj \ .\$(OBJDIR)\nsActions.obj \ .\$(OBJDIR)\BookmarksImpl.obj \ .\$(OBJDIR)\CurrentPageImpl.obj \ .\$(OBJDIR)\DocumentLoaderObserverImpl.obj \ + .\$(OBJDIR)\DOMMouseListenerImpl.obj \ .\$(OBJDIR)\EventRegistration.obj \ .\$(OBJDIR)\HistoryImpl.obj \ .\$(OBJDIR)\WrapperFactoryImpl.obj \ @@ -76,6 +78,7 @@ LLIBS = \ $(DIST)\lib\nsreg.lib \ $(DIST)\lib\nspr3.lib \ $(DIST)\lib\plds3.lib \ + $(DIST)\lib\plc3.lib \ # $(DEPTH)\xpfe\bootstrap\$(OBJDIR)\nsSetupRegistry.obj \ $(NULL) diff --git a/mozilla/java/webclient/src_moz/NativeEventThread.cpp b/mozilla/java/webclient/src_moz/NativeEventThread.cpp index 3e42d9b5ba8..cf2f7de18ea 100644 --- a/mozilla/java/webclient/src_moz/NativeEventThread.cpp +++ b/mozilla/java/webclient/src_moz/NativeEventThread.cpp @@ -110,6 +110,7 @@ char * errorMessages[] = { const char *gSupportedListenerInterfaces[] = { "org/mozilla/webclient/DocumentLoadListener", + "java/awt/event/MouseListener", nsnull }; @@ -118,6 +119,7 @@ const char *gSupportedListenerInterfaces[] = { typedef enum { DOCUMENT_LOAD_LISTENER = 0, + MOUSE_LISTENER, LISTENER_NOT_FOUND } LISTENER_CLASSES; @@ -245,6 +247,9 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThr case DOCUMENT_LOAD_LISTENER: addDocumentLoadListener(env, initContext, globalRef); break; + case MOUSE_LISTENER: + addMouseListener(env, initContext, globalRef); + break; } } diff --git a/mozilla/java/webclient/src_moz/NavigationImpl.cpp b/mozilla/java/webclient/src_moz/NavigationImpl.cpp index 4d6c754ea0a..18894f7d245 100644 --- a/mozilla/java/webclient/src_moz/NavigationImpl.cpp +++ b/mozilla/java/webclient/src_moz/NavigationImpl.cpp @@ -52,7 +52,7 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NavigationImpl if (::util_ExceptionOccurred(env)) { ::util_ThrowExceptionToJava(env, "raptorWebShellLoadURL Exception: unable to extract Java string"); if (urlStringChars != nsnull) - ::util_ReleaseStringChars(env, urlString, urlStringChars); + ::util_ReleaseStringChars(env, urlString, (const jchar *) urlStringChars); return; } @@ -61,7 +61,7 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NavigationImpl if (initContext == nsnull) { ::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellLoadURL"); if (urlStringChars != nsnull) - ::util_ReleaseStringChars(env, urlString, urlStringChars); + ::util_ReleaseStringChars(env, urlString, (const jchar *) urlStringChars); return; } @@ -72,7 +72,7 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NavigationImpl ::util_PostEvent(initContext, event); } - ::util_ReleaseStringChars(env, urlString, urlStringChars); + ::util_ReleaseStringChars(env, urlString, (const jchar *) urlStringChars); } JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NavigationImpl_nativeRefresh diff --git a/mozilla/java/webclient/src_moz/RDFTreeNode.cpp b/mozilla/java/webclient/src_moz/RDFTreeNode.cpp index f048132b6dd..728de927911 100644 --- a/mozilla/java/webclient/src_moz/RDFTreeNode.cpp +++ b/mozilla/java/webclient/src_moz/RDFTreeNode.cpp @@ -233,7 +233,7 @@ Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeToString length = string->Length(); } - result = ::util_NewString(env, textForNode, length); + result = ::util_NewString(env, (const jchar *) textForNode, length); } else { result = ::util_NewStringUTF(env, ""); diff --git a/mozilla/java/webclient/src_moz/bal_util.cpp b/mozilla/java/webclient/src_moz/bal_util.cpp index 29987545ad2..25f31812163 100644 --- a/mozilla/java/webclient/src_moz/bal_util.cpp +++ b/mozilla/java/webclient/src_moz/bal_util.cpp @@ -32,6 +32,8 @@ #include "bal_util.h" +#include "wchar.h" + void JNICALL bal_jstring_newFromAscii(jstring *newStr, const char *value) { jint length; diff --git a/mozilla/java/webclient/src_moz/dom_util.cpp b/mozilla/java/webclient/src_moz/dom_util.cpp new file mode 100644 index 00000000000..c52b80d617b --- /dev/null +++ b/mozilla/java/webclient/src_moz/dom_util.cpp @@ -0,0 +1,114 @@ +/* -*- 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.1 (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 and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Ed Burns + */ + +#include "dom_util.h" + +#include "ns_globals.h" // for prLogModuleInfo and gComponentManager + +#include "prlog.h" // for PR_ASSERT + +#include "nsIDocShell.h" +#include "nsIContentViewer.h" +#include "nsIDocumentViewer.h" +#include "nsIDocument.h" +#include "nsIDOMDocument.h" +#include "nsIDocumentLoader.h" +#include "nsIDOMEventTarget.h" + +nsresult dom_iterateToRoot(nsCOMPtr currentNode, + fpTakeActionOnNodeType nodeFunction, + void *yourObject) +{ + nsCOMPtr parentNode; + nsresult rv; + + if (nodeFunction) { + rv = nodeFunction(currentNode, yourObject); + } + if (NS_FAILED(rv)) { + return rv; + } + rv = currentNode->GetParentNode(getter_AddRefs(parentNode)); + if (NS_FAILED(rv)) { + return rv; + } + if (nsnull == parentNode) { + return rv; + } + dom_iterateToRoot(parentNode, nodeFunction, yourObject); + return rv; +} + +nsCOMPtr dom_getDocumentFromLoader(nsIDocumentLoader *loader) +{ + PR_ASSERT(nsnull != loader); + nsresult rv; + + nsCOMPtr container; + nsCOMPtr docShell; + nsCOMPtr result = nsnull; + + rv = loader->GetContainer(getter_AddRefs(container)); + if (NS_FAILED(rv) || !container) { + return result; + } + + rv = container->QueryInterface(NS_GET_IID(nsIDocShell), + getter_AddRefs(docShell)); + if (NS_FAILED(rv) || !docShell) { + return result; + } + result = dom_getDocumentFromDocShell(docShell); + + return result; +} + +nsCOMPtr dom_getDocumentFromDocShell(nsIDocShell *docShell) +{ + PR_ASSERT(nsnull != docShell); + nsCOMPtr result = nsnull; + nsCOMPtr contentv; + nsCOMPtr docv; + nsIDocument *document; // PENDING(edburns): does GetDocument do an AddRef? + nsresult rv; + + rv = docShell->GetContentViewer(getter_AddRefs(contentv)); + if (NS_FAILED(rv) || !contentv) { + return result; + } + + rv = contentv->QueryInterface(NS_GET_IID(nsIDocumentViewer), + getter_AddRefs(docv)); + if (NS_FAILED(rv) || !docv) { + return result; + } + + rv = docv->GetDocument(document); + if (NS_FAILED(rv) || !document) { + return result; + } + + rv = document->QueryInterface(NS_GET_IID(nsIDOMDocument), + getter_AddRefs(result)); + + return result; +} diff --git a/mozilla/java/webclient/src_moz/dom_util.h b/mozilla/java/webclient/src_moz/dom_util.h new file mode 100644 index 00000000000..d2741b19fef --- /dev/null +++ b/mozilla/java/webclient/src_moz/dom_util.h @@ -0,0 +1,77 @@ +/* -*- 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.1 (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 and + * Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are + * Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All + * Rights Reserved. + * + * Contributor(s): Ed Burns + */ + +#ifndef dom_util_h +#define dom_util_h + +#include // for JNICALL + +#include "nsCOMPtr.h" +#include "nsIDOMNode.h" +class nsIDocumentLoader; +class nsIDocShell; + +/** + + * Methods to simplify webclient accessing the mozilla DOM. + + */ + +/** + + * Used in conjunction with dom_iterateToRoot to allow action to be + * taken on each node in a path from a node to the root. + + */ + +typedef nsresult (JNICALL *fpTakeActionOnNodeType) (nsCOMPtr curNode, + void *yourObject); + +/** + + * Starting from startNode, recursively ascend the DOM tree to the root, + * calling the user provided function at each node, passing the user + * provided object to the function. + + */ + +nsresult dom_iterateToRoot(nsCOMPtr startNode, + fpTakeActionOnNodeType nodeFunction, + void *yourObject); + +/** + + * Given an nsIDocumentLoader instance, obtain the nsIDOMDocument instance. + + */ + +nsCOMPtr dom_getDocumentFromLoader(nsIDocumentLoader *loader); + +/** + + * Given an nsIDocShell instance, obtain the nsIDOMDocument instance. + + */ + +nsCOMPtr dom_getDocumentFromDocShell(nsIDocShell *docShell); + +#endif // dom_util_h diff --git a/mozilla/java/webclient/src_moz/jni_util.cpp b/mozilla/java/webclient/src_moz/jni_util.cpp index 61c2e1f7c1e..44f5285820b 100644 --- a/mozilla/java/webclient/src_moz/jni_util.cpp +++ b/mozilla/java/webclient/src_moz/jni_util.cpp @@ -25,11 +25,21 @@ * Ann Sunhachawee */ +#include "prlog.h" // for PR_ASSERT + #include "jni_util.h" JavaVM *gVm = nsnull; // declared in ns_globals.h, which is included in // jni_util.h +// +// Local cache variables of JNI data items +// + +static jclass gPropertiesClass = nsnull; +static jmethodID gPropertiesInitMethodID = nsnull; +static jmethodID gPropertiesSetPropertyMethodID = nsnull; + void util_ThrowExceptionToJava (JNIEnv * env, const char * message) { if (env->ExceptionOccurred()) { @@ -358,7 +368,73 @@ void util_SetIntValueForInstance(JNIEnv *env, jobject obj, #endif; } +jobject util_CreatePropertiesObject(JNIEnv *env, jobject reserved_NotUsed) +{ + jobject result = nsnull; +#ifdef BAL_INTERFACE + if (nsnull != externalCreatePropertiesObject) { + result = externalCreatePropertiesObject(env, reserved_NotUsed); + } +#else + // For some reason, we have to do FindClass each time. If we try to + // cache the class, it crashes. I think this may have something to + // do with threading issues. + if (nsnull == (gPropertiesClass + = ::util_FindClass(env, "java/util/Properties"))) { + return result; + } + + if (nsnull == gPropertiesInitMethodID) { + if (nsnull == (gPropertiesInitMethodID = + env->GetMethodID(gPropertiesClass, "", "()V"))) { + return result; + } + } + result = env->NewObject(gPropertiesClass, gPropertiesInitMethodID); + +#endif + return result; +} + +void util_DestroyPropertiesObject(JNIEnv *env, jobject propertiesObject, + jobject reserved_NotUsed) +{ +#ifdef BAL_INTERFACE + if (nsnull != externalDestroyPropertiesObject) { + externalDestroyPropertiesObject(env, propertiesObject, + reserved_NotUsed); + } +#else +#endif +} + +void util_StoreIntoPropertiesObject(JNIEnv *env, jobject propertiesObject, + jobject name, jobject value) +{ +#ifdef BAL_INTERFACE + if (nsnull != externalStoreIntoPropertiesObject) { + externalStoreIntoPropertiesObject(env, propertiesObject, name, value); + } +#else + if (nsnull == gPropertiesSetPropertyMethodID) { + PR_ASSERT(gPropertiesClass); + if (nsnull == (gPropertiesSetPropertyMethodID = + env->GetMethodID(gPropertiesClass, + "setProperty", + "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;"))) { + return; + } + } + PR_ASSERT(gPropertiesSetPropertyMethodID); + + env->CallObjectMethod(propertiesObject, gPropertiesSetPropertyMethodID, + name, value); + + + +#endif +} JNIEXPORT jvalue JNICALL JNU_CallMethodByName(JNIEnv *env, diff --git a/mozilla/java/webclient/src_moz/jni_util.h b/mozilla/java/webclient/src_moz/jni_util.h index b2a56c0bdd6..98b5e4772d3 100644 --- a/mozilla/java/webclient/src_moz/jni_util.h +++ b/mozilla/java/webclient/src_moz/jni_util.h @@ -182,6 +182,34 @@ jint util_GetIntValueFromInstance(JNIEnv *env, jobject instance, void util_SetIntValueForInstance(JNIEnv *env, jobject instance, const char *fieldName, jint newValue); +/** + + * A JNI wrapper to create a java.util.Properties object, or the + * equivalent object in the BAL case. + + */ + +jobject util_CreatePropertiesObject(JNIEnv *env, jobject reserved_NotUsed); + +/** + + * A JNI wrapper to destroy the object from CreatePropertiesObject + + */ + +void util_DestroyPropertiesObject(JNIEnv *env, jobject propertiesObject, + jobject reserved_NotUsed); + +/** + + * A JNI wrapper for storing a name/value pair into the Properties + * object created by CreatePropertiesObject + + */ + +void util_StoreIntoPropertiesObject(JNIEnv *env, jobject propertiesObject, + jobject name, jobject value); + // // Functions from secret JDK files diff --git a/mozilla/java/webclient/src_moz/jni_util_export.cpp b/mozilla/java/webclient/src_moz/jni_util_export.cpp index e7cfc27b216..58e38780455 100644 --- a/mozilla/java/webclient/src_moz/jni_util_export.cpp +++ b/mozilla/java/webclient/src_moz/jni_util_export.cpp @@ -40,6 +40,12 @@ fpInstanceOfType externalInstanceOf = nsnull; // jni_util_export.h fpInitializeEventMaskType externalInitializeEventMask = nsnull; // jni_util_export.h +fpCreatePropertiesObjectType externalCreatePropertiesObject = nsnull; // jni_util_export.h + +fpDestroyPropertiesObjectType externalDestroyPropertiesObject = nsnull; // jni_util_export.h + +fpStoreIntoPropertiesObjectType externalStoreIntoPropertiesObject = nsnull; // jni_util_export.h + JNIEXPORT const char * JNICALL util_GetStringUTFChars(JNIEnv *env, jstring inString) { @@ -114,10 +120,7 @@ JNIEXPORT void JNICALL util_DeleteStringUTF(JNIEnv *env, jstring toDelete) #ifdef BAL_INTERFACE util_DeleteString(env, toDelete); #else - if (prLogModuleInfo) { - PR_LOG(prLogModuleInfo, 3, - ("This shouldn't get called in a non-BAL context!\n")); - } + // do nothing, java takes care of it #endif } @@ -140,10 +143,7 @@ JNIEXPORT void JNICALL util_DeleteString(JNIEnv *env, jstring toDelete) #ifdef BAL_INTERFACE bal_jstring_release(toDelete); #else - if (prLogModuleInfo) { - PR_LOG(prLogModuleInfo, 3, - ("This shouldn't get called in a non-BAL context!\n")); - } + // do nothing, java takes care of it #endif } @@ -193,6 +193,21 @@ JNIEXPORT void JNICALL util_SetInitializeEventMaskFunction(fpInitializeEventMask externalInitializeEventMask = fp; } +JNIEXPORT void JNICALL util_SetCreatePropertiesObjectFunction(fpCreatePropertiesObjectType fp) +{ + externalCreatePropertiesObject = fp; +} + +JNIEXPORT void JNICALL util_SetDestroyPropertiesObjectFunction(fpDestroyPropertiesObjectType fp) +{ + externalDestroyPropertiesObject = fp; +} + +JNIEXPORT void JNICALL util_SetStoreIntoPropertiesObjectFunction(fpStoreIntoPropertiesObjectType fp) +{ + externalStoreIntoPropertiesObject = fp; +} + JNIEXPORT void JNICALL util_InitializeEventMaskValuesFromClass(const char *className, char *maskNames[], diff --git a/mozilla/java/webclient/src_moz/jni_util_export.h b/mozilla/java/webclient/src_moz/jni_util_export.h index 5d50c970547..4f419728ed4 100644 --- a/mozilla/java/webclient/src_moz/jni_util_export.h +++ b/mozilla/java/webclient/src_moz/jni_util_export.h @@ -149,7 +149,48 @@ typedef JNIEXPORT void (JNICALL * fpInitializeEventMaskType) jclass listenerClass, const char **nullTermMaskNameArray, jlong *maskValueArray); - + +/** + + * Called when webclient wants to create a "Properties" object. Right + * now, no parameters are actually used. + + */ + +typedef JNIEXPORT jobject (JNICALL * fpCreatePropertiesObjectType) + (JNIEnv *env, jobject reserved_NotUsed); + +/** + + * Called after webclient is done using a "Properties" object it created + * with fpCreatePropertiesObject + + * @param propertiesObject the propertiesObject created with + * fpCreatePropertiesObject + + */ + +typedef JNIEXPORT void (JNICALL * fpDestroyPropertiesObjectType) + (JNIEnv *env, jobject propertiesObject, jobject reserved_NotUsed); + +/** + + * Called after webclient has called fpCreatePropertiesObjectType when + * webclient wants to store values into the properties object. + + * @param env not used + + * @param propertiesObject obtained from fpCreatePropertiesObjectType + + * @param name the name of the property + + * @param the value of the property + + */ + +typedef JNIEXPORT void (JNICALL * fpStoreIntoPropertiesObjectType) + (JNIEnv *env, jobject propertiesObject, jobject name, jobject value); + /** * This function must be called at app initialization. @@ -180,6 +221,37 @@ JNIEXPORT void JNICALL util_SetEventOccurredFunction(fpEventOccurredType fp); JNIEXPORT void JNICALL util_SetInitializeEventMaskFunction(fpInitializeEventMaskType fp); +/** + + * This function must be called at app initialization. + + * @see fpCreatePropertiesObjectType + + */ + +JNIEXPORT void JNICALL util_SetCreatePropertiesObjectFunction(fpCreatePropertiesObjectType fp); + +/** + + * This function must be called at app initialization. + + * @see fpDestroyPropertiesObjectType + + */ + +JNIEXPORT void JNICALL util_SetDestroyPropertiesObjectFunction(fpDestroyPropertiesObjectType fp); + +/** + + * This function must be called at app initialization. + + * @see fpStoreIntoPropertiesObjectType + + */ + +JNIEXPORT void JNICALL util_SetStoreIntoPropertiesObjectFunction(fpStoreIntoPropertiesObjectType fp); + + /** @@ -211,6 +283,36 @@ extern fpInstanceOfType externalInstanceOf; extern fpInitializeEventMaskType externalInitializeEventMask; +/** + + * defined in jni_util_export.cpp + + * The function pointer set with util_SetCreatePropertiesObjectFunction + + */ + +extern fpCreatePropertiesObjectType externalCreatePropertiesObject; + +/** + + * defined in jni_util_export.cpp + + * The function pointer set with util_SetDestroyPropertiesObjectFunction + + */ + +extern fpDestroyPropertiesObjectType externalDestroyPropertiesObject; + +/** + + * defined in jni_util_export.cpp + + * The function pointer set with util_SetStoreIntoPropertiesObjectFunction + + */ + +extern fpStoreIntoPropertiesObjectType externalStoreIntoPropertiesObject; + /** * Called by the mozilla event listener implementation class at