From ed7795ffac0e83b93d360b13fd30dc727488c355 Mon Sep 17 00:00:00 2001 From: "edburns%acm.org" Date: Wed, 9 Apr 2003 17:42:41 +0000 Subject: [PATCH] Author= Daniel Park r=edburns SECTION: classes changes M build.xml - Removed spurious linebreak on Kyle's create.webclient.scripts. M classes_spec/org/mozilla/webclient/BrowserControlCanvas.java - Bugfix from Daniel Park M classes_spec/org/mozilla/webclient/test/EMWindow.java - Leverage new CurrentPage2 interface to display the Selection object. M classes_spec/org/mozilla/webclient/wrapper_native/CurrentPageImpl.java M classes_spec/org/mozilla/webclient/wrapper_nonnative/CurrentPageImpl.java - Implement new methods from CurrentPage2. M src_moz/CurrentPageActionEvents.cpp M src_moz/CurrentPageActionEvents.h M src_moz/CurrentPageImpl.cpp M src_moz/gtk/GtkBrowserControlCanvasStub.cpp M src_moz/gtk/StubFunctions.h Native details for CurrentPage2. SECTION: New files A classes_spec/org/mozilla/webclient/Selection.java A classes_spec/org/mozilla/webclient/CurrentPage2.java A classes_spec/org/mozilla/webclient/wrapper_native/SelectionImpl.java git-svn-id: svn://10.0.0.236/trunk@140912 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/java/webclient/build.xml | 6 +- .../webclient/BrowserControlCanvas.java | 8 +- .../org/mozilla/webclient/CurrentPage2.java | 35 +++ .../org/mozilla/webclient/Selection.java | 123 +++++++++ .../org/mozilla/webclient/test/EMWindow.java | 21 +- .../wrapper_native/CurrentPageImpl.java | 49 +++- .../wrapper_native/SelectionImpl.java | 100 +++++++ .../wrapper_nonnative/CurrentPageImpl.java | 23 +- .../src_moz/CurrentPageActionEvents.cpp | 261 ++++++++++++++++++ .../src_moz/CurrentPageActionEvents.h | 36 +++ .../webclient/src_moz/CurrentPageImpl.cpp | 60 ++++ .../gtk/GtkBrowserControlCanvasStub.cpp | 48 ++++ .../webclient/src_moz/gtk/StubFunctions.h | 3 + 13 files changed, 756 insertions(+), 17 deletions(-) create mode 100644 mozilla/java/webclient/classes_spec/org/mozilla/webclient/CurrentPage2.java create mode 100644 mozilla/java/webclient/classes_spec/org/mozilla/webclient/Selection.java create mode 100644 mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/SelectionImpl.java diff --git a/mozilla/java/webclient/build.xml b/mozilla/java/webclient/build.xml index cb893fb2721..8947707b873 100644 --- a/mozilla/java/webclient/build.xml +++ b/mozilla/java/webclient/build.xml @@ -202,8 +202,7 @@ depends="create.win32.webclient.scripts,create.unix.webclient.scripts"/> - + @@ -221,8 +220,7 @@ ${myenv.MOZ_JDKHOME}/bin/java ${debug.options} org.mozilla.webclient.test.Embedd - + diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/BrowserControlCanvas.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/BrowserControlCanvas.java index b904c0716f0..c92c15e9b8f 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/BrowserControlCanvas.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/BrowserControlCanvas.java @@ -52,7 +52,7 @@ import java.awt.*; * See concrete subclasses for scope info. - * @version $Id: BrowserControlCanvas.java,v 1.4 2002-10-01 00:39:19 edburns%acm.org Exp $ + * @version $Id: BrowserControlCanvas.java,v 1.5 2003-04-09 17:42:30 edburns%acm.org Exp $ * @see org.mozilla.webclient.win32.Win32BrowserControlCanvas @@ -229,6 +229,12 @@ public void setBounds(int x, int y, int w, int h) super.setBounds(x, y, w, h); Rectangle boundsRect = new Rectangle(0, 0, w - 1, h - 1); if (webShell != null) { + if (boundsRect.width < 1) { + boundsRect.width = 1; + } + if (boundsRect.height < 1) { + boundsRect.height = 1; + } System.out.println("in BrowserControlCanvas setBounds: x = " + x + " y = " + y + " w = " + w + " h = " + h); try { WindowControl wc = (WindowControl) diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/CurrentPage2.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/CurrentPage2.java new file mode 100644 index 00000000000..733678c7d90 --- /dev/null +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/CurrentPage2.java @@ -0,0 +1,35 @@ +/* -*- 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): Daniel Park + */ + +package org.mozilla.webclient; + + +public interface CurrentPage2 extends CurrentPage +{ + public Selection getSelection(); + + public void highlightSelection(Selection selection); + + public void clearAllSelections(); + +} +// end of interface CurrentPage diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/Selection.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/Selection.java new file mode 100644 index 00000000000..29fe2ae327b --- /dev/null +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/Selection.java @@ -0,0 +1,123 @@ +/* -*- 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. + */ + +package org.mozilla.webclient; + +import org.w3c.dom.Node; + + /** + * Selection is more like a DOM Range object which represents a + * portion of a document or a document fragment. This is described as + * all of the content between two boundary points, the start and end + * containers. A selection is define by the following properties: + * startContainer, endContainer, startOffset, endOffset and the text + * representation of the selection. + * + *

