Fixing bug 50058 - too many onSelect firings. r=hyatt.

This commit is contained in:
bryner%uiuc.edu 2000-09-02 18:59:39 +00:00
Родитель d41d21ad60
Коммит 25f69ad484
13 изменённых файлов: 256 добавлений и 138 удалений

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

@ -106,6 +106,7 @@ nsXULTreeElement::nsXULTreeElement(nsIDOMXULElement* aOuter)
mCurrentItem = nsnull;
mSelectionStart = nsnull;
mSuppressOnSelect = PR_FALSE;
}
nsXULTreeElement::~nsXULTreeElement()
@ -137,7 +138,23 @@ nsXULTreeElement::GetSelectedItems(nsIDOMNodeList** aSelectedItems)
}
nsresult
nsXULTreeElement::SetSelectionInternal(nsIDOMXULElement* aTreeItem, PRBool aTimedFlag)
nsXULTreeElement::GetSuppressOnSelect(PRBool* aSuppressOnSelect)
{
*aSuppressOnSelect = mSuppressOnSelect;
return NS_OK;
}
nsresult
nsXULTreeElement::SetSuppressOnSelect(PRBool aSuppressOnSelect)
{
if (!aSuppressOnSelect && mSuppressOnSelect)
FireOnSelectHandler();
mSuppressOnSelect = aSuppressOnSelect;
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::SelectItem(nsIDOMXULElement* aTreeItem)
{
NS_ASSERTION(aTreeItem, "trying to select a null tree item");
if (!aTreeItem) return NS_OK;
@ -155,49 +172,50 @@ nsXULTreeElement::SetSelectionInternal(nsIDOMXULElement* aTreeItem, PRBool aTime
}
// First clear our selection.
ClearItemSelectionInternal();
PRBool suppressSelect = mSuppressOnSelect;
SetSuppressOnSelect(PR_TRUE);
ClearItemSelection();
// Now add ourselves to the selection by setting our selected attribute.
AddItemToSelectionInternal(aTreeItem);
AddItemToSelection(aTreeItem);
SetCurrentItem(aTreeItem);
mSelectionStart = nsnull;
if (aTimedFlag) {
if (mSelectTimer)
mSelectTimer->Cancel();
mSelectTimer = do_CreateInstance("component://netscape/timer");
mSelectTimer->Init(SelectCallback, this, 500, NS_PRIORITY_HIGH); // 100 ms delay
}
else FireOnSelectHandler();
SetSuppressOnSelect(suppressSelect);
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::SelectItem(nsIDOMXULElement* aTreeItem)
nsXULTreeElement::TimedSelect(nsIDOMXULElement* aTreeItem, PRInt32 aMsec)
{
return SetSelectionInternal(aTreeItem, PR_FALSE);
}
PRBool suppressSelect = mSuppressOnSelect;
NS_IMETHODIMP
nsXULTreeElement::TimedSelect(nsIDOMXULElement* aTreeItem)
{
return SetSelectionInternal(aTreeItem, PR_TRUE);
if (aMsec != -1)
SetSuppressOnSelect(PR_TRUE);
nsresult rv = SelectItem(aTreeItem);
if (aMsec != -1) {
// Note, not using SetSuppressOnSelect here because that will
// force FireOnSelect to fire immediately (if selection was not
// initially suppressed).
mSuppressOnSelect = suppressSelect;
if (!mSuppressOnSelect) {
if (mSelectTimer)
mSelectTimer->Cancel();
mSelectTimer = do_CreateInstance("component://netscape/timer");
mSelectTimer->Init(SelectCallback, this, aMsec, NS_PRIORITY_HIGH);
}
}
return rv;
}
NS_IMETHODIMP
nsXULTreeElement::ClearItemSelection()
{
ClearItemSelectionInternal();
mSelectionStart = nsnull;
FireOnSelectHandler();
return NS_OK;
}
void
nsXULTreeElement::ClearItemSelectionInternal()
{
// Enumerate the elements and remove them from the selection.
PRUint32 length;
@ -208,41 +226,37 @@ nsXULTreeElement::ClearItemSelectionInternal()
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
content->UnsetAttribute(kNameSpaceID_None, kSelectedAtom, PR_TRUE);
}
}
mSelectionStart = nsnull;
void
nsXULTreeElement::AddItemToSelectionInternal(nsIDOMXULElement* aTreeItem)
{
NS_ASSERTION(aTreeItem,"attepting to add a null tree item to the selection");
if (!aTreeItem) return;
// Without clearing the selection, perform the add.
nsCOMPtr<nsIContent> content = do_QueryInterface(aTreeItem);
content->SetAttribute(kNameSpaceID_None, kSelectedAtom, NS_ConvertASCIItoUCS2("true"), PR_TRUE);
if (!mSuppressOnSelect)
FireOnSelectHandler();
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::AddItemToSelection(nsIDOMXULElement* aTreeItem)
{
NS_ASSERTION(aTreeItem,"attepting to add a null tree item to the selection");
if (!aTreeItem) return NS_ERROR_FAILURE;
// Without clearing the selection, perform the add.
AddItemToSelectionInternal(aTreeItem);
FireOnSelectHandler();
nsCOMPtr<nsIContent> content = do_QueryInterface(aTreeItem);
content->SetAttribute(kNameSpaceID_None, kSelectedAtom, NS_ConvertASCIItoUCS2("true"), PR_TRUE);
if (!mSuppressOnSelect)
FireOnSelectHandler();
return NS_OK;
}
void
nsXULTreeElement::RemoveItemFromSelectionInternal(nsIDOMXULElement* aTreeItem)
{
nsCOMPtr<nsIContent> content = do_QueryInterface(aTreeItem);
content->UnsetAttribute(kNameSpaceID_None, kSelectedAtom, PR_TRUE);
}
NS_IMETHODIMP
nsXULTreeElement::RemoveItemFromSelection(nsIDOMXULElement* aTreeItem)
{
RemoveItemFromSelectionInternal(aTreeItem);
FireOnSelectHandler();
nsCOMPtr<nsIContent> content = do_QueryInterface(aTreeItem);
content->UnsetAttribute(kNameSpaceID_None, kSelectedAtom, PR_TRUE);
if (!mSuppressOnSelect)
FireOnSelectHandler();
return NS_OK;
}
@ -257,16 +271,20 @@ nsXULTreeElement::ToggleItemSelection(nsIDOMXULElement* aTreeItem)
nsAutoString isSelected;
aTreeItem->GetAttribute(NS_ConvertASCIItoUCS2("selected"), isSelected);
PRBool suppressSelect = mSuppressOnSelect;
SetSuppressOnSelect(PR_TRUE);
if (isSelected.EqualsWithConversion("true"))
RemoveItemFromSelectionInternal(aTreeItem);
RemoveItemFromSelection(aTreeItem);
else if (multiple.EqualsWithConversion("true") || length == 0)
AddItemToSelectionInternal(aTreeItem);
AddItemToSelection(aTreeItem);
else
return NS_OK;
SetCurrentItem(aTreeItem);
SetSuppressOnSelect(suppressSelect);
FireOnSelectHandler();
return NS_OK;
}
@ -295,7 +313,9 @@ nsXULTreeElement::SelectItemRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement
startItem = aEndItem;
// First clear our selection out completely.
ClearItemSelectionInternal();
PRBool suppressSelect = mSuppressOnSelect;
SetSuppressOnSelect(PR_TRUE);
ClearItemSelection();
PRInt32 startIndex = 0,
endIndex = 0;
@ -338,7 +358,7 @@ nsXULTreeElement::SelectItemRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement
currentItem = nextItem;
}
FireOnSelectHandler();
SetSuppressOnSelect(suppressSelect);
return NS_OK;
}
@ -391,6 +411,7 @@ nsXULTreeElement::InvertSelection()
nsresult
nsXULTreeElement::FireOnSelectHandler()
{
printf("FireOnSelectHandler\n");
nsCOMPtr<nsIContent> content = do_QueryInterface(mOuter);
nsCOMPtr<nsIDocument> document;
content->GetDocument(*getter_AddRefs(document));

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

@ -73,12 +73,6 @@ public:
protected:
// Helpers
nsresult SetSelectionInternal(nsIDOMXULElement* aTreeItem, PRBool aTimedFlag);
void ClearItemSelectionInternal();
void AddItemToSelectionInternal(nsIDOMXULElement* aTreeItem);
void RemoveItemFromSelectionInternal(nsIDOMXULElement* aTreeItem);
static nsresult IndexOfContent(nsIContent *aRoot, nsIContent *aContent,
PRBool aDescendIntoRows,
PRBool aParentIsOpen,
@ -90,6 +84,7 @@ protected:
nsRDFDOMNodeList* mSelectedItems;
nsIDOMXULElement* mCurrentItem;
nsIDOMXULElement* mSelectionStart;
PRBool mSuppressOnSelect;
nsCOMPtr<nsITimer> mSelectTimer;
};

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

@ -4,9 +4,10 @@ interface XULTreeElement : XULElement {
readonly attribute NodeList selectedItems;
attribute XULElement currentItem;
attribute boolean suppressOnSelect;
void selectItem(in XULElement treeItem);
void timedSelect(in XULElement treeItem);
void timedSelect(in XULElement treeItem, in long timeout);
void clearItemSelection();

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

@ -1099,6 +1099,7 @@ enum nsDOMProp {
NS_DOM_PROP_XULTREEELEMENT_SELECTEDITEMS,
NS_DOM_PROP_XULTREEELEMENT_SELECTITEM,
NS_DOM_PROP_XULTREEELEMENT_SELECTITEMRANGE,
NS_DOM_PROP_XULTREEELEMENT_SUPPRESSONSELECT,
NS_DOM_PROP_XULTREEELEMENT_TIMEDSELECT,
NS_DOM_PROP_XULTREEELEMENT_TOGGLECELLSELECTION,
NS_DOM_PROP_XULTREEELEMENT_TOGGLEITEMSELECTION,

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

@ -1097,6 +1097,7 @@
"xultreeelement.selecteditems", \
"xultreeelement.selectitem", \
"xultreeelement.selectitemrange", \
"xultreeelement.suppressonselect", \
"xultreeelement.timedselect", \
"xultreeelement.togglecellselection", \
"xultreeelement.toggleitemselection", \

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

@ -45,9 +45,12 @@ public:
NS_IMETHOD GetCurrentItem(nsIDOMXULElement** aCurrentItem)=0;
NS_IMETHOD SetCurrentItem(nsIDOMXULElement* aCurrentItem)=0;
NS_IMETHOD GetSuppressOnSelect(PRBool* aSuppressOnSelect)=0;
NS_IMETHOD SetSuppressOnSelect(PRBool aSuppressOnSelect)=0;
NS_IMETHOD SelectItem(nsIDOMXULElement* aTreeItem)=0;
NS_IMETHOD TimedSelect(nsIDOMXULElement* aTreeItem)=0;
NS_IMETHOD TimedSelect(nsIDOMXULElement* aTreeItem, PRInt32 aTimeout)=0;
NS_IMETHOD ClearItemSelection()=0;
@ -69,8 +72,10 @@ public:
NS_IMETHOD GetSelectedItems(nsIDOMNodeList** aSelectedItems); \
NS_IMETHOD GetCurrentItem(nsIDOMXULElement** aCurrentItem); \
NS_IMETHOD SetCurrentItem(nsIDOMXULElement* aCurrentItem); \
NS_IMETHOD GetSuppressOnSelect(PRBool* aSuppressOnSelect); \
NS_IMETHOD SetSuppressOnSelect(PRBool aSuppressOnSelect); \
NS_IMETHOD SelectItem(nsIDOMXULElement* aTreeItem); \
NS_IMETHOD TimedSelect(nsIDOMXULElement* aTreeItem); \
NS_IMETHOD TimedSelect(nsIDOMXULElement* aTreeItem, PRInt32 aTimeout); \
NS_IMETHOD ClearItemSelection(); \
NS_IMETHOD AddItemToSelection(nsIDOMXULElement* aTreeItem); \
NS_IMETHOD RemoveItemFromSelection(nsIDOMXULElement* aTreeItem); \
@ -85,8 +90,10 @@ public:
NS_IMETHOD GetSelectedItems(nsIDOMNodeList** aSelectedItems) { return _to GetSelectedItems(aSelectedItems); } \
NS_IMETHOD GetCurrentItem(nsIDOMXULElement** aCurrentItem) { return _to GetCurrentItem(aCurrentItem); } \
NS_IMETHOD SetCurrentItem(nsIDOMXULElement* aCurrentItem) { return _to SetCurrentItem(aCurrentItem); } \
NS_IMETHOD GetSuppressOnSelect(PRBool* aSuppressOnSelect) { return _to GetSuppressOnSelect(aSuppressOnSelect); } \
NS_IMETHOD SetSuppressOnSelect(PRBool aSuppressOnSelect) { return _to SetSuppressOnSelect(aSuppressOnSelect); } \
NS_IMETHOD SelectItem(nsIDOMXULElement* aTreeItem) { return _to SelectItem(aTreeItem); } \
NS_IMETHOD TimedSelect(nsIDOMXULElement* aTreeItem) { return _to TimedSelect(aTreeItem); } \
NS_IMETHOD TimedSelect(nsIDOMXULElement* aTreeItem, PRInt32 aTimeout) { return _to TimedSelect(aTreeItem, aTimeout); } \
NS_IMETHOD ClearItemSelection() { return _to ClearItemSelection(); } \
NS_IMETHOD AddItemToSelection(nsIDOMXULElement* aTreeItem) { return _to AddItemToSelection(aTreeItem); } \
NS_IMETHOD RemoveItemFromSelection(nsIDOMXULElement* aTreeItem) { return _to RemoveItemFromSelection(aTreeItem); } \

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

@ -51,7 +51,8 @@ static NS_DEFINE_IID(kINodeListIID, NS_IDOMNODELIST_IID);
//
enum XULTreeElement_slots {
XULTREEELEMENT_SELECTEDITEMS = -1,
XULTREEELEMENT_CURRENTITEM = -2
XULTREEELEMENT_CURRENTITEM = -2,
XULTREEELEMENT_SUPPRESSONSELECT = -3
};
/***********************************************************************/
@ -100,6 +101,18 @@ GetXULTreeElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
}
break;
}
case XULTREEELEMENT_SUPPRESSONSELECT:
{
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_XULTREEELEMENT_SUPPRESSONSELECT, PR_FALSE);
if (NS_SUCCEEDED(rv)) {
PRBool prop;
rv = a->GetSuppressOnSelect(&prop);
if (NS_SUCCEEDED(rv)) {
*vp = BOOLEAN_TO_JSVAL(prop);
}
}
break;
}
default:
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, obj, id, vp);
}
@ -150,6 +163,21 @@ SetXULTreeElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
}
break;
}
case XULTREEELEMENT_SUPPRESSONSELECT:
{
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_XULTREEELEMENT_SUPPRESSONSELECT, PR_TRUE);
if (NS_SUCCEEDED(rv)) {
PRBool prop;
if (PR_FALSE == nsJSUtils::nsConvertJSValToBool(&prop, cx, *vp)) {
rv = NS_ERROR_DOM_NOT_BOOLEAN_ERR;
break;
}
rv = a->SetSuppressOnSelect(prop);
}
break;
}
default:
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, obj, id, vp);
}
@ -250,6 +278,7 @@ XULTreeElementTimedSelect(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
nsIDOMXULTreeElement *nativeThis = (nsIDOMXULTreeElement*)nsJSUtils::nsGetNativeThis(cx, obj);
nsresult result = NS_OK;
nsCOMPtr<nsIDOMXULElement> b0;
PRInt32 b1;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
@ -264,7 +293,7 @@ XULTreeElementTimedSelect(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result);
}
if (argc < 1) {
if (argc < 2) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
}
@ -275,8 +304,11 @@ XULTreeElementTimedSelect(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
argv[0])) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_OBJECT_ERR);
}
if (!JS_ValueToInt32(cx, argv[1], (int32 *)&b1)) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_NUMBER_ERR);
}
result = nativeThis->TimedSelect(b0);
result = nativeThis->TimedSelect(b0, b1);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result);
}
@ -616,6 +648,7 @@ static JSPropertySpec XULTreeElementProperties[] =
{
{"selectedItems", XULTREEELEMENT_SELECTEDITEMS, JSPROP_ENUMERATE | JSPROP_READONLY},
{"currentItem", XULTREEELEMENT_CURRENTITEM, JSPROP_ENUMERATE},
{"suppressOnSelect", XULTREEELEMENT_SUPPRESSONSELECT, JSPROP_ENUMERATE},
{0}
};
@ -626,7 +659,7 @@ static JSPropertySpec XULTreeElementProperties[] =
static JSFunctionSpec XULTreeElementMethods[] =
{
{"selectItem", XULTreeElementSelectItem, 1},
{"timedSelect", XULTreeElementTimedSelect, 1},
{"timedSelect", XULTreeElementTimedSelect, 2},
{"clearItemSelection", XULTreeElementClearItemSelection, 0},
{"addItemToSelection", XULTreeElementAddItemToSelection, 1},
{"removeItemFromSelection", XULTreeElementRemoveItemFromSelection, 1},

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

@ -4,9 +4,10 @@ interface XULTreeElement : XULElement {
readonly attribute NodeList selectedItems;
attribute XULElement currentItem;
attribute boolean suppressOnSelect;
void selectItem(in XULElement treeItem);
void timedSelect(in XULElement treeItem);
void timedSelect(in XULElement treeItem, in long timeout);
void clearItemSelection();

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

@ -45,9 +45,12 @@ public:
NS_IMETHOD GetCurrentItem(nsIDOMXULElement** aCurrentItem)=0;
NS_IMETHOD SetCurrentItem(nsIDOMXULElement* aCurrentItem)=0;
NS_IMETHOD GetSuppressOnSelect(PRBool* aSuppressOnSelect)=0;
NS_IMETHOD SetSuppressOnSelect(PRBool aSuppressOnSelect)=0;
NS_IMETHOD SelectItem(nsIDOMXULElement* aTreeItem)=0;
NS_IMETHOD TimedSelect(nsIDOMXULElement* aTreeItem)=0;
NS_IMETHOD TimedSelect(nsIDOMXULElement* aTreeItem, PRInt32 aTimeout)=0;
NS_IMETHOD ClearItemSelection()=0;
@ -69,8 +72,10 @@ public:
NS_IMETHOD GetSelectedItems(nsIDOMNodeList** aSelectedItems); \
NS_IMETHOD GetCurrentItem(nsIDOMXULElement** aCurrentItem); \
NS_IMETHOD SetCurrentItem(nsIDOMXULElement* aCurrentItem); \
NS_IMETHOD GetSuppressOnSelect(PRBool* aSuppressOnSelect); \
NS_IMETHOD SetSuppressOnSelect(PRBool aSuppressOnSelect); \
NS_IMETHOD SelectItem(nsIDOMXULElement* aTreeItem); \
NS_IMETHOD TimedSelect(nsIDOMXULElement* aTreeItem); \
NS_IMETHOD TimedSelect(nsIDOMXULElement* aTreeItem, PRInt32 aTimeout); \
NS_IMETHOD ClearItemSelection(); \
NS_IMETHOD AddItemToSelection(nsIDOMXULElement* aTreeItem); \
NS_IMETHOD RemoveItemFromSelection(nsIDOMXULElement* aTreeItem); \
@ -85,8 +90,10 @@ public:
NS_IMETHOD GetSelectedItems(nsIDOMNodeList** aSelectedItems) { return _to GetSelectedItems(aSelectedItems); } \
NS_IMETHOD GetCurrentItem(nsIDOMXULElement** aCurrentItem) { return _to GetCurrentItem(aCurrentItem); } \
NS_IMETHOD SetCurrentItem(nsIDOMXULElement* aCurrentItem) { return _to SetCurrentItem(aCurrentItem); } \
NS_IMETHOD GetSuppressOnSelect(PRBool* aSuppressOnSelect) { return _to GetSuppressOnSelect(aSuppressOnSelect); } \
NS_IMETHOD SetSuppressOnSelect(PRBool aSuppressOnSelect) { return _to SetSuppressOnSelect(aSuppressOnSelect); } \
NS_IMETHOD SelectItem(nsIDOMXULElement* aTreeItem) { return _to SelectItem(aTreeItem); } \
NS_IMETHOD TimedSelect(nsIDOMXULElement* aTreeItem) { return _to TimedSelect(aTreeItem); } \
NS_IMETHOD TimedSelect(nsIDOMXULElement* aTreeItem, PRInt32 aTimeout) { return _to TimedSelect(aTreeItem, aTimeout); } \
NS_IMETHOD ClearItemSelection() { return _to ClearItemSelection(); } \
NS_IMETHOD AddItemToSelection(nsIDOMXULElement* aTreeItem) { return _to AddItemToSelection(aTreeItem); } \
NS_IMETHOD RemoveItemFromSelection(nsIDOMXULElement* aTreeItem) { return _to RemoveItemFromSelection(aTreeItem); } \

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

@ -51,7 +51,8 @@ static NS_DEFINE_IID(kINodeListIID, NS_IDOMNODELIST_IID);
//
enum XULTreeElement_slots {
XULTREEELEMENT_SELECTEDITEMS = -1,
XULTREEELEMENT_CURRENTITEM = -2
XULTREEELEMENT_CURRENTITEM = -2,
XULTREEELEMENT_SUPPRESSONSELECT = -3
};
/***********************************************************************/
@ -100,6 +101,18 @@ GetXULTreeElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
}
break;
}
case XULTREEELEMENT_SUPPRESSONSELECT:
{
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_XULTREEELEMENT_SUPPRESSONSELECT, PR_FALSE);
if (NS_SUCCEEDED(rv)) {
PRBool prop;
rv = a->GetSuppressOnSelect(&prop);
if (NS_SUCCEEDED(rv)) {
*vp = BOOLEAN_TO_JSVAL(prop);
}
}
break;
}
default:
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, obj, id, vp);
}
@ -150,6 +163,21 @@ SetXULTreeElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
}
break;
}
case XULTREEELEMENT_SUPPRESSONSELECT:
{
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_XULTREEELEMENT_SUPPRESSONSELECT, PR_TRUE);
if (NS_SUCCEEDED(rv)) {
PRBool prop;
if (PR_FALSE == nsJSUtils::nsConvertJSValToBool(&prop, cx, *vp)) {
rv = NS_ERROR_DOM_NOT_BOOLEAN_ERR;
break;
}
rv = a->SetSuppressOnSelect(prop);
}
break;
}
default:
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, obj, id, vp);
}
@ -250,6 +278,7 @@ XULTreeElementTimedSelect(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
nsIDOMXULTreeElement *nativeThis = (nsIDOMXULTreeElement*)nsJSUtils::nsGetNativeThis(cx, obj);
nsresult result = NS_OK;
nsCOMPtr<nsIDOMXULElement> b0;
PRInt32 b1;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
@ -264,7 +293,7 @@ XULTreeElementTimedSelect(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result);
}
if (argc < 1) {
if (argc < 2) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
}
@ -275,8 +304,11 @@ XULTreeElementTimedSelect(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
argv[0])) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_OBJECT_ERR);
}
if (!JS_ValueToInt32(cx, argv[1], (int32 *)&b1)) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_NUMBER_ERR);
}
result = nativeThis->TimedSelect(b0);
result = nativeThis->TimedSelect(b0, b1);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result);
}
@ -616,6 +648,7 @@ static JSPropertySpec XULTreeElementProperties[] =
{
{"selectedItems", XULTREEELEMENT_SELECTEDITEMS, JSPROP_ENUMERATE | JSPROP_READONLY},
{"currentItem", XULTREEELEMENT_CURRENTITEM, JSPROP_ENUMERATE},
{"suppressOnSelect", XULTREEELEMENT_SUPPRESSONSELECT, JSPROP_ENUMERATE},
{0}
};
@ -626,7 +659,7 @@ static JSPropertySpec XULTreeElementProperties[] =
static JSFunctionSpec XULTreeElementMethods[] =
{
{"selectItem", XULTreeElementSelectItem, 1},
{"timedSelect", XULTreeElementTimedSelect, 1},
{"timedSelect", XULTreeElementTimedSelect, 2},
{"clearItemSelection", XULTreeElementClearItemSelection, 0},
{"addItemToSelection", XULTreeElementAddItemToSelection, 1},
{"removeItemFromSelection", XULTreeElementRemoveItemFromSelection, 1},

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

@ -106,6 +106,7 @@ nsXULTreeElement::nsXULTreeElement(nsIDOMXULElement* aOuter)
mCurrentItem = nsnull;
mSelectionStart = nsnull;
mSuppressOnSelect = PR_FALSE;
}
nsXULTreeElement::~nsXULTreeElement()
@ -137,7 +138,23 @@ nsXULTreeElement::GetSelectedItems(nsIDOMNodeList** aSelectedItems)
}
nsresult
nsXULTreeElement::SetSelectionInternal(nsIDOMXULElement* aTreeItem, PRBool aTimedFlag)
nsXULTreeElement::GetSuppressOnSelect(PRBool* aSuppressOnSelect)
{
*aSuppressOnSelect = mSuppressOnSelect;
return NS_OK;
}
nsresult
nsXULTreeElement::SetSuppressOnSelect(PRBool aSuppressOnSelect)
{
if (!aSuppressOnSelect && mSuppressOnSelect)
FireOnSelectHandler();
mSuppressOnSelect = aSuppressOnSelect;
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::SelectItem(nsIDOMXULElement* aTreeItem)
{
NS_ASSERTION(aTreeItem, "trying to select a null tree item");
if (!aTreeItem) return NS_OK;
@ -155,49 +172,50 @@ nsXULTreeElement::SetSelectionInternal(nsIDOMXULElement* aTreeItem, PRBool aTime
}
// First clear our selection.
ClearItemSelectionInternal();
PRBool suppressSelect = mSuppressOnSelect;
SetSuppressOnSelect(PR_TRUE);
ClearItemSelection();
// Now add ourselves to the selection by setting our selected attribute.
AddItemToSelectionInternal(aTreeItem);
AddItemToSelection(aTreeItem);
SetCurrentItem(aTreeItem);
mSelectionStart = nsnull;
if (aTimedFlag) {
if (mSelectTimer)
mSelectTimer->Cancel();
mSelectTimer = do_CreateInstance("component://netscape/timer");
mSelectTimer->Init(SelectCallback, this, 500, NS_PRIORITY_HIGH); // 100 ms delay
}
else FireOnSelectHandler();
SetSuppressOnSelect(suppressSelect);
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::SelectItem(nsIDOMXULElement* aTreeItem)
nsXULTreeElement::TimedSelect(nsIDOMXULElement* aTreeItem, PRInt32 aMsec)
{
return SetSelectionInternal(aTreeItem, PR_FALSE);
}
PRBool suppressSelect = mSuppressOnSelect;
NS_IMETHODIMP
nsXULTreeElement::TimedSelect(nsIDOMXULElement* aTreeItem)
{
return SetSelectionInternal(aTreeItem, PR_TRUE);
if (aMsec != -1)
SetSuppressOnSelect(PR_TRUE);
nsresult rv = SelectItem(aTreeItem);
if (aMsec != -1) {
// Note, not using SetSuppressOnSelect here because that will
// force FireOnSelect to fire immediately (if selection was not
// initially suppressed).
mSuppressOnSelect = suppressSelect;
if (!mSuppressOnSelect) {
if (mSelectTimer)
mSelectTimer->Cancel();
mSelectTimer = do_CreateInstance("component://netscape/timer");
mSelectTimer->Init(SelectCallback, this, aMsec, NS_PRIORITY_HIGH);
}
}
return rv;
}
NS_IMETHODIMP
nsXULTreeElement::ClearItemSelection()
{
ClearItemSelectionInternal();
mSelectionStart = nsnull;
FireOnSelectHandler();
return NS_OK;
}
void
nsXULTreeElement::ClearItemSelectionInternal()
{
// Enumerate the elements and remove them from the selection.
PRUint32 length;
@ -208,41 +226,37 @@ nsXULTreeElement::ClearItemSelectionInternal()
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
content->UnsetAttribute(kNameSpaceID_None, kSelectedAtom, PR_TRUE);
}
}
mSelectionStart = nsnull;
void
nsXULTreeElement::AddItemToSelectionInternal(nsIDOMXULElement* aTreeItem)
{
NS_ASSERTION(aTreeItem,"attepting to add a null tree item to the selection");
if (!aTreeItem) return;
// Without clearing the selection, perform the add.
nsCOMPtr<nsIContent> content = do_QueryInterface(aTreeItem);
content->SetAttribute(kNameSpaceID_None, kSelectedAtom, NS_ConvertASCIItoUCS2("true"), PR_TRUE);
if (!mSuppressOnSelect)
FireOnSelectHandler();
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::AddItemToSelection(nsIDOMXULElement* aTreeItem)
{
NS_ASSERTION(aTreeItem,"attepting to add a null tree item to the selection");
if (!aTreeItem) return NS_ERROR_FAILURE;
// Without clearing the selection, perform the add.
AddItemToSelectionInternal(aTreeItem);
FireOnSelectHandler();
nsCOMPtr<nsIContent> content = do_QueryInterface(aTreeItem);
content->SetAttribute(kNameSpaceID_None, kSelectedAtom, NS_ConvertASCIItoUCS2("true"), PR_TRUE);
if (!mSuppressOnSelect)
FireOnSelectHandler();
return NS_OK;
}
void
nsXULTreeElement::RemoveItemFromSelectionInternal(nsIDOMXULElement* aTreeItem)
{
nsCOMPtr<nsIContent> content = do_QueryInterface(aTreeItem);
content->UnsetAttribute(kNameSpaceID_None, kSelectedAtom, PR_TRUE);
}
NS_IMETHODIMP
nsXULTreeElement::RemoveItemFromSelection(nsIDOMXULElement* aTreeItem)
{
RemoveItemFromSelectionInternal(aTreeItem);
FireOnSelectHandler();
nsCOMPtr<nsIContent> content = do_QueryInterface(aTreeItem);
content->UnsetAttribute(kNameSpaceID_None, kSelectedAtom, PR_TRUE);
if (!mSuppressOnSelect)
FireOnSelectHandler();
return NS_OK;
}
@ -257,16 +271,20 @@ nsXULTreeElement::ToggleItemSelection(nsIDOMXULElement* aTreeItem)
nsAutoString isSelected;
aTreeItem->GetAttribute(NS_ConvertASCIItoUCS2("selected"), isSelected);
PRBool suppressSelect = mSuppressOnSelect;
SetSuppressOnSelect(PR_TRUE);
if (isSelected.EqualsWithConversion("true"))
RemoveItemFromSelectionInternal(aTreeItem);
RemoveItemFromSelection(aTreeItem);
else if (multiple.EqualsWithConversion("true") || length == 0)
AddItemToSelectionInternal(aTreeItem);
AddItemToSelection(aTreeItem);
else
return NS_OK;
SetCurrentItem(aTreeItem);
SetSuppressOnSelect(suppressSelect);
FireOnSelectHandler();
return NS_OK;
}
@ -295,7 +313,9 @@ nsXULTreeElement::SelectItemRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement
startItem = aEndItem;
// First clear our selection out completely.
ClearItemSelectionInternal();
PRBool suppressSelect = mSuppressOnSelect;
SetSuppressOnSelect(PR_TRUE);
ClearItemSelection();
PRInt32 startIndex = 0,
endIndex = 0;
@ -338,7 +358,7 @@ nsXULTreeElement::SelectItemRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement
currentItem = nextItem;
}
FireOnSelectHandler();
SetSuppressOnSelect(suppressSelect);
return NS_OK;
}
@ -391,6 +411,7 @@ nsXULTreeElement::InvertSelection()
nsresult
nsXULTreeElement::FireOnSelectHandler()
{
printf("FireOnSelectHandler\n");
nsCOMPtr<nsIContent> content = do_QueryInterface(mOuter);
nsCOMPtr<nsIDocument> document;
content->GetDocument(*getter_AddRefs(document));

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

@ -73,12 +73,6 @@ public:
protected:
// Helpers
nsresult SetSelectionInternal(nsIDOMXULElement* aTreeItem, PRBool aTimedFlag);
void ClearItemSelectionInternal();
void AddItemToSelectionInternal(nsIDOMXULElement* aTreeItem);
void RemoveItemFromSelectionInternal(nsIDOMXULElement* aTreeItem);
static nsresult IndexOfContent(nsIContent *aRoot, nsIContent *aContent,
PRBool aDescendIntoRows,
PRBool aParentIsOpen,
@ -90,6 +84,7 @@ protected:
nsRDFDOMNodeList* mSelectedItems;
nsIDOMXULElement* mCurrentItem;
nsIDOMXULElement* mSelectionStart;
PRBool mSuppressOnSelect;
nsCOMPtr<nsITimer> mSelectTimer;
};

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

@ -217,7 +217,7 @@
var n = this.getPreviousItem(this.selectedItems[0], 1);
if (n) {
this.ensureIndexIsVisible(this.getIndexOfItem(this.selectedItems[0])-1);
this.timedSelect(n);
this.timedSelect(n, 500);
}
]]>
</handler>
@ -228,7 +228,7 @@
var n = this.getNextItem(this.selectedItems[0], 1);
if (n) {
this.ensureIndexIsVisible(this.getIndexOfItem(this.selectedItems[0])+1);
this.timedSelect(n);
this.timedSelect(n, 500);
}
]]>
</handler>
@ -334,6 +334,7 @@
parentNode.currentItem = event.target.parentNode.parentNode;
}
else {
parentNode.suppressOnSelect = true;
var selectedItems = parentNode.selectedItems;
var i = 0;
while (i < selectedItems.length) {
@ -342,6 +343,7 @@
else
i++;
}
parentNode.suppressOnSelect = false;
}
}
]]>