diff --git a/mozilla/accessible/build/Makefile.in b/mozilla/accessible/build/Makefile.in index 5bb9f9a32d6..51018b71aca 100644 --- a/mozilla/accessible/build/Makefile.in +++ b/mozilla/accessible/build/Makefile.in @@ -66,6 +66,9 @@ EXTRA_DSO_LDOPTS = \ $(MOZ_COMPONENT_LIBS) \ $(NULL) +ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2) +EXTRA_DSO_LDOPTS += $(MOZ_GTK2_LIBS) +endif + include $(topsrcdir)/config/rules.mk - diff --git a/mozilla/accessible/src/atk/Makefile.in b/mozilla/accessible/src/atk/Makefile.in index a0b161e0d37..f9b1d842a38 100644 --- a/mozilla/accessible/src/atk/Makefile.in +++ b/mozilla/accessible/src/atk/Makefile.in @@ -69,6 +69,7 @@ CPPSRCS = \ nsAccessibleWrap.cpp \ nsDocAccessibleWrap.cpp \ nsRootAccessibleWrap.cpp \ + nsAppRootAccessible.cpp \ nsAccessibleText.cpp \ nsAccessibleHyperText.cpp \ nsHTMLFormControlAccessibleWrap.cpp \ @@ -91,15 +92,19 @@ EXPORTS = \ nsRootAccessibleWrap.h \ $(NULL) -# we don't want the shared lib, but we want to force the creation of a static lib. +# we want to force the creation of a static lib. FORCE_STATIC_LIB = 1 +EXTRA_DSO_LDOPTS += $(MOZ_GTK2_LIBS) + include $(topsrcdir)/config/rules.mk +CFLAGS += $(MOZ_GTK2_CFLAGS) +CXXFLAGS += $(MOZ_GTK2_CFLAGS) + LOCAL_INCLUDES += \ -I$(srcdir) \ -I$(srcdir)/../base \ -I$(srcdir)/../html \ -I$(srcdir)/../xul \ $(NULL) - diff --git a/mozilla/accessible/src/atk/nsAccessNodeWrap.h b/mozilla/accessible/src/atk/nsAccessNodeWrap.h index 92cc581afdc..f1c728db575 100644 --- a/mozilla/accessible/src/atk/nsAccessNodeWrap.h +++ b/mozilla/accessible/src/atk/nsAccessNodeWrap.h @@ -56,4 +56,3 @@ class nsAccessNodeWrap : public nsAccessNode }; #endif - diff --git a/mozilla/accessible/src/atk/nsAccessibleWrap.cpp b/mozilla/accessible/src/atk/nsAccessibleWrap.cpp index b721d97eb81..ed99830cff7 100644 --- a/mozilla/accessible/src/atk/nsAccessibleWrap.cpp +++ b/mozilla/accessible/src/atk/nsAccessibleWrap.cpp @@ -1,26 +1,29 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim:expandtab:shiftwidth=4:tabstop=4: + */ /* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * Version: NPL 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 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 - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. + * The Initial Developer of the Original Code is Sun Microsystems, Inc. + * Portions created by Sun Microsystems are Copyright (C) 2002 Sun + * Microsystems, Inc. All Rights Reserved. * - * Contributor(s): - * Original Author: Aaron Leventhal (aaronl@netscape.com) + * Original Author: Bolian Yin (bolian.yin@sun.com) + * + * Contributor(s): John Sun (john.sun@sun.com) * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -28,28 +31,567 @@ * 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 + * use your version of this file under the terms of the NPL, 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. + * the terms of any one of the NPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ -#include "nsAccessibleWrap.h" +#include +#include +#include -//----------------------------------------------------- -// construction -//----------------------------------------------------- -nsAccessibleWrap::nsAccessibleWrap(nsIDOMNode* aNode, nsIWeakReference *aShell): - nsAccessible(aNode, aShell) +#include "nsAccessibleWrap.h" +#include "nsString.h" + +/* MaiAtkObject */ + +#define MAI_TYPE_ATK_OBJECT (mai_atk_object_get_type ()) +#define MAI_ATK_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + MAI_TYPE_ATK_OBJECT, MaiAtkObject)) +#define MAI_ATK_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), \ + MAI_TYPE_ATK_OBJECT, \ + MaiAtkObjectClass)) +#define MAI_IS_ATK_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ + MAI_TYPE_ATK_OBJECT)) +#define MAI_IS_ATK_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), \ + MAI_TYPE_ATK_OBJECT)) +#define MAI_ATK_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + MAI_TYPE_ATK_OBJECT, \ + MaiAtkObjectClass)) + +//typedef struct _MaiAtkObject MaiAtkObject; +typedef struct _MaiAtkObjectClass MaiAtkObjectClass; + +/** + * This MaiAtkObject is a thin wrapper, in the MAI namespace, for AtkObject + */ + +struct _MaiAtkObject { + AtkObject parent; + + /* + * The nsAccessibleWrap whose properties and features are exported + * via this object instance. + */ + nsAccessibleWrap *accWrap; +}; + +struct _MaiAtkObjectClass +{ + AtkObjectClass parent_class; +}; + +GType mai_atk_object_get_type(void); + +#ifdef MAI_LOGGING +gint num_created_mai_object = 0; +gint num_deleted_mai_object = 0; +#endif + +static nsresult CheckMaiAtkObject(AtkObject *aAtkObj); + +G_BEGIN_DECLS +/* callbacks for MaiAtkObject */ +static void classInitCB(AtkObjectClass *aClass); +static void initializeCB(AtkObject *aAtkObj, gpointer aData); +static void finalizeCB(GObject *aObj); + +/* callbacks for AtkObject virtual functions */ +static const gchar* getNameCB (AtkObject *aAtkObj); +static const gchar* getDescriptionCB (AtkObject *aAtkObj); +static AtkRole getRoleCB(AtkObject *aAtkObj); +static AtkObject* getParentCB(AtkObject *aAtkObj); +static gint getChildCountCB(AtkObject *aAtkObj); +static AtkObject* refChildCB(AtkObject *aAtkObj, gint aChildIndex); +static gint getIndexInParentCB(AtkObject *aAtkObj); + +/* implemented by MaiWidget */ +//static AtkStateSet* refStateSetCB(AtkObject *aAtkObj); +//static AtkRole getRoleCB(AtkObject *aAtkObj); + +//static AtkRelationSet* refRelationSetCB(AtkObject *aAtkObj); +//static AtkLayer getLayerCB(AtkObject *aAtkObj); +//static gint getMdiZorderCB(AtkObject *aAtkObj); + +/* the missing atkobject virtual functions */ +/* + static void SetNameCB(AtkObject *aAtkObj, + const gchar *name); + static void SetDescriptionCB(AtkObject *aAtkObj, + const gchar *description); + static void SetParentCB(AtkObject *aAtkObj, + AtkObject *parent); + static void SetRoleCB(AtkObject *aAtkObj, + AtkRole role); + static guint ConnectPropertyChangeHandlerCB( + AtkObject *aObj, + AtkPropertyChangeHandler *handler); + static void RemovePropertyChangeHandlerCB( + AtkObject *aAtkObj, + guint handler_id); + static void InitializeCB(AtkObject *aAtkObj, + gpointer data); + static void ChildrenChangedCB(AtkObject *aAtkObj, + guint change_index, + gpointer changed_child); + static void FocusEventCB(AtkObject *aAtkObj, + gboolean focus_in); + static void PropertyChangeCB(AtkObject *aAtkObj, + AtkPropertyValues *values); + static void StateChangeCB(AtkObject *aAtkObj, + const gchar *name, + gboolean state_set); + static void VisibleDataChangedCB(AtkObject *aAtkObj); +*/ +G_END_DECLS + +static gpointer parent_class = NULL; + +GType +mai_atk_object_get_type(void) +{ + static GType type = 0; + + if (!type) { + static const GTypeInfo tinfo = { + sizeof(MaiAtkObjectClass), + (GBaseInitFunc)NULL, + (GBaseFinalizeFunc)NULL, + (GClassInitFunc)classInitCB, + (GClassFinalizeFunc)NULL, + NULL, /* class data */ + sizeof(MaiAtkObject), /* instance size */ + 0, /* nb preallocs */ + (GInstanceInitFunc)NULL, + NULL /* value table */ + }; + + type = g_type_register_static(ATK_TYPE_OBJECT, + "MaiAtkObject", &tinfo, GTypeFlags(0)); + } + return type; +} + +nsAccessibleWrap::nsAccessibleWrap(nsIDOMNode* aNode, + nsIWeakReference *aShell) + : nsAccessible(aNode, aShell), + mMaiAtkObject(nsnull) +{ +#ifdef MAI_LOGGING + num_created_mai_object++; +#endif + MAI_LOG_DEBUG(("==nsAccessibleWrap creating this=0x%x,total %d created\n", + (unsigned int)this, num_created_mai_object)); } -//----------------------------------------------------- -// destruction -//----------------------------------------------------- nsAccessibleWrap::~nsAccessibleWrap() { + +#ifdef MAI_LOGGING + num_deleted_mai_object++; +#endif + MAI_LOG_DEBUG(("==nsAccessibleWrap deleting this=0x%x, total %d deleted\n", + (unsigned int)this, num_deleted_mai_object)); + + if (mMaiAtkObject) { + mMaiAtkObject->accWrap = nsnull; + g_object_unref(mMaiAtkObject); + } } +AtkObject * +nsAccessibleWrap::GetAtkObject(void) +{ + if (mMaiAtkObject) + return ATK_OBJECT(mMaiAtkObject); + + CreateMaiInterfaces(); + mMaiAtkObject = (MaiAtkObject*) g_object_new(MAI_TYPE_ATK_OBJECT, NULL); + g_return_val_if_fail(mMaiAtkObject != NULL, NULL); + + atk_object_initialize(ATK_OBJECT(mMaiAtkObject), this); + ATK_OBJECT(mMaiAtkObject)->role = ATK_ROLE_INVALID; + ATK_OBJECT(mMaiAtkObject)->layer = ATK_LAYER_INVALID; + MAI_LOG_DEBUG(("nsAccessibleWrap: Create MaiAtkObject=%p for AccWrap=%p\n", + (void*)mMaiAtkObject, (void*)this)); + + return ATK_OBJECT(mMaiAtkObject); +} + +/* private */ +void +nsAccessibleWrap::CreateMaiInterfaces(void) +{ + return; +} + + +/* static functions for ATK callbacks */ +void +classInitCB(AtkObjectClass *aClass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS(aClass); + + parent_class = g_type_class_peek_parent(aClass); + + aClass->get_name = getNameCB; + aClass->get_description = getDescriptionCB; + aClass->get_parent = getParentCB; + aClass->get_n_children = getChildCountCB; + aClass->ref_child = refChildCB; + aClass->get_index_in_parent = getIndexInParentCB; + aClass->get_role = getRoleCB; + + aClass->initialize = initializeCB; + + gobject_class->finalize = finalizeCB; +} + +void +initializeCB(AtkObject *aAtkObj, gpointer aData) +{ + g_return_if_fail(MAI_IS_ATK_OBJECT(aAtkObj)); + g_return_if_fail(aData != NULL); + + /* call parent init function */ + /* AtkObjectClass has not a "initialize" function now, + * maybe it has later + */ + + if (ATK_OBJECT_CLASS(parent_class)->initialize) + ATK_OBJECT_CLASS(parent_class)->initialize(aAtkObj, aData); + + /* initialize object */ + MAI_ATK_OBJECT(aAtkObj)->accWrap = + NS_STATIC_CAST(nsAccessibleWrap*, aData); +} + +void +finalizeCB(GObject *aObj) +{ + if (!MAI_IS_ATK_OBJECT(aObj)) + return; + NS_ASSERTION(MAI_ATK_OBJECT(aObj)->accWrap == nsnull, "AccWrap NOT null"); + MAI_LOG_DEBUG(("====release MaiAtkObject=0x%x\n", (guint)aObj)); + + // call parent finalize function + // finalize of GObjectClass will unref the accessible parent if has + if (G_OBJECT_CLASS (parent_class)->finalize) + G_OBJECT_CLASS (parent_class)->finalize(aObj); +} + +const gchar * +getNameCB(AtkObject *aAtkObj) +{ + NS_ENSURE_SUCCESS(CheckMaiAtkObject(aAtkObj), nsnull); + + if (!aAtkObj->name) { + gchar default_name[] = "no name"; + gint len; + nsAutoString uniName; + + nsAccessibleWrap *accWrap = + NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap; + + /* nsIAccessible is responsible for the non-NULL name */ + nsresult rv = accWrap->GetAccName(uniName); + NS_ENSURE_SUCCESS(rv, nsnull); + len = uniName.Length(); + if (len > 0) { + atk_object_set_name(aAtkObj, + NS_ConvertUCS2toUTF8(uniName).get()); + } + else { + atk_object_set_name(aAtkObj, default_name); + } + } + return aAtkObj->name; +} + +const gchar * +getDescriptionCB(AtkObject *aAtkObj) +{ + NS_ENSURE_SUCCESS(CheckMaiAtkObject(aAtkObj), nsnull); + + if (!aAtkObj->description) { + gchar default_description[] = "no description"; + gint len; + nsAutoString uniDesc; + + nsAccessibleWrap *accWrap = + NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap; + + /* nsIAccessible is responsible for the non-NULL description */ + nsresult rv = accWrap->GetAccDescription(uniDesc); + NS_ENSURE_SUCCESS(rv, nsnull); + len = uniDesc.Length(); + if (len > 0) { + atk_object_set_description(aAtkObj, + NS_ConvertUCS2toUTF8(uniDesc).get()); + } + else { + atk_object_set_description(aAtkObj, default_description); + } + } + return aAtkObj->description; +} + +AtkRole +getRoleCB(AtkObject *aAtkObj) +{ + NS_ENSURE_SUCCESS(CheckMaiAtkObject(aAtkObj), ATK_ROLE_INVALID); + + if (aAtkObj->role == ATK_ROLE_INVALID) { + nsAccessibleWrap *accWrap = + NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap; + + PRUint32 accRole; + nsresult rv = accWrap->GetAccRole(&accRole); + NS_ENSURE_SUCCESS(rv, ATK_ROLE_INVALID); + + //the cross-platform Accessible object returns the same value for + //both "ATK_ROLE_MENU_ITEM" and "ATK_ROLE_MENU" + if (accRole == ATK_ROLE_MENU_ITEM) { + PRInt32 childCount = 0; + accWrap->GetAccChildCount(&childCount); + if (childCount > 0) + accRole = ATK_ROLE_MENU; + } + aAtkObj->role = NS_STATIC_CAST(AtkRole, accRole); + } + return aAtkObj->role; +} + +AtkObject * +getParentCB(AtkObject *aAtkObj) +{ + NS_ENSURE_SUCCESS(CheckMaiAtkObject(aAtkObj), nsnull); + nsAccessibleWrap *accWrap = + NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap; + + nsCOMPtr accParent; + nsresult rv = accWrap->GetAccParent(getter_AddRefs(accParent)); + if (NS_FAILED(rv) || !accParent) + return nsnull; + nsIAccessible *tmpAccParent = accParent; + nsAccessibleWrap *accWrapParent = NS_STATIC_CAST(nsAccessibleWrap *, + tmpAccParent); + + AtkObject *parentAtkObj = accWrapParent->GetAtkObject(); + if (parentAtkObj && !aAtkObj->accessible_parent) { + atk_object_set_parent(aAtkObj, parentAtkObj); + } + return parentAtkObj; +} + +gint +getChildCountCB(AtkObject *aAtkObj) +{ + NS_ENSURE_SUCCESS(CheckMaiAtkObject(aAtkObj), 0); + nsAccessibleWrap *accWrap = + NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap; + + PRInt32 count = 0; + accWrap->GetAccChildCount(&count); + return count; +} + +AtkObject * +refChildCB(AtkObject *aAtkObj, gint aChildIndex) +{ + NS_ENSURE_SUCCESS(CheckMaiAtkObject(aAtkObj), nsnull); + nsAccessibleWrap *accWrap = + NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap; + + nsresult rv; + nsCOMPtr accChild; + rv = accWrap->GetChildAt(aChildIndex, getter_AddRefs(accChild)); + + if (NS_FAILED(rv) || !accChild) + return nsnull; + + nsIAccessible *tmpAccChild = accChild; + nsAccessibleWrap *accWrapChild = + NS_STATIC_CAST(nsAccessibleWrap*, tmpAccChild); + + //this will addref parent + AtkObject *childAtkObj = accWrapChild->GetAtkObject(); + NS_ASSERTION(childAtkObj, "Fail to get AtkObj"); + if (!childAtkObj) + return nsnull; + atk_object_set_parent(childAtkObj, + accWrap->GetAtkObject()); + g_object_ref(childAtkObj); + return childAtkObj; +} + +gint +getIndexInParentCB(AtkObject *aAtkObj) +{ + NS_ENSURE_SUCCESS(CheckMaiAtkObject(aAtkObj), -1); + nsAccessibleWrap *accWrap = + NS_REINTERPRET_CAST(MaiAtkObject*, aAtkObj)->accWrap; + + // we use accId to decide two accessible objects are the same. + void *accId = nsnull; + NS_ENSURE_SUCCESS(accWrap->GetUniqueID(&accId), -1); + + nsCOMPtr accParent; + nsresult rv = accWrap->GetAccParent(getter_AddRefs(accParent)); + if (NS_FAILED(rv) || !accParent) + return -1; + + nsCOMPtr accChild; + nsCOMPtr accTmpChild; + accWrap->GetAccFirstChild(getter_AddRefs(accChild)); + + PRInt32 currentIndex = -1; + void *currentAccId = nsnull; + while (accChild) { + ++currentIndex; + nsCOMPtr accNode(do_QueryInterface(accChild)); + if (accNode) { + accNode->GetUniqueID(¤tAccId); + if (currentAccId == accId) + break; + } + accChild->GetAccNextSibling(getter_AddRefs(accTmpChild)); + accChild = accTmpChild; + } + return currentIndex; +} + +/****************************************************************************** +The following nsIAccessible states aren't translated, just ignored. + STATE_MIXED: For a three-state check box. + STATE_READONLY: The object is designated read-only. + STATE_HOTTRACKED: Means its appearance has changed to indicate mouse + over it. + STATE_DEFAULT: Represents the default button in a window. + STATE_FLOATING: Not supported yet. + STATE_MARQUEED: Indicate scrolling or moving text or graphics. + STATE_ANIMATED: + STATE_OFFSCREEN: Has no on-screen representation. + STATE_MOVEABLE: + STATE_SELFVOICING: The object has self-TTS. + STATE_LINKED: The object is formatted as a hyperlink. + STATE_TRAVERSE: The object is a hyperlink that has been visited. + STATE_EXTSELECTABLE: Indicates that an object extends its selectioin. + STATE_ALERT_LOW: Not supported yet. + STATE_ALERT_MEDIUM: Not supported yet. + STATE_ALERT_HIGH: Not supported yet. + STATE_PROTECTED: The object is a password-protected edit control. + STATE_HASPOPUP: Object displays a pop-up menu or window when invoked. + +Returned AtkStatusSet never contain the following AtkStates. + ATK_STATE_ARMED: Indicates that the object is armed. + ATK_STATE_DEFUNCT: Indicates the user interface object corresponding to + thus object no longer exists. + ATK_STATE_EDITABLE: Indicates the user can change the contents of the object. + ATK_STATE_HORIZONTAL:Indicates the orientation of this object is horizontal. + ATK_STATE_ICONIFIED: + ATK_STATE_OPAQUE: Indicates the object paints every pixel within its + rectangular region + ATK_STATE_STALE: The index associated with this object has changed since + the user accessed the object +******************************************************************************/ + +void +nsAccessibleWrap::TranslateStates(PRUint32 aAccState, AtkStateSet *state_set) +{ + g_return_if_fail(state_set); + + if (aAccState & nsIAccessible::STATE_SELECTED) + atk_state_set_add_state (state_set, ATK_STATE_SELECTED); + + if (aAccState & nsIAccessible::STATE_FOCUSED) + atk_state_set_add_state (state_set, ATK_STATE_FOCUSED); + + if (aAccState & nsIAccessible::STATE_PRESSED) + atk_state_set_add_state (state_set, ATK_STATE_PRESSED); + + if (aAccState & nsIAccessible::STATE_CHECKED) + atk_state_set_add_state (state_set, ATK_STATE_CHECKED); + + if (aAccState & nsIAccessible::STATE_EXPANDED) + atk_state_set_add_state (state_set, ATK_STATE_EXPANDED); + + if (aAccState & nsIAccessible::STATE_COLLAPSED) + atk_state_set_add_state (state_set, ATK_STATE_EXPANDABLE); + + // The control can't accept input at this time + if (aAccState & nsIAccessible::STATE_BUSY) + atk_state_set_add_state (state_set, ATK_STATE_BUSY); + + if (aAccState & nsIAccessible::STATE_FOCUSABLE) + atk_state_set_add_state (state_set, ATK_STATE_FOCUSABLE); + + if (!(aAccState & nsIAccessible::STATE_INVISIBLE)) + atk_state_set_add_state (state_set, ATK_STATE_VISIBLE); + + if (aAccState & nsIAccessible::STATE_SELECTABLE) + atk_state_set_add_state (state_set, ATK_STATE_SELECTABLE); + + if (aAccState & nsIAccessible::STATE_SIZEABLE) + atk_state_set_add_state (state_set, ATK_STATE_RESIZABLE); + + if (aAccState & nsIAccessible::STATE_MULTISELECTABLE) + atk_state_set_add_state (state_set, ATK_STATE_MULTISELECTABLE); + + if (!(aAccState & nsIAccessible::STATE_UNAVAILABLE)) + atk_state_set_add_state (state_set, ATK_STATE_ENABLED); + + // The following state is + // Extended state flags (for now non-MSAA, for Java and Gnome/ATK support) + // This is only the states that there isn't already a mapping for in MSAA + // See www.accessmozilla.org/article.php?sid=11 for information on the + // mappings between accessibility API state + if (aAccState & nsIAccessible::STATE_INVALID) + atk_state_set_add_state (state_set, ATK_STATE_INVALID); + + if (aAccState & nsIAccessible::STATE_ACTIVE) + atk_state_set_add_state (state_set, ATK_STATE_ACTIVE); + + if (aAccState & nsIAccessible::STATE_EXPANDABLE) + atk_state_set_add_state (state_set, ATK_STATE_EXPANDABLE); + + if (aAccState & nsIAccessible::STATE_MODAL) + atk_state_set_add_state (state_set, ATK_STATE_MODAL); + + if (aAccState & nsIAccessible::STATE_MULTI_LINE) + atk_state_set_add_state (state_set, ATK_STATE_MULTI_LINE); + + if (aAccState & nsIAccessible::STATE_SENSITIVE) + atk_state_set_add_state (state_set, ATK_STATE_SENSITIVE); + + if (aAccState & nsIAccessible::STATE_RESIZABLE) + atk_state_set_add_state (state_set, ATK_STATE_RESIZABLE); + + if (aAccState & nsIAccessible::STATE_SHOWING) + atk_state_set_add_state (state_set, ATK_STATE_SHOWING); + + if (aAccState & nsIAccessible::STATE_SINGLE_LINE) + atk_state_set_add_state (state_set, ATK_STATE_SINGLE_LINE); + + if (aAccState & nsIAccessible::STATE_TRANSIENT) + atk_state_set_add_state (state_set, ATK_STATE_TRANSIENT); + + if (aAccState & nsIAccessible::STATE_VERTICAL) + atk_state_set_add_state (state_set, ATK_STATE_VERTICAL); + +} + +nsresult +CheckMaiAtkObject(AtkObject *aAtkObj) +{ + NS_ENSURE_ARG(MAI_IS_ATK_OBJECT(aAtkObj)); + nsAccessibleWrap * tmpAccWrap = MAI_ATK_OBJECT(aAtkObj)->accWrap; + NS_ENSURE_TRUE(tmpAccWrap != nsnull, NS_ERROR_INVALID_POINTER); + NS_ENSURE_TRUE(tmpAccWrap->GetAtkObject() == aAtkObj, + NS_ERROR_FAILURE); + return NS_OK; +} diff --git a/mozilla/accessible/src/atk/nsAccessibleWrap.h b/mozilla/accessible/src/atk/nsAccessibleWrap.h index 58540c2bdf6..1d686dd7d78 100644 --- a/mozilla/accessible/src/atk/nsAccessibleWrap.h +++ b/mozilla/accessible/src/atk/nsAccessibleWrap.h @@ -1,26 +1,29 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim:expandtab:shiftwidth=4:tabstop=4: + */ /* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * Version: NPL 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 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 - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. + * The Initial Developer of the Original Code is Sun Microsystems, Inc. + * Portions created by Sun Microsystems are Copyright (C) 2002 Sun + * Microsystems, Inc. All Rights Reserved. * - * Contributor(s): - * Original Author: Aaron Leventhal (aaronl@netscape.com) + * Original Author: Bolian Yin (bolian.yin@sun.com) + * + * Contributor(s): John Sun (john.sun@sun.com) * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -28,29 +31,86 @@ * 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 + * use your version of this file under the terms of the NPL, 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. + * the terms of any one of the NPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ -/* For documentation of the accessibility architecture, - * see http://lxr.mozilla.org/seamonkey/source/accessible/accessible-docs.html - */ - -#ifndef _nsAccessibleWrap_H_ -#define _nsAccessibleWrap_H_ +#ifndef __NS_ACCESSIBLE_WRAP_H__ +#define __NS_ACCESSIBLE_WRAP_H__ #include "nsCOMPtr.h" #include "nsAccessible.h" -class nsAccessibleWrap : public nsAccessible +#include "prlog.h" + +extern PRLogModuleInfo *gMaiLog; + +#ifdef PR_LOGGING +#define MAI_LOGGING +#endif /* #ifdef PR_LOGGING */ + +#ifdef MAI_LOGGING +#define MAI_LOG(level, args) \ +PR_BEGIN_MACRO \ + if (!gMaiLog) { \ + gMaiLog = PR_NewLogModule("Mai"); \ + PR_ASSERT(gMaiLog); \ + } \ + PR_LOG(gMaiLog, (level), args); \ +PR_END_MACRO +#else +#define MAI_LOG(level, args) +#endif + +#define MAI_LOG_DEBUG(args) MAI_LOG(PR_LOG_DEBUG, args) +#define MAI_LOG_WARNING(args) MAI_LOG(PR_LOG_WARNING, args) +#define MAI_LOG_ERROR(args) MAI_LOG(PR_LOG_ERROR, args) + +struct _AtkObject; +struct _AtkStateSet; +struct _MaiAtkObject; +struct _GHashTable; + +typedef struct _AtkObject AtkObject; +typedef struct _AtkStateSet AtkStateSet; +typedef struct _MaiAtkObject MaiAtkObject; +typedef struct _GHashTable GHashTable; + +/** + * nsAccessibleWrap, and its descendents in atk directory provide the + * implementation of AtkObject. + */ + +class nsAccessibleWrap: public nsAccessible { - public: // construction, destruction +public: nsAccessibleWrap(nsIDOMNode*, nsIWeakReference *aShell); virtual ~nsAccessibleWrap(); + +#ifdef MAI_LOGGING + virtual void DumpnsAccessibleWrapInfo(int aDepth) {} +#endif + +public: + virtual AtkObject *GetAtkObject(void); + + static void TranslateStates(PRUint32 aAccState, + AtkStateSet *state_set); +protected: + MaiAtkObject *mMaiAtkObject; + +private: + void CreateMaiInterfaces(void); + }; +#ifdef MAI_LOGGING +extern PRInt32 num_created_mai_object; +extern PRInt32 num_deleted_mai_object; #endif + +#endif /* __NS_ACCESSIBLE_WRAP_H__ */ diff --git a/mozilla/accessible/src/atk/nsAppRootAccessible.cpp b/mozilla/accessible/src/atk/nsAppRootAccessible.cpp new file mode 100644 index 00000000000..076048b1f50 --- /dev/null +++ b/mozilla/accessible/src/atk/nsAppRootAccessible.cpp @@ -0,0 +1,632 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim:expandtab:shiftwidth=4:tabstop=4: + */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 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 Sun Microsystems, Inc. + * Portions created by Sun Microsystems are Copyright (C) 2002 Sun + * Microsystems, Inc. All Rights Reserved. + * + * Original Author: Bolian Yin (bolian.yin@sun.com) + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsCOMPtr.h" +#include "nsAppRootAccessible.h" +#include "prlink.h" + +#include + +/* maiutil */ + +static guint mai_util_add_global_event_listener(GSignalEmissionHook listener, + const gchar *event_type); +static void mai_util_remove_global_event_listener(guint remove_listener); +static AtkObject *mai_util_get_root(void); +static G_CONST_RETURN gchar *mai_util_get_toolkit_name(void); +static G_CONST_RETURN gchar *mai_util_get_toolkit_version(void); + + +/* Misc */ + +static void _listener_info_destroy(gpointer data); +static guint add_listener (GSignalEmissionHook listener, + const gchar *object_type, + const gchar *signal, + const gchar *hook_data); + +static GHashTable *listener_list = NULL; +static gint listener_idx = 1; + +typedef struct _MaiUtilListenerInfo MaiUtilListenerInfo; + + +#define MAI_TYPE_UTIL (mai_util_get_type ()) +#define MAI_UTIL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + MAI_TYPE_UTIL, MaiUtil)) +#define MAI_UTIL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), \ + MAI_TYPE_UTIL, MaiUtilClass)) +#define MAI_IS_UTIL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ + MAI_TYPE_UTIL)) +#define MAI_IS_UTIL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), \ + MAI_TYPE_UTIL)) +#define MAI_UTIL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + MAI_TYPE_UTIL, MaiUtilClass)) + +typedef struct _MaiUtil MaiUtil; +typedef struct _MaiUtilClass MaiUtilClass; + +G_BEGIN_DECLS +typedef void (*GnomeAccessibilityInit) (void); +typedef void (*GnomeAccessibilityShutdown) (void); +G_END_DECLS + +struct _MaiUtil +{ + AtkUtil parent; + GList *listener_list; +}; + +struct GnomeAccessibilityModule +{ + const char *libName; + PRLibrary *lib; + const char *initName; + GnomeAccessibilityInit init; + const char *shutdownName; + GnomeAccessibilityShutdown shutdown; +}; + +GType mai_util_get_type (void); +static void mai_util_class_init(MaiUtilClass *klass); + +struct _MaiUtilClass +{ + AtkUtilClass parent_class; +}; + +/* supporting */ +PRLogModuleInfo *gMaiLog = NULL; + +#define MAI_VERSION "0.0.6" +#define MAI_NAME "mozilla" + +struct _MaiUtilListenerInfo +{ + gint key; + guint signal_id; + gulong hook_id; +}; + +static GnomeAccessibilityModule sAtkBridge = { + "libatk-bridge.so", NULL, + "gnome_accessibility_module_init", NULL, + "gnome_accessibility_module_shutdown", NULL, +}; + +GType +mai_util_get_type(void) +{ + static GType type = 0; + + if (!type) { + static const GTypeInfo tinfo = { + sizeof(MaiUtilClass), + (GBaseInitFunc) NULL, /* base init */ + (GBaseFinalizeFunc) NULL, /* base finalize */ + (GClassInitFunc) mai_util_class_init, /* class init */ + (GClassFinalizeFunc) NULL, /* class finalize */ + NULL, /* class data */ + sizeof(MaiUtil), /* instance size */ + 0, /* nb preallocs */ + (GInstanceInitFunc) NULL, /* instance init */ + NULL /* value table */ + }; + + type = g_type_register_static(ATK_TYPE_UTIL, + "MaiUtil", &tinfo, GTypeFlags(0)); + } + return type; +} + +/* intialize the the atk interface (function pointers) with MAI implementation. + * When atk bridge get loaded, these interface can be used. + */ +static void +mai_util_class_init(MaiUtilClass *klass) +{ + AtkUtilClass *atk_class; + gpointer data; + + data = g_type_class_peek(ATK_TYPE_UTIL); + atk_class = ATK_UTIL_CLASS(data); + + atk_class->add_global_event_listener = + mai_util_add_global_event_listener; + atk_class->remove_global_event_listener = + mai_util_remove_global_event_listener; + /* + atk_class->add_key_event_listener = + mai_util_add_key_event_listener; + atk_class->remove_key_event_listener = + mai_util_remove_key_event_listener; + */ + atk_class->get_root = mai_util_get_root; + atk_class->get_toolkit_name = mai_util_get_toolkit_name; + atk_class->get_toolkit_version = mai_util_get_toolkit_version; + + listener_list = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, + _listener_info_destroy); +} + +static guint +mai_util_add_global_event_listener(GSignalEmissionHook listener, + const gchar *event_type) +{ + guint rc = 0; + gchar **split_string; + + split_string = g_strsplit (event_type, ":", 3); + + if (split_string) { + if (!strcmp ("window", split_string[0])) { + /* ??? + static gboolean initialized = FALSE; + + if (!initialized) { + do_window_event_initialization (); + initialized = TRUE; + } + rc = add_listener (listener, "MaiWindow", + split_string[1], event_type); + */ + } + else { + rc = add_listener (listener, split_string[1], split_string[2], + event_type); + } + } + return rc; +} + +static void +mai_util_remove_global_event_listener(guint remove_listener) +{ + if (remove_listener > 0) { + MaiUtilListenerInfo *listener_info; + gint tmp_idx = remove_listener; + + listener_info = (MaiUtilListenerInfo *) + g_hash_table_lookup(listener_list, &tmp_idx); + + if (listener_info != NULL) { + /* Hook id of 0 and signal id of 0 are invalid */ + if (listener_info->hook_id != 0 && listener_info->signal_id != 0) { + /* Remove the emission hook */ + g_signal_remove_emission_hook(listener_info->signal_id, + listener_info->hook_id); + + /* Remove the element from the hash */ + g_hash_table_remove(listener_list, &tmp_idx); + } + else { + /* do not use g_warning with such complex format args, */ + /* Forte CC can not preprocess it correctly */ + g_log((gchar *)0, G_LOG_LEVEL_WARNING, + "Invalid listener hook_id %ld or signal_id %d\n", + listener_info->hook_id, listener_info->signal_id); + + } + } + else { + /* do not use g_warning with such complex format args, */ + /* Forte CC can not preprocess it correctly */ + g_log((gchar *)0, G_LOG_LEVEL_WARNING, + "No listener with the specified listener id %d", + remove_listener); + } + } + else { + g_warning("Invalid listener_id %d", remove_listener); + } +} + +AtkObject * +mai_util_get_root(void) +{ + nsAppRootAccessible *root = nsAppRootAccessible::Create(); + + if (!root) + return nsnull; + return root->GetAtkObject(); +} + +G_CONST_RETURN gchar * +mai_util_get_toolkit_name(void) +{ + return MAI_NAME; +} + +G_CONST_RETURN gchar * +mai_util_get_toolkit_version(void) +{ + return MAI_VERSION; +} + +void +_listener_info_destroy(gpointer data) +{ + g_free(data); +} + +guint +add_listener (GSignalEmissionHook listener, + const gchar *object_type, + const gchar *signal, + const gchar *hook_data) +{ + GType type; + guint signal_id; + gint rc = 0; + + type = g_type_from_name(object_type); + if (type) { + signal_id = g_signal_lookup(signal, type); + if (signal_id > 0) { + MaiUtilListenerInfo *listener_info; + + rc = listener_idx; + + listener_info = (MaiUtilListenerInfo *) + g_malloc(sizeof(MaiUtilListenerInfo)); + listener_info->key = listener_idx; + listener_info->hook_id = + g_signal_add_emission_hook(signal_id, 0, listener, + g_strdup(hook_data), + (GDestroyNotify)g_free); + listener_info->signal_id = signal_id; + + g_hash_table_insert(listener_list, &(listener_info->key), + listener_info); + listener_idx++; + } + else { + g_warning("Invalid signal type %s\n", signal); + } + } + else { + g_warning("Invalid object type %s\n", object_type); + } + return rc; +} + + + + +// currently support one child +nsRootAccessibleWrap *sOnlyChild = nsnull; + +static nsresult LoadGtkModule(GnomeAccessibilityModule& aModule); + +nsAppRootAccessible::nsAppRootAccessible(): + nsAccessibleWrap(nsnull, nsnull), + mChildren(nsnull), + mInitialized(PR_FALSE) +{ + MAI_LOG_DEBUG(("======Create AppRootAcc=%p\n", (void*)this)); +} + +nsAppRootAccessible::~nsAppRootAccessible() +{ +} + +/* virtual functions */ + +/* +#ifdef MAI_LOGGING +void +nsAppRootAccessible::DumpMaiObjectInfo(int aDepth) +{ + --aDepth; + if (aDepth < 0) + return; + g_print("nsAppRootAccessible: this=0x%x, aDepth=%d, type=%s\n", + (unsigned int)this, aDepth, "nsAppRootAccessible"); + gint nChild = GetChildCount(); + g_print("#child=%d
\n", nChild); + g_print("Iface num: 1=component, 2=action, 3=value, 4=editabletext," + "5=hyperlink, 6=hypertext, 7=selection, 8=table, 9=text\n"); + g_print("
    \n"); + + MaiObject *maiChild; + for (int childIndex = 0; childIndex < nChild; childIndex++) { + maiChild = RefChild(childIndex); + if (maiChild) { + g_print("
  • "); + maiChild->DumpMaiObjectInfo(aDepth); + } + } + g_print("
