This commit is contained in:
slamm%netscape.com 1999-09-01 20:14:02 +00:00
Родитель ff653c9c33
Коммит 09d51b6c8b
9 изменённых файлов: 193 добавлений и 4 удалений

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

@ -67,6 +67,10 @@
#include "nsIGlobalHistory.h"
#include "prmem.h"
#include "nsXPIDLString.h"
#include "nsIDOMHTMLElement.h"
#include "nsIDOMHTMLDocument.h"
#include "nsLayoutCID.h"
#include "nsIDOMRange.h"
#ifndef XP_MAC
#include "nsMultiMixedConv.h" // for
@ -606,7 +610,8 @@ static NS_DEFINE_IID(kIBrowserWindowIID, NS_IBROWSER_WINDOW_IID);
static NS_DEFINE_IID(kIClipboardCommandsIID, NS_ICLIPBOARDCOMMANDS_IID);
static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID);
static NS_DEFINE_IID(kISessionHistoryIID, NS_ISESSION_HISTORY_IID);
static NS_DEFINE_IID(kIDOMHTMLDocumentIID, NS_IDOMHTMLDOCUMENT_IID);
static NS_DEFINE_CID(kCDOMRangeCID, NS_RANGE_CID);
// XXX not sure
static NS_DEFINE_IID(kILinkHandlerIID, NS_ILINKHANDLER_IID);
@ -4134,7 +4139,60 @@ nsWebShell::PasteSelection(void)
NS_IMETHODIMP
nsWebShell::SelectAll(void)
{
return NS_ERROR_FAILURE;
nsresult rv;
nsCOMPtr<nsIDocumentViewer> docViewer;
rv = mContentViewer->QueryInterface(kIDocumentViewerIID,
getter_AddRefs(docViewer));
if (NS_FAILED(rv) || !docViewer) return rv;
nsCOMPtr<nsIPresShell> presShell;
rv = docViewer->GetPresShell(*getter_AddRefs(presShell));
if (NS_FAILED(rv) || !presShell) return rv;
nsCOMPtr<nsIDOMSelection> selection;
rv = presShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection));
if (NS_FAILED(rv) || !selection) return rv;
// Get the document object
nsCOMPtr<nsIDocument> doc;
rv = docViewer->GetDocument(*getter_AddRefs(doc));
if (NS_FAILED(rv) || !doc) return rv;
nsCOMPtr<nsIDOMHTMLDocument> htmldoc;
rv = doc->QueryInterface(kIDOMHTMLDocumentIID, (void**)&htmldoc);
if (NS_FAILED(rv) || !htmldoc) return rv;
nsCOMPtr<nsIDOMHTMLElement>bodyElement;
rv = htmldoc->GetBody(getter_AddRefs(bodyElement));
if (NS_FAILED(rv) || !bodyElement) return rv;
nsCOMPtr<nsIDOMNode>bodyNode = do_QueryInterface(bodyElement);
if (!bodyNode) return NS_ERROR_NO_INTERFACE;
#if 0
rv = selection->Collapse(bodyNode, 0);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDOMRange>range;
rv = selection->GetRangeAt(0, getter_AddRefs(range));
if (NS_FAILED(rv) || !range) return rv;
#endif
rv = selection->ClearSelection();
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDOMRange> range;
rv = nsComponentManager::CreateInstance(kCDOMRangeCID, nsnull,
nsIDOMRange::GetIID(),
getter_AddRefs(range));
rv = range->SelectNodeContents(bodyNode);
if (NS_FAILED(rv)) return rv;
rv = selection->AddRange(range);
return rv;
}
NS_IMETHODIMP

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

