a=edburns
r=drapeau

This checkin creates a dependency on the mozilla java dom module.

Please see mozilla\java\dom\README to build the java dom.
Note that you can just run make in mozilla\java and everything
should be built correctly.

A webclient/classes_spec/org/mozilla/webclient/test/DOMAccessPanel.java
A webclient/classes_spec/org/mozilla/webclient/test/DOMCellRenderer.java
A webclient/classes_spec/org/mozilla/webclient/test/DOMTreeDumper.java
A webclient/classes_spec/org/mozilla/webclient/test/DOMTreeModel.java
A webclient/classes_spec/org/mozilla/webclient/test/DOMTreeNotifier.java
A webclient/classes_spec/org/mozilla/webclient/test/DOMViewerFrame.java

M Makefile.win
M README
M webclient/classes_spec/Makefile.unix
M webclient/classes_spec/Makefile.win
M webclient/classes_spec/org/mozilla/webclient/CurrentPage.java
M webclient/classes_spec/org/mozilla/webclient/test/EMWindow.java
M webclient/classes_spec/org/mozilla/webclient/wrapper_native/CurrentPageImpl.java
M webclient/src_moz/CurrentPageImpl.cpp
M webclient/src_moz/DocumentLoaderObserverImpl.cpp
M webclient/src_moz/Makefile.win
M webclient/src_moz/WindowControlImpl.cpp
M webclient/src_moz/jni_util.h
This commit is contained in:
edburns%acm.org 2000-06-04 22:16:36 +00:00
Родитель 6f007914b8
Коммит baf982031b
18 изменённых файлов: 1603 добавлений и 549 удалений

Просмотреть файл

@ -36,6 +36,7 @@ IGNORE_MANIFEST=1
DEPTH = ..
DIRS = util \
dom \
webclient
include <$(DEPTH)\config\rules.mak>

Просмотреть файл

@ -4,23 +4,19 @@ Authors: see the README files for each individual subdirectory
Requirements:
* JDK1.1.7 or greater (may work with lower versions, haven't checked).
* JDK1.2 or greater (may work with lower versions, haven't checked).
* M8 or post M8 mozilla tree
* Successfully built MOZ_DEBUG=1 Mozilla M13 tree.
* Perl 5 perl.exe must be in your path
How To Build:
* make it so the directory in which this file resides is a child of your
top level mozilla directory
* Copy the files .\config\buildpkg.bat and
.\config\outofdate.pl to mozilla\config. These file were
modified after M8 and the modifications are required to build java.
top level Mozilla M13 directory
* make sure the environment var JDKHOME is set to your jdk installation
directory, ie SET JDKHOME=C:\jdk1.1.8
directory, ie SET JDKHOME=C:\jdk1.2.2
* type "nmake /f makefile.win all" and hope for the best

Просмотреть файл

@ -7,7 +7,7 @@ JAVAC = ${JDK_LOCATION}/bin/javac
JAVAH = ${JDK_LOCATION}/bin/javah
OUTPUT_DIR = ../../../dist/classes
# If you're using JDK 1.2
CLASSES = ${OUTPUT_DIR}:${JDK_LOCATION}/lib/tools.jar:${JDK_LOCATION}/lib/rt.jar
CLASSES = ${OUTPUT_DIR}:${JDK_LOCATION}/lib/tools.jar:${JDK_LOCATION}/lib/rt.jar:${CLASSPATH}
JAVA_FILES = ./org/mozilla/webclient/*.java ./org/mozilla/webclient/wrapper_native/*.java ./org/mozilla/webclient/wrapper_native/motif/*.java ./org/mozilla/webclient/test/*.java
JAVAH_OUTPUT_DIR = ../src_moz
CP = cp

Просмотреть файл

@ -62,9 +62,21 @@ WEBCLIENT_JAR_NAME=webclient(VERSION_NUMBER).jar
JAVAC_PROG=$(JDKHOME)\bin\javac
export::
@echo +++ NOTE, you must have the org.w3c.dom classes in your classpath!
@echo +++ If you do not have org.w3c.dom classes, webclient will not build.
@echo +++ You can get the required dom classes at
@echo +++ http://www.mozilla.org/projects/blackwood/webclient/bin/m3/dom2-20000307.jar
@echo +++
@echo +++ checking that org.mozilla.dom classes have been built...
if not exist $(MOZ_SRC)\mozilla\dist\classes\org\mozilla\dom\DOMAccessor.class \
stopbuild.exe
@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
!ifdef CLASSPATH
JAVAC_CLASSPATH=$(JAVAC_CLASSPATH);$(CLASSPATH)
!endif
include <$(DEPTH)\config\rules.mak>

Просмотреть файл

@ -23,6 +23,7 @@
package org.mozilla.webclient;
import java.util.Properties;
import org.w3c.dom.Document;
public interface CurrentPage
{
@ -34,7 +35,7 @@ public void findNextInPage(boolean forward);
public String getCurrentURL();
// org.w3c.dom.Document getDOM();
public Document getDOM();
public Properties getPageInfo();

Просмотреть файл

@ -0,0 +1,395 @@
/*
* 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.
*
* Contributor(s): Denis Sharypov <sdv@sparc.spb.su>
* Igor Kushnirskiy <idk@eng.sun.com>
*/
package org.mozilla.webclient.test;
import java.awt.*;
import java.awt.event.*;
import org.w3c.dom.*;
import org.mozilla.dom.*;
import javax.swing.*;
import javax.swing.tree.*; //idk
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.JFileChooser;
public class DOMAccessPanel extends JPanel implements ActionListener, ItemListener, TreeSelectionListener {
private JTextField name, aValue;
private JComboBox type, aName;
private JTextArea value;
private JButton newNode, insert, append, remove, set, removeAttr, save;
private Node node, prv;
private NamedNodeMap attrMap;
private boolean updating;
private String[] types = {
"ELEMENT",
"ATTRIBUTE",
"TEXT",
"CDATA_SECTION",
"ENTITY_REF",
"ENTITY",
"PROC_INSTR",
"COMMENT",
"DOCUMENT",
"DOCUMENT_TYPE",
"DOC_FRAGM",
"NOTATION"
};
// private boolean debug = true;
private boolean debug = false;
private Component tree;
private DOMTreeNotifier treeNotifier;
private TreePath nodePath;
private DOMTreeDumper treeDumper;
private JFileChooser chooser;
public DOMAccessPanel() {
GridBagLayout layout = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
JPanel nodeInfo = new JPanel();
nodeInfo.setLayout(layout);
JLabel l = new JLabel("Name:");
c.anchor = GridBagConstraints.WEST;
c.fill = GridBagConstraints.BOTH;
layout.setConstraints(l, c);
nodeInfo.add(l);
l = new JLabel("Type:");
c.gridwidth = GridBagConstraints.REMAINDER; //end row
layout.setConstraints(l, c);
nodeInfo.add(l);
c.gridwidth = GridBagConstraints.RELATIVE; //new row
name = new JTextField(10);
layout.setConstraints(name, c);
nodeInfo.add(name);
c.gridwidth = GridBagConstraints.REMAINDER; //end row
type = new JComboBox(types);
layout.setConstraints(type, c);
nodeInfo.add(type);
// Attribute panel
JPanel attrPanel = new JPanel();
GridBagLayout attrLayout = new GridBagLayout();
attrPanel.setLayout(attrLayout);
c.gridwidth = GridBagConstraints.RELATIVE; //new row
aName = new JComboBox();
aName.setEditable(true);
aName.addItemListener(this);
attrLayout.setConstraints(aName, c);
attrPanel.add(aName);
JPanel p = new JPanel();
l = new JLabel("=");
p.add(l);
aValue = new JTextField(9);
p.add(aValue);
c.gridwidth = GridBagConstraints.REMAINDER; //end row
attrLayout.setConstraints(p, c);
attrPanel.add(p);
p = new JPanel();
set = new JButton("Set");
set.addActionListener(this);
p.add(set);
removeAttr = new JButton("Remove");
removeAttr.setActionCommand("remove_attr");
removeAttr.addActionListener(this);
p.add(removeAttr);
attrLayout.setConstraints(p, c);
attrPanel.add(p);
attrPanel.setBorder(new TitledBorder(new BevelBorder(BevelBorder.LOWERED), " Attributes "));
layout.setConstraints(attrPanel, c);
// End Attribute panel
nodeInfo.add(attrPanel);
l = new JLabel("Value:");
layout.setConstraints(l, c);
nodeInfo.add(l);
value = new JTextArea(5, 23);
value.addCaretListener (new CaretListener() {
public void caretUpdate(CaretEvent e) {
dbg("caret:");
if (node == null || updating) return;
String valueStr = value.getText();
if (!valueStr.equals("")) {
node.setNodeValue(valueStr);
}
}
});
c.fill = GridBagConstraints.BOTH;
JScrollPane valueScrollPane = new JScrollPane(value);
layout.setConstraints(valueScrollPane, c);
nodeInfo.add(valueScrollPane);
JPanel nodeButtonPanel = new JPanel();
GridLayout gl = new GridLayout(2, 2);
nodeButtonPanel.setLayout(gl);
newNode = new JButton("New");
newNode.setToolTipText("Create a new node");
newNode.addActionListener(this);
nodeButtonPanel.add(newNode);
insert = new JButton("Insert");
insert.setToolTipText("Inserts a node before the selected node ");
insert.addActionListener(this);
nodeButtonPanel.add(insert);
append = new JButton("Append");
append.setToolTipText("Adds a node to the end of the list of children of the selected node");
append.addActionListener(this);
nodeButtonPanel.add(append);
remove = new JButton("Remove");
remove.setToolTipText("Removes the selected node from the tree");
remove.addActionListener(this);
nodeButtonPanel.add(remove);
nodeButtonPanel.setBorder(new TitledBorder(new BevelBorder(BevelBorder.LOWERED), " Node Manipulation "));
c.fill = GridBagConstraints.HORIZONTAL;
layout.setConstraints(nodeButtonPanel, c);
nodeInfo.add(nodeButtonPanel);
nodeInfo.setBorder(new TitledBorder(new EtchedBorder(), " Node info "));
layout = new GridBagLayout();
setLayout(layout);
layout.setConstraints(nodeInfo, c);
add(nodeInfo);
save = new JButton("Dump Tree To File");
save.setActionCommand("save");
save.addActionListener(this);
c.anchor = GridBagConstraints.CENTER;
c.fill = GridBagConstraints.HORIZONTAL;
layout.setConstraints(save, c);
add(save);
setMinimumSize(new Dimension(350, 400));
setButtonState();
}
public void setTreeNotifier(DOMTreeNotifier newTreeNotifier)
{
treeNotifier = newTreeNotifier;
}
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
dbg("AttrInfoPanel.actionPerformed: " + command);
if (command.equalsIgnoreCase("new")) {
prv = node;
updateInfo(null);
type.setEnabled(true);
insert.setEnabled(true);
append.setEnabled(true);
} else if (command.equalsIgnoreCase("insert")) {
insertNode();
treeNotifier.treeStructureChanged(
new TreeModelEvent(this, nodePath.getParentPath()));
} else if (command.equalsIgnoreCase("append")) {
appendNode();
treeNotifier.treeStructureChanged(
new TreeModelEvent(this, nodePath.getParentPath()));
} else if (command.equalsIgnoreCase("remove")) {
if (node == null) return;
Node parent = node.getParentNode();
parent.removeChild(node);
node = parent;
treeNotifier.treeStructureChanged(new TreeModelEvent(this, nodePath.getParentPath()));
} else if (command.equalsIgnoreCase("save")) {
saveDoc();
} else if (command.equalsIgnoreCase("set")) {
((Element)node).setAttribute((String)aName.getSelectedItem(), aValue.getText());
updateInfo(node);
} else if (command.equalsIgnoreCase("remove_attr")) {
removeAttribute();
}
}
public void itemStateChanged(ItemEvent e) {
if ((node != null) && (aName.getSelectedItem() != null)) {
set.setEnabled(true);
if (((attrMap = node.getAttributes()) != null) &&
(aName.getSelectedIndex() >=0)) {
dbg("setting attr...");
aValue.setText(attrMap.item(aName.getSelectedIndex()).getNodeValue());
}
}
}
public void updateInfo(Node node) {
updating = true;
dbg("updateInfo" + node);
this.node = node;
setButtonState();
name.setText("");
value.setText("");
aValue.setText("");
aName.removeAllItems();
if (node == null) {
updating = false;
return;
}
prv = node;
name.setText(node.getNodeName());
type.setSelectedIndex(node.getNodeType() - 1);
dbg("1 update node name: " + node.getNodeName());
dbg("1 update node value:" + node.getNodeValue());
value.setText(node.getNodeValue());
dbg("2 update node name: " + node.getNodeName());
dbg("2 update node value:" + node.getNodeValue());
attrMap = node.getAttributes();
if (attrMap == null) {
updating = false;
return;
}
int length = attrMap.getLength();
for (int i=0; i < length; i++) {
Attr a = (Attr)attrMap.item(i);
aName.addItem(a.getName());
}
if (length > 0) {
aName.setSelectedIndex(0);
aValue.setText(attrMap.item(0).getNodeValue());
}
updating = false;
}
public void valueChanged(TreeSelectionEvent e) {
dbg("DOMAccessPanel.valueChanged");
if (e.isAddedPath()) {
updateInfo((Node)e.getPath().getLastPathComponent());
}
nodePath = e.getPath();
tree = (Component)e.getSource();
}
private Node createNode() {
int nodeType = type.getSelectedIndex();
Document doc = prv.getOwnerDocument();
Node newNode = null;
switch (nodeType + 1) {
case Node.ELEMENT_NODE:
dbg("ELEMENT");
newNode = doc.createElement(name.getText());
break;
case Node.ATTRIBUTE_NODE:
dbg("ATTRIBUTE");
return null;
case Node.TEXT_NODE:
dbg("TEXT");
newNode = doc.createTextNode(value.getText());
break;
case Node.CDATA_SECTION_NODE:
dbg("CDATA_SECTION");
return null;
case Node.ENTITY_REFERENCE_NODE:
dbg("ENTITY_REFERENCE");
return null;
case Node.ENTITY_NODE:
dbg("ENTITY");
return null;
case Node.PROCESSING_INSTRUCTION_NODE:
dbg("PROCESSING_INSTRUCTION");
return null;
case Node.COMMENT_NODE:
dbg("COMMENT");
newNode = doc.createComment(value.getText());
break;
case Node.DOCUMENT_NODE:
dbg("DOCUMENT");
return null;
case Node.DOCUMENT_TYPE_NODE:
dbg("DOCUMENT_TYPE");
return null;
case Node.DOCUMENT_FRAGMENT_NODE:
dbg("DOCUMENT_FRAGMENT");
return null;
case Node.NOTATION_NODE:
dbg("NOTATION");
return null;
}
return newNode;
}
private void insertNode() {
Node newNode = createNode();
if (newNode == null) return;
dbg("inserting...");
prv.getParentNode().insertBefore(newNode, prv);
}
private void appendNode() {
Node newNode = createNode();
if (newNode == null) return;
dbg("appending...");
prv.appendChild(newNode);
}
private void removeAttribute() {
((Element)node).removeAttribute((String)aName.getSelectedItem());
updateInfo(node);
}
private void saveDoc() {
if (chooser == null) {
chooser = new JFileChooser();
}
int returnVal = chooser.showSaveDialog(this);
if(returnVal == JFileChooser.APPROVE_OPTION) {
String fileName = chooser.getSelectedFile().getPath();
if (treeDumper == null) {
treeDumper = new DOMTreeDumper(debug);
}
treeDumper.dumpToFile(fileName, node.getOwnerDocument());
}
}
private void setButtonState() {
boolean nodeExists = (node != null);
boolean attrExists = nodeExists && !(node.getAttributes() == null || node.getAttributes().getLength() == 0);
type.setEnabled(nodeExists);
newNode.setEnabled(nodeExists);
insert.setEnabled(nodeExists);
append.setEnabled(nodeExists);
save.setEnabled(nodeExists);
remove.setEnabled(nodeExists);
set.setEnabled(attrExists);
removeAttr.setEnabled(attrExists);
}
private void dbg(String str) {
if (debug) {
System.out.println(str);
}
}
}

Просмотреть файл

@ -0,0 +1,47 @@
/*
* 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.
*
* Contributor(s): Igor Kushnirskiy <idk@eng.sun.com>
*/
package org.mozilla.webclient.test;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.JTree;
import org.w3c.dom.Node;
import java.awt.Component;
class DOMCellRenderer implements TreeCellRenderer {
private TreeCellRenderer cellRenderer;
public DOMCellRenderer(TreeCellRenderer cellRenderer) {
this.cellRenderer = cellRenderer;
}
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean selected,
boolean expanded,
boolean leaf, int row,
boolean hasFocus) {
return cellRenderer.getTreeCellRendererComponent(tree,
((Node)value).getNodeName(),
selected,
expanded,
leaf, row,
hasFocus);
}
}