\n"); + g_print("End of nsAppRootAccessible: this=0x%x, type=%s\n
", + (unsigned int)this, "nsAppRootAccessible"); +} +#endif +*/ + +void +nsAppRootAccessible::Initialize(void) +{ +} + +NS_IMETHODIMP nsAppRootAccessible::Init() +{ + NS_ASSERTION((mInitialized == FALSE), "Init AppRoot Again!!"); + if (mInitialized == PR_TRUE) + return NS_OK; + + MAI_LOG_DEBUG(("Mozilla Atk Implementation initializing\n")); + g_type_init(); + // Initialize the MAI Utility class + g_type_class_unref(g_type_class_ref(MAI_TYPE_UTIL)); + + // load and initialize atk-bridge library + nsresult rv = LoadGtkModule(sAtkBridge); + if (NS_SUCCEEDED(rv)) { + // init atk-bridge + (*sAtkBridge.init)(); + } + else + MAI_LOG_DEBUG(("Fail to load lib: %s\n", sAtkBridge.libName)); + + rv = NS_NewArray(getter_AddRefs(mChildren)); + return rv; +} + +NS_IMETHODIMP nsAppRootAccessible::Shutdown() +{ + nsAppRootAccessible *root = nsAppRootAccessible::Create(); + if (root) + NS_IF_RELEASE(root); + if (sAtkBridge.lib) { + if (sAtkBridge.shutdown) + (*sAtkBridge.shutdown)(); + //Not unload atk-bridge library + //an exit function registered will take care of it + sAtkBridge.lib = NULL; + sAtkBridge.init = NULL; + sAtkBridge.shutdown = NULL; + } + return NS_OK; +} + +NS_IMETHODIMP nsAppRootAccessible::GetAccName(nsAString& _retval) +{ + _retval = NS_LITERAL_STRING("Mozilla"); + return NS_OK; +} + +NS_IMETHODIMP nsAppRootAccessible::GetAccDescription(nsAString& aDescription) +{ + aDescription = NS_LITERAL_STRING("Mozilla Root Accessible"); + return NS_OK; +} + +NS_IMETHODIMP nsAppRootAccessible::GetAccRole(PRUint32 *aAccRole) +{ + *aAccRole = ROLE_APPLICATION; + return NS_OK; +} + +NS_IMETHODIMP nsAppRootAccessible::GetAccParent(nsIAccessible ** aAccParent) +{ + *aAccParent = nsnull; + return NS_OK; +} + +NS_IMETHODIMP nsAppRootAccessible::GetChildAt(PRInt32 aChildNum, + nsIAccessible **aChild) +{ + nsCOMPtr childWeakRef; + *aChild = nsnull; + nsresult rv = NS_OK; + rv = mChildren->QueryElementAt(aChildNum, NS_GET_IID(nsIWeakReference), + getter_AddRefs(childWeakRef)); + if (childWeakRef) { + MAI_LOG_DEBUG(("GetChildAt(%d), has weak ref\n", aChildNum)); + nsCOMPtr childAcc = do_QueryReferent(childWeakRef); + if (childAcc) { + MAI_LOG_DEBUG(("GetChildAt(%d), has Acc Child ref\n", aChildNum)); + NS_IF_ADDREF(*aChild = childAcc); + } + else + MAI_LOG_DEBUG(("GetChildAt(%d), NOT has Acc Child ref\n", + aChildNum)); + + } + else + MAI_LOG_DEBUG(("GetChildAt(%d), NOT has weak ref\n", aChildNum)); + return rv; +} + +NS_IMETHODIMP nsAppRootAccessible::GetAccChildCount(PRInt32 *aAccChildCount) +{ + PRUint32 count = 0; + nsresult rv = NS_OK; + if (mChildren) + rv = mChildren->GetLength(&count); + if (NS_SUCCEEDED(rv)) { + MAI_LOG_DEBUG(("\nGet Acc Child OK, count=%d\n", count)); + } + else + MAI_LOG_DEBUG(("\nGet Acc Child Failed, count=%d\n", count)); + + *aAccChildCount = NS_STATIC_CAST(PRInt32, count); + return rv; +} + +NS_IMETHODIMP nsAppRootAccessible::GetAccFirstChild(nsIAccessible * *aAccFirstChild) +{ + nsCOMPtr firstChild; + *aAccFirstChild = nsnull; + nsresult rv = NS_OK; + rv = mChildren->QueryElementAt(0, NS_GET_IID(nsIAccessible), + getter_AddRefs(firstChild)); + if (firstChild) + NS_IF_ADDREF(*aAccFirstChild = firstChild); + return rv; +} + +NS_IMETHODIMP nsAppRootAccessible::GetAccNextSibling(nsIAccessible * *aAccNextSibling) +{ + *aAccNextSibling = nsnull; + return NS_OK; +} + +NS_IMETHODIMP nsAppRootAccessible::GetAccPreviousSibling(nsIAccessible * *aAccPreviousSibling) +{ + *aAccPreviousSibling = nsnull; + return NS_OK; +} + +nsresult +nsAppRootAccessible::AddRootAccessible(nsRootAccessibleWrap *aRootAccWrap) +{ + NS_ENSURE_ARG_POINTER(aRootAccWrap); + + nsresult rv = NS_ERROR_FAILURE; + + // weak reference + rv = mChildren->AppendElement(NS_STATIC_CAST(nsISupports *, + NS_STATIC_CAST(nsIAccessibleDocument*, aRootAccWrap)), + PR_TRUE); + PRUint32 count = 0; + mChildren->GetLength(&count); + + if (NS_SUCCEEDED(rv)) { + MAI_LOG_DEBUG(("\nAdd RootAcc=%p OK, count=%d\n", + (void*)aRootAccWrap, count)); + } + else + MAI_LOG_DEBUG(("\nAdd RootAcc=%p Failed, count=%d\n", + (void*)aRootAccWrap, count)); + + return rv; +} + +nsresult +nsAppRootAccessible::RemoveRootAccessible(nsRootAccessibleWrap *aRootAccWrap) +{ + NS_ENSURE_ARG_POINTER(aRootAccWrap); + PRUint32 index = 0; + nsresult rv = mChildren->IndexOf(0, NS_STATIC_CAST(nsISupports *, + NS_STATIC_CAST(nsIAccessibleDocument*, aRootAccWrap)), + &index); + if (NS_SUCCEEDED(rv)) + rv = mChildren->RemoveElementAt(index); + + MAI_LOG_DEBUG(("\nRemove RootAcc=%p\n", (void*)aRootAccWrap)); + return rv; +} + +nsAppRootAccessible * +nsAppRootAccessible::Create() +{ + static nsAppRootAccessible *sAppRoot = nsnull; + if (!sAppRoot) { + sAppRoot = new nsAppRootAccessible(); + NS_ASSERTION(sAppRoot, "OUT OF MEMORY"); + if (sAppRoot) { + if (NS_FAILED(sAppRoot->Init())) { + delete sAppRoot; + sAppRoot = nsnull; + } + else + NS_IF_ADDREF(sAppRoot); + } + } + return sAppRoot; +} + +static nsresult +LoadGtkModule(GnomeAccessibilityModule& aModule) +{ + NS_ENSURE_ARG(aModule.libName); + + if (!(aModule.lib = PR_LoadLibrary(aModule.libName))) { + + MAI_LOG_DEBUG(("Fail to load lib: %s in default path\n", aModule.libName)); + + //try to load the module with "gtk-2.0/modules" appended + char *curLibPath = PR_GetLibraryPath(); + nsCAutoString libPath(curLibPath); + MAI_LOG_DEBUG(("Current Lib path=%s\n", curLibPath)); + PR_FreeLibraryName(curLibPath); + + PRInt16 loc1 = 0, loc2 = 0; + PRInt16 subLen = 0; + while (loc2 >= 0) { + loc2 = libPath.FindChar(':', loc1); + if (loc2 < 0) + subLen = libPath.Length() - loc1; + else + subLen = loc2 - loc1; + nsCAutoString sub(Substring(libPath, loc1, subLen)); + sub.Append("/gtk-2.0/modules/"); + sub.Append(aModule.libName); + aModule.lib = PR_LoadLibrary(sub.get()); + if (aModule.lib) { + MAI_LOG_DEBUG(("Ok, load %s from %s\n", aModule.libName, sub.get())); + break; + } + loc1 = loc2+1; + } + if (!aModule.lib) { + MAI_LOG_DEBUG(("Fail to load %s\n", aModule.libName)); + return NS_ERROR_FAILURE; + } + } + + //we have loaded the library, try to get the function ptrs + if (!(aModule.init = PR_FindFunctionSymbol(aModule.lib, + aModule.initName)) || + !(aModule.shutdown = PR_FindFunctionSymbol(aModule.lib, + aModule.shutdownName))) { + + //fail, :( + MAI_LOG_DEBUG(("Fail to find symbol %s in %s", + aModule.init ? aModule.shutdownName : aModule.initName, + aModule.libName)); + PR_UnloadLibrary(aModule.lib); + aModule.lib = NULL; + return NS_ERROR_FAILURE; + } + return NS_OK; +} diff --git a/mozilla/accessible/src/atk/nsAppRootAccessible.h b/mozilla/accessible/src/atk/nsAppRootAccessible.h new file mode 100644 index 00000000000..d7c90257398 --- /dev/null +++ b/mozilla/accessible/src/atk/nsAppRootAccessible.h @@ -0,0 +1,102 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim:expandtab:shiftwidth=4:tabstop=4: + */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 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 Sun Microsystems, Inc. + * Portions created by Sun Microsystems are Copyright (C) 2002 Sun + * Microsystems, Inc. All Rights Reserved. + * + * Original Author: Bolian Yin (bolian.yin@sun.com) + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef __NS_APP_ROOT_ACCESSIBLE_H__ +#define __NS_APP_ROOT_ACCESSIBLE_H__ + +#include "nsArray.h" +#include "nsIAccessibleDocument.h" +#include "nsAccessibilityService.h" +#include "nsAccessibleWrap.h" +#include "nsRootAccessibleWrap.h" + +#define MAI_TYPE_APP_ROOT (MAI_TYPE_ATK_OBJECT) + +/* nsAppRootAccessible is for the whole application of Mozilla. + * Only one instance of nsAppRootAccessible exists for one Mozilla instance. + * And this one should be created when Mozilla Startup (if accessibility + * feature has been enabled) and destroyed when Mozilla Shutdown. + * + * All the accessibility objects for toplevel windows are direct children of + * the nsAppRootAccessible instance. + */ +class nsAppRootAccessible; +class nsAppRootAccessible: public nsAccessibleWrap +{ +public: + virtual ~nsAppRootAccessible(); +#ifdef MAI_LOGGING + // virtual void DumpMaiObjectInfo(int aDepth); +#endif + + static nsAppRootAccessible *Create(); + +public: + nsAppRootAccessible(); + + /* virtual functions from nsAccessibleNode */ + NS_IMETHOD Init(); + NS_IMETHOD Shutdown(); + + /* virtual functions from nsAccessible */ + NS_IMETHOD GetAccName(nsAString & aAccName); + NS_IMETHOD GetAccDescription(nsAString & aAccDescription); + NS_IMETHOD GetAccRole(PRUint32 *aAccRole); + NS_IMETHOD GetAccParent(nsIAccessible * *aAccParent); + NS_IMETHOD GetAccNextSibling(nsIAccessible * *aAccNextSibling); + NS_IMETHOD GetAccPreviousSibling(nsIAccessible **aAccPreviousSibling); + NS_IMETHOD GetChildAt(PRInt32 aChildNum, nsIAccessible **aChild); + + NS_IMETHOD GetAccFirstChild(nsIAccessible * *aAccFirstChild); + NS_IMETHOD GetAccChildCount(PRInt32 *aAccChildCount); + + /* virtual functions from nsAccessibleWrap */ + virtual void Initialize(void); + // virtual void Finalize(void); + + nsresult AddRootAccessible(nsRootAccessibleWrap *aRootAccWrap); + nsresult RemoveRootAccessible(nsRootAccessibleWrap *aRootAccWrap); +private: + nsCOMPtr mChildren; + PRBool mInitialized; +}; + +#endif /* __NS_APP_ROOT_ACCESSIBLE_H__ */ diff --git a/mozilla/accessible/src/atk/nsDocAccessibleWrap.cpp b/mozilla/accessible/src/atk/nsDocAccessibleWrap.cpp index 8187c63c62d..f7711477433 100644 --- a/mozilla/accessible/src/atk/nsDocAccessibleWrap.cpp +++ b/mozilla/accessible/src/atk/nsDocAccessibleWrap.cpp @@ -1,26 +1,29 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim:expandtab:shiftwidth=4:tabstop=4: + */ /* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * Version: NPL 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 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 - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. + * The Initial Developer of the Original Code is Sun Microsystems, Inc. + * Portions created by Sun Microsystems are Copyright (C) 2002 Sun + * Microsystems, Inc. All Rights Reserved. * - * Contributor(s): - * Original Author: Aaron Leventhal (aaronl@netscape.com) + * Original Author: Bolian Yin (bolian.yin@sun.com) + * + * Contributor(s): John Sun (john.sun@sun.com) * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -28,19 +31,49 @@ * 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 + * use your version of this file under the terms of the NPL, 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. + * the terms of any one of the NPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ #include "nsDocAccessibleWrap.h" +#include "nsAccessibleEventData.h" +#include +#include +#include + +#define YBL_SHORT 1 //----- nsDocAccessibleWrap ----- -nsDocAccessibleWrap::nsDocAccessibleWrap(nsIDOMNode *aDOMNode, nsIWeakReference *aShell): +/* + * 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_value", + "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" +}; + +static AtkStateType TranslateAState(PRUint32 aAccState); + +nsDocAccessibleWrap::nsDocAccessibleWrap(nsIDOMNode *aDOMNode, + nsIWeakReference *aShell): nsDocAccessible(aDOMNode, aShell) { } @@ -49,8 +82,400 @@ nsDocAccessibleWrap::~nsDocAccessibleWrap() { } -NS_IMETHODIMP nsDocAccessibleWrap::FireToolkitEvent(PRUint32 aEvent, nsIAccessible* aAccessible, void* aData) +NS_IMETHODIMP nsDocAccessibleWrap::FireToolkitEvent(PRUint32 aEvent, + nsIAccessible* aAccessible, + void* aEventData) { - // XXX Bolian fire events from here - return NS_OK; + NS_ENSURE_ARG_POINTER(aAccessible); + + nsresult rv = NS_ERROR_FAILURE; +#ifdef YBL_SHORT + return rv; +#else + + nsAccessibleWrap *accWrap = + NS_STATIC_CAST(nsAccessibleWrap *, aAccessible); + MAI_LOG_DEBUG(("\n\nReceived event: aEvent=%u, obj=0x%x, data=0x%x \n", + aEvent, aAccessible, aEventData)); + + nsAccessibleWrap *oldAccWrap = nsnull, *newAccWrap = nsnull; + AtkTableChange * pAtkTableChange = nsnull; + + switch (aEvent) { + case nsIAccessibleEventReceiver::EVENT_FOCUS: + MAI_LOG_DEBUG(("\n\nReceived: EVENT_FOCUS\n")); + atk_focus_tracker_notify(accWrap->GetAtkObject()); + rv = NS_OK; + break; + + case nsIAccessibleEventReceiver::EVENT_STATE_CHANGE: + AtkStateChange *pAtkStateChange; + AtkStateType atkState; + + MAI_LOG_DEBUG(("\n\nReceived: EVENT_STATE_CHANGE\n")); + if (!aEventData) + break; + + pAtkStateChange = NS_REINTERPRET_CAST(AtkStateChange *, aEventData); + + switch (pAtkStateChange->state) { + case nsIAccessible::STATE_INVISIBLE: + atkState = ATK_STATE_VISIBLE; + break; + case nsIAccessible::STATE_UNAVAILABLE: + atkState = ATK_STATE_ENABLED; + break; + default: + atkState = TranslateAState(pAtkStateChange->state); + } + + atk_object_notify_state_change(accWrap->GetAtkObject(), + atkState, pAtkStateChange->enable); + rv = NS_OK; + break; + + /* + * More complex than I ever thought. + * Need handle them separately. + */ + case nsIAccessibleEventReceiver::EVENT_ATK_PROPERTY_CHANGE : + AtkPropertyChange *pAtkPropChange; + AtkPropertyValues values; + + MAI_LOG_DEBUG(("\n\nReceived: EVENT_ATK_PROPERTY_CHANGE\n")); + if (!aEventData) + break; + + pAtkPropChange = NS_REINTERPRET_CAST(AtkPropertyChange *, aEventData); + values.property_name = sAtkPropertyNameArray[pAtkPropChange->type]; + + MAI_LOG_DEBUG(("\n\nthe type of EVENT_ATK_PROPERTY_CHANGE: %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; + } + /* ??? YBL it is different now, can we still unref them */ + /* + if (oldAccWrap) + g_object_unref(oldAccWrap->GetAtkObject()); + if (newAccWrap) + g_object_unref(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)); + 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)) + g_signal_emit_by_name(accWrap->GetAtkObject(), + g_strconcat("property_change::", + values.property_name), + &values, NULL); + + break; + + case nsIAccessibleEventReceiver::EVENT_ATK_SELECTION_CHANGE: + MAI_LOG_DEBUG(("\n\nReceived: EVENT_ATK_SELECTION_CHANGE\n")); + g_signal_emit_by_name(accWrap->GetAtkObject(), + "selection_changed"); + rv = NS_OK; + break; + + case nsIAccessibleEventReceiver::EVENT_ATK_TEXT_CHANGE: + AtkTextChange *pAtkTextChange; + + MAI_LOG_DEBUG(("\n\nReceived: EVENT_ATK_TEXT_CHANGE\n")); + if (!aEventData) + break; + + pAtkTextChange = NS_REINTERPRET_CAST(AtkTextChange *, aEventData); + g_signal_emit_by_name (accWrap->GetAtkObject(), + pAtkTextChange->add ? \ + "text_changed::insert":"text_changed::delete", + pAtkTextChange->start, + pAtkTextChange->length); + rv = NS_OK; + break; + + case nsIAccessibleEventReceiver::EVENT_ATK_TEXT_SELECTION_CHANGE: + MAI_LOG_DEBUG(("\n\nReceived: EVENT_ATK_TEXT_SELECTION_CHANGE\n")); + g_signal_emit_by_name(accWrap->GetAtkObject(), + "text_selection_changed"); + rv = NS_OK; + break; + + case nsIAccessibleEventReceiver::EVENT_ATK_TEXT_CARET_MOVE: + MAI_LOG_DEBUG(("\n\nReceived: EVENT_ATK_TEXT_CARET_MOVE\n")); + if (!aEventData) + break; + + MAI_LOG_DEBUG(("\n\nCaret postion: %d", *(gint *)aEventData )); + g_signal_emit_by_name(accWrap->GetAtkObject(), + "text_caret_moved", + // Curent caret position + *(gint *)aEventData); + rv = NS_OK; + break; + + case nsIAccessibleEventReceiver::EVENT_ATK_TABLE_MODEL_CHANGE: + MAI_LOG_DEBUG(("\n\nReceived: EVENT_ATK_TABLE_MODEL_CHANGE\n")); + g_signal_emit_by_name(accWrap->GetAtkObject(), + "model_changed"); + rv = NS_OK; + break; + + case nsIAccessibleEventReceiver::EVENT_ATK_TABLE_ROW_INSERT: + MAI_LOG_DEBUG(("\n\nReceived: EVENT_ATK_TABLE_ROW_INSERT\n")); + if (!aEventData) + break; + + pAtkTableChange = NS_REINTERPRET_CAST(AtkTableChange *, aEventData); + + g_signal_emit_by_name(accWrap->GetAtkObject(), + "row_inserted", + // After which the rows are inserted + pAtkTableChange->index, + // The number of the inserted + pAtkTableChange->count); + rv = NS_OK; + break; + + case nsIAccessibleEventReceiver::EVENT_ATK_TABLE_ROW_DELETE: + MAI_LOG_DEBUG(("\n\nReceived: EVENT_ATK_TABLE_ROW_DELETE\n")); + if (!aEventData) + break; + + pAtkTableChange = NS_REINTERPRET_CAST(AtkTableChange *, aEventData); + + g_signal_emit_by_name(accWrap->GetAtkObject(), + "row_deleted", + // After which the rows are deleted + pAtkTableChange->index, + // The number of the deleted + pAtkTableChange->count); + rv = NS_OK; + break; + + case nsIAccessibleEventReceiver::EVENT_ATK_TABLE_ROW_REORDER: + MAI_LOG_DEBUG(("\n\nReceived: EVENT_ATK_TABLE_ROW_REORDER\n")); + g_signal_emit_by_name(accWrap->GetAtkObject(), + "row_reordered"); + rv = NS_OK; + break; + + case nsIAccessibleEventReceiver::EVENT_ATK_TABLE_COLUMN_INSERT: + MAI_LOG_DEBUG(("\n\nReceived: EVENT_ATK_TABLE_COLUMN_INSERT\n")); + if (!aEventData) + break; + + pAtkTableChange = NS_REINTERPRET_CAST(AtkTableChange *, aEventData); + + g_signal_emit_by_name(accWrap->GetAtkObject(), + "column_inserted", + // After which the columns are inserted + pAtkTableChange->index, + // The number of the inserted + pAtkTableChange->count); + rv = NS_OK; + break; + + case nsIAccessibleEventReceiver::EVENT_ATK_TABLE_COLUMN_DELETE: + MAI_LOG_DEBUG(("\n\nReceived: EVENT_ATK_TABLE_COLUMN_DELETE\n")); + if (!aEventData) + break; + + pAtkTableChange = NS_REINTERPRET_CAST(AtkTableChange *, aEventData); + + g_signal_emit_by_name(accWrap->GetAtkObject(), + "column_deleted", + // After which the columns are deleted + pAtkTableChange->index, + // The number of the deleted + pAtkTableChange->count); + rv = NS_OK; + break; + + case nsIAccessibleEventReceiver::EVENT_ATK_TABLE_COLUMN_REORDER: + MAI_LOG_DEBUG(("\n\nReceived: EVENT_ATK_TABLE_COLUMN_REORDER\n")); + g_signal_emit_by_name(accWrap->GetAtkObject(), + "column_reordered"); + rv = NS_OK; + break; + + case nsIAccessibleEventReceiver::EVENT_ATK_VISIBLE_DATA_CHANGE: + MAI_LOG_DEBUG(("\n\nReceived: EVENT_ATK_VISIBLE_DATA_CHANGE\n")); + g_signal_emit_by_name(accWrap->GetAtkObject(), + "visible_data_changed"); + rv = NS_OK; + break; + + // Is a superclass of ATK event children_changed + case nsIAccessibleEventReceiver::EVENT_REORDER: + AtkChildrenChange *pAtkChildrenChange; + + MAI_LOG_DEBUG(("\n\nReceived: EVENT_REORDER(children_change)\n")); + + pAtkChildrenChange = NS_REINTERPRET_CAST(AtkChildrenChange *, + aEventData); + nsAccessibleWrap *childAccWrap; + if (pAtkChildrenChange && pAtkChildrenChange->child) { + childAccWrap = NS_STATIC_CAST(nsAccessibleWrap *, + pAtkChildrenChange->child); + g_signal_emit_by_name (accWrap->GetAtkObject(), + pAtkChildrenChange->add ? \ + "children_changed::add" : \ + "children_changed::remove", + pAtkChildrenChange->index, + childAccWrap->GetAtkObject(), + NULL); + /* ??? YBL same as above ??? */ + // g_object_unref(childAccWrap->GetAtkObject()); + } + else { + g_signal_emit_by_name (accWrap->GetAtkObject(), + "children_changed", + -1, NULL, NULL); + } + + rv = NS_OK; + break; + + /* + * Because dealing with menu is very different between nsIAccessible + * and ATK, and the menu activity is important, specially transfer the + * following two event. + * Need more verification by AT test. + */ + case nsIAccessibleEventReceiver::EVENT_MENUSTART: + MAI_LOG_DEBUG(("\n\nReceived: EVENT_MENUSTART\n")); + atk_focus_tracker_notify(accWrap->GetAtkObject()); + g_signal_emit_by_name(accWrap->GetAtkObject(), + "selection_changed"); + rv = NS_OK; + break; + + case nsIAccessibleEventReceiver::EVENT_MENUEND: + MAI_LOG_DEBUG(("\n\nReceived: EVENT_MENUEND\n")); + g_signal_emit_by_name(accWrap->GetAtkObject(), + "selection_changed"); + rv = NS_OK; + break; + + default: + // Don't transfer others + MAI_LOG_DEBUG(("\n\nReceived an unknown event=0x%u\n", aEvent)); + break; + } + + g_object_unref(accWrap->GetAtkObject()); + return rv; +} + +/* static */ +AtkStateType +TranslateAState(PRUint32 aAccState) +{ + switch (aAccState) { + case nsIAccessible::STATE_SELECTED: + return ATK_STATE_SELECTED; + case nsIAccessible::STATE_FOCUSED: + return ATK_STATE_FOCUSED; + case nsIAccessible::STATE_PRESSED: + return ATK_STATE_PRESSED; + case nsIAccessible::STATE_CHECKED: + return ATK_STATE_CHECKED; + case nsIAccessible::STATE_EXPANDED: + return ATK_STATE_EXPANDED; + case nsIAccessible::STATE_COLLAPSED: + return ATK_STATE_EXPANDABLE; + // The control can't accept input at this time + case nsIAccessible::STATE_BUSY: + return ATK_STATE_BUSY; + case nsIAccessible::STATE_FOCUSABLE: + return ATK_STATE_FOCUSABLE; + case nsIAccessible::STATE_SELECTABLE: + return ATK_STATE_SELECTABLE; + case nsIAccessible::STATE_SIZEABLE: + return ATK_STATE_RESIZABLE; + case nsIAccessible::STATE_MULTISELECTABLE: + return ATK_STATE_MULTISELECTABLE; + +#if 0 + // The following two state need to deal specially + case nsIAccessible::STATE_INVISIBLE: + return !ATK_STATE_VISIBLE; + + case nsIAccessible::STATE_UNAVAILABLE: + return !ATK_STATE_ENABLED; +#endif + + // The following state is + // Extended state flags (for non-MSAA, for Java and Gnome/ATK support) + // They are only the states that are not already mapped in MSAA + // See www.accessmozilla.org/article.php?sid=11 for information on the + // mappings between accessibility API state + + case nsIAccessible::STATE_ACTIVE: + return ATK_STATE_ACTIVE; + case nsIAccessible::STATE_EXPANDABLE: + return ATK_STATE_EXPANDABLE; +#if 0 + // Need change definitions in nsIAccessible.idl to avoid + // duplicate value + case nsIAccessible::STATE_MODAL: + return ATK_STATE_MODAL; +#endif + case nsIAccessible::STATE_MULTI_LINE: + return ATK_STATE_MULTI_LINE; + case nsIAccessible::STATE_SENSITIVE: + return ATK_STATE_SENSITIVE; + case nsIAccessible::STATE_RESIZABLE: + return ATK_STATE_RESIZABLE; + case nsIAccessible::STATE_SHOWING: + return ATK_STATE_SHOWING; + case nsIAccessible::STATE_SINGLE_LINE: + return ATK_STATE_SINGLE_LINE; + case nsIAccessible::STATE_TRANSIENT: + return ATK_STATE_TRANSIENT; + case nsIAccessible::STATE_VERTICAL: + return ATK_STATE_VERTICAL; + default: + return ATK_STATE_INVALID; + } +#endif } diff --git a/mozilla/accessible/src/atk/nsDocAccessibleWrap.h b/mozilla/accessible/src/atk/nsDocAccessibleWrap.h index a4ff9cb4350..64b988a5510 100644 --- a/mozilla/accessible/src/atk/nsDocAccessibleWrap.h +++ b/mozilla/accessible/src/atk/nsDocAccessibleWrap.h @@ -1,26 +1,29 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim:expandtab:shiftwidth=4:tabstop=4: + */ /* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * Version: NPL 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 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 - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. + * The Initial Developer of the Original Code is Sun Microsystems, Inc. + * Portions created by Sun Microsystems are Copyright (C) 2002 Sun + * Microsystems, Inc. All Rights Reserved. * - * Contributor(s): - * Original Author: Aaron Leventhal (aaronl@netscape.com) + * Original Author: Bolian Yin (bolian.yin@sun.com) + * + * Contributor(s): John Sun (john.sun@sun.com) * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -28,11 +31,11 @@ * 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 + * use your version of this file under the terms of the NPL, 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. + * the terms of any one of the NPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ @@ -48,9 +51,10 @@ class nsDocAccessibleWrap: public nsDocAccessible { public: - nsDocAccessibleWrap(nsIDOMNode *aNode, nsIWeakReference *aShell); - virtual ~nsDocAccessibleWrap(); - NS_IMETHOD FireToolkitEvent(PRUint32 aEvent, nsIAccessible* aAccessible, void* aData); + nsDocAccessibleWrap(nsIDOMNode *aNode, nsIWeakReference *aShell); + virtual ~nsDocAccessibleWrap(); + NS_IMETHOD FireToolkitEvent(PRUint32 aEvent, nsIAccessible* aAccessible, + void* aData); }; #endif diff --git a/mozilla/accessible/src/atk/nsRootAccessibleWrap.cpp b/mozilla/accessible/src/atk/nsRootAccessibleWrap.cpp index abf28ddaf91..aae638ba8b6 100644 --- a/mozilla/accessible/src/atk/nsRootAccessibleWrap.cpp +++ b/mozilla/accessible/src/atk/nsRootAccessibleWrap.cpp @@ -1,26 +1,27 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim:expandtab:shiftwidth=4:tabstop=4: + */ /* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * Version: NPL 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 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 - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. + * The Initial Developer of the Original Code is Sun Microsystems, Inc. + * Portions created by Sun Microsystems are Copyright (C) 2002 Sun + * Microsystems, Inc. All Rights Reserved. * - * Contributor(s): - * Original Author: Aaron Leventhal (aaronl@netscape.com) + * Original Author: Bolian Yin (bolian.yin@sun.com) * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -28,27 +29,60 @@ * 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 + * use your version of this file under the terms of the NPL, 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. + * the terms of any one of the NPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ -#include "nsCOMPtr.h" #include "nsRootAccessibleWrap.h" -#include "nsIServiceManager.h" -#include "nsIAccessibilityService.h" +#include "nsAppRootAccessible.h" -//----- nsRootAccessibleWrap ----- - -nsRootAccessibleWrap::nsRootAccessibleWrap(nsIDOMNode *aDOMNode, nsIWeakReference *aShell): - nsRootAccessible(aDOMNode, aShell) +nsRootAccessibleWrap::nsRootAccessibleWrap(nsIDOMNode *aDOMNode, + nsIWeakReference* aShell): + nsRootAccessible(aDOMNode, aShell) { + MAI_LOG_DEBUG(("New Root Acc=%p\n", (void*)this)); } nsRootAccessibleWrap::~nsRootAccessibleWrap() { + MAI_LOG_DEBUG(("Delete Root Acc=%p\n", (void*)this)); } +NS_IMETHODIMP nsRootAccessibleWrap::Init() +{ + nsRootAccessible::Init(); + nsAppRootAccessible *root = nsAppRootAccessible::Create(); + + nsresult rv = NS_ERROR_FAILURE; + if (root) + rv = root->AddRootAccessible(this); + return rv; +} + +NS_IMETHODIMP nsRootAccessibleWrap::Shutdown() +{ + nsAppRootAccessible *root = nsAppRootAccessible::Create(); + nsresult rv = NS_ERROR_FAILURE; + if (root) + rv = root->RemoveRootAccessible(this); + nsRootAccessible::Shutdown(); + return rv; +} + +NS_IMETHODIMP nsRootAccessibleWrap::GetAccParent(nsIAccessible ** aAccParent) +{ + nsAppRootAccessible *root = nsAppRootAccessible::Create(); + nsresult rv = NS_OK; + if (root) { + NS_IF_ADDREF(*aAccParent = root); + } + else { + *aAccParent = nsnull; + rv = NS_ERROR_FAILURE; + } + return rv; +} diff --git a/mozilla/accessible/src/atk/nsRootAccessibleWrap.h b/mozilla/accessible/src/atk/nsRootAccessibleWrap.h index 89942f4e6e9..83e4c3e077e 100644 --- a/mozilla/accessible/src/atk/nsRootAccessibleWrap.h +++ b/mozilla/accessible/src/atk/nsRootAccessibleWrap.h @@ -1,26 +1,29 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim:expandtab:shiftwidth=4:tabstop=4: + */ /* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * Version: NPL 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 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 - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. + * The Initial Developer of the Original Code is Sun Microsystems, Inc. + * Portions created by Sun Microsystems are Copyright (C) 2002 Sun + * Microsystems, Inc. All Rights Reserved. * - * Contributor(s): - * Original Author: Aaron Leventhal (aaronl@netscape.com) + * Original Author: Bolian Yin (bolian.yin@sun.com) + * + * Contributor(s): * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -28,29 +31,36 @@ * 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 + * use your version of this file under the terms of the NPL, 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. + * the terms of any one of the NPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ -/* For documentation of the accessibility architecture, - * see http://lxr.mozilla.org/seamonkey/source/accessible/accessible-docs.html - */ - -#ifndef _nsRootAccessibleWrap_H_ -#define _nsRootAccessibleWrap_H_ +#ifndef __NS_ROOT_ACCESSIBLE_WRAP_H__ +#define __NS_ROOT_ACCESSIBLE_WRAP_H__ #include "nsRootAccessible.h" +/* nsRootAccessibleWrap is the accessible class for toplevel Window. + * The instance of nsRootAccessibleWrap will be child of MaiAppRoot instance. + * It is added into root when the toplevel window is created, and removed + * from root when the toplevel window is destroyed. + */ + class nsRootAccessibleWrap: public nsRootAccessible { public: - nsRootAccessibleWrap(nsIDOMNode *aNode, nsIWeakReference *aShell); + nsRootAccessibleWrap(nsIDOMNode *aDOMNode, nsIWeakReference* aShell); virtual ~nsRootAccessibleWrap(); + + // virtual funcs from nsIAccessNode + NS_IMETHOD Init(void); + NS_IMETHOD Shutdown(void); + + NS_IMETHOD GetAccParent(nsIAccessible ** aAccParent); }; - -#endif +#endif /* __NS_ROOT_ACCESSIBLE_WRAP_H__ */ diff --git a/mozilla/accessible/src/base/nsAccessible.cpp b/mozilla/accessible/src/base/nsAccessible.cpp index 1c30a9eff60..4e52bd60baa 100644 --- a/mozilla/accessible/src/base/nsAccessible.cpp +++ b/mozilla/accessible/src/base/nsAccessible.cpp @@ -298,6 +298,11 @@ NS_IMETHODIMP nsAccessible::GetChildAt(PRInt32 aChildNum, nsIAccessible **aChild PRInt32 numChildren; GetAccChildCount(&numChildren); + if (aChildNum >= numChildren) { + *aChild = nsnull; + return NS_ERROR_FAILURE; + } + nsCOMPtr current(mFirstChild), nextSibling; PRInt32 index = 0; diff --git a/mozilla/accessible/src/base/nsAccessibleEventData.h b/mozilla/accessible/src/base/nsAccessibleEventData.h index cc143ff0c76..fbc0e9c4065 100644 --- a/mozilla/accessible/src/base/nsAccessibleEventData.h +++ b/mozilla/accessible/src/base/nsAccessibleEventData.h @@ -76,7 +76,7 @@ struct AtkPropertyChange { }; struct AtkChildrenChange { - PRUint32 index; // index of child in parent + PRInt32 index; // index of child in parent nsIAccessible *child; PRBool add; // true for add, false for delete }; diff --git a/mozilla/allmakefiles.sh b/mozilla/allmakefiles.sh index 3eea5ef0aa6..764283d6173 100755 --- a/mozilla/allmakefiles.sh +++ b/mozilla/allmakefiles.sh @@ -531,7 +531,6 @@ widget/src/Makefile widget/src/beos/Makefile widget/src/build/Makefile widget/src/gtk/Makefile -widget/src/gtk2/mai/Makefile widget/src/gtksuperwin/Makefile widget/src/gtkxtbin/Makefile widget/src/photon/Makefile diff --git a/mozilla/config/module2dir.pl b/mozilla/config/module2dir.pl index c133d70426e..894695fda58 100755 --- a/mozilla/config/module2dir.pl +++ b/mozilla/config/module2dir.pl @@ -92,7 +92,6 @@ my %map = ( 'liveconnect', 'js/src/liveconnect', 'locale', 'intl/locale', 'lwbrk', 'intl/lwbrk', - 'mai', 'widget/src/gtk2/mai', 'mailnews', 'mailnews', 'MapiProxy', 'mailnews/mapi/mapihook/build', 'mfcEmbed', 'embedding/tests/winEmbed', diff --git a/mozilla/widget/src/gtk2/Makefile.in b/mozilla/widget/src/gtk2/Makefile.in index 89ecf13a740..af8c0645178 100644 --- a/mozilla/widget/src/gtk2/Makefile.in +++ b/mozilla/widget/src/gtk2/Makefile.in @@ -60,14 +60,11 @@ CPPSRCS = \ nsClipboard.cpp \ nsDragService.cpp \ nsSound.cpp \ - nsGConfInterface.cpp \ $(NULL) # build our subdirs, too ifdef ACCESSIBILITY -DIRS = mai REQUIRES += accessibility -CPPSRCS += nsAccessibilityInterface.cpp endif SHARED_LIBRARY_LIBS = $(DIST)/lib/libxpwidgets_s.a diff --git a/mozilla/widget/src/gtk2/nsAccessibilityInterface.cpp b/mozilla/widget/src/gtk2/nsAccessibilityInterface.cpp deleted file mode 100644 index 9fe356b6578..00000000000 --- a/mozilla/widget/src/gtk2/nsAccessibilityInterface.cpp +++ /dev/null @@ -1,230 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* vim:expandtab:shiftwidth=4:tabstop=4: - */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 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 Sun Microsystems, Inc. - * Portions created by Sun Microsystems are Copyright (C) 2002 Sun - * Microsystems, Inc. All Rights Reserved. - * - * Original Author: Bolian Yin (bolian.yin@sun.com) - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include -#include - -#include "prenv.h" -#include "nsCommonWidget.h" - -#include "nsGConfInterface.h" -#include "nsAccessibilityInterface.h" - - -static const char sMaiLibName [] ="libmai.so"; -static const char sMaiInitFunc [] = "mai_init"; - -static const char sGconfAccKey [] = "/desktop/gnome/interface/accessibility"; -static const char sAccEnv [] = "GNOME_ACCESSIBILITY"; - -GnomeAccessibilityModule nsAccessibilityInterface::mAtkBridge = { - "libatk-bridge.so", NULL, - "gnome_accessibility_module_init", NULL, - "gnome_accessibility_module_shutdown", NULL, -}; - -MaiHook *nsAccessibilityInterface::mMaiHook = nsnull; -PRLibrary *nsAccessibilityInterface::mMaiLib = nsnull; -PRBool nsAccessibilityInterface::mInitialized = PR_FALSE; - -PRBool -nsAccessibilityInterface::Init() -{ - if (mInitialized) - return PR_TRUE; - - //load accessibility when - // 1. GNOME_ACCESSIBILITY set to non-zero, or - // 2. accessibility gconf key set to True. - - PRFuncPtr maiInit = NULL; - PRBool enableAcc = FALSE; - - //check if accessibility enabled/disabled by environment variable - const char *envValue = PR_GetEnv(sAccEnv); - - if (envValue) { - enableAcc = atoi(envValue); - LOG(("Accessibility Env %s=%s\n", sAccEnv, envValue)); - } - //check gconf-2 setting - else { - enableAcc = nsGConfInterface::GetBool(sGconfAccKey); - LOG(("Accessibility Gconf %s Enabled\n", enableAcc ? "" : "NOT")); - } - - if (!enableAcc) { - LOG(("Accessibility NOT Enabled\n")); - goto cleanup; - } - - //load and initialize mai library - mMaiLib = PR_LoadLibrary(sMaiLibName); - if (!mMaiLib) { - LOG(("Accessibility Fail to load Mai library %s\n", sMaiLibName)); - goto cleanup; - } - maiInit = PR_FindFunctionSymbol(mMaiLib, sMaiInitFunc); - if (!maiInit || !(*MaiInit(maiInit))(&mMaiHook) || !mMaiHook) { - LOG(("Accessibility Fail to initialize mai library\n")); - goto cleanup; - } - - //load and initialize atk-bridge library - if (!LoadGtkModule(mAtkBridge)) { - LOG(("Fail to load lib: %s\n", mAtkBridge.libName)); - goto cleanup; - } - //init atk-bridge - (*mAtkBridge.init)(); - - //at last - mInitialized = PR_TRUE; - return PR_TRUE; - - cleanup: - if (mMaiLib) { - mMaiHook = nsnull; - PR_UnloadLibrary(mMaiLib); - mMaiLib = nsnull; - mMaiHook = nsnull; - } - return PR_FALSE; -} - -PRBool -nsAccessibilityInterface::ShutDown() -{ - if (!mInitialized) - return PR_TRUE; - - mInitialized = PR_FALSE; - if (mMaiHook) { - mMaiHook->MaiShutdown(); - mMaiHook = NULL; - } - if (mAtkBridge.lib) { - if (mAtkBridge.shutdown) - (*mAtkBridge.shutdown)(); - //Not unload atk-bridge library - //an exit function registered will take care of it - mAtkBridge.lib = NULL; - mAtkBridge.init = NULL; - mAtkBridge.shutdown = NULL; - } - if (mMaiLib) { - PR_UnloadLibrary(mMaiLib); - mMaiLib = nsnull; - } - return PR_TRUE; -} - -PRBool -nsAccessibilityInterface::AddTopLevel(nsIAccessible *toplevel) -{ - if (mMaiHook && mMaiHook->AddTopLevelAccessible) - return (*mMaiHook->AddTopLevelAccessible)(toplevel); - return PR_FALSE; -} - -PRBool -nsAccessibilityInterface::RemoveTopLevel(nsIAccessible *toplevel) -{ - if (mMaiHook && mMaiHook->RemoveTopLevelAccessible) - return (*mMaiHook->RemoveTopLevelAccessible)(toplevel); - return PR_FALSE; -} - -PRBool -nsAccessibilityInterface::LoadGtkModule(GnomeAccessibilityModule& aModule) -{ - if (!aModule.libName) - return PR_FALSE; - if (!(aModule.lib = PR_LoadLibrary(aModule.libName))) { - - LOG(("Fail to load lib: %s in default path\n", aModule.libName)); - - //try to load the module with "gtk-2.0/modules" appended - char *curLibPath = PR_GetLibraryPath(); - nsCAutoString libPath(curLibPath); - LOG(("Current Lib path=%s\n", curLibPath)); - PR_FreeLibraryName(curLibPath); - - PRInt16 loc1 = 0, loc2 = 0; - PRInt16 subLen = 0; - while (loc2 >= 0) { - loc2 = libPath.FindChar(':', loc1); - if (loc2 < 0) - subLen = libPath.Length() - loc1; - else - subLen = loc2 - loc1; - nsCAutoString sub(Substring(libPath, loc1, subLen)); - sub.Append("/gtk-2.0/modules/"); - sub.Append(aModule.libName); - aModule.lib = PR_LoadLibrary(sub.get()); - if (aModule.lib) { - LOG(("Ok, load %s from %s\n", aModule.libName, sub.get())); - break; - } - loc1 = loc2+1; - } - if (!aModule.lib) { - LOG(("Fail to load %s\n", aModule.libName)); - return PR_FALSE; - } - } - - //we have loaded the library, try to get the function ptrs - if (!(aModule.init = PR_FindFunctionSymbol(aModule.lib, - aModule.initName)) || - !(aModule.shutdown = PR_FindFunctionSymbol(aModule.lib, - aModule.shutdownName))) { - - //fail, :( - LOG(("Fail to find symbol %s in %s", aModule.init ? - aModule.shutdownName : aModule.initName, aModule.libName)); - PR_UnloadLibrary(aModule.lib); - aModule.lib = NULL; - return PR_FALSE; - } - - return PR_TRUE; -} diff --git a/mozilla/widget/src/gtk2/nsAccessibilityInterface.h b/mozilla/widget/src/gtk2/nsAccessibilityInterface.h deleted file mode 100644 index 99f712bea86..00000000000 --- a/mozilla/widget/src/gtk2/nsAccessibilityInterface.h +++ /dev/null @@ -1,96 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* vim:expandtab:shiftwidth=4:tabstop=4: - */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 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 Sun Microsystems, Inc. - * Portions created by Sun Microsystems are Copyright (C) 2002 Sun - * Microsystems, Inc. All Rights Reserved. - * - * Original Author: Bolian Yin (bolian.yin@sun.com) - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __ACCESSIBILITY_INTERFACE_H__ -#define __ACCESSIBILITY_INTERFACE_H__ - -#include "nsIAccessible.h" -#include "prlink.h" - -struct MaiHook -{ - PRBool (*MaiShutdown)(void); - PRBool (*MaiStartup)(MaiHook **); - PRBool (*AddTopLevelAccessible)(nsIAccessible *toplevel); - PRBool (*RemoveTopLevelAccessible)(nsIAccessible *toplevel); -}; - -G_BEGIN_DECLS -typedef PRBool (*MaiInit) (MaiHook **aMaiHook); -typedef void (*GnomeAccessibilityInit) (void); -typedef void (*GnomeAccessibilityShutdown) (void); -G_END_DECLS - -struct GnomeAccessibilityModule -{ - const char *libName; - PRLibrary *lib; - const char *initName; - GnomeAccessibilityInit init; - const char *shutdownName; - GnomeAccessibilityShutdown shutdown; -}; - -class nsAccessibilityInterface -{ -public: - nsAccessibilityInterface() {} - ~nsAccessibilityInterface() {} - -public: - static PRBool Init(void); - static PRBool ShutDown(void); - static inline PRBool IsInitialized() {return mInitialized; } - - static PRBool AddTopLevel(nsIAccessible *toplevel); - static PRBool RemoveTopLevel(nsIAccessible *toplevel); - -private: - static PRBool LoadGtkModule(GnomeAccessibilityModule& aModule); -private: - static PRBool mInitialized; - static PRLibrary *mMaiLib; - static MaiHook *mMaiHook; - - static GnomeAccessibilityModule mAtkBridge; -}; - -#endif /* __ACCESSIBILITY_INTERFACE_H__ */ diff --git a/mozilla/widget/src/gtk2/nsAppShell.cpp b/mozilla/widget/src/gtk2/nsAppShell.cpp index e4c67bf9cbc..5d4a6869f9d 100644 --- a/mozilla/widget/src/gtk2/nsAppShell.cpp +++ b/mozilla/widget/src/gtk2/nsAppShell.cpp @@ -47,10 +47,6 @@ #include -#ifdef ACCESSIBILITY -#include "nsAccessibilityInterface.h" -#endif - static PRBool sInitialized = PR_FALSE; static PLHashTable *sQueueHashTable = nsnull; static PLHashTable *sCountHashTable = nsnull; @@ -112,9 +108,6 @@ nsAppShell::Create(int *argc, char **argv) // XXX add all of the command line handling -#ifdef ACCESSIBILITY - nsAccessibilityInterface::Init(); -#endif if (PR_GetEnv("MOZ_DEBUG_PAINTS")) { gdk_window_set_debug_updates(TRUE); diff --git a/mozilla/widget/src/gtk2/nsGConfInterface.cpp b/mozilla/widget/src/gtk2/nsGConfInterface.cpp deleted file mode 100644 index 9fd41cf559e..00000000000 --- a/mozilla/widget/src/gtk2/nsGConfInterface.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* vim:expandtab:shiftwidth=4:tabstop=4: - */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 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 Sun Microsystems, Inc. - * Portions created by Sun Microsystems are Copyright (C) 2002 Sun - * Microsystems, Inc. All Rights Reserved. - * - * Original Author: Bolian Yin (bolian.yin@sun.com) - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include -#include - -#include "prenv.h" -#include "nsCOMPtr.h" -#include "nsIPref.h" -#include "nsIServiceManagerUtils.h" - -#include "nsCommonWidget.h" -#include "nsGConfInterface.h" - -//gconf function type -G_BEGIN_DECLS -typedef PRBool (*GConfClientGetBool) (void *client, const gchar *key, - GError **err); -typedef void * (*GConfClientGetDefault) (void); -G_END_DECLS - -typedef struct { - const char *FuncName; - PRFuncPtr FuncPtr; -}GConfFuncListType; - -static GConfFuncListType sGConfFuncList[] = { - {"gconf_client_get_default", nsnull}, - {"gconf_client_get_bool", nsnull}, - {nsnull, nsnull}, -}; - -static const char sPrefGConfKey[] = "accessibility.unix.gconf2.shared-library"; -static const char sDefaultLibName1[] = "libgconf-2.so.4"; -static const char sDefaultLibName2[] = "libgconf-2.so"; - -void *nsGConfInterface::mGConfClient = nsnull; -PRLibrary *nsGConfInterface::mGConfLib = nsnull; -PRBool nsGConfInterface::mInitialized = PR_FALSE; - -/* public */ -PRBool -nsGConfInterface::GetBool(const char *aKey) -{ - if (!mInitialized && !Init()) - return PR_FALSE; - GConfClientGetBool getBool = - NS_REINTERPRET_CAST(GConfClientGetBool, sGConfFuncList[1].FuncPtr); - return getBool(mGConfClient, aKey, NULL); -} - -/* private */ -PRBool -nsGConfInterface::Init() -{ - if (mInitialized) - return PR_TRUE; - - nsCOMPtr pref = do_GetService(NS_PREF_CONTRACTID); - if (!pref) - return PR_FALSE; - - - nsXPIDLCString gconfLibName; - nsresult rv; - - //check if gconf-2 library is given in prefs - rv = pref->GetCharPref(sPrefGConfKey, getter_Copies(gconfLibName)); - if (NS_SUCCEEDED(rv)) { - //use the library name in the preference - LOG(("GConf library in prefs is %s\n", gconfLibName.get())); - mGConfLib = PR_LoadLibrary(gconfLibName.get()); - } - else { - LOG(("GConf library not specified in prefs, try the default: " - "%s and %s\n", sDefaultLibName1, sDefaultLibName2)); - mGConfLib = PR_LoadLibrary(sDefaultLibName1); - if (!mGConfLib) - mGConfLib = PR_LoadLibrary(sDefaultLibName2); - } - - if (!mGConfLib) { - LOG(("Fail to load GConf library\n")); - return PR_FALSE; - } - - - //check every func we need in the gconf library - GConfFuncListType *funcList; - PRFuncPtr func; - for (funcList = sGConfFuncList; funcList->FuncName; ++funcList) { - func = PR_FindFunctionSymbol(mGConfLib, funcList->FuncName); - if (!func) { - LOG(("Check GConf Function Error: %s", funcList->FuncName)); - PR_UnloadLibrary(mGConfLib); - mGConfLib = nsnull; - return PR_FALSE; - } - funcList->FuncPtr = func; - } - - //get default gconf client - GConfClientGetDefault getDefault = - NS_REINTERPRET_CAST(GConfClientGetDefault, sGConfFuncList[0].FuncPtr); - - mGConfClient = (*getDefault)(); - if (!mGConfClient) { - LOG(("Fail to Get default gconf client\n")); - PR_UnloadLibrary(mGConfLib); - mGConfLib = nsnull; - return PR_FALSE; - } - mInitialized = PR_TRUE; - return PR_TRUE; -} diff --git a/mozilla/widget/src/gtk2/nsGConfInterface.h b/mozilla/widget/src/gtk2/nsGConfInterface.h deleted file mode 100644 index f5e516ace45..00000000000 --- a/mozilla/widget/src/gtk2/nsGConfInterface.h +++ /dev/null @@ -1,65 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* vim:expandtab:shiftwidth=4:tabstop=4: - */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 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 Sun Microsystems, Inc. - * Portions created by Sun Microsystems are Copyright (C) 2002 Sun - * Microsystems, Inc. All Rights Reserved. - * - * Original Author: Bolian Yin (bolian.yin@sun.com) - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __GCONF_INTERFACE_H__ -#define __GCONF_INTERFACE_H__ - -#include "prlink.h" - -class nsGConfInterface -{ -public: - nsGConfInterface() {} - ~nsGConfInterface() {} - - inline static PRBool IsInitialized(void) { return mInitialized; } - static PRBool GetBool(const char *aKey); - -private: - static PRBool Init(); - -private: - static void *mGConfClient; - static PRLibrary *mGConfLib; - static PRBool mInitialized; -}; - -#endif /* __GCONF_INTERFACE_H__ */ diff --git a/mozilla/widget/src/gtk2/nsWidgetFactory.cpp b/mozilla/widget/src/gtk2/nsWidgetFactory.cpp index 8d0cd64aa8f..8c1038c477f 100644 --- a/mozilla/widget/src/gtk2/nsWidgetFactory.cpp +++ b/mozilla/widget/src/gtk2/nsWidgetFactory.cpp @@ -51,10 +51,6 @@ #include "nsSound.h" #include "nsBidiKeyboard.h" -#ifdef ACCESSIBILITY -#include "nsAccessibilityInterface.h" -#endif - NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindow) NS_GENERIC_FACTORY_CONSTRUCTOR(nsChildWindow) NS_GENERIC_FACTORY_CONSTRUCTOR(nsAppShell) @@ -123,9 +119,6 @@ static const nsModuleComponentInfo components[] = PR_STATIC_CALLBACK(void) nsWidgetGtk2ModuleDtor(nsIModule *aSelf) { -#ifdef ACCESSIBILITY - nsAccessibilityInterface::ShutDown(); -#endif } NS_IMPL_NSGETMODULE_WITH_DTOR(nsWidgetGtk2Module, diff --git a/mozilla/widget/src/gtk2/nsWindow.cpp b/mozilla/widget/src/gtk2/nsWindow.cpp index 192e8d5edba..3db8f61dfa6 100644 --- a/mozilla/widget/src/gtk2/nsWindow.cpp +++ b/mozilla/widget/src/gtk2/nsWindow.cpp @@ -58,6 +58,15 @@ #include "nsIPref.h" #include "nsIServiceManager.h" +#ifdef ACCESSIBILITY +#include "prenv.h" +#include "stdlib.h" +static PRBool sAccessibilityChecked = PR_FALSE; +static PRBool sAccessibilityEnabled = PR_FALSE; +static const char sGconfAccKey [] = "/desktop/gnome/interface/accessibility"; +static const char sAccEnv [] = "GNOME_ACCESSIBILITY"; +#endif + /* For SetIcon */ #include "nsAppDirectoryServiceDefs.h" #include "nsXPIDLString.h" @@ -249,7 +258,7 @@ nsWindow::nsWindow() #endif #ifdef ACCESSIBILITY - mTopLevelAccessible = nsnull; + mRootAccessible = nsnull; #endif } @@ -276,9 +285,6 @@ nsWindow::Create(nsIWidget *aParent, { nsresult rv = NativeCreate(aParent, nsnull, aRect, aHandleEventFunction, aContext, aAppShell, aToolkit, aInitData); -#ifdef ACCESSIBILITY - CreateTopLevelAccessible(); -#endif return rv; } @@ -293,9 +299,6 @@ nsWindow::Create(nsNativeWidget aParent, { nsresult rv = NativeCreate(nsnull, aParent, aRect, aHandleEventFunction, aContext, aAppShell, aToolkit, aInitData); -#ifdef ACCESSIBILITY - CreateTopLevelAccessible(); -#endif return rv; } @@ -376,9 +379,11 @@ nsWindow::Destroy(void) OnDestroy(); #ifdef ACCESSIBILITY - if (mTopLevelAccessible) { - nsAccessibilityInterface::RemoveTopLevel(mTopLevelAccessible); - mTopLevelAccessible = nsnull; + if (mRootAccessible) { + nsCOMPtr accNode(do_QueryInterface(mRootAccessible)); + if (accNode) + accNode->Shutdown(); + mRootAccessible = nsnull; } #endif @@ -2221,6 +2226,37 @@ nsWindow::NativeCreate(nsIWidget *aParent, // resize so that everything is set to the right dimensions Resize(mBounds.width, mBounds.height, PR_FALSE); +#ifdef ACCESSIBILITY + nsresult rv; + if (!sAccessibilityChecked) { + sAccessibilityChecked = PR_TRUE; + + //check if accessibility enabled/disabled by environment variable + const char *envValue = PR_GetEnv(sAccEnv); + if (envValue) { + sAccessibilityEnabled = atoi(envValue); + LOG(("Accessibility Env %s=%s\n", sAccEnv, envValue)); + } + //check gconf-2 setting + else { + nsCOMPtr sysPrefService = + do_GetService(sGconfAccKey, &rv); + if (NS_SUCCEEDED(rv) && sysPrefService) { + + // do the work to get gconf setting. + // will be done soon later. + sysPrefService->GetBoolPref("accessibility.enabled", + &sAccessibilityEnabled); + } + + } + } + if (sAccessibilityEnabled) { + LOG(("nsWindow:: Create Toplevel Accessibility\n")); + CreateRootAccessible(); + } +#endif + return NS_OK; } @@ -3537,22 +3573,19 @@ key_event_to_context_menu_event(const nsKeyEvent* aKeyEvent, #ifdef ACCESSIBILITY /** * void - * nsWindow::CreateTopLevelAccessible + * nsWindow::CreateRootAccessible * * request to create the nsIAccessible Object for the toplevel window **/ void -nsWindow::CreateTopLevelAccessible() +nsWindow::CreateRootAccessible() { - if (mIsTopLevel && !mTopLevelAccessible && - nsAccessibilityInterface::IsInitialized()) { - + if (mIsTopLevel && !mRootAccessible) { nsCOMPtr acc; DispatchAccessibleEvent(getter_AddRefs(acc)); if (acc) { - mTopLevelAccessible = acc; - nsAccessibilityInterface::AddTopLevel(acc); + mRootAccessible = acc; } } } diff --git a/mozilla/widget/src/gtk2/nsWindow.h b/mozilla/widget/src/gtk2/nsWindow.h index 2039a77b91b..1b721253251 100644 --- a/mozilla/widget/src/gtk2/nsWindow.h +++ b/mozilla/widget/src/gtk2/nsWindow.h @@ -53,7 +53,8 @@ #include #ifdef ACCESSIBILITY -#include "nsAccessibilityInterface.h" +#include "nsIAccessNode.h" +#include "nsIAccessible.h" #endif #ifdef USE_XIM @@ -283,8 +284,8 @@ private: PRInt32 mSizeState; #ifdef ACCESSIBILITY - nsCOMPtr mTopLevelAccessible; - void CreateTopLevelAccessible(); + nsCOMPtr mRootAccessible; + void CreateRootAccessible(); NS_IMETHOD_(PRBool) DispatchAccessibleEvent(nsIAccessible** aAccessible); #endif diff --git a/mozilla/xpinstall/packager/packages-unix b/mozilla/xpinstall/packager/packages-unix index a68a5eb4066..ab375632dcc 100644 --- a/mozilla/xpinstall/packager/packages-unix +++ b/mozilla/xpinstall/packager/packages-unix @@ -150,8 +150,6 @@ bin/components/libwallet.so bin/components/libwalletviewers.so bin/components/libwidget_gtk.so bin/components/libwidget_gtk2.so -; accessibility library for gtk2 is loaded at runtime -bin/libmai.so bin/components/libxpconnect.so bin/components/locale.xpt bin/components/mozbrwsr.xpt