From 6df645c12d28eee746ca06fd0b36db20f3e35247 Mon Sep 17 00:00:00 2001 From: "surkov.alexander%gmail.com" Date: Fri, 20 Apr 2007 07:29:08 +0000 Subject: [PATCH] Fix for bug 377756 - move property change events code to atk, r=ginn.chen --- accessible/src/atk/nsAccessibleWrap.cpp | 221 +++++++++++++++----- accessible/src/atk/nsAccessibleWrap.h | 30 +++ accessible/src/atk/nsDocAccessibleWrap.cpp | 91 -------- accessible/src/base/nsAccessibleEventData.h | 25 +-- 4 files changed, 196 insertions(+), 171 deletions(-) diff --git a/accessible/src/atk/nsAccessibleWrap.cpp b/accessible/src/atk/nsAccessibleWrap.cpp index a60512035ed..8d257130671 100644 --- a/accessible/src/atk/nsAccessibleWrap.cpp +++ b/accessible/src/atk/nsAccessibleWrap.cpp @@ -253,6 +253,26 @@ mai_atk_object_get_type(void) return type; } +/* + * Must keep sychronization with enumerate AtkProperty in + * accessible/src/base/nsAccessibleEventData.h + */ +static char * sAtkPropertyNameArray[PROP_LAST] = { + 0, + "accessible-name", + "accessible-description", + "accessible-parent", + "accessible-role", + "accessible-layer", + "accessible-mdi-zorder", + "accessible-table-caption", + "accessible-table-column-description", + "accessible-table-column-header", + "accessible-table-row-description", + "accessible-table-row-header", + "accessible-table-summary" +}; + #ifdef MAI_LOGGING PRInt32 nsAccessibleWrap::mAccWrapCreated = 0; PRInt32 nsAccessibleWrap::mAccWrapDeleted = 0; @@ -1039,68 +1059,155 @@ nsAccessibleWrap::FireAccessibleEvent(nsIAccessibleEvent *aEvent) switch (type) { case nsIAccessibleEvent::EVENT_STATE_CHANGE: - { - MAI_LOG_DEBUG(("\n\nReceived: EVENT_STATE_CHANGE\n")); - - nsCOMPtr event = - do_QueryInterface(aEvent); - NS_ENSURE_TRUE(event, NS_ERROR_FAILURE); - - PRUint32 state = 0; - event->GetState(&state); - - PRBool isExtra; - event->IsExtraState(&isExtra); - - PRBool isEnabled; - event->IsEnabled(&isEnabled); - - PRInt32 stateIndex = AtkStateMap::GetStateIndexFor(state); - if (stateIndex >= 0) { - const AtkStateMap *atkStateMap = isExtra ? gAtkStateMapExt : gAtkStateMap; - NS_ASSERTION(atkStateMap[stateIndex].stateMapEntryType != kNoSuchState, - "No such state"); - - if (atkStateMap[stateIndex].atkState != kNone) { - NS_ASSERTION(atkStateMap[stateIndex].stateMapEntryType != kNoStateChange, - "State changes should not fired for this state"); - - if (atkStateMap[stateIndex].stateMapEntryType == kMapOpposite) - isEnabled = !isEnabled; - - // Fire state change for first state if there is one to map - atk_object_notify_state_change(atkObj, - atkStateMap[stateIndex].atkState, - isEnabled); - } - } - break; - } + return FireAtkStateChangeEvent(aEvent, atkObj); case nsIAccessibleEvent::EVENT_TEXT_CHANGED: - MAI_LOG_DEBUG(("\n\nReceived: EVENT_TEXT_CHANGED\n")); + return FireAtkTextChangedEvent(aEvent, atkObj); - nsCOMPtr event = - do_QueryInterface(aEvent); - NS_ENSURE_TRUE(event, NS_ERROR_FAILURE); - - PRInt32 start = 0; - event->GetStart(&start); - - PRUint32 length = 0; - event->GetLength(&length); - - PRBool isInserted; - event->IsInserted(&isInserted); - - g_signal_emit_by_name (atkObj, - isInserted ? \ - "text_changed::insert":"text_changed::delete", - start, - length); - break; + case nsIAccessibleEvent::EVENT_PROPERTY_CHANGED: + return FireAtkPropChangedEvent(aEvent, atkObj); } return NS_OK; } +nsresult +nsAccessibleWrap::FireAtkStateChangeEvent(nsIAccessibleEvent *aEvent, + AtkObject *aObject) +{ + MAI_LOG_DEBUG(("\n\nReceived: EVENT_STATE_CHANGE\n")); + + nsCOMPtr event = + do_QueryInterface(aEvent); + NS_ENSURE_TRUE(event, NS_ERROR_FAILURE); + + PRUint32 state = 0; + event->GetState(&state); + + PRBool isExtra; + event->IsExtraState(&isExtra); + + PRBool isEnabled; + event->IsEnabled(&isEnabled); + + PRInt32 stateIndex = AtkStateMap::GetStateIndexFor(state); + if (stateIndex >= 0) { + const AtkStateMap *atkStateMap = isExtra ? gAtkStateMapExt : gAtkStateMap; + NS_ASSERTION(atkStateMap[stateIndex].stateMapEntryType != kNoSuchState, + "No such state"); + + if (atkStateMap[stateIndex].atkState != kNone) { + NS_ASSERTION(atkStateMap[stateIndex].stateMapEntryType != kNoStateChange, + "State changes should not fired for this state"); + + if (atkStateMap[stateIndex].stateMapEntryType == kMapOpposite) + isEnabled = !isEnabled; + + // Fire state change for first state if there is one to map + atk_object_notify_state_change(aObject, + atkStateMap[stateIndex].atkState, + isEnabled); + } + } + + return NS_OK; +} + +nsresult +nsAccessibleWrap::FireAtkTextChangedEvent(nsIAccessibleEvent *aEvent, + AtkObject *aObject) +{ + MAI_LOG_DEBUG(("\n\nReceived: EVENT_TEXT_CHANGED\n")); + + nsCOMPtr event = + do_QueryInterface(aEvent); + NS_ENSURE_TRUE(event, NS_ERROR_FAILURE); + + PRInt32 start = 0; + event->GetStart(&start); + + PRUint32 length = 0; + event->GetLength(&length); + + PRBool isInserted; + event->IsInserted(&isInserted); + + g_signal_emit_by_name (aObject, + isInserted ? \ + "text_changed::insert":"text_changed::delete", + start, + length); + + return NS_OK; +} + +nsresult +nsAccessibleWrap::FireAtkPropChangedEvent(nsIAccessibleEvent *aEvent, + AtkObject *aObject) +{ + MAI_LOG_DEBUG(("\n\nReceived: EVENT_PROPERTY_CHANGED\n")); + + AtkPropertyChange *pAtkPropChange; + AtkPropertyValues values = { NULL }; + nsAccessibleWrap *oldAccWrap = nsnull, *newAccWrap = nsnull; + + nsAccEvent *event = NS_REINTERPRET_CAST(nsAccEvent*, aEvent); + + pAtkPropChange = NS_REINTERPRET_CAST(AtkPropertyChange *, event->mEventData); + values.property_name = sAtkPropertyNameArray[pAtkPropChange->type]; + + NS_ASSERTION(pAtkPropChange, "Event needs event data"); + if (!pAtkPropChange) + return NS_OK; + + MAI_LOG_DEBUG(("\n\nthe type of EVENT_PROPERTY_CHANGED: %d\n\n", + pAtkPropChange->type)); + + switch (pAtkPropChange->type) { + case PROP_TABLE_CAPTION: + case PROP_TABLE_SUMMARY: + + if (pAtkPropChange->oldvalue) + oldAccWrap = NS_REINTERPRET_CAST(nsAccessibleWrap *, + pAtkPropChange->oldvalue); + + if (pAtkPropChange->newvalue) + newAccWrap = NS_REINTERPRET_CAST(nsAccessibleWrap *, + pAtkPropChange->newvalue); + + if (oldAccWrap && newAccWrap) { + g_value_init(&values.old_value, G_TYPE_POINTER); + g_value_set_pointer(&values.old_value, + oldAccWrap->GetAtkObject()); + g_value_init(&values.new_value, G_TYPE_POINTER); + g_value_set_pointer(&values.new_value, + newAccWrap->GetAtkObject()); + } + break; + + case PROP_TABLE_COLUMN_DESCRIPTION: + case PROP_TABLE_COLUMN_HEADER: + case PROP_TABLE_ROW_HEADER: + case PROP_TABLE_ROW_DESCRIPTION: + g_value_init(&values.new_value, G_TYPE_INT); + g_value_set_int(&values.new_value, + *NS_REINTERPRET_CAST(gint *, + pAtkPropChange->newvalue)); + break; + + //Perhaps need more cases in the future + default: + g_value_init (&values.old_value, G_TYPE_POINTER); + g_value_set_pointer (&values.old_value, pAtkPropChange->oldvalue); + g_value_init (&values.new_value, G_TYPE_POINTER); + g_value_set_pointer (&values.new_value, pAtkPropChange->newvalue); + } + + char *signal_name = g_strconcat("property_change::", + values.property_name, NULL); + g_signal_emit_by_name(aObject, signal_name, &values, NULL); + g_free (signal_name); + + return NS_OK; +} + diff --git a/accessible/src/atk/nsAccessibleWrap.h b/accessible/src/atk/nsAccessibleWrap.h index 0e98ed90dbc..82e27755e47 100644 --- a/accessible/src/atk/nsAccessibleWrap.h +++ b/accessible/src/atk/nsAccessibleWrap.h @@ -53,6 +53,29 @@ struct _AtkObject; typedef struct _AtkObject AtkObject; +enum AtkProperty { + PROP_0, // gobject convention + PROP_NAME, + PROP_DESCRIPTION, + PROP_PARENT, // ancestry has changed + PROP_ROLE, + PROP_LAYER, + PROP_MDI_ZORDER, + PROP_TABLE_CAPTION, + PROP_TABLE_COLUMN_DESCRIPTION, + PROP_TABLE_COLUMN_HEADER, + PROP_TABLE_ROW_DESCRIPTION, + PROP_TABLE_ROW_HEADER, + PROP_TABLE_SUMMARY, + PROP_LAST // gobject convention +}; + +struct AtkPropertyChange { + PRInt32 type; // property type as listed above + void *oldvalue; + void *newvalue; +}; + /** * nsAccessibleWrap, and its descendents in atk directory provide the * implementation of AtkObject. @@ -85,6 +108,13 @@ public: } protected: + nsresult FireAtkStateChangeEvent(nsIAccessibleEvent *aEvent, + AtkObject *aObject); + nsresult FireAtkTextChangedEvent(nsIAccessibleEvent *aEvent, + AtkObject *aObject); + nsresult FireAtkPropChangedEvent(nsIAccessibleEvent *aEvent, + AtkObject *aObject); + AtkObject *mAtkObject; private: diff --git a/accessible/src/atk/nsDocAccessibleWrap.cpp b/accessible/src/atk/nsDocAccessibleWrap.cpp index c024d1e839b..8ca5c24bf36 100644 --- a/accessible/src/atk/nsDocAccessibleWrap.cpp +++ b/accessible/src/atk/nsDocAccessibleWrap.cpp @@ -55,26 +55,6 @@ //----- nsDocAccessibleWrap ----- -/* - * Must keep sychronization with enumerate AtkProperty in - * accessible/src/base/nsAccessibleEventData.h - */ -static char * sAtkPropertyNameArray[PROP_LAST] = { - 0, - "accessible-name", - "accessible-description", - "accessible-parent", - "accessible-role", - "accessible-layer", - "accessible-mdi-zorder", - "accessible-table-caption", - "accessible-table-column-description", - "accessible-table-column-header", - "accessible-table-row-description", - "accessible-table-row-header", - "accessible-table-summary" -}; - nsDocAccessibleWrap::nsDocAccessibleWrap(nsIDOMNode *aDOMNode, nsIWeakReference *aShell): nsDocAccessible(aDOMNode, aShell), mActivated(PR_FALSE) @@ -107,7 +87,6 @@ NS_IMETHODIMP nsDocAccessibleWrap::FireToolkitEvent(PRUint32 aEvent, return NS_OK; } - nsAccessibleWrap *oldAccWrap = nsnull, *newAccWrap = nsnull; AtkTableChange * pAtkTableChange = nsnull; switch (aEvent) { @@ -131,76 +110,6 @@ NS_IMETHODIMP nsDocAccessibleWrap::FireToolkitEvent(PRUint32 aEvent, } } break; - - /* - * Need handle each type of property change separately. - */ - case nsIAccessibleEvent::EVENT_PROPERTY_CHANGED : - { - AtkPropertyChange *pAtkPropChange; - AtkPropertyValues values = { NULL }; - - MAI_LOG_DEBUG(("\n\nReceived: EVENT_PROPERTY_CHANGED\n")); - NS_ASSERTION(aEventData, "Event needs event data"); - if (!aEventData) - break; - - pAtkPropChange = NS_REINTERPRET_CAST(AtkPropertyChange *, aEventData); - values.property_name = sAtkPropertyNameArray[pAtkPropChange->type]; - - MAI_LOG_DEBUG(("\n\nthe type of EVENT_PROPERTY_CHANGED: %d\n\n", - pAtkPropChange->type)); - - switch (pAtkPropChange->type) { - case PROP_TABLE_CAPTION: - case PROP_TABLE_SUMMARY: - - if (pAtkPropChange->oldvalue) - oldAccWrap = NS_REINTERPRET_CAST(nsAccessibleWrap *, - pAtkPropChange->oldvalue); - - if (pAtkPropChange->newvalue) - newAccWrap = NS_REINTERPRET_CAST(nsAccessibleWrap *, - pAtkPropChange->newvalue); - - if (oldAccWrap && newAccWrap) { - g_value_init(&values.old_value, G_TYPE_POINTER); - g_value_set_pointer(&values.old_value, - oldAccWrap->GetAtkObject()); - g_value_init(&values.new_value, G_TYPE_POINTER); - g_value_set_pointer(&values.new_value, - newAccWrap->GetAtkObject()); - rv = NS_OK; - } - break; - - case PROP_TABLE_COLUMN_DESCRIPTION: - case PROP_TABLE_COLUMN_HEADER: - case PROP_TABLE_ROW_HEADER: - case PROP_TABLE_ROW_DESCRIPTION: - g_value_init(&values.new_value, G_TYPE_INT); - g_value_set_int(&values.new_value, - *NS_REINTERPRET_CAST(gint *, - pAtkPropChange->newvalue)); - rv = NS_OK; - break; - - //Perhaps need more cases in the future - default: - g_value_init (&values.old_value, G_TYPE_POINTER); - g_value_set_pointer (&values.old_value, pAtkPropChange->oldvalue); - g_value_init (&values.new_value, G_TYPE_POINTER); - g_value_set_pointer (&values.new_value, pAtkPropChange->newvalue); - rv = NS_OK; - } - if (NS_SUCCEEDED(rv)) { - char *signal_name = g_strconcat("property_change::", - values.property_name, NULL); - g_signal_emit_by_name(atkObj, signal_name, &values, NULL); - g_free (signal_name); - } - } - break; case nsIAccessibleEvent::EVENT_SELECTION_CHANGED: MAI_LOG_DEBUG(("\n\nReceived: EVENT_SELECTION_CHANGED\n")); diff --git a/accessible/src/base/nsAccessibleEventData.h b/accessible/src/base/nsAccessibleEventData.h index a9b6218e441..b30a54d7059 100644 --- a/accessible/src/base/nsAccessibleEventData.h +++ b/accessible/src/base/nsAccessibleEventData.h @@ -63,6 +63,8 @@ private: nsCOMPtr mAccessible; nsCOMPtr mDOMNode; nsCOMPtr mDocAccessible; + +public: void *mEventData; }; @@ -111,29 +113,6 @@ private: // XXX todo: We might want to use XPCOM interfaces instead of structs // e.g., nsAccessibleTextChangeEvent: public nsIAccessibleTextChangeEvent -enum AtkProperty { - PROP_0, // gobject convention - PROP_NAME, - PROP_DESCRIPTION, - PROP_PARENT, // ancestry has changed - PROP_ROLE, - PROP_LAYER, - PROP_MDI_ZORDER, - PROP_TABLE_CAPTION, - PROP_TABLE_COLUMN_DESCRIPTION, - PROP_TABLE_COLUMN_HEADER, - PROP_TABLE_ROW_DESCRIPTION, - PROP_TABLE_ROW_HEADER, - PROP_TABLE_SUMMARY, - PROP_LAST // gobject convention -}; - -struct AtkPropertyChange { - PRInt32 type; // property type as listed above - void *oldvalue; - void *newvalue; -}; - struct AtkChildrenChange { PRInt32 index; // index of child in parent nsIAccessible *child;