Просмотреть файл

@ -0,0 +1,215 @@
/*
* 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.
*
* Contributor(s): Denis Sharypov <sdv@sparc.spb.su>
*
*/
package org.mozilla.webclient.test;
import java.io.BufferedOutputStream;
import java.io.PrintStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentType;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class DOMTreeDumper {
private String prefix = "DOMTreeDumper";
private boolean debug;
private PrintStream ps;
private boolean inA;
private final String[] endTagForbiddenNames = {"AREA",
"BASE",
"BASEFONT",
"BR",
"COL",
"FRAME",
"HR",
"IMG",
"INPUT",
"ISINDEX",
"LINK",
"META",
"PARAM"};
DOMTreeDumper() {
this(true);
}
DOMTreeDumper(boolean debug) {
this.debug = debug;
}
private void dumpDocument(Document doc) {
if (doc == null) return;
Element element = doc.getDocumentElement();
if (element == null) return;
element.normalize();
// DocumentType dt = doc.getDoctype();
// dumpNode(dt);
dumpNode(element);
ps.println();
ps.flush();
element = null;
doc = null;
}
private void dumpNode(Node node) {
dumpNode(node, false);
}
private void dumpNode(Node node, boolean isMapNode) {
if (node == null) {
return;
}
int type = node.getNodeType();
String name = node.getNodeName();
String value = node.getNodeValue();
switch (type) {
case Node.ELEMENT_NODE:
if (name.equals("A")) inA = true;
if (!(inA || name.equals("BR"))) {
ps.println();
}
ps.print("<" + name);
dumpAttributes(node);
ps.print(">");
dumpChildren(node);
if (name.equals("A")) inA = false;
if (!endTagForbidden(name)) {
ps.print("</" + node.getNodeName() + ">");
}
break;
case Node.ATTRIBUTE_NODE:
ps.print(" " + name.toUpperCase() + "=\"" + value + "\"");
break;
case Node.TEXT_NODE:
if (!node.getParentNode().getNodeName().equals("PRE")) {
value = value.trim();
}
if (!value.equals("")) {
if (!inA) {
ps.println();
}
ps.print(canonicalize(value));
}
break;
case Node.COMMENT_NODE:
ps.print("\n<!--" + value + "-->");
break;
case Node.CDATA_SECTION_NODE:
case Node.ENTITY_REFERENCE_NODE:
case Node.ENTITY_NODE:
case Node.PROCESSING_INSTRUCTION_NODE:
case Node.DOCUMENT_NODE:
case Node.DOCUMENT_TYPE_NODE:
case Node.DOCUMENT_FRAGMENT_NODE:
case Node.NOTATION_NODE:
ps.println("\n<!-- NOT HANDLED: " + name +
" value=" + value + " -->");
break;
}
}
private void dumpAttributes(Node node) {
NamedNodeMap map = node.getAttributes();
if (map == null) return;
int length = map.getLength();
for (int i=0; i < length; i++) {
Node item = map.item(i);
dumpNode(item, true);
}
}
private void dumpChildren(Node node) {
NodeList children = node.getChildNodes();
int length = 0;
boolean hasChildren = ((children != null) && ((length = children.getLength()) > 0));
if (!hasChildren) {
return;
}
for (int i=0; i < length; i++) {
dumpNode(children.item(i), false);
}
if (!inA) {
ps.println();
}
}
private String canonicalize(String str) {
StringBuffer in = new StringBuffer(str);
int length = in.length();
StringBuffer out = new StringBuffer(length);
char c;
for (int i = 0; i < length; i++) {
switch (c = in.charAt(i)) {
case '&' :
out.append("&amp;");
break;
case '<':
out.append("&lt;");
break;
case '>':
out.append("&gt;");
break;
case '\u00A0':
out.append("&nbsp;");
break;
default:
out.append(c);
}
}
return out.toString();
}
private boolean endTagForbidden(String name) {
for (int i = 0; i < endTagForbiddenNames.length; i++) {
if (name.equals(endTagForbiddenNames[i])) {
return true;
}
}
return false;
}
public void dumpToFile(String fileName, Document doc) {
try {
FileOutputStream fos = new FileOutputStream(fileName);
ps = new PrintStream(new BufferedOutputStream(fos, 1024));
} catch (IOException ex) {
ex.printStackTrace();
return;
}
dbg("dumping to " + fileName);
dumpDocument(doc);
dbg("finished dumping...");
}
private void dbg(String str) {
if (debug) {
System.out.println(prefix + ": " + str);
}
}
}

Просмотреть файл

@ -0,0 +1,112 @@
/*
* 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.
*
* Contributor(s): Igor Kushnirskiy <idk@eng.sun.com>
*/
package org.mozilla.webclient.test;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeModel;
import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeModelListener;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.Vector;
class DOMTreeModel implements TreeModel, DOMTreeNotifier {
private Node rootNode;
private Vector treeModelListeners = new Vector();
public DOMTreeModel(Node node) {
rootNode = node;
}
public void addTreeModelListener(TreeModelListener l) {
treeModelListeners.add(l);
}
public void removeTreeModelListener(TreeModelListener l) {
treeModelListeners.removeElement(l);
}
public Object getChild(Object parent, int index) {
return ((Node)parent).getChildNodes().item(index);
}
public int getChildCount(Object parent) {
return ((Node)parent).getChildNodes().getLength();
}
public int getIndexOfChild(Object parent, Object child) {
NodeList childNodes = ((Node)parent).getChildNodes();
int res = -1;
int length = childNodes.getLength();
for (int i = 0; i < length; i++) {
if (childNodes.item(i) == child) {
res = i;
break;
}
}
return res;
}
public Object getRoot() {
return rootNode;
}
public boolean isLeaf(Object node) {
return getChildCount(node) == 0;
}
public void valueForPathChanged(TreePath path, Object newValue) {
return;
}
/*
* Invoked after a node (or a set of siblings) has changed in some way.
*/
public void treeNodesChanged(TreeModelEvent e) {
for (int i = 0; i < treeModelListeners.size() ; i++) {
((TreeModelListener)treeModelListeners.elementAt(i)).
treeNodesChanged(e);
}
}
/*
* Invoked after nodes have been inserted into the tree.
*/
public void treeNodesInserted(TreeModelEvent e) {
for (int i = 0; i < treeModelListeners.size(); i++) {
((TreeModelListener)treeModelListeners.elementAt(i)).
treeNodesInserted(e);
}
}
/*
* Invoked after nodes have been removed from the tree.
*/
public void treeNodesRemoved(TreeModelEvent e) {
for (int i = 0; i < treeModelListeners.size(); i++) {
((TreeModelListener)treeModelListeners.elementAt(i)).
treeNodesRemoved(e);
}
}
/*
* Invoked after the tree has drastically changed structure from a given node down.
*/
public void treeStructureChanged(TreeModelEvent e) {
for (int i = 0; i < treeModelListeners.size(); i++) {
((TreeModelListener)treeModelListeners.elementAt(i)).
treeStructureChanged(e);
}
}
}

Просмотреть файл

@ -0,0 +1,43 @@
/*
* 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.
*
* Contributor(s): Igor Kushnirskiy <idk@eng.sun.com>
*/
package org.mozilla.webclient.test;
import javax.swing.event.TreeModelEvent;
interface DOMTreeNotifier {
/*
* Invoked after a node (or a set of siblings) has changed in some way.
*/
public void treeNodesChanged(TreeModelEvent e);
/*
* Invoked after nodes have been inserted into the tree.
*/
public void treeNodesInserted(TreeModelEvent e);
/*
* Invoked after nodes have been removed from the tree.
*/
public void treeNodesRemoved(TreeModelEvent e);
/*
* Invoked after the tree has drastically changed structure from a given node down.
*/
public void treeStructureChanged(TreeModelEvent e);
};

Просмотреть файл

@ -0,0 +1,141 @@
/* -*- Mode: java; 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): Kirk Baker <kbaker@eb.com>
* Ian Wilkinson <iw@ennoble.com>
* Mark Goddard
* Ed Burns <edburns@acm.org>
*/
package org.mozilla.webclient.test;
import org.mozilla.util.Assert;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Element;
import org.w3c.dom.Document;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JTree;
import javax.swing.tree.TreeSelectionModel;
import java.awt.BorderLayout;
/**
*
* A dom viewer Frame
*
* @version $Id: DOMViewerFrame.java,v 1.1 2000/06/04 22:16:04 edburns%acm.org Exp $
*
* @see org.mozilla.webclient.BrowserControlFactory
* Based on DOMViewerFactor.java by idk
* Contributor(s): Ed Burns <edburns@acm.org>
* Igor Kushnirskiy <idk@eng.sun.com>
*/
public class DOMViewerFrame extends JFrame {
private EmbeddedMozilla creator;
private Node rootNode;
private DOMAccessPanel elementPanel;
private JScrollPane treePane;
private JSplitPane splitPane;
private JPanel panel;
private JTree tree;
private Document doc;
public DOMViewerFrame (String title, EmbeddedMozilla Creator)
{
super(title);
creator = Creator;
this.getContentPane().setLayout(new BorderLayout());
// create the content for the top of the splitPane
treePane = new JScrollPane();
panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add("Center", treePane);
// create the content for the bottom of the splitPane
elementPanel = new DOMAccessPanel();
// create the splitPane, adding the top and bottom content
splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, panel, elementPanel);
// add the splitPane to myself
this.getContentPane().add(splitPane);
this.pack();
splitPane.setDividerLocation(0.35);
} // DOMViewerFrame() ctor
public void setDocument(Document newDocument)
{
if (null == newDocument) {
return;
}
doc = newDocument;
try {
// store the document as the root node
Element e;
e = doc.getDocumentElement();
e.normalize();
rootNode = e;
// create a tree model for the DOM tree
DOMTreeModel treeModel = new DOMTreeModel(rootNode);
// hook the treeModel up to the elementPanel
elementPanel.setTreeNotifier(treeModel);
tree = new JTree(treeModel);
// hook the elementPanel up to the treeModel
tree.addTreeSelectionListener(elementPanel);
tree.setCellRenderer(new DOMCellRenderer(tree.getCellRenderer()));
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
treePane.setViewportView(tree);
} catch (Exception e) {
e.printStackTrace();
}
}
}
// EOF

Просмотреть файл

