Forgot to check that we fire the select event with Select All. Also fix event.target. Part of bug 46085. r=mjudge.

This commit is contained in:
heikki%netscape.com 2000-09-12 20:54:41 +00:00
Родитель 540b148f99
Коммит 3f6567dd27
15 изменённых файлов: 153 добавлений и 1827 удалений

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

@ -136,6 +136,7 @@ public:
NS_IMETHOD Collapse(nsIDOMNode* aParentNode, PRInt32 aOffset);
NS_IMETHOD CollapseToStart();
NS_IMETHOD CollapseToEnd();
NS_IMETHOD SelectAllChildren(nsIDOMNode* parentNode);
NS_IMETHOD Extend(nsIDOMNode* aParentNode, PRInt32 aOffset);
NS_IMETHOD ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aAYes);
NS_IMETHOD DeleteFromDocument();
@ -1468,14 +1469,12 @@ nsSelection::MoveCaret(PRUint32 aKeycode, PRBool aContinue, nsSelectionAmount aA
case nsIDOMKeyEvent::DOM_VK_HOME :
InvalidateDesiredX();
pos.mAmount = eSelectBeginLine;
InvalidateDesiredX();
mHint = HINTRIGHT;//stick to opposite of movement
PostReason(nsIDOMSelectionListener::KEYPRESS_REASON);
break;
case nsIDOMKeyEvent::DOM_VK_END :
InvalidateDesiredX();
pos.mAmount = eSelectEndLine;
InvalidateDesiredX();
mHint = HINTLEFT;//stick to this line
PostReason(nsIDOMSelectionListener::KEYPRESS_REASON);
break;
@ -1627,7 +1626,6 @@ nsDOMSelection::GetHint(PRBool *aHintRight)
return rv;
}
NS_IMETHODIMP
nsSelection::HandleClick(nsIContent *aNewFocus, PRUint32 aContentOffset,
PRUint32 aContentEndOffset, PRBool aContinueSelection,
@ -5520,6 +5518,45 @@ nsDOMSelection::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset)
return mFrameSelection->NotifySelectionListeners(GetType());
}
static inline nsresult GetChildOffset(nsIDOMNode *aChild, nsIDOMNode *aParent, PRInt32 &aOffset)
{
NS_ASSERTION((aChild && aParent), "bad args");
if (!aChild || !aParent) return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIContent> content = do_QueryInterface(aParent);
nsCOMPtr<nsIContent> cChild = do_QueryInterface(aChild);
if (!cChild || !content) return NS_ERROR_NULL_POINTER;
nsresult res = content->IndexOf(cChild, aOffset);
return res;
}
NS_IMETHODIMP
nsDOMSelection::SelectAllChildren(nsIDOMNode* aParentNode)
{
NS_ENSURE_ARG_POINTER(aParentNode);
if (mFrameSelection)
{
mFrameSelection->PostReason(nsIDOMSelectionListener::SELECTALL_REASON);
}
nsresult result = Collapse(aParentNode, 0);
if (NS_SUCCEEDED(result))
{
nsCOMPtr<nsIDOMNode>lastChild;
result = aParentNode->GetLastChild(getter_AddRefs(lastChild));
if ((NS_SUCCEEDED(result)) && lastChild)
{
PRInt32 numBodyChildren=0;
GetChildOffset(lastChild, aParentNode, numBodyChildren);
if (mFrameSelection)
{
mFrameSelection->PostReason(nsIDOMSelectionListener::SELECTALL_REASON);
}
result = Extend(aParentNode, numBodyChildren+1);
}
}
return result;
}
NS_IMETHODIMP
nsDOMSelection::ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aYes)
{

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

@ -1,41 +0,0 @@
interface Selection {
/* IID: { 0xa6cf90e1, 0x15b3, 0x11d2, \
{ 0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } } */
readonly attribute Node anchorNode;
readonly attribute long anchorOffset;
readonly attribute Node focusNode;
readonly attribute long focusOffset;
readonly attribute boolean isCollapsed;
readonly attribute long rangeCount;
Range getRangeAt(in long index);
void clearSelection();
void collapse(in Node parentNode, in long offset);
void extend(in Node parentNode, in long offset);
void collapseToStart();
void collapseToEnd();
boolean containsNode(in Node node, in boolean recursive);
void deleteFromDocument();
void addRange(in Range range);
void removeRange(in Range range);
void startBatchChanges();
void endBatchChanges();
void addSelectionListener(in SelectionListener newListener);
void removeSelectionListener(in SelectionListener listenerToRemove);
void setHint(in boolean right);
boolean getHint();
noscript xpidl nsIEnumerator getEnumerator();
DOMString toString(in DOMString formatType, in unsigned long flags, in int wrapCount);
};

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

@ -1,11 +0,0 @@
interface SelectionListener {
/* IID: { 0xa6cf90e2, 0x15b3, 0x11d2, \
{ 0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} } */
const short NO_REASON=0;
const short DRAG_REASON=1;
const short MOUSEDOWN_REASON=2;/*bitflags*/
const short MOUSEUP_REASON=4;/*bitflags*/
const short KEYPRESS_REASON=8;/*bitflags*/
void notifySelectionChanged(in Document doc, in Selection sel, in short reason);
};

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

@ -908,6 +908,7 @@ enum nsDOMProp {
NS_DOM_PROP_SELECTION_RANGECOUNT,
NS_DOM_PROP_SELECTION_REMOVERANGE,
NS_DOM_PROP_SELECTION_REMOVESELECTIONLISTENER,
NS_DOM_PROP_SELECTION_SELECTALLCHILDREN,
NS_DOM_PROP_SELECTION_SETHINT,
NS_DOM_PROP_SELECTION_STARTBATCHCHANGES,
NS_DOM_PROP_SELECTION_TOSTRING,

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

@ -906,6 +906,7 @@
"selection.rangecount", \
"selection.removerange", \
"selection.removeselectionlistener", \
"selection.selectallchildren", \
"selection.sethint", \
"selection.startbatchchanges", \
"selection.tostring", \

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

@ -1,153 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMSelection_h__
#define nsIDOMSelection_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
class nsIDOMNode;
class nsIDOMSelectionListener;
class nsIEnumerator;
class nsIDOMRange;
#define NS_IDOMSELECTION_IID \
{ 0xa6cf90e1, 0x15b3, 0x11d2, \
{ 0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } }
class nsIDOMSelection : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IDOMSELECTION_IID; return iid; }
NS_IMETHOD GetAnchorNode(nsIDOMNode** aAnchorNode)=0;
NS_IMETHOD GetAnchorOffset(PRInt32* aAnchorOffset)=0;
NS_IMETHOD GetFocusNode(nsIDOMNode** aFocusNode)=0;
NS_IMETHOD GetFocusOffset(PRInt32* aFocusOffset)=0;
NS_IMETHOD GetIsCollapsed(PRBool* aIsCollapsed)=0;
NS_IMETHOD GetRangeCount(PRInt32* aRangeCount)=0;
NS_IMETHOD GetRangeAt(PRInt32 aIndex, nsIDOMRange** aReturn)=0;
NS_IMETHOD ClearSelection()=0;
NS_IMETHOD Collapse(nsIDOMNode* aParentNode, PRInt32 aOffset)=0;
NS_IMETHOD Extend(nsIDOMNode* aParentNode, PRInt32 aOffset)=0;
NS_IMETHOD CollapseToStart()=0;
NS_IMETHOD CollapseToEnd()=0;
NS_IMETHOD ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aReturn)=0;
NS_IMETHOD DeleteFromDocument()=0;
NS_IMETHOD AddRange(nsIDOMRange* aRange)=0;
NS_IMETHOD RemoveRange(nsIDOMRange* aRange)=0;
NS_IMETHOD StartBatchChanges()=0;
NS_IMETHOD EndBatchChanges()=0;
NS_IMETHOD AddSelectionListener(nsIDOMSelectionListener* aNewListener)=0;
NS_IMETHOD RemoveSelectionListener(nsIDOMSelectionListener* aListenerToRemove)=0;
NS_IMETHOD SetHint(PRBool aRight)=0;
NS_IMETHOD GetHint(PRBool* aReturn)=0;
NS_IMETHOD GetEnumerator(nsIEnumerator** aReturn)=0;
NS_IMETHOD ToString(const nsAReadableString& aFormatType, PRUint32 aFlags, PRInt32 aWrapCount, nsAWritableString& aReturn)=0;
};
#define NS_DECL_IDOMSELECTION \
NS_IMETHOD GetAnchorNode(nsIDOMNode** aAnchorNode); \
NS_IMETHOD GetAnchorOffset(PRInt32* aAnchorOffset); \
NS_IMETHOD GetFocusNode(nsIDOMNode** aFocusNode); \
NS_IMETHOD GetFocusOffset(PRInt32* aFocusOffset); \
NS_IMETHOD GetIsCollapsed(PRBool* aIsCollapsed); \
NS_IMETHOD GetRangeCount(PRInt32* aRangeCount); \
NS_IMETHOD GetRangeAt(PRInt32 aIndex, nsIDOMRange** aReturn); \
NS_IMETHOD ClearSelection(); \
NS_IMETHOD Collapse(nsIDOMNode* aParentNode, PRInt32 aOffset); \
NS_IMETHOD Extend(nsIDOMNode* aParentNode, PRInt32 aOffset); \
NS_IMETHOD CollapseToStart(); \
NS_IMETHOD CollapseToEnd(); \
NS_IMETHOD ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aReturn); \
NS_IMETHOD DeleteFromDocument(); \
NS_IMETHOD AddRange(nsIDOMRange* aRange); \
NS_IMETHOD RemoveRange(nsIDOMRange* aRange); \
NS_IMETHOD StartBatchChanges(); \
NS_IMETHOD EndBatchChanges(); \
NS_IMETHOD AddSelectionListener(nsIDOMSelectionListener* aNewListener); \
NS_IMETHOD RemoveSelectionListener(nsIDOMSelectionListener* aListenerToRemove); \
NS_IMETHOD SetHint(PRBool aRight); \
NS_IMETHOD GetHint(PRBool* aReturn); \
NS_IMETHOD GetEnumerator(nsIEnumerator** aReturn); \
NS_IMETHOD ToString(const nsAReadableString& aFormatType, PRUint32 aFlags, PRInt32 aWrapCount, nsAWritableString& aReturn); \
#define NS_FORWARD_IDOMSELECTION(_to) \
NS_IMETHOD GetAnchorNode(nsIDOMNode** aAnchorNode) { return _to GetAnchorNode(aAnchorNode); } \
NS_IMETHOD GetAnchorOffset(PRInt32* aAnchorOffset) { return _to GetAnchorOffset(aAnchorOffset); } \
NS_IMETHOD GetFocusNode(nsIDOMNode** aFocusNode) { return _to GetFocusNode(aFocusNode); } \
NS_IMETHOD GetFocusOffset(PRInt32* aFocusOffset) { return _to GetFocusOffset(aFocusOffset); } \
NS_IMETHOD GetIsCollapsed(PRBool* aIsCollapsed) { return _to GetIsCollapsed(aIsCollapsed); } \
NS_IMETHOD GetRangeCount(PRInt32* aRangeCount) { return _to GetRangeCount(aRangeCount); } \
NS_IMETHOD GetRangeAt(PRInt32 aIndex, nsIDOMRange** aReturn) { return _to GetRangeAt(aIndex, aReturn); } \
NS_IMETHOD ClearSelection() { return _to ClearSelection(); } \
NS_IMETHOD Collapse(nsIDOMNode* aParentNode, PRInt32 aOffset) { return _to Collapse(aParentNode, aOffset); } \
NS_IMETHOD Extend(nsIDOMNode* aParentNode, PRInt32 aOffset) { return _to Extend(aParentNode, aOffset); } \
NS_IMETHOD CollapseToStart() { return _to CollapseToStart(); } \
NS_IMETHOD CollapseToEnd() { return _to CollapseToEnd(); } \
NS_IMETHOD ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aReturn) { return _to ContainsNode(aNode, aRecursive, aReturn); } \
NS_IMETHOD DeleteFromDocument() { return _to DeleteFromDocument(); } \
NS_IMETHOD AddRange(nsIDOMRange* aRange) { return _to AddRange(aRange); } \
NS_IMETHOD RemoveRange(nsIDOMRange* aRange) { return _to RemoveRange(aRange); } \
NS_IMETHOD StartBatchChanges() { return _to StartBatchChanges(); } \
NS_IMETHOD EndBatchChanges() { return _to EndBatchChanges(); } \
NS_IMETHOD AddSelectionListener(nsIDOMSelectionListener* aNewListener) { return _to AddSelectionListener(aNewListener); } \
NS_IMETHOD RemoveSelectionListener(nsIDOMSelectionListener* aListenerToRemove) { return _to RemoveSelectionListener(aListenerToRemove); } \
NS_IMETHOD SetHint(PRBool aRight) { return _to SetHint(aRight); } \
NS_IMETHOD GetHint(PRBool* aReturn) { return _to GetHint(aReturn); } \
NS_IMETHOD GetEnumerator(nsIEnumerator** aReturn) { return _to GetEnumerator(aReturn); } \
NS_IMETHOD ToString(const nsAReadableString& aFormatType, PRUint32 aFlags, PRInt32 aWrapCount, nsAWritableString& aReturn) { return _to ToString(aFormatType, aFlags, aWrapCount, aReturn); } \
extern "C" NS_DOM nsresult NS_InitSelectionClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptSelection(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMSelection_h__

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

@ -1,66 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMSelectionListener_h__
#define nsIDOMSelectionListener_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
class nsIDOMDocument;
class nsIDOMSelection;
#define NS_IDOMSELECTIONLISTENER_IID \
{ 0xa6cf90e2, 0x15b3, 0x11d2, \
{ 0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
class nsIDOMSelectionListener : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IDOMSELECTIONLISTENER_IID; return iid; }
enum {
NO_REASON = 0,
DRAG_REASON = 1,
MOUSEDOWN_REASON = 2,
MOUSEUP_REASON = 4,
KEYPRESS_REASON = 8
};
NS_IMETHOD NotifySelectionChanged(nsIDOMDocument* aDoc, nsIDOMSelection* aSel, PRInt16 aReason)=0;
};
#define NS_DECL_IDOMSELECTIONLISTENER \
NS_IMETHOD NotifySelectionChanged(nsIDOMDocument* aDoc, nsIDOMSelection* aSel, PRInt16 aReason); \
#define NS_FORWARD_IDOMSELECTIONLISTENER(_to) \
NS_IMETHOD NotifySelectionChanged(nsIDOMDocument* aDoc, nsIDOMSelection* aSel, PRInt16 aReason) { return _to NotifySelectionChanged(aDoc, aSel, aReason); } \
extern "C" NS_DOM nsresult NS_InitSelectionListenerClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptSelectionListener(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMSelectionListener_h__

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -1,372 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nsJSUtils.h"
#include "nsDOMError.h"
#include "nscore.h"
#include "nsIServiceManager.h"
#include "nsIScriptContext.h"
#include "nsIScriptSecurityManager.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsCOMPtr.h"
#include "nsDOMPropEnums.h"
#include "nsString.h"
#include "nsIDOMDocument.h"
#include "nsIDOMSelection.h"
#include "nsIDOMSelectionListener.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIDocumentIID, NS_IDOMDOCUMENT_IID);
static NS_DEFINE_IID(kISelectionIID, NS_IDOMSELECTION_IID);
static NS_DEFINE_IID(kISelectionListenerIID, NS_IDOMSELECTIONLISTENER_IID);
/***********************************************************************/
//
// SelectionListener Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetSelectionListenerProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMSelectionListener *a = (nsIDOMSelectionListener*)nsJSUtils::nsGetNativeThis(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
nsresult rv = NS_OK;
if (JSVAL_IS_INT(id)) {
nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj);
if (!secMan)
return PR_FALSE;
switch(JSVAL_TO_INT(id)) {
case 0:
default:
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, obj, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, obj, id, vp);
}
if (NS_FAILED(rv))
return nsJSUtils::nsReportError(cx, obj, rv);
return PR_TRUE;
}
/***********************************************************************/
//
// SelectionListener Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetSelectionListenerProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMSelectionListener *a = (nsIDOMSelectionListener*)nsJSUtils::nsGetNativeThis(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
nsresult rv = NS_OK;
if (JSVAL_IS_INT(id)) {
nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj);
if (!secMan)
return PR_FALSE;
switch(JSVAL_TO_INT(id)) {
case 0:
default:
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, obj, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, obj, id, vp);
}
if (NS_FAILED(rv))
return nsJSUtils::nsReportError(cx, obj, rv);
return PR_TRUE;
}
//
// SelectionListener finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeSelectionListener(JSContext *cx, JSObject *obj)
{
nsJSUtils::nsGenericFinalize(cx, obj);
}
//
// SelectionListener enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateSelectionListener(JSContext *cx, JSObject *obj)
{
return nsJSUtils::nsGenericEnumerate(cx, obj);
}
//
// SelectionListener resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveSelectionListener(JSContext *cx, JSObject *obj, jsval id)
{
return nsJSUtils::nsGenericResolve(cx, obj, id);
}
//
// Native method NotifySelectionChanged
//
PR_STATIC_CALLBACK(JSBool)
SelectionListenerNotifySelectionChanged(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMSelectionListener *nativeThis = (nsIDOMSelectionListener*)nsJSUtils::nsGetNativeThis(cx, obj);
nsresult result = NS_OK;
nsCOMPtr<nsIDOMDocument> b0;
nsCOMPtr<nsIDOMSelection> b1;
PRInt32 b2;
// 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_SELECTIONLISTENER_NOTIFYSELECTIONCHANGED, PR_FALSE);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result);
}
if (argc < 3) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
}
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)(void**)getter_AddRefs(b0),
kIDocumentIID,
NS_ConvertASCIItoUCS2("Document"),
cx,
argv[0])) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_OBJECT_ERR);
}
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)(void**)getter_AddRefs(b1),
kISelectionIID,
NS_ConvertASCIItoUCS2("Selection"),
cx,
argv[1])) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_OBJECT_ERR);
}
if (!JS_ValueToInt32(cx, argv[2], (int32 *)&b2)) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_NUMBER_ERR);
}
result = nativeThis->NotifySelectionChanged(b0, b1, b2);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result);
}
*rval = JSVAL_VOID;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for SelectionListener
//
JSClass SelectionListenerClass = {
"SelectionListener",
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS,
JS_PropertyStub,
JS_PropertyStub,
GetSelectionListenerProperty,
SetSelectionListenerProperty,
EnumerateSelectionListener,
ResolveSelectionListener,
JS_ConvertStub,
FinalizeSelectionListener,
nsnull,
nsJSUtils::nsCheckAccess
};
//
// SelectionListener class properties
//
static JSPropertySpec SelectionListenerProperties[] =
{
{0}
};
//
// SelectionListener class methods
//
static JSFunctionSpec SelectionListenerMethods[] =
{
{"notifySelectionChanged", SelectionListenerNotifySelectionChanged, 3},
{0}
};
//
// SelectionListener constructor
//
PR_STATIC_CALLBACK(JSBool)
SelectionListener(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_FALSE;
}
//
// SelectionListener class initialization
//
extern "C" NS_DOM nsresult NS_InitSelectionListenerClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *parent_proto = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "SelectionListener", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&SelectionListenerClass, // JSClass
SelectionListener, // JSNative ctor
0, // ctor args
SelectionListenerProperties, // proto props
SelectionListenerMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
return NS_ERROR_FAILURE;
}
if ((PR_TRUE == JS_LookupProperty(jscontext, global, "SelectionListener", &vp)) &&
JSVAL_IS_OBJECT(vp) &&
((constructor = JSVAL_TO_OBJECT(vp)) != nsnull)) {
vp = INT_TO_JSVAL(nsIDOMSelectionListener::NO_REASON);
JS_SetProperty(jscontext, constructor, "NO_REASON", &vp);
vp = INT_TO_JSVAL(nsIDOMSelectionListener::DRAG_REASON);
JS_SetProperty(jscontext, constructor, "DRAG_REASON", &vp);
vp = INT_TO_JSVAL(nsIDOMSelectionListener::MOUSEDOWN_REASON);
JS_SetProperty(jscontext, constructor, "MOUSEDOWN_REASON", &vp);
vp = INT_TO_JSVAL(nsIDOMSelectionListener::MOUSEUP_REASON);
JS_SetProperty(jscontext, constructor, "MOUSEUP_REASON", &vp);
vp = INT_TO_JSVAL(nsIDOMSelectionListener::KEYPRESS_REASON);
JS_SetProperty(jscontext, constructor, "KEYPRESS_REASON", &vp);
}
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
proto = JSVAL_TO_OBJECT(vp);
}
else {
return NS_ERROR_FAILURE;
}
if (aPrototype) {
*aPrototype = proto;
}
return NS_OK;
}
//
// Method for creating a new SelectionListener JavaScript object
//
extern "C" NS_DOM nsresult NS_NewScriptSelectionListener(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptSelectionListener");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
nsresult result = NS_OK;
nsIDOMSelectionListener *aSelectionListener;
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitSelectionListenerClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
result = aSupports->QueryInterface(kISelectionListenerIID, (void **)&aSelectionListener);
if (NS_OK != result) {
return result;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &SelectionListenerClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aSelectionListener);
}
else {
NS_RELEASE(aSelectionListener);
return NS_ERROR_FAILURE;
}
return NS_OK;
}

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

