diff --git a/accessible/src/base/nsRootAccessible.cpp b/accessible/src/base/nsRootAccessible.cpp index 50b829a4f51..25137e51701 100644 --- a/accessible/src/base/nsRootAccessible.cpp +++ b/accessible/src/base/nsRootAccessible.cpp @@ -649,7 +649,7 @@ nsresult nsRootAccessible::HandleEventWithTarget(nsIDOMEvent* aEvent, nsCOMPtr treeContent = do_QueryInterface(aTargetNode); nsAccEvent::PrepareForEvent(aTargetNode, PR_TRUE); return accService->InvalidateSubtreeFor(eventShell, treeContent, - nsIAccessibleEvent::EVENT_ASYNCH_SIGNIFICANT_CHANGE); + nsIAccessibleEvent::EVENT_DOM_SIGNIFICANT_CHANGE); } #endif diff --git a/accessible/tests/mochitest/test_bug368835.xul b/accessible/tests/mochitest/test_bug368835.xul index fe72762c46d..1c49dc47673 100644 --- a/accessible/tests/mochitest/test_bug368835.xul +++ b/accessible/tests/mochitest/test_bug368835.xul @@ -62,13 +62,21 @@ performActionOnCell: function(aAction, aRow, aCol) {} }; + var gTreeViewChangedCount = 0; var gTreeViewChanged = false; function TreeViewChangedHandler(aEvent) { - gTreeViewChanged = true; + gTreeViewChangedCount++; - // Tree view has been setted. We can continue tests for the tree. - window.setTimeout(doTest2, 0); + // We get two systems 'treeViewChanged' event when tree is initialized + // The third one is our when we change the tree view by + // nsITreeBoxObject::setTree. + if (gTreeViewChangedCount == 3) { + gTreeViewChanged = true; + + // Tree view has been setted. We can continue tests for the tree. + window.setTimeout(doTest2, 500); + } } var gTreeRowCountChanged = false; @@ -83,59 +91,50 @@ is(count, 1, "Wrong 'count' data of 'treeRowCountChanged' event."); } + var gTreeColumnInvalidated = false; + var gTreeRowInvalidated = false; + var gTreeInvalidatedCount = 0; function TreeInvalidatedHandler(aEvent) { gTreeInvalidatedCount++; - if (gTreeInvalidatedCount == 2) - TreeColumnInvalidatedHandler(aEvent); - else if (gTreeInvalidatedCount == 5) - TreeRowInvalidatedHandler(aEvent); + switch (gTreeInvalidatedCount) { + case 1: + TreeInvalidatedHandlerHelper(aEvent, 0, 5, null, null, + "nsITreeBoxObject::rowCountChanged"); + break; + case 2: + TreeInvalidatedHandlerHelper(aEvent, null, null, 0, 0, + "nsITreeBoxObject::invalidateColumn"); + gTreeColumnInvalidated = true; + break; + case 3: + TreeInvalidatedHandlerHelper(aEvent, 1, 1, null, null, + "nsITreeBoxObject::invalidateRow"); + gTreeRowInvalidated = true; + break; + } } - var gTreeColumnInvalidated = false; - function TreeColumnInvalidatedHandler(aEvent) + function TreeInvalidatedHandlerHelper(aEvent, aStartRow, aEndRow, + aStartCol, aEndCol, aCauseMsg) { var startRow = aEvent.getData("startrow"); - is(startRow, null, - "Wrong 'startrow' of 'treeInvalidated' event on InvalidateRow()."); + is(startRow, aStartRow, + "Wrong 'startrow' of 'treeInvalidated' event on " + aCauseMsg); var endRow = aEvent.getData("endrow"); - is(endRow, null, - "Wrong 'endrow' of 'treeInvalidated' event on InvalidateRow()."); + is(endRow, aEndRow, + "Wrong 'endrow' of 'treeInvalidated' event on " + aCauseMsg); var startCol = aEvent.getData("startcolumn"); - is(startCol, 0, - "Wrong 'startcolumn' of 'treeInvalidated' event on InvalidateRow()."); + is(startCol, aStartCol, + "Wrong 'startcolumn' of 'treeInvalidated' event on " + aCauseMsg); var endCol = aEvent.getData("endcolumn"); - is(endCol, 0, - "Wrong 'endcolumn' of 'treeInvalidated' event on InvalidateRow()."); - - gTreeColumnInvalidated = true; - } - - var gTreeRowInvalidated = false; - function TreeRowInvalidatedHandler(aEvent) - { - var startRow = aEvent.getData("startrow"); - is(startRow, 1, - "Wrong 'startrow' of 'treeInvalidated' event on InvalidateColumn()."); - - var endRow = aEvent.getData("endrow"); - is(endRow, 1, - "Wrong 'endrow' of 'treeInvalidated' event on InvalidateColumn()."); - - var startCol = aEvent.getData("startcolumn"); - is(startCol, null, - "Wrong 'startcolumn' of 'treeInvalidated' event on InvalidateColumn()."); - - var endCol = aEvent.getData("endcolumn"); - is(endCol, null, - "Wrong 'endcolumn' of 'treeInvalidated' event on InvalidateColumn()."); - - gTreeRowInvalidated = true; + is(endCol, aEndCol, + "Wrong 'endcolumn' of 'treeInvalidated' event on " + aCauseMsg); } var gNameChangedOnTreeRowInvalidated = false; @@ -155,6 +154,9 @@ ++this.mCount; + // We should get first six 'name changed' events on + // nsITreeBoxObject::invalidateColumn when we update 0th column + // containing six rows. if (this.mCount == 6) { gNameChangedOnTreeColumnInvalidated = true; @@ -166,8 +168,7 @@ gNameChangedOnTreeRowInvalidated = true; }, - mCount: 0, - mType: "" + mCount: 0 }; function CheckEvents() @@ -175,22 +176,26 @@ // If these fail then it doesn't mean actually events are not fired, // possibly setTimeout was executed earlier than events have been fired. - // DOM events + // nsITreeBoxObject::view ok(gTreeViewChanged, "TreeViewChanged event should have been fired."); + + // nsITreeBoxObject::rowCountChanged ok(gTreeRowCountChanged, "TreeRowCountChanged event should have been fired."); + + // nsITreeBoxObject::invalidateColumn ok(gTreeColumnInvalidated, "TreeInvalidated event should have been fired for InvalidateColumn()."); - ok(gTreeRowInvalidated, - "TreeInvalidated event should have been fired for InvalidateRow()."); - - // A11y events - ok(gNameChangedOnTreeRowInvalidated, - "Wrong NameChanged events number on tree row invalidation."); ok(gNameChangedOnTreeColumnInvalidated, "Wrong NameChanged events number on tree column invalidation."); + // nsITreeBoxObject::invalidateRow + ok(gTreeRowInvalidated, + "TreeInvalidated event should have been fired for InvalidateRow()."); + ok(gNameChangedOnTreeRowInvalidated, + "Wrong NameChanged events number on tree row invalidation."); + // Remove DOM event listeners document.removeEventListener("TreeViewChanged", TreeViewChangedHandler, true); @@ -225,7 +230,6 @@ getService(Components.interfaces.nsIObserverService); gObserverService.addObserver(gA11yEventObserver, "accessible-event", false); - // Add DOM event listeners document.addEventListener("TreeViewChanged", TreeViewChangedHandler, true); diff --git a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp index 3d30e58b3b3..d73d7838698 100644 --- a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp +++ b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp @@ -742,12 +742,6 @@ nsTreeBodyFrame::InvalidateRange(PRInt32 aStart, PRInt32 aEnd) if (aStart == aEnd) return InvalidateRow(aStart); -#ifdef ACCESSIBILITY - nsIPresShell *presShell = PresContext()->PresShell(); - if (presShell->IsAccessibilityActive()) - FireInvalidateEvent(aStart, aEnd, nsnull, nsnull); -#endif - PRInt32 last = GetLastVisibleRow(); if (aStart > aEnd || aEnd < mTopRowIndex || aStart > last) return NS_OK; @@ -758,6 +752,15 @@ nsTreeBodyFrame::InvalidateRange(PRInt32 aStart, PRInt32 aEnd) if (aEnd > last) aEnd = last; +#ifdef ACCESSIBILITY + nsIPresShell *presShell = PresContext()->PresShell(); + if (presShell->IsAccessibilityActive()) { + PRInt32 end = + mRowCount > 0 ? ((mRowCount <= aEnd) ? mRowCount - 1 : aEnd) : 0; + FireInvalidateEvent(aStart, end, nsnull, nsnull); + } +#endif + nsRect rangeRect(mInnerBox.x, mInnerBox.y+mRowHeight*(aStart-mTopRowIndex), mInnerBox.width, mRowHeight*(aEnd-aStart+1)); nsIFrame::Invalidate(rangeRect, PR_FALSE); @@ -777,12 +780,6 @@ nsTreeBodyFrame::InvalidateColumnRange(PRInt32 aStart, PRInt32 aEnd, nsITreeColu if (aStart == aEnd) return InvalidateCell(aStart, col); -#ifdef ACCESSIBILITY - nsIPresShell *presShell = PresContext()->PresShell(); - if (presShell->IsAccessibilityActive()) - FireInvalidateEvent(aStart, aEnd, aCol, aCol); -#endif - PRInt32 last = GetLastVisibleRow(); if (aStart > aEnd || aEnd < mTopRowIndex || aStart > last) return NS_OK; @@ -793,6 +790,15 @@ nsTreeBodyFrame::InvalidateColumnRange(PRInt32 aStart, PRInt32 aEnd, nsITreeColu if (aEnd > last) aEnd = last; +#ifdef ACCESSIBILITY + nsIPresShell *presShell = PresContext()->PresShell(); + if (presShell->IsAccessibilityActive()) { + PRInt32 end = + mRowCount > 0 ? ((mRowCount <= aEnd) ? mRowCount - 1 : aEnd) : 0; + FireInvalidateEvent(aStart, end, aCol, aCol); + } +#endif + nsRect rangeRect; nsresult rv = col->GetRect(this, mInnerBox.y+mRowHeight*(aStart-mTopRowIndex),