Diff
Modified: trunk/Source/WebCore/ChangeLog (105726 => 105727)
--- trunk/Source/WebCore/ChangeLog 2012-01-24 12:04:16 UTC (rev 105726)
+++ trunk/Source/WebCore/ChangeLog 2012-01-24 12:25:13 UTC (rev 105727)
@@ -5,6 +5,38 @@
Reviewed by Martin Robinson.
+ New files for the implementation of the AtkSelection interface,
+ containing the related code from WebKitAccessibleWrapperAtk.cpp.
+
+ * accessibility/gtk/WebKitAccessibleInterfaceSelection.cpp: Added.
+ (core):
+ (listObjectForSelection):
+ (optionFromList):
+ (optionFromSelection):
+ (webkitAccessibleSelectionInterfaceInit):
+ (webkitAccessibleSelectionAddSelection):
+ (webkitAccessibleSelectionClearSelection):
+ (webkitAccessibleSelectionRefSelection):
+ (webkitAccessibleSelectionGetSelectionCount):
+ (webkitAccessibleSelectionIsChildSelected):
+ (webkitAccessibleSelectionRemoveSelection):
+ (webkitAccessibleSelectionSelectAllSelection):
+ * accessibility/gtk/WebKitAccessibleInterfaceSelection.h: Added.
+ * accessibility/gtk/WebKitAccessibleWrapperAtk.cpp: Remove code
+ related to the implementation of the AtkSelection interface.
+
+ Add new files to build files.
+
+ * GNUmakefile.list.am: Add WebKitAccessibleInterfaceSelection.[h|cpp].
+ * WebCore.gypi: Ditto.
+
+2012-01-24 Mario Sanchez Prada <[email protected]>
+
+ [GTK] Refactor GTK's accessibilitity code to be more modular
+ https://bugs.webkit.org/show_bug.cgi?id=76783
+
+ Reviewed by Martin Robinson.
+
New files for the implementation of the AtkImage interface,
containing the related code from WebKitAccessibleWrapperAtk.cpp.
Modified: trunk/Source/WebCore/GNUmakefile.list.am (105726 => 105727)
--- trunk/Source/WebCore/GNUmakefile.list.am 2012-01-24 12:04:16 UTC (rev 105726)
+++ trunk/Source/WebCore/GNUmakefile.list.am 2012-01-24 12:25:13 UTC (rev 105727)
@@ -4435,6 +4435,8 @@
Source/WebCore/accessibility/gtk/WebKitAccessibleInterfaceHypertext.h \
Source/WebCore/accessibility/gtk/WebKitAccessibleInterfaceImage.cpp \
Source/WebCore/accessibility/gtk/WebKitAccessibleInterfaceImage.h \
+ Source/WebCore/accessibility/gtk/WebKitAccessibleInterfaceSelection.cpp \
+ Source/WebCore/accessibility/gtk/WebKitAccessibleInterfaceSelection.h \
Source/WebCore/accessibility/gtk/WebKitAccessibleUtil.cpp \
Source/WebCore/accessibility/gtk/WebKitAccessibleUtil.h \
Source/WebCore/accessibility/gtk/WebKitAccessibleWrapperAtk.cpp \
Modified: trunk/Source/WebCore/WebCore.gypi (105726 => 105727)
--- trunk/Source/WebCore/WebCore.gypi 2012-01-24 12:04:16 UTC (rev 105726)
+++ trunk/Source/WebCore/WebCore.gypi 2012-01-24 12:25:13 UTC (rev 105727)
@@ -1359,6 +1359,8 @@
'accessibility/gtk/WebKitAccessibleInterfaceHypertext.h',
'accessibility/gtk/WebKitAccessibleInterfaceImage.cpp',
'accessibility/gtk/WebKitAccessibleInterfaceImage.h',
+ 'accessibility/gtk/WebKitAccessibleInterfaceSelection.cpp',
+ 'accessibility/gtk/WebKitAccessibleInterfaceSelection.h',
'accessibility/gtk/WebKitAccessibleUtil.cpp',
'accessibility/gtk/WebKitAccessibleUtil.h',
'accessibility/gtk/WebKitAccessibleWrapperAtk.cpp',
Added: trunk/Source/WebCore/accessibility/gtk/WebKitAccessibleInterfaceSelection.cpp (0 => 105727)
--- trunk/Source/WebCore/accessibility/gtk/WebKitAccessibleInterfaceSelection.cpp (rev 0)
+++ trunk/Source/WebCore/accessibility/gtk/WebKitAccessibleInterfaceSelection.cpp 2012-01-24 12:25:13 UTC (rev 105727)
@@ -0,0 +1,250 @@
+/*
+ * Copyright (C) 2008 Nuanti Ltd.
+ * Copyright (C) 2009 Jan Alonzo
+ * Copyright (C) 2010, 2011, 2012 Igalia S.L.
+ *
+ * Portions from Mozilla a11y, copyright as follows:
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Sun Microsystems, Inc.
+ * Portions created by the Initial Developer are Copyright (C) 2002
+ * the Initial Developer. All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebKitAccessibleInterfaceSelection.h"
+
+#include "AccessibilityListBox.h"
+#include "AccessibilityObject.h"
+#include "HTMLSelectElement.h"
+#include "RenderObject.h"
+#include "WebKitAccessibleWrapperAtk.h"
+
+using namespace WebCore;
+
+static AccessibilityObject* core(AtkSelection* selection)
+{
+ if (!WEBKIT_IS_ACCESSIBLE(selection))
+ return 0;
+
+ return webkitAccessibleGetAccessibilityObject(WEBKIT_ACCESSIBLE(selection));
+}
+
+static AccessibilityObject* listObjectForSelection(AtkSelection* selection)
+{
+ AccessibilityObject* coreSelection = core(selection);
+
+ // Only list boxes and menu lists supported so far.
+ if (!coreSelection->isListBox() && !coreSelection->isMenuList())
+ return 0;
+
+ // For list boxes the list object is just itself.
+ if (coreSelection->isListBox())
+ return coreSelection;
+
+ // For menu lists we need to return the first accessible child,
+ // with role MenuListPopupRole, since that's the one holding the list
+ // of items with role MenuListOptionRole.
+ AccessibilityObject::AccessibilityChildrenVector children = coreSelection->children();
+ if (!children.size())
+ return 0;
+
+ AccessibilityObject* listObject = children.at(0).get();
+ if (!listObject->isMenuListPopup())
+ return 0;
+
+ return listObject;
+}
+
+static AccessibilityObject* optionFromList(AtkSelection* selection, gint index)
+{
+ AccessibilityObject* coreSelection = core(selection);
+ if (!coreSelection || index < 0)
+ return 0;
+
+ // Need to select the proper list object depending on the type.
+ AccessibilityObject* listObject = listObjectForSelection(selection);
+ if (!listObject)
+ return 0;
+
+ AccessibilityObject::AccessibilityChildrenVector options = listObject->children();
+ if (index < static_cast<gint>(options.size()))
+ return options.at(index).get();
+
+ return 0;
+}
+
+static AccessibilityObject* optionFromSelection(AtkSelection* selection, gint index)
+{
+ // i is the ith selection as opposed to the ith child.
+
+ AccessibilityObject* coreSelection = core(selection);
+ if (!coreSelection || !coreSelection->isAccessibilityRenderObject() || index < 0)
+ return 0;
+
+ AccessibilityObject::AccessibilityChildrenVector selectedItems;
+ if (coreSelection->isListBox())
+ coreSelection->selectedChildren(selectedItems);
+ else if (coreSelection->isMenuList()) {
+ RenderObject* renderer = coreSelection->renderer();
+ if (!renderer)
+ return 0;
+
+ HTMLSelectElement* selectNode = toHTMLSelectElement(renderer->node());
+ int selectedIndex = selectNode->selectedIndex();
+ const Vector<HTMLElement*> listItems = selectNode->listItems();
+
+ if (selectedIndex < 0 || selectedIndex >= static_cast<int>(listItems.size()))
+ return 0;
+
+ return optionFromList(selection, selectedIndex);
+ }
+
+ if (index < static_cast<gint>(selectedItems.size()))
+ return selectedItems.at(index).get();
+
+ return 0;
+}
+
+void webkitAccessibleSelectionInterfaceInit(AtkSelectionIface* iface)
+{
+ iface->add_selection = webkitAccessibleSelectionAddSelection;
+ iface->clear_selection = webkitAccessibleSelectionClearSelection;
+ iface->ref_selection = webkitAccessibleSelectionRefSelection;
+ iface->get_selection_count = webkitAccessibleSelectionGetSelectionCount;
+ iface->is_child_selected = webkitAccessibleSelectionIsChildSelected;
+ iface->remove_selection = webkitAccessibleSelectionRemoveSelection;
+ iface->select_all_selection = webkitAccessibleSelectionSelectAllSelection;
+}
+
+gboolean webkitAccessibleSelectionAddSelection(AtkSelection* selection, gint index)
+{
+ AccessibilityObject* coreSelection = core(selection);
+ if (!coreSelection)
+ return FALSE;
+
+ AccessibilityObject* option = optionFromList(selection, index);
+ if (option && (coreSelection->isListBox() || coreSelection->isMenuList())) {
+ option->setSelected(true);
+ return option->isSelected();
+ }
+
+ return FALSE;
+}
+
+gboolean webkitAccessibleSelectionClearSelection(AtkSelection* selection)
+{
+ AccessibilityObject* coreSelection = core(selection);
+ if (!coreSelection)
+ return FALSE;
+
+ AccessibilityObject::AccessibilityChildrenVector selectedItems;
+ if (coreSelection->isListBox() || coreSelection->isMenuList()) {
+ // Set the list of selected items to an empty list; then verify that it worked.
+ AccessibilityListBox* listBox = static_cast<AccessibilityListBox*>(coreSelection);
+ listBox->setSelectedChildren(selectedItems);
+ listBox->selectedChildren(selectedItems);
+ return !selectedItems.size();
+ }
+ return FALSE;
+}
+
+AtkObject* webkitAccessibleSelectionRefSelection(AtkSelection* selection, gint index)
+{
+ AccessibilityObject* option = optionFromSelection(selection, index);
+ if (option) {
+ AtkObject* child = option->wrapper();
+ g_object_ref(child);
+ return child;
+ }
+
+ return 0;
+}
+
+gint webkitAccessibleSelectionGetSelectionCount(AtkSelection* selection)
+{
+ AccessibilityObject* coreSelection = core(selection);
+ if (!coreSelection || !coreSelection->isAccessibilityRenderObject())
+ return 0;
+
+ if (coreSelection->isListBox()) {
+ AccessibilityObject::AccessibilityChildrenVector selectedItems;
+ coreSelection->selectedChildren(selectedItems);
+ return static_cast<gint>(selectedItems.size());
+ }
+
+ if (coreSelection->isMenuList()) {
+ RenderObject* renderer = coreSelection->renderer();
+ if (!renderer)
+ return 0;
+
+ int selectedIndex = toHTMLSelectElement(renderer->node())->selectedIndex();
+ return selectedIndex >= 0 && selectedIndex < static_cast<int>(toHTMLSelectElement(renderer->node())->listItems().size());
+ }
+
+ return 0;
+}
+
+gboolean webkitAccessibleSelectionIsChildSelected(AtkSelection* selection, gint index)
+{
+ AccessibilityObject* coreSelection = core(selection);
+ if (!coreSelection)
+ return 0;
+
+ AccessibilityObject* option = optionFromList(selection, index);
+ if (option && (coreSelection->isListBox() || coreSelection->isMenuList()))
+ return option->isSelected();
+
+ return FALSE;
+}
+
+gboolean webkitAccessibleSelectionRemoveSelection(AtkSelection* selection, gint index)
+{
+ AccessibilityObject* coreSelection = core(selection);
+ if (!coreSelection)
+ return 0;
+
+ // TODO: This is only getting called if i == 0. What is preventing the rest?
+ AccessibilityObject* option = optionFromSelection(selection, index);
+ if (option && (coreSelection->isListBox() || coreSelection->isMenuList())) {
+ option->setSelected(false);
+ return !option->isSelected();
+ }
+
+ return FALSE;
+}
+
+gboolean webkitAccessibleSelectionSelectAllSelection(AtkSelection* selection)
+{
+ AccessibilityObject* coreSelection = core(selection);
+ if (!coreSelection || !coreSelection->isMultiSelectable())
+ return FALSE;
+
+ AccessibilityObject::AccessibilityChildrenVector children = coreSelection->children();
+ if (coreSelection->isListBox()) {
+ AccessibilityListBox* listBox = static_cast<AccessibilityListBox*>(coreSelection);
+ listBox->setSelectedChildren(children);
+ AccessibilityObject::AccessibilityChildrenVector selectedItems;
+ listBox->selectedChildren(selectedItems);
+ return selectedItems.size() == children.size();
+ }
+
+ return FALSE;
+}
Added: trunk/Source/WebCore/accessibility/gtk/WebKitAccessibleInterfaceSelection.h (0 => 105727)
--- trunk/Source/WebCore/accessibility/gtk/WebKitAccessibleInterfaceSelection.h (rev 0)
+++ trunk/Source/WebCore/accessibility/gtk/WebKitAccessibleInterfaceSelection.h 2012-01-24 12:25:13 UTC (rev 105727)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2008 Nuanti Ltd.
+ * Copyright (C) 2009 Jan Alonzo
+ * Copyright (C) 2010, 2011, 2012 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef WebKitAccessibleInterfaceSelection_h
+#define WebKitAccessibleInterfaceSelection_h
+
+#include <atk/atk.h>
+
+void webkitAccessibleSelectionInterfaceInit(AtkSelectionIface*);
+gboolean webkitAccessibleSelectionAddSelection(AtkSelection*, gint index);
+gboolean webkitAccessibleSelectionClearSelection(AtkSelection*);
+AtkObject* webkitAccessibleSelectionRefSelection(AtkSelection*, gint index);
+gint webkitAccessibleSelectionGetSelectionCount(AtkSelection*);
+gboolean webkitAccessibleSelectionIsChildSelected(AtkSelection*, gint index);
+gboolean webkitAccessibleSelectionRemoveSelection(AtkSelection*, gint index);
+gboolean webkitAccessibleSelectionSelectAllSelection(AtkSelection*);
+
+#endif // WebKitAccessibleInterfaceSelection_h
Modified: trunk/Source/WebCore/accessibility/gtk/WebKitAccessibleWrapperAtk.cpp (105726 => 105727)
--- trunk/Source/WebCore/accessibility/gtk/WebKitAccessibleWrapperAtk.cpp 2012-01-24 12:04:16 UTC (rev 105726)
+++ trunk/Source/WebCore/accessibility/gtk/WebKitAccessibleWrapperAtk.cpp 2012-01-24 12:25:13 UTC (rev 105727)
@@ -70,6 +70,7 @@
#include "WebKitAccessibleInterfaceHyperlinkImpl.h"
#include "WebKitAccessibleInterfaceHypertext.h"
#include "WebKitAccessibleInterfaceImage.h"
+#include "WebKitAccessibleInterfaceSelection.h"
#include "WebKitAccessibleUtil.h"
#include "htmlediting.h"
#include "visible_units.h"
@@ -114,11 +115,6 @@
return core(WEBKIT_ACCESSIBLE(object));
}
-static AccessibilityObject* core(AtkSelection* selection)
-{
- return core(ATK_OBJECT(selection));
-}
-
static AccessibilityObject* core(AtkText* text)
{
return core(ATK_OBJECT(text));
@@ -831,210 +827,6 @@
return type_volatile;
}
-// Selection (for controls)
-
-static AccessibilityObject* listObjectForSelection(AtkSelection* selection)
-{
- AccessibilityObject* coreSelection = core(selection);
-
- // Only list boxes and menu lists supported so far.
- if (!coreSelection->isListBox() && !coreSelection->isMenuList())
- return 0;
-
- // For list boxes the list object is just itself.
- if (coreSelection->isListBox())
- return coreSelection;
-
- // For menu lists we need to return the first accessible child,
- // with role MenuListPopupRole, since that's the one holding the list
- // of items with role MenuListOptionRole.
- AccessibilityObject::AccessibilityChildrenVector children = coreSelection->children();
- if (!children.size())
- return 0;
-
- AccessibilityObject* listObject = children.at(0).get();
- if (!listObject->isMenuListPopup())
- return 0;
-
- return listObject;
-}
-
-static AccessibilityObject* optionFromList(AtkSelection* selection, gint i)
-{
- AccessibilityObject* coreSelection = core(selection);
- if (!coreSelection || i < 0)
- return 0;
-
- // Need to select the proper list object depending on the type.
- AccessibilityObject* listObject = listObjectForSelection(selection);
- if (!listObject)
- return 0;
-
- AccessibilityObject::AccessibilityChildrenVector options = listObject->children();
- if (i < static_cast<gint>(options.size()))
- return options.at(i).get();
-
- return 0;
-}
-
-static AccessibilityObject* optionFromSelection(AtkSelection* selection, gint i)
-{
- // i is the ith selection as opposed to the ith child.
-
- AccessibilityObject* coreSelection = core(selection);
- if (!coreSelection || !coreSelection->isAccessibilityRenderObject() || i < 0)
- return 0;
-
- AccessibilityObject::AccessibilityChildrenVector selectedItems;
- if (coreSelection->isListBox())
- coreSelection->selectedChildren(selectedItems);
- else if (coreSelection->isMenuList()) {
- RenderObject* renderer = coreSelection->renderer();
- if (!renderer)
- return 0;
-
- HTMLSelectElement* selectNode = toHTMLSelectElement(renderer->node());
- int selectedIndex = selectNode->selectedIndex();
- const Vector<HTMLElement*> listItems = selectNode->listItems();
-
- if (selectedIndex < 0 || selectedIndex >= static_cast<int>(listItems.size()))
- return 0;
-
- return optionFromList(selection, selectedIndex);
- }
-
- if (i < static_cast<gint>(selectedItems.size()))
- return selectedItems.at(i).get();
-
- return 0;
-}
-
-static gboolean webkit_accessible_selection_add_selection(AtkSelection* selection, gint i)
-{
- AccessibilityObject* coreSelection = core(selection);
- if (!coreSelection)
- return false;
-
- AccessibilityObject* option = optionFromList(selection, i);
- if (option && (coreSelection->isListBox() || coreSelection->isMenuList())) {
- option->setSelected(true);
- return option->isSelected();
- }
-
- return false;
-}
-
-static gboolean webkit_accessible_selection_clear_selection(AtkSelection* selection)
-{
- AccessibilityObject* coreSelection = core(selection);
- if (!coreSelection)
- return false;
-
- AccessibilityObject::AccessibilityChildrenVector selectedItems;
- if (coreSelection->isListBox() || coreSelection->isMenuList()) {
- // Set the list of selected items to an empty list; then verify that it worked.
- AccessibilityListBox* listBox = static_cast<AccessibilityListBox*>(coreSelection);
- listBox->setSelectedChildren(selectedItems);
- listBox->selectedChildren(selectedItems);
- return !selectedItems.size();
- }
- return false;
-}
-
-static AtkObject* webkit_accessible_selection_ref_selection(AtkSelection* selection, gint i)
-{
- AccessibilityObject* option = optionFromSelection(selection, i);
- if (option) {
- AtkObject* child = option->wrapper();
- g_object_ref(child);
- return child;
- }
-
- return 0;
-}
-
-static gint webkit_accessible_selection_get_selection_count(AtkSelection* selection)
-{
- AccessibilityObject* coreSelection = core(selection);
- if (!coreSelection || !coreSelection->isAccessibilityRenderObject())
- return 0;
-
- if (coreSelection->isListBox()) {
- AccessibilityObject::AccessibilityChildrenVector selectedItems;
- coreSelection->selectedChildren(selectedItems);
- return static_cast<gint>(selectedItems.size());
- }
-
- if (coreSelection->isMenuList()) {
- RenderObject* renderer = coreSelection->renderer();
- if (!renderer)
- return 0;
-
- int selectedIndex = toHTMLSelectElement(renderer->node())->selectedIndex();
- return selectedIndex >= 0 && selectedIndex < static_cast<int>(toHTMLSelectElement(renderer->node())->listItems().size());
- }
-
- return 0;
-}
-
-static gboolean webkit_accessible_selection_is_child_selected(AtkSelection* selection, gint i)
-{
- AccessibilityObject* coreSelection = core(selection);
- if (!coreSelection)
- return 0;
-
- AccessibilityObject* option = optionFromList(selection, i);
- if (option && (coreSelection->isListBox() || coreSelection->isMenuList()))
- return option->isSelected();
-
- return false;
-}
-
-static gboolean webkit_accessible_selection_remove_selection(AtkSelection* selection, gint i)
-{
- AccessibilityObject* coreSelection = core(selection);
- if (!coreSelection)
- return 0;
-
- // TODO: This is only getting called if i == 0. What is preventing the rest?
- AccessibilityObject* option = optionFromSelection(selection, i);
- if (option && (coreSelection->isListBox() || coreSelection->isMenuList())) {
- option->setSelected(false);
- return !option->isSelected();
- }
-
- return false;
-}
-
-static gboolean webkit_accessible_selection_select_all_selection(AtkSelection* selection)
-{
- AccessibilityObject* coreSelection = core(selection);
- if (!coreSelection || !coreSelection->isMultiSelectable())
- return false;
-
- AccessibilityObject::AccessibilityChildrenVector children = coreSelection->children();
- if (coreSelection->isListBox()) {
- AccessibilityListBox* listBox = static_cast<AccessibilityListBox*>(coreSelection);
- listBox->setSelectedChildren(children);
- AccessibilityObject::AccessibilityChildrenVector selectedItems;
- listBox->selectedChildren(selectedItems);
- return selectedItems.size() == children.size();
- }
-
- return false;
-}
-
-static void atk_selection_interface_init(AtkSelectionIface* iface)
-{
- iface->add_selection = webkit_accessible_selection_add_selection;
- iface->clear_selection = webkit_accessible_selection_clear_selection;
- iface->ref_selection = webkit_accessible_selection_ref_selection;
- iface->get_selection_count = webkit_accessible_selection_get_selection_count;
- iface->is_child_selected = webkit_accessible_selection_is_child_selected;
- iface->remove_selection = webkit_accessible_selection_remove_selection;
- iface->select_all_selection = webkit_accessible_selection_select_all_selection;
-}
-
// Text
static gchar* utf8Substr(const gchar* string, gint start, gint end)
@@ -2086,8 +1878,7 @@
static const GInterfaceInfo AtkInterfacesInitFunctions[] = {
{reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleActionInterfaceInit), 0, 0},
- {(GInterfaceInitFunc)atk_selection_interface_init,
- (GInterfaceFinalizeFunc) 0, 0},
+ {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleSelectionInterfaceInit), 0, 0},
{reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleEditableTextInterfaceInit), 0, 0},
{(GInterfaceInitFunc)atk_text_interface_init,
(GInterfaceFinalizeFunc) 0, 0},