@ -2991,18 +2991,7 @@ NS_IMETHODIMP nsEditor::SelectEntireDocument(nsIDOMSelection *aSelection)
nsCOMPtr<nsIDOMNode>bodyNode = do_QueryInterface(bodyElement);
if (bodyNode)
{
result = aSelection->Collapse(bodyNode, 0);
if (NS_SUCCEEDED(result))
{
PRInt32 numBodyChildren=0;
nsCOMPtr<nsIDOMNode>lastChild;
result = bodyNode->GetLastChild(getter_AddRefs(lastChild));
if ((NS_SUCCEEDED(result)) && lastChild)
{
GetChildOffset(lastChild, bodyNode, numBodyChildren);
result = aSelection->Extend(bodyNode, numBodyChildren+1);
}
}
result = aSelection->SelectAllChildren(bodyNode);
}
else {
return NS_ERROR_NO_INTERFACE;

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

@ -2991,18 +2991,7 @@ NS_IMETHODIMP nsEditor::SelectEntireDocument(nsIDOMSelection *aSelection)
nsCOMPtr<nsIDOMNode>bodyNode = do_QueryInterface(bodyElement);
if (bodyNode)
{
result = aSelection->Collapse(bodyNode, 0);
if (NS_SUCCEEDED(result))
{
PRInt32 numBodyChildren=0;
nsCOMPtr<nsIDOMNode>lastChild;
result = bodyNode->GetLastChild(getter_AddRefs(lastChild));
if ((NS_SUCCEEDED(result)) && lastChild)
{
GetChildOffset(lastChild, bodyNode, numBodyChildren);
result = aSelection->Extend(bodyNode, numBodyChildren+1);
}
}
result = aSelection->SelectAllChildren(bodyNode);
}
else {
return NS_ERROR_NO_INTERFACE;

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

@ -136,6 +136,7 @@ public:
NS_IMETHOD Collapse(nsIDOMNode* aParentNode, PRInt32 aOffset);
NS_IMETHOD CollapseToStart();
NS_IMETHOD CollapseToEnd();
NS_IMETHOD SelectAllChildren(nsIDOMNode* parentNode);
NS_IMETHOD Extend(nsIDOMNode* aParentNode, PRInt32 aOffset);
NS_IMETHOD ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aAYes);
NS_IMETHOD DeleteFromDocument();
@ -1468,14 +1469,12 @@ nsSelection::MoveCaret(PRUint32 aKeycode, PRBool aContinue, nsSelectionAmount aA
case nsIDOMKeyEvent::DOM_VK_HOME :
InvalidateDesiredX();
pos.mAmount = eSelectBeginLine;
InvalidateDesiredX();
mHint = HINTRIGHT;//stick to opposite of movement
PostReason(nsIDOMSelectionListener::KEYPRESS_REASON);
break;
case nsIDOMKeyEvent::DOM_VK_END :
InvalidateDesiredX();
pos.mAmount = eSelectEndLine;
InvalidateDesiredX();
mHint = HINTLEFT;//stick to this line
PostReason(nsIDOMSelectionListener::KEYPRESS_REASON);
break;
@ -1627,7 +1626,6 @@ nsDOMSelection::GetHint(PRBool *aHintRight)
return rv;
}
NS_IMETHODIMP
nsSelection::HandleClick(nsIContent *aNewFocus, PRUint32 aContentOffset,
PRUint32 aContentEndOffset, PRBool aContinueSelection,
@ -5520,6 +5518,45 @@ nsDOMSelection::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset)
return mFrameSelection->NotifySelectionListeners(GetType());
}
static inline nsresult GetChildOffset(nsIDOMNode *aChild, nsIDOMNode *aParent, PRInt32 &aOffset)
{
NS_ASSERTION((aChild && aParent), "bad args");
if (!aChild || !aParent) return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIContent> content = do_QueryInterface(aParent);
nsCOMPtr<nsIContent> cChild = do_QueryInterface(aChild);
if (!cChild || !content) return NS_ERROR_NULL_POINTER;
nsresult res = content->IndexOf(cChild, aOffset);
return res;
}
NS_IMETHODIMP
nsDOMSelection::SelectAllChildren(nsIDOMNode* aParentNode)
{
NS_ENSURE_ARG_POINTER(aParentNode);
if (mFrameSelection)
{
mFrameSelection->PostReason(nsIDOMSelectionListener::SELECTALL_REASON);
}
nsresult result = Collapse(aParentNode, 0);
if (NS_SUCCEEDED(result))
{
nsCOMPtr<nsIDOMNode>lastChild;
result = aParentNode->GetLastChild(getter_AddRefs(lastChild));
if ((NS_SUCCEEDED(result)) && lastChild)
{
PRInt32 numBodyChildren=0;
GetChildOffset(lastChild, aParentNode, numBodyChildren);
if (mFrameSelection)
{
mFrameSelection->PostReason(nsIDOMSelectionListener::SELECTALL_REASON);
}
result = Extend(aParentNode, numBodyChildren+1);
}
}
return result;
}
NS_IMETHODIMP
nsDOMSelection::ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aYes)
{

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

@ -136,6 +136,7 @@ public:
NS_IMETHOD Collapse(nsIDOMNode* aParentNode, PRInt32 aOffset);
NS_IMETHOD CollapseToStart();
NS_IMETHOD CollapseToEnd();
NS_IMETHOD SelectAllChildren(nsIDOMNode* parentNode);
NS_IMETHOD Extend(nsIDOMNode* aParentNode, PRInt32 aOffset);
NS_IMETHOD ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aAYes);
NS_IMETHOD DeleteFromDocument();
@ -1468,14 +1469,12 @@ nsSelection::MoveCaret(PRUint32 aKeycode, PRBool aContinue, nsSelectionAmount aA
case nsIDOMKeyEvent::DOM_VK_HOME :
InvalidateDesiredX();
pos.mAmount = eSelectBeginLine;
InvalidateDesiredX();
mHint = HINTRIGHT;//stick to opposite of movement
PostReason(nsIDOMSelectionListener::KEYPRESS_REASON);
break;
case nsIDOMKeyEvent::DOM_VK_END :
InvalidateDesiredX();
pos.mAmount = eSelectEndLine;
InvalidateDesiredX();
mHint = HINTLEFT;//stick to this line
PostReason(nsIDOMSelectionListener::KEYPRESS_REASON);
break;
@ -1627,7 +1626,6 @@ nsDOMSelection::GetHint(PRBool *aHintRight)
return rv;
}
NS_IMETHODIMP
nsSelection::HandleClick(nsIContent *aNewFocus, PRUint32 aContentOffset,
PRUint32 aContentEndOffset, PRBool aContinueSelection,
@ -5520,6 +5518,45 @@ nsDOMSelection::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset)
return mFrameSelection->NotifySelectionListeners(GetType());
}
static inline nsresult GetChildOffset(nsIDOMNode *aChild, nsIDOMNode *aParent, PRInt32 &aOffset)
{
NS_ASSERTION((aChild && aParent), "bad args");
if (!aChild || !aParent) return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIContent> content = do_QueryInterface(aParent);
nsCOMPtr<nsIContent> cChild = do_QueryInterface(aChild);
if (!cChild || !content) return NS_ERROR_NULL_POINTER;
nsresult res = content->IndexOf(cChild, aOffset);
return res;
}
NS_IMETHODIMP
nsDOMSelection::SelectAllChildren(nsIDOMNode* aParentNode)
{
NS_ENSURE_ARG_POINTER(aParentNode);
if (mFrameSelection)
{
mFrameSelection->PostReason(nsIDOMSelectionListener::SELECTALL_REASON);
}
nsresult result = Collapse(aParentNode, 0);
if (NS_SUCCEEDED(result))
{
nsCOMPtr<nsIDOMNode>lastChild;
result = aParentNode->GetLastChild(getter_AddRefs(lastChild));
if ((NS_SUCCEEDED(result)) && lastChild)
{
PRInt32 numBodyChildren=0;
GetChildOffset(lastChild, aParentNode, numBodyChildren);
if (mFrameSelection)
{
mFrameSelection->PostReason(nsIDOMSelectionListener::SELECTALL_REASON);
}
result = Extend(aParentNode, numBodyChildren+1);
}
}
return result;
}
NS_IMETHODIMP
nsDOMSelection::ContainsNode(nsIDOMNode* aNode, PRBool aRecursive, PRBool* aYes)
{

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

@ -296,8 +296,7 @@ nsTextInputListener::KeyPress(nsIDOMEvent* aKeyEvent)
//END KeyListener
//BEGIN NS_IDOMSELECITONLISTENER
//BEGIN NS_IDOMSELECTIONLISTENER
NS_IMETHODIMP
nsTextInputListener::NotifySelectionChanged(nsIDOMDocument* aDoc, nsIDOMSelection* aSel, PRInt16 aReason)
@ -309,31 +308,39 @@ nsTextInputListener::NotifySelectionChanged(nsIDOMDocument* aDoc, nsIDOMSelectio
// Fire the select event
// The specs don't exactly say when we should fire the select event.
// IE: Whenever you add/remove a character to/from the selection. Also
// if you get to the end of the text field you will get new event for each
// keypress or a continuous stream of events if you use the mouse. IE will
// fire select event when the selection collapses to nothing if you are holding down
// each time for select all. Also if you get to the end of the text
// field you will get new event for each keypress or a continuous
// stream of events if you use the mouse. IE will fire select event
// when the selection collapses to nothing if you are holding down
// the shift or mouse button.
// Mozilla: If we have non-empty selection we will fire a new event for each
// keypress (or mouseup) if the selection changed. Mozilla will never
// create an event if the selection collapses to nothing.
if (!collapsed && ((aReason & MOUSEUP_REASON) || (aReason & KEYPRESS_REASON))) {
// keypress (or mouseup) if the selection changed. Mozilla will also
// create the event each time select all is called, even if everything
// was previously selected, becase technically select all will first collapse
// and then extend. Mozilla will never create an event if the selection
// collapses to nothing.
if (!collapsed && (aReason & (nsIDOMSelectionListener::MOUSEUP_REASON |
nsIDOMSelectionListener::KEYPRESS_REASON |
nsIDOMSelectionListener::SELECTALL_REASON)))
{
nsCOMPtr<nsIContent> content;
mFrame->GetFormContent(*getter_AddRefs(content));
if (content) {
nsEventStatus status = nsEventStatus_eIgnore;
nsEvent event;
event.eventStructType = NS_EVENT;
event.message = NS_FORM_SELECTED;
if (content)
{
nsCOMPtr<nsIDocument> doc;
if (NS_SUCCEEDED(content->GetDocument(*getter_AddRefs(doc)))) {
if (doc) {
if (NS_SUCCEEDED(content->GetDocument(*getter_AddRefs(doc))))
{
if (doc)
{
nsCOMPtr<nsIPresShell> presShell = dont_AddRef(doc->GetShellAt(0));
if (presShell) {
nsCOMPtr<nsIPresContext> context;
if (NS_SUCCEEDED(presShell->GetPresContext(getter_AddRefs(context)))&& context) {
content->HandleDOMEvent(context, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
}
if (presShell)
{
nsEventStatus status = nsEventStatus_eIgnore;
nsEvent event;
event.eventStructType = NS_EVENT;
event.message = NS_FORM_SELECTED;
presShell->HandleEventWithTarget(&event,mFrame,content,&status);
}
}
}
@ -343,7 +350,7 @@ nsTextInputListener::NotifySelectionChanged(nsIDOMDocument* aDoc, nsIDOMSelectio
// if the collapsed state did not change, don't fire notifications
if (mKnowSelectionCollapsed && collapsed == mSelectionWasCollapsed)
return NS_OK;
mSelectionWasCollapsed = collapsed;
mKnowSelectionCollapsed = PR_TRUE;

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

@ -251,7 +251,6 @@ private:
nsFormFrame *mFormFrame;
nsTextInputSelectionImpl *mTextSelImpl;
nsTextInputListener *mTextListener;
};
#endif