+ *

    + * + *
  • startContainer: This property is a reference to a Node + * within the document or document fragment. The start of the range + * is contained within this node and the boundary point is determined + * by the startOffset property. + * + *
  • endContainer: This property is a reference to a Node within the + * document or document fragment. The end of the range is contained + * within this node and the boundary point is determined by the + * endOffset property. + * + *
  • startOffset: This property has one of two meanings, depending + * upon the type of node that the startContainer references. If the + * startContainer is a Text node, Comment node or a CDATASection node + * then this offset represents the number of characters from the + * beginning of the node to where the boundary point lies. Any other + * type of node and it represents the child node index number that the + * boundary point lies BEFORE. If the offset is equal to the number + * of child nodes then the boundary point lies after the last child + * node. + * + *
  • endOffset: This property has one of two meanings, depending + * upon the type of node that the endContainer references. If the + * endContainer is a Text node, Comment node or a CDATASection node + * then this offset represents the number of characters from the + * beginning of the node to where the boundary point lies. Any other + * type of node and it represents the child node index number that the + * boundary point lies BEFORE. If the offset is equal to the number + * of child nodes then the boundary point lies after the last child + * node. + * + *
+ * + * @author daepark@apmindsf.com + */ + +public interface Selection { + + /** + * Initialize this Selection object. + * + * @param selection the text representation of this selection + * @param startContainer the start of this selection is contained + * within this node + * @param endContainer the end of this selection is contained within + * this node + * @param startOffset the offset to which the selection starts + * within the startContainer + * @param endOffset the offset to which the selection ends within + * the endContainer + * @see #isValid + */ + public void init(String selection, + Node startContainer, + Node endContainer, + int startOffset, + int endOffset); + + /** + * Get the text representation of this Selection object. + */ + public String toString(); + + /** + * Get the Node that contains the start of this selection. + */ + public Node getStartContainer(); + + /** + * Get the Node that contains the end of this selection. + */ + public Node getEndContainer(); + + /** + * Get the offset to which the selection starts within the startContainer. + */ + public int getStartOffset(); + + /** + * Get the offset to which the selection ends within the endContainer. + */ + public int getEndOffset(); + + /** + * Test if the selection properties have been set. + */ + public boolean isValid(); + +} // end interface "Selection" 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 918821c7ed0..38ca69cc0f1 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 @@ -59,7 +59,7 @@ import java.io.FileInputStream; * This is a test application for using the BrowserControl. * - * @version $Id: EMWindow.java,v 1.37 2002-08-31 02:09:12 edburns%acm.org Exp $ + * @version $Id: EMWindow.java,v 1.38 2003-04-09 17:42:32 edburns%acm.org Exp $ * * @see org.mozilla.webclient.BrowserControlFactory @@ -76,7 +76,7 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc private BrowserControlCanvas browserCanvas; private Navigation2 navigation = null; - private CurrentPage currentPage; + private CurrentPage2 currentPage; private History history; private static Preferences prefs; private Bookmarks bookmarks; @@ -109,7 +109,7 @@ private UniversalDialog uniDialog = null; private Component refreshButton; private PopupMenu popup; - private MenuItem popup_ViewSource, popup_SelectAll; + private MenuItem popup_ViewSource, popup_SelectAll, popup_ViewSelection; private PopupActionListener contextListener; private String myBinDir; @@ -294,11 +294,13 @@ private UniversalDialog uniDialog = null; popup.add(popup_ViewSource = new MenuItem("View Source as ByteArray")); popup.add(popup_SelectAll = new MenuItem("Select All")); + popup.add(popup_ViewSelection = new MenuItem("View Selection")); contextListener = new PopupActionListener(); popup_ViewSource.addActionListener (contextListener); popup_SelectAll.addActionListener (contextListener); + popup_ViewSelection.addActionListener (contextListener); show(); toFront(); @@ -307,7 +309,7 @@ private UniversalDialog uniDialog = null; navigation = (Navigation2) browserControl.queryInterface(BrowserControl.NAVIGATION_NAME); navigation.setPrompt(this); - currentPage = (CurrentPage) + currentPage = (CurrentPage2) browserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME); history = (History) browserControl.queryInterface(BrowserControl.HISTORY_NAME); @@ -589,7 +591,7 @@ public void dialogDismissed(Dialog d) { else if(searchString.equals("")) { System.out.println("Clear button selected"); try { - CurrentPage currentPage = (CurrentPage) + CurrentPage2 currentPage = (CurrentPage2) browserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME); currentPage.resetFind(); } @@ -601,7 +603,7 @@ public void dialogDismissed(Dialog d) { System.out.println("Tring to Find String - " + searchString); System.out.println("Parameters are - Backwrads = " + findDialog.backwards + " and Matchcase = " + findDialog.matchcase); try { - CurrentPage currentPage = (CurrentPage) + CurrentPage2 currentPage = (CurrentPage2) browserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME); currentPage.findInPage(searchString, !findDialog.backwards, findDialog.matchcase); } @@ -967,6 +969,13 @@ public void actionPerformed(ActionEvent event) { System.out.println("I will now Select All"); EMWindow.this.currentPage.selectAll(); } + else if (command.equals("View Selection")) { + Selection selection = EMWindow.this.currentPage.getSelection(); + if (selection != null) { + System.err.println("you've selected: " + selection.toString()); + } + } + } } diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/CurrentPageImpl.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/CurrentPageImpl.java index 7208ddbef9a..1e1ce582d6b 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/CurrentPageImpl.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/CurrentPageImpl.java @@ -27,7 +27,8 @@ import org.mozilla.util.Log; import org.mozilla.util.ParameterCheck; import org.mozilla.webclient.BrowserControl; -import org.mozilla.webclient.CurrentPage; +import org.mozilla.webclient.CurrentPage2; +import org.mozilla.webclient.Selection; import org.mozilla.webclient.WindowControl; import org.mozilla.webclient.WrapperFactory; @@ -36,12 +37,13 @@ import java.io.*; import java.net.*; import org.w3c.dom.Document; +import org.w3c.dom.Node; import org.mozilla.webclient.UnimplementedException; import org.mozilla.dom.DOMAccessor; -public class CurrentPageImpl extends ImplObjectNative implements CurrentPage +public class CurrentPageImpl extends ImplObjectNative implements CurrentPage2 { // // Protected Constants @@ -97,6 +99,41 @@ public void copyCurrentSelectionToSystemClipboard() nativeCopyCurrentSelectionToSystemClipboard(nativeWebShell); } } + +public Selection getSelection() { + Selection selection = new SelectionImpl(); + + myFactory.throwExceptionIfNotInitialized(); + Assert.assert_it(-1 != nativeWebShell); + synchronized(myBrowserControl) { + nativeGetSelection(nativeWebShell, selection); + } + + return selection; +} + +public void highlightSelection(Selection selection) { + if (selection != null && selection.isValid()) { + Node startContainer = selection.getStartContainer(); + Node endContainer = selection.getEndContainer(); + int startOffset = selection.getStartOffset(); + int endOffset = selection.getEndOffset(); + + myFactory.throwExceptionIfNotInitialized(); + Assert.assert_it(-1 != nativeWebShell); + synchronized(myBrowserControl) { + nativeHighlightSelection(nativeWebShell, startContainer, endContainer, startOffset, endOffset); + } + } +} + +public void clearAllSelections() { + myFactory.throwExceptionIfNotInitialized(); + Assert.assert_it(-1 != nativeWebShell); + synchronized(myBrowserControl) { + nativeClearAllSelections(nativeWebShell); + } +} public void findInPage(String stringToFind, boolean forward, boolean matchCase) { @@ -235,6 +272,12 @@ public void selectAll() // native public void nativeCopyCurrentSelectionToSystemClipboard(int webShellPtr); +native public void nativeGetSelection(int webShellPtr, + Selection selection); + +native public void nativeHighlightSelection(int webShellPtr, Node startContainer, Node endContainer, int startOffset, int endOffset); + +native public void nativeClearAllSelections(int webShellPtr); native public void nativeFindInPage(int webShellPtr, String stringToFind, boolean forward, boolean matchCase); @@ -268,7 +311,7 @@ public static void main(String [] args) Assert.setEnabled(true); Log.setApplicationName("CurrentPageImpl"); Log.setApplicationVersion("0.0"); - Log.setApplicationVersionDate("$Id: CurrentPageImpl.java,v 1.18 2001-05-29 18:36:06 ashuk%eng.sun.com Exp $"); + Log.setApplicationVersionDate("$Id: CurrentPageImpl.java,v 1.19 2003-04-09 17:42:34 edburns%acm.org Exp $"); } diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/SelectionImpl.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/SelectionImpl.java new file mode 100644 index 00000000000..5908e824b97 --- /dev/null +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/SelectionImpl.java @@ -0,0 +1,100 @@ +/* -*- 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. + * + + * Contributor(s): Daniel Park + * + */ + +package org.mozilla.webclient.wrapper_native; + +import org.w3c.dom.Node; + +import org.mozilla.webclient.Selection; + +public class SelectionImpl extends Object implements Selection { + + private String _selection = null; + private Node _startContainer = null; + private Node _endContainer = null; + private int _startOffset = -1; + private int _endOffset = -1; + + /** + * Create an invalid (or uninitialized) Selection object. + */ + public SelectionImpl() {} + + public void init(String selection, + Node startContainer, + Node endContainer, + int startOffset, + int endOffset) + { + _selection = selection; + _startContainer = startContainer; + _endContainer = endContainer; + _startOffset = startOffset; + _endOffset = endOffset; + } + + /** + * Get the text representation of this Selection object. + */ + public String toString() { + return (_selection); + } + + /** + * Get the Node that contains the start of this selection. + */ + public Node getStartContainer() { + return (_startContainer); + } + + /** + * Get the Node that contains the end of this selection. + */ + public Node getEndContainer() { + return (_endContainer); + } + + /** + * Get the offset to which the selection starts within the startContainer. + */ + public int getStartOffset() { + return (_startOffset); + } + + /** + * Get the offset to which the selection ends within the endContainer. + */ + public int getEndOffset() { + return (_endOffset); + } + + /** + * Test if the selection properties have been set. + */ + public boolean isValid() { + if (_selection == null || + _startContainer == null || + _endContainer == null || + _startOffset == -1 || + _endOffset == -1) { + return (false); + } + + return (true); + } + +} // end class "SelectionImpl" diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_nonnative/CurrentPageImpl.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_nonnative/CurrentPageImpl.java index 157a2ea5335..9c66964436a 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_nonnative/CurrentPageImpl.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_nonnative/CurrentPageImpl.java @@ -32,7 +32,8 @@ import org.mozilla.util.ParameterCheck; import org.mozilla.webclient.BrowserControl; import org.mozilla.webclient.BrowserType; -import org.mozilla.webclient.CurrentPage; +import org.mozilla.webclient.CurrentPage2; +import org.mozilla.webclient.Selection; import org.mozilla.webclient.WrapperFactory; import java.util.Properties; @@ -40,6 +41,7 @@ import java.io.*; import java.net.*; import org.w3c.dom.Document; +import org.w3c.dom.Node; import ice.storm.*; @@ -73,7 +75,22 @@ public void copyCurrentSelectionToSystemClipboard() { throw new UnimplementedException("\nUnimplementedException -----\n API Function CurrentPage::copyCurrentSelectionToSystemClipboard has not yet been implemented.\n"); } - + +public Selection getSelection() { + throw new UnimplementedException("\nUnimplementedException -----\n API Function CurrentPage::getSelection has not yet been implemented.\n"); +} + +public void highlightSelection(Selection selection) { + throw new UnimplementedException("\nUnimplementedException -----\n API Function CurrentPage::highlightSelection has not yet been implemented.\n"); +} + +public void clearAllSelections() { + throw new UnimplementedException("\nUnimplementedException -----\n API Function CurrentPage::clearAllSelections has not yet been implemented.\n"); +} + + public void findInPage(String stringToFind, boolean forward, boolean matchCase) + { + throw new UnimplementedException("\nUnimplementedException -----\n API Function CurrentPage::findInPage has not yet been implemented.\n"); public void findInPage(String stringToFind, boolean forward, boolean matchCase) { throw new UnimplementedException("\nUnimplementedException -----\n API Function CurrentPage::findInPage has not yet been implemented.\n"); @@ -190,7 +207,7 @@ public static void main(String [] args) Assert.setEnabled(true); Log.setApplicationName("CurrentPageImpl"); Log.setApplicationVersion("0.0"); - Log.setApplicationVersionDate("$Id: CurrentPageImpl.java,v 1.1 2001-07-27 21:01:08 ashuk%eng.sun.com Exp $"); + Log.setApplicationVersionDate("$Id: CurrentPageImpl.java,v 1.2 2003-04-09 17:42:38 edburns%acm.org Exp $"); } diff --git a/mozilla/java/webclient/src_moz/CurrentPageActionEvents.cpp b/mozilla/java/webclient/src_moz/CurrentPageActionEvents.cpp index 630546d8c30..f0a4115dd62 100644 --- a/mozilla/java/webclient/src_moz/CurrentPageActionEvents.cpp +++ b/mozilla/java/webclient/src_moz/CurrentPageActionEvents.cpp @@ -46,6 +46,12 @@ #include "nsString.h" #include "nsReadableUtils.h" #include "nsIWebBrowserFind.h" +#include "nsIDOMWindow.h" +#include "nsISelection.h" +#include "nsIDOMRange.h" +#include "nsIDOMDocumentRange.h" +#include "nsIDOMNode.h" +#include "nsCRT.h" wsCopySelectionEvent::wsCopySelectionEvent(WebShellInitContext *yourInitContext) : nsActionEvent(), @@ -75,6 +81,261 @@ wsCopySelectionEvent::handleEvent () return result; } +wsGetSelectionEvent::wsGetSelectionEvent(JNIEnv *yourEnv, WebShellInitContext *yourInitContext, jobject yourSelection) : + nsActionEvent(), + mEnv(yourEnv), + mInitContext(yourInitContext), + mSelection(yourSelection) +{ +} + +void * +wsGetSelectionEvent::handleEvent() +{ + void *result = nsnull; + + if (mEnv != nsnull && mInitContext != nsnull && mSelection != nsnull) { + nsresult rv = nsnull; + + // Get the DOM window + nsIDOMWindow *domWindow; + rv = mInitContext->webBrowser->GetContentDOMWindow(&domWindow); + if (NS_FAILED(rv) || domWindow == nsnull ) { + return (void *) rv; + } + + // Get the selection object of the DOM window + nsISelection *selection; + rv = domWindow->GetSelection(&selection); + if (NS_FAILED(rv) || selection == nsnull) { + return (void *) rv; + } + + // Get the range count + PRInt32 rangeCount; + rv = selection->GetRangeCount(&rangeCount); + if (NS_FAILED(rv) || rangeCount == 0) { + return (void *) rv; + } + + // Get the actual selection string + PRUnichar *selectionStr; + rv = selection->ToString(&selectionStr); + if (NS_FAILED(rv)) { + return (void *) rv; + } + + jstring string = + mEnv->NewString((jchar*)selectionStr, nsCRT::strlen(selectionStr)); + + // Get the first range object of the selection object + nsIDOMRange *range; + rv = selection->GetRangeAt(0, &range); + if (NS_FAILED(rv) || range == nsnull) { + return (void *) rv; + } + + // Get the properties of the range object (startContainer, + // startOffset, endContainer, endOffset) + PRInt32 startOffset; + PRInt32 endOffset; + nsIDOMNode* startContainer; + nsIDOMNode* endContainer; + + // start container + rv = range->GetStartContainer(&startContainer); + if (NS_FAILED(rv)) { + return (void *) rv; + } + + // end container + rv = range->GetEndContainer(&endContainer); + if (NS_FAILED(rv)) { + return (void *) rv; + } + + // start offset + rv = range->GetStartOffset(&startOffset); + if (NS_FAILED(rv)) { + return (void *) rv; + } + + // end offset + rv = range->GetEndOffset(&endOffset); + if (NS_FAILED(rv)) { + return (void *) rv; + } + + // get a handle on to acutal (java) Node representing the start + // and end containers + jlong node1Long = nsnull; + jlong node2Long = nsnull; + + nsCOMPtr node1Ptr(do_QueryInterface(startContainer)); + nsCOMPtr node2Ptr(do_QueryInterface(endContainer)); + + if (nsnull == (node1Long = (jlong)node1Ptr.get())) { + return result; + } + if (nsnull == (node2Long = (jlong)node2Ptr.get())) { + return result; + } + + jclass clazz = nsnull; + jmethodID mid = nsnull; + + if (nsnull == (clazz = ::util_FindClass(mEnv, + "org/mozilla/dom/DOMAccessor"))) { + return result; + } + if (nsnull == (mid = mEnv->GetStaticMethodID(clazz, "getNodeByHandle", + "(J)Lorg/w3c/dom/Node;"))) { + return result; + } + + jobject node1 = (jobject) ((void *)::util_CallStaticObjectMethodlongArg(mEnv, clazz, mid, node1Long)); + jobject node2 = (jobject) ((void *)::util_CallStaticObjectMethodlongArg(mEnv, clazz, mid, node2Long)); + + // prepare the (java) Selection object that is to be returned. + if (nsnull == (clazz = ::util_FindClass(mEnv, "org/mozilla/webclient/Selection"))) { + return result; + } + + if (nsnull == (mid = mEnv->GetMethodID(clazz, "init", + "(Ljava/lang/String;Lorg/w3c/dom/Node;Lorg/w3c/dom/Node;II)V"))) { + return result; + } + + mEnv->CallVoidMethod(mSelection, mid, + string, node1, node2, + (jint)startOffset, (jint)endOffset); + } + + return result; +} + + +wsHighlightSelectionEvent::wsHighlightSelectionEvent(JNIEnv *yourEnv, WebShellInitContext *yourInitContext, jobject startContainer, jobject endContainer, PRInt32 startOffset, PRInt32 endOffset) : + nsActionEvent(), + mEnv(yourEnv), + mInitContext(yourInitContext), + mStartContainer(startContainer), + mEndContainer(endContainer), + mStartOffset(startOffset), + mEndOffset(endOffset) +{ +} + +void * +wsHighlightSelectionEvent::handleEvent() +{ + void *result = nsnull; + + if (mEnv != nsnull && mInitContext != nsnull && + mStartContainer != nsnull && mEndContainer != nsnull && + mStartOffset > -1 && mEndOffset > -1) + { + nsresult rv = nsnull; + + // resolve ptrs to the nodes + jclass nodeClass = mEnv->FindClass("org/mozilla/dom/NodeImpl"); + if (!nodeClass) { + return result; + } + jfieldID nodePtrFID = mEnv->GetFieldID(nodeClass, "p_nsIDOMNode", "J"); + if (!nodePtrFID) { + return result; + } + + // get the nsIDOMNode representation of the start and end containers + nsIDOMNode* node1 = (nsIDOMNode*) + mEnv->GetLongField(mStartContainer, nodePtrFID); + + nsIDOMNode* node2 = (nsIDOMNode*) + mEnv->GetLongField(mEndContainer, nodePtrFID); + + if (!node1 || !node2) { + return result; + } + + // Get the DOM window + nsIDOMWindow* domWindow; + rv = mInitContext->webBrowser->GetContentDOMWindow(&domWindow); + if (NS_FAILED(rv) || domWindow == nsnull ) { + return (void *) rv; + } + + // Get the selection object of the DOM window + nsISelection* selection; + rv = domWindow->GetSelection(&selection); + if (NS_FAILED(rv) || selection == nsnull) { + return (void *) rv; + } + + nsCOMPtr docRange(do_QueryInterface(mInitContext->currentDocument)); + if (docRange) { + nsCOMPtr range; + rv = docRange->CreateRange(getter_AddRefs(range)); + + if (range) { + rv = range->SetStart(node1, mStartOffset); + if (NS_FAILED(rv)) { + return (void *) rv; + } + + rv = range->SetEnd(node2, mEndOffset); + if (NS_FAILED(rv)) { + return (void *) rv; + } + + rv = selection->AddRange(range); + if (NS_FAILED(rv)) { + return (void *) rv; + } + } + } + } + + return result; +} + +wsClearAllSelectionEvent::wsClearAllSelectionEvent(WebShellInitContext *yourInitContext) : + nsActionEvent(), + mInitContext(yourInitContext) +{ +} + +void * +wsClearAllSelectionEvent::handleEvent() +{ + void *result = nsnull; + + if (mInitContext != nsnull) { + nsresult rv = nsnull; + + // Get the DOM window + nsIDOMWindow* domWindow; + rv = mInitContext->webBrowser->GetContentDOMWindow(&domWindow); + if (NS_FAILED(rv) || domWindow == nsnull ) { + return (void *) rv; + } + + // Get the selection object of the DOM window + nsISelection* selection; + rv = domWindow->GetSelection(&selection); + if (NS_FAILED(rv) || selection == nsnull) { + return (void *) rv; + } + + rv = selection->RemoveAllRanges(); + if (NS_FAILED(rv)) { + return (void *) rv; + } + } + + return result; +} + wsFindEvent::wsFindEvent(WebShellInitContext *yourInitContext) : nsActionEvent(), mInitContext(yourInitContext), diff --git a/mozilla/java/webclient/src_moz/CurrentPageActionEvents.h b/mozilla/java/webclient/src_moz/CurrentPageActionEvents.h index 5ce1c72fc90..a5956728d24 100644 --- a/mozilla/java/webclient/src_moz/CurrentPageActionEvents.h +++ b/mozilla/java/webclient/src_moz/CurrentPageActionEvents.h @@ -102,6 +102,42 @@ protected: jlong mDoc; }; +class wsGetSelectionEvent: public nsActionEvent { +public: + wsGetSelectionEvent (JNIEnv *yourEnv, WebShellInitContext *yourInitContext, jobject yourSelection); + void * handleEvent (void); + +protected: + JNIEnv * mEnv; + WebShellInitContext *mInitContext; + jobject mSelection; +}; + + +class wsHighlightSelectionEvent: public nsActionEvent { +public: + wsHighlightSelectionEvent (JNIEnv *yourEnv, WebShellInitContext *yourInitContext, jobject startContainer, jobject endContainer, PRInt32 startOffset, PRInt32 endOffset); + void * handleEvent (void); + +protected: + JNIEnv *mEnv; + WebShellInitContext *mInitContext; + jobject mStartContainer; + jobject mEndContainer; + PRInt32 mStartOffset; + PRInt32 mEndOffset; +}; + + +class wsClearAllSelectionEvent: public nsActionEvent { +public: + wsClearAllSelectionEvent (WebShellInitContext *yourInitContext); + void * handleEvent (void); + +protected: + WebShellInitContext *mInitContext; +}; + #endif /* CurrentPageActionEvents_h___ */ diff --git a/mozilla/java/webclient/src_moz/CurrentPageImpl.cpp b/mozilla/java/webclient/src_moz/CurrentPageImpl.cpp index 4972c730572..7e7ae5d0149 100644 --- a/mozilla/java/webclient/src_moz/CurrentPageImpl.cpp +++ b/mozilla/java/webclient/src_moz/CurrentPageImpl.cpp @@ -51,6 +51,66 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImp } +JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeGetSelection +(JNIEnv *env, jobject obj, jint webShellPtr, jobject selection) +{ + WebShellInitContext *initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed nativeGetSelection"); + return; + } + + PR_ASSERT(initContext->initComplete); + + if (selection == nsnull) { + ::util_ThrowExceptionToJava(env, "Exception: null Selection object passed to raptorWebShellGetSelection"); + return; + } + + wsGetSelectionEvent *actionEvent = new wsGetSelectionEvent(env, initContext, selection); + + PLEvent *event = (PLEvent *) *actionEvent; + ::util_PostSynchronousEvent(initContext, event); +} + + +JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeHighlightSelection +(JNIEnv *env, jobject obj, jint webShellPtr, jobject startContainer, jobject endContainer, jint startOffset, jint endOffset) +{ + WebShellInitContext *initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to nativeHighlightSelection"); + return; + } + + PR_ASSERT(initContext->initComplete); + + wsHighlightSelectionEvent *actionEvent = new wsHighlightSelectionEvent(env, initContext, startContainer, endContainer, (PRInt32) startOffset, (PRInt32) endOffset); + PLEvent *event = (PLEvent *) *actionEvent; + ::util_PostSynchronousEvent(initContext, event); +} + + +JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeClearAllSelections +(JNIEnv *env, jobject obj, jint webShellPtr) +{ + WebShellInitContext *initContext = (WebShellInitContext *) webShellPtr; + + if (initContext == nsnull) { + ::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to nativeClearAllSelections"); + return; + } + + PR_ASSERT(initContext->initComplete); + + wsClearAllSelectionEvent *actionEvent = new wsClearAllSelectionEvent(initContext); + + PLEvent *event = (PLEvent *) *actionEvent; + ::util_PostSynchronousEvent(initContext, event); +} + /* * Class: org_mozilla_webclient_wrapper_0005fnative_CurrentPageImpl * Method: nativeFindInPage diff --git a/mozilla/java/webclient/src_moz/gtk/GtkBrowserControlCanvasStub.cpp b/mozilla/java/webclient/src_moz/gtk/GtkBrowserControlCanvasStub.cpp index 2f59fe413a7..484166d7214 100644 --- a/mozilla/java/webclient/src_moz/gtk/GtkBrowserControlCanvasStub.cpp +++ b/mozilla/java/webclient/src_moz/gtk/GtkBrowserControlCanvasStub.cpp @@ -351,6 +351,25 @@ int locateStubFunctions(void *dll) PR_LOG(webclientStubLog, PR_LOG_ERROR, ("got dlsym error %s\n", dlerror())); return -1; } + + nativeGetSelection = (void (*) (JNIEnv *env, jobject obj, jint webShellPtr, jobject selection)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeGetSelection"); + if (!nativeGetSelection) { + PR_LOG(webclientStubLog, PR_LOG_ERROR, ("got dlsym error %s\n", dlerror())); + return -1; + } + + nativeHighlightSelection = (void (*) (JNIEnv *env, jobject obj, jint webShellPtr, jobject startContainer, jobject endContainer, jint startOffset, jint endOffset)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeHighlightSelection"); + if (!nativeHighlightSelection) { + PR_LOG(webclientStubLog, PR_LOG_ERROR, ("got dlsym error %s\n", dlerror())); + return -1; + } + + nativeClearAllSelections = (void (*) (JNIEnv *env, jobject obj, jint webShellPtr)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeClearAllSelections"); + if (!nativeClearAllSelections) { + PR_LOG(webclientStubLog, PR_LOG_ERROR, ("got dlsym error %s\n", dlerror())); + return -1; + } + nativeFindInPage = (void (*) (JNIEnv *, jobject, jint, jstring, jboolean, jboolean)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeFindInPage"); if (!nativeFindInPage) { PR_LOG(webclientStubLog, PR_LOG_ERROR, ("got dlsym error %s\n", dlerror())); @@ -648,6 +667,35 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImp (* nativeCopyCurrentSelectionToSystemClipboard) (env, obj, webShellPtr); } +/* + * Class: org_mozilla_webclient_wrapper_0005fnative_CurrentPageImpl + * Method: nativeGetSelection + * Signature: (ILorg/mozilla/webclient/Selection;)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeGetSelection +(JNIEnv *env, jobject obj, jint webShellPtr, jobject selection) { + (* nativeGetSelection) (env, obj, webShellPtr, selection); +} + +/* + * Class: org_mozilla_webclient_wrapper_0005fnative_CurrentPageImpl + * Method: nativeHighlightSelection + * Signature: (ILorg/w3c/dom/Node;Lorg/w3c/dom/Node;II)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeHighlightSelection +(JNIEnv *env, jobject obj, jint webShellPtr, jobject startContainer, jobject endContainer, jint startOffset, jint endOffset) { + (* nativeHighlightSelection) (env, obj, webShellPtr, startContainer, endContainer, startOffset, endOffset); +} + +/* + * Class: org_mozilla_webclient_wrapper_0005fnative_CurrentPageImpl + * Method: nativeClearAllSelections + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPageImpl_nativeClearAllSelections +(JNIEnv *env, jobject obj, jint webShellPtr) { + (* nativeClearAllSelections) (env, obj, webShellPtr); + /* * Class: org_mozilla_webclient_wrapper_0005fnative_CurrentPageImpl * Method: nativeFindInPage diff --git a/mozilla/java/webclient/src_moz/gtk/StubFunctions.h b/mozilla/java/webclient/src_moz/gtk/StubFunctions.h index 48bd15393d3..a4196351903 100644 --- a/mozilla/java/webclient/src_moz/gtk/StubFunctions.h +++ b/mozilla/java/webclient/src_moz/gtk/StubFunctions.h @@ -81,6 +81,9 @@ jobject (* nativeGetPrefs) (JNIEnv *env, jobject obj, jint webShellPtr, jobject void (* nativeRegisterPrefChangedCallback) (JNIEnv *env, jobject obj, jint webShellPtr, jobject callback, jstring prefName, jobject closure); // from CurrentPageImpl.h void (* nativeCopyCurrentSelectionToSystemClipboard) (JNIEnv *, jobject, jint); +void (* nativeGetSelection) (JNIEnv *, jobject, jint, jobject); +void (* nativeHighlightSelection) (JNIEnv *, jobject, jint, jobject, jobject, jint, jint); +void (* nativeClearAllSelections) (JNIEnv *, jobject, jint); void (* nativeFindInPage) (JNIEnv *, jobject, jint, jstring, jboolean, jboolean); void (* nativeFindNextInPage) (JNIEnv *, jobject, jint); jstring (* nativeGetCurrentURL) (JNIEnv *, jobject, jint);