Next step is to try to re-enable the printing APIs. Not sure if this
will work. A test/automated/src/test/DOMSelectionTest.html - test CurrentPage.highlightSelection and clearAllSelections(). M classes_spec/org/mozilla/webclient/impl/wrapper_native/CurrentPageImpl.java - send all native methods through the event thread M classes_spec/org/mozilla/webclient/impl/wrapper_native/SelectionImpl.java - never return null from toString(). Return "" instead. M src_moz/CurrentPageImpl.cpp - copy from CurrentPageActionEvents.cpp M test/automated/src/classes/org/mozilla/webclient/CurrentPageTest.java M test/automated/src/classes/org/mozilla/webclient/DOMTest.java - new test conent git-svn-id: svn://10.0.0.236/trunk@169173 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
a686f22491
commit
a5d1754eb2
@ -119,70 +119,77 @@ public Selection getSelection() {
|
||||
|
||||
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();
|
||||
final Node startContainer = selection.getStartContainer();
|
||||
final Node endContainer = selection.getEndContainer();
|
||||
final int startOffset = selection.getStartOffset();
|
||||
final int endOffset = selection.getEndOffset();
|
||||
|
||||
getWrapperFactory().verifyInitialized();
|
||||
Assert.assert_it(-1 != getNativeBrowserControl());
|
||||
synchronized(getBrowserControl()) {
|
||||
nativeHighlightSelection(getNativeBrowserControl(), startContainer, endContainer, startOffset, endOffset);
|
||||
NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() {
|
||||
public Object run() {
|
||||
nativeHighlightSelection(CurrentPageImpl.this.getNativeBrowserControl(),
|
||||
startContainer, endContainer,
|
||||
startOffset, endOffset);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAllSelections() {
|
||||
getWrapperFactory().verifyInitialized();
|
||||
Assert.assert_it(-1 != getNativeBrowserControl());
|
||||
synchronized(getBrowserControl()) {
|
||||
nativeClearAllSelections(getNativeBrowserControl());
|
||||
NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() {
|
||||
public Object run() {
|
||||
nativeClearAllSelections(CurrentPageImpl.this.getNativeBrowserControl());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void findInPage(String stringToFind, boolean forward, boolean matchCase)
|
||||
{
|
||||
find(stringToFind, forward, matchCase);
|
||||
}
|
||||
|
||||
public boolean find(String stringToFind, boolean forward, boolean matchCase)
|
||||
public boolean find(String toFind, boolean dir, boolean doCase)
|
||||
{
|
||||
final String stringToFind = toFind;
|
||||
final boolean forward = dir;
|
||||
final boolean matchCase = doCase;
|
||||
ParameterCheck.nonNull(stringToFind);
|
||||
getWrapperFactory().verifyInitialized();
|
||||
boolean result = false;
|
||||
Boolean result = Boolean.FALSE;
|
||||
|
||||
synchronized(getBrowserControl()) {
|
||||
result = nativeFind(getNativeBrowserControl(), stringToFind, forward,
|
||||
matchCase);
|
||||
}
|
||||
return result;
|
||||
result = (Boolean)
|
||||
NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable(){
|
||||
public Object run() {
|
||||
boolean rc = nativeFind(CurrentPageImpl.this.getNativeBrowserControl(),
|
||||
stringToFind, forward, matchCase);
|
||||
return rc ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
});
|
||||
return result.booleanValue();
|
||||
}
|
||||
|
||||
public void findNextInPage()
|
||||
{
|
||||
getWrapperFactory().verifyInitialized();
|
||||
|
||||
synchronized(getBrowserControl()) {
|
||||
nativeFindNext(getNativeBrowserControl());
|
||||
}
|
||||
findNext();
|
||||
}
|
||||
|
||||
public boolean findNext()
|
||||
{
|
||||
getWrapperFactory().verifyInitialized();
|
||||
boolean result = false;
|
||||
|
||||
synchronized(getBrowserControl()) {
|
||||
result = nativeFindNext(getNativeBrowserControl());
|
||||
}
|
||||
return result;
|
||||
Boolean result = Boolean.FALSE;
|
||||
|
||||
result = (Boolean)
|
||||
NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable(){
|
||||
public Object run() {
|
||||
boolean rc = nativeFindNext(CurrentPageImpl.this.getNativeBrowserControl());
|
||||
return rc ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
});
|
||||
return result.booleanValue();
|
||||
}
|
||||
|
||||
|
||||
public String getCurrentURL()
|
||||
{
|
||||
String result = null;
|
||||
getWrapperFactory().verifyInitialized();
|
||||
|
||||
synchronized(getBrowserControl()) {
|
||||
result = nativeGetCurrentURL(getNativeBrowserControl());
|
||||
@ -348,21 +355,4 @@ native public void nativePrint(int webShellPtr);
|
||||
|
||||
native public void nativePrintPreview(int webShellPtr, boolean preview);
|
||||
|
||||
// ----VERTIGO_TEST_START
|
||||
|
||||
//
|
||||
// Test methods
|
||||
//
|
||||
|
||||
public static void main(String [] args)
|
||||
{
|
||||
Assert.setEnabled(true);
|
||||
Log.setApplicationName("CurrentPageImpl");
|
||||
Log.setApplicationVersion("0.0");
|
||||
Log.setApplicationVersionDate("$Id: CurrentPageImpl.java,v 1.8 2005-02-10 04:20:50 edburns%acm.org Exp $");
|
||||
|
||||
}
|
||||
|
||||
// ----VERTIGO_TEST_END
|
||||
|
||||
} // end of class CurrentPageImpl
|
||||
|
||||
@ -51,6 +51,9 @@ public class SelectionImpl extends Object implements Selection {
|
||||
* Get the text representation of this Selection object.
|
||||
*/
|
||||
public String toString() {
|
||||
if (null == _selection) {
|
||||
return "";
|
||||
}
|
||||
return (_selection);
|
||||
}
|
||||
|
||||
|
||||
@ -41,6 +41,9 @@
|
||||
#include "nsIWebBrowserFind.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMRange.h"
|
||||
#include "nsISelection.h"
|
||||
#include "nsIDOMDocumentRange.h"
|
||||
#include "nsIHistoryEntry.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
@ -90,24 +93,104 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPa
|
||||
|
||||
}
|
||||
|
||||
#if 0 // convenience
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPageImpl_nativeHighlightSelection
|
||||
(JNIEnv *env, jobject obj, jint nativeBCPtr, jobject startContainer, jobject endContainer, jint startOffset, jint endOffset)
|
||||
{
|
||||
NativeBrowserControl *nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr;
|
||||
|
||||
|
||||
if (nativeBrowserControl == nsnull) {
|
||||
::util_ThrowExceptionToJava(env, "Exception: null nativeBCPtr passed to nativeHighlightSelection");
|
||||
return;
|
||||
}
|
||||
|
||||
if (env != nsnull && startContainer != nsnull && endContainer != nsnull &&
|
||||
startOffset > -1 && endOffset > -1) {
|
||||
nsresult rv = nsnull;
|
||||
|
||||
// resolve ptrs to the nodes
|
||||
jclass nodeClass = env->FindClass("org/mozilla/dom/NodeImpl");
|
||||
if (!nodeClass) {
|
||||
::util_ThrowExceptionToJava(env, "Exception: nativeHighlightSelection");
|
||||
return;
|
||||
}
|
||||
jfieldID nodePtrFID = env->GetFieldID(nodeClass, "p_nsIDOMNode", "J");
|
||||
if (!nodePtrFID) {
|
||||
::util_ThrowExceptionToJava(env, "Exception: nativeHighlightSelection");
|
||||
return;
|
||||
}
|
||||
|
||||
// get the nsIDOMNode representation of the start and end containers
|
||||
nsIDOMNode* node1 = (nsIDOMNode*)
|
||||
env->GetLongField(startContainer, nodePtrFID);
|
||||
|
||||
PR_ASSERT(nativeBrowserControl->initComplete);
|
||||
nsIDOMNode* node2 = (nsIDOMNode*)
|
||||
env->GetLongField(endContainer, nodePtrFID);
|
||||
|
||||
if (!node1 || !node2) {
|
||||
::util_ThrowExceptionToJava(env, "Exception: nativeHighlightSelection");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the DOM window and document
|
||||
nsCOMPtr<nsIDOMWindow> domWindow;
|
||||
nsCOMPtr<nsIWebBrowser> webBrowser;
|
||||
nsCOMPtr<nsIDOMDocument> domDocument;
|
||||
nativeBrowserControl->mWindow->GetWebBrowser(getter_AddRefs(webBrowser));
|
||||
|
||||
wsHighlightSelectionEvent *actionEvent = new wsHighlightSelectionEvent(env, nativeBrowserControl, startContainer, endContainer, (PRInt32) startOffset, (PRInt32) endOffset);
|
||||
PLEvent *event = (PLEvent *) *actionEvent;
|
||||
::util_PostSynchronousEvent(nativeBrowserControl, event);
|
||||
}
|
||||
if (NS_FAILED(rv) || !webBrowser) {
|
||||
::util_ThrowExceptionToJava(env, "Exception: nativeHighlightSelection");
|
||||
return;
|
||||
}
|
||||
|
||||
// get the content DOM window for that web browser
|
||||
rv = webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
|
||||
|
||||
if (NS_FAILED(rv) || !domWindow ) {
|
||||
::util_ThrowExceptionToJava(env, "Exception: nativeHighlightSelection");
|
||||
return;
|
||||
}
|
||||
|
||||
rv = domWindow->GetDocument(getter_AddRefs(domDocument));
|
||||
if (NS_FAILED(rv) || !domDocument ) {
|
||||
::util_ThrowExceptionToJava(env, "Exception: nativeHighlightSelection");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the selection object of the DOM window
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
rv = domWindow->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_FAILED(rv) || selection == nsnull) {
|
||||
::util_ThrowExceptionToJava(env, "Exception: nativeHighlightSelection");
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMDocumentRange> docRange(do_QueryInterface(domDocument));
|
||||
if (docRange) {
|
||||
nsCOMPtr<nsIDOMRange> range;
|
||||
rv = docRange->CreateRange(getter_AddRefs(range));
|
||||
|
||||
if (range) {
|
||||
rv = range->SetStart(node1, startOffset);
|
||||
if (NS_FAILED(rv)) {
|
||||
::util_ThrowExceptionToJava(env, "Exception: nativeHighlightSelection");
|
||||
return;
|
||||
}
|
||||
|
||||
rv = range->SetEnd(node2, endOffset);
|
||||
if (NS_FAILED(rv)) {
|
||||
::util_ThrowExceptionToJava(env, "Exception: nativeHighlightSelection");
|
||||
return;
|
||||
}
|
||||
|
||||
rv = selection->AddRange(range);
|
||||
if (NS_FAILED(rv)) {
|
||||
::util_ThrowExceptionToJava(env, "Exception: nativeHighlightSelection");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPageImpl_nativeClearAllSelections
|
||||
(JNIEnv *env, jobject obj, jint nativeBCPtr)
|
||||
@ -118,17 +201,41 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPa
|
||||
::util_ThrowExceptionToJava(env, "Exception: null nativeBCPtr passed to nativeClearAllSelections");
|
||||
return;
|
||||
}
|
||||
nsresult rv;
|
||||
|
||||
PR_ASSERT(nativeBrowserControl->initComplete);
|
||||
// Get the DOM window and document
|
||||
nsCOMPtr<nsIDOMWindow> domWindow;
|
||||
nsCOMPtr<nsIWebBrowser> webBrowser;
|
||||
rv = nativeBrowserControl->mWindow->GetWebBrowser(getter_AddRefs(webBrowser));
|
||||
|
||||
wsClearAllSelectionEvent *actionEvent = new wsClearAllSelectionEvent(nativeBrowserControl);
|
||||
if (NS_FAILED(rv) || !webBrowser) {
|
||||
::util_ThrowExceptionToJava(env, "Exception: nativeClearAllSelections");
|
||||
return;
|
||||
}
|
||||
|
||||
PLEvent *event = (PLEvent *) *actionEvent;
|
||||
::util_PostSynchronousEvent(nativeBrowserControl, event);
|
||||
// get the content DOM window for that web browser
|
||||
rv = webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
|
||||
|
||||
if (NS_FAILED(rv) || !domWindow ) {
|
||||
::util_ThrowExceptionToJava(env, "Exception: nativeClearAllSelections");
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
rv = domWindow->GetSelection(getter_AddRefs(selection));
|
||||
if (NS_FAILED(rv) || !selection) {
|
||||
::util_ThrowExceptionToJava(env, "Exception: nativeClearAllSelections");
|
||||
return;
|
||||
}
|
||||
|
||||
rv = selection->RemoveAllRanges();
|
||||
if (NS_FAILED(rv)) {
|
||||
::util_ThrowExceptionToJava(env, "Exception: nativeClearAllSelections");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Class: org_mozilla_webclient_impl_wrapper_0005fnative_CurrentPageImpl
|
||||
* Method: nativeFind
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: CurrentPageTest.java,v 1.7 2005-02-12 21:29:47 edburns%acm.org Exp $
|
||||
* $Id: CurrentPageTest.java,v 1.8 2005-02-14 02:16:18 edburns%acm.org Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -44,6 +44,9 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.BufferedReader;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
// CurrentPageTest.java
|
||||
|
||||
public class CurrentPageTest extends WebclientTestCase implements ClipboardOwner {
|
||||
@ -301,5 +304,81 @@ public class CurrentPageTest extends WebclientTestCase implements ClipboardOwner
|
||||
BrowserControlFactory.deleteBrowserControl(firstBrowserControl);
|
||||
}
|
||||
|
||||
public void testHighlightDomRegion() throws Exception {
|
||||
BrowserControl firstBrowserControl = null;
|
||||
DocumentLoadListenerImpl listener = null;
|
||||
Selection selection = null;
|
||||
firstBrowserControl = BrowserControlFactory.newBrowserControl();
|
||||
assertNotNull(firstBrowserControl);
|
||||
BrowserControlCanvas canvas = (BrowserControlCanvas)
|
||||
firstBrowserControl.queryInterface(BrowserControl.BROWSER_CONTROL_CANVAS_NAME);
|
||||
eventRegistration = (EventRegistration2)
|
||||
firstBrowserControl.queryInterface(BrowserControl.EVENT_REGISTRATION_NAME);
|
||||
|
||||
assertNotNull(canvas);
|
||||
Frame frame = new Frame();
|
||||
frame.setUndecorated(true);
|
||||
frame.setBounds(0, 0, 640, 480);
|
||||
frame.add(canvas, BorderLayout.CENTER);
|
||||
frame.setVisible(true);
|
||||
canvas.setVisible(true);
|
||||
|
||||
Navigation2 nav = (Navigation2)
|
||||
firstBrowserControl.queryInterface(BrowserControl.NAVIGATION_NAME);
|
||||
assertNotNull(nav);
|
||||
currentPage = (CurrentPage2)
|
||||
firstBrowserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME);
|
||||
|
||||
assertNotNull(currentPage);
|
||||
|
||||
eventRegistration.addDocumentLoadListener(listener = new DocumentLoadListenerImpl() {
|
||||
public void doEndCheck() {
|
||||
CurrentPageTest.keepWaiting = false;
|
||||
}
|
||||
});
|
||||
|
||||
Thread.currentThread().sleep(3000);
|
||||
|
||||
|
||||
CurrentPageTest.keepWaiting = true;
|
||||
|
||||
nav.loadURL("http://localhost:5243/DOMSelectionTest.html");
|
||||
|
||||
// keep waiting until the previous load completes
|
||||
while (CurrentPageTest.keepWaiting) {
|
||||
Thread.currentThread().sleep(1000);
|
||||
}
|
||||
|
||||
Document dom = currentPage.getDOM();
|
||||
assertNotNull(dom);
|
||||
|
||||
Node
|
||||
start = dom.getElementById("p2"),
|
||||
end = dom.getElementById("p4");
|
||||
assertNotNull(start);
|
||||
assertNotNull(end);
|
||||
|
||||
selection = currentPage.getSelection();
|
||||
selection.init("", start, end, 0, 0);
|
||||
// select Paragraphs 2 - 4 exclusive
|
||||
currentPage.highlightSelection(selection);
|
||||
|
||||
Thread.currentThread().sleep(3000); // PENDING remove
|
||||
|
||||
selection = currentPage.getSelection();
|
||||
assertTrue(-1 == selection.toString().indexOf("Paragraph 1"));
|
||||
assertTrue(-1 != selection.toString().indexOf("Paragraph 2"));
|
||||
assertTrue(-1 != selection.toString().indexOf("Paragraph 3"));
|
||||
assertTrue(-1 == selection.toString().indexOf("Paragraph 4"));
|
||||
assertTrue(-1 == selection.toString().indexOf("Paragraph 5"));
|
||||
|
||||
currentPage.clearAllSelections();
|
||||
selection = currentPage.getSelection();
|
||||
assertEquals(0, selection.toString().length());
|
||||
|
||||
|
||||
frame.setVisible(false);
|
||||
BrowserControlFactory.deleteBrowserControl(firstBrowserControl);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: DOMTest.java,v 1.1 2005-02-04 15:43:47 edburns%acm.org Exp $
|
||||
* $Id: DOMTest.java,v 1.2 2005-02-14 02:16:18 edburns%acm.org Exp $
|
||||
*/
|
||||
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
@ -73,7 +73,7 @@ public class DOMTest extends WebclientTestCase {
|
||||
// Testcases
|
||||
//
|
||||
|
||||
public void testHttpLoad() throws Exception {
|
||||
public void testGetDOM() throws Exception {
|
||||
BrowserControl firstBrowserControl = null;
|
||||
DocumentLoadListenerImpl listener = null;
|
||||
Selection selection = null;
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>DOM Selection Test</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>DOM Selection Test</h1>
|
||||
|
||||
<p id="p1">Paragraph 1</p>
|
||||
<p id="p2">Paragraph 2</p>
|
||||
<p id="p3">Paragraph 3</p>
|
||||
<p id="p4">Paragraph 4</p>
|
||||
<p id="p5">Paragraph 5</p>
|
||||
|
||||
<hr>
|
||||
<!-- Created: Sun Feb 13 11:20:10 Eastern Standard Time 2005 -->
|
||||
<!-- hhmts start -->
|
||||
Last modified: Sun Feb 13 11:21:35 Eastern Standard Time 2005
|
||||
<!-- hhmts end -->
|
||||
</body>
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user