Closed Bug 151136 Opened 22 years ago Closed 22 years ago

support nsIAccessibleSelection in MAI (Mozilla Atk Implementation)

Categories

(Core :: Disability Access APIs, defect)

x86
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: yinbolian, Assigned: silvia.zhao)

References

Details

(Keywords: access)

Attachments

(1 file, 3 obsolete files)

 
Blocks: 145863
Status: NEW → ASSIGNED
Keywords: access
QA Contact: dsirnapalli → mindy.liu
Siliva will own this bug
Assignee: bolian.yin → silvia.zhao
Status: ASSIGNED → NEW
Attached patch patch_v1 (obsolete) — Splinter Review
Attached patch patch_v2 (obsolete) — Splinter Review
Attachment #89226 - Attachment is obsolete: true
+MaiObject *
+MaiInterfaceSelection::RefSelection(gint i)
+{
+    MAI_IFACE_RETURN_VAL_IF_FAIL(accessInterfaceSelectable, FALSE);
                                                             ^^^^^^
mismatch return value.
Status: NEW → ASSIGNED
Comment on attachment 89229 [details] [diff] [review]
patch_v2

>Index: nsMaiInterfaceSelection.cpp
>===================================================================
>RCS file: nsMaiInterfaceSelection.cpp
>diff -N nsMaiInterfaceSelection.cpp
>--- /dev/null	Wed Jun 26 14:20:48 2002
>+++ nsMaiInterfaceSelection.cpp	Wed Jun 26 14:25:14 2002
>@@ -0,0 +1,308 @@
>+/* -*- 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: Silvia Zhao (silvia.zhao@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 "nsMaiInterfaceSelection.h"
>+#include "nsIAccessibleSelectable.h"
>+
>+/* helpers */
>+static MaiInterfaceSelection *getSelection(AtkSelection *aIface);
>+
>+G_BEGIN_DECLS
>+
>+/* selection interface callbacks */
>+
>+static void interfaceInitCB(AtkSelectionIface *aIface);
>+static gboolean addSelectionCB(AtkSelection *aSelection,
>+                               gint i);
>+static gboolean clearSelectionCB(AtkSelection *aSelection);
>+static AtkObject *refSelectionCB(AtkSelection *aSelection,
>+                                 gint i);
>+static gint getSelectionCountCB(AtkSelection *aSelection);
>+static gboolean isChildSelectedCB(AtkSelection *aSelection,
>+                                  gint i);
>+static gboolean removeSelectionCB(AtkSelection *aSelection,
>+                                  gint i);
>+static gboolean selectAllSelectionCB(AtkSelection *aSelection);
>+
>+G_END_DECLS
>+
>+MaiInterfaceSelection::MaiInterfaceSelection(MaiWidget *aMaiWidget):
>+    MaiInterface(aMaiWidget)
>+{
>+}
>+
>+MaiInterfaceSelection::~MaiInterfaceSelection()
>+{
>+}
>+
>+MaiInterfaceType
>+MaiInterfaceSelection::GetType()
>+{
>+    return MAI_INTERFACE_SELECTION;
>+}
>+
>+const GInterfaceInfo *
>+MaiInterfaceSelection::GetInterfaceInfo()
>+{
>+    static const GInterfaceInfo atk_if_selection_info = {
>+        (GInterfaceInitFunc) interfaceInitCB,
>+        (GInterfaceFinalizeFunc) NULL,
>+        NULL
>+    };
>+    return &atk_if_selection_info;
>+}
>+
>+#define MAI_IFACE_RETURN_VAL_IF_FAIL(accessIface, retvalue) \
>+    nsIAccessible *tmpAccess = GetNSAccessible(); \
>+    nsCOMPtr<nsIAccessibleSelectable> \
>+        accessIface(do_QueryInterface(tmpAccess)); \
>+    if (!(accessIface)) \
>+        return (retvalue)
>+
>+/*interface virtual functions*/
>+gboolean
>+MaiInterfaceSelection::AddSelection(gint i)
>+{
>+    MAI_IFACE_RETURN_VAL_IF_FAIL(accessInterfaceSelectable, FALSE);
>+
>+    nsresult rv = accessInterfaceSelectable->AddSelection(i);
>+    if (NS_FAILED(rv))
>+        return FALSE;
>+    else
>+        return TRUE;
>+}
>+
>+gboolean
>+MaiInterfaceSelection::ClearSelection()
>+{
>+    MAI_IFACE_RETURN_VAL_IF_FAIL(accessInterfaceSelectable, FALSE);
>+
>+    nsresult rv = accessInterfaceSelectable->ClearSelection();
>+    if (NS_FAILED(rv))
>+        return FALSE;
>+    else
>+        return TRUE;
>+}
>+
>+MaiObject *
>+MaiInterfaceSelection::RefSelection(gint i)
>+{
>+    MAI_IFACE_RETURN_VAL_IF_FAIL(accessInterfaceSelectable, FALSE);
+    MAI_IFACE_RETURN_VAL_IF_FAIL(accessInterfaceSelectable, NULL);
>+
>+    nsCOMPtr<nsIAccessible> aSelection;
>+    nsresult rv =
>+        accessInterfaceSelectable->RefSelection(i, getter_AddRefs(aSelection));
>+    if (NS_FAILED(rv))
>+        return NULL;
>+    else {
>+        MaiWidget *maiWidget = new MaiWidget(aSelection);
>+        return maiWidget;
>+    }
>+}
>+
>+gint
>+MaiInterfaceSelection::GetSelectionCount()
>+{
>+    MAI_IFACE_RETURN_VAL_IF_FAIL(accessInterfaceSelectable, 0);
>+
>+    PRInt32 num = 0;
>+    nsresult rv = accessInterfaceSelectable->GetSelectionCount(&num);
>+    if (NS_FAILED(rv))
>+        return -1;
>+    else
>+        return num;
>+}
>+
>+gboolean
>+MaiInterfaceSelection::IsChildSelected(gint i)
>+{
>+    MAI_IFACE_RETURN_VAL_IF_FAIL(accessInterfaceSelectable, FALSE);
>+
>+    PRBool result = FALSE;
>+    nsresult rv = accessInterfaceSelectable->IsChildSelected(i, &result);
>+    if (NS_FAILED(rv))
>+        return FALSE;
>+    else
>+        return result;
>+}
>+
>+gboolean
>+MaiInterfaceSelection::RemoveSelection(gint i)
>+{
>+    MAI_IFACE_RETURN_VAL_IF_FAIL(accessInterfaceSelectable, FALSE);
>+
>+    nsresult rv = accessInterfaceSelectable->RemoveSelection(i);
>+    if (NS_FAILED(rv))
>+        return FALSE;
>+    else
>+        return TRUE;
>+}
>+
>+gboolean
>+MaiInterfaceSelection::SelectAllSelection()
>+{
>+    MAI_IFACE_RETURN_VAL_IF_FAIL(accessInterfaceSelectable, FALSE);
>+
>+    PRBool result = FALSE;
>+    nsresult rv = accessInterfaceSelectable->SelectAllSelection(&result);
>+    if (NS_FAILED(rv))
>+        return FALSE;
>+    else
>+        return result;
>+}
>+
>+/* static functions */
>+
>+/* do general checking for callbacks functions
>+ * return the MaiInterfaceSelection extracted from atk selection
>+ */
>+
>+MaiInterfaceSelection *
>+getSelection(AtkSelection *aSelection)
>+{
>+    MAI_CHECK_ATK_OBJECT_RETURN_VAL_IF_FAIL(aSelection, NULL);
>+    g_return_val_if_fail(MAI_IS_ATK_WIDGET(aSelection), NULL);
>+    MaiWidget *maiWidget = (MaiWidget*)(MAI_ATK_OBJECT(aSelection)->maiObject);
>+    
>+    MaiInterfaceSelection *maiInterfaceSelection = (MaiInterfaceSelection*)
>+        maiWidget->GetMaiInterface(MAI_INTERFACE_SELECTION);
>+    return maiInterfaceSelection;
>+}
>+
>+void
>+interfaceInitCB(AtkSelectionIface *aIface)
>+{
>+    g_return_if_fail(aIface != NULL);
>+    aIface->add_selection = addSelectionCB;
>+    aIface->clear_selection = clearSelectionCB;
>+    aIface->ref_selection = refSelectionCB;
>+    aIface->get_selection_count = getSelectionCountCB;
>+    aIface->is_child_selected = isChildSelectedCB;
>+    aIface->remove_selection = removeSelectionCB;
>+    aIface->select_all_selection = selectAllSelectionCB;
>+}
>+
>+gboolean
>+addSelectionCB(AtkSelection *aSelection, gint i)
>+{
>+    MaiInterfaceSelection *maiInterfaceSelection = getSelection(aSelection);
>+
>+    if (maiInterfaceSelection)
>+        return maiInterfaceSelection->AddSelection(i);
>+    else
>+        return FALSE;
>+}
>+
>+gboolean
>+clearSelectionCB(AtkSelection *aSelection)
>+{
>+    MaiInterfaceSelection *maiInterfaceSelection = getSelection(aSelection);
>+
>+    if (maiInterfaceSelection)
>+        return maiInterfaceSelection->ClearSelection();
>+    else 
>+        return FALSE;
>+}
>+
>+AtkObject *
>+refSelectionCB(AtkSelection *aSelection, gint i)
>+{
>+    MaiInterfaceSelection *maiInterfaceSelection = getSelection(aSelection);
>+
>+    if (!maiInterfaceSelection)
>+        return NULL;
>+
>+    MaiObject *maiObj =
>+        maiInterfaceSelection->RefSelection(i);
>+    if (!maiObj)
>+        return NULL;
>+
>+    AtkObject *atkObj = maiObj->GetAtkObject();
>+    if (!atkObj)
>+        return NULL;
>+    g_object_ref(atkObj);
>+    return atkObj;
>+
>+}
>+
>+gint
>+getSelectionCountCB(AtkSelection *aSelection)
>+{
>+    MaiInterfaceSelection *maiInterfaceSelection = getSelection(aSelection);
>+    
>+    if (maiInterfaceSelection)
>+        return maiInterfaceSelection->GetSelectionCount();
>+    else
>+        return 0;
>+}
>+
>+gboolean
>+isChildSelectedCB(AtkSelection *aSelection, gint i)
>+{
>+    MaiInterfaceSelection *maiInterfaceSelection = getSelection(aSelection);
>+    
>+    if (maiInterfaceSelection)
>+        return maiInterfaceSelection->IsChildSelected(i);
>+    else
>+        return FALSE;
>+}
>+
>+gboolean
>+removeSelectionCB(AtkSelection *aSelection, gint i)
>+{
>+    MaiInterfaceSelection *maiInterfaceSelection = getSelection(aSelection);
>+
>+    if (maiInterfaceSelection)
>+        return maiInterfaceSelection->RemoveSelection(i);
>+    else
>+        return FALSE;
>+}
>+
>+gboolean
>+selectAllSelectionCB(AtkSelection *aSelection)
>+{
>+    MaiInterfaceSelection *maiInterfaceSelection = getSelection(aSelection);
>+
>+    if (maiInterfaceSelection)
>+        return maiInterfaceSelection->SelectAllSelection();
>+    else
>+        return FALSE;
>+}
>Index: nsMaiInterfaceSelection.h
>===================================================================
>RCS file: nsMaiInterfaceSelection.h
>diff -N nsMaiInterfaceSelection.h
>--- /dev/null	Wed Jun 26 14:20:48 2002
>+++ nsMaiInterfaceSelection.h	Wed Jun 26 14:25:14 2002
>@@ -0,0 +1,69 @@
>+/* -*- 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: Silvia Zhao (silvia.zhao@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 __MAI_INTERFACE_SELECTION_H__
>+#define __MAI_INTERFACE_SELECTION_H__
>+
>+#include "nsMaiWidget.h"
>+#include "nsIAccessibleSelectable.h"
>+
>+class MaiInterfaceSelection: public MaiInterface
>+{
>+public:
>+    MaiInterfaceSelection(MaiWidget*);
>+    ~MaiInterfaceSelection();
>+
>+    virtual MaiInterfaceType GetType();
>+    virtual const GInterfaceInfo *GetInterfaceInfo();
>+
>+public:
>+    
>+    gboolean AddSelection(gint i);
>+    gboolean ClearSelection();
>+    MaiObject *RefSelection(gint i);
>+    gint GetSelectionCount();
>+    gboolean IsChildSelected(gint i);
>+    gboolean RemoveSelection(gint i);
>+    gboolean SelectAllSelection();
>+
>+};
>+
>+#endif /* __MAI_INTERFACE_SELECTION_H__ */
>
Attached patch patch_v3 (obsolete) — Splinter Review
Sorry for the wrong action just now. It makes such a long email. :-P
Attachment #89229 - Attachment is obsolete: true
Always avoid else after return.

Also, simplify as much as possible.

+    nsresult rv = accessInterfaceSelectable->ClearSelection();
+    if (NS_FAILED(rv))
+        return FALSE;
+    else
+        return TRUE;
+}
can become

return NS_SUCCEEDED(accessInterfaceSelectable->ClearSelection()) != 0;
Attached patch patch_v4Splinter Review
removed else after return

Thanks aaronl.:-)
Attachment #89232 - Attachment is obsolete: true
Comment on attachment 89246 [details] [diff] [review]
patch_v4

r=aaronl
Attachment #89246 - Flags: review+
This bug has been checked in.
It is not in the default build and we need it to do later work. Further
comments, review, and super-review is still welcome, I will file new bug if
needed. Thanks for everyone.
Status: ASSIGNED → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: