зеркало из https://github.com/mozilla/pjs.git
Bug 300779. Expose XUL tree selection via accessibility events. r=timeless, sr=roc, a=mkaply
This commit is contained in:
Родитель
571d758bef
Коммит
a7b193f472
|
@ -237,14 +237,6 @@ nsresult nsRootAccessible::AddEventListeners()
|
|||
rv = target->AddEventListener(NS_LITERAL_STRING("select"), NS_STATIC_CAST(nsIDOMFormListener*, this), PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// capture non-text selection changes
|
||||
rv = target->AddEventListener(NS_LITERAL_STRING("DOMItemSelected"), NS_STATIC_CAST(nsIDOMXULListener*, this), PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// capture non-text selection changes
|
||||
rv = target->AddEventListener(NS_LITERAL_STRING("DOMItemUnselected"), NS_STATIC_CAST(nsIDOMXULListener*, this), PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// capture ValueChange events (fired whenever value changes, immediately after, whether focus moves or not)
|
||||
rv = target->AddEventListener(NS_LITERAL_STRING("ValueChange"), NS_STATIC_CAST(nsIDOMXULListener*, this), PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -317,8 +309,6 @@ nsresult nsRootAccessible::RemoveEventListeners()
|
|||
if (target) {
|
||||
target->RemoveEventListener(NS_LITERAL_STRING("focus"), NS_STATIC_CAST(nsIDOMFocusListener*, this), PR_TRUE);
|
||||
target->RemoveEventListener(NS_LITERAL_STRING("select"), NS_STATIC_CAST(nsIDOMFormListener*, this), PR_TRUE);
|
||||
target->RemoveEventListener(NS_LITERAL_STRING("DOMItemSelected"), NS_STATIC_CAST(nsIDOMXULListener*, this), PR_TRUE);
|
||||
target->RemoveEventListener(NS_LITERAL_STRING("DOMItemUnselected"), NS_STATIC_CAST(nsIDOMXULListener*, this), PR_TRUE);
|
||||
target->RemoveEventListener(NS_LITERAL_STRING("ValueChange"), NS_STATIC_CAST(nsIDOMXULListener*, this), PR_TRUE);
|
||||
target->RemoveEventListener(NS_LITERAL_STRING("AlertActive"), NS_STATIC_CAST(nsIDOMXULListener*, this), PR_TRUE);
|
||||
target->RemoveEventListener(NS_LITERAL_STRING("OpenStateChange"), NS_STATIC_CAST(nsIDOMXULListener*, this), PR_TRUE);
|
||||
|
@ -487,6 +477,9 @@ NS_IMETHODIMP nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent)
|
|||
if (localName.EqualsIgnoreCase("tree")) {
|
||||
printf("\ndebugging events in tree, event is %s", NS_ConvertUCS2toUTF8(eventType).get());
|
||||
}
|
||||
if (localName.EqualsIgnoreCase("select")) {
|
||||
printf("\ndebugging events in select, event is %s", NS_ConvertUCS2toUTF8(eventType).get());
|
||||
}
|
||||
#endif
|
||||
|
||||
nsCOMPtr<nsIPresShell> eventShell = GetPresShellFor(targetNode);
|
||||
|
@ -557,14 +550,33 @@ NS_IMETHODIMP nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent)
|
|||
if (eventType.LowerCaseEqualsLiteral("focus")) {
|
||||
FireAccessibleFocusEvent(accessible, targetNode); // Tree has focus
|
||||
}
|
||||
else if (eventType.LowerCaseEqualsLiteral("dommenuitemactive") ||
|
||||
eventType.LowerCaseEqualsLiteral("select")) {
|
||||
else if (eventType.LowerCaseEqualsLiteral("dommenuitemactive")) {
|
||||
if (gLastFocusedNode == targetNode) {
|
||||
privAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_FOCUS,
|
||||
treeItemAccessible, nsnull);
|
||||
}
|
||||
privAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_SELECTION,
|
||||
treeItemAccessible, nsnull);
|
||||
}
|
||||
else if (eventType.LowerCaseEqualsLiteral("select")) {
|
||||
// If multiselect tree, we should fire selectionadd or selection removed
|
||||
if (gLastFocusedNode == targetNode) {
|
||||
nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSel =
|
||||
do_QueryInterface(targetNode);
|
||||
nsAutoString selType;
|
||||
multiSel->GetSelType(selType);
|
||||
if (selType.IsEmpty() || !selType.EqualsLiteral("single")) {
|
||||
privAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_SELECTION_WITHIN,
|
||||
accessible, nsnull);
|
||||
// XXX We need to fire EVENT_SELECTION_ADD and EVENT_SELECTION_REMOVE
|
||||
// for each tree item. Perhaps each tree item will need to
|
||||
// cache its selection state and fire an event after a DOM "select"
|
||||
// event when that state changes.
|
||||
// nsXULTreeAccessible::UpdateTreeSelection();
|
||||
}
|
||||
else {
|
||||
privAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_SELECTION,
|
||||
treeItemAccessible, nsnull);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -678,20 +690,6 @@ NS_IMETHODIMP nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent)
|
|||
// Focus was inside of popup that's being hidden
|
||||
FireCurrentFocusEvent();
|
||||
}
|
||||
else if (eventType.EqualsLiteral("DOMItemUnselected")) {
|
||||
nsCOMPtr<nsIAccessible> multiSelect = GetMultiSelectFor(targetNode);
|
||||
if (multiSelect) {
|
||||
privAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_SELECTION_WITHIN, multiSelect, nsnull);
|
||||
privAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_SELECTION_REMOVE, accessible, nsnull);
|
||||
}
|
||||
}
|
||||
else if (eventType.EqualsLiteral("DOMItemSelected")) {
|
||||
nsCOMPtr<nsIAccessible> multiSelect = GetMultiSelectFor(targetNode);
|
||||
if (multiSelect) {
|
||||
privAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_SELECTION_WITHIN, multiSelect, nsnull);
|
||||
privAcc->FireToolkitEvent(nsIAccessibleEvent::EVENT_SELECTION_ADD, accessible, nsnull);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Menu popup events
|
||||
PRUint32 menuEvent = 0;
|
||||
|
@ -747,7 +745,7 @@ NS_IMETHODIMP nsRootAccessible::HandleEvent(nsIDOMEvent* aEvent)
|
|||
// XXX todo: value change events for ATK are done with
|
||||
// AtkPropertyChange, PROP_VALUE. Need the old and new value.
|
||||
// Not sure how we'll get the old value.
|
||||
// Aaron: I think this is a problem with the ATK API -- it's much harder to
|
||||
// Aaron: I think this is a problem with the ATK API -- its much harder to
|
||||
// grab the old value for all the application developers than it is for
|
||||
// AT's to cache old values when they need to (when would that be!?)
|
||||
else if (eventType.LowerCaseEqualsLiteral("valuechange")) {
|
||||
|
|
|
@ -457,6 +457,14 @@ nsXULTreeitemAccessible::nsXULTreeitemAccessible(nsIAccessible *aParent, nsIDOMN
|
|||
|
||||
NS_IMPL_ISUPPORTS_INHERITED0(nsXULTreeitemAccessible, nsLeafAccessible)
|
||||
|
||||
NS_IMETHODIMP nsXULTreeitemAccessible::Shutdown()
|
||||
{
|
||||
mTree = nsnull;
|
||||
mTreeView = nsnull;
|
||||
mColumn = nsnull;
|
||||
return nsLeafAccessible::Shutdown();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsXULTreeitemAccessible::GetName(nsAString& aName)
|
||||
{
|
||||
NS_ENSURE_TRUE(mTree && mTreeView, NS_ERROR_FAILURE);
|
||||
|
|
|
@ -95,6 +95,8 @@ public:
|
|||
nsXULTreeitemAccessible(nsIAccessible *aParent, nsIDOMNode *aDOMNode, nsIWeakReference *aShell, PRInt32 aRow, nsITreeColumn* aColumn = nsnull);
|
||||
virtual ~nsXULTreeitemAccessible() {}
|
||||
|
||||
NS_IMETHOD Shutdown();
|
||||
|
||||
/* ----- nsIAccessible ----- */
|
||||
NS_IMETHOD GetName(nsAString& _retval);
|
||||
NS_IMETHOD GetRole(PRUint32 *_retval);
|
||||
|
|
|
@ -52,6 +52,7 @@ EXPORTS = \
|
|||
nsIPrivateTextEvent.h \
|
||||
nsIPrivateTextRange.h \
|
||||
nsIPrivateCompositionEvent.h \
|
||||
nsPLDOMEvent.h \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla 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/MPL/
|
||||
*
|
||||
* 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
|
||||
* Aaron Leventhal (aaronleventhal@moonset.net)
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsPLDOMEvent_h___
|
||||
#define nsPLDOMEvent_h___
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "plevent.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsString.h"
|
||||
/**
|
||||
* Use nsPLDOMEvent to fire a DOM event that requires safe a stable DOM.
|
||||
* For example, you may need to fire an event from within layout, but
|
||||
* want to ensure that the event handler doesn't mutate the DOM at
|
||||
* the wrong time, in order to avoid resulting instability.
|
||||
*/
|
||||
|
||||
struct nsPLDOMEvent : public PLEvent {
|
||||
nsPLDOMEvent (nsIDOMNode *aEventNode, const nsAString& aEventType)
|
||||
: mEventNode(aEventNode), mEventType(aEventType)
|
||||
{ }
|
||||
|
||||
void HandleEvent();
|
||||
nsresult PostDOMEvent();
|
||||
|
||||
nsCOMPtr<nsIDOMNode> mEventNode;
|
||||
nsString mEventType;
|
||||
};
|
||||
|
||||
static void PR_CALLBACK HandlePLDOMEvent(nsPLDOMEvent* aEvent);
|
||||
static void PR_CALLBACK DestroyPLDOMEvent(nsPLDOMEvent* aEvent);
|
||||
|
||||
#endif
|
|
@ -80,6 +80,7 @@ CPPSRCS = \
|
|||
nsDOMEventGroup.cpp \
|
||||
nsXMLEventsManager.cpp \
|
||||
nsXMLEventsElement.cpp \
|
||||
nsPLDOMEvent.cpp \
|
||||
$(NULL)
|
||||
|
||||
# we don't want the shared lib, but we want to force the creation of a static lib.
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla 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/MPL/
|
||||
*
|
||||
* 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
|
||||
* Aaron Leventhal (aaronleventhal@moonset.net)
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsPLDOMEvent.h"
|
||||
#include "nsEventQueueUtils.h"
|
||||
#include "nsIDOMEvent.h"
|
||||
#include "nsIPrivateDOMEvent.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMDocumentEvent.h"
|
||||
#include "nsIDOMEventTarget.h"
|
||||
|
||||
void nsPLDOMEvent::HandleEvent()
|
||||
{
|
||||
if (!mEventNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
mEventNode->GetOwnerDocument(getter_AddRefs(domDoc));
|
||||
nsCOMPtr<nsIDOMDocumentEvent> domEventDoc = do_QueryInterface(domDoc);
|
||||
if (domEventDoc) {
|
||||
nsCOMPtr<nsIDOMEvent> domEvent;
|
||||
domEventDoc->CreateEvent(NS_LITERAL_STRING("Events"),
|
||||
getter_AddRefs(domEvent));
|
||||
|
||||
nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(domEvent));
|
||||
if (privateEvent && NS_SUCCEEDED(domEvent->InitEvent(mEventType, PR_TRUE, PR_TRUE))) {
|
||||
privateEvent->SetTrusted(PR_TRUE);
|
||||
|
||||
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mEventNode);
|
||||
PRBool defaultActionEnabled; // This is not used because the caller is async
|
||||
target->DispatchEvent(domEvent, &defaultActionEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsresult nsPLDOMEvent::PostDOMEvent()
|
||||
{
|
||||
nsCOMPtr<nsIEventQueue> eventQueue;
|
||||
nsresult rv = NS_GetCurrentEventQ(getter_AddRefs(eventQueue));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PL_InitEvent(this, nsnull, (PLHandleEventProc) ::HandlePLDOMEvent, (PLDestroyEventProc) ::DestroyPLDOMEvent);
|
||||
rv = eventQueue->PostEvent(this);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static void PR_CALLBACK HandlePLDOMEvent(nsPLDOMEvent* aEvent)
|
||||
{
|
||||
aEvent->HandleEvent();
|
||||
}
|
||||
|
||||
static void PR_CALLBACK DestroyPLDOMEvent(nsPLDOMEvent* aEvent)
|
||||
{
|
||||
delete aEvent;
|
||||
}
|
|
@ -53,6 +53,7 @@
|
|||
#include "nsGUIEvent.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsXULAtoms.h"
|
||||
#include "nsPLDOMEvent.h"
|
||||
|
||||
// A helper class for managing our ranges of selection.
|
||||
struct nsTreeRange
|
||||
|
@ -589,6 +590,9 @@ NS_IMETHODIMP nsTreeSelection::GetCurrentIndex(PRInt32 *aCurrentIndex)
|
|||
|
||||
NS_IMETHODIMP nsTreeSelection::SetCurrentIndex(PRInt32 aIndex)
|
||||
{
|
||||
if (mCurrentIndex == aIndex) {
|
||||
return NS_OK;
|
||||
}
|
||||
if (mCurrentIndex != -1)
|
||||
mTree->InvalidateRow(mCurrentIndex);
|
||||
|
||||
|
@ -597,7 +601,32 @@ NS_IMETHODIMP nsTreeSelection::SetCurrentIndex(PRInt32 aIndex)
|
|||
if (aIndex != -1)
|
||||
mTree->InvalidateRow(aIndex);
|
||||
|
||||
return NS_OK;
|
||||
// Fire DOMMenuItemActive event for tree
|
||||
nsCOMPtr<nsIBoxObject> boxObject = do_QueryInterface(mTree);
|
||||
NS_ASSERTION(boxObject, "no box object!");
|
||||
if (!boxObject)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
nsCOMPtr<nsIDOMElement> treeElt;
|
||||
boxObject->GetElement(getter_AddRefs(treeElt));
|
||||
|
||||
nsCOMPtr<nsIDOMNode> treeDOMNode(do_QueryInterface(treeElt));
|
||||
NS_ENSURE_TRUE(treeDOMNode, NS_ERROR_UNEXPECTED);
|
||||
|
||||
nsPLDOMEvent *event = new nsPLDOMEvent(treeDOMNode,
|
||||
NS_LITERAL_STRING("DOMMenuItemActive"));
|
||||
|
||||
nsresult rv;
|
||||
if (event) {
|
||||
rv = event->PostDOMEvent();
|
||||
if (NS_FAILED(rv)) {
|
||||
PL_DestroyEvent(event);
|
||||
}
|
||||
}
|
||||
else {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
#define ADD_NEW_RANGE(macro_range, macro_selection, macro_start, macro_end) \
|
||||
|
|
Загрузка…
Ссылка в новой задаче