@ -680,6 +680,14 @@ function OpenSearch(tabName, searchStr)
}
}
function BrowserSelectAll() {
if (appCore != null) {
appCore.selectAll();
} else {
dump("BrowserAppCore has not been created!\n");
}
}
function BrowserFind() {
if (appCore != null) {
appCore.find();

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

@ -67,6 +67,10 @@
#include "nsIGlobalHistory.h"
#include "prmem.h"
#include "nsXPIDLString.h"
#include "nsIDOMHTMLElement.h"
#include "nsIDOMHTMLDocument.h"
#include "nsLayoutCID.h"
#include "nsIDOMRange.h"
#ifndef XP_MAC
#include "nsMultiMixedConv.h" // for
@ -606,7 +610,8 @@ static NS_DEFINE_IID(kIBrowserWindowIID, NS_IBROWSER_WINDOW_IID);
static NS_DEFINE_IID(kIClipboardCommandsIID, NS_ICLIPBOARDCOMMANDS_IID);
static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID);
static NS_DEFINE_IID(kISessionHistoryIID, NS_ISESSION_HISTORY_IID);
static NS_DEFINE_IID(kIDOMHTMLDocumentIID, NS_IDOMHTMLDOCUMENT_IID);
static NS_DEFINE_CID(kCDOMRangeCID, NS_RANGE_CID);
// XXX not sure
static NS_DEFINE_IID(kILinkHandlerIID, NS_ILINKHANDLER_IID);
@ -4134,7 +4139,60 @@ nsWebShell::PasteSelection(void)
NS_IMETHODIMP
nsWebShell::SelectAll(void)
{
return NS_ERROR_FAILURE;
nsresult rv;
nsCOMPtr<nsIDocumentViewer> docViewer;
rv = mContentViewer->QueryInterface(kIDocumentViewerIID,
getter_AddRefs(docViewer));
if (NS_FAILED(rv) || !docViewer) return rv;
nsCOMPtr<nsIPresShell> presShell;
rv = docViewer->GetPresShell(*getter_AddRefs(presShell));
if (NS_FAILED(rv) || !presShell) return rv;
nsCOMPtr<nsIDOMSelection> selection;
rv = presShell->GetSelection(SELECTION_NORMAL, getter_AddRefs(selection));
if (NS_FAILED(rv) || !selection) return rv;
// Get the document object
nsCOMPtr<nsIDocument> doc;
rv = docViewer->GetDocument(*getter_AddRefs(doc));
if (NS_FAILED(rv) || !doc) return rv;
nsCOMPtr<nsIDOMHTMLDocument> htmldoc;
rv = doc->QueryInterface(kIDOMHTMLDocumentIID, (void**)&htmldoc);
if (NS_FAILED(rv) || !htmldoc) return rv;
nsCOMPtr<nsIDOMHTMLElement>bodyElement;
rv = htmldoc->GetBody(getter_AddRefs(bodyElement));
if (NS_FAILED(rv) || !bodyElement) return rv;
nsCOMPtr<nsIDOMNode>bodyNode = do_QueryInterface(bodyElement);
if (!bodyNode) return NS_ERROR_NO_INTERFACE;
#if 0
rv = selection->Collapse(bodyNode, 0);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDOMRange>range;
rv = selection->GetRangeAt(0, getter_AddRefs(range));
if (NS_FAILED(rv) || !range) return rv;
#endif
rv = selection->ClearSelection();
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDOMRange> range;
rv = nsComponentManager::CreateInstance(kCDOMRangeCID, nsnull,
nsIDOMRange::GetIID(),
getter_AddRefs(range));
rv = range->SelectNodeContents(bodyNode);
if (NS_FAILED(rv)) return rv;
rv = selection->AddRange(range);
return rv;
}
NS_IMETHODIMP

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

@ -40,6 +40,7 @@ interface BrowserAppCore : BaseAppCore
void close();
void exit();
void selectAll();
void find();
void findNext();

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

@ -89,6 +89,8 @@ public:
NS_IMETHOD Exit()=0;
NS_IMETHOD SelectAll()=0;
NS_IMETHOD Find()=0;
NS_IMETHOD FindNext()=0;
@ -123,6 +125,7 @@ public:
NS_IMETHOD Print(); \
NS_IMETHOD Close(); \
NS_IMETHOD Exit(); \
NS_IMETHOD SelectAll(); \
NS_IMETHOD Find(); \
NS_IMETHOD FindNext(); \
@ -156,6 +159,7 @@ public:
NS_IMETHOD Print() { return _to Print(); } \
NS_IMETHOD Close() { return _to Close(); } \
NS_IMETHOD Exit() { return _to Exit(); } \
NS_IMETHOD SelectAll() { return _to SelectAll(); } \
NS_IMETHOD Find() { return _to Find(); } \
NS_IMETHOD FindNext() { return _to FindNext(); } \

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

@ -21,6 +21,7 @@
#include "nsIBrowserWindow.h"
#include "nsIWebShell.h"
#include "nsIClipboardCommands.h"
#include "pratom.h"
#include "prprf.h"
#include "nsIComponentManager.h"
@ -2254,6 +2255,13 @@ nsBrowserAppCore::Exit()
return NS_OK;
}
NS_IMETHODIMP
nsBrowserAppCore::SelectAll()
{
nsCOMPtr<nsIClipboardCommands> clip(do_QueryInterface(mContentAreaWebShell));
return clip->SelectAll();
}
void
nsBrowserAppCore::InitializeSearch( nsIFindComponent *finder )
{

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

@ -95,6 +95,7 @@ class nsBrowserAppCore : public nsBaseAppCore,
NS_IMETHOD Copy();
NS_IMETHOD Close();
NS_IMETHOD Exit();
NS_IMETHOD SelectAll();
NS_IMETHOD Find();
NS_IMETHOD FindNext();
NS_IMETHOD SetDocumentCharset(const nsString& aCharset);

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

@ -1429,6 +1429,48 @@ BrowserAppCoreExit(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval
}
//
// Native method SelectAll
//
PR_STATIC_CALLBACK(JSBool)
BrowserAppCoreSelectAll(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMBrowserAppCore *nativeThis = (nsIDOMBrowserAppCore*)nsJSUtils::nsGetNativeThis(cx, obj);
*rval = JSVAL_NULL;
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
nsCOMPtr<nsIScriptSecurityManager> secMan;
if (NS_OK != scriptCX->GetSecurityManager(getter_AddRefs(secMan))) {
return JS_FALSE;
}
{
PRBool ok;
secMan->CheckScriptAccess(scriptCX, obj, "browserappcore.selectall", PR_FALSE, &ok);
if (!ok) {
//Need to throw error here
return JS_FALSE;
}
}
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
{
if (NS_OK != nativeThis->SelectAll()) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
return JS_TRUE;
}
//
// Native method Find
//
@ -1572,6 +1614,7 @@ static JSFunctionSpec BrowserAppCoreMethods[] =
{"print", BrowserAppCorePrint, 0},
{"close", BrowserAppCoreClose, 0},
{"exit", BrowserAppCoreExit, 0},
{"selectAll", BrowserAppCoreSelectAll, 0},
{"find", BrowserAppCoreFind, 0},
{"findNext", BrowserAppCoreFindNext, 0},
{0}

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

@ -680,6 +680,14 @@ function OpenSearch(tabName, searchStr)
}
}
function BrowserSelectAll() {
if (appCore != null) {
appCore.selectAll();
} else {
dump("BrowserAppCore has not been created!\n");
}
}
function BrowserFind() {
if (appCore != null) {
appCore.find();