зеркало из https://github.com/mozilla/gecko-dev.git
Hooking up window.getSelection() to return a selection object.
This commit is contained in:
Родитель
c29c060230
Коммит
2e5aeec95e
|
@ -31,6 +31,7 @@
|
||||||
|
|
||||||
class nsIDOMNavigator;
|
class nsIDOMNavigator;
|
||||||
class nsIDOMDocument;
|
class nsIDOMDocument;
|
||||||
|
class nsIDOMSelection;
|
||||||
class nsIDOMBarProp;
|
class nsIDOMBarProp;
|
||||||
class nsIDOMScreen;
|
class nsIDOMScreen;
|
||||||
class nsIDOMHistory;
|
class nsIDOMHistory;
|
||||||
|
@ -201,6 +202,8 @@ public:
|
||||||
NS_IMETHOD Escape(const nsString& aStr, nsString& aReturn)=0;
|
NS_IMETHOD Escape(const nsString& aStr, nsString& aReturn)=0;
|
||||||
|
|
||||||
NS_IMETHOD Unescape(const nsString& aStr, nsString& aReturn)=0;
|
NS_IMETHOD Unescape(const nsString& aStr, nsString& aReturn)=0;
|
||||||
|
|
||||||
|
NS_IMETHOD GetSelection(nsIDOMSelection** aReturn)=0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -288,6 +291,7 @@ public:
|
||||||
NS_IMETHOD UpdateCommands(const nsString& aAction); \
|
NS_IMETHOD UpdateCommands(const nsString& aAction); \
|
||||||
NS_IMETHOD Escape(const nsString& aStr, nsString& aReturn); \
|
NS_IMETHOD Escape(const nsString& aStr, nsString& aReturn); \
|
||||||
NS_IMETHOD Unescape(const nsString& aStr, nsString& aReturn); \
|
NS_IMETHOD Unescape(const nsString& aStr, nsString& aReturn); \
|
||||||
|
NS_IMETHOD GetSelection(nsIDOMSelection** aReturn); \
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -375,6 +379,7 @@ public:
|
||||||
NS_IMETHOD UpdateCommands(const nsString& aAction) { return _to UpdateCommands(aAction); } \
|
NS_IMETHOD UpdateCommands(const nsString& aAction) { return _to UpdateCommands(aAction); } \
|
||||||
NS_IMETHOD Escape(const nsString& aStr, nsString& aReturn) { return _to Escape(aStr, aReturn); } \
|
NS_IMETHOD Escape(const nsString& aStr, nsString& aReturn) { return _to Escape(aStr, aReturn); } \
|
||||||
NS_IMETHOD Unescape(const nsString& aStr, nsString& aReturn) { return _to Unescape(aStr, aReturn); } \
|
NS_IMETHOD Unescape(const nsString& aStr, nsString& aReturn) { return _to Unescape(aStr, aReturn); } \
|
||||||
|
NS_IMETHOD GetSelection(nsIDOMSelection** aReturn) { return _to GetSelection(aReturn); } \
|
||||||
|
|
||||||
|
|
||||||
extern nsresult NS_InitWindowClass(nsIScriptContext *aContext, nsIScriptGlobalObject *aGlobal);
|
extern nsresult NS_InitWindowClass(nsIScriptContext *aContext, nsIScriptGlobalObject *aGlobal);
|
||||||
|
|
|
@ -80,6 +80,7 @@ interface Window {
|
||||||
|
|
||||||
DOMString escape(in DOMString str);
|
DOMString escape(in DOMString str);
|
||||||
DOMString unescape(in DOMString str);
|
DOMString unescape(in DOMString str);
|
||||||
|
Selection getSelection();
|
||||||
};
|
};
|
||||||
|
|
||||||
interface EventTarget {
|
interface EventTarget {
|
||||||
|
|
|
@ -896,6 +896,7 @@ enum nsDOMProp {
|
||||||
NS_DOM_PROP_WINDOW_FORWARD,
|
NS_DOM_PROP_WINDOW_FORWARD,
|
||||||
NS_DOM_PROP_WINDOW_FRAMES,
|
NS_DOM_PROP_WINDOW_FRAMES,
|
||||||
NS_DOM_PROP_WINDOW_GETATTENTION,
|
NS_DOM_PROP_WINDOW_GETATTENTION,
|
||||||
|
NS_DOM_PROP_WINDOW_GETSELECTION,
|
||||||
NS_DOM_PROP_WINDOW_HISTORY,
|
NS_DOM_PROP_WINDOW_HISTORY,
|
||||||
NS_DOM_PROP_WINDOW_HOME,
|
NS_DOM_PROP_WINDOW_HOME,
|
||||||
NS_DOM_PROP_WINDOW_INNERHEIGHT,
|
NS_DOM_PROP_WINDOW_INNERHEIGHT,
|
||||||
|
|
|
@ -895,6 +895,7 @@
|
||||||
"window.forward", \
|
"window.forward", \
|
||||||
"window.frames", \
|
"window.frames", \
|
||||||
"window.getattention", \
|
"window.getattention", \
|
||||||
|
"window.getselection", \
|
||||||
"window.history", \
|
"window.history", \
|
||||||
"window.home", \
|
"window.home", \
|
||||||
"window.innerheight", \
|
"window.innerheight", \
|
||||||
|
|
|
@ -80,6 +80,8 @@
|
||||||
#include "nsIScriptGlobalObjectOwner.h"
|
#include "nsIScriptGlobalObjectOwner.h"
|
||||||
#include "nsIScriptSecurityManager.h"
|
#include "nsIScriptSecurityManager.h"
|
||||||
#include "nsISelectionController.h"
|
#include "nsISelectionController.h"
|
||||||
|
#include "nsIDOMSelection.h"
|
||||||
|
#include "nsIFrameSelection.h"
|
||||||
#include "nsISidebar.h" // XXX for sidebar HACK, see bug 20721
|
#include "nsISidebar.h" // XXX for sidebar HACK, see bug 20721
|
||||||
#include "nsIStyleContext.h"
|
#include "nsIStyleContext.h"
|
||||||
#include "nsIWebNavigation.h"
|
#include "nsIWebNavigation.h"
|
||||||
|
@ -1809,6 +1811,32 @@ NS_IMETHODIMP GlobalWindowImpl::Unescape(const nsString& aStr, nsString& aReturn
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
GlobalWindowImpl::GetSelection(nsIDOMSelection** aSelection)
|
||||||
|
{
|
||||||
|
NS_ENSURE_ARG_POINTER(aSelection);
|
||||||
|
*aSelection = nsnull;
|
||||||
|
|
||||||
|
if (!mDocShell)
|
||||||
|
return NS_OK;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIPresShell> presShell;
|
||||||
|
mDocShell->GetPresShell(getter_AddRefs(presShell));
|
||||||
|
|
||||||
|
if (!presShell)
|
||||||
|
return NS_OK;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIFrameSelection> selection;
|
||||||
|
presShell->GetFrameSelection(getter_AddRefs(selection));
|
||||||
|
|
||||||
|
if (!selection)
|
||||||
|
return NS_OK;
|
||||||
|
|
||||||
|
return selection->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
||||||
|
aSelection);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//*****************************************************************************
|
//*****************************************************************************
|
||||||
// GlobalWindowImpl::nsIJSScriptObject
|
// GlobalWindowImpl::nsIJSScriptObject
|
||||||
//*****************************************************************************
|
//*****************************************************************************
|
||||||
|
|
|
@ -37,13 +37,14 @@
|
||||||
#include "nsIDOMNavigator.h"
|
#include "nsIDOMNavigator.h"
|
||||||
#include "nsIDOMDocumentView.h"
|
#include "nsIDOMDocumentView.h"
|
||||||
#include "nsIDOMDocument.h"
|
#include "nsIDOMDocument.h"
|
||||||
|
#include "nsIDOMSelection.h"
|
||||||
#include "nsIDOMBarProp.h"
|
#include "nsIDOMBarProp.h"
|
||||||
#include "nsIDOMAbstractView.h"
|
#include "nsIDOMAbstractView.h"
|
||||||
#include "nsIDOMScreen.h"
|
#include "nsIDOMScreen.h"
|
||||||
#include "nsIDOMHistory.h"
|
#include "nsIDOMHistory.h"
|
||||||
#include "nsIDOMEventListener.h"
|
|
||||||
#include "nsIDOMWindowCollection.h"
|
#include "nsIDOMWindowCollection.h"
|
||||||
#include "nsIDOMEvent.h"
|
#include "nsIDOMEvent.h"
|
||||||
|
#include "nsIDOMEventListener.h"
|
||||||
#include "nsIDOMEventTarget.h"
|
#include "nsIDOMEventTarget.h"
|
||||||
#include "nsISidebar.h"
|
#include "nsISidebar.h"
|
||||||
#include "nsIDOMWindow.h"
|
#include "nsIDOMWindow.h"
|
||||||
|
@ -56,13 +57,14 @@ static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
|
||||||
static NS_DEFINE_IID(kINavigatorIID, NS_IDOMNAVIGATOR_IID);
|
static NS_DEFINE_IID(kINavigatorIID, NS_IDOMNAVIGATOR_IID);
|
||||||
static NS_DEFINE_IID(kIDocumentViewIID, NS_IDOMDOCUMENTVIEW_IID);
|
static NS_DEFINE_IID(kIDocumentViewIID, NS_IDOMDOCUMENTVIEW_IID);
|
||||||
static NS_DEFINE_IID(kIDocumentIID, NS_IDOMDOCUMENT_IID);
|
static NS_DEFINE_IID(kIDocumentIID, NS_IDOMDOCUMENT_IID);
|
||||||
|
static NS_DEFINE_IID(kISelectionIID, NS_IDOMSELECTION_IID);
|
||||||
static NS_DEFINE_IID(kIBarPropIID, NS_IDOMBARPROP_IID);
|
static NS_DEFINE_IID(kIBarPropIID, NS_IDOMBARPROP_IID);
|
||||||
static NS_DEFINE_IID(kIAbstractViewIID, NS_IDOMABSTRACTVIEW_IID);
|
static NS_DEFINE_IID(kIAbstractViewIID, NS_IDOMABSTRACTVIEW_IID);
|
||||||
static NS_DEFINE_IID(kIScreenIID, NS_IDOMSCREEN_IID);
|
static NS_DEFINE_IID(kIScreenIID, NS_IDOMSCREEN_IID);
|
||||||
static NS_DEFINE_IID(kIHistoryIID, NS_IDOMHISTORY_IID);
|
static NS_DEFINE_IID(kIHistoryIID, NS_IDOMHISTORY_IID);
|
||||||
static NS_DEFINE_IID(kIEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
|
||||||
static NS_DEFINE_IID(kIWindowCollectionIID, NS_IDOMWINDOWCOLLECTION_IID);
|
static NS_DEFINE_IID(kIWindowCollectionIID, NS_IDOMWINDOWCOLLECTION_IID);
|
||||||
static NS_DEFINE_IID(kIEventIID, NS_IDOMEVENT_IID);
|
static NS_DEFINE_IID(kIEventIID, NS_IDOMEVENT_IID);
|
||||||
|
static NS_DEFINE_IID(kIEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
||||||
static NS_DEFINE_IID(kIEventTargetIID, NS_IDOMEVENTTARGET_IID);
|
static NS_DEFINE_IID(kIEventTargetIID, NS_IDOMEVENTTARGET_IID);
|
||||||
static NS_DEFINE_IID(kISidebarIID, NS_ISIDEBAR_IID);
|
static NS_DEFINE_IID(kISidebarIID, NS_ISIDEBAR_IID);
|
||||||
static NS_DEFINE_IID(kIWindowIID, NS_IDOMWINDOW_IID);
|
static NS_DEFINE_IID(kIWindowIID, NS_IDOMWINDOW_IID);
|
||||||
|
@ -2420,6 +2422,42 @@ WindowUnescape(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Native method GetSelection
|
||||||
|
//
|
||||||
|
PR_STATIC_CALLBACK(JSBool)
|
||||||
|
WindowGetSelection(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||||
|
{
|
||||||
|
nsIDOMWindow *nativeThis = (nsIDOMWindow*)nsJSUtils::nsGetNativeThis(cx, obj);
|
||||||
|
nsresult result = NS_OK;
|
||||||
|
nsIDOMSelection* nativeRet;
|
||||||
|
// If there's no private data, this must be the prototype, so ignore
|
||||||
|
if (nsnull == nativeThis) {
|
||||||
|
return JS_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
*rval = JSVAL_NULL;
|
||||||
|
nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj);
|
||||||
|
if (!secMan)
|
||||||
|
return PR_FALSE;
|
||||||
|
result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_WINDOW_GETSELECTION, PR_FALSE);
|
||||||
|
if (NS_FAILED(result)) {
|
||||||
|
return nsJSUtils::nsReportError(cx, obj, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
result = nativeThis->GetSelection(&nativeRet);
|
||||||
|
if (NS_FAILED(result)) {
|
||||||
|
return nsJSUtils::nsReportError(cx, obj, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval);
|
||||||
|
}
|
||||||
|
|
||||||
|
return JS_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Native method AddEventListener
|
// Native method AddEventListener
|
||||||
//
|
//
|
||||||
|
@ -2639,6 +2677,7 @@ static JSFunctionSpec WindowMethods[] =
|
||||||
{"updateCommands", WindowUpdateCommands, 1},
|
{"updateCommands", WindowUpdateCommands, 1},
|
||||||
{"escape", WindowEscape, 1},
|
{"escape", WindowEscape, 1},
|
||||||
{"unescape", WindowUnescape, 1},
|
{"unescape", WindowUnescape, 1},
|
||||||
|
{"getSelection", WindowGetSelection, 0},
|
||||||
{"addEventListener", EventTargetAddEventListener, 3},
|
{"addEventListener", EventTargetAddEventListener, 3},
|
||||||
{"removeEventListener", EventTargetRemoveEventListener, 3},
|
{"removeEventListener", EventTargetRemoveEventListener, 3},
|
||||||
{0}
|
{0}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче