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
This commit is contained in:
@@ -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<nsIDOMNode> node1Ptr(do_QueryInterface(startContainer));
|
||||
nsCOMPtr<nsIDOMNode> 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<nsIDOMDocumentRange> docRange(do_QueryInterface(mInitContext->currentDocument));
|
||||
if (docRange) {
|
||||
nsCOMPtr<nsIDOMRange> 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),
|
||||
|
||||
Reference in New Issue
Block a user