@ -43,6 +43,8 @@ import java.util.*;
import org.mozilla.webclient.*;
import org.mozilla.util.Assert;
import org.w3c.dom.Document;
/**
*
@ -50,7 +52,7 @@ import org.mozilla.util.Assert;
* This is a test application for using the BrowserControl.
*
* @version $Id: EMWindow.java,v 1.9 2000/06/01 23:42:35 edburns%acm.org Exp $
* @version $Id: EMWindow.java,v 1.10 2000/06/04 22:16:04 edburns%acm.org Exp $
*
* @see org.mozilla.webclient.BrowserControlFactory
@ -68,8 +70,9 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc
private CurrentPage currentPage;
private Bookmarks bookmarks;
private BookmarksFrame bookmarksFrame = null;
private BookmarksFrame bookmarksFrame = null;
private TreeModel bookmarksTree;
private DOMViewerFrame domViewer;
private Panel controlPanel;
private Panel statusPanel;
private Panel buttonsPanel;
@ -77,6 +80,8 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc
private MenuBar menuBar;
private Label statusLabel;
private Document currentDocument = null;
private EmbeddedMozilla creator;
private boolean viewMode = true;
@ -143,6 +148,7 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc
makeItem(buttonsPanel, "Stop", 2, 0, 1, 1, 0.0, 0.0);
makeItem(buttonsPanel, "Refresh", 3, 0, 1, 1, 0.0, 0.0);
makeItem(buttonsPanel, "Bookmarks", 4, 0, 1, 1, 0.0, 0.0);
makeItem(buttonsPanel, "DOMViewer", 5, 0, 1, 1, 0.0, 0.0);
// Create the control panel
controlPanel = new Panel();
@ -284,6 +290,11 @@ public void delete()
bookmarksFrame.dispose();
bookmarksFrame = null;
}
if (null != domViewer) {
domViewer.setVisible(false);
domViewer.dispose();
domViewer = null;
}
BrowserControlFactory.deleteBrowserControl(browserControl);
browserControl = null;
System.out.println("debug: edburns: about to hide");
@ -297,92 +308,108 @@ public void delete()
bookmarksTree = null;
controlPanel = null;
buttonsPanel = null;
currentDocument = null;
}
public void actionPerformed (ActionEvent evt) {
String command = evt.getActionCommand();
public void actionPerformed (ActionEvent evt)
{
String command = evt.getActionCommand();
try {
Navigation navigation = (Navigation)
browserControl.queryInterface(BrowserControl.NAVIGATION_NAME);
CurrentPage currentPage = (CurrentPage)
browserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME);
History history = (History)
browserControl.queryInterface(BrowserControl.HISTORY_NAME);
try {
Navigation navigation = (Navigation)
browserControl.queryInterface(BrowserControl.NAVIGATION_NAME);
CurrentPage currentPage = (CurrentPage)
browserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME);
History history = (History)
browserControl.queryInterface(BrowserControl.HISTORY_NAME);
if (evt.getSource() instanceof MenuItem) {
if (command.equals("New Window")) {
creator.CreateEMWindow();
}
else if (command.equals("Close")) {
System.out.println("Got windowClosing");
System.out.println("destroying the BrowserControl");
EMWindow.this.delete();
// deal with the menu item commands
if (evt.getSource() instanceof MenuItem) {
if (command.equals("New Window")) {
creator.CreateEMWindow();
}
else if (command.equals("Close")) {
System.out.println("Got windowClosing");
System.out.println("destroying the BrowserControl");
EMWindow.this.delete();
// should close the BrowserControlCanvas
creator.DestroyEMWindow(winNum);
}
else if (command.equals("Find")) {
creator.DestroyEMWindow(winNum);
}
else if (command.equals("Find")) {
if (null == findDialog) {
Frame f = new Frame();
f.setSize(350,150);
findDialog = new FindDialog(this, this,
"Find in Page", "Find ",
"", 20, false);
findDialog.setModal(false);
Frame f = new Frame();
f.setSize(350,150);
findDialog = new FindDialog(this, this,
"Find in Page", "Find ",
"", 20, false);
findDialog.setModal(false);
}
findDialog.setVisible(true);
// currentPage.findInPage("Sun", true, true);
}
else if (command.equals("Find Next")) {
currentPage.findNextInPage(false);
}
else if (command.equals("View Page Source")) {
currentPage.getSourceBytes(viewMode);
viewMode = !viewMode;
}
else if (command.equals("View Page Info")) {
currentPage.getPageInfo();
}
else if (command.equals("Select All")) {
currentPage.selectAll();
}
// currentPage.findInPage("Sun", true, true);
}
else if (command.equals("Find Next")) {
currentPage.findNextInPage(false);
}
else if (command.equals("View Page Source")) {
currentPage.getSourceBytes(viewMode);
viewMode = !viewMode;
}
else if (command.equals("View Page Info")) {
currentPage.getPageInfo();
}
else if (command.equals("Select All")) {
currentPage.selectAll();
}
}
// deal with the button bar commands
else if(command.equals("Stop")) {
navigation.stop();
}
else if (command.equals("Refresh")) {
navigation.refresh(Navigation.LOAD_NORMAL);
}
else if (command.equals("Bookmarks")) {
if (null == bookmarksTree) {
bookmarksTree = bookmarks.getBookmarks();
}
if (null == bookmarksFrame) {
bookmarksFrame = new BookmarksFrame(bookmarksTree);
bookmarksFrame.setSize(new Dimension(320,480));
}
bookmarksFrame.setVisible(true);
}
else if (command.equals("Back")) {
if (history.canBack()) {
history.back();
}
}
else if (command.equals("Forward")) {
if (history.canForward()) {
history.forward();
}
}
else {
navigation.loadURL(urlField.getText());
}
navigation.stop();
}
catch (Exception e) {
System.out.println(e.getMessage());
else if (command.equals("Refresh")) {
navigation.refresh(Navigation.LOAD_NORMAL);
}
} // actionPerformed()
else if (command.equals("Bookmarks")) {
if (null == bookmarksTree) {
bookmarksTree = bookmarks.getBookmarks();
}
if (null == bookmarksFrame) {
bookmarksFrame = new BookmarksFrame(bookmarksTree);
bookmarksFrame.setSize(new Dimension(320,480));
bookmarksFrame.setLocation(defaultWidth + 5, 0);
}
bookmarksFrame.setVisible(true);
}
else if (command.equals("DOMViewer")) {
if (null == domViewer) {
domViewer = new DOMViewerFrame("DOM Viewer", creator);
domViewer.setSize(new Dimension(300, 600));
domViewer.setLocation(defaultWidth + 5, 0);
}
if (null != currentDocument) {
domViewer.setDocument(currentDocument);
domViewer.setVisible(true);
}
}
else if (command.equals("Back")) {
if (history.canBack()) {
history.back();
}
}
else if (command.equals("Forward")) {
if (history.canForward()) {
history.forward();
}
}
else {
navigation.loadURL(urlField.getText());
}
}
catch (Exception e) {
System.out.println(e.getMessage());
}
} // actionPerformed()
public void dialogDismissed(Dialog d) {
@ -482,9 +509,14 @@ public void eventDispatched(WebclientEvent event)
currentURL);
statusLabel.setText("Starting to load " + currentURL);
urlField.setText(currentURL);
currentDocument = null;
break;
case ((int) DocumentLoadEvent.END_DOCUMENT_LOAD_EVENT_MASK):
statusLabel.setText("Done.");
currentDocument = currentPage.getDOM();
if (null != domViewer) {
domViewer.setDocument(currentDocument);
}
break;
}
}

Просмотреть файл

@ -35,8 +35,12 @@ import java.util.Properties;
import java.io.*;
import java.net.*;
import org.w3c.dom.Document;
import org.mozilla.webclient.UnimplementedException;
import org.mozilla.dom.DOMAccessor;
public class CurrentPageImpl extends ImplObjectNative implements CurrentPage
{
//
@ -47,12 +51,15 @@ public class CurrentPageImpl extends ImplObjectNative implements CurrentPage
// Class Variables
//
private static boolean domInitialized = false;
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
//
@ -63,6 +70,10 @@ public CurrentPageImpl(WrapperFactory yourFactory,
BrowserControl yourBrowserControl)
{
super(yourFactory, yourBrowserControl);
// force the class to be loaded, thus loading the JNI library
if (!domInitialized) {
DOMAccessor.initialize();
}
}
//
@ -116,7 +127,11 @@ public String getCurrentURL()
return result;
}
// org.w3c.dom.Document getDOM();
public Document getDOM()
{
Document result = nativeGetDOM(nativeWebShell);
return result;
}
public Properties getPageInfo()
{
@ -221,7 +236,7 @@ native public void nativeFindNextInPage(int webShellPtr, boolean forward);
native public String nativeGetCurrentURL(int webShellPtr);
// org.w3c.dom.Document getDOM();
native public Document nativeGetDOM(int webShellPtr);
// webclient.PageInfo getPageInfo();
@ -245,7 +260,7 @@ public static void main(String [] args)
Assert.setEnabled(true);
Log.setApplicationName("CurrentPageImpl");
Log.setApplicationVersion("0.0");
Log.setApplicationVersionDate("$Id: CurrentPageImpl.java,v 1.5 2000/05/23 21:06:11 ashuk%eng.sun.com Exp $");
Log.setApplicationVersionDate("$Id: CurrentPageImpl.java,v 1.6 2000/06/04 22:16:05 edburns%acm.org Exp $");
}

Просмотреть файл

@ -35,7 +35,7 @@
#include "jni_util_export.h"
#include "rdf_util.h"
#include "nsActions.h"
#include "nsLayoutCID.h"
#include "nsCRT.h"
#include "nsIPresShell.h"
@ -43,21 +43,21 @@
#include "nsISupports.h"
#include "nsIFindComponent.h"
#include "nsISearchContext.h"
#include "nsIDocShell.h"
#include "nsIDOMSelection.h"
#include "nsIDocumentViewer.h"
#include "nsIDocument.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIDOMHTMLElement.h"
#include "nsIDOMNode.h"
#include "nsIDOMRange.h"
#include "nsIDocShell.h"
#include "nsIDOMSelection.h"
#include "nsIDocumentViewer.h"
#include "nsIDocument.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIDOMHTMLElement.h"
#include "nsIDOMNode.h"
#include "nsIDOMRange.h"
#include "nsIContentViewer.h"
#include "nsIServiceManager.h"
static NS_DEFINE_CID(kCDOMRangeCID, NS_RANGE_CID);
static NS_DEFINE_IID(kIDOMHTMLDocumentIID, NS_IDOMHTMLDOCUMENT_IID);
static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID);
static NS_DEFINE_CID(kCDOMRangeCID, NS_RANGE_CID);
static NS_DEFINE_IID(kIDOMHTMLDocumentIID, NS_IDOMHTMLDOCUMENT_IID);
static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID);
JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeCopyCurrentSelectionToSystemClipboard
(JNIEnv *env, jobject obj, jint webShellPtr)
@ -230,6 +230,40 @@ JNIEXPORT jstring JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPage
return urlString;
}
JNIEXPORT jobject JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeGetDOM
(JNIEnv *env, jobject obj, jint webShellPtr)
{
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
jobject result = nsnull;
jlong documentLong = nsnull;
jclass clazz = nsnull;
jmethodID mid = nsnull;
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellGetDOM");
return nsnull;
}
if (nsnull == initContext->currentDocument ||
nsnull == (documentLong = (jlong) initContext->currentDocument.get())){
return nsnull;
}
if (nsnull == (clazz = ::util_FindClass(env,
"org/mozilla/dom/DOMAccessor"))) {
::util_ThrowExceptionToJava(env, "Exception: Can't get DOMAccessor class");
return nsnull;
}
if (nsnull == (mid = env->GetStaticMethodID(clazz, "getNodeByHandle",
"(J)Lorg/w3c/dom/Node;"))) {
::util_ThrowExceptionToJava(env, "Exception: Can't get DOM Node.");
return nsnull;
}
result = env->CallStaticObjectMethod(clazz, mid, documentLong);
return result;
}
/*
* Class: org_mozilla_webclient_wrapper_0005fnative_CurrentPageImpl
* Method: nativeGetSource
@ -285,82 +319,82 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImp
JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeSelectAll
(JNIEnv * env, jobject obj, jint webShellPtr)
{
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
nsCOMPtr<nsIPresShell> presShell;
nsresult rv;
rv = initContext->docShell->GetPresShell(getter_AddRefs(presShell));
if (NS_FAILED(rv)) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get PresShell");
return;
}
nsCOMPtr<nsIDOMSelection> selection;
rv = presShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection));
if (NS_FAILED(rv)) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get DOMSelection");
return;
}
nsCOMPtr<nsIContentViewer> contentViewer;
rv = initContext->docShell->GetContentViewer(getter_AddRefs(contentViewer));
if (NS_FAILED(rv)) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get contentViewer");
return;
}
nsCOMPtr<nsIDocumentViewer> docViewer(do_QueryInterface(contentViewer));
nsCOMPtr<nsIDocument> doc;
rv = docViewer->GetDocument(*getter_AddRefs(doc));
if (NS_FAILED(rv)) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get Document object");
return;
}
nsCOMPtr<nsIDOMHTMLDocument> htmldoc;
rv = doc->QueryInterface(kIDOMHTMLDocumentIID, getter_AddRefs(htmldoc));
if (NS_FAILED(rv)) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get DOMHTMLDocument");
return;
}
nsCOMPtr<nsIDOMHTMLElement>bodyElement;
rv = htmldoc->GetBody(getter_AddRefs(bodyElement));
if (NS_FAILED(rv)) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get DOMHTMLElement");
return;
}
nsCOMPtr<nsIDOMNode>bodyNode = do_QueryInterface(bodyElement);
if (!bodyNode) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get DOMNode");
return;
}
rv = selection->ClearSelection();
nsCOMPtr<nsIDOMRange> range;
rv = nsComponentManager::CreateInstance(kCDOMRangeCID, nsnull,
NS_GET_IID(nsIDOMRange),
getter_AddRefs(range));
rv = range->SelectNodeContents(bodyNode);
rv = selection->AddRange(range);
if (NS_FAILED(rv)) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get final Select working");
return;
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
nsCOMPtr<nsIPresShell> presShell;
nsresult rv;
rv = initContext->docShell->GetPresShell(getter_AddRefs(presShell));
if (NS_FAILED(rv)) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get PresShell");
return;
}
nsCOMPtr<nsIDOMSelection> selection;
rv = presShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection));
if (NS_FAILED(rv)) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get DOMSelection");
return;
}
nsCOMPtr<nsIContentViewer> contentViewer;
rv = initContext->docShell->GetContentViewer(getter_AddRefs(contentViewer));
if (NS_FAILED(rv)) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get contentViewer");
return;
}
nsCOMPtr<nsIDocumentViewer> docViewer(do_QueryInterface(contentViewer));
nsCOMPtr<nsIDocument> doc;
rv = docViewer->GetDocument(*getter_AddRefs(doc));
if (NS_FAILED(rv)) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get Document object");
return;
}
nsCOMPtr<nsIDOMHTMLDocument> htmldoc;
rv = doc->QueryInterface(kIDOMHTMLDocumentIID, getter_AddRefs(htmldoc));
if (NS_FAILED(rv)) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get DOMHTMLDocument");
return;
}
nsCOMPtr<nsIDOMHTMLElement>bodyElement;
rv = htmldoc->GetBody(getter_AddRefs(bodyElement));
if (NS_FAILED(rv)) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get DOMHTMLElement");
return;
}
nsCOMPtr<nsIDOMNode>bodyNode = do_QueryInterface(bodyElement);
if (!bodyNode) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get DOMNode");
return;
}
rv = selection->ClearSelection();
nsCOMPtr<nsIDOMRange> range;
rv = nsComponentManager::CreateInstance(kCDOMRangeCID, nsnull,
NS_GET_IID(nsIDOMRange),
getter_AddRefs(range));
rv = range->SelectNodeContents(bodyNode);
rv = selection->AddRange(range);
if (NS_FAILED(rv)) {
initContext->initFailCode = kSelectAllError;
::util_ThrowExceptionToJava(env, "Exception: can't get final Select working");
return;
}
}

Просмотреть файл

@ -1,370 +1,371 @@
/* -*- 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): Kirk Baker <kbaker@eb.com>
* Ian Wilkinson <iw@ennoble.com>
* Mark Lin <mark.lin@eng.sun.com>
* Mark Goddard
* Ed Burns <edburns@acm.org>
* Ann Sunhachawee
*/
#include "DocumentLoaderObserverImpl.h"
#include "nsString.h"
#include "jni_util.h"
#include "dom_util.h"
#include "nsActions.h"
#include "nsIDOMDocument.h"
#include "prlog.h" // for PR_ASSERT
jlong DocumentLoaderObserverImpl::maskValues[] = { -1L };
char *DocumentLoaderObserverImpl::maskNames[] = {
"START_DOCUMENT_LOAD_EVENT_MASK",
"END_DOCUMENT_LOAD_EVENT_MASK",
"START_URL_LOAD_EVENT_MASK",
"END_URL_LOAD_EVENT_MASK",
"PROGRESS_URL_LOAD_EVENT_MASK",
"STATUS_URL_LOAD_EVENT_MASK",
"UNKNOWN_CONTENT_EVENT_MASK",
"FETCH_INTERRUPT_EVENT_MASK",
nsnull
};
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() : mRefCnt(1),
mTarget(nsnull), mMouseListener(nsnull), mDomEventTarget(nsnull) {
}
DocumentLoaderObserverImpl::DocumentLoaderObserverImpl(JNIEnv *env,
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!
}
#ifndef BAL_INTERFACE
PR_ASSERT(gVm);
#endif
if (-1 == maskValues[0]) {
util_InitializeEventMaskValuesFromClass("org/mozilla/webclient/DocumentLoadEvent",
maskNames, maskValues);
}
mRefCnt = 1; // PENDING(edburns): not sure about how right this is to do.
}
DocumentLoaderObserverImpl::~DocumentLoaderObserverImpl()
{
RemoveMouseListener();
}
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;
}
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,
const char* aCommand)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("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) {
// 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);
aURL->GetSpec(&urlStr);
if (nsnull != urlStr) {
urlJStr = (jobject) ::util_NewStringUTF(env, urlStr);
::Recycle(urlStr);
}
}
util_SendEventToJava(mInitContext->env,
mInitContext->nativeEventThread, mTarget,
maskValues[START_DOCUMENT_LOAD_EVENT_MASK], urlJStr);
if (urlJStr) {
::util_DeleteStringUTF(mInitContext->env, (jstring) urlJStr);
}
return NS_OK;
}
NS_IMETHODIMP DocumentLoaderObserverImpl::OnEndDocumentLoad(nsIDocumentLoader* loader,
nsIChannel* channel,
nsresult aStatus)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("!!DocumentLoaderObserverImpl.cpp: OnEndDocumentLoad\n"));
}
#endif
// if we have a mouse listener
if (mMouseListener) {
// install the mouse listener into mozilla
nsCOMPtr<nsIDOMDocument> 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;
}
nsresult rv;
rv = doc->QueryInterface(NS_GET_IID(nsIDOMEventTarget),
getter_AddRefs(mDomEventTarget));
if (NS_FAILED(rv) || !mDomEventTarget) {
return NS_OK;
}
nsAutoString eType("mouseover");
mDomEventTarget->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,
maskValues[END_DOCUMENT_LOAD_EVENT_MASK], nsnull);
return NS_OK;
}
NS_IMETHODIMP DocumentLoaderObserverImpl::OnStartURLLoad(nsIDocumentLoader* loader,
nsIChannel* channel)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("!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);
return NS_OK;
}
NS_IMETHODIMP DocumentLoaderObserverImpl::OnProgressURLLoad(nsIDocumentLoader* loader,
nsIChannel* channel,
PRUint32 aProgress,
PRUint32 aProgressMax)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("!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);
return NS_OK;
}
NS_IMETHODIMP DocumentLoaderObserverImpl::OnStatusURLLoad(nsIDocumentLoader* loader,
nsIChannel* channel,
nsString& aMsg)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("!DocumentLoaderObserverImpl: OnStatusURLLoad: %S\n",
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, (const jchar *)
aMsg.GetUnicode(), length);
util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mTarget,
maskValues[STATUS_URL_LOAD_EVENT_MASK], (jobject) statusMessage);
if (statusMessage) {
::util_DeleteString(mInitContext->env, statusMessage);
}
return NS_OK;
}
NS_IMETHODIMP DocumentLoaderObserverImpl::OnEndURLLoad(nsIDocumentLoader* loader,
nsIChannel* channel,
nsresult aStatus)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("!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);
return NS_OK;
}
NS_IMETHODIMP DocumentLoaderObserverImpl::HandleUnknownContentType(nsIDocumentLoader* loader,
nsIChannel* channel,
const char *aContentType,
const char *aCommand)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("!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<nsIDOMMouseListener> toAdd)
{
nsresult rv = NS_ERROR_FAILURE;
if (nsnull == toAdd) {
return rv;
}
mMouseListener = toAdd;
return NS_OK;
}
NS_IMETHODIMP DocumentLoaderObserverImpl::RemoveMouseListener()
{
nsresult rv = NS_OK;
if (mDomEventTarget && mMouseListener) {
nsAutoString eType("mouseover");
mDomEventTarget->RemoveEventListener(eType, mMouseListener, PR_FALSE);
mDomEventTarget = nsnull;
mMouseListener = nsnull;
}
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;
}
/* -*- 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): Kirk Baker <kbaker@eb.com>
* Ian Wilkinson <iw@ennoble.com>
* Mark Lin <mark.lin@eng.sun.com>
* Mark Goddard
* Ed Burns <edburns@acm.org>
* Ann Sunhachawee
*/
#include "DocumentLoaderObserverImpl.h"
#include "nsString.h"
#include "jni_util.h"
#include "dom_util.h"
#include "nsActions.h"
#include "nsIDOMDocument.h"
#include "prlog.h" // for PR_ASSERT
jlong DocumentLoaderObserverImpl::maskValues[] = { -1L };
char *DocumentLoaderObserverImpl::maskNames[] = {
"START_DOCUMENT_LOAD_EVENT_MASK",
"END_DOCUMENT_LOAD_EVENT_MASK",
"START_URL_LOAD_EVENT_MASK",
"END_URL_LOAD_EVENT_MASK",
"PROGRESS_URL_LOAD_EVENT_MASK",
"STATUS_URL_LOAD_EVENT_MASK",
"UNKNOWN_CONTENT_EVENT_MASK",
"FETCH_INTERRUPT_EVENT_MASK",
nsnull
};
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() : mRefCnt(1),
mTarget(nsnull), mMouseListener(nsnull), mDomEventTarget(nsnull) {
}
DocumentLoaderObserverImpl::DocumentLoaderObserverImpl(JNIEnv *env,
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!
}
#ifndef BAL_INTERFACE
PR_ASSERT(gVm);
#endif
if (-1 == maskValues[0]) {
util_InitializeEventMaskValuesFromClass("org/mozilla/webclient/DocumentLoadEvent",
maskNames, maskValues);
}
mRefCnt = 1; // PENDING(edburns): not sure about how right this is to do.
}
DocumentLoaderObserverImpl::~DocumentLoaderObserverImpl()
{
RemoveMouseListener();
}
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;
}
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,
const char* aCommand)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("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) {
// 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);
aURL->GetSpec(&urlStr);
if (nsnull != urlStr) {
urlJStr = (jobject) ::util_NewStringUTF(env, urlStr);
::Recycle(urlStr);
}
}
util_SendEventToJava(mInitContext->env,
mInitContext->nativeEventThread, mTarget,
maskValues[START_DOCUMENT_LOAD_EVENT_MASK], urlJStr);
if (urlJStr) {
::util_DeleteStringUTF(mInitContext->env, (jstring) urlJStr);
}
return NS_OK;
}
NS_IMETHODIMP DocumentLoaderObserverImpl::OnEndDocumentLoad(nsIDocumentLoader* loader,
nsIChannel* channel,
nsresult aStatus)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("!!DocumentLoaderObserverImpl.cpp: OnEndDocumentLoad\n"));
}
#endif
nsCOMPtr<nsIDOMDocument> doc;
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;
}
mInitContext->currentDocument = doc;
// if we have a mouse listener
if (mMouseListener) {
// install the mouse listener into mozilla
PR_ASSERT(mMouseListener);
nsresult rv;
rv = doc->QueryInterface(NS_GET_IID(nsIDOMEventTarget),
getter_AddRefs(mDomEventTarget));
if (NS_FAILED(rv) || !mDomEventTarget) {
return NS_OK;
}
nsAutoString eType("mouseover");
mDomEventTarget->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,
maskValues[END_DOCUMENT_LOAD_EVENT_MASK], nsnull);
return NS_OK;
}
NS_IMETHODIMP DocumentLoaderObserverImpl::OnStartURLLoad(nsIDocumentLoader* loader,
nsIChannel* channel)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("!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);
return NS_OK;
}
NS_IMETHODIMP DocumentLoaderObserverImpl::OnProgressURLLoad(nsIDocumentLoader* loader,
nsIChannel* channel,
PRUint32 aProgress,
PRUint32 aProgressMax)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("!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);
return NS_OK;
}
NS_IMETHODIMP DocumentLoaderObserverImpl::OnStatusURLLoad(nsIDocumentLoader* loader,
nsIChannel* channel,
nsString& aMsg)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("!DocumentLoaderObserverImpl: OnStatusURLLoad: %S\n",
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, (const jchar *)
aMsg.GetUnicode(), length);
util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mTarget,
maskValues[STATUS_URL_LOAD_EVENT_MASK], (jobject) statusMessage);
if (statusMessage) {
::util_DeleteString(mInitContext->env, statusMessage);
}
return NS_OK;
}
NS_IMETHODIMP DocumentLoaderObserverImpl::OnEndURLLoad(nsIDocumentLoader* loader,
nsIChannel* channel,
nsresult aStatus)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("!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);
return NS_OK;
}
NS_IMETHODIMP DocumentLoaderObserverImpl::HandleUnknownContentType(nsIDocumentLoader* loader,
nsIChannel* channel,
const char *aContentType,
const char *aCommand)
{
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("!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<nsIDOMMouseListener> toAdd)
{
nsresult rv = NS_ERROR_FAILURE;
if (nsnull == toAdd) {
return rv;
}
mMouseListener = toAdd;
return NS_OK;
}
NS_IMETHODIMP DocumentLoaderObserverImpl::RemoveMouseListener()
{
nsresult rv = NS_OK;
if (mDomEventTarget && mMouseListener) {
nsAutoString eType("mouseover");
mDomEventTarget->RemoveEventListener(eType, mMouseListener, PR_FALSE);
mDomEventTarget = nsnull;
mMouseListener = nsnull;
}
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;
}

Просмотреть файл

@ -93,6 +93,10 @@ include <$(DEPTH)\config\rules.mak>
include <$(DEPTH)\java\config\localdefs.mak>
!ifdef CLASSPATH
JAVAC_CLASSPATH=$(JAVAC_CLASSPATH);$(CLASSPATH)
!endif
!ifdef BAL_INTERFACE
INCS = \
-I..\bal\ \
@ -188,3 +192,4 @@ clobber::
rm -f nsSetupRegistry.cpp
rm -f .\$(OBJDIR)\runem.bat
rm -f .\$(OBJDIR)\swingem.bat

Просмотреть файл

@ -94,6 +94,7 @@ JNIEXPORT jint JNICALL Java_org_mozilla_webclient_wrapper_1native_WindowControlI
initContext->w = width;
initContext->h = height;
initContext->searchContext = nsnull;
initContext->currentDocument = nsnull;
#ifdef XP_UNIX
initContext->gtkWinPtr =
@ -147,6 +148,7 @@ Java_org_mozilla_webclient_wrapper_1native_WindowControlImpl_nativeDestroyInitCo
initContext->h = -1;
initContext->gtkWinPtr = nsnull;
initContext->searchContext = nsnull;
initContext->currentDocument = nsnull;
delete initContext;
}

Просмотреть файл

@ -44,6 +44,7 @@
#include "nsIWebShell.h" // for nsIWebShell
#include "nsIEventQueueService.h" // for PLEventQueue
#include "nsISearchContext.h" // for Find
#include "nsIDOMDocument.h"
#include "ns_globals.h"
@ -84,6 +85,7 @@ struct WebShellInitContext {
int h;
int gtkWinPtr;
nsCOMPtr<nsISearchContext> searchContext;
nsCOMPtr<nsIDOMDocument> currentDocument;
};
enum {