summaryrefslogtreecommitdiffstats
path: root/WebCore/accessibility
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/accessibility')
-rw-r--r--WebCore/accessibility/AXObjectCache.cpp341
-rw-r--r--WebCore/accessibility/AXObjectCache.h130
-rw-r--r--WebCore/accessibility/AccessibilityARIAGrid.cpp154
-rw-r--r--WebCore/accessibility/AccessibilityARIAGrid.h60
-rw-r--r--WebCore/accessibility/AccessibilityARIAGridCell.cpp96
-rw-r--r--WebCore/accessibility/AccessibilityARIAGridCell.h55
-rw-r--r--WebCore/accessibility/AccessibilityARIAGridRow.cpp75
-rw-r--r--WebCore/accessibility/AccessibilityARIAGridRow.h50
-rw-r--r--WebCore/accessibility/AccessibilityImageMapLink.cpp138
-rw-r--r--WebCore/accessibility/AccessibilityImageMapLink.h73
-rw-r--r--WebCore/accessibility/AccessibilityList.cpp94
-rw-r--r--WebCore/accessibility/AccessibilityList.h62
-rw-r--r--WebCore/accessibility/AccessibilityListBox.cpp181
-rw-r--r--WebCore/accessibility/AccessibilityListBox.h66
-rw-r--r--WebCore/accessibility/AccessibilityListBoxOption.cpp207
-rw-r--r--WebCore/accessibility/AccessibilityListBoxOption.h79
-rw-r--r--WebCore/accessibility/AccessibilityObject.cpp1036
-rw-r--r--WebCore/accessibility/AccessibilityObject.h432
-rw-r--r--WebCore/accessibility/AccessibilityRenderObject.cpp2539
-rw-r--r--WebCore/accessibility/AccessibilityRenderObject.h245
-rw-r--r--WebCore/accessibility/AccessibilityTable.cpp489
-rw-r--r--WebCore/accessibility/AccessibilityTable.h93
-rw-r--r--WebCore/accessibility/AccessibilityTableCell.cpp162
-rw-r--r--WebCore/accessibility/AccessibilityTableCell.h65
-rw-r--r--WebCore/accessibility/AccessibilityTableColumn.cpp185
-rw-r--r--WebCore/accessibility/AccessibilityTableColumn.h75
-rw-r--r--WebCore/accessibility/AccessibilityTableHeaderContainer.cpp87
-rw-r--r--WebCore/accessibility/AccessibilityTableHeaderContainer.h67
-rw-r--r--WebCore/accessibility/AccessibilityTableRow.cpp118
-rw-r--r--WebCore/accessibility/AccessibilityTableRow.h65
-rw-r--r--WebCore/accessibility/chromium/AXObjectCacheChromium.cpp54
-rw-r--r--WebCore/accessibility/chromium/AccessibilityObjectChromium.cpp37
-rw-r--r--WebCore/accessibility/chromium/AccessibilityObjectWrapper.h54
-rw-r--r--WebCore/accessibility/gtk/AXObjectCacheAtk.cpp62
-rw-r--r--WebCore/accessibility/gtk/AccessibilityObjectAtk.cpp56
-rw-r--r--WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp1189
-rw-r--r--WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.h62
-rw-r--r--WebCore/accessibility/mac/AXObjectCacheMac.mm69
-rw-r--r--WebCore/accessibility/mac/AccessibilityObjectMac.mm42
-rw-r--r--WebCore/accessibility/mac/AccessibilityObjectWrapper.h60
-rw-r--r--WebCore/accessibility/mac/AccessibilityObjectWrapper.mm2147
-rw-r--r--WebCore/accessibility/qt/AccessibilityObjectQt.cpp34
-rw-r--r--WebCore/accessibility/win/AXObjectCacheWin.cpp57
-rw-r--r--WebCore/accessibility/win/AccessibilityObjectWin.cpp40
-rw-r--r--WebCore/accessibility/win/AccessibilityObjectWrapperWin.h54
-rw-r--r--WebCore/accessibility/wx/AccessibilityObjectWx.cpp34
46 files changed, 11570 insertions, 0 deletions
diff --git a/WebCore/accessibility/AXObjectCache.cpp b/WebCore/accessibility/AXObjectCache.cpp
new file mode 100644
index 0000000..ec250ed
--- /dev/null
+++ b/WebCore/accessibility/AXObjectCache.cpp
@@ -0,0 +1,341 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "AXObjectCache.h"
+
+#include "AccessibilityARIAGrid.h"
+#include "AccessibilityARIAGridRow.h"
+#include "AccessibilityARIAGridCell.h"
+#include "AccessibilityList.h"
+#include "AccessibilityListBox.h"
+#include "AccessibilityListBoxOption.h"
+#include "AccessibilityImageMapLink.h"
+#include "AccessibilityRenderObject.h"
+#include "AccessibilityTable.h"
+#include "AccessibilityTableCell.h"
+#include "AccessibilityTableColumn.h"
+#include "AccessibilityTableHeaderContainer.h"
+#include "AccessibilityTableRow.h"
+#include "HTMLNames.h"
+#include "RenderObject.h"
+#include "RenderView.h"
+
+#include <wtf/PassRefPtr.h>
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+bool AXObjectCache::gAccessibilityEnabled = false;
+bool AXObjectCache::gAccessibilityEnhancedUserInterfaceEnabled = false;
+
+AXObjectCache::AXObjectCache()
+ : m_notificationPostTimer(this, &AXObjectCache::notificationPostTimerFired)
+{
+}
+
+AXObjectCache::~AXObjectCache()
+{
+ HashMap<AXID, RefPtr<AccessibilityObject> >::iterator end = m_objects.end();
+ for (HashMap<AXID, RefPtr<AccessibilityObject> >::iterator it = m_objects.begin(); it != end; ++it) {
+ AccessibilityObject* obj = (*it).second.get();
+ detachWrapper(obj);
+ obj->detach();
+ removeAXID(obj);
+ }
+}
+
+AccessibilityObject* AXObjectCache::get(RenderObject* renderer)
+{
+ if (!renderer)
+ return 0;
+
+ AccessibilityObject* obj = 0;
+ AXID axID = m_renderObjectMapping.get(renderer);
+ ASSERT(!HashTraits<AXID>::isDeletedValue(axID));
+
+ if (axID)
+ obj = m_objects.get(axID).get();
+
+ return obj;
+}
+
+bool AXObjectCache::nodeIsAriaType(Node* node, String role)
+{
+ if (!node || !node->isElementNode())
+ return false;
+
+ return equalIgnoringCase(static_cast<Element*>(node)->getAttribute(roleAttr), role);
+}
+
+AccessibilityObject* AXObjectCache::getOrCreate(RenderObject* renderer)
+{
+ if (!renderer)
+ return 0;
+
+ AccessibilityObject* obj = get(renderer);
+
+ if (!obj) {
+ Node* node = renderer->node();
+ RefPtr<AccessibilityObject> newObj = 0;
+ if (renderer->isListBox())
+ newObj = AccessibilityListBox::create(renderer);
+ else if (node && (node->hasTagName(ulTag) || node->hasTagName(olTag) || node->hasTagName(dlTag)))
+ newObj = AccessibilityList::create(renderer);
+
+ // aria tables
+ else if (nodeIsAriaType(node, "grid"))
+ newObj = AccessibilityARIAGrid::create(renderer);
+ else if (nodeIsAriaType(node, "row"))
+ newObj = AccessibilityARIAGridRow::create(renderer);
+ else if (nodeIsAriaType(node, "gridcell") || nodeIsAriaType(node, "columnheader") || nodeIsAriaType(node, "rowheader"))
+ newObj = AccessibilityARIAGridCell::create(renderer);
+
+ // standard tables
+ else if (renderer->isTable())
+ newObj = AccessibilityTable::create(renderer);
+ else if (renderer->isTableRow())
+ newObj = AccessibilityTableRow::create(renderer);
+ else if (renderer->isTableCell())
+ newObj = AccessibilityTableCell::create(renderer);
+
+ else
+ newObj = AccessibilityRenderObject::create(renderer);
+
+ obj = newObj.get();
+
+ getAXID(obj);
+
+ m_renderObjectMapping.set(renderer, obj->axObjectID());
+ m_objects.set(obj->axObjectID(), obj);
+ attachWrapper(obj);
+ }
+
+ return obj;
+}
+
+AccessibilityObject* AXObjectCache::getOrCreate(AccessibilityRole role)
+{
+ RefPtr<AccessibilityObject> obj = 0;
+
+ // will be filled in...
+ switch (role) {
+ case ListBoxOptionRole:
+ obj = AccessibilityListBoxOption::create();
+ break;
+ case ImageMapLinkRole:
+ obj = AccessibilityImageMapLink::create();
+ break;
+ case ColumnRole:
+ obj = AccessibilityTableColumn::create();
+ break;
+ case TableHeaderContainerRole:
+ obj = AccessibilityTableHeaderContainer::create();
+ break;
+ default:
+ obj = 0;
+ }
+
+ if (obj)
+ getAXID(obj.get());
+ else
+ return 0;
+
+ m_objects.set(obj->axObjectID(), obj);
+ attachWrapper(obj.get());
+ return obj.get();
+}
+
+void AXObjectCache::remove(AXID axID)
+{
+ if (!axID)
+ return;
+
+ // first fetch object to operate some cleanup functions on it
+ AccessibilityObject* obj = m_objects.get(axID).get();
+ if (!obj)
+ return;
+
+ detachWrapper(obj);
+ obj->detach();
+ removeAXID(obj);
+
+ // finally remove the object
+ if (!m_objects.take(axID)) {
+ return;
+ }
+
+ ASSERT(m_objects.size() >= m_idsInUse.size());
+}
+
+void AXObjectCache::remove(RenderObject* renderer)
+{
+ if (!renderer)
+ return;
+
+ AXID axID = m_renderObjectMapping.get(renderer);
+ remove(axID);
+ m_renderObjectMapping.remove(renderer);
+}
+
+AXID AXObjectCache::getAXID(AccessibilityObject* obj)
+{
+ // check for already-assigned ID
+ AXID objID = obj->axObjectID();
+ if (objID) {
+ ASSERT(m_idsInUse.contains(objID));
+ return objID;
+ }
+
+ // generate a new ID
+ static AXID lastUsedID = 0;
+ objID = lastUsedID;
+ do
+ ++objID;
+ while (objID == 0 || HashTraits<AXID>::isDeletedValue(objID) || m_idsInUse.contains(objID));
+ m_idsInUse.add(objID);
+ lastUsedID = objID;
+ obj->setAXObjectID(objID);
+
+ return objID;
+}
+
+void AXObjectCache::removeAXID(AccessibilityObject* obj)
+{
+ if (!obj)
+ return;
+
+ AXID objID = obj->axObjectID();
+ if (objID == 0)
+ return;
+ ASSERT(!HashTraits<AXID>::isDeletedValue(objID));
+ ASSERT(m_idsInUse.contains(objID));
+ obj->setAXObjectID(0);
+ m_idsInUse.remove(objID);
+}
+
+void AXObjectCache::childrenChanged(RenderObject* renderer)
+{
+ if (!renderer)
+ return;
+
+ AXID axID = m_renderObjectMapping.get(renderer);
+ if (!axID)
+ return;
+
+ AccessibilityObject* obj = m_objects.get(axID).get();
+ if (obj)
+ obj->childrenChanged();
+}
+
+void AXObjectCache::notificationPostTimerFired(Timer<AXObjectCache>*)
+{
+ m_notificationPostTimer.stop();
+
+ unsigned i = 0, count = m_notificationsToPost.size();
+ for (i = 0; i < count; ++i) {
+ AccessibilityObject* obj = m_notificationsToPost[i].first;
+#ifndef NDEBUG
+ // Make sure none of the render views are in the process of being layed out.
+ // Notifications should only be sent after the renderer has finished
+ if (obj->isAccessibilityRenderObject()) {
+ AccessibilityRenderObject* renderObj = static_cast<AccessibilityRenderObject*>(obj);
+ RenderObject* renderer = renderObj->renderer();
+ if (renderer && renderer->view())
+ ASSERT(!renderer->view()->layoutState());
+ }
+#endif
+
+ postPlatformNotification(obj, m_notificationsToPost[i].second);
+ }
+
+ m_notificationsToPost.clear();
+}
+
+#if HAVE(ACCESSIBILITY)
+void AXObjectCache::postNotification(RenderObject* renderer, const String& message, bool postToElement)
+{
+ // Notifications for text input objects are sent to that object.
+ // All others are sent to the top WebArea.
+ if (!renderer)
+ return;
+
+ // Get an accessibility object that already exists. One should not be created here
+ // because a render update may be in progress and creating an AX object can re-trigger a layout
+ RefPtr<AccessibilityObject> obj = get(renderer);
+ while (!obj && renderer) {
+ renderer = renderer->parent();
+ obj = get(renderer);
+ }
+
+ if (!renderer)
+ return;
+
+ if (obj && !postToElement)
+ obj = obj->observableObject();
+
+ Document* document = renderer->document();
+ if (!obj && document)
+ obj = get(document->renderer());
+
+ if (!obj)
+ return;
+
+ m_notificationsToPost.append(make_pair(obj.get(), message));
+ if (!m_notificationPostTimer.isActive())
+ m_notificationPostTimer.startOneShot(0);
+}
+
+void AXObjectCache::selectedChildrenChanged(RenderObject* renderer)
+{
+ postNotification(renderer, "AXSelectedChildrenChanged", true);
+}
+#endif
+
+#if HAVE(ACCESSIBILITY)
+void AXObjectCache::handleActiveDescendantChanged(RenderObject* renderer)
+{
+ if (!renderer)
+ return;
+ AccessibilityObject* obj = getOrCreate(renderer);
+ if (obj)
+ obj->handleActiveDescendantChanged();
+}
+
+void AXObjectCache::handleAriaRoleChanged(RenderObject* renderer)
+{
+ if (!renderer)
+ return;
+ AccessibilityObject* obj = getOrCreate(renderer);
+ if (obj && obj->isAccessibilityRenderObject())
+ static_cast<AccessibilityRenderObject*>(obj)->setAriaRole();
+}
+#endif
+
+} // namespace WebCore
diff --git a/WebCore/accessibility/AXObjectCache.h b/WebCore/accessibility/AXObjectCache.h
new file mode 100644
index 0000000..904283c
--- /dev/null
+++ b/WebCore/accessibility/AXObjectCache.h
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2003, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef AXObjectCache_h
+#define AXObjectCache_h
+
+#include "AccessibilityObject.h"
+#include "EventHandler.h"
+#include "Timer.h"
+#include <limits.h>
+#include <wtf/HashMap.h>
+#include <wtf/HashSet.h>
+#include <wtf/RefPtr.h>
+
+#ifdef __OBJC__
+@class WebCoreTextMarker;
+#else
+class WebCoreTextMarker;
+#endif
+
+namespace WebCore {
+
+ class RenderObject;
+ class String;
+ class VisiblePosition;
+ class AccessibilityObject;
+ class Node;
+
+ typedef unsigned AXID;
+
+ struct TextMarkerData {
+ AXID axID;
+ Node* node;
+ int offset;
+ EAffinity affinity;
+ };
+
+ class AXObjectCache {
+ public:
+ AXObjectCache();
+ ~AXObjectCache();
+
+ // to be used with render objects
+ AccessibilityObject* getOrCreate(RenderObject*);
+
+ // used for objects without backing elements
+ AccessibilityObject* getOrCreate(AccessibilityRole);
+
+ // will only return the AccessibilityObject if it already exists
+ AccessibilityObject* get(RenderObject*);
+
+ void remove(RenderObject*);
+ void remove(AXID);
+
+ void detachWrapper(AccessibilityObject*);
+ void attachWrapper(AccessibilityObject*);
+ void postNotification(RenderObject*, const String&, bool postToElement);
+ void postPlatformNotification(AccessibilityObject*, const String&);
+ void childrenChanged(RenderObject*);
+ void selectedChildrenChanged(RenderObject*);
+ void handleActiveDescendantChanged(RenderObject*);
+ void handleAriaRoleChanged(RenderObject*);
+ void handleFocusedUIElementChanged();
+#if PLATFORM(GTK)
+ void handleFocusedUIElementChangedWithRenderers(RenderObject*, RenderObject*);
+#endif
+ static void enableAccessibility() { gAccessibilityEnabled = true; }
+ static void enableEnhancedUserInterfaceAccessibility() { gAccessibilityEnhancedUserInterfaceEnabled = true; }
+
+ static bool accessibilityEnabled() { return gAccessibilityEnabled; }
+ static bool accessibilityEnhancedUserInterfaceEnabled() { return gAccessibilityEnhancedUserInterfaceEnabled; }
+
+ void removeAXID(AccessibilityObject*);
+ bool isIDinUse(AXID id) const { return m_idsInUse.contains(id); }
+
+ private:
+ HashMap<AXID, RefPtr<AccessibilityObject> > m_objects;
+ HashMap<RenderObject*, AXID> m_renderObjectMapping;
+ static bool gAccessibilityEnabled;
+ static bool gAccessibilityEnhancedUserInterfaceEnabled;
+
+ HashSet<AXID> m_idsInUse;
+
+ Timer<AXObjectCache> m_notificationPostTimer;
+ Vector<pair<AccessibilityObject*, const String> > m_notificationsToPost;
+ void notificationPostTimerFired(Timer<AXObjectCache>*);
+
+ AXID getAXID(AccessibilityObject*);
+ bool nodeIsAriaType(Node* node, String role);
+ };
+
+#if !HAVE(ACCESSIBILITY)
+ inline void AXObjectCache::handleActiveDescendantChanged(RenderObject*) { }
+ inline void AXObjectCache::handleAriaRoleChanged(RenderObject*) { }
+ inline void AXObjectCache::handleFocusedUIElementChanged() { }
+ inline void AXObjectCache::detachWrapper(AccessibilityObject*) { }
+ inline void AXObjectCache::attachWrapper(AccessibilityObject*) { }
+ inline void AXObjectCache::selectedChildrenChanged(RenderObject*) { }
+ inline void AXObjectCache::postNotification(RenderObject*, const String&, bool postToElement) { }
+ inline void AXObjectCache::postPlatformNotification(AccessibilityObject*, const String&) { }
+#if PLATFORM(GTK)
+ inline void AXObjectCache::handleFocusedUIElementChangedWithRenderers(RenderObject*, RenderObject*) { }
+#endif
+#endif
+
+}
+
+#endif
diff --git a/WebCore/accessibility/AccessibilityARIAGrid.cpp b/WebCore/accessibility/AccessibilityARIAGrid.cpp
new file mode 100644
index 0000000..69c4512
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityARIAGrid.cpp
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2009 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "AccessibilityARIAGrid.h"
+
+#include "AccessibilityTableCell.h"
+#include "AccessibilityTableColumn.h"
+#include "AccessibilityTableHeaderContainer.h"
+#include "AccessibilityTableRow.h"
+#include "AXObjectCache.h"
+#include "RenderObject.h"
+
+using namespace std;
+
+namespace WebCore {
+
+AccessibilityARIAGrid::AccessibilityARIAGrid(RenderObject* renderer)
+ : AccessibilityTable(renderer)
+{
+#if ACCESSIBILITY_TABLES
+ m_isAccessibilityTable = true;
+#else
+ m_isAccessibilityTable = false;
+#endif
+}
+
+AccessibilityARIAGrid::~AccessibilityARIAGrid()
+{
+}
+
+PassRefPtr<AccessibilityARIAGrid> AccessibilityARIAGrid::create(RenderObject* renderer)
+{
+ return adoptRef(new AccessibilityARIAGrid(renderer));
+}
+
+void AccessibilityARIAGrid::addChild(AccessibilityObject* child, HashSet<AccessibilityObject*>& appendedRows, unsigned& columnCount)
+{
+ if (!child || !child->isTableRow() || child->ariaRoleAttribute() != RowRole)
+ return;
+
+ AccessibilityTableRow* row = static_cast<AccessibilityTableRow*>(child);
+ if (appendedRows.contains(row))
+ return;
+
+ // store the maximum number of columns
+ unsigned rowCellCount = row->children().size();
+ if (rowCellCount > columnCount)
+ columnCount = rowCellCount;
+
+ row->setRowIndex((int)m_rows.size());
+ m_rows.append(row);
+ m_children.append(row);
+ appendedRows.add(row);
+}
+
+void AccessibilityARIAGrid::addChildren()
+{
+ ASSERT(!m_haveChildren);
+
+ if (!isDataTable()) {
+ AccessibilityRenderObject::addChildren();
+ return;
+ }
+
+ m_haveChildren = true;
+ if (!m_renderer)
+ return;
+
+ AXObjectCache* axCache = m_renderer->document()->axObjectCache();
+
+ // add only rows that are labeled as aria rows
+ HashSet<AccessibilityObject*> appendedRows;
+ unsigned columnCount = 0;
+ for (RefPtr<AccessibilityObject> child = firstChild(); child; child = child->nextSibling()) {
+
+ // in case the render tree doesn't match the expected ARIA hierarchy, look at the children
+ if (child->accessibilityIsIgnored()) {
+ if (!child->hasChildren())
+ child->addChildren();
+
+ AccessibilityChildrenVector children = child->children();
+ unsigned length = children.size();
+ for (unsigned i = 0; i < length; ++i)
+ addChild(children[i].get(), appendedRows, columnCount);
+ } else
+ addChild(child.get(), appendedRows, columnCount);
+ }
+
+ // make the columns based on the number of columns in the first body
+ for (unsigned i = 0; i < columnCount; ++i) {
+ AccessibilityTableColumn* column = static_cast<AccessibilityTableColumn*>(axCache->getOrCreate(ColumnRole));
+ column->setColumnIndex((int)i);
+ column->setParentTable(this);
+ m_columns.append(column);
+ m_children.append(column);
+ }
+
+ AccessibilityObject* headerContainerObject = headerContainer();
+ if (headerContainerObject)
+ m_children.append(headerContainerObject);
+}
+
+AccessibilityTableCell* AccessibilityARIAGrid::cellForColumnAndRow(unsigned column, unsigned row)
+{
+ if (!m_renderer)
+ return 0;
+
+ if (!hasChildren())
+ addChildren();
+
+ if (column >= columnCount() || row >= rowCount())
+ return 0;
+
+ AccessibilityObject *tableRow = m_rows[row].get();
+ if (!tableRow)
+ return 0;
+
+ AccessibilityChildrenVector children = tableRow->children();
+ // in case this row had fewer columns than other rows
+ AccessibilityObject* tableCell = 0;
+ if (column >= children.size())
+ return 0;
+
+ tableCell = children[column].get();
+ return static_cast<AccessibilityTableCell*>(tableCell);
+}
+
+} // namespace WebCore
diff --git a/WebCore/accessibility/AccessibilityARIAGrid.h b/WebCore/accessibility/AccessibilityARIAGrid.h
new file mode 100644
index 0000000..32c8ce9
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityARIAGrid.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2009 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef AccessibilityARIAGrid_h
+#define AccessibilityARIAGrid_h
+
+#include "AccessibilityTable.h"
+
+namespace WebCore {
+
+class String;
+class AccessibilityTableCell;
+class AccessibilityTableHeaderContainer;
+
+class AccessibilityARIAGrid : public AccessibilityTable {
+
+private:
+ AccessibilityARIAGrid(RenderObject*);
+public:
+ static PassRefPtr<AccessibilityARIAGrid> create(RenderObject*);
+ virtual ~AccessibilityARIAGrid();
+
+ virtual bool isAriaTable() const { return true; }
+
+ virtual void addChildren();
+
+ virtual AccessibilityTableCell* cellForColumnAndRow(unsigned column, unsigned row);
+
+private:
+ void addChild(AccessibilityObject* object, HashSet<AccessibilityObject*>& appendedRows, unsigned& columnCount);
+};
+
+} // namespace WebCore
+
+#endif // AccessibilityARIAGrid_h
diff --git a/WebCore/accessibility/AccessibilityARIAGridCell.cpp b/WebCore/accessibility/AccessibilityARIAGridCell.cpp
new file mode 100644
index 0000000..1771bb8
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityARIAGridCell.cpp
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2009 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "AccessibilityARIAGridCell.h"
+
+#include "AccessibilityObject.h"
+#include "AccessibilityTableRow.h"
+
+using namespace std;
+
+namespace WebCore {
+
+AccessibilityARIAGridCell::AccessibilityARIAGridCell(RenderObject* renderer)
+ : AccessibilityTableCell(renderer)
+{
+}
+
+AccessibilityARIAGridCell::~AccessibilityARIAGridCell()
+{
+}
+
+PassRefPtr<AccessibilityARIAGridCell> AccessibilityARIAGridCell::create(RenderObject* renderer)
+{
+ return adoptRef(new AccessibilityARIAGridCell(renderer));
+}
+
+AccessibilityObject* AccessibilityARIAGridCell::parentTable() const
+{
+ AccessibilityObject* parent = parentObjectUnignored();
+ if (!parent || !parent->isTableRow())
+ return 0;
+
+ parent = parent->parentObjectUnignored();
+ if (!parent || !parent->isDataTable())
+ return 0;
+
+ return parent;
+}
+
+void AccessibilityARIAGridCell::rowIndexRange(pair<int, int>& rowRange)
+{
+ AccessibilityObject* parent = parentObjectUnignored();
+ if (!parent || !parent->isTableRow())
+ return;
+
+ // as far as I can tell, grid cells cannot span rows
+ rowRange.first = static_cast<AccessibilityTableRow*>(parent)->rowIndex();
+ rowRange.second = 1;
+}
+
+void AccessibilityARIAGridCell::columnIndexRange(pair<int, int>& columnRange)
+{
+ AccessibilityObject* parent = parentObjectUnignored();
+ if (!parent || !parent->isTableRow())
+ return;
+
+ AccessibilityChildrenVector siblings = parent->children();
+ unsigned childrenSize = siblings.size();
+ for (unsigned k = 0; k < childrenSize; ++k) {
+ if (siblings[k].get() == this) {
+ columnRange.first = k;
+ break;
+ }
+ }
+
+ // as far as I can tell, grid cells cannot span columns
+ columnRange.second = 1;
+}
+
+} // namespace WebCore
diff --git a/WebCore/accessibility/AccessibilityARIAGridCell.h b/WebCore/accessibility/AccessibilityARIAGridCell.h
new file mode 100644
index 0000000..2923de8
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityARIAGridCell.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2009 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef AccessibilityARIAGridCell_h
+#define AccessibilityARIAGridCell_h
+
+#include "AccessibilityTableCell.h"
+
+namespace WebCore {
+
+class AccessibilityARIAGridCell : public AccessibilityTableCell {
+
+private:
+ AccessibilityARIAGridCell(RenderObject*);
+public:
+ static PassRefPtr<AccessibilityARIAGridCell> create(RenderObject*);
+ virtual ~AccessibilityARIAGridCell();
+
+ // fills in the start location and row span of cell
+ virtual void rowIndexRange(pair<int, int>& rowRange);
+ // fills in the start location and column span of cell
+ virtual void columnIndexRange(pair<int, int>& columnRange);
+
+protected:
+ virtual AccessibilityObject* parentTable() const;
+};
+
+} // namespace WebCore
+
+#endif // AccessibilityARIAGridCell_h
diff --git a/WebCore/accessibility/AccessibilityARIAGridRow.cpp b/WebCore/accessibility/AccessibilityARIAGridRow.cpp
new file mode 100644
index 0000000..6e1f1c8
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityARIAGridRow.cpp
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2009 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "AccessibilityARIAGridRow.h"
+
+#include "AccessibilityObject.h"
+#include "RenderObject.h"
+
+using namespace std;
+
+namespace WebCore {
+
+AccessibilityARIAGridRow::AccessibilityARIAGridRow(RenderObject* renderer)
+ : AccessibilityTableRow(renderer)
+{
+}
+
+AccessibilityARIAGridRow::~AccessibilityARIAGridRow()
+{
+}
+
+PassRefPtr<AccessibilityARIAGridRow> AccessibilityARIAGridRow::create(RenderObject* renderer)
+{
+ return adoptRef(new AccessibilityARIAGridRow(renderer));
+}
+
+AccessibilityObject* AccessibilityARIAGridRow::parentTable() const
+{
+ AccessibilityObject* parent = parentObjectUnignored();
+ if (!parent->isDataTable())
+ return 0;
+
+ return parent;
+}
+
+AccessibilityObject* AccessibilityARIAGridRow::headerObject()
+{
+ AccessibilityChildrenVector rowChildren = children();
+ unsigned childrenCount = rowChildren.size();
+ for (unsigned i = 0; i < childrenCount; ++i) {
+ AccessibilityObject* cell = rowChildren[i].get();
+ if (cell->ariaRoleAttribute() == RowHeaderRole)
+ return cell;
+ }
+
+ return 0;
+}
+
+} // namespace WebCore
diff --git a/WebCore/accessibility/AccessibilityARIAGridRow.h b/WebCore/accessibility/AccessibilityARIAGridRow.h
new file mode 100644
index 0000000..c2ca8b8
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityARIAGridRow.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2009 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef AccessibilityARIAGridRow_h
+#define AccessibilityARIAGridRow_h
+
+#include "AccessibilityTableRow.h"
+
+namespace WebCore {
+
+class AccessibilityARIAGridRow : public AccessibilityTableRow {
+
+private:
+ AccessibilityARIAGridRow(RenderObject*);
+public:
+ static PassRefPtr<AccessibilityARIAGridRow> create(RenderObject*);
+ virtual ~AccessibilityARIAGridRow();
+
+ virtual AccessibilityObject* headerObject();
+ virtual AccessibilityObject* parentTable() const;
+};
+
+} // namespace WebCore
+
+#endif // AccessibilityARIAGridRow_h
diff --git a/WebCore/accessibility/AccessibilityImageMapLink.cpp b/WebCore/accessibility/AccessibilityImageMapLink.cpp
new file mode 100644
index 0000000..943122e
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityImageMapLink.cpp
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "AccessibilityImageMapLink.h"
+
+#include "AccessibilityRenderObject.h"
+#include "AXObjectCache.h"
+#include "Document.h"
+#include "HTMLNames.h"
+#include "IntRect.h"
+#include "RenderObject.h"
+
+using namespace std;
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+AccessibilityImageMapLink::AccessibilityImageMapLink()
+ : m_areaElement(0),
+ m_mapElement(0)
+{
+}
+
+AccessibilityImageMapLink::~AccessibilityImageMapLink()
+{
+}
+
+PassRefPtr<AccessibilityImageMapLink> AccessibilityImageMapLink::create()
+{
+ return adoptRef(new AccessibilityImageMapLink());
+}
+
+AccessibilityObject* AccessibilityImageMapLink::parentObject() const
+{
+ if (m_parent)
+ return m_parent;
+
+ if (!m_mapElement || !m_mapElement->renderer())
+ return 0;
+
+ return m_mapElement->document()->axObjectCache()->getOrCreate(m_mapElement->renderer());
+}
+
+Element* AccessibilityImageMapLink::actionElement() const
+{
+ return anchorElement();
+}
+
+Element* AccessibilityImageMapLink::anchorElement() const
+{
+ return m_areaElement;
+}
+
+KURL AccessibilityImageMapLink::url() const
+{
+ if (!m_areaElement)
+ return KURL();
+
+ return m_areaElement->href();
+}
+
+String AccessibilityImageMapLink::accessibilityDescription() const
+{
+ if (!m_areaElement)
+ return String();
+
+ const AtomicString& alt = m_areaElement->getAttribute(altAttr);
+ if (!alt.isEmpty())
+ return alt;
+
+ return String();
+}
+
+String AccessibilityImageMapLink::title() const
+{
+ if (!m_areaElement)
+ return String();
+
+ const AtomicString& title = m_areaElement->getAttribute(titleAttr);
+ if (!title.isEmpty())
+ return title;
+ const AtomicString& summary = m_areaElement->getAttribute(summaryAttr);
+ if (!summary.isEmpty())
+ return summary;
+
+ return String();
+}
+
+IntRect AccessibilityImageMapLink::elementRect() const
+{
+ if (!m_mapElement || !m_areaElement)
+ return IntRect();
+
+ RenderObject* renderer;
+ if (m_parent && m_parent->isAccessibilityRenderObject())
+ renderer = static_cast<AccessibilityRenderObject*>(m_parent)->renderer();
+ else
+ renderer = m_mapElement->renderer();
+
+ if (!renderer)
+ return IntRect();
+
+ return m_areaElement->getRect(renderer);
+}
+
+IntSize AccessibilityImageMapLink::size() const
+{
+ return elementRect().size();
+}
+
+} // namespace WebCore
diff --git a/WebCore/accessibility/AccessibilityImageMapLink.h b/WebCore/accessibility/AccessibilityImageMapLink.h
new file mode 100644
index 0000000..2c27e46
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityImageMapLink.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef AccessibilityImageMapLink_h
+#define AccessibilityImageMapLink_h
+
+#include "AccessibilityObject.h"
+#include "HTMLAreaElement.h"
+#include "HTMLMapElement.h"
+
+namespace WebCore {
+
+class AccessibilityImageMapLink : public AccessibilityObject {
+
+private:
+ AccessibilityImageMapLink();
+public:
+ static PassRefPtr<AccessibilityImageMapLink> create();
+ virtual ~AccessibilityImageMapLink();
+
+ void setHTMLAreaElement(HTMLAreaElement* element) { m_areaElement = element; }
+ void setHTMLMapElement(HTMLMapElement* element) { m_mapElement = element; }
+ void setParent(AccessibilityObject* parent) { m_parent = parent; }
+
+ virtual AccessibilityRole roleValue() const { return WebCoreLinkRole; }
+ virtual bool accessibilityIsIgnored() const { return false; }
+ virtual bool isEnabled() const { return true; }
+
+ virtual AccessibilityObject* parentObject() const;
+ virtual Element* anchorElement() const;
+ virtual Element* actionElement() const;
+ virtual KURL url() const;
+ virtual bool isLink() const { return true; }
+ virtual String title() const;
+ virtual String accessibilityDescription() const;
+
+ virtual IntSize size() const;
+ virtual IntRect elementRect() const;
+
+private:
+ HTMLAreaElement* m_areaElement;
+ HTMLMapElement* m_mapElement;
+ AccessibilityObject* m_parent;
+};
+
+} // namespace WebCore
+
+#endif // AccessibilityImageMapLink_h
diff --git a/WebCore/accessibility/AccessibilityList.cpp b/WebCore/accessibility/AccessibilityList.cpp
new file mode 100644
index 0000000..3b7c7a4
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityList.cpp
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "AccessibilityList.h"
+
+#include "AXObjectCache.h"
+#include "HTMLNames.h"
+#include "RenderObject.h"
+
+using namespace std;
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+AccessibilityList::AccessibilityList(RenderObject* renderer)
+ : AccessibilityRenderObject(renderer)
+{
+}
+
+AccessibilityList::~AccessibilityList()
+{
+}
+
+PassRefPtr<AccessibilityList> AccessibilityList::create(RenderObject* renderer)
+{
+ return adoptRef(new AccessibilityList(renderer));
+}
+
+bool AccessibilityList::accessibilityIsIgnored() const
+{
+ // lists don't appear on tiger/leopard on the mac
+#if ACCESSIBILITY_LISTS
+ return false;
+#else
+ return true;
+#endif
+}
+
+bool AccessibilityList::isUnorderedList() const
+{
+ if (!m_renderer)
+ return false;
+
+ Node* node = m_renderer->node();
+ return node && node->hasTagName(ulTag);
+}
+
+bool AccessibilityList::isOrderedList() const
+{
+ if (!m_renderer)
+ return false;
+
+ Node* node = m_renderer->node();
+ return node && node->hasTagName(olTag);
+}
+
+bool AccessibilityList::isDefinitionList() const
+{
+ if (!m_renderer)
+ return false;
+
+ Node* node = m_renderer->node();
+ return node && node->hasTagName(dlTag);
+}
+
+
+} // namespace WebCore
diff --git a/WebCore/accessibility/AccessibilityList.h b/WebCore/accessibility/AccessibilityList.h
new file mode 100644
index 0000000..89befb2
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityList.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef AccessibilityList_h
+#define AccessibilityList_h
+
+#if PLATFORM(MAC) && (defined(BUILDING_ON_TIGER) || defined(BUILDING_ON_LEOPARD))
+#define ACCESSIBILITY_LISTS 0
+#else
+#define ACCESSIBILITY_LISTS 1
+#endif
+
+#include "AccessibilityRenderObject.h"
+
+namespace WebCore {
+
+class AccessibilityList : public AccessibilityRenderObject {
+
+private:
+ AccessibilityList(RenderObject*);
+public:
+ static PassRefPtr<AccessibilityList> create(RenderObject*);
+ virtual ~AccessibilityList();
+
+ virtual bool isList() const { return true; };
+ bool isUnorderedList() const;
+ bool isOrderedList() const;
+ bool isDefinitionList() const;
+
+ virtual AccessibilityRole roleValue() const { return ListRole; }
+ virtual bool accessibilityIsIgnored() const;
+
+};
+
+} // namespace WebCore
+
+#endif // AccessibilityList_h
diff --git a/WebCore/accessibility/AccessibilityListBox.cpp b/WebCore/accessibility/AccessibilityListBox.cpp
new file mode 100644
index 0000000..e38aff5
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityListBox.cpp
@@ -0,0 +1,181 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "AccessibilityListBox.h"
+
+#include "AXObjectCache.h"
+#include "AccessibilityListBoxOption.h"
+#include "HitTestResult.h"
+#include "HTMLNames.h"
+#include "HTMLSelectElement.h"
+#include "RenderListBox.h"
+#include "RenderObject.h"
+
+using namespace std;
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+AccessibilityListBox::AccessibilityListBox(RenderObject* renderer)
+ : AccessibilityRenderObject(renderer)
+{
+}
+
+AccessibilityListBox::~AccessibilityListBox()
+{
+}
+
+PassRefPtr<AccessibilityListBox> AccessibilityListBox::create(RenderObject* renderer)
+{
+ return adoptRef(new AccessibilityListBox(renderer));
+}
+
+bool AccessibilityListBox::canSetSelectedChildrenAttribute() const
+{
+ Node* selectNode = m_renderer->node();
+ if (!selectNode)
+ return false;
+
+ return !static_cast<HTMLSelectElement*>(selectNode)->disabled();
+}
+
+void AccessibilityListBox::addChildren()
+{
+ Node* selectNode = m_renderer->node();
+ if (!selectNode)
+ return;
+
+ m_haveChildren = true;
+
+ const Vector<Element*>& listItems = static_cast<HTMLSelectElement*>(selectNode)->listItems();
+ unsigned length = listItems.size();
+ for (unsigned i = 0; i < length; i++) {
+ // The cast to HTMLElement below is safe because the only other possible listItem type
+ // would be a WMLElement, but WML builds don't use accessbility features at all.
+ AccessibilityObject* listOption = listBoxOptionAccessibilityObject(static_cast<HTMLElement*>(listItems[i]));
+ if (listOption)
+ m_children.append(listOption);
+ }
+}
+
+void AccessibilityListBox::setSelectedChildren(AccessibilityChildrenVector& children)
+{
+ if (!canSetSelectedChildrenAttribute())
+ return;
+
+ Node* selectNode = m_renderer->node();
+ if (!selectNode)
+ return;
+
+ // disable any selected options
+ unsigned length = m_children.size();
+ for (unsigned i = 0; i < length; i++) {
+ AccessibilityListBoxOption* listBoxOption = static_cast<AccessibilityListBoxOption*>(m_children[i].get());
+ if (listBoxOption->isSelected())
+ listBoxOption->setSelected(false);
+ }
+
+ length = children.size();
+ for (unsigned i = 0; i < length; i++) {
+ AccessibilityObject* obj = children[i].get();
+ if (obj->roleValue() != ListBoxOptionRole)
+ continue;
+
+ static_cast<AccessibilityListBoxOption*>(obj)->setSelected(true);
+ }
+}
+
+void AccessibilityListBox::selectedChildren(AccessibilityChildrenVector& result)
+{
+ ASSERT(result.isEmpty());
+
+ if (!hasChildren())
+ addChildren();
+
+ unsigned length = m_children.size();
+ for (unsigned i = 0; i < length; i++) {
+ if (static_cast<AccessibilityListBoxOption*>(m_children[i].get())->isSelected())
+ result.append(m_children[i]);
+ }
+}
+
+void AccessibilityListBox::visibleChildren(AccessibilityChildrenVector& result)
+{
+ ASSERT(result.isEmpty());
+
+ if (!hasChildren())
+ addChildren();
+
+ unsigned length = m_children.size();
+ for (unsigned i = 0; i < length; i++) {
+ if (static_cast<RenderListBox*>(m_renderer)->listIndexIsVisible(i))
+ result.append(m_children[i]);
+ }
+}
+
+AccessibilityObject* AccessibilityListBox::listBoxOptionAccessibilityObject(HTMLElement* element) const
+{
+ // skip hr elements
+ if (!element || element->hasTagName(hrTag))
+ return 0;
+
+ AccessibilityObject* listBoxObject = m_renderer->document()->axObjectCache()->getOrCreate(ListBoxOptionRole);
+ static_cast<AccessibilityListBoxOption*>(listBoxObject)->setHTMLElement(element);
+
+ return listBoxObject;
+}
+
+AccessibilityObject* AccessibilityListBox::doAccessibilityHitTest(const IntPoint& point) const
+{
+ // the internal HTMLSelectElement methods for returning a listbox option at a point
+ // ignore optgroup elements.
+ if (!m_renderer)
+ return 0;
+
+ Node* node = m_renderer->node();
+ if (!node)
+ return 0;
+
+ IntRect parentRect = boundingBoxRect();
+
+ const Vector<Element*>& listItems = static_cast<HTMLSelectElement*>(node)->listItems();
+ unsigned length = listItems.size();
+ for (unsigned i = 0; i < length; i++) {
+ IntRect rect = static_cast<RenderListBox*>(m_renderer)->itemBoundingBoxRect(parentRect.x(), parentRect.y(), i);
+ // The cast to HTMLElement below is safe because the only other possible listItem type
+ // would be a WMLElement, but WML builds don't use accessbility features at all.
+ if (rect.contains(point))
+ return listBoxOptionAccessibilityObject(static_cast<HTMLElement*>(listItems[i]));
+ }
+
+ return axObjectCache()->getOrCreate(m_renderer);
+}
+
+} // namespace WebCore
diff --git a/WebCore/accessibility/AccessibilityListBox.h b/WebCore/accessibility/AccessibilityListBox.h
new file mode 100644
index 0000000..3f3352d
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityListBox.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef AccessibilityListBox_h
+#define AccessibilityListBox_h
+
+#include "AccessibilityObject.h"
+#include "AccessibilityRenderObject.h"
+
+namespace WebCore {
+
+class AccessibilityListBox : public AccessibilityRenderObject {
+
+private:
+ AccessibilityListBox(RenderObject*);
+public:
+ static PassRefPtr<AccessibilityListBox> create(RenderObject*);
+ virtual ~AccessibilityListBox();
+
+ virtual AccessibilityObject* doAccessibilityHitTest(const IntPoint&) const;
+ virtual bool isListBox() const { return true; };
+
+ virtual bool canSetFocusAttribute() const { return true; }
+ virtual bool canSetSelectedChildrenAttribute() const;
+ void setSelectedChildren(AccessibilityChildrenVector&);
+ virtual AccessibilityRole roleValue() const { return ListBoxRole; }
+
+ virtual bool accessibilityIsIgnored() const { return false; }
+
+ virtual void selectedChildren(AccessibilityChildrenVector&);
+ virtual void visibleChildren(AccessibilityChildrenVector&);
+
+ virtual void addChildren();
+
+private:
+ AccessibilityObject* listBoxOptionAccessibilityObject(HTMLElement*) const;
+};
+
+} // namespace WebCore
+
+#endif // AccessibilityListBox_h
diff --git a/WebCore/accessibility/AccessibilityListBoxOption.cpp b/WebCore/accessibility/AccessibilityListBoxOption.cpp
new file mode 100644
index 0000000..a5cd5da
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityListBoxOption.cpp
@@ -0,0 +1,207 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "AccessibilityListBoxOption.h"
+
+#include "AXObjectCache.h"
+#include "AccessibilityListBox.h"
+#include "Element.h"
+#include "HTMLElement.h"
+#include "HTMLNames.h"
+#include "HTMLOptionElement.h"
+#include "HTMLOptGroupElement.h"
+#include "HTMLSelectElement.h"
+#include "IntRect.h"
+#include "RenderObject.h"
+#include "RenderListBox.h"
+
+using namespace std;
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+AccessibilityListBoxOption::AccessibilityListBoxOption()
+ : m_optionElement(0)
+{
+}
+
+AccessibilityListBoxOption::~AccessibilityListBoxOption()
+{
+}
+
+PassRefPtr<AccessibilityListBoxOption> AccessibilityListBoxOption::create()
+{
+ return adoptRef(new AccessibilityListBoxOption());
+}
+
+bool AccessibilityListBoxOption::isEnabled() const
+{
+ if (!m_optionElement)
+ return false;
+
+ if (m_optionElement->hasTagName(optgroupTag))
+ return false;
+
+ return true;
+}
+
+bool AccessibilityListBoxOption::isSelected() const
+{
+ if (!m_optionElement)
+ return false;
+
+ if (!m_optionElement->hasTagName(optionTag))
+ return false;
+
+ return static_cast<HTMLOptionElement*>(m_optionElement)->selected();
+}
+
+IntRect AccessibilityListBoxOption::elementRect() const
+{
+ IntRect rect;
+ if (!m_optionElement)
+ return rect;
+
+ HTMLSelectElement* listBoxParentNode = listBoxOptionParentNode();
+ if (!listBoxParentNode)
+ return rect;
+
+ RenderObject* listBoxRenderer = listBoxParentNode->renderer();
+ if (!listBoxRenderer)
+ return rect;
+
+ IntRect parentRect = listBoxRenderer->document()->axObjectCache()->getOrCreate(listBoxRenderer)->boundingBoxRect();
+ int index = listBoxOptionIndex();
+ if (index != -1)
+ rect = static_cast<RenderListBox*>(listBoxRenderer)->itemBoundingBoxRect(parentRect.x(), parentRect.y(), index);
+
+ return rect;
+}
+
+bool AccessibilityListBoxOption::canSetSelectedAttribute() const
+{
+ if (!m_optionElement)
+ return false;
+
+ if (!m_optionElement->hasTagName(optionTag))
+ return false;
+
+ if (m_optionElement->disabled())
+ return false;
+
+ HTMLSelectElement* selectElement = listBoxOptionParentNode();
+ if (selectElement && selectElement->disabled())
+ return false;
+
+ return true;
+}
+
+String AccessibilityListBoxOption::stringValue() const
+{
+ if (!m_optionElement)
+ return String();
+
+ if (m_optionElement->hasTagName(optionTag))
+ return static_cast<HTMLOptionElement*>(m_optionElement)->text();
+
+ if (m_optionElement->hasTagName(optgroupTag))
+ return static_cast<HTMLOptGroupElement*>(m_optionElement)->groupLabelText();
+
+ return String();
+}
+
+IntSize AccessibilityListBoxOption::size() const
+{
+ return elementRect().size();
+}
+
+Element* AccessibilityListBoxOption::actionElement() const
+{
+ return m_optionElement;
+}
+
+AccessibilityObject* AccessibilityListBoxOption::parentObject() const
+{
+ HTMLSelectElement* parentNode = listBoxOptionParentNode();
+ if (!parentNode)
+ return 0;
+
+ return m_optionElement->document()->axObjectCache()->getOrCreate(parentNode->renderer());
+}
+
+void AccessibilityListBoxOption::setSelected(bool selected)
+{
+ HTMLSelectElement* selectElement = listBoxOptionParentNode();
+ if (!selectElement)
+ return;
+
+ if (!canSetSelectedAttribute())
+ return;
+
+ bool isOptionSelected = isSelected();
+ if ((isOptionSelected && selected) || (!isOptionSelected && !selected))
+ return;
+
+ selectElement->accessKeySetSelectedIndex(listBoxOptionIndex());
+}
+
+HTMLSelectElement* AccessibilityListBoxOption::listBoxOptionParentNode() const
+{
+ if (!m_optionElement)
+ return 0;
+
+ if (m_optionElement->hasTagName(optionTag))
+ return static_cast<HTMLOptionElement*>(m_optionElement)->ownerSelectElement();
+
+ if (m_optionElement->hasTagName(optgroupTag))
+ return static_cast<HTMLOptGroupElement*>(m_optionElement)->ownerSelectElement();
+
+ return 0;
+}
+
+int AccessibilityListBoxOption::listBoxOptionIndex() const
+{
+ if (!m_optionElement)
+ return -1;
+
+ HTMLSelectElement* selectElement = listBoxOptionParentNode();
+ if (!selectElement)
+ return -1;
+
+ const Vector<Element*>& listItems = selectElement->listItems();
+ unsigned length = listItems.size();
+ for (unsigned i = 0; i < length; i++)
+ if (listItems[i] == m_optionElement)
+ return i;
+
+ return -1;
+}
+
+} // namespace WebCore
diff --git a/WebCore/accessibility/AccessibilityListBoxOption.h b/WebCore/accessibility/AccessibilityListBoxOption.h
new file mode 100644
index 0000000..1b588cd
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityListBoxOption.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef AccessibilityListBoxOption_h
+#define AccessibilityListBoxOption_h
+
+#include "AccessibilityObject.h"
+#include "HTMLElement.h"
+
+namespace WebCore {
+
+class AccessibilityListBox;
+class Element;
+class HTMLElement;
+class HTMLSelectElement;
+class String;
+
+class AccessibilityListBoxOption : public AccessibilityObject {
+
+private:
+ AccessibilityListBoxOption();
+public:
+ static PassRefPtr<AccessibilityListBoxOption> create();
+ virtual ~AccessibilityListBoxOption();
+
+ void setHTMLElement(HTMLElement* element) { m_optionElement = element; }
+
+ virtual AccessibilityRole roleValue() const { return ListBoxOptionRole; }
+ virtual bool accessibilityIsIgnored() const { return false; }
+ virtual bool isSelected() const;
+ virtual bool isEnabled() const;
+ virtual String stringValue() const;
+ virtual Element* actionElement() const;
+
+ virtual void setSelected(bool);
+ virtual bool canSetSelectedAttribute() const;
+
+ virtual IntRect elementRect() const;
+ virtual IntSize size() const;
+ virtual AccessibilityObject* parentObject() const;
+ bool isListBoxOption() const { return true; };
+
+private:
+ HTMLElement* m_optionElement;
+
+ HTMLSelectElement* listBoxOptionParentNode() const;
+ int listBoxOptionIndex() const;
+ IntRect listBoxOptionRect() const;
+ AccessibilityObject* listBoxOptionAccessibilityObject(HTMLElement* element) const;
+};
+
+} // namespace WebCore
+
+#endif // AccessibilityListBoxOption_h
diff --git a/WebCore/accessibility/AccessibilityObject.cpp b/WebCore/accessibility/AccessibilityObject.cpp
new file mode 100644
index 0000000..dccff82
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityObject.cpp
@@ -0,0 +1,1036 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "AccessibilityObject.h"
+
+#include "AccessibilityRenderObject.h"
+#include "AXObjectCache.h"
+#include "CharacterNames.h"
+#include "FloatRect.h"
+#include "FocusController.h"
+#include "Frame.h"
+#include "FrameLoader.h"
+#include "LocalizedStrings.h"
+#include "NodeList.h"
+#include "NotImplemented.h"
+#include "Page.h"
+#include "RenderImage.h"
+#include "RenderListMarker.h"
+#include "RenderMenuList.h"
+#include "RenderTextControl.h"
+#include "RenderTheme.h"
+#include "RenderView.h"
+#include "RenderWidget.h"
+#include "SelectionController.h"
+#include "TextIterator.h"
+#include "htmlediting.h"
+#include "visible_units.h"
+#include <wtf/StdLibExtras.h>
+
+using namespace std;
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+AccessibilityObject::AccessibilityObject()
+ : m_id(0)
+ , m_haveChildren(false)
+#if PLATFORM(GTK)
+ , m_wrapper(0)
+#endif
+{
+}
+
+AccessibilityObject::~AccessibilityObject()
+{
+ ASSERT(isDetached());
+}
+
+void AccessibilityObject::detach()
+{
+#if HAVE(ACCESSIBILITY)
+ setWrapper(0);
+#endif
+}
+
+AccessibilityObject* AccessibilityObject::firstChild() const
+{
+ return 0;
+}
+
+AccessibilityObject* AccessibilityObject::lastChild() const
+{
+ return 0;
+}
+
+AccessibilityObject* AccessibilityObject::previousSibling() const
+{
+ return 0;
+}
+
+AccessibilityObject* AccessibilityObject::nextSibling() const
+{
+ return 0;
+}
+
+AccessibilityObject* AccessibilityObject::parentObject() const
+{
+ return 0;
+}
+
+AccessibilityObject* AccessibilityObject::parentObjectUnignored() const
+{
+ AccessibilityObject* parent;
+ for (parent = parentObject(); parent && parent->accessibilityIsIgnored(); parent = parent->parentObject())
+ ;
+ return parent;
+}
+
+AccessibilityObject* AccessibilityObject::parentObjectIfExists() const
+{
+ return 0;
+}
+
+int AccessibilityObject::layoutCount() const
+{
+ return 0;
+}
+
+String AccessibilityObject::text() const
+{
+ return String();
+}
+
+String AccessibilityObject::helpText() const
+{
+ return String();
+}
+
+String AccessibilityObject::textUnderElement() const
+{
+ return String();
+}
+
+bool AccessibilityObject::isARIAInput(AccessibilityRole ariaRole)
+{
+ return ariaRole == RadioButtonRole || ariaRole == CheckBoxRole || ariaRole == TextFieldRole;
+}
+
+bool AccessibilityObject::isARIAControl(AccessibilityRole ariaRole)
+{
+ return isARIAInput(ariaRole) || ariaRole == TextAreaRole || ariaRole == ButtonRole
+ || ariaRole == ComboBoxRole || ariaRole == SliderRole;
+}
+
+int AccessibilityObject::intValue() const
+{
+ return 0;
+}
+
+String AccessibilityObject::stringValue() const
+{
+ return String();
+}
+
+String AccessibilityObject::ariaAccessiblityName(const String&) const
+{
+ return String();
+}
+
+String AccessibilityObject::ariaLabeledByAttribute() const
+{
+ return String();
+}
+
+String AccessibilityObject::title() const
+{
+ return String();
+}
+
+String AccessibilityObject::ariaDescribedByAttribute() const
+{
+ return String();
+}
+
+String AccessibilityObject::accessibilityDescription() const
+{
+ return String();
+}
+
+IntRect AccessibilityObject::boundingBoxRect() const
+{
+ return IntRect();
+}
+
+IntRect AccessibilityObject::elementRect() const
+{
+ return IntRect();
+}
+
+IntSize AccessibilityObject::size() const
+{
+ return IntSize();
+}
+
+IntPoint AccessibilityObject::clickPoint() const
+{
+ IntRect rect = elementRect();
+ return IntPoint(rect.x() + rect.width() / 2, rect.y() + rect.height() / 2);
+}
+
+void AccessibilityObject::linkedUIElements(AccessibilityChildrenVector&) const
+{
+ return;
+}
+
+AccessibilityObject* AccessibilityObject::titleUIElement() const
+{
+ return 0;
+}
+
+int AccessibilityObject::textLength() const
+{
+ return 0;
+}
+
+PassRefPtr<Range> AccessibilityObject::ariaSelectedTextDOMRange() const
+{
+ return 0;
+}
+
+String AccessibilityObject::selectedText() const
+{
+ return String();
+}
+
+const AtomicString& AccessibilityObject::accessKey() const
+{
+ return nullAtom;
+}
+
+VisibleSelection AccessibilityObject::selection() const
+{
+ return VisibleSelection();
+}
+
+PlainTextRange AccessibilityObject::selectedTextRange() const
+{
+ return PlainTextRange();
+}
+
+unsigned AccessibilityObject::selectionStart() const
+{
+ return selectedTextRange().start;
+}
+
+unsigned AccessibilityObject::selectionEnd() const
+{
+ return selectedTextRange().length;
+}
+
+void AccessibilityObject::setSelectedText(const String&)
+{
+ // TODO: set selected text (ReplaceSelectionCommand). <rdar://problem/4712125>
+ notImplemented();
+}
+
+void AccessibilityObject::setSelectedTextRange(const PlainTextRange&)
+{
+}
+
+void AccessibilityObject::makeRangeVisible(const PlainTextRange&)
+{
+ // TODO: make range visible (scrollRectToVisible). <rdar://problem/4712101>
+ notImplemented();
+}
+
+KURL AccessibilityObject::url() const
+{
+ return KURL();
+}
+
+void AccessibilityObject::setFocused(bool)
+{
+}
+
+void AccessibilityObject::setValue(const String&)
+{
+}
+
+void AccessibilityObject::setSelected(bool)
+{
+}
+
+bool AccessibilityObject::press() const
+{
+ Element* actionElem = actionElement();
+ if (!actionElem)
+ return false;
+ if (Frame* f = actionElem->document()->frame())
+ f->loader()->resetMultipleFormSubmissionProtection();
+ actionElem->accessKeyAction(true);
+ return true;
+}
+
+AXObjectCache* AccessibilityObject::axObjectCache() const
+{
+ return 0;
+}
+
+Widget* AccessibilityObject::widget() const
+{
+ return 0;
+}
+
+Widget* AccessibilityObject::widgetForAttachmentView() const
+{
+ return 0;
+}
+
+Element* AccessibilityObject::anchorElement() const
+{
+ return 0;
+}
+
+Element* AccessibilityObject::actionElement() const
+{
+ return 0;
+}
+
+// This function is like a cross-platform version of - (WebCoreTextMarkerRange*)textMarkerRange. It returns
+// a Range that we can convert to a WebCoreRange in the Obj-C file
+VisiblePositionRange AccessibilityObject::visiblePositionRange() const
+{
+ return VisiblePositionRange();
+}
+
+VisiblePositionRange AccessibilityObject::visiblePositionRangeForLine(unsigned) const
+{
+ return VisiblePositionRange();
+}
+
+VisiblePosition AccessibilityObject::visiblePositionForIndex(int) const
+{
+ return VisiblePosition();
+}
+
+int AccessibilityObject::indexForVisiblePosition(const VisiblePosition&) const
+{
+ return 0;
+}
+
+VisiblePositionRange AccessibilityObject::visiblePositionRangeForUnorderedPositions(const VisiblePosition& visiblePos1, const VisiblePosition& visiblePos2) const
+{
+ if (visiblePos1.isNull() || visiblePos2.isNull())
+ return VisiblePositionRange();
+
+ VisiblePosition startPos;
+ VisiblePosition endPos;
+ bool alreadyInOrder;
+
+ // upstream is ordered before downstream for the same position
+ if (visiblePos1 == visiblePos2 && visiblePos2.affinity() == UPSTREAM)
+ alreadyInOrder = false;
+
+ // use selection order to see if the positions are in order
+ else
+ alreadyInOrder = VisibleSelection(visiblePos1, visiblePos2).isBaseFirst();
+
+ if (alreadyInOrder) {
+ startPos = visiblePos1;
+ endPos = visiblePos2;
+ } else {
+ startPos = visiblePos2;
+ endPos = visiblePos1;
+ }
+
+ return VisiblePositionRange(startPos, endPos);
+}
+
+VisiblePositionRange AccessibilityObject::positionOfLeftWord(const VisiblePosition& visiblePos) const
+{
+ VisiblePosition startPosition = startOfWord(visiblePos, LeftWordIfOnBoundary);
+ VisiblePosition endPosition = endOfWord(startPosition);
+ return VisiblePositionRange(startPosition, endPosition);
+}
+
+VisiblePositionRange AccessibilityObject::positionOfRightWord(const VisiblePosition& visiblePos) const
+{
+ VisiblePosition startPosition = startOfWord(visiblePos, RightWordIfOnBoundary);
+ VisiblePosition endPosition = endOfWord(startPosition);
+ return VisiblePositionRange(startPosition, endPosition);
+}
+
+static VisiblePosition updateAXLineStartForVisiblePosition(const VisiblePosition& visiblePosition)
+{
+ // A line in the accessibility sense should include floating objects, such as aligned image, as part of a line.
+ // So let's update the position to include that.
+ VisiblePosition tempPosition;
+ VisiblePosition startPosition = visiblePosition;
+ Position p;
+ RenderObject* renderer;
+ while (true) {
+ tempPosition = startPosition.previous();
+ if (tempPosition.isNull())
+ break;
+ p = tempPosition.deepEquivalent();
+ if (!p.node())
+ break;
+ renderer = p.node()->renderer();
+ if (!renderer || (renderer->isRenderBlock() && !p.deprecatedEditingOffset()))
+ break;
+ InlineBox* box;
+ int ignoredCaretOffset;
+ p.getInlineBoxAndOffset(tempPosition.affinity(), box, ignoredCaretOffset);
+ if (box)
+ break;
+ startPosition = tempPosition;
+ }
+
+ return startPosition;
+}
+
+VisiblePositionRange AccessibilityObject::leftLineVisiblePositionRange(const VisiblePosition& visiblePos) const
+{
+ if (visiblePos.isNull())
+ return VisiblePositionRange();
+
+ // make a caret selection for the position before marker position (to make sure
+ // we move off of a line start)
+ VisiblePosition prevVisiblePos = visiblePos.previous();
+ if (prevVisiblePos.isNull())
+ return VisiblePositionRange();
+
+ VisiblePosition startPosition = startOfLine(prevVisiblePos);
+
+ // keep searching for a valid line start position. Unless the VisiblePosition is at the very beginning, there should
+ // always be a valid line range. However, startOfLine will return null for position next to a floating object,
+ // since floating object doesn't really belong to any line.
+ // This check will reposition the marker before the floating object, to ensure we get a line start.
+ if (startPosition.isNull()) {
+ while (startPosition.isNull() && prevVisiblePos.isNotNull()) {
+ prevVisiblePos = prevVisiblePos.previous();
+ startPosition = startOfLine(prevVisiblePos);
+ }
+ } else
+ startPosition = updateAXLineStartForVisiblePosition(startPosition);
+
+ VisiblePosition endPosition = endOfLine(prevVisiblePos);
+ return VisiblePositionRange(startPosition, endPosition);
+}
+
+VisiblePositionRange AccessibilityObject::rightLineVisiblePositionRange(const VisiblePosition& visiblePos) const
+{
+ if (visiblePos.isNull())
+ return VisiblePositionRange();
+
+ // make sure we move off of a line end
+ VisiblePosition nextVisiblePos = visiblePos.next();
+ if (nextVisiblePos.isNull())
+ return VisiblePositionRange();
+
+ VisiblePosition startPosition = startOfLine(nextVisiblePos);
+
+ // fetch for a valid line start position
+ if (startPosition.isNull() ) {
+ startPosition = visiblePos;
+ nextVisiblePos = nextVisiblePos.next();
+ } else
+ startPosition = updateAXLineStartForVisiblePosition(startPosition);
+
+ VisiblePosition endPosition = endOfLine(nextVisiblePos);
+
+ // as long as the position hasn't reached the end of the doc, keep searching for a valid line end position
+ // Unless the VisiblePosition is at the very end, there should always be a valid line range. However, endOfLine will
+ // return null for position by a floating object, since floating object doesn't really belong to any line.
+ // This check will reposition the marker after the floating object, to ensure we get a line end.
+ while (endPosition.isNull() && nextVisiblePos.isNotNull()) {
+ nextVisiblePos = nextVisiblePos.next();
+ endPosition = endOfLine(nextVisiblePos);
+ }
+
+ return VisiblePositionRange(startPosition, endPosition);
+}
+
+VisiblePositionRange AccessibilityObject::sentenceForPosition(const VisiblePosition& visiblePos) const
+{
+ // FIXME: FO 2 IMPLEMENT (currently returns incorrect answer)
+ // Related? <rdar://problem/3927736> Text selection broken in 8A336
+ VisiblePosition startPosition = startOfSentence(visiblePos);
+ VisiblePosition endPosition = endOfSentence(startPosition);
+ return VisiblePositionRange(startPosition, endPosition);
+}
+
+VisiblePositionRange AccessibilityObject::paragraphForPosition(const VisiblePosition& visiblePos) const
+{
+ VisiblePosition startPosition = startOfParagraph(visiblePos);
+ VisiblePosition endPosition = endOfParagraph(startPosition);
+ return VisiblePositionRange(startPosition, endPosition);
+}
+
+static VisiblePosition startOfStyleRange(const VisiblePosition visiblePos)
+{
+ RenderObject* renderer = visiblePos.deepEquivalent().node()->renderer();
+ RenderObject* startRenderer = renderer;
+ RenderStyle* style = renderer->style();
+
+ // traverse backward by renderer to look for style change
+ for (RenderObject* r = renderer->previousInPreOrder(); r; r = r->previousInPreOrder()) {
+ // skip non-leaf nodes
+ if (r->firstChild())
+ continue;
+
+ // stop at style change
+ if (r->style() != style)
+ break;
+
+ // remember match
+ startRenderer = r;
+ }
+
+ return VisiblePosition(startRenderer->node(), 0, VP_DEFAULT_AFFINITY);
+}
+
+static VisiblePosition endOfStyleRange(const VisiblePosition& visiblePos)
+{
+ RenderObject* renderer = visiblePos.deepEquivalent().node()->renderer();
+ RenderObject* endRenderer = renderer;
+ RenderStyle* style = renderer->style();
+
+ // traverse forward by renderer to look for style change
+ for (RenderObject* r = renderer->nextInPreOrder(); r; r = r->nextInPreOrder()) {
+ // skip non-leaf nodes
+ if (r->firstChild())
+ continue;
+
+ // stop at style change
+ if (r->style() != style)
+ break;
+
+ // remember match
+ endRenderer = r;
+ }
+
+ return lastDeepEditingPositionForNode(endRenderer->node());
+}
+
+VisiblePositionRange AccessibilityObject::styleRangeForPosition(const VisiblePosition& visiblePos) const
+{
+ if (visiblePos.isNull())
+ return VisiblePositionRange();
+
+ return VisiblePositionRange(startOfStyleRange(visiblePos), endOfStyleRange(visiblePos));
+}
+
+// NOTE: Consider providing this utility method as AX API
+VisiblePositionRange AccessibilityObject::visiblePositionRangeForRange(const PlainTextRange& range) const
+{
+ if (range.start + range.length > text().length())
+ return VisiblePositionRange();
+
+ VisiblePosition startPosition = visiblePositionForIndex(range.start);
+ startPosition.setAffinity(DOWNSTREAM);
+ VisiblePosition endPosition = visiblePositionForIndex(range.start + range.length);
+ return VisiblePositionRange(startPosition, endPosition);
+}
+
+static bool replacedNodeNeedsCharacter(Node* replacedNode)
+{
+ // we should always be given a rendered node and a replaced node, but be safe
+ // replaced nodes are either attachments (widgets) or images
+ if (!replacedNode || !replacedNode->renderer() || !replacedNode->renderer()->isReplaced() || replacedNode->isTextNode()) {
+ return false;
+ }
+
+ // create an AX object, but skip it if it is not supposed to be seen
+ AccessibilityObject* object = replacedNode->renderer()->document()->axObjectCache()->getOrCreate(replacedNode->renderer());
+ if (object->accessibilityIsIgnored())
+ return false;
+
+ return true;
+}
+
+String AccessibilityObject::stringForVisiblePositionRange(const VisiblePositionRange& visiblePositionRange) const
+{
+ if (visiblePositionRange.isNull())
+ return String();
+
+ Vector<UChar> resultVector;
+ RefPtr<Range> range = makeRange(visiblePositionRange.start, visiblePositionRange.end);
+ for (TextIterator it(range.get()); !it.atEnd(); it.advance()) {
+ // non-zero length means textual node, zero length means replaced node (AKA "attachments" in AX)
+ if (it.length() != 0) {
+ resultVector.append(it.characters(), it.length());
+ } else {
+ // locate the node and starting offset for this replaced range
+ int exception = 0;
+ Node* node = it.range()->startContainer(exception);
+ ASSERT(node == it.range()->endContainer(exception));
+ int offset = it.range()->startOffset(exception);
+
+ if (replacedNodeNeedsCharacter(node->childNode(offset))) {
+ resultVector.append(objectReplacementCharacter);
+ }
+ }
+ }
+
+ return String::adopt(resultVector);
+}
+
+IntRect AccessibilityObject::boundsForVisiblePositionRange(const VisiblePositionRange&) const
+{
+ return IntRect();
+}
+
+int AccessibilityObject::lengthForVisiblePositionRange(const VisiblePositionRange& visiblePositionRange) const
+{
+ // FIXME: Multi-byte support
+ if (visiblePositionRange.isNull())
+ return -1;
+
+ int length = 0;
+ RefPtr<Range> range = makeRange(visiblePositionRange.start, visiblePositionRange.end);
+ for (TextIterator it(range.get()); !it.atEnd(); it.advance()) {
+ // non-zero length means textual node, zero length means replaced node (AKA "attachments" in AX)
+ if (it.length() != 0) {
+ length += it.length();
+ } else {
+ // locate the node and starting offset for this replaced range
+ int exception = 0;
+ Node* node = it.range()->startContainer(exception);
+ ASSERT(node == it.range()->endContainer(exception));
+ int offset = it.range()->startOffset(exception);
+
+ if (replacedNodeNeedsCharacter(node->childNode(offset)))
+ length++;
+ }
+ }
+
+ return length;
+}
+
+void AccessibilityObject::setSelectedVisiblePositionRange(const VisiblePositionRange&) const
+{
+}
+
+VisiblePosition AccessibilityObject::visiblePositionForPoint(const IntPoint&) const
+{
+ return VisiblePosition();
+}
+
+VisiblePosition AccessibilityObject::nextVisiblePosition(const VisiblePosition& visiblePos) const
+{
+ return visiblePos.next();
+}
+
+VisiblePosition AccessibilityObject::previousVisiblePosition(const VisiblePosition& visiblePos) const
+{
+ return visiblePos.previous();
+}
+
+VisiblePosition AccessibilityObject::nextWordEnd(const VisiblePosition& visiblePos) const
+{
+ if (visiblePos.isNull())
+ return VisiblePosition();
+
+ // make sure we move off of a word end
+ VisiblePosition nextVisiblePos = visiblePos.next();
+ if (nextVisiblePos.isNull())
+ return VisiblePosition();
+
+ return endOfWord(nextVisiblePos, LeftWordIfOnBoundary);
+}
+
+VisiblePosition AccessibilityObject::previousWordStart(const VisiblePosition& visiblePos) const
+{
+ if (visiblePos.isNull())
+ return VisiblePosition();
+
+ // make sure we move off of a word start
+ VisiblePosition prevVisiblePos = visiblePos.previous();
+ if (prevVisiblePos.isNull())
+ return VisiblePosition();
+
+ return startOfWord(prevVisiblePos, RightWordIfOnBoundary);
+}
+
+VisiblePosition AccessibilityObject::nextLineEndPosition(const VisiblePosition& visiblePos) const
+{
+ if (visiblePos.isNull())
+ return VisiblePosition();
+
+ // to make sure we move off of a line end
+ VisiblePosition nextVisiblePos = visiblePos.next();
+ if (nextVisiblePos.isNull())
+ return VisiblePosition();
+
+ VisiblePosition endPosition = endOfLine(nextVisiblePos);
+
+ // as long as the position hasn't reached the end of the doc, keep searching for a valid line end position
+ // There are cases like when the position is next to a floating object that'll return null for end of line. This code will avoid returning null.
+ while (endPosition.isNull() && nextVisiblePos.isNotNull()) {
+ nextVisiblePos = nextVisiblePos.next();
+ endPosition = endOfLine(nextVisiblePos);
+ }
+
+ return endPosition;
+}
+
+VisiblePosition AccessibilityObject::previousLineStartPosition(const VisiblePosition& visiblePos) const
+{
+ if (visiblePos.isNull())
+ return VisiblePosition();
+
+ // make sure we move off of a line start
+ VisiblePosition prevVisiblePos = visiblePos.previous();
+ if (prevVisiblePos.isNull())
+ return VisiblePosition();
+
+ VisiblePosition startPosition = startOfLine(prevVisiblePos);
+
+ // as long as the position hasn't reached the beginning of the doc, keep searching for a valid line start position
+ // There are cases like when the position is next to a floating object that'll return null for start of line. This code will avoid returning null.
+ if (startPosition.isNull()) {
+ while (startPosition.isNull() && prevVisiblePos.isNotNull()) {
+ prevVisiblePos = prevVisiblePos.previous();
+ startPosition = startOfLine(prevVisiblePos);
+ }
+ } else
+ startPosition = updateAXLineStartForVisiblePosition(startPosition);
+
+ return startPosition;
+}
+
+VisiblePosition AccessibilityObject::nextSentenceEndPosition(const VisiblePosition& visiblePos) const
+{
+ // FIXME: FO 2 IMPLEMENT (currently returns incorrect answer)
+ // Related? <rdar://problem/3927736> Text selection broken in 8A336
+ if (visiblePos.isNull())
+ return VisiblePosition();
+
+ // make sure we move off of a sentence end
+ VisiblePosition nextVisiblePos = visiblePos.next();
+ if (nextVisiblePos.isNull())
+ return VisiblePosition();
+
+ // an empty line is considered a sentence. If it's skipped, then the sentence parser will not
+ // see this empty line. Instead, return the end position of the empty line.
+ VisiblePosition endPosition;
+
+ String lineString = plainText(makeRange(startOfLine(nextVisiblePos), endOfLine(nextVisiblePos)).get());
+ if (lineString.isEmpty())
+ endPosition = nextVisiblePos;
+ else
+ endPosition = endOfSentence(nextVisiblePos);
+
+ return endPosition;
+}
+
+VisiblePosition AccessibilityObject::previousSentenceStartPosition(const VisiblePosition& visiblePos) const
+{
+ // FIXME: FO 2 IMPLEMENT (currently returns incorrect answer)
+ // Related? <rdar://problem/3927736> Text selection broken in 8A336
+ if (visiblePos.isNull())
+ return VisiblePosition();
+
+ // make sure we move off of a sentence start
+ VisiblePosition previousVisiblePos = visiblePos.previous();
+ if (previousVisiblePos.isNull())
+ return VisiblePosition();
+
+ // treat empty line as a separate sentence.
+ VisiblePosition startPosition;
+
+ String lineString = plainText(makeRange(startOfLine(previousVisiblePos), endOfLine(previousVisiblePos)).get());
+ if (lineString.isEmpty())
+ startPosition = previousVisiblePos;
+ else
+ startPosition = startOfSentence(previousVisiblePos);
+
+ return startPosition;
+}
+
+VisiblePosition AccessibilityObject::nextParagraphEndPosition(const VisiblePosition& visiblePos) const
+{
+ if (visiblePos.isNull())
+ return VisiblePosition();
+
+ // make sure we move off of a paragraph end
+ VisiblePosition nextPos = visiblePos.next();
+ if (nextPos.isNull())
+ return VisiblePosition();
+
+ return endOfParagraph(nextPos);
+}
+
+VisiblePosition AccessibilityObject::previousParagraphStartPosition(const VisiblePosition& visiblePos) const
+{
+ if (visiblePos.isNull())
+ return VisiblePosition();
+
+ // make sure we move off of a paragraph start
+ VisiblePosition previousPos = visiblePos.previous();
+ if (previousPos.isNull())
+ return VisiblePosition();
+
+ return startOfParagraph(previousPos);
+}
+
+// NOTE: Consider providing this utility method as AX API
+VisiblePosition AccessibilityObject::visiblePositionForIndex(unsigned, bool) const
+{
+ return VisiblePosition();
+}
+
+AccessibilityObject* AccessibilityObject::accessibilityObjectForPosition(const VisiblePosition& visiblePos) const
+{
+ if (visiblePos.isNull())
+ return 0;
+
+ RenderObject* obj = visiblePos.deepEquivalent().node()->renderer();
+ if (!obj)
+ return 0;
+
+ return obj->document()->axObjectCache()->getOrCreate(obj);
+}
+
+int AccessibilityObject::lineForPosition(const VisiblePosition& visiblePos) const
+{
+ if (visiblePos.isNull())
+ return 0;
+
+ unsigned lineCount = 0;
+ VisiblePosition currentVisiblePos = visiblePos;
+ VisiblePosition savedVisiblePos;
+
+ // move up until we get to the top
+ // FIXME: This only takes us to the top of the rootEditableElement, not the top of the
+ // top document.
+ while (currentVisiblePos.isNotNull() && !(inSameLine(currentVisiblePos, savedVisiblePos))) {
+ ++lineCount;
+ savedVisiblePos = currentVisiblePos;
+ VisiblePosition prevVisiblePos = previousLinePosition(currentVisiblePos, 0);
+ currentVisiblePos = prevVisiblePos;
+ }
+
+ return lineCount - 1;
+}
+
+// NOTE: Consider providing this utility method as AX API
+PlainTextRange AccessibilityObject::plainTextRangeForVisiblePositionRange(const VisiblePositionRange& positionRange) const
+{
+ int index1 = index(positionRange.start);
+ int index2 = index(positionRange.end);
+ if (index1 < 0 || index2 < 0 || index1 > index2)
+ return PlainTextRange();
+
+ return PlainTextRange(index1, index2 - index1);
+}
+
+// NOTE: Consider providing this utility method as AX API
+int AccessibilityObject::index(const VisiblePosition&) const
+{
+ return -1;
+}
+
+// Given a line number, the range of characters of the text associated with this accessibility
+// object that contains the line number.
+PlainTextRange AccessibilityObject::doAXRangeForLine(unsigned) const
+{
+ return PlainTextRange();
+}
+
+// The composed character range in the text associated with this accessibility object that
+// is specified by the given screen coordinates. This parameterized attribute returns the
+// complete range of characters (including surrogate pairs of multi-byte glyphs) at the given
+// screen coordinates.
+// NOTE: This varies from AppKit when the point is below the last line. AppKit returns an
+// an error in that case. We return textControl->text().length(), 1. Does this matter?
+PlainTextRange AccessibilityObject::doAXRangeForPosition(const IntPoint& point) const
+{
+ int i = index(visiblePositionForPoint(point));
+ if (i < 0)
+ return PlainTextRange();
+
+ return PlainTextRange(i, 1);
+}
+
+// The composed character range in the text associated with this accessibility object that
+// is specified by the given index value. This parameterized attribute returns the complete
+// range of characters (including surrogate pairs of multi-byte glyphs) at the given index.
+PlainTextRange AccessibilityObject::doAXRangeForIndex(unsigned) const
+{
+ return PlainTextRange();
+}
+
+// Given a character index, the range of text associated with this accessibility object
+// over which the style in effect at that character index applies.
+PlainTextRange AccessibilityObject::doAXStyleRangeForIndex(unsigned index) const
+{
+ VisiblePositionRange range = styleRangeForPosition(visiblePositionForIndex(index, false));
+ return plainTextRangeForVisiblePositionRange(range);
+}
+
+// A substring of the text associated with this accessibility object that is
+// specified by the given character range.
+String AccessibilityObject::doAXStringForRange(const PlainTextRange&) const
+{
+ return String();
+}
+
+// The bounding rectangle of the text associated with this accessibility object that is
+// specified by the given range. This is the bounding rectangle a sighted user would see
+// on the display screen, in pixels.
+IntRect AccessibilityObject::doAXBoundsForRange(const PlainTextRange&) const
+{
+ return IntRect();
+}
+
+// Given an indexed character, the line number of the text associated with this accessibility
+// object that contains the character.
+unsigned AccessibilityObject::doAXLineForIndex(unsigned index)
+{
+ return lineForPosition(visiblePositionForIndex(index, false));
+}
+
+FrameView* AccessibilityObject::documentFrameView() const
+{
+ const AccessibilityObject* object = this;
+ while (object && !object->isAccessibilityRenderObject())
+ object = object->parentObject();
+
+ if (!object)
+ return 0;
+
+ return object->documentFrameView();
+}
+
+AccessibilityObject* AccessibilityObject::doAccessibilityHitTest(const IntPoint&) const
+{
+ return 0;
+}
+
+AccessibilityObject* AccessibilityObject::focusedUIElement() const
+{
+ return 0;
+}
+
+AccessibilityObject* AccessibilityObject::observableObject() const
+{
+ return 0;
+}
+
+AccessibilityRole AccessibilityObject::roleValue() const
+{
+ return UnknownRole;
+}
+
+AccessibilityRole AccessibilityObject::ariaRoleAttribute() const
+{
+ return UnknownRole;
+}
+
+bool AccessibilityObject::isPresentationalChildOfAriaRole() const
+{
+ return false;
+}
+
+bool AccessibilityObject::ariaRoleHasPresentationalChildren() const
+{
+ return false;
+}
+
+void AccessibilityObject::clearChildren()
+{
+ m_haveChildren = false;
+ m_children.clear();
+}
+
+void AccessibilityObject::childrenChanged()
+{
+ return;
+}
+
+void AccessibilityObject::addChildren()
+{
+}
+
+void AccessibilityObject::selectedChildren(AccessibilityChildrenVector&)
+{
+}
+
+void AccessibilityObject::visibleChildren(AccessibilityChildrenVector&)
+{
+}
+
+unsigned AccessibilityObject::axObjectID() const
+{
+ return m_id;
+}
+
+void AccessibilityObject::setAXObjectID(unsigned axObjectID)
+{
+ m_id = axObjectID;
+}
+
+const String& AccessibilityObject::actionVerb() const
+{
+ // FIXME: Need to add verbs for select elements.
+ DEFINE_STATIC_LOCAL(const String, buttonAction, (AXButtonActionVerb()));
+ DEFINE_STATIC_LOCAL(const String, textFieldAction, (AXTextFieldActionVerb()));
+ DEFINE_STATIC_LOCAL(const String, radioButtonAction, (AXRadioButtonActionVerb()));
+ DEFINE_STATIC_LOCAL(const String, checkedCheckBoxAction, (AXCheckedCheckBoxActionVerb()));
+ DEFINE_STATIC_LOCAL(const String, uncheckedCheckBoxAction, (AXUncheckedCheckBoxActionVerb()));
+ DEFINE_STATIC_LOCAL(const String, linkAction, (AXLinkActionVerb()));
+ DEFINE_STATIC_LOCAL(const String, noAction, ());
+
+ switch (roleValue()) {
+ case ButtonRole:
+ return buttonAction;
+ case TextFieldRole:
+ case TextAreaRole:
+ return textFieldAction;
+ case RadioButtonRole:
+ return radioButtonAction;
+ case CheckBoxRole:
+ return isChecked() ? checkedCheckBoxAction : uncheckedCheckBoxAction;
+ case LinkRole:
+ case WebCoreLinkRole:
+ return linkAction;
+ default:
+ return noAction;
+ }
+}
+
+void AccessibilityObject::updateBackingStore()
+{
+}
+
+} // namespace WebCore
diff --git a/WebCore/accessibility/AccessibilityObject.h b/WebCore/accessibility/AccessibilityObject.h
new file mode 100644
index 0000000..f71be99
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityObject.h
@@ -0,0 +1,432 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2008 Nuanti Ltd.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef AccessibilityObject_h
+#define AccessibilityObject_h
+
+#include "VisiblePosition.h"
+#include <wtf/Platform.h>
+#include <wtf/RefPtr.h>
+#include <wtf/Vector.h>
+
+#if PLATFORM(MAC)
+#include <wtf/RetainPtr.h>
+#elif PLATFORM(WIN)
+#include "AccessibilityObjectWrapperWin.h"
+#include "COMPtr.h"
+#elif PLATFORM(CHROMIUM)
+#include "AccessibilityObjectWrapper.h"
+#endif
+
+typedef struct _NSRange NSRange;
+
+#ifdef __OBJC__
+@class AccessibilityObjectWrapper;
+@class NSArray;
+@class NSAttributedString;
+@class NSData;
+@class NSMutableAttributedString;
+@class NSString;
+@class NSValue;
+@class NSView;
+#else
+class NSArray;
+class NSAttributedString;
+class NSData;
+class NSMutableAttributedString;
+class NSString;
+class NSValue;
+class NSView;
+#if PLATFORM(GTK)
+typedef struct _AtkObject AtkObject;
+typedef struct _AtkObject AccessibilityObjectWrapper;
+#else
+class AccessibilityObjectWrapper;
+#endif
+#endif
+
+namespace WebCore {
+
+class AXObjectCache;
+class Element;
+class Frame;
+class FrameView;
+class HTMLAnchorElement;
+class HTMLAreaElement;
+class IntPoint;
+class IntSize;
+class Node;
+class RenderObject;
+class VisibleSelection;
+class String;
+class Widget;
+
+enum AccessibilityRole {
+ UnknownRole = 1,
+ ButtonRole,
+ RadioButtonRole,
+ CheckBoxRole,
+ SliderRole,
+ TabGroupRole,
+ TextFieldRole,
+ StaticTextRole,
+ TextAreaRole,
+ ScrollAreaRole,
+ PopUpButtonRole,
+ MenuButtonRole,
+ TableRole,
+ ApplicationRole,
+ GroupRole,
+ RadioGroupRole,
+ ListRole,
+ ScrollBarRole,
+ ValueIndicatorRole,
+ ImageRole,
+ MenuBarRole,
+ MenuRole,
+ MenuItemRole,
+ ColumnRole,
+ RowRole,
+ ToolbarRole,
+ BusyIndicatorRole,
+ ProgressIndicatorRole,
+ WindowRole,
+ DrawerRole,
+ SystemWideRole,
+ OutlineRole,
+ IncrementorRole,
+ BrowserRole,
+ ComboBoxRole,
+ SplitGroupRole,
+ SplitterRole,
+ ColorWellRole,
+ GrowAreaRole,
+ SheetRole,
+ HelpTagRole,
+ MatteRole,
+ RulerRole,
+ RulerMarkerRole,
+ LinkRole,
+ DisclosureTriangleRole,
+ GridRole,
+ CellRole,
+ ColumnHeaderRole,
+ RowHeaderRole,
+ // AppKit includes SortButtonRole but it is misnamed and really a subrole of ButtonRole so we do not include it here.
+
+ // WebCore-specific roles
+ WebCoreLinkRole,
+ ImageMapLinkRole,
+ ImageMapRole,
+ ListMarkerRole,
+ WebAreaRole,
+ HeadingRole,
+ ListBoxRole,
+ ListBoxOptionRole,
+ TableHeaderContainerRole,
+ DefinitionListTermRole,
+ DefinitionListDefinitionRole
+};
+
+struct VisiblePositionRange {
+
+ VisiblePosition start;
+ VisiblePosition end;
+
+ VisiblePositionRange() {}
+
+ VisiblePositionRange(const VisiblePosition& s, const VisiblePosition& e)
+ : start(s)
+ , end(e)
+ { }
+
+ bool isNull() const { return start.isNull() || end.isNull(); }
+};
+
+struct PlainTextRange {
+
+ unsigned start;
+ unsigned length;
+
+ PlainTextRange()
+ : start(0)
+ , length(0)
+ { }
+
+ PlainTextRange(unsigned s, unsigned l)
+ : start(s)
+ , length(l)
+ { }
+
+ bool isNull() const { return start == 0 && length == 0; }
+};
+
+class AccessibilityObject : public RefCounted<AccessibilityObject> {
+protected:
+ AccessibilityObject();
+public:
+ virtual ~AccessibilityObject();
+
+ typedef Vector<RefPtr<AccessibilityObject> > AccessibilityChildrenVector;
+
+ virtual bool isAccessibilityRenderObject() const { return false; };
+ virtual bool isAnchor() const { return false; };
+ virtual bool isAttachment() const { return false; };
+ virtual bool isHeading() const { return false; };
+ virtual bool isLink() const { return false; };
+ virtual bool isImage() const { return false; };
+ virtual bool isNativeImage() const { return false; };
+ virtual bool isImageButton() const { return false; };
+ virtual bool isPasswordField() const { return false; };
+ virtual bool isTextControl() const { return false; };
+ virtual bool isNativeTextControl() const { return false; };
+ virtual bool isWebArea() const { return false; };
+ virtual bool isCheckboxOrRadio() const { return false; };
+ virtual bool isListBox() const { return roleValue() == ListBoxRole; };
+ virtual bool isMenuRelated() const { return false; }
+ virtual bool isMenu() const { return false; }
+ virtual bool isMenuBar() const { return false; }
+ virtual bool isMenuButton() const { return false; }
+ virtual bool isMenuItem() const { return false; }
+ virtual bool isFileUploadButton() const { return false; };
+ virtual bool isInputImage() const { return false; }
+ virtual bool isProgressIndicator() const { return false; };
+ virtual bool isSlider() const { return false; };
+ virtual bool isControl() const { return false; };
+ virtual bool isList() const { return false; };
+ virtual bool isDataTable() const { return false; };
+ virtual bool isTableRow() const { return false; };
+ virtual bool isTableColumn() const { return false; };
+ virtual bool isTableCell() const { return false; };
+ virtual bool isFieldset() const { return false; };
+ virtual bool isGroup() const { return false; };
+
+ virtual bool isChecked() const { return false; };
+ virtual bool isEnabled() const { return false; };
+ virtual bool isSelected() const { return false; };
+ virtual bool isFocused() const { return false; };
+ virtual bool isHovered() const { return false; };
+ virtual bool isIndeterminate() const { return false; };
+ virtual bool isLoaded() const { return false; };
+ virtual bool isMultiSelect() const { return false; };
+ virtual bool isOffScreen() const { return false; };
+ virtual bool isPressed() const { return false; };
+ virtual bool isReadOnly() const { return false; };
+ virtual bool isVisited() const { return false; };
+
+ virtual bool canSetFocusAttribute() const { return false; };
+ virtual bool canSetTextRangeAttributes() const { return false; };
+ virtual bool canSetValueAttribute() const { return false; };
+ virtual bool canSetSelectedAttribute() const { return false; }
+ virtual bool canSetSelectedChildrenAttribute() const { return false; }
+
+ virtual bool hasIntValue() const { return false; };
+
+ bool accessibilityShouldUseUniqueId() const { return true; };
+ virtual bool accessibilityIsIgnored() const { return true; };
+
+ virtual int intValue() const;
+ virtual float valueForRange() const { return 0.0f; }
+ virtual float maxValueForRange() const { return 0.0f; }
+ virtual float minValueForRange() const { return 0.0f; }
+ virtual int layoutCount() const;
+ static bool isARIAControl(AccessibilityRole);
+ static bool isARIAInput(AccessibilityRole);
+ unsigned axObjectID() const;
+
+ virtual AccessibilityObject* doAccessibilityHitTest(const IntPoint&) const;
+ virtual AccessibilityObject* focusedUIElement() const;
+ virtual AccessibilityObject* firstChild() const;
+ virtual AccessibilityObject* lastChild() const;
+ virtual AccessibilityObject* previousSibling() const;
+ virtual AccessibilityObject* nextSibling() const;
+ virtual AccessibilityObject* parentObject() const;
+ virtual AccessibilityObject* parentObjectUnignored() const;
+ virtual AccessibilityObject* parentObjectIfExists() const;
+ virtual AccessibilityObject* observableObject() const;
+ virtual void linkedUIElements(AccessibilityChildrenVector&) const;
+ virtual AccessibilityObject* titleUIElement() const;
+ virtual bool exposesTitleUIElement() const { return true; }
+ virtual AccessibilityRole ariaRoleAttribute() const;
+ virtual bool isPresentationalChildOfAriaRole() const;
+ virtual bool ariaRoleHasPresentationalChildren() const;
+
+ virtual AccessibilityRole roleValue() const;
+ virtual AXObjectCache* axObjectCache() const;
+
+ virtual Element* anchorElement() const;
+ virtual Element* actionElement() const;
+ virtual IntRect boundingBoxRect() const;
+ virtual IntRect elementRect() const;
+ virtual IntSize size() const;
+ IntPoint clickPoint() const;
+
+ virtual KURL url() const;
+ virtual PlainTextRange selectedTextRange() const;
+ virtual VisibleSelection selection() const;
+ unsigned selectionStart() const;
+ unsigned selectionEnd() const;
+ virtual String stringValue() const;
+ virtual String ariaAccessiblityName(const String&) const;
+ virtual String ariaLabeledByAttribute() const;
+ virtual String title() const;
+ virtual String ariaDescribedByAttribute() const;
+ virtual String accessibilityDescription() const;
+ virtual String helpText() const;
+ virtual String textUnderElement() const;
+ virtual String text() const;
+ virtual int textLength() const;
+ virtual PassRefPtr<Range> ariaSelectedTextDOMRange() const;
+ virtual String selectedText() const;
+ virtual const AtomicString& accessKey() const;
+ const String& actionVerb() const;
+ virtual Widget* widget() const;
+ virtual Widget* widgetForAttachmentView() const;
+ virtual Document* document() const { return 0; }
+ virtual FrameView* topDocumentFrameView() const { return 0; }
+ virtual FrameView* documentFrameView() const;
+
+ void setAXObjectID(unsigned);
+ virtual void setFocused(bool);
+ virtual void setSelectedText(const String&);
+ virtual void setSelectedTextRange(const PlainTextRange&);
+ virtual void setValue(const String&);
+ virtual void setSelected(bool);
+
+ virtual void detach();
+ virtual void makeRangeVisible(const PlainTextRange&);
+ virtual bool press() const;
+ bool performDefaultAction() const { return press(); }
+
+ virtual void childrenChanged();
+ virtual const AccessibilityChildrenVector& children() { return m_children; }
+ virtual void addChildren();
+ virtual bool canHaveChildren() const { return true; }
+ virtual bool hasChildren() const { return m_haveChildren; };
+ virtual void selectedChildren(AccessibilityChildrenVector&);
+ virtual void visibleChildren(AccessibilityChildrenVector&);
+ virtual bool shouldFocusActiveDescendant() const { return false; }
+ virtual AccessibilityObject* activeDescendant() const { return 0; }
+ virtual void handleActiveDescendantChanged() { }
+
+ virtual VisiblePositionRange visiblePositionRange() const;
+ virtual VisiblePositionRange visiblePositionRangeForLine(unsigned) const;
+
+ VisiblePositionRange visiblePositionRangeForUnorderedPositions(const VisiblePosition&, const VisiblePosition&) const;
+ VisiblePositionRange positionOfLeftWord(const VisiblePosition&) const;
+ VisiblePositionRange positionOfRightWord(const VisiblePosition&) const;
+ VisiblePositionRange leftLineVisiblePositionRange(const VisiblePosition&) const;
+ VisiblePositionRange rightLineVisiblePositionRange(const VisiblePosition&) const;
+ VisiblePositionRange sentenceForPosition(const VisiblePosition&) const;
+ VisiblePositionRange paragraphForPosition(const VisiblePosition&) const;
+ VisiblePositionRange styleRangeForPosition(const VisiblePosition&) const;
+ VisiblePositionRange visiblePositionRangeForRange(const PlainTextRange&) const;
+
+ String stringForVisiblePositionRange(const VisiblePositionRange&) const;
+ virtual IntRect boundsForVisiblePositionRange(const VisiblePositionRange&) const;
+ int lengthForVisiblePositionRange(const VisiblePositionRange&) const;
+ virtual void setSelectedVisiblePositionRange(const VisiblePositionRange&) const;
+
+ virtual VisiblePosition visiblePositionForPoint(const IntPoint&) const;
+ VisiblePosition nextVisiblePosition(const VisiblePosition&) const;
+ VisiblePosition previousVisiblePosition(const VisiblePosition&) const;
+ VisiblePosition nextWordEnd(const VisiblePosition&) const;
+ VisiblePosition previousWordStart(const VisiblePosition&) const;
+ VisiblePosition nextLineEndPosition(const VisiblePosition&) const;
+ VisiblePosition previousLineStartPosition(const VisiblePosition&) const;
+ VisiblePosition nextSentenceEndPosition(const VisiblePosition&) const;
+ VisiblePosition previousSentenceStartPosition(const VisiblePosition&) const;
+ VisiblePosition nextParagraphEndPosition(const VisiblePosition&) const;
+ VisiblePosition previousParagraphStartPosition(const VisiblePosition&) const;
+ virtual VisiblePosition visiblePositionForIndex(unsigned indexValue, bool lastIndexOK) const;
+
+ virtual VisiblePosition visiblePositionForIndex(int) const;
+ virtual int indexForVisiblePosition(const VisiblePosition&) const;
+
+ AccessibilityObject* accessibilityObjectForPosition(const VisiblePosition&) const;
+ int lineForPosition(const VisiblePosition&) const;
+ PlainTextRange plainTextRangeForVisiblePositionRange(const VisiblePositionRange&) const;
+ virtual int index(const VisiblePosition&) const;
+
+ virtual PlainTextRange doAXRangeForLine(unsigned) const;
+ PlainTextRange doAXRangeForPosition(const IntPoint&) const;
+ virtual PlainTextRange doAXRangeForIndex(unsigned) const;
+ PlainTextRange doAXStyleRangeForIndex(unsigned) const;
+
+ virtual String doAXStringForRange(const PlainTextRange&) const;
+ virtual IntRect doAXBoundsForRange(const PlainTextRange&) const;
+
+ unsigned doAXLineForIndex(unsigned);
+
+#if HAVE(ACCESSIBILITY)
+#if PLATFORM(GTK)
+ AccessibilityObjectWrapper* wrapper() const;
+ void setWrapper(AccessibilityObjectWrapper*);
+#else
+ AccessibilityObjectWrapper* wrapper() const { return m_wrapper.get(); }
+ void setWrapper(AccessibilityObjectWrapper* wrapper)
+ {
+ m_wrapper = wrapper;
+ }
+#endif
+#endif
+
+ // a platform-specific method for determining if an attachment is ignored
+#if HAVE(ACCESSIBILITY)
+ bool accessibilityIgnoreAttachment() const;
+#else
+ bool accessibilityIgnoreAttachment() const { return true; }
+#endif
+
+ // allows for an AccessibilityObject to update its render tree or perform
+ // other operations update type operations
+ virtual void updateBackingStore();
+
+protected:
+ unsigned m_id;
+ AccessibilityChildrenVector m_children;
+ mutable bool m_haveChildren;
+
+ virtual void clearChildren();
+ virtual bool isDetached() const { return true; }
+
+#if PLATFORM(MAC)
+ RetainPtr<AccessibilityObjectWrapper> m_wrapper;
+#elif PLATFORM(WIN)
+ COMPtr<AccessibilityObjectWrapper> m_wrapper;
+#elif PLATFORM(GTK)
+ AtkObject* m_wrapper;
+#elif PLATFORM(CHROMIUM)
+ RefPtr<AccessibilityObjectWrapper> m_wrapper;
+#endif
+};
+
+} // namespace WebCore
+
+#endif // AccessibilityObject_h
diff --git a/WebCore/accessibility/AccessibilityRenderObject.cpp b/WebCore/accessibility/AccessibilityRenderObject.cpp
new file mode 100644
index 0000000..8c522a1
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityRenderObject.cpp
@@ -0,0 +1,2539 @@
+/*
+* Copyright (C) 2008 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+* its contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "config.h"
+#include "AccessibilityRenderObject.h"
+
+#include "AXObjectCache.h"
+#include "AccessibilityListBox.h"
+#include "AccessibilityImageMapLink.h"
+#include "CharacterNames.h"
+#include "EventNames.h"
+#include "FloatRect.h"
+#include "FocusController.h"
+#include "Frame.h"
+#include "FrameLoader.h"
+#include "HTMLAreaElement.h"
+#include "HTMLFormElement.h"
+#include "HTMLFrameElementBase.h"
+#include "HTMLImageElement.h"
+#include "HTMLInputElement.h"
+#include "HTMLLabelElement.h"
+#include "HTMLMapElement.h"
+#include "HTMLOptGroupElement.h"
+#include "HTMLOptionElement.h"
+#include "HTMLOptionsCollection.h"
+#include "HTMLSelectElement.h"
+#include "HTMLTextAreaElement.h"
+#include "HitTestRequest.h"
+#include "HitTestResult.h"
+#include "LocalizedStrings.h"
+#include "NodeList.h"
+#include "Page.h"
+#include "RenderFieldset.h"
+#include "RenderFileUploadControl.h"
+#include "RenderHTMLCanvas.h"
+#include "RenderImage.h"
+#include "RenderInline.h"
+#include "RenderListBox.h"
+#include "RenderListMarker.h"
+#include "RenderMenuList.h"
+#include "RenderText.h"
+#include "RenderTextControl.h"
+#include "RenderTheme.h"
+#include "RenderView.h"
+#include "RenderWidget.h"
+#include "SelectionController.h"
+#include "Text.h"
+#include "TextIterator.h"
+#include "htmlediting.h"
+#include "visible_units.h"
+#include <wtf/StdLibExtras.h>
+
+using namespace std;
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+AccessibilityRenderObject::AccessibilityRenderObject(RenderObject* renderer)
+ : m_renderer(renderer)
+ , m_ariaRole(UnknownRole)
+{
+ setAriaRole();
+#ifndef NDEBUG
+ m_renderer->setHasAXObject(true);
+#endif
+}
+
+AccessibilityRenderObject::~AccessibilityRenderObject()
+{
+ ASSERT(isDetached());
+}
+
+PassRefPtr<AccessibilityRenderObject> AccessibilityRenderObject::create(RenderObject* renderer)
+{
+ return adoptRef(new AccessibilityRenderObject(renderer));
+}
+
+void AccessibilityRenderObject::detach()
+{
+ clearChildren();
+ AccessibilityObject::detach();
+
+#ifndef NDEBUG
+ if (m_renderer)
+ m_renderer->setHasAXObject(false);
+#endif
+ m_renderer = 0;
+}
+
+AccessibilityObject* AccessibilityRenderObject::firstChild() const
+{
+ if (!m_renderer)
+ return 0;
+
+ RenderObject* firstChild = m_renderer->firstChild();
+ if (!firstChild)
+ return 0;
+
+ return m_renderer->document()->axObjectCache()->getOrCreate(firstChild);
+}
+
+AccessibilityObject* AccessibilityRenderObject::lastChild() const
+{
+ if (!m_renderer)
+ return 0;
+
+ RenderObject* lastChild = m_renderer->lastChild();
+ if (!lastChild)
+ return 0;
+
+ return m_renderer->document()->axObjectCache()->getOrCreate(lastChild);
+}
+
+AccessibilityObject* AccessibilityRenderObject::previousSibling() const
+{
+ if (!m_renderer)
+ return 0;
+
+ RenderObject* previousSibling = m_renderer->previousSibling();
+ if (!previousSibling)
+ return 0;
+
+ return m_renderer->document()->axObjectCache()->getOrCreate(previousSibling);
+}
+
+AccessibilityObject* AccessibilityRenderObject::nextSibling() const
+{
+ if (!m_renderer)
+ return 0;
+
+ RenderObject* nextSibling = m_renderer->nextSibling();
+ if (!nextSibling)
+ return 0;
+
+ return m_renderer->document()->axObjectCache()->getOrCreate(nextSibling);
+}
+
+AccessibilityObject* AccessibilityRenderObject::parentObjectIfExists() const
+{
+ if (!m_renderer)
+ return 0;
+
+ RenderObject *parent = m_renderer->parent();
+ if (!parent)
+ return 0;
+
+ return m_renderer->document()->axObjectCache()->get(parent);
+}
+
+AccessibilityObject* AccessibilityRenderObject::parentObject() const
+{
+ if (!m_renderer)
+ return 0;
+
+ RenderObject *parent = m_renderer->parent();
+ if (!parent)
+ return 0;
+
+ if (ariaRoleAttribute() == MenuBarRole)
+ return m_renderer->document()->axObjectCache()->getOrCreate(parent);
+
+ // menuButton and its corresponding menu are DOM siblings, but Accessibility needs them to be parent/child
+ if (ariaRoleAttribute() == MenuRole) {
+ AccessibilityObject* parent = menuButtonForMenu();
+ if (parent)
+ return parent;
+ }
+
+ return m_renderer->document()->axObjectCache()->getOrCreate(parent);
+}
+
+bool AccessibilityRenderObject::isWebArea() const
+{
+ return roleValue() == WebAreaRole;
+}
+
+bool AccessibilityRenderObject::isImageButton() const
+{
+ return isNativeImage() && roleValue() == ButtonRole;
+}
+
+bool AccessibilityRenderObject::isAnchor() const
+{
+ return !isNativeImage() && isLink();
+}
+
+bool AccessibilityRenderObject::isNativeTextControl() const
+{
+ return m_renderer->isTextControl();
+}
+
+bool AccessibilityRenderObject::isTextControl() const
+{
+ AccessibilityRole role = roleValue();
+ return role == TextAreaRole || role == TextFieldRole;
+}
+
+bool AccessibilityRenderObject::isNativeImage() const
+{
+ return m_renderer->isImage();
+}
+
+bool AccessibilityRenderObject::isImage() const
+{
+ return roleValue() == ImageRole;
+}
+
+bool AccessibilityRenderObject::isAttachment() const
+{
+ if (!m_renderer)
+ return false;
+
+ // Widgets are the replaced elements that we represent to AX as attachments
+ bool isWidget = m_renderer && m_renderer->isWidget();
+ ASSERT(!isWidget || (m_renderer->isReplaced() && !isImage()));
+ return isWidget && ariaRoleAttribute() == UnknownRole;
+}
+
+bool AccessibilityRenderObject::isPasswordField() const
+{
+ ASSERT(m_renderer);
+ if (!m_renderer->node() || !m_renderer->node()->isHTMLElement())
+ return false;
+ if (ariaRoleAttribute() != UnknownRole)
+ return false;
+
+ InputElement* inputElement = toInputElement(static_cast<Element*>(m_renderer->node()));
+ if (!inputElement)
+ return false;
+
+ return inputElement->isPasswordField();
+}
+
+bool AccessibilityRenderObject::isCheckboxOrRadio() const
+{
+ AccessibilityRole role = roleValue();
+ return role == RadioButtonRole || role == CheckBoxRole;
+}
+
+bool AccessibilityRenderObject::isFileUploadButton() const
+{
+ if (m_renderer && m_renderer->node() && m_renderer->node()->hasTagName(inputTag)) {
+ HTMLInputElement* input = static_cast<HTMLInputElement*>(m_renderer->node());
+ return input->inputType() == HTMLInputElement::FILE;
+ }
+
+ return false;
+}
+
+bool AccessibilityRenderObject::isInputImage() const
+{
+ if (m_renderer && m_renderer->node() && m_renderer->node()->hasTagName(inputTag)) {
+ HTMLInputElement* input = static_cast<HTMLInputElement*>(m_renderer->node());
+ return input->inputType() == HTMLInputElement::IMAGE;
+ }
+
+ return false;
+}
+
+bool AccessibilityRenderObject::isProgressIndicator() const
+{
+ return roleValue() == ProgressIndicatorRole;
+}
+
+bool AccessibilityRenderObject::isSlider() const
+{
+ return roleValue() == SliderRole;
+}
+
+bool AccessibilityRenderObject::isMenuRelated() const
+{
+ AccessibilityRole role = roleValue();
+ return role == MenuRole ||
+ role == MenuBarRole ||
+ role == MenuButtonRole ||
+ role == MenuItemRole;
+}
+
+bool AccessibilityRenderObject::isMenu() const
+{
+ return roleValue() == MenuRole;
+}
+
+bool AccessibilityRenderObject::isMenuBar() const
+{
+ return roleValue() == MenuBarRole;
+}
+
+bool AccessibilityRenderObject::isMenuButton() const
+{
+ return roleValue() == MenuButtonRole;
+}
+
+bool AccessibilityRenderObject::isMenuItem() const
+{
+ return roleValue() == MenuItemRole;
+}
+
+bool AccessibilityRenderObject::isPressed() const
+{
+ ASSERT(m_renderer);
+ if (roleValue() != ButtonRole)
+ return false;
+
+ Node* node = m_renderer->node();
+ if (!node)
+ return false;
+
+ // If this is an ARIA button, check the aria-pressed attribute rather than node()->active()
+ if (ariaRoleAttribute() == ButtonRole) {
+ if (equalIgnoringCase(getAttribute(aria_pressedAttr).string(), "true"))
+ return true;
+ return false;
+ }
+
+ return node->active();
+}
+
+bool AccessibilityRenderObject::isIndeterminate() const
+{
+ ASSERT(m_renderer);
+ if (!m_renderer->node() || !m_renderer->node()->isElementNode())
+ return false;
+
+ InputElement* inputElement = toInputElement(static_cast<Element*>(m_renderer->node()));
+ if (!inputElement)
+ return false;
+
+ return inputElement->isIndeterminate();
+}
+
+bool AccessibilityRenderObject::isChecked() const
+{
+ ASSERT(m_renderer);
+ if (!m_renderer->node() || !m_renderer->node()->isElementNode())
+ return false;
+
+ InputElement* inputElement = toInputElement(static_cast<Element*>(m_renderer->node()));
+ if (!inputElement)
+ return false;
+
+ return inputElement->isChecked();
+}
+
+bool AccessibilityRenderObject::isHovered() const
+{
+ ASSERT(m_renderer);
+ return m_renderer->node() && m_renderer->node()->hovered();
+}
+
+bool AccessibilityRenderObject::isMultiSelect() const
+{
+ ASSERT(m_renderer);
+ if (!m_renderer->isListBox())
+ return false;
+ return m_renderer->node() && static_cast<HTMLSelectElement*>(m_renderer->node())->multiple();
+}
+
+bool AccessibilityRenderObject::isReadOnly() const
+{
+ ASSERT(m_renderer);
+
+ if (isWebArea()) {
+ Document* document = m_renderer->document();
+ if (!document)
+ return true;
+
+ HTMLElement* body = document->body();
+ if (body && body->isContentEditable())
+ return false;
+
+ Frame* frame = document->frame();
+ if (!frame)
+ return true;
+
+ return !frame->isContentEditable();
+ }
+
+ return !m_renderer->node() || !m_renderer->node()->isContentEditable();
+}
+
+bool AccessibilityRenderObject::isOffScreen() const
+{
+ ASSERT(m_renderer);
+ IntRect contentRect = m_renderer->absoluteClippedOverflowRect();
+ FrameView* view = m_renderer->document()->frame()->view();
+ FloatRect viewRect = view->visibleContentRect();
+ viewRect.intersect(contentRect);
+ return viewRect.isEmpty();
+}
+
+int AccessibilityRenderObject::headingLevel(Node* node)
+{
+ // headings can be in block flow and non-block flow
+ if (!node)
+ return 0;
+
+ if (RenderObject* renderer = node->renderer()) {
+ AccessibilityObject* axObjectForNode = node->document()->axObjectCache()->getOrCreate(renderer);
+ if (axObjectForNode->ariaRoleAttribute() == HeadingRole) {
+ if (!node->isElementNode())
+ return 0;
+ Element* element = static_cast<Element*>(node);
+ return element->getAttribute(aria_levelAttr).toInt();
+ }
+ }
+
+
+ if (node->hasTagName(h1Tag))
+ return 1;
+
+ if (node->hasTagName(h2Tag))
+ return 2;
+
+ if (node->hasTagName(h3Tag))
+ return 3;
+
+ if (node->hasTagName(h4Tag))
+ return 4;
+
+ if (node->hasTagName(h5Tag))
+ return 5;
+
+ if (node->hasTagName(h6Tag))
+ return 6;
+
+ return 0;
+}
+
+bool AccessibilityRenderObject::isHeading() const
+{
+ return roleValue() == HeadingRole;
+}
+
+bool AccessibilityRenderObject::isLink() const
+{
+ return roleValue() == WebCoreLinkRole;
+}
+
+bool AccessibilityRenderObject::isControl() const
+{
+ if (!m_renderer)
+ return false;
+
+ Node* node = m_renderer->node();
+ return node && ((node->isElementNode() && static_cast<Element*>(node)->isFormControlElement())
+ || AccessibilityObject::isARIAControl(ariaRoleAttribute()));
+}
+
+bool AccessibilityRenderObject::isFieldset() const
+{
+ if (!m_renderer)
+ return false;
+
+ return m_renderer->isFieldset();
+}
+
+bool AccessibilityRenderObject::isGroup() const
+{
+ return roleValue() == GroupRole;
+}
+
+const AtomicString& AccessibilityRenderObject::getAttribute(const QualifiedName& attribute) const
+{
+ Node* node = m_renderer->node();
+ if (!node)
+ return nullAtom;
+
+ if (!node->isElementNode())
+ return nullAtom;
+
+ Element* element = static_cast<Element*>(node);
+ return element->getAttribute(attribute);
+}
+
+Element* AccessibilityRenderObject::anchorElement() const
+{
+ if (!m_renderer)
+ return 0;
+
+ AXObjectCache* cache = axObjectCache();
+ RenderObject* currRenderer;
+
+ // Search up the render tree for a RenderObject with a DOM node. Defer to an earlier continuation, though.
+ for (currRenderer = m_renderer; currRenderer && !currRenderer->node(); currRenderer = currRenderer->parent()) {
+ if (currRenderer->isRenderBlock()) {
+ RenderInline* continuation = toRenderBlock(currRenderer)->inlineContinuation();
+ if (continuation)
+ return cache->getOrCreate(continuation)->anchorElement();
+ }
+ }
+
+ // bail if none found
+ if (!currRenderer)
+ return 0;
+
+ // search up the DOM tree for an anchor element
+ // NOTE: this assumes that any non-image with an anchor is an HTMLAnchorElement
+ Node* node = currRenderer->node();
+ for ( ; node; node = node->parentNode()) {
+ if (node->hasTagName(aTag) || (node->renderer() && cache->getOrCreate(node->renderer())->isAnchor()))
+ return static_cast<Element*>(node);
+ }
+
+ return 0;
+}
+
+Element* AccessibilityRenderObject::actionElement() const
+{
+ if (!m_renderer)
+ return 0;
+
+ Node* node = m_renderer->node();
+ if (node) {
+ if (node->hasTagName(inputTag)) {
+ HTMLInputElement* input = static_cast<HTMLInputElement*>(node);
+ if (!input->disabled() && (isCheckboxOrRadio() || input->isTextButton()))
+ return input;
+ } else if (node->hasTagName(buttonTag))
+ return static_cast<Element*>(node);
+ }
+
+ if (isFileUploadButton())
+ return static_cast<Element*>(m_renderer->node());
+
+ if (AccessibilityObject::isARIAInput(ariaRoleAttribute()))
+ return static_cast<Element*>(m_renderer->node());
+
+ if (isImageButton())
+ return static_cast<Element*>(m_renderer->node());
+
+ if (m_renderer->isMenuList())
+ return static_cast<Element*>(m_renderer->node());
+
+ Element* elt = anchorElement();
+ if (!elt)
+ elt = mouseButtonListener();
+ return elt;
+}
+
+Element* AccessibilityRenderObject::mouseButtonListener() const
+{
+ Node* node = m_renderer->node();
+ if (!node)
+ return 0;
+
+ // check if our parent is a mouse button listener
+ while (node && !node->isElementNode())
+ node = node->parent();
+
+ if (!node)
+ return 0;
+
+ // FIXME: Do the continuation search like anchorElement does
+ for (Element* element = static_cast<Element*>(node); element; element = element->parentElement()) {
+ if (element->getAttributeEventListener(eventNames().clickEvent) || element->getAttributeEventListener(eventNames().mousedownEvent) || element->getAttributeEventListener(eventNames().mouseupEvent))
+ return element;
+ }
+
+ return 0;
+}
+
+static Element* siblingWithAriaRole(String role, Node* node)
+{
+ Node* sibling = node->parent()->firstChild();
+ while (sibling) {
+ if (sibling->isElementNode()) {
+ String siblingAriaRole = static_cast<Element*>(sibling)->getAttribute(roleAttr).string();
+ if (equalIgnoringCase(siblingAriaRole, role))
+ return static_cast<Element*>(sibling);
+ }
+ sibling = sibling->nextSibling();
+ }
+
+ return 0;
+}
+
+Element* AccessibilityRenderObject::menuElementForMenuButton() const
+{
+ if (ariaRoleAttribute() != MenuButtonRole)
+ return 0;
+
+ return siblingWithAriaRole("menu", renderer()->node());
+}
+
+AccessibilityObject* AccessibilityRenderObject::menuForMenuButton() const
+{
+ Element* menu = menuElementForMenuButton();
+ if (menu && menu->renderer())
+ return m_renderer->document()->axObjectCache()->getOrCreate(menu->renderer());
+ return 0;
+}
+
+Element* AccessibilityRenderObject::menuItemElementForMenu() const
+{
+ if (ariaRoleAttribute() != MenuRole)
+ return 0;
+
+ return siblingWithAriaRole("menuitem", renderer()->node());
+}
+
+AccessibilityObject* AccessibilityRenderObject::menuButtonForMenu() const
+{
+ Element* menuItem = menuItemElementForMenu();
+
+ if (menuItem && menuItem->renderer()) {
+ // ARIA just has generic menu items. AppKit needs to know if this is a top level items like MenuBarButton or MenuBarItem
+ AccessibilityObject* menuItemAX = m_renderer->document()->axObjectCache()->getOrCreate(menuItem->renderer());
+ if (menuItemAX->isMenuButton())
+ return menuItemAX;
+ }
+ return 0;
+}
+
+String AccessibilityRenderObject::helpText() const
+{
+ if (!m_renderer)
+ return String();
+
+ for (RenderObject* curr = m_renderer; curr; curr = curr->parent()) {
+ if (curr->node() && curr->node()->isHTMLElement()) {
+ const AtomicString& summary = static_cast<Element*>(curr->node())->getAttribute(summaryAttr);
+ if (!summary.isEmpty())
+ return summary;
+ const AtomicString& title = static_cast<Element*>(curr->node())->getAttribute(titleAttr);
+ if (!title.isEmpty())
+ return title;
+ }
+ }
+
+ return String();
+}
+
+String AccessibilityRenderObject::textUnderElement() const
+{
+ if (!m_renderer)
+ return String();
+
+ if (isFileUploadButton()) {
+ RenderFileUploadControl* uploadControl = static_cast<RenderFileUploadControl*>(m_renderer);
+ return uploadControl->buttonValue();
+ }
+
+ Node* node = m_renderer->node();
+ if (node) {
+ if (Frame* frame = node->document()->frame()) {
+ // catch stale WebCoreAXObject (see <rdar://problem/3960196>)
+ if (frame->document() != node->document())
+ return String();
+ return plainText(rangeOfContents(node).get());
+ }
+ }
+
+ // return the null string for anonymous text because it is non-trivial to get
+ // the actual text and, so far, that is not needed
+ return String();
+}
+
+bool AccessibilityRenderObject::hasIntValue() const
+{
+ if (isHeading())
+ return true;
+
+ if (m_renderer->node() && isCheckboxOrRadio())
+ return true;
+
+ return false;
+}
+
+int AccessibilityRenderObject::intValue() const
+{
+ if (!m_renderer || isPasswordField())
+ return 0;
+
+ if (isHeading())
+ return headingLevel(m_renderer->node());
+
+ Node* node = m_renderer->node();
+ if (!node || !isCheckboxOrRadio())
+ return 0;
+
+ // If this is an ARIA checkbox or radio, check the aria-checked attribute rather than node()->checked()
+ AccessibilityRole ariaRole = ariaRoleAttribute();
+ if (ariaRole == RadioButtonRole || ariaRole == CheckBoxRole) {
+ if (equalIgnoringCase(getAttribute(aria_checkedAttr).string(), "true"))
+ return true;
+ return false;
+ }
+
+ return static_cast<HTMLInputElement*>(node)->checked();
+}
+
+float AccessibilityRenderObject::valueForRange() const
+{
+ if (!isProgressIndicator() && !isSlider())
+ return 0.0f;
+
+ return getAttribute(aria_valuenowAttr).toFloat();
+}
+
+float AccessibilityRenderObject::maxValueForRange() const
+{
+ if (!isProgressIndicator() && !isSlider())
+ return 0.0f;
+
+ return getAttribute(aria_valuemaxAttr).toFloat();
+}
+
+float AccessibilityRenderObject::minValueForRange() const
+{
+ if (!isProgressIndicator() && !isSlider())
+ return 0.0f;
+
+ return getAttribute(aria_valueminAttr).toFloat();
+}
+
+String AccessibilityRenderObject::stringValue() const
+{
+ if (!m_renderer || isPasswordField())
+ return String();
+
+ if (m_renderer->isText())
+ return textUnderElement();
+
+ if (m_renderer->isMenuList())
+ return static_cast<RenderMenuList*>(m_renderer)->text();
+
+ if (m_renderer->isListMarker())
+ return static_cast<RenderListMarker*>(m_renderer)->text();
+
+ if (isWebArea()) {
+ if (m_renderer->document()->frame())
+ return String();
+
+ // FIXME: should use startOfDocument and endOfDocument (or rangeForDocument?) here
+ VisiblePosition startVisiblePosition = m_renderer->positionForCoordinates(0, 0);
+ VisiblePosition endVisiblePosition = m_renderer->positionForCoordinates(INT_MAX, INT_MAX);
+ if (startVisiblePosition.isNull() || endVisiblePosition.isNull())
+ return String();
+
+ return plainText(makeRange(startVisiblePosition, endVisiblePosition).get());
+ }
+
+ if (isTextControl())
+ return text();
+
+ if (isFileUploadButton()) {
+ RenderFileUploadControl* uploadControl = static_cast<RenderFileUploadControl*>(m_renderer);
+ return uploadControl->fileTextValue();
+ }
+
+ // FIXME: We might need to implement a value here for more types
+ // FIXME: It would be better not to advertise a value at all for the types for which we don't implement one;
+ // this would require subclassing or making accessibilityAttributeNames do something other than return a
+ // single static array.
+ return String();
+}
+
+// This function implements the ARIA accessible name as described by the Mozilla
+// ARIA Implementer's Guide.
+static String accessibleNameForNode(Node* node)
+{
+ if (node->isTextNode())
+ return static_cast<Text*>(node)->data();
+
+ if (node->hasTagName(inputTag))
+ return static_cast<HTMLInputElement*>(node)->value();
+
+ if (node->isHTMLElement()) {
+ const AtomicString& alt = static_cast<HTMLElement*>(node)->getAttribute(altAttr);
+ if (!alt.isEmpty())
+ return alt;
+ }
+
+ return String();
+}
+
+String AccessibilityRenderObject::ariaAccessiblityName(const String& s) const
+{
+ Document* document = m_renderer->document();
+ if (!document)
+ return String();
+
+ String idList = s;
+ idList.replace('\n', ' ');
+ Vector<String> idVector;
+ idList.split(' ', idVector);
+
+ Vector<UChar> ariaLabel;
+ unsigned size = idVector.size();
+ for (unsigned i = 0; i < size; ++i) {
+ String idName = idVector[i];
+ Element* idElement = document->getElementById(idName);
+ if (idElement) {
+ String nameFragment = accessibleNameForNode(idElement);
+ ariaLabel.append(nameFragment.characters(), nameFragment.length());
+ for (Node* n = idElement->firstChild(); n; n = n->traverseNextNode(idElement)) {
+ nameFragment = accessibleNameForNode(n);
+ ariaLabel.append(nameFragment.characters(), nameFragment.length());
+ }
+ ariaLabel.append(' ');
+ }
+ }
+ return String::adopt(ariaLabel);
+}
+
+String AccessibilityRenderObject::ariaLabeledByAttribute() const
+{
+ Node* node = m_renderer->node();
+ if (!node)
+ return String();
+
+ if (!node->isElementNode())
+ return String();
+
+ // The ARIA spec uses the British spelling: "labelled." It seems prudent to support the American
+ // spelling ("labeled") as well.
+ String idList = getAttribute(aria_labeledbyAttr).string();
+ if (idList.isEmpty()) {
+ idList = getAttribute(aria_labelledbyAttr).string();
+ if (idList.isEmpty())
+ return String();
+ }
+
+ return ariaAccessiblityName(idList);
+}
+
+static HTMLLabelElement* labelForElement(Element* element)
+{
+ RefPtr<NodeList> list = element->document()->getElementsByTagName("label");
+ unsigned len = list->length();
+ for (unsigned i = 0; i < len; i++) {
+ if (list->item(i)->hasTagName(labelTag)) {
+ HTMLLabelElement* label = static_cast<HTMLLabelElement*>(list->item(i));
+ if (label->correspondingControl() == element)
+ return label;
+ }
+ }
+
+ return 0;
+}
+
+HTMLLabelElement* AccessibilityRenderObject::labelElementContainer() const
+{
+ if (!m_renderer)
+ return false;
+
+ // the control element should not be considered part of the label
+ if (isControl())
+ return false;
+
+ // find if this has a parent that is a label
+ for (Node* parentNode = m_renderer->node(); parentNode; parentNode = parentNode->parentNode()) {
+ if (parentNode->hasTagName(labelTag))
+ return static_cast<HTMLLabelElement*>(parentNode);
+ }
+
+ return 0;
+}
+
+String AccessibilityRenderObject::title() const
+{
+ AccessibilityRole ariaRole = ariaRoleAttribute();
+
+ if (!m_renderer)
+ return String();
+
+ Node* node = m_renderer->node();
+ if (!node)
+ return String();
+
+ String ariaLabel = ariaLabeledByAttribute();
+ if (!ariaLabel.isEmpty())
+ return ariaLabel;
+
+ const AtomicString& title = getAttribute(titleAttr);
+ if (!title.isEmpty())
+ return title;
+
+ bool isInputTag = node->hasTagName(inputTag);
+ if (isInputTag) {
+ HTMLInputElement* input = static_cast<HTMLInputElement*>(node);
+ if (input->isTextButton())
+ return input->value();
+ }
+
+ if (isInputTag || AccessibilityObject::isARIAInput(ariaRole) || isControl()) {
+ HTMLLabelElement* label = labelForElement(static_cast<Element*>(node));
+ if (label && !titleUIElement())
+ return label->innerText();
+
+ const AtomicString& placeholder = getAttribute(placeholderAttr);
+ if (!placeholder.isEmpty())
+ return placeholder;
+ }
+
+ if (roleValue() == ButtonRole
+ || ariaRole == ListBoxOptionRole
+ || ariaRole == MenuItemRole
+ || ariaRole == MenuButtonRole
+ || isHeading())
+ return textUnderElement();
+
+ if (isLink())
+ return textUnderElement();
+
+ return String();
+}
+
+String AccessibilityRenderObject::ariaDescribedByAttribute() const
+{
+ String idList = getAttribute(aria_describedbyAttr).string();
+ if (idList.isEmpty())
+ return String();
+
+ return ariaAccessiblityName(idList);
+}
+
+String AccessibilityRenderObject::accessibilityDescription() const
+{
+ if (!m_renderer)
+ return String();
+
+ String ariaDescription = ariaDescribedByAttribute();
+ if (!ariaDescription.isEmpty())
+ return ariaDescription;
+
+ if (isImage() || isInputImage() || isNativeImage()) {
+ Node* node = m_renderer->node();
+ if (node && node->isHTMLElement()) {
+ const AtomicString& alt = static_cast<HTMLElement*>(node)->getAttribute(altAttr);
+ if (alt.isEmpty())
+ return String();
+ return alt;
+ }
+ }
+
+ if (isWebArea()) {
+ Document *document = m_renderer->document();
+ Node* owner = document->ownerElement();
+ if (owner) {
+ if (owner->hasTagName(frameTag) || owner->hasTagName(iframeTag)) {
+ const AtomicString& title = static_cast<HTMLFrameElementBase*>(owner)->getAttribute(titleAttr);
+ if (!title.isEmpty())
+ return title;
+ return static_cast<HTMLFrameElementBase*>(owner)->name();
+ }
+ if (owner->isHTMLElement())
+ return static_cast<HTMLElement*>(owner)->getAttribute(nameAttr);
+ }
+ owner = document->body();
+ if (owner && owner->isHTMLElement())
+ return static_cast<HTMLElement*>(owner)->getAttribute(nameAttr);
+ }
+
+ if (roleValue() == DefinitionListTermRole)
+ return AXDefinitionListTermText();
+ if (roleValue() == DefinitionListDefinitionRole)
+ return AXDefinitionListDefinitionText();
+
+ return String();
+}
+
+IntRect AccessibilityRenderObject::boundingBoxRect() const
+{
+ RenderObject* obj = m_renderer;
+
+ if (!obj)
+ return IntRect();
+
+ if (obj->node()) // If we are a continuation, we want to make sure to use the primary renderer.
+ obj = obj->node()->renderer();
+
+ Vector<FloatQuad> quads;
+ obj->absoluteQuads(quads);
+ const size_t n = quads.size();
+ if (!n)
+ return IntRect();
+
+ IntRect result;
+ for (size_t i = 0; i < n; ++i) {
+ IntRect r = quads[i].enclosingBoundingBox();
+ if (!r.isEmpty()) {
+ if (obj->style()->hasAppearance())
+ theme()->adjustRepaintRect(obj, r);
+ result.unite(r);
+ }
+ }
+ return result;
+}
+
+IntRect AccessibilityRenderObject::checkboxOrRadioRect() const
+{
+ if (!m_renderer)
+ return IntRect();
+
+ HTMLLabelElement* label = labelForElement(static_cast<Element*>(m_renderer->node()));
+ if (!label || !label->renderer())
+ return boundingBoxRect();
+
+ IntRect labelRect = axObjectCache()->getOrCreate(label->renderer())->elementRect();
+ labelRect.unite(boundingBoxRect());
+ return labelRect;
+}
+
+IntRect AccessibilityRenderObject::elementRect() const
+{
+ // a checkbox or radio button should encompass its label
+ if (isCheckboxOrRadio())
+ return checkboxOrRadioRect();
+
+ return boundingBoxRect();
+}
+
+IntSize AccessibilityRenderObject::size() const
+{
+ IntRect rect = elementRect();
+ return rect.size();
+}
+
+AccessibilityObject* AccessibilityRenderObject::internalLinkElement() const
+{
+ Element* element = anchorElement();
+ if (!element)
+ return 0;
+
+ // Right now, we do not support ARIA links as internal link elements
+ if (!element->hasTagName(aTag))
+ return 0;
+ HTMLAnchorElement* anchor = static_cast<HTMLAnchorElement*>(element);
+
+ KURL linkURL = anchor->href();
+ String ref = linkURL.ref();
+ if (ref.isEmpty())
+ return 0;
+
+ // check if URL is the same as current URL
+ linkURL.removeRef();
+ if (m_renderer->document()->url() != linkURL)
+ return 0;
+
+ Node* linkedNode = m_renderer->document()->findAnchor(ref);
+ if (!linkedNode)
+ return 0;
+
+ // the element we find may not be accessible, keep searching until we find a good one
+ AccessibilityObject* linkedAXElement = m_renderer->document()->axObjectCache()->getOrCreate(linkedNode->renderer());
+ while (linkedAXElement && linkedAXElement->accessibilityIsIgnored()) {
+ linkedNode = linkedNode->traverseNextNode();
+
+ while (linkedNode && !linkedNode->renderer())
+ linkedNode = linkedNode->traverseNextSibling();
+
+ if (!linkedNode)
+ return 0;
+ linkedAXElement = m_renderer->document()->axObjectCache()->getOrCreate(linkedNode->renderer());
+ }
+
+ return linkedAXElement;
+}
+
+void AccessibilityRenderObject::addRadioButtonGroupMembers(AccessibilityChildrenVector& linkedUIElements) const
+{
+ if (!m_renderer || roleValue() != RadioButtonRole)
+ return;
+
+ Node* node = m_renderer->node();
+ if (!node || !node->hasTagName(inputTag))
+ return;
+
+ HTMLInputElement* input = static_cast<HTMLInputElement*>(node);
+ // if there's a form, then this is easy
+ if (input->form()) {
+ Vector<RefPtr<Node> > formElements;
+ input->form()->getNamedElements(input->name(), formElements);
+
+ unsigned len = formElements.size();
+ for (unsigned i = 0; i < len; ++i) {
+ Node* associateElement = formElements[i].get();
+ if (AccessibilityObject* object = m_renderer->document()->axObjectCache()->getOrCreate(associateElement->renderer()))
+ linkedUIElements.append(object);
+ }
+ } else {
+ RefPtr<NodeList> list = node->document()->getElementsByTagName("input");
+ unsigned len = list->length();
+ for (unsigned i = 0; i < len; ++i) {
+ if (list->item(i)->hasTagName(inputTag)) {
+ HTMLInputElement* associateElement = static_cast<HTMLInputElement*>(list->item(i));
+ if (associateElement->isRadioButton() && associateElement->name() == input->name()) {
+ if (AccessibilityObject* object = m_renderer->document()->axObjectCache()->getOrCreate(associateElement->renderer()))
+ linkedUIElements.append(object);
+ }
+ }
+ }
+ }
+}
+
+// linked ui elements could be all the related radio buttons in a group
+// or an internal anchor connection
+void AccessibilityRenderObject::linkedUIElements(AccessibilityChildrenVector& linkedUIElements) const
+{
+ if (isAnchor()) {
+ AccessibilityObject* linkedAXElement = internalLinkElement();
+ if (linkedAXElement)
+ linkedUIElements.append(linkedAXElement);
+ }
+
+ if (roleValue() == RadioButtonRole)
+ addRadioButtonGroupMembers(linkedUIElements);
+}
+
+bool AccessibilityRenderObject::exposesTitleUIElement() const
+{
+ if (!isControl())
+ return false;
+
+ // checkbox or radio buttons don't expose the title ui element unless it has a title already
+ if (isCheckboxOrRadio() && getAttribute(titleAttr).isEmpty())
+ return false;
+
+ return true;
+}
+
+AccessibilityObject* AccessibilityRenderObject::titleUIElement() const
+{
+ if (!m_renderer)
+ return 0;
+
+ // if isFieldset is true, the renderer is guaranteed to be a RenderFieldset
+ if (isFieldset())
+ return axObjectCache()->getOrCreate(static_cast<RenderFieldset*>(m_renderer)->findLegend());
+
+ if (!exposesTitleUIElement())
+ return 0;
+
+ Node* element = m_renderer->node();
+ HTMLLabelElement* label = labelForElement(static_cast<Element*>(element));
+ if (label && label->renderer())
+ return axObjectCache()->getOrCreate(label->renderer());
+
+ return 0;
+}
+
+bool AccessibilityRenderObject::accessibilityIsIgnored() const
+{
+ // ignore invisible element
+ if (!m_renderer || m_renderer->style()->visibility() != VISIBLE)
+ return true;
+
+ if (isPresentationalChildOfAriaRole())
+ return true;
+
+ // ignore popup menu items because AppKit does
+ for (RenderObject* parent = m_renderer->parent(); parent; parent = parent->parent()) {
+ if (parent->isMenuList())
+ return true;
+ }
+
+ // find out if this element is inside of a label element.
+ // if so, it may be ignored because it's the label for a checkbox or radio button
+ HTMLLabelElement* labelElement = labelElementContainer();
+ if (labelElement) {
+ HTMLElement* correspondingControl = labelElement->correspondingControl();
+ if (correspondingControl && correspondingControl->renderer()) {
+ AccessibilityObject* controlObject = axObjectCache()->getOrCreate(correspondingControl->renderer());
+ if (!controlObject->exposesTitleUIElement())
+ return true;
+ }
+ }
+
+ AccessibilityRole ariaRole = ariaRoleAttribute();
+ if (ariaRole == TextAreaRole || ariaRole == StaticTextRole) {
+ String ariaText = text();
+ return ariaText.isNull() || ariaText.isEmpty();
+ }
+
+ // NOTE: BRs always have text boxes now, so the text box check here can be removed
+ if (m_renderer->isText()) {
+ // static text beneath MenuItems and MenuButtons are just reported along with the menu item, so it's ignored on an individual level
+ if (parentObjectUnignored()->ariaRoleAttribute() == MenuItemRole ||
+ parentObjectUnignored()->ariaRoleAttribute() == MenuButtonRole)
+ return true;
+ RenderText* renderText = toRenderText(m_renderer);
+ if (m_renderer->isBR() || !renderText->firstTextBox())
+ return true;
+
+ // text elements that are just empty whitespace should not be returned
+ return renderText->text()->containsOnlyWhitespace();
+ }
+
+ if (isHeading())
+ return false;
+
+ if (isLink())
+ return false;
+
+ // all controls are accessible
+ if (isControl())
+ return false;
+
+ // don't ignore labels, because they serve as TitleUIElements
+ Node* node = m_renderer->node();
+ if (node && node->hasTagName(labelTag))
+ return false;
+
+ if (m_renderer->isBlockFlow() && m_renderer->childrenInline())
+ return !toRenderBlock(m_renderer)->firstLineBox() && !mouseButtonListener();
+
+ // ignore images seemingly used as spacers
+ if (isImage()) {
+ if (node && node->isElementNode()) {
+ Element* elt = static_cast<Element*>(node);
+ const AtomicString& alt = elt->getAttribute(altAttr);
+ // don't ignore an image that has an alt tag
+ if (!alt.isEmpty())
+ return false;
+ // informal standard is to ignore images with zero-length alt strings
+ if (!alt.isNull())
+ return true;
+ }
+
+ if (node && node->hasTagName(canvasTag)) {
+ RenderHTMLCanvas* canvas = static_cast<RenderHTMLCanvas*>(m_renderer);
+ if (canvas->height() <= 1 || canvas->width() <= 1)
+ return true;
+ return false;
+ }
+
+ // check for one-dimensional image
+ RenderImage* image = toRenderImage(m_renderer);
+ if (image->height() <= 1 || image->width() <= 1)
+ return true;
+
+ // check whether rendered image was stretched from one-dimensional file image
+ if (isNativeImage()) {
+ if (image->cachedImage()) {
+ IntSize imageSize = image->cachedImage()->imageSize(image->view()->zoomFactor());
+ return imageSize.height() <= 1 || imageSize.width() <= 1;
+ }
+ }
+ return false;
+ }
+
+ if (ariaRole != UnknownRole)
+ return false;
+
+ // make a platform-specific decision
+ if (isAttachment())
+ return accessibilityIgnoreAttachment();
+
+ return !m_renderer->isListMarker() && !isWebArea();
+}
+
+bool AccessibilityRenderObject::isLoaded() const
+{
+ return !m_renderer->document()->tokenizer();
+}
+
+int AccessibilityRenderObject::layoutCount() const
+{
+ if (!m_renderer->isRenderView())
+ return 0;
+ return toRenderView(m_renderer)->frameView()->layoutCount();
+}
+
+String AccessibilityRenderObject::text() const
+{
+ if (!isTextControl() || isPasswordField())
+ return String();
+
+ if (isNativeTextControl())
+ return toRenderTextControl(m_renderer)->text();
+
+ Node* node = m_renderer->node();
+ if (!node)
+ return String();
+ if (!node->isElementNode())
+ return String();
+
+ return static_cast<Element*>(node)->innerText();
+}
+
+int AccessibilityRenderObject::textLength() const
+{
+ ASSERT(isTextControl());
+
+ if (isPasswordField())
+ return -1; // need to return something distinct from 0
+
+ return text().length();
+}
+
+PassRefPtr<Range> AccessibilityRenderObject::ariaSelectedTextDOMRange() const
+{
+ Node* node = m_renderer->node();
+ if (!node)
+ return 0;
+
+ RefPtr<Range> currentSelectionRange = selection().toNormalizedRange();
+ if (!currentSelectionRange)
+ return 0;
+
+ ExceptionCode ec = 0;
+ if (!currentSelectionRange->intersectsNode(node, ec))
+ return Range::create(currentSelectionRange->ownerDocument());
+
+ RefPtr<Range> ariaRange = rangeOfContents(node);
+ Position startPosition, endPosition;
+
+ // Find intersection of currentSelectionRange and ariaRange
+ if (ariaRange->startOffset() > currentSelectionRange->startOffset())
+ startPosition = ariaRange->startPosition();
+ else
+ startPosition = currentSelectionRange->startPosition();
+
+ if (ariaRange->endOffset() < currentSelectionRange->endOffset())
+ endPosition = ariaRange->endPosition();
+ else
+ endPosition = currentSelectionRange->endPosition();
+
+ return Range::create(ariaRange->ownerDocument(), startPosition, endPosition);
+}
+
+String AccessibilityRenderObject::selectedText() const
+{
+ ASSERT(isTextControl());
+
+ if (isPasswordField())
+ return String(); // need to return something distinct from empty string
+
+ if (isNativeTextControl()) {
+ RenderTextControl* textControl = toRenderTextControl(m_renderer);
+ return textControl->text().substring(textControl->selectionStart(), textControl->selectionEnd() - textControl->selectionStart());
+ }
+
+ if (ariaRoleAttribute() == UnknownRole)
+ return String();
+
+ RefPtr<Range> ariaRange = ariaSelectedTextDOMRange();
+ if (!ariaRange)
+ return String();
+ return ariaRange->text();
+}
+
+const AtomicString& AccessibilityRenderObject::accessKey() const
+{
+ Node* node = m_renderer->node();
+ if (!node)
+ return nullAtom;
+ if (!node->isElementNode())
+ return nullAtom;
+ return static_cast<Element*>(node)->getAttribute(accesskeyAttr);
+}
+
+VisibleSelection AccessibilityRenderObject::selection() const
+{
+ return m_renderer->document()->frame()->selection()->selection();
+}
+
+PlainTextRange AccessibilityRenderObject::selectedTextRange() const
+{
+ ASSERT(isTextControl());
+
+ if (isPasswordField())
+ return PlainTextRange();
+
+ AccessibilityRole ariaRole = ariaRoleAttribute();
+ if (isNativeTextControl() && ariaRole == UnknownRole) {
+ RenderTextControl* textControl = toRenderTextControl(m_renderer);
+ return PlainTextRange(textControl->selectionStart(), textControl->selectionEnd() - textControl->selectionStart());
+ }
+
+ if (ariaRole == UnknownRole)
+ return PlainTextRange();
+
+ RefPtr<Range> ariaRange = ariaSelectedTextDOMRange();
+ if (!ariaRange)
+ return PlainTextRange();
+ return PlainTextRange(ariaRange->startOffset(), ariaRange->endOffset());
+}
+
+void AccessibilityRenderObject::setSelectedTextRange(const PlainTextRange& range)
+{
+ if (isNativeTextControl()) {
+ RenderTextControl* textControl = toRenderTextControl(m_renderer);
+ textControl->setSelectionRange(range.start, range.start + range.length);
+ return;
+ }
+
+ Document* document = m_renderer->document();
+ if (!document)
+ return;
+ Frame* frame = document->frame();
+ if (!frame)
+ return;
+ Node* node = m_renderer->node();
+ frame->selection()->setSelection(VisibleSelection(Position(node, range.start),
+ Position(node, range.start + range.length), DOWNSTREAM));
+}
+
+KURL AccessibilityRenderObject::url() const
+{
+ if (isAnchor() && m_renderer->node()->hasTagName(aTag)) {
+ if (HTMLAnchorElement* anchor = static_cast<HTMLAnchorElement*>(anchorElement()))
+ return anchor->href();
+ }
+
+ if (isWebArea())
+ return m_renderer->document()->url();
+
+ if (isImage() && m_renderer->node() && m_renderer->node()->hasTagName(imgTag))
+ return static_cast<HTMLImageElement*>(m_renderer->node())->src();
+
+ if (isInputImage())
+ return static_cast<HTMLInputElement*>(m_renderer->node())->src();
+
+ return KURL();
+}
+
+bool AccessibilityRenderObject::isVisited() const
+{
+ return m_renderer->style()->pseudoState() == PseudoVisited;
+}
+
+bool AccessibilityRenderObject::isSelected() const
+{
+ if (!m_renderer)
+ return false;
+
+ Node* node = m_renderer->node();
+ if (!node)
+ return false;
+
+ return false;
+}
+
+bool AccessibilityRenderObject::isFocused() const
+{
+ if (!m_renderer)
+ return false;
+
+ Document* document = m_renderer->document();
+ if (!document)
+ return false;
+
+ Node* focusedNode = document->focusedNode();
+ if (!focusedNode)
+ return false;
+
+ // A web area is represented by the Document node in the DOM tree, which isn't focusable.
+ // Check instead if the frame's selection controller is focused
+ if (focusedNode == m_renderer->node() ||
+ (roleValue() == WebAreaRole && document->frame()->selection()->isFocusedAndActive()))
+ return true;
+
+ return false;
+}
+
+void AccessibilityRenderObject::setFocused(bool on)
+{
+ if (!canSetFocusAttribute())
+ return;
+
+ if (!on)
+ m_renderer->document()->setFocusedNode(0);
+ else {
+ if (m_renderer->node()->isElementNode())
+ static_cast<Element*>(m_renderer->node())->focus();
+ else
+ m_renderer->document()->setFocusedNode(m_renderer->node());
+ }
+}
+
+void AccessibilityRenderObject::setValue(const String& string)
+{
+ // FIXME: Do we want to do anything here for ARIA textboxes?
+ if (m_renderer->isTextField()) {
+ HTMLInputElement* input = static_cast<HTMLInputElement*>(m_renderer->node());
+ input->setValue(string);
+ } else if (m_renderer->isTextArea()) {
+ HTMLTextAreaElement* textArea = static_cast<HTMLTextAreaElement*>(m_renderer->node());
+ textArea->setValue(string);
+ }
+}
+
+bool AccessibilityRenderObject::isEnabled() const
+{
+ ASSERT(m_renderer);
+ Node* node = m_renderer->node();
+ if (!node || !node->isElementNode())
+ return true;
+
+ return static_cast<Element*>(node)->isEnabledFormControl();
+}
+
+RenderView* AccessibilityRenderObject::topRenderer() const
+{
+ return m_renderer->document()->topDocument()->renderView();
+}
+
+Document* AccessibilityRenderObject::document() const
+{
+ return m_renderer->document();
+}
+
+FrameView* AccessibilityRenderObject::topDocumentFrameView() const
+{
+ return topRenderer()->view()->frameView();
+}
+
+Widget* AccessibilityRenderObject::widget() const
+{
+ if (!m_renderer->isWidget())
+ return 0;
+
+ return static_cast<RenderWidget*>(m_renderer)->widget();
+}
+
+AXObjectCache* AccessibilityRenderObject::axObjectCache() const
+{
+ return m_renderer->document()->axObjectCache();
+}
+
+AccessibilityObject* AccessibilityRenderObject::accessibilityParentForImageMap(HTMLMapElement* map) const
+{
+ // find an image that is using this map
+ if (!m_renderer || !map)
+ return 0;
+
+ String mapName = map->getName().string().lower();
+ RefPtr<HTMLCollection> coll = m_renderer->document()->images();
+ for (Node* curr = coll->firstItem(); curr; curr = coll->nextItem()) {
+ RenderObject* obj = curr->renderer();
+ if (!obj || !curr->hasTagName(imgTag))
+ continue;
+
+ // The HTMLImageElement's useMap() value includes the '#' symbol at the beginning,
+ // which has to be stripped off
+ String useMapName = static_cast<HTMLImageElement*>(curr)->useMap().substring(1).lower();
+ if (useMapName == mapName)
+ return axObjectCache()->getOrCreate(obj);
+ }
+
+ return 0;
+}
+
+void AccessibilityRenderObject::getDocumentLinks(AccessibilityChildrenVector& result)
+{
+ Document* document = m_renderer->document();
+ RefPtr<HTMLCollection> coll = document->links();
+ Node* curr = coll->firstItem();
+ while (curr) {
+ RenderObject* obj = curr->renderer();
+ if (obj) {
+ RefPtr<AccessibilityObject> axobj = document->axObjectCache()->getOrCreate(obj);
+ ASSERT(axobj);
+ if (!axobj->accessibilityIsIgnored() && axobj->isLink())
+ result.append(axobj);
+ } else {
+ Node* parent = curr->parent();
+ if (parent && curr->hasTagName(areaTag) && parent->hasTagName(mapTag)) {
+ AccessibilityImageMapLink* areaObject = static_cast<AccessibilityImageMapLink*>(axObjectCache()->getOrCreate(ImageMapLinkRole));
+ areaObject->setHTMLAreaElement(static_cast<HTMLAreaElement*>(curr));
+ areaObject->setHTMLMapElement(static_cast<HTMLMapElement*>(parent));
+ areaObject->setParent(accessibilityParentForImageMap(static_cast<HTMLMapElement*>(parent)));
+
+ result.append(areaObject);
+ }
+ }
+ curr = coll->nextItem();
+ }
+}
+
+FrameView* AccessibilityRenderObject::documentFrameView() const
+{
+ if (!m_renderer || !m_renderer->document())
+ return 0;
+
+ // this is the RenderObject's Document's Frame's FrameView
+ return m_renderer->document()->view();
+}
+
+Widget* AccessibilityRenderObject::widgetForAttachmentView() const
+{
+ if (!isAttachment())
+ return 0;
+ return static_cast<RenderWidget*>(m_renderer)->widget();
+}
+
+FrameView* AccessibilityRenderObject::frameViewIfRenderView() const
+{
+ if (!m_renderer->isRenderView())
+ return 0;
+ // this is the RenderObject's Document's renderer's FrameView
+ return m_renderer->view()->frameView();
+}
+
+// This function is like a cross-platform version of - (WebCoreTextMarkerRange*)textMarkerRange. It returns
+// a Range that we can convert to a WebCoreTextMarkerRange in the Obj-C file
+VisiblePositionRange AccessibilityRenderObject::visiblePositionRange() const
+{
+ if (!m_renderer)
+ return VisiblePositionRange();
+
+ // construct VisiblePositions for start and end
+ Node* node = m_renderer->node();
+ if (!node)
+ return VisiblePositionRange();
+
+ VisiblePosition startPos = firstDeepEditingPositionForNode(node);
+ VisiblePosition endPos = lastDeepEditingPositionForNode(node);
+
+ // the VisiblePositions are equal for nodes like buttons, so adjust for that
+ // FIXME: Really? [button, 0] and [button, 1] are distinct (before and after the button)
+ // I expect this code is only hit for things like empty divs? In which case I don't think
+ // the behavior is correct here -- eseidel
+ if (startPos == endPos) {
+ endPos = endPos.next();
+ if (endPos.isNull())
+ endPos = startPos;
+ }
+
+ return VisiblePositionRange(startPos, endPos);
+}
+
+VisiblePositionRange AccessibilityRenderObject::visiblePositionRangeForLine(unsigned lineCount) const
+{
+ if (lineCount == 0 || !m_renderer)
+ return VisiblePositionRange();
+
+ // iterate over the lines
+ // FIXME: this is wrong when lineNumber is lineCount+1, because nextLinePosition takes you to the
+ // last offset of the last line
+ VisiblePosition visiblePos = m_renderer->document()->renderer()->positionForCoordinates(0, 0);
+ VisiblePosition savedVisiblePos;
+ while (--lineCount != 0) {
+ savedVisiblePos = visiblePos;
+ visiblePos = nextLinePosition(visiblePos, 0);
+ if (visiblePos.isNull() || visiblePos == savedVisiblePos)
+ return VisiblePositionRange();
+ }
+
+ // make a caret selection for the marker position, then extend it to the line
+ // NOTE: ignores results of sel.modify because it returns false when
+ // starting at an empty line. The resulting selection in that case
+ // will be a caret at visiblePos.
+ SelectionController selection;
+ selection.setSelection(VisibleSelection(visiblePos));
+ selection.modify(SelectionController::EXTEND, SelectionController::RIGHT, LineBoundary);
+
+ return VisiblePositionRange(selection.selection().visibleStart(), selection.selection().visibleEnd());
+}
+
+VisiblePosition AccessibilityRenderObject::visiblePositionForIndex(int index) const
+{
+ if (!m_renderer)
+ return VisiblePosition();
+
+ if (isNativeTextControl())
+ return toRenderTextControl(m_renderer)->visiblePositionForIndex(index);
+
+ if (!isTextControl() && !m_renderer->isText())
+ return VisiblePosition();
+
+ Node* node = m_renderer->node();
+ if (!node)
+ return VisiblePosition();
+
+ if (index <= 0)
+ return VisiblePosition(node, 0, DOWNSTREAM);
+
+ ExceptionCode ec = 0;
+ RefPtr<Range> range = Range::create(m_renderer->document());
+ range->selectNodeContents(node, ec);
+ CharacterIterator it(range.get());
+ it.advance(index - 1);
+ return VisiblePosition(it.range()->endContainer(ec), it.range()->endOffset(ec), UPSTREAM);
+}
+
+int AccessibilityRenderObject::indexForVisiblePosition(const VisiblePosition& pos) const
+{
+ if (isNativeTextControl())
+ return toRenderTextControl(m_renderer)->indexForVisiblePosition(pos);
+
+ if (!isTextControl())
+ return 0;
+
+ Node* node = m_renderer->node();
+ if (!node)
+ return 0;
+
+ Position indexPosition = pos.deepEquivalent();
+ if (!indexPosition.node() || indexPosition.node()->rootEditableElement() != node)
+ return 0;
+
+ ExceptionCode ec = 0;
+ RefPtr<Range> range = Range::create(m_renderer->document());
+ range->setStart(node, 0, ec);
+ range->setEnd(indexPosition.node(), indexPosition.deprecatedEditingOffset(), ec);
+ return TextIterator::rangeLength(range.get());
+}
+
+IntRect AccessibilityRenderObject::boundsForVisiblePositionRange(const VisiblePositionRange& visiblePositionRange) const
+{
+ if (visiblePositionRange.isNull())
+ return IntRect();
+
+ // Create a mutable VisiblePositionRange.
+ VisiblePositionRange range(visiblePositionRange);
+ IntRect rect1 = range.start.absoluteCaretBounds();
+ IntRect rect2 = range.end.absoluteCaretBounds();
+
+ // readjust for position at the edge of a line. This is to exclude line rect that doesn't need to be accounted in the range bounds
+ if (rect2.y() != rect1.y()) {
+ VisiblePosition endOfFirstLine = endOfLine(range.start);
+ if (range.start == endOfFirstLine) {
+ range.start.setAffinity(DOWNSTREAM);
+ rect1 = range.start.absoluteCaretBounds();
+ }
+ if (range.end == endOfFirstLine) {
+ range.end.setAffinity(UPSTREAM);
+ rect2 = range.end.absoluteCaretBounds();
+ }
+ }
+
+ IntRect ourrect = rect1;
+ ourrect.unite(rect2);
+
+ // if the rectangle spans lines and contains multiple text chars, use the range's bounding box intead
+ if (rect1.bottom() != rect2.bottom()) {
+ RefPtr<Range> dataRange = makeRange(range.start, range.end);
+ IntRect boundingBox = dataRange->boundingBox();
+ String rangeString = plainText(dataRange.get());
+ if (rangeString.length() > 1 && !boundingBox.isEmpty())
+ ourrect = boundingBox;
+ }
+
+#if PLATFORM(MAC)
+ return m_renderer->document()->view()->contentsToScreen(ourrect);
+#else
+ return ourrect;
+#endif
+}
+
+void AccessibilityRenderObject::setSelectedVisiblePositionRange(const VisiblePositionRange& range) const
+{
+ if (range.start.isNull() || range.end.isNull())
+ return;
+
+ // make selection and tell the document to use it. if it's zero length, then move to that position
+ if (range.start == range.end) {
+ m_renderer->document()->frame()->selection()->moveTo(range.start, true);
+ }
+ else {
+ VisibleSelection newSelection = VisibleSelection(range.start, range.end);
+ m_renderer->document()->frame()->selection()->setSelection(newSelection);
+ }
+}
+
+VisiblePosition AccessibilityRenderObject::visiblePositionForPoint(const IntPoint& point) const
+{
+ // convert absolute point to view coordinates
+ FrameView* frameView = m_renderer->document()->topDocument()->renderer()->view()->frameView();
+ RenderView* renderView = topRenderer();
+ Node* innerNode = 0;
+
+ // locate the node containing the point
+ IntPoint pointResult;
+ while (1) {
+ IntPoint ourpoint;
+#if PLATFORM(MAC)
+ ourpoint = frameView->screenToContents(point);
+#else
+ ourpoint = point;
+#endif
+ HitTestRequest request(HitTestRequest::ReadOnly |
+ HitTestRequest::Active);
+ HitTestResult result(ourpoint);
+ renderView->layer()->hitTest(request, result);
+ innerNode = result.innerNode();
+ if (!innerNode || !innerNode->renderer())
+ return VisiblePosition();
+
+ pointResult = result.localPoint();
+
+ // done if hit something other than a widget
+ RenderObject* renderer = innerNode->renderer();
+ if (!renderer->isWidget())
+ break;
+
+ // descend into widget (FRAME, IFRAME, OBJECT...)
+ Widget* widget = static_cast<RenderWidget*>(renderer)->widget();
+ if (!widget || !widget->isFrameView())
+ break;
+ Frame* frame = static_cast<FrameView*>(widget)->frame();
+ if (!frame)
+ break;
+ renderView = frame->document()->renderView();
+ frameView = static_cast<FrameView*>(widget);
+ }
+
+ return innerNode->renderer()->positionForPoint(pointResult);
+}
+
+// NOTE: Consider providing this utility method as AX API
+VisiblePosition AccessibilityRenderObject::visiblePositionForIndex(unsigned indexValue, bool lastIndexOK) const
+{
+ if (!isTextControl())
+ return VisiblePosition();
+
+ // lastIndexOK specifies whether the position after the last character is acceptable
+ if (indexValue >= text().length()) {
+ if (!lastIndexOK || indexValue > text().length())
+ return VisiblePosition();
+ }
+ VisiblePosition position = visiblePositionForIndex(indexValue);
+ position.setAffinity(DOWNSTREAM);
+ return position;
+}
+
+// NOTE: Consider providing this utility method as AX API
+int AccessibilityRenderObject::index(const VisiblePosition& position) const
+{
+ if (!isTextControl())
+ return -1;
+
+ Node* node = position.deepEquivalent().node();
+ if (!node)
+ return -1;
+
+ for (RenderObject* renderer = node->renderer(); renderer && renderer->node(); renderer = renderer->parent()) {
+ if (renderer == m_renderer)
+ return indexForVisiblePosition(position);
+ }
+
+ return -1;
+}
+
+// Given a line number, the range of characters of the text associated with this accessibility
+// object that contains the line number.
+PlainTextRange AccessibilityRenderObject::doAXRangeForLine(unsigned lineNumber) const
+{
+ if (!isTextControl())
+ return PlainTextRange();
+
+ // iterate to the specified line
+ VisiblePosition visiblePos = visiblePositionForIndex(0);
+ VisiblePosition savedVisiblePos;
+ for (unsigned lineCount = lineNumber; lineCount != 0; lineCount -= 1) {
+ savedVisiblePos = visiblePos;
+ visiblePos = nextLinePosition(visiblePos, 0);
+ if (visiblePos.isNull() || visiblePos == savedVisiblePos)
+ return PlainTextRange();
+ }
+
+ // make a caret selection for the marker position, then extend it to the line
+ // NOTE: ignores results of selection.modify because it returns false when
+ // starting at an empty line. The resulting selection in that case
+ // will be a caret at visiblePos.
+ SelectionController selection;
+ selection.setSelection(VisibleSelection(visiblePos));
+ selection.modify(SelectionController::EXTEND, SelectionController::LEFT, LineBoundary);
+ selection.modify(SelectionController::EXTEND, SelectionController::RIGHT, LineBoundary);
+
+ // calculate the indices for the selection start and end
+ VisiblePosition startPosition = selection.selection().visibleStart();
+ VisiblePosition endPosition = selection.selection().visibleEnd();
+ int index1 = indexForVisiblePosition(startPosition);
+ int index2 = indexForVisiblePosition(endPosition);
+
+ // add one to the end index for a line break not caused by soft line wrap (to match AppKit)
+ if (endPosition.affinity() == DOWNSTREAM && endPosition.next().isNotNull())
+ index2 += 1;
+
+ // return nil rather than an zero-length range (to match AppKit)
+ if (index1 == index2)
+ return PlainTextRange();
+
+ return PlainTextRange(index1, index2 - index1);
+}
+
+// The composed character range in the text associated with this accessibility object that
+// is specified by the given index value. This parameterized attribute returns the complete
+// range of characters (including surrogate pairs of multi-byte glyphs) at the given index.
+PlainTextRange AccessibilityRenderObject::doAXRangeForIndex(unsigned index) const
+{
+ if (!isTextControl())
+ return PlainTextRange();
+
+ String elementText = text();
+ if (!elementText.length() || index > elementText.length() - 1)
+ return PlainTextRange();
+
+ return PlainTextRange(index, 1);
+}
+
+// A substring of the text associated with this accessibility object that is
+// specified by the given character range.
+String AccessibilityRenderObject::doAXStringForRange(const PlainTextRange& range) const
+{
+ if (isPasswordField())
+ return String();
+
+ if (range.length == 0)
+ return "";
+
+ if (!isTextControl())
+ return String();
+
+ String elementText = text();
+ if (range.start + range.length > elementText.length())
+ return String();
+
+ return elementText.substring(range.start, range.length);
+}
+
+// The bounding rectangle of the text associated with this accessibility object that is
+// specified by the given range. This is the bounding rectangle a sighted user would see
+// on the display screen, in pixels.
+IntRect AccessibilityRenderObject::doAXBoundsForRange(const PlainTextRange& range) const
+{
+ if (isTextControl())
+ return boundsForVisiblePositionRange(visiblePositionRangeForRange(range));
+ return IntRect();
+}
+
+AccessibilityObject* AccessibilityRenderObject::accessibilityImageMapHitTest(HTMLAreaElement* area, const IntPoint& point) const
+{
+ if (!area)
+ return 0;
+
+ HTMLMapElement *map = static_cast<HTMLMapElement*>(area->parent());
+ AccessibilityObject* parent = accessibilityParentForImageMap(map);
+ if (!parent)
+ return 0;
+
+ AccessibilityObject::AccessibilityChildrenVector children = parent->children();
+
+ unsigned count = children.size();
+ for (unsigned k = 0; k < count; ++k) {
+ if (children[k]->elementRect().contains(point))
+ return children[k].get();
+ }
+
+ return 0;
+}
+
+AccessibilityObject* AccessibilityRenderObject::doAccessibilityHitTest(const IntPoint& point) const
+{
+ if (!m_renderer || !m_renderer->hasLayer())
+ return 0;
+
+ RenderLayer* layer = toRenderBox(m_renderer)->layer();
+
+ HitTestRequest request(HitTestRequest::ReadOnly |
+ HitTestRequest::Active);
+ HitTestResult hitTestResult = HitTestResult(point);
+ layer->hitTest(request, hitTestResult);
+ if (!hitTestResult.innerNode())
+ return 0;
+ Node* node = hitTestResult.innerNode()->shadowAncestorNode();
+
+ if (node->hasTagName(areaTag))
+ return accessibilityImageMapHitTest(static_cast<HTMLAreaElement*>(node), point);
+
+ RenderObject* obj = node->renderer();
+ if (!obj)
+ return 0;
+
+ AccessibilityObject *result = obj->document()->axObjectCache()->getOrCreate(obj);
+
+ if (obj->isListBox())
+ return static_cast<AccessibilityListBox*>(result)->doAccessibilityHitTest(point);
+
+ if (result->accessibilityIsIgnored())
+ result = result->parentObjectUnignored();
+
+ return result;
+}
+
+AccessibilityObject* AccessibilityRenderObject::focusedUIElement() const
+{
+ // get the focused node in the page
+ Page* page = m_renderer->document()->page();
+ if (!page)
+ return 0;
+
+ Document* focusedDocument = page->focusController()->focusedOrMainFrame()->document();
+ Node* focusedNode = focusedDocument->focusedNode();
+ if (!focusedNode)
+ focusedNode = focusedDocument;
+
+ RenderObject* focusedNodeRenderer = focusedNode->renderer();
+ if (!focusedNodeRenderer)
+ return 0;
+
+ AccessibilityObject* obj = focusedNodeRenderer->document()->axObjectCache()->getOrCreate(focusedNodeRenderer);
+
+ if (obj->shouldFocusActiveDescendant()) {
+ if (AccessibilityObject* descendant = obj->activeDescendant())
+ obj = descendant;
+ }
+
+ // the HTML element, for example, is focusable but has an AX object that is ignored
+ if (obj->accessibilityIsIgnored())
+ obj = obj->parentObjectUnignored();
+
+ return obj;
+}
+
+bool AccessibilityRenderObject::shouldFocusActiveDescendant() const
+{
+ switch (ariaRoleAttribute()) {
+ case GroupRole:
+ case ComboBoxRole:
+ case ListBoxRole:
+ case MenuRole:
+ case MenuBarRole:
+ case RadioGroupRole:
+ case RowRole:
+ case PopUpButtonRole:
+ case ProgressIndicatorRole:
+ case ToolbarRole:
+ case OutlineRole:
+ /* FIXME: replace these with actual roles when they are added to AccessibilityRole
+ composite
+ alert
+ alertdialog
+ grid
+ status
+ timer
+ tree
+ */
+ return true;
+ default:
+ return false;
+ }
+}
+
+AccessibilityObject* AccessibilityRenderObject::activeDescendant() const
+{
+ if (renderer()->node() && !renderer()->node()->isElementNode())
+ return 0;
+ Element* element = static_cast<Element*>(renderer()->node());
+
+ String activeDescendantAttrStr = element->getAttribute(aria_activedescendantAttr).string();
+ if (activeDescendantAttrStr.isNull() || activeDescendantAttrStr.isEmpty())
+ return 0;
+
+ Element* target = renderer()->document()->getElementById(activeDescendantAttrStr);
+ if (!target)
+ return 0;
+
+ AccessibilityObject* obj = renderer()->document()->axObjectCache()->getOrCreate(target->renderer());
+ if (obj->isAccessibilityRenderObject())
+ // an activedescendant is only useful if it has a renderer, because that's what's needed to post the notification
+ return obj;
+ return 0;
+}
+
+
+void AccessibilityRenderObject::handleActiveDescendantChanged()
+{
+ Element* element = static_cast<Element*>(renderer()->node());
+ if (!element)
+ return;
+ Document* doc = renderer()->document();
+ if (!doc->frame()->selection()->isFocusedAndActive() || doc->focusedNode() != element)
+ return;
+ AccessibilityRenderObject* activedescendant = static_cast<AccessibilityRenderObject*>(activeDescendant());
+
+ if (activedescendant && shouldFocusActiveDescendant())
+ doc->axObjectCache()->postNotification(activedescendant->renderer(), "AXFocusedUIElementChanged", true);
+}
+
+
+AccessibilityObject* AccessibilityRenderObject::observableObject() const
+{
+ for (RenderObject* renderer = m_renderer; renderer && renderer->node(); renderer = renderer->parent()) {
+ if (renderer->isTextControl())
+ return renderer->document()->axObjectCache()->getOrCreate(renderer);
+ }
+
+ return 0;
+}
+
+typedef HashMap<String, AccessibilityRole, CaseFoldingHash> ARIARoleMap;
+
+static const ARIARoleMap& createARIARoleMap()
+{
+ struct RoleEntry {
+ String ariaRole;
+ AccessibilityRole webcoreRole;
+ };
+
+ const RoleEntry roles[] = {
+ { "button", ButtonRole },
+ { "checkbox", CheckBoxRole },
+ { "grid", TableRole },
+ { "gridcell", CellRole },
+ { "columnheader", ColumnHeaderRole },
+ { "rowheader", RowHeaderRole },
+ { "group", GroupRole },
+ { "heading", HeadingRole },
+ { "img", ImageRole },
+ { "link", WebCoreLinkRole },
+ { "listbox", ListBoxRole },
+ // "option" isn't here because it may map to different roles depending on the parent element's role
+ { "menu", MenuRole },
+ { "menubar", GroupRole },
+ // "menuitem" isn't here because it may map to different roles depending on the parent element's role
+ { "menuitemcheckbox", MenuItemRole },
+ { "menuitemradio", MenuItemRole },
+ { "progressbar", ProgressIndicatorRole },
+ { "radio", RadioButtonRole },
+ { "row", RowRole },
+ { "range", SliderRole },
+ { "slider", SliderRole },
+ { "spinbutton", ProgressIndicatorRole },
+ { "textbox", TextAreaRole }
+ };
+ ARIARoleMap& roleMap = *new ARIARoleMap;
+
+ const unsigned numRoles = sizeof(roles) / sizeof(roles[0]);
+ for (unsigned i = 0; i < numRoles; ++i)
+ roleMap.set(roles[i].ariaRole, roles[i].webcoreRole);
+ return roleMap;
+}
+
+static AccessibilityRole ariaRoleToWebCoreRole(String value)
+{
+ ASSERT(!value.isEmpty() && !value.isNull());
+ static const ARIARoleMap& roleMap = createARIARoleMap();
+ return roleMap.get(value);
+}
+
+AccessibilityRole AccessibilityRenderObject::determineAriaRoleAttribute() const
+{
+ String ariaRole = getAttribute(roleAttr).string();
+ if (ariaRole.isNull() || ariaRole.isEmpty())
+ return UnknownRole;
+
+ AccessibilityRole role = ariaRoleToWebCoreRole(ariaRole);
+ if (role)
+ return role;
+ // selects and listboxes both have options as child roles, but they map to different roles within WebCore
+ if (equalIgnoringCase(ariaRole,"option")) {
+ if (parentObjectUnignored()->ariaRoleAttribute() == MenuRole)
+ return MenuItemRole;
+ if (parentObjectUnignored()->ariaRoleAttribute() == ListBoxRole)
+ return ListBoxOptionRole;
+ }
+ // an aria "menuitem" may map to MenuButton or MenuItem depending on its parent
+ if (equalIgnoringCase(ariaRole,"menuitem")) {
+ if (parentObjectUnignored()->ariaRoleAttribute() == GroupRole)
+ return MenuButtonRole;
+ if (parentObjectUnignored()->ariaRoleAttribute() == MenuRole)
+ return MenuItemRole;
+ }
+
+ return UnknownRole;
+}
+
+void AccessibilityRenderObject::setAriaRole()
+{
+ m_ariaRole = determineAriaRoleAttribute();
+}
+
+AccessibilityRole AccessibilityRenderObject::ariaRoleAttribute() const
+{
+ return m_ariaRole;
+}
+
+AccessibilityRole AccessibilityRenderObject::roleValue() const
+{
+ if (!m_renderer)
+ return UnknownRole;
+
+ Node* node = m_renderer->node();
+ AccessibilityRole ariaRole = ariaRoleAttribute();
+ if (ariaRole != UnknownRole)
+ return ariaRole;
+
+ if (node && node->isLink()) {
+ if (m_renderer->isImage())
+ return ImageMapRole;
+ return WebCoreLinkRole;
+ }
+ if (m_renderer->isListMarker())
+ return ListMarkerRole;
+ if (node && node->hasTagName(buttonTag))
+ return ButtonRole;
+ if (m_renderer->isText())
+ return StaticTextRole;
+ if (m_renderer->isImage()) {
+ if (node && node->hasTagName(inputTag))
+ return ButtonRole;
+ return ImageRole;
+ }
+ if (node && node->hasTagName(canvasTag))
+ return ImageRole;
+
+ if (m_renderer->isRenderView())
+ return WebAreaRole;
+
+ if (m_renderer->isTextField())
+ return TextFieldRole;
+
+ if (m_renderer->isTextArea())
+ return TextAreaRole;
+
+ if (node && node->hasTagName(inputTag)) {
+ HTMLInputElement* input = static_cast<HTMLInputElement*>(node);
+ if (input->inputType() == HTMLInputElement::CHECKBOX)
+ return CheckBoxRole;
+ if (input->inputType() == HTMLInputElement::RADIO)
+ return RadioButtonRole;
+ if (input->isTextButton())
+ return ButtonRole;
+ }
+
+ if (node && node->hasTagName(buttonTag))
+ return ButtonRole;
+
+ if (isFileUploadButton())
+ return ButtonRole;
+
+ if (m_renderer->isMenuList())
+ return PopUpButtonRole;
+
+ if (headingLevel(m_renderer->node()) != 0)
+ return HeadingRole;
+
+ if (node && node->hasTagName(ddTag))
+ return DefinitionListDefinitionRole;
+
+ if (node && node->hasTagName(dtTag))
+ return DefinitionListTermRole;
+
+ if (m_renderer->isBlockFlow() || (node && node->hasTagName(labelTag)))
+ return GroupRole;
+
+ return UnknownRole;
+}
+
+bool AccessibilityRenderObject::isPresentationalChildOfAriaRole() const
+{
+ // Walk the parent chain looking for a parent that has presentational children
+ AccessibilityObject* parent;
+ for (parent = parentObject(); parent && !parent->ariaRoleHasPresentationalChildren(); parent = parent->parentObject())
+ ;
+ return parent;
+}
+
+bool AccessibilityRenderObject::ariaRoleHasPresentationalChildren() const
+{
+ switch (m_ariaRole) {
+ case ButtonRole:
+ case SliderRole:
+ case ImageRole:
+ case ProgressIndicatorRole:
+ //case SeparatorRole:
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool AccessibilityRenderObject::canSetFocusAttribute() const
+{
+ ASSERT(m_renderer);
+ Node* node = m_renderer->node();
+
+ // NOTE: It would be more accurate to ask the document whether setFocusedNode() would
+ // do anything. For example, it setFocusedNode() will do nothing if the current focused
+ // node will not relinquish the focus.
+ if (!node || !node->isElementNode())
+ return false;
+
+ if (!static_cast<Element*>(node)->isEnabledFormControl())
+ return false;
+
+ switch (roleValue()) {
+ case WebCoreLinkRole:
+ case ImageMapLinkRole:
+ case TextFieldRole:
+ case TextAreaRole:
+ case ButtonRole:
+ case PopUpButtonRole:
+ case CheckBoxRole:
+ case RadioButtonRole:
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool AccessibilityRenderObject::canSetValueAttribute() const
+{
+ if (isWebArea())
+ return !isReadOnly();
+
+ return isTextControl() || isProgressIndicator() || isSlider();
+}
+
+bool AccessibilityRenderObject::canSetTextRangeAttributes() const
+{
+ return isTextControl();
+}
+
+void AccessibilityRenderObject::childrenChanged()
+{
+ // this method is meant as a quick way of marking dirty
+ // a portion of the accessibility tree
+
+ markChildrenDirty();
+
+ if (!m_renderer)
+ return;
+
+ // Go up the render parent chain, marking children as dirty.
+ // We can't rely on the accessibilityParent() because it may not exist and we must not create an AX object here either
+ for (RenderObject* renderParent = m_renderer->parent(); renderParent; renderParent = renderParent->parent()) {
+ AccessibilityObject* parent = m_renderer->document()->axObjectCache()->get(renderParent);
+ if (parent && parent->isAccessibilityRenderObject())
+ static_cast<AccessibilityRenderObject *>(parent)->markChildrenDirty();
+ }
+}
+
+bool AccessibilityRenderObject::canHaveChildren() const
+{
+ if (!m_renderer)
+ return false;
+
+ // Elements that should not have children
+ switch (roleValue()) {
+ case ImageRole:
+ case ButtonRole:
+ case PopUpButtonRole:
+ case CheckBoxRole:
+ case RadioButtonRole:
+ return false;
+ default:
+ return true;
+ }
+}
+
+const AccessibilityObject::AccessibilityChildrenVector& AccessibilityRenderObject::children()
+{
+ if (m_childrenDirty) {
+ clearChildren();
+ m_childrenDirty = false;
+ }
+
+ if (!m_haveChildren)
+ addChildren();
+ return m_children;
+}
+
+void AccessibilityRenderObject::addChildren()
+{
+ // If the need to add more children in addition to existing children arises,
+ // childrenChanged should have been called, leaving the object with no children.
+ ASSERT(!m_haveChildren);
+
+ // nothing to add if there is no RenderObject
+ if (!m_renderer)
+ return;
+
+ m_haveChildren = true;
+
+ if (!canHaveChildren())
+ return;
+
+ // add all unignored acc children
+ for (RefPtr<AccessibilityObject> obj = firstChild(); obj; obj = obj->nextSibling()) {
+ if (obj->accessibilityIsIgnored()) {
+ if (!obj->hasChildren())
+ obj->addChildren();
+ AccessibilityChildrenVector children = obj->children();
+ unsigned length = children.size();
+ for (unsigned i = 0; i < length; ++i)
+ m_children.append(children[i]);
+ } else
+ m_children.append(obj);
+ }
+
+ // for a RenderImage, add the <area> elements as individual accessibility objects
+ if (m_renderer->isRenderImage()) {
+ HTMLMapElement* map = toRenderImage(m_renderer)->imageMap();
+ if (map) {
+ for (Node* current = map->firstChild(); current; current = current->traverseNextNode(map)) {
+
+ // add an <area> element for this child if it has a link
+ if (current->isLink()) {
+ AccessibilityImageMapLink* areaObject = static_cast<AccessibilityImageMapLink*>(m_renderer->document()->axObjectCache()->getOrCreate(ImageMapLinkRole));
+ areaObject->setHTMLAreaElement(static_cast<HTMLAreaElement*>(current));
+ areaObject->setHTMLMapElement(map);
+ areaObject->setParent(this);
+
+ m_children.append(areaObject);
+ }
+ }
+ }
+ }
+}
+
+void AccessibilityRenderObject::ariaListboxSelectedChildren(AccessibilityChildrenVector& result)
+{
+ AccessibilityObject* child = firstChild();
+ bool isMultiselectable = false;
+
+ Element* element = static_cast<Element*>(renderer()->node());
+ if (!element || !element->isElementNode()) // do this check to ensure safety of static_cast above
+ return;
+
+ String multiselectablePropertyStr = element->getAttribute("aria-multiselectable").string();
+ isMultiselectable = equalIgnoringCase(multiselectablePropertyStr, "true");
+
+ while (child) {
+ // every child should have aria-role option, and if so, check for selected attribute/state
+ AccessibilityRole ariaRole = child->ariaRoleAttribute();
+ RenderObject* childRenderer = 0;
+ if (child->isAccessibilityRenderObject())
+ childRenderer = static_cast<AccessibilityRenderObject*>(child)->renderer();
+ if (childRenderer && ariaRole == ListBoxOptionRole) {
+ Element* childElement = static_cast<Element*>(childRenderer->node());
+ if (childElement && childElement->isElementNode()) { // do this check to ensure safety of static_cast above
+ String selectedAttrString = childElement->getAttribute("aria-selected").string();
+ if (equalIgnoringCase(selectedAttrString, "true")) {
+ result.append(child);
+ if (isMultiselectable)
+ return;
+ }
+ }
+ }
+ child = child->nextSibling();
+ }
+}
+
+void AccessibilityRenderObject::selectedChildren(AccessibilityChildrenVector& result)
+{
+ ASSERT(result.isEmpty());
+
+ // only listboxes should be asked for their selected children.
+ if (ariaRoleAttribute() != ListBoxRole) { // native list boxes would be AccessibilityListBoxes, so only check for aria list boxes
+ ASSERT_NOT_REACHED();
+ return;
+ }
+ return ariaListboxSelectedChildren(result);
+}
+
+void AccessibilityRenderObject::ariaListboxVisibleChildren(AccessibilityChildrenVector& result)
+{
+ if (!hasChildren())
+ addChildren();
+
+ unsigned length = m_children.size();
+ for (unsigned i = 0; i < length; i++) {
+ if (!m_children[i]->isOffScreen())
+ result.append(m_children[i]);
+ }
+}
+
+void AccessibilityRenderObject::visibleChildren(AccessibilityChildrenVector& result)
+{
+ ASSERT(result.isEmpty());
+
+ // only listboxes are asked for their visible children.
+ if (ariaRoleAttribute() != ListBoxRole) { // native list boxes would be AccessibilityListBoxes, so only check for aria list boxes
+ ASSERT_NOT_REACHED();
+ return;
+ }
+ return ariaListboxVisibleChildren(result);
+}
+
+const String& AccessibilityRenderObject::actionVerb() const
+{
+ // FIXME: Need to add verbs for select elements.
+ DEFINE_STATIC_LOCAL(const String, buttonAction, (AXButtonActionVerb()));
+ DEFINE_STATIC_LOCAL(const String, textFieldAction, (AXTextFieldActionVerb()));
+ DEFINE_STATIC_LOCAL(const String, radioButtonAction, (AXRadioButtonActionVerb()));
+ DEFINE_STATIC_LOCAL(const String, checkedCheckBoxAction, (AXCheckedCheckBoxActionVerb()));
+ DEFINE_STATIC_LOCAL(const String, uncheckedCheckBoxAction, (AXUncheckedCheckBoxActionVerb()));
+ DEFINE_STATIC_LOCAL(const String, linkAction, (AXLinkActionVerb()));
+ DEFINE_STATIC_LOCAL(const String, noAction, ());
+
+ switch (roleValue()) {
+ case ButtonRole:
+ return buttonAction;
+ case TextFieldRole:
+ case TextAreaRole:
+ return textFieldAction;
+ case RadioButtonRole:
+ return radioButtonAction;
+ case CheckBoxRole:
+ return isChecked() ? checkedCheckBoxAction : uncheckedCheckBoxAction;
+ case LinkRole:
+ case WebCoreLinkRole:
+ return linkAction;
+ default:
+ return noAction;
+ }
+}
+
+void AccessibilityRenderObject::updateBackingStore()
+{
+ if (!m_renderer)
+ return;
+ m_renderer->view()->layoutIfNeeded();
+}
+
+} // namespace WebCore
diff --git a/WebCore/accessibility/AccessibilityRenderObject.h b/WebCore/accessibility/AccessibilityRenderObject.h
new file mode 100644
index 0000000..3fa88a2
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityRenderObject.h
@@ -0,0 +1,245 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef AccessibilityRenderObject_h
+#define AccessibilityRenderObject_h
+
+#include "AccessibilityObject.h"
+
+namespace WebCore {
+
+class AXObjectCache;
+class Element;
+class Frame;
+class FrameView;
+class HitTestResult;
+class HTMLAnchorElement;
+class HTMLAreaElement;
+class HTMLElement;
+class HTMLLabelElement;
+class HTMLMapElement;
+class HTMLSelectElement;
+class IntPoint;
+class IntSize;
+class Node;
+class RenderObject;
+class RenderListBox;
+class RenderTextControl;
+class RenderView;
+class VisibleSelection;
+class String;
+class Widget;
+
+class AccessibilityRenderObject : public AccessibilityObject {
+protected:
+ AccessibilityRenderObject(RenderObject*);
+public:
+ static PassRefPtr<AccessibilityRenderObject> create(RenderObject*);
+ virtual ~AccessibilityRenderObject();
+
+ bool isAccessibilityRenderObject() const { return true; };
+
+ virtual bool isAnchor() const;
+ virtual bool isAttachment() const;
+ virtual bool isHeading() const;
+ virtual bool isLink() const;
+ virtual bool isImageButton() const;
+ virtual bool isImage() const;
+ virtual bool isNativeImage() const;
+ virtual bool isPasswordField() const;
+ virtual bool isTextControl() const;
+ virtual bool isNativeTextControl() const;
+ virtual bool isWebArea() const;
+ virtual bool isCheckboxOrRadio() const;
+ virtual bool isFileUploadButton() const;
+ virtual bool isInputImage() const;
+ virtual bool isProgressIndicator() const;
+ virtual bool isSlider() const;
+ virtual bool isMenuRelated() const;
+ virtual bool isMenu() const;
+ virtual bool isMenuBar() const;
+ virtual bool isMenuButton() const;
+ virtual bool isMenuItem() const;
+ virtual bool isControl() const;
+ virtual bool isFieldset() const;
+ virtual bool isGroup() const;
+
+ virtual bool isEnabled() const;
+ virtual bool isSelected() const;
+ virtual bool isFocused() const;
+ virtual bool isChecked() const;
+ virtual bool isHovered() const;
+ virtual bool isIndeterminate() const;
+ virtual bool isLoaded() const;
+ virtual bool isMultiSelect() const;
+ virtual bool isOffScreen() const;
+ virtual bool isPressed() const;
+ virtual bool isReadOnly() const;
+ virtual bool isVisited() const;
+
+ const AtomicString& getAttribute(const QualifiedName&) const;
+ virtual bool canSetFocusAttribute() const;
+ virtual bool canSetTextRangeAttributes() const;
+ virtual bool canSetValueAttribute() const;
+
+ virtual bool hasIntValue() const;
+
+ virtual bool accessibilityIsIgnored() const;
+
+ static int headingLevel(Node*);
+ virtual int intValue() const;
+ virtual float valueForRange() const;
+ virtual float maxValueForRange() const;
+ virtual float minValueForRange() const;
+ virtual int layoutCount() const;
+
+ virtual AccessibilityObject* doAccessibilityHitTest(const IntPoint&) const;
+ virtual AccessibilityObject* focusedUIElement() const;
+ virtual AccessibilityObject* firstChild() const;
+ virtual AccessibilityObject* lastChild() const;
+ virtual AccessibilityObject* previousSibling() const;
+ virtual AccessibilityObject* nextSibling() const;
+ virtual AccessibilityObject* parentObject() const;
+ virtual AccessibilityObject* parentObjectIfExists() const;
+ virtual AccessibilityObject* observableObject() const;
+ virtual void linkedUIElements(AccessibilityChildrenVector&) const;
+ virtual bool exposesTitleUIElement() const;
+ virtual AccessibilityObject* titleUIElement() const;
+ virtual AccessibilityRole ariaRoleAttribute() const;
+ virtual bool isPresentationalChildOfAriaRole() const;
+ virtual bool ariaRoleHasPresentationalChildren() const;
+ void setAriaRole();
+ virtual AccessibilityRole roleValue() const;
+ virtual AXObjectCache* axObjectCache() const;
+
+ virtual Element* actionElement() const;
+ Element* mouseButtonListener() const;
+ FrameView* frameViewIfRenderView() const;
+ virtual Element* anchorElement() const;
+ AccessibilityObject* menuForMenuButton() const;
+ AccessibilityObject* menuButtonForMenu() const;
+
+ virtual IntRect boundingBoxRect() const;
+ virtual IntRect elementRect() const;
+ virtual IntSize size() const;
+
+ void setRenderer(RenderObject* renderer) { m_renderer = renderer; }
+ RenderObject* renderer() const { return m_renderer; }
+ RenderView* topRenderer() const;
+ RenderTextControl* textControl() const;
+ Document* document() const;
+ FrameView* topDocumentFrameView() const;
+ HTMLLabelElement* labelElementContainer() const;
+
+ virtual KURL url() const;
+ virtual PlainTextRange selectedTextRange() const;
+ virtual VisibleSelection selection() const;
+ virtual String stringValue() const;
+ virtual String ariaAccessiblityName(const String&) const;
+ virtual String ariaLabeledByAttribute() const;
+ virtual String title() const;
+ virtual String ariaDescribedByAttribute() const;
+ virtual String accessibilityDescription() const;
+ virtual String helpText() const;
+ virtual String textUnderElement() const;
+ virtual String text() const;
+ virtual int textLength() const;
+ virtual PassRefPtr<Range> ariaSelectedTextDOMRange() const;
+ virtual String selectedText() const;
+ virtual const AtomicString& accessKey() const;
+ virtual const String& actionVerb() const;
+ virtual Widget* widget() const;
+ virtual Widget* widgetForAttachmentView() const;
+ virtual void getDocumentLinks(AccessibilityChildrenVector&);
+ virtual FrameView* documentFrameView() const;
+
+ virtual const AccessibilityChildrenVector& children();
+
+ virtual void setFocused(bool);
+ virtual void setSelectedTextRange(const PlainTextRange&);
+ virtual void setValue(const String&);
+
+ virtual void detach();
+ virtual void childrenChanged();
+ virtual void addChildren();
+ virtual bool canHaveChildren() const;
+ virtual void selectedChildren(AccessibilityChildrenVector&);
+ virtual void visibleChildren(AccessibilityChildrenVector&);
+ virtual bool shouldFocusActiveDescendant() const;
+ virtual AccessibilityObject* activeDescendant() const;
+ virtual void handleActiveDescendantChanged();
+
+ virtual VisiblePositionRange visiblePositionRange() const;
+ virtual VisiblePositionRange visiblePositionRangeForLine(unsigned) const;
+ virtual IntRect boundsForVisiblePositionRange(const VisiblePositionRange&) const;
+ virtual void setSelectedVisiblePositionRange(const VisiblePositionRange&) const;
+
+ virtual VisiblePosition visiblePositionForPoint(const IntPoint&) const;
+ virtual VisiblePosition visiblePositionForIndex(unsigned indexValue, bool lastIndexOK) const;
+ virtual int index(const VisiblePosition&) const;
+
+ virtual VisiblePosition visiblePositionForIndex(int) const;
+ virtual int indexForVisiblePosition(const VisiblePosition&) const;
+
+ virtual PlainTextRange doAXRangeForLine(unsigned) const;
+ virtual PlainTextRange doAXRangeForIndex(unsigned) const;
+
+ virtual String doAXStringForRange(const PlainTextRange&) const;
+ virtual IntRect doAXBoundsForRange(const PlainTextRange&) const;
+
+ virtual void updateBackingStore();
+
+protected:
+ RenderObject* m_renderer;
+ AccessibilityRole m_ariaRole;
+ mutable bool m_childrenDirty;
+
+ void setRenderObject(RenderObject* renderer) { m_renderer = renderer; }
+
+ virtual bool isDetached() const { return !m_renderer; }
+
+private:
+ void ariaListboxSelectedChildren(AccessibilityChildrenVector&);
+ void ariaListboxVisibleChildren(AccessibilityChildrenVector&);
+
+ Element* menuElementForMenuButton() const;
+ Element* menuItemElementForMenu() const;
+ AccessibilityRole determineAriaRoleAttribute() const;
+
+ IntRect checkboxOrRadioRect() const;
+ void addRadioButtonGroupMembers(AccessibilityChildrenVector& linkedUIElements) const;
+ AccessibilityObject* internalLinkElement() const;
+ AccessibilityObject* accessibilityImageMapHitTest(HTMLAreaElement*, const IntPoint&) const;
+ AccessibilityObject* accessibilityParentForImageMap(HTMLMapElement* map) const;
+
+ void markChildrenDirty() const { m_childrenDirty = true; }
+};
+
+} // namespace WebCore
+
+#endif // AccessibilityRenderObject_h
diff --git a/WebCore/accessibility/AccessibilityTable.cpp b/WebCore/accessibility/AccessibilityTable.cpp
new file mode 100644
index 0000000..6d7dbe2
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityTable.cpp
@@ -0,0 +1,489 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "AccessibilityTable.h"
+
+#include "AccessibilityTableCell.h"
+#include "AccessibilityTableColumn.h"
+#include "AccessibilityTableHeaderContainer.h"
+#include "AccessibilityTableRow.h"
+#include "AXObjectCache.h"
+#include "HTMLNames.h"
+#include "HTMLTableElement.h"
+#include "HTMLTableCaptionElement.h"
+#include "HTMLTableCellElement.h"
+#include "RenderObject.h"
+#include "RenderTable.h"
+#include "RenderTableCell.h"
+#include "RenderTableSection.h"
+
+using namespace std;
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+AccessibilityTable::AccessibilityTable(RenderObject* renderer)
+ : AccessibilityRenderObject(renderer),
+ m_headerContainer(0)
+{
+#if ACCESSIBILITY_TABLES
+ m_isAccessibilityTable = isTableExposableThroughAccessibility();
+#else
+ m_isAccessibilityTable = false;
+#endif
+}
+
+AccessibilityTable::~AccessibilityTable()
+{
+}
+
+PassRefPtr<AccessibilityTable> AccessibilityTable::create(RenderObject* renderer)
+{
+ return adoptRef(new AccessibilityTable(renderer));
+}
+
+bool AccessibilityTable::isTableExposableThroughAccessibility()
+{
+ // the following is a heuristic used to determine if a
+ // <table> should be exposed as an AXTable. The goal
+ // is to only show "data" tables
+
+ if (!m_renderer || !m_renderer->isTable())
+ return false;
+
+ // if the developer assigned an aria role to this, then we shouldn't
+ // expose it as a table, unless, of course, the aria role is a table
+ AccessibilityRole ariaRole = ariaRoleAttribute();
+ if (ariaRole != UnknownRole)
+ return false;
+
+ RenderTable* table = static_cast<RenderTable*>(m_renderer);
+
+ // this employs a heuristic to determine if this table should appear.
+ // Only "data" tables should be exposed as tables.
+ // Unfortunately, there is no good way to determine the difference
+ // between a "layout" table and a "data" table
+
+ Node* tableNode = table->node();
+ if (!tableNode || !tableNode->hasTagName(tableTag))
+ return false;
+
+ // if there is a caption element, summary, THEAD, or TFOOT section, it's most certainly a data table
+ HTMLTableElement* tableElement = static_cast<HTMLTableElement*>(tableNode);
+ if (!tableElement->summary().isEmpty() || tableElement->tHead() || tableElement->tFoot() || tableElement->caption())
+ return true;
+
+ // if someone used "rules" attribute than the table should appear
+ if (!tableElement->rules().isEmpty())
+ return true;
+
+ // go through the cell's and check for tell-tale signs of "data" table status
+ // cells have borders, or use attributes like headers, abbr, scope or axis
+ RenderTableSection* firstBody = table->firstBody();
+ if (!firstBody)
+ return false;
+
+ int numCols = firstBody->numColumns();
+ int numRows = firstBody->numRows();
+
+ // if there's only one cell, it's not a good AXTable candidate
+ if (numRows == 1 && numCols == 1)
+ return false;
+
+ // store the background color of the table to check against cell's background colors
+ RenderStyle* tableStyle = table->style();
+ if (!tableStyle)
+ return false;
+ Color tableBGColor = tableStyle->backgroundColor();
+
+ // check enough of the cells to find if the table matches our criteria
+ // Criteria:
+ // 1) must have at least one valid cell (and)
+ // 2) at least half of cells have borders (or)
+ // 3) at least half of cells have different bg colors than the table, and there is cell spacing
+ unsigned validCellCount = 0;
+ unsigned borderedCellCount = 0;
+ unsigned backgroundDifferenceCellCount = 0;
+
+ for (int row = 0; row < numRows; ++row) {
+ for (int col = 0; col < numCols; ++col) {
+ RenderTableCell* cell = firstBody->cellAt(row, col).cell;
+ if (!cell)
+ continue;
+ Node* cellNode = cell->node();
+ if (!cellNode)
+ continue;
+
+ if (cell->width() < 1 || cell->height() < 1)
+ continue;
+
+ validCellCount++;
+
+ HTMLTableCellElement* cellElement = static_cast<HTMLTableCellElement*>(cellNode);
+
+ // in this case, the developer explicitly assigned a "data" table attribute
+ if (!cellElement->headers().isEmpty() || !cellElement->abbr().isEmpty() ||
+ !cellElement->axis().isEmpty() || !cellElement->scope().isEmpty())
+ return true;
+
+ RenderStyle* renderStyle = cell->style();
+ if (!renderStyle)
+ continue;
+
+ // a cell needs to have matching bordered sides, before it can be considered a bordered cell.
+ if ((cell->borderTop() > 0 && cell->borderBottom() > 0) ||
+ (cell->borderLeft() > 0 && cell->borderRight() > 0))
+ borderedCellCount++;
+
+ // if the cell has a different color from the table and there is cell spacing,
+ // then it is probably a data table cell (spacing and colors take the place of borders)
+ Color cellColor = renderStyle->backgroundColor();
+ if (table->hBorderSpacing() > 0 && table->vBorderSpacing() > 0 &&
+ tableBGColor != cellColor && cellColor.alpha() != 1)
+ backgroundDifferenceCellCount++;
+
+ // if we've found 10 "good" cells, we don't need to keep searching
+ if (borderedCellCount >= 10 || backgroundDifferenceCellCount >= 10)
+ return true;
+ }
+ }
+
+ // if there is less than two valid cells, it's not a data table
+ if (validCellCount <= 1)
+ return false;
+
+ // half of the cells had borders, it's a data table
+ unsigned neededCellCount = validCellCount / 2;
+ if (borderedCellCount >= neededCellCount)
+ return true;
+
+ // half had different background colors, it's a data table
+ if (backgroundDifferenceCellCount >= neededCellCount)
+ return true;
+
+ return false;
+}
+
+void AccessibilityTable::clearChildren()
+{
+ m_children.clear();
+ m_rows.clear();
+ m_columns.clear();
+ m_haveChildren = false;
+}
+
+void AccessibilityTable::addChildren()
+{
+ if (!isDataTable()) {
+ AccessibilityRenderObject::addChildren();
+ return;
+ }
+
+ ASSERT(!m_haveChildren);
+
+ m_haveChildren = true;
+ if (!m_renderer || !m_renderer->isTable())
+ return;
+
+ RenderTable* table = static_cast<RenderTable*>(m_renderer);
+ AXObjectCache* axCache = m_renderer->document()->axObjectCache();
+
+ // go through all the available sections to pull out the rows
+ // and add them as children
+ RenderTableSection* tableSection = table->header();
+ if (!tableSection)
+ tableSection = table->firstBody();
+
+ if (!tableSection)
+ return;
+
+ RenderTableSection* initialTableSection = tableSection;
+
+ while (tableSection) {
+
+ HashSet<AccessibilityObject*> appendedRows;
+
+ unsigned numRows = tableSection->numRows();
+ unsigned numCols = tableSection->numColumns();
+ for (unsigned rowIndex = 0; rowIndex < numRows; ++rowIndex) {
+ for (unsigned colIndex = 0; colIndex < numCols; ++colIndex) {
+
+ RenderTableCell* cell = tableSection->cellAt(rowIndex, colIndex).cell;
+ if (!cell)
+ continue;
+
+ AccessibilityObject* rowObject = axCache->getOrCreate(cell->parent());
+ if (!rowObject->isTableRow())
+ continue;
+
+ AccessibilityTableRow* row = static_cast<AccessibilityTableRow*>(rowObject);
+ // we need to check every cell for a new row, because cell spans
+ // can cause us to mess rows if we just check the first column
+ if (appendedRows.contains(row))
+ continue;
+
+ row->setRowIndex((int)m_rows.size());
+ m_rows.append(row);
+ m_children.append(row);
+ appendedRows.add(row);
+ }
+ }
+
+ tableSection = table->sectionBelow(tableSection, true);
+ }
+
+ // make the columns based on the number of columns in the first body
+ unsigned length = initialTableSection->numColumns();
+ for (unsigned i = 0; i < length; ++i) {
+ AccessibilityTableColumn* column = static_cast<AccessibilityTableColumn*>(axCache->getOrCreate(ColumnRole));
+ column->setColumnIndex((int)i);
+ column->setParentTable(this);
+ m_columns.append(column);
+ m_children.append(column);
+ }
+
+ AccessibilityObject* headerContainerObject = headerContainer();
+ if (headerContainerObject)
+ m_children.append(headerContainerObject);
+}
+
+AccessibilityObject* AccessibilityTable::headerContainer()
+{
+ if (m_headerContainer)
+ return m_headerContainer;
+
+ m_headerContainer = static_cast<AccessibilityTableHeaderContainer*>(axObjectCache()->getOrCreate(TableHeaderContainerRole));
+ m_headerContainer->setParentTable(this);
+
+ return m_headerContainer;
+}
+
+AccessibilityObject::AccessibilityChildrenVector& AccessibilityTable::columns()
+{
+ if (!hasChildren())
+ addChildren();
+
+ return m_columns;
+}
+
+AccessibilityObject::AccessibilityChildrenVector& AccessibilityTable::rows()
+{
+ if (!hasChildren())
+ addChildren();
+
+ return m_rows;
+}
+
+void AccessibilityTable::rowHeaders(AccessibilityChildrenVector& headers)
+{
+ if (!m_renderer)
+ return;
+
+ if (!hasChildren())
+ addChildren();
+
+ unsigned rowCount = m_rows.size();
+ for (unsigned k = 0; k < rowCount; ++k) {
+ AccessibilityObject* header = static_cast<AccessibilityTableRow*>(m_rows[k].get())->headerObject();
+ if (!header)
+ continue;
+ headers.append(header);
+ }
+}
+
+void AccessibilityTable::columnHeaders(AccessibilityChildrenVector& headers)
+{
+ if (!m_renderer)
+ return;
+
+ if (!hasChildren())
+ addChildren();
+
+ unsigned colCount = m_columns.size();
+ for (unsigned k = 0; k < colCount; ++k) {
+ AccessibilityObject* header = static_cast<AccessibilityTableColumn*>(m_columns[k].get())->headerObject();
+ if (!header)
+ continue;
+ headers.append(header);
+ }
+}
+
+void AccessibilityTable::cells(AccessibilityObject::AccessibilityChildrenVector& cells)
+{
+ if (!m_renderer)
+ return;
+
+ if (!hasChildren())
+ addChildren();
+
+ int numRows = m_rows.size();
+ for (int row = 0; row < numRows; ++row) {
+ AccessibilityChildrenVector rowChildren = m_rows[row]->children();
+ cells.append(rowChildren);
+ }
+}
+
+unsigned AccessibilityTable::columnCount()
+{
+ if (!hasChildren())
+ addChildren();
+
+ return m_columns.size();
+}
+
+unsigned AccessibilityTable::rowCount()
+{
+ if (!hasChildren())
+ addChildren();
+
+ return m_rows.size();
+}
+
+AccessibilityTableCell* AccessibilityTable::cellForColumnAndRow(unsigned column, unsigned row)
+{
+ if (!m_renderer || !m_renderer->isTable())
+ return 0;
+
+ if (!hasChildren())
+ addChildren();
+
+ RenderTable* table = static_cast<RenderTable*>(m_renderer);
+ RenderTableSection* tableSection = table->header();
+ if (!tableSection)
+ tableSection = table->firstBody();
+
+ RenderTableCell* cell = 0;
+ unsigned rowCount = 0;
+ unsigned rowOffset = 0;
+ while (tableSection) {
+
+ unsigned numRows = tableSection->numRows();
+ unsigned numCols = tableSection->numColumns();
+
+ rowCount += numRows;
+
+ unsigned sectionSpecificRow = row - rowOffset;
+ if (row < rowCount && column < numCols && sectionSpecificRow < numRows) {
+ cell = tableSection->cellAt(sectionSpecificRow, column).cell;
+
+ // we didn't find the cell, which means there's spanning happening
+ // search backwards to find the spanning cell
+ if (!cell) {
+
+ // first try rows
+ for (int testRow = sectionSpecificRow-1; testRow >= 0; --testRow) {
+ cell = tableSection->cellAt(testRow, column).cell;
+ // cell overlapped. use this one
+ if (cell && ((cell->row() + (cell->rowSpan()-1)) >= (int)sectionSpecificRow))
+ break;
+ cell = 0;
+ }
+
+ if (!cell) {
+ // try cols
+ for (int testCol = column-1; testCol >= 0; --testCol) {
+ cell = tableSection->cellAt(sectionSpecificRow, testCol).cell;
+ // cell overlapped. use this one
+ if (cell && ((cell->col() + (cell->colSpan()-1)) >= (int)column))
+ break;
+ cell = 0;
+ }
+ }
+ }
+ }
+
+ if (cell)
+ break;
+
+ rowOffset += numRows;
+ // we didn't find anything between the rows we should have
+ if (row < rowCount)
+ break;
+ tableSection = table->sectionBelow(tableSection, true);
+ }
+
+ if (!cell)
+ return 0;
+
+ AccessibilityObject* cellObject = axObjectCache()->getOrCreate(cell);
+ ASSERT(cellObject->isTableCell());
+
+ return static_cast<AccessibilityTableCell*>(cellObject);
+}
+
+AccessibilityRole AccessibilityTable::roleValue() const
+{
+ if (!isDataTable())
+ return AccessibilityRenderObject::roleValue();
+
+ return TableRole;
+}
+
+bool AccessibilityTable::accessibilityIsIgnored() const
+{
+ if (!isDataTable())
+ return AccessibilityRenderObject::accessibilityIsIgnored();
+
+ return false;
+}
+
+String AccessibilityTable::title() const
+{
+ if (!isDataTable())
+ return AccessibilityRenderObject::title();
+
+ String title;
+ if (!m_renderer)
+ return title;
+
+ // see if there is a caption
+ Node* tableElement = m_renderer->node();
+ if (tableElement && tableElement->hasTagName(tableTag)) {
+ HTMLTableCaptionElement* caption = static_cast<HTMLTableElement*>(tableElement)->caption();
+ if (caption)
+ title = caption->innerText();
+ }
+
+ // try the standard
+ if (title.isEmpty())
+ title = AccessibilityRenderObject::title();
+
+ return title;
+}
+
+bool AccessibilityTable::isDataTable() const
+{
+ if (!m_renderer)
+ return false;
+
+ return m_isAccessibilityTable;
+}
+
+} // namespace WebCore
diff --git a/WebCore/accessibility/AccessibilityTable.h b/WebCore/accessibility/AccessibilityTable.h
new file mode 100644
index 0000000..b6aa3ca
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityTable.h
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef AccessibilityTable_h
+#define AccessibilityTable_h
+
+#include "AccessibilityRenderObject.h"
+
+#if PLATFORM(MAC) && (defined(BUILDING_ON_TIGER) || defined(BUILDING_ON_LEOPARD))
+#define ACCESSIBILITY_TABLES 0
+#else
+#define ACCESSIBILITY_TABLES 1
+#endif
+
+namespace WebCore {
+
+class String;
+class AccessibilityTableCell;
+class AccessibilityTableHeaderContainer;
+
+class AccessibilityTable : public AccessibilityRenderObject {
+
+protected:
+ AccessibilityTable(RenderObject*);
+public:
+ static PassRefPtr<AccessibilityTable> create(RenderObject*);
+ virtual ~AccessibilityTable();
+
+ virtual bool isDataTable() const;
+ virtual AccessibilityRole roleValue() const;
+ virtual bool isAriaTable() const { return false; }
+
+ virtual bool accessibilityIsIgnored() const;
+
+ virtual void addChildren();
+ virtual void clearChildren();
+
+ AccessibilityChildrenVector& columns();
+ AccessibilityChildrenVector& rows();
+
+ unsigned columnCount();
+ unsigned rowCount();
+
+ virtual String title() const;
+
+ // all the cells in the table
+ void cells(AccessibilityChildrenVector&);
+ virtual AccessibilityTableCell* cellForColumnAndRow(unsigned column, unsigned row);
+
+ void columnHeaders(AccessibilityChildrenVector&);
+ void rowHeaders(AccessibilityChildrenVector&);
+
+ // an object that contains, as children, all the objects that act as headers
+ AccessibilityObject* headerContainer();
+
+protected:
+ AccessibilityChildrenVector m_rows;
+ AccessibilityChildrenVector m_columns;
+
+ AccessibilityTableHeaderContainer* m_headerContainer;
+ mutable bool m_isAccessibilityTable;
+
+ bool isTableExposableThroughAccessibility();
+};
+
+} // namespace WebCore
+
+#endif // AccessibilityTable_h
diff --git a/WebCore/accessibility/AccessibilityTableCell.cpp b/WebCore/accessibility/AccessibilityTableCell.cpp
new file mode 100644
index 0000000..4d7cf5a
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityTableCell.cpp
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "AccessibilityTableCell.h"
+
+#include "AXObjectCache.h"
+#include "HTMLNames.h"
+#include "RenderObject.h"
+#include "RenderTableCell.h"
+
+using namespace std;
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+AccessibilityTableCell::AccessibilityTableCell(RenderObject* renderer)
+ : AccessibilityRenderObject(renderer)
+{
+}
+
+AccessibilityTableCell::~AccessibilityTableCell()
+{
+}
+
+PassRefPtr<AccessibilityTableCell> AccessibilityTableCell::create(RenderObject* renderer)
+{
+ return adoptRef(new AccessibilityTableCell(renderer));
+}
+
+bool AccessibilityTableCell::accessibilityIsIgnored() const
+{
+ if (!isTableCell())
+ return AccessibilityRenderObject::accessibilityIsIgnored();
+
+ return false;
+}
+
+AccessibilityObject* AccessibilityTableCell::parentTable() const
+{
+ if (!m_renderer || !m_renderer->isTableCell())
+ return false;
+
+ return axObjectCache()->getOrCreate(static_cast<RenderTableCell*>(m_renderer)->table());
+}
+
+bool AccessibilityTableCell::isTableCell() const
+{
+ AccessibilityObject* table = parentTable();
+ if (!table || !table->isDataTable())
+ return false;
+
+ return true;
+}
+
+AccessibilityRole AccessibilityTableCell::roleValue() const
+{
+ if (!isTableCell())
+ return AccessibilityRenderObject::roleValue();
+
+ return CellRole;
+}
+
+void AccessibilityTableCell::rowIndexRange(pair<int, int>& rowRange)
+{
+ if (!m_renderer || !m_renderer->isTableCell())
+ return;
+
+ RenderTableCell* renderCell = static_cast<RenderTableCell*>(m_renderer);
+ rowRange.first = renderCell->row();
+ rowRange.second = renderCell->rowSpan();
+
+ // since our table might have multiple sections, we have to offset our row appropriately
+ RenderTableSection* section = renderCell->section();
+ RenderTable* table = renderCell->table();
+ if (!table || !section)
+ return;
+
+ RenderTableSection* tableSection = table->header();
+ if (!tableSection)
+ tableSection = table->firstBody();
+
+ unsigned rowOffset = 0;
+ while (tableSection) {
+ if (tableSection == section)
+ break;
+ rowOffset += tableSection->numRows();
+ tableSection = table->sectionBelow(tableSection, true);
+ }
+
+ rowRange.first += rowOffset;
+}
+
+void AccessibilityTableCell::columnIndexRange(pair<int, int>& columnRange)
+{
+ if (!m_renderer || !m_renderer->isTableCell())
+ return;
+
+ RenderTableCell* renderCell = static_cast<RenderTableCell*>(m_renderer);
+ columnRange.first = renderCell->col();
+ columnRange.second = renderCell->colSpan();
+}
+
+AccessibilityObject* AccessibilityTableCell::titleUIElement() const
+{
+ // Try to find if the first cell in this row is a <th>. If it is,
+ // then it can act as the title ui element. (This is only in the
+ // case when the table is not appearing as an AXTable.)
+ if (isTableCell() || !m_renderer || !m_renderer->isTableCell())
+ return 0;
+
+ RenderTableCell* renderCell = static_cast<RenderTableCell*>(m_renderer);
+
+ // If this cell is in the first column, there is no need to continue.
+ int col = renderCell->col();
+ if (!col)
+ return 0;
+
+ int row = renderCell->row();
+
+ RenderTableSection* section = renderCell->section();
+ if (!section)
+ return 0;
+
+ RenderTableCell* headerCell = section->cellAt(row, 0).cell;
+ if (!headerCell || headerCell == renderCell)
+ return 0;
+
+ Node* cellElement = headerCell->node();
+ if (!cellElement || !cellElement->hasTagName(thTag))
+ return 0;
+
+ return axObjectCache()->getOrCreate(headerCell);
+}
+
+} // namespace WebCore
diff --git a/WebCore/accessibility/AccessibilityTableCell.h b/WebCore/accessibility/AccessibilityTableCell.h
new file mode 100644
index 0000000..dabbce2
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityTableCell.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef AccessibilityTableCell_h
+#define AccessibilityTableCell_h
+
+#include "AccessibilityRenderObject.h"
+
+namespace WebCore {
+
+class AccessibilityTableCell : public AccessibilityRenderObject {
+
+protected:
+ AccessibilityTableCell(RenderObject*);
+public:
+ static PassRefPtr<AccessibilityTableCell> create(RenderObject*);
+ virtual ~AccessibilityTableCell();
+
+ virtual bool isTableCell() const;
+ virtual AccessibilityRole roleValue() const;
+
+ virtual bool accessibilityIsIgnored() const;
+
+ // fills in the start location and row span of cell
+ virtual void rowIndexRange(pair<int, int>& rowRange);
+ // fills in the start location and column span of cell
+ virtual void columnIndexRange(pair<int, int>& columnRange);
+
+ // if a table cell is not exposed as a table cell, a TH element can
+ // serve as its title ui element
+ AccessibilityObject* titleUIElement() const;
+
+protected:
+ virtual AccessibilityObject* parentTable() const;
+ int m_rowIndex;
+};
+
+} // namespace WebCore
+
+#endif // AccessibilityTableCell_h
diff --git a/WebCore/accessibility/AccessibilityTableColumn.cpp b/WebCore/accessibility/AccessibilityTableColumn.cpp
new file mode 100644
index 0000000..ee79444
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityTableColumn.cpp
@@ -0,0 +1,185 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "AccessibilityTableColumn.h"
+
+#include "AccessibilityTableCell.h"
+#include "AXObjectCache.h"
+#include "HTMLNames.h"
+#include "RenderTable.h"
+#include "RenderTableSection.h"
+#include "RenderTableCell.h"
+
+using namespace std;
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+AccessibilityTableColumn::AccessibilityTableColumn()
+ : m_parentTable(0)
+{
+}
+
+AccessibilityTableColumn::~AccessibilityTableColumn()
+{
+}
+
+PassRefPtr<AccessibilityTableColumn> AccessibilityTableColumn::create()
+{
+ return adoptRef(new AccessibilityTableColumn());
+}
+
+void AccessibilityTableColumn::setParentTable(AccessibilityTable* table)
+{
+ m_parentTable = table;
+
+ clearChildren();
+}
+
+IntRect AccessibilityTableColumn::elementRect() const
+{
+ // this will be filled in when addChildren is called
+ return m_columnRect;
+}
+
+IntSize AccessibilityTableColumn::size() const
+{
+ return elementRect().size();
+}
+
+const AccessibilityObject::AccessibilityChildrenVector& AccessibilityTableColumn::children()
+{
+ if (!m_haveChildren)
+ addChildren();
+ return m_children;
+}
+
+AccessibilityObject* AccessibilityTableColumn::headerObject()
+{
+ if (!m_parentTable)
+ return 0;
+
+ RenderObject* renderer = m_parentTable->renderer();
+ if (!renderer)
+ return 0;
+
+ if (m_parentTable->isAriaTable()) {
+ AccessibilityChildrenVector rowChildren = children();
+ unsigned childrenCount = rowChildren.size();
+ for (unsigned i = 0; i < childrenCount; ++i) {
+ AccessibilityObject* cell = rowChildren[i].get();
+ if (cell->ariaRoleAttribute() == ColumnHeaderRole)
+ return cell;
+ }
+
+ return 0;
+ }
+
+ if (!renderer->isTable())
+ return 0;
+
+ RenderTable* table = static_cast<RenderTable*>(renderer);
+
+ AccessibilityObject* headerObject = 0;
+
+ // try the <thead> section first. this doesn't require th tags
+ headerObject = headerObjectForSection(table->header(), false);
+
+ if (headerObject)
+ return headerObject;
+
+ // now try for <th> tags in the first body
+ headerObject = headerObjectForSection(table->firstBody(), true);
+
+ return headerObject;
+}
+
+AccessibilityObject* AccessibilityTableColumn::headerObjectForSection(RenderTableSection* section, bool thTagRequired)
+{
+ if (!section)
+ return 0;
+
+ int numCols = section->numColumns();
+ if (m_columnIndex >= numCols)
+ return 0;
+
+ RenderTableCell* cell = 0;
+ // also account for cells that have a span
+ for (int testCol = m_columnIndex; testCol >= 0; --testCol) {
+ RenderTableCell* testCell = section->cellAt(0, testCol).cell;
+ if (!testCell)
+ continue;
+
+ // we've reached a cell that doesn't even overlap our column
+ // it can't be our header
+ if ((testCell->col() + (testCell->colSpan()-1)) < m_columnIndex)
+ break;
+
+ Node* node = testCell->node();
+ if (!node)
+ continue;
+
+ if (thTagRequired && !node->hasTagName(thTag))
+ continue;
+
+ cell = testCell;
+ }
+
+ if (!cell)
+ return 0;
+
+ return m_parentTable->axObjectCache()->getOrCreate(cell);
+}
+
+void AccessibilityTableColumn::addChildren()
+{
+ ASSERT(!m_haveChildren);
+
+ m_haveChildren = true;
+ if (!m_parentTable)
+ return;
+
+ int numRows = m_parentTable->rowCount();
+
+ for (int i = 0; i < numRows; i++) {
+ AccessibilityTableCell* cell = m_parentTable->cellForColumnAndRow(m_columnIndex, i);
+ if (!cell)
+ continue;
+
+ // make sure the last one isn't the same as this one (rowspan cells)
+ if (m_children.size() > 0 && m_children.last() == cell)
+ continue;
+
+ m_children.append(cell);
+ m_columnRect.unite(cell->elementRect());
+ }
+}
+
+} // namespace WebCore
diff --git a/WebCore/accessibility/AccessibilityTableColumn.h b/WebCore/accessibility/AccessibilityTableColumn.h
new file mode 100644
index 0000000..6270398
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityTableColumn.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef AccessibilityTableColumn_h
+#define AccessibilityTableColumn_h
+
+#include "AccessibilityObject.h"
+#include "AccessibilityTable.h"
+#include "IntRect.h"
+
+namespace WebCore {
+
+class RenderTableSection;
+
+class AccessibilityTableColumn : public AccessibilityObject {
+
+private:
+ AccessibilityTableColumn();
+public:
+ static PassRefPtr<AccessibilityTableColumn> create();
+ virtual ~AccessibilityTableColumn();
+
+ void setParentTable(AccessibilityTable*);
+ virtual AccessibilityObject* parentObject() const { return m_parentTable; }
+ AccessibilityObject* headerObject();
+
+ virtual AccessibilityRole roleValue() const { return ColumnRole; }
+ virtual bool accessibilityIsIgnored() const { return false; }
+ virtual bool isTableColumn() const { return true; }
+
+ void setColumnIndex(int columnIndex) { m_columnIndex = columnIndex; }
+ int columnIndex() const { return m_columnIndex; }
+
+ virtual const AccessibilityChildrenVector& children();
+ virtual void addChildren();
+
+ virtual IntSize size() const;
+ virtual IntRect elementRect() const;
+
+private:
+ AccessibilityTable* m_parentTable;
+ int m_columnIndex;
+ IntRect m_columnRect;
+
+ AccessibilityObject* headerObjectForSection(RenderTableSection*, bool thTagRequired);
+};
+
+} // namespace WebCore
+
+#endif // AccessibilityTableColumn_h
diff --git a/WebCore/accessibility/AccessibilityTableHeaderContainer.cpp b/WebCore/accessibility/AccessibilityTableHeaderContainer.cpp
new file mode 100644
index 0000000..af9de39
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityTableHeaderContainer.cpp
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "AccessibilityTableHeaderContainer.h"
+
+#include "AccessibilityTable.h"
+#include "AXObjectCache.h"
+
+using namespace std;
+
+namespace WebCore {
+
+AccessibilityTableHeaderContainer::AccessibilityTableHeaderContainer()
+ : m_parentTable(0)
+{
+}
+
+AccessibilityTableHeaderContainer::~AccessibilityTableHeaderContainer()
+{
+}
+
+PassRefPtr<AccessibilityTableHeaderContainer> AccessibilityTableHeaderContainer::create()
+{
+ return adoptRef(new AccessibilityTableHeaderContainer());
+}
+
+const AccessibilityObject::AccessibilityChildrenVector& AccessibilityTableHeaderContainer::children()
+{
+ if (!m_haveChildren)
+ addChildren();
+ return m_children;
+}
+
+IntRect AccessibilityTableHeaderContainer::elementRect() const
+{
+ // this will be filled in when addChildren is called
+ return m_headerRect;
+}
+
+IntSize AccessibilityTableHeaderContainer::size() const
+{
+ return elementRect().size();
+}
+
+void AccessibilityTableHeaderContainer::addChildren()
+{
+ ASSERT(!m_haveChildren);
+
+ m_haveChildren = true;
+ if (!m_parentTable || !m_parentTable->isDataTable())
+ return;
+
+ static_cast<AccessibilityTable*>(m_parentTable)->columnHeaders(m_children);
+
+ unsigned length = m_children.size();
+ for (unsigned k = 0; k < length; ++k) {
+ m_headerRect.unite(m_children[k]->elementRect());
+ }
+}
+
+} // namespace WebCore
diff --git a/WebCore/accessibility/AccessibilityTableHeaderContainer.h b/WebCore/accessibility/AccessibilityTableHeaderContainer.h
new file mode 100644
index 0000000..8a9448a
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityTableHeaderContainer.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef AccessibilityTableHeaderContainer_h
+#define AccessibilityTableHeaderContainer_h
+
+#include "AccessibilityObject.h"
+#include "AccessibilityTable.h"
+#include "IntRect.h"
+
+namespace WebCore {
+
+class AccessibilityTableHeaderContainer : public AccessibilityObject {
+
+private:
+ AccessibilityTableHeaderContainer();
+public:
+ static PassRefPtr<AccessibilityTableHeaderContainer> create();
+ virtual ~AccessibilityTableHeaderContainer();
+
+ virtual AccessibilityRole roleValue() const { return TableHeaderContainerRole; }
+
+ void setParentTable(AccessibilityTable* table) { m_parentTable = table; }
+ virtual AccessibilityObject* parentObject() const { return m_parentTable; }
+
+ virtual bool accessibilityIsIgnored() const { return false; }
+
+ virtual const AccessibilityChildrenVector& children();
+ virtual void addChildren();
+
+ virtual IntSize size() const;
+ virtual IntRect elementRect() const;
+
+private:
+ AccessibilityTable* m_parentTable;
+ IntRect m_headerRect;
+
+};
+
+} // namespace WebCore
+
+#endif // AccessibilityTableHeaderContainer_h
diff --git a/WebCore/accessibility/AccessibilityTableRow.cpp b/WebCore/accessibility/AccessibilityTableRow.cpp
new file mode 100644
index 0000000..9f5f972
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityTableRow.cpp
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "AccessibilityTableRow.h"
+
+#include "AccessibilityTableCell.h"
+#include "AXObjectCache.h"
+#include "HTMLNames.h"
+#include "HTMLTableRowElement.h"
+#include "RenderObject.h"
+#include "RenderTableCell.h"
+#include "RenderTableRow.h"
+
+using namespace std;
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+AccessibilityTableRow::AccessibilityTableRow(RenderObject* renderer)
+ : AccessibilityRenderObject(renderer)
+{
+}
+
+AccessibilityTableRow::~AccessibilityTableRow()
+{
+}
+
+PassRefPtr<AccessibilityTableRow> AccessibilityTableRow::create(RenderObject* renderer)
+{
+ return adoptRef(new AccessibilityTableRow(renderer));
+}
+
+AccessibilityRole AccessibilityTableRow::roleValue() const
+{
+ if (!isTableRow())
+ return AccessibilityRenderObject::roleValue();
+
+ return RowRole;
+}
+
+bool AccessibilityTableRow::isTableRow() const
+{
+ AccessibilityObject* table = parentTable();
+ if (!table || !table->isDataTable())
+ return false;
+
+ return true;
+}
+
+bool AccessibilityTableRow::accessibilityIsIgnored() const
+{
+ if (!isTableRow())
+ return AccessibilityRenderObject::accessibilityIsIgnored();
+
+ return false;
+}
+
+AccessibilityObject* AccessibilityTableRow::parentTable() const
+{
+ if (!m_renderer || !m_renderer->isTableRow())
+ return 0;
+
+ return axObjectCache()->getOrCreate(static_cast<RenderTableRow*>(m_renderer)->table());
+}
+
+AccessibilityObject* AccessibilityTableRow::headerObject()
+{
+ if (!m_renderer || !m_renderer->isTableRow())
+ return 0;
+
+ AccessibilityChildrenVector rowChildren = children();
+ if (!rowChildren.size())
+ return 0;
+
+ // check the first element in the row to see if it is a TH element
+ AccessibilityObject* cell = rowChildren[0].get();
+ if (!cell->isTableCell())
+ return 0;
+
+ RenderObject* cellRenderer = static_cast<AccessibilityTableCell*>(cell)->renderer();
+ if (!cellRenderer)
+ return 0;
+
+ Node* cellNode = cellRenderer->node();
+ if (!cellNode || !cellNode->hasTagName(thTag))
+ return 0;
+
+ return cell;
+}
+
+} // namespace WebCore
diff --git a/WebCore/accessibility/AccessibilityTableRow.h b/WebCore/accessibility/AccessibilityTableRow.h
new file mode 100644
index 0000000..29ac935
--- /dev/null
+++ b/WebCore/accessibility/AccessibilityTableRow.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef AccessibilityTableRow_h
+#define AccessibilityTableRow_h
+
+#include "AccessibilityRenderObject.h"
+
+namespace WebCore {
+
+class AccessibilityTableRow : public AccessibilityRenderObject {
+
+protected:
+ AccessibilityTableRow(RenderObject*);
+public:
+ static PassRefPtr<AccessibilityTableRow> create(RenderObject*);
+ virtual ~AccessibilityTableRow();
+
+ virtual bool isTableRow() const;
+ virtual AccessibilityRole roleValue() const;
+ virtual bool accessibilityIsIgnored() const;
+
+ // retrieves the "row" header (a th tag in the rightmost column)
+ virtual AccessibilityObject* headerObject();
+ virtual AccessibilityObject* parentTable() const;
+
+ void setRowIndex(int rowIndex) { m_rowIndex = rowIndex; }
+ int rowIndex() const { return m_rowIndex; }
+
+ // allows the table to add other children that may not originate
+ // in the row, but their col/row spans overlap into it
+ void appendChild(AccessibilityObject*);
+
+private:
+ int m_rowIndex;
+};
+
+} // namespace WebCore
+
+#endif // AccessibilityTableRow_h
diff --git a/WebCore/accessibility/chromium/AXObjectCacheChromium.cpp b/WebCore/accessibility/chromium/AXObjectCacheChromium.cpp
new file mode 100644
index 0000000..d0f1882
--- /dev/null
+++ b/WebCore/accessibility/chromium/AXObjectCacheChromium.cpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2008 Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "AXObjectCache.h"
+
+#include "AccessibilityObject.h"
+
+namespace WebCore {
+
+void AXObjectCache::detachWrapper(AccessibilityObject* obj)
+{
+ // In Chromium, AccessibilityObjects are wrapped lazily.
+ if (AccessibilityObjectWrapper* wrapper = obj->wrapper())
+ wrapper->detach();
+}
+
+void AXObjectCache::attachWrapper(AccessibilityObject*)
+{
+ // In Chromium, AccessibilityObjects are wrapped lazily.
+}
+
+void AXObjectCache::postPlatformNotification(AccessibilityObject*, const String&)
+{
+}
+
+void AXObjectCache::handleFocusedUIElementChanged()
+{
+}
+
+} // namespace WebCore
diff --git a/WebCore/accessibility/chromium/AccessibilityObjectChromium.cpp b/WebCore/accessibility/chromium/AccessibilityObjectChromium.cpp
new file mode 100644
index 0000000..650fb3a
--- /dev/null
+++ b/WebCore/accessibility/chromium/AccessibilityObjectChromium.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2008 Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "AccessibilityObject.h"
+
+namespace WebCore {
+
+bool AccessibilityObject::accessibilityIgnoreAttachment() const
+{
+ return false;
+}
+
+} // namespace WebCore
diff --git a/WebCore/accessibility/chromium/AccessibilityObjectWrapper.h b/WebCore/accessibility/chromium/AccessibilityObjectWrapper.h
new file mode 100644
index 0000000..d7238e1
--- /dev/null
+++ b/WebCore/accessibility/chromium/AccessibilityObjectWrapper.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2008 Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef AccessibilityObjectWrapper_h
+#define AccessibilityObjectWrapper_h
+
+namespace WebCore {
+
+ class AccessibilityObject;
+ class AccessibilityObjectWrapper : public RefCounted<AccessibilityObjectWrapper> {
+ public:
+ virtual ~AccessibilityObjectWrapper() {}
+ virtual void detach() = 0;
+ bool attached() const { return m_object; }
+ AccessibilityObject* accessibilityObject() const { return m_object; }
+
+ protected:
+ AccessibilityObjectWrapper(AccessibilityObject* obj)
+ : m_object(obj)
+ {
+ // FIXME: Remove this once our immediate subclass no longer uses COM.
+ *addressOfCount() = 0;
+ }
+ AccessibilityObjectWrapper() : m_object(0) { }
+
+ AccessibilityObject* m_object;
+ };
+
+} // namespace WebCore
+
+#endif
diff --git a/WebCore/accessibility/gtk/AXObjectCacheAtk.cpp b/WebCore/accessibility/gtk/AXObjectCacheAtk.cpp
new file mode 100644
index 0000000..25665b1
--- /dev/null
+++ b/WebCore/accessibility/gtk/AXObjectCacheAtk.cpp
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2008 Nuanti Ltd.
+ *
+ * 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 "AXObjectCache.h"
+
+#include "AccessibilityObject.h"
+#include "AccessibilityObjectWrapperAtk.h"
+
+namespace WebCore {
+
+void AXObjectCache::detachWrapper(AccessibilityObject* obj)
+{
+ webkit_accessible_detach(WEBKIT_ACCESSIBLE(obj->wrapper()));
+}
+
+void AXObjectCache::attachWrapper(AccessibilityObject* obj)
+{
+ AtkObject* atkObj = ATK_OBJECT(webkit_accessible_new(obj));
+ obj->setWrapper(atkObj);
+ g_object_unref(atkObj);
+}
+
+void AXObjectCache::postPlatformNotification(AccessibilityObject*, const String&)
+{
+}
+
+void AXObjectCache::handleFocusedUIElementChanged()
+{
+}
+
+void AXObjectCache::handleFocusedUIElementChangedWithRenderers(RenderObject* oldFocusedRender, RenderObject* newFocusedRender)
+{
+ RefPtr<AccessibilityObject> oldObject = getOrCreate(oldFocusedRender);
+ if (oldObject) {
+ g_signal_emit_by_name(oldObject->wrapper(), "focus-event", false);
+ g_signal_emit_by_name(oldObject->wrapper(), "state-change", "focused", false);
+ }
+ RefPtr<AccessibilityObject> newObject = getOrCreate(newFocusedRender);
+ if (newObject) {
+ g_signal_emit_by_name(newObject->wrapper(), "focus-event", true);
+ g_signal_emit_by_name(newObject->wrapper(), "state-change", "focused", true);
+ }
+}
+
+} // namespace WebCore
diff --git a/WebCore/accessibility/gtk/AccessibilityObjectAtk.cpp b/WebCore/accessibility/gtk/AccessibilityObjectAtk.cpp
new file mode 100644
index 0000000..854816f
--- /dev/null
+++ b/WebCore/accessibility/gtk/AccessibilityObjectAtk.cpp
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2008 Apple Ltd.
+ * Copyright (C) 2008 Alp Toker <alp@atoker.com>
+ *
+ * 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 "AccessibilityObject.h"
+
+#include <glib-object.h>
+
+#if HAVE(ACCESSIBILITY)
+
+namespace WebCore {
+
+bool AccessibilityObject::accessibilityIgnoreAttachment() const
+{
+ return false;
+}
+
+AccessibilityObjectWrapper* AccessibilityObject::wrapper() const
+{
+ return m_wrapper;
+}
+
+void AccessibilityObject::setWrapper(AccessibilityObjectWrapper* wrapper)
+{
+ if (wrapper == m_wrapper)
+ return;
+
+ if (m_wrapper)
+ g_object_unref(m_wrapper);
+
+ m_wrapper = wrapper;
+
+ if (m_wrapper)
+ g_object_ref(m_wrapper);
+}
+
+} // namespace WebCore
+
+#endif // HAVE(ACCESSIBILITY)
diff --git a/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp b/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp
new file mode 100644
index 0000000..141d561
--- /dev/null
+++ b/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp
@@ -0,0 +1,1189 @@
+/*
+ * Copyright (C) 2008 Nuanti Ltd.
+ * Copyright (C) 2009 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 "AccessibilityObjectWrapperAtk.h"
+
+#if HAVE(ACCESSIBILITY)
+
+#include "AXObjectCache.h"
+#include "AccessibilityListBox.h"
+#include "AccessibilityRenderObject.h"
+#include "AtomicString.h"
+#include "CString.h"
+#include "Document.h"
+#include "Editor.h"
+#include "Frame.h"
+#include "FrameView.h"
+#include "HTMLNames.h"
+#include "IntRect.h"
+#include "NotImplemented.h"
+
+#include <atk/atk.h>
+#include <glib.h>
+#include <glib/gprintf.h>
+#include <pango/pango.h>
+
+using namespace WebCore;
+
+static AccessibilityObject* fallbackObject()
+{
+ static AXObjectCache* fallbackCache = new AXObjectCache();
+ static AccessibilityObject* object = 0;
+ if (!object) {
+ // FIXME: using fallbackCache->getOrCreate(ListBoxOptionRole) is a hack
+ object = fallbackCache->getOrCreate(ListBoxOptionRole);
+ object->ref();
+ }
+
+ return object;
+}
+
+// Used to provide const char* returns.
+static const char* returnString(const String& str)
+{
+ static CString returnedString;
+ returnedString = str.utf8();
+ return returnedString.data();
+}
+
+static AccessibilityObject* core(WebKitAccessible* accessible)
+{
+ if (!accessible)
+ return 0;
+
+ return accessible->m_object;
+}
+
+static AccessibilityObject* core(AtkObject* object)
+{
+ if (!WEBKIT_IS_ACCESSIBLE(object))
+ return 0;
+
+ return core(WEBKIT_ACCESSIBLE(object));
+}
+
+static AccessibilityObject* core(AtkAction* action)
+{
+ return core(ATK_OBJECT(action));
+}
+
+static AccessibilityObject* core(AtkStreamableContent* streamable)
+{
+ return core(ATK_OBJECT(streamable));
+}
+
+static AccessibilityObject* core(AtkText* text)
+{
+ return core(ATK_OBJECT(text));
+}
+
+static AccessibilityObject* core(AtkEditableText* text)
+{
+ return core(ATK_OBJECT(text));
+}
+
+static AccessibilityObject* core(AtkComponent* component)
+{
+ return core(ATK_OBJECT(component));
+}
+
+static AccessibilityObject* core(AtkImage* image)
+{
+ return core(ATK_OBJECT(image));
+}
+
+static const gchar* webkit_accessible_get_name(AtkObject* object)
+{
+ return returnString(core(object)->stringValue());
+}
+
+static const gchar* webkit_accessible_get_description(AtkObject* object)
+{
+ // TODO: the Mozilla MSAA implementation prepends "Description: "
+ // Should we do this too?
+ return returnString(core(object)->accessibilityDescription());
+}
+
+static AtkObject* webkit_accessible_get_parent(AtkObject* object)
+{
+ AccessibilityObject* coreParent = core(object)->parentObject();
+
+ if (!coreParent)
+ return NULL;
+
+ return coreParent->wrapper();
+}
+
+static gint webkit_accessible_get_n_children(AtkObject* object)
+{
+ return core(object)->children().size();
+}
+
+static AtkObject* webkit_accessible_ref_child(AtkObject* object, gint index)
+{
+ AccessibilityObject* coreObject = core(object);
+
+ g_return_val_if_fail(index >= 0, NULL);
+ g_return_val_if_fail(static_cast<size_t>(index) < coreObject->children().size(), NULL);
+
+ AccessibilityObject* coreChild = coreObject->children().at(index).get();
+
+ if (!coreChild)
+ return NULL;
+
+ AtkObject* child = coreChild->wrapper();
+ // TODO: Should we call atk_object_set_parent() here?
+ //atk_object_set_parent(child, object);
+ g_object_ref(child);
+
+ return child;
+}
+
+static gint webkit_accessible_get_index_in_parent(AtkObject* object)
+{
+ // FIXME: This needs to be implemented.
+ notImplemented();
+ return 0;
+}
+
+static AtkRole atkRole(AccessibilityRole role)
+{
+ switch (role) {
+ case UnknownRole:
+ return ATK_ROLE_UNKNOWN;
+ case ButtonRole:
+ return ATK_ROLE_PUSH_BUTTON;
+ case RadioButtonRole:
+ return ATK_ROLE_RADIO_BUTTON;
+ case CheckBoxRole:
+ return ATK_ROLE_CHECK_BOX;
+ case SliderRole:
+ return ATK_ROLE_SLIDER;
+ case TabGroupRole:
+ return ATK_ROLE_PAGE_TAB_LIST;
+ case TextFieldRole:
+ case TextAreaRole:
+ return ATK_ROLE_ENTRY;
+ case StaticTextRole:
+ return ATK_ROLE_TEXT;
+ case OutlineRole:
+ return ATK_ROLE_TREE;
+ case MenuBarRole:
+ return ATK_ROLE_MENU_BAR;
+ case MenuRole:
+ return ATK_ROLE_MENU;
+ case MenuItemRole:
+ return ATK_ROLE_MENU_ITEM;
+ case ColumnRole:
+ //return ATK_ROLE_TABLE_COLUMN_HEADER; // Is this right?
+ return ATK_ROLE_UNKNOWN; // Matches Mozilla
+ case RowRole:
+ //return ATK_ROLE_TABLE_ROW_HEADER; // Is this right?
+ return ATK_ROLE_LIST_ITEM; // Matches Mozilla
+ case ToolbarRole:
+ return ATK_ROLE_TOOL_BAR;
+ case BusyIndicatorRole:
+ return ATK_ROLE_PROGRESS_BAR; // Is this right?
+ case ProgressIndicatorRole:
+ //return ATK_ROLE_SPIN_BUTTON; // Some confusion about this role in AccessibilityRenderObject.cpp
+ return ATK_ROLE_PROGRESS_BAR;
+ case WindowRole:
+ return ATK_ROLE_WINDOW;
+ case ComboBoxRole:
+ return ATK_ROLE_COMBO_BOX;
+ case SplitGroupRole:
+ return ATK_ROLE_SPLIT_PANE;
+ case SplitterRole:
+ return ATK_ROLE_SEPARATOR;
+ case ColorWellRole:
+ return ATK_ROLE_COLOR_CHOOSER;
+ case ListRole:
+ return ATK_ROLE_LIST;
+ case ScrollBarRole:
+ return ATK_ROLE_SCROLL_BAR;
+ case GridRole: // Is this right?
+ case TableRole:
+ return ATK_ROLE_TABLE;
+ case ApplicationRole:
+ return ATK_ROLE_APPLICATION;
+ //case LabelRole: // TODO: should this be covered in the switch?
+ // return ATK_ROLE_LABEL;
+ case GroupRole:
+ case RadioGroupRole:
+ return ATK_ROLE_PANEL;
+ case CellRole:
+ return ATK_ROLE_TABLE_CELL;
+ case LinkRole:
+ case WebCoreLinkRole:
+ case ImageMapLinkRole:
+ return ATK_ROLE_LINK;
+ case ImageMapRole:
+ case ImageRole:
+ return ATK_ROLE_IMAGE;
+ case ListMarkerRole:
+ return ATK_ROLE_TEXT;
+ case WebAreaRole:
+ //return ATK_ROLE_HTML_CONTAINER; // Is this right?
+ return ATK_ROLE_DOCUMENT_FRAME;
+ case HeadingRole:
+ return ATK_ROLE_HEADING;
+ case ListBoxRole:
+ return ATK_ROLE_LIST;
+ case ListBoxOptionRole:
+ return ATK_ROLE_LIST_ITEM;
+ default:
+ return ATK_ROLE_UNKNOWN;
+ }
+}
+
+static AtkRole webkit_accessible_get_role(AtkObject* object)
+{
+ AccessibilityObject* AXObject = core(object);
+
+ if (!AXObject)
+ return ATK_ROLE_UNKNOWN;
+
+ // WebCore does not seem to have a role for list items
+ if (AXObject->isGroup()) {
+ AccessibilityObject* parent = AXObject->parentObjectUnignored();
+ if (parent && parent->isList())
+ return ATK_ROLE_LIST_ITEM;
+ }
+
+ // WebCore does not know about paragraph role
+ Node* node = static_cast<AccessibilityRenderObject*>(AXObject)->renderer()->node();
+ if (node && node->hasTagName(HTMLNames::pTag))
+ return ATK_ROLE_PARAGRAPH;
+
+ // Note: Why doesn't WebCore have a password field for this
+ if (AXObject->isPasswordField())
+ return ATK_ROLE_PASSWORD_TEXT;
+
+ return atkRole(AXObject->roleValue());
+}
+
+static void setAtkStateSetFromCoreObject(AccessibilityObject* coreObject, AtkStateSet* stateSet)
+{
+ // Please keep the state list in alphabetical order
+
+ if (coreObject->isChecked())
+ atk_state_set_add_state(stateSet, ATK_STATE_CHECKED);
+
+ if (!coreObject->isReadOnly())
+ atk_state_set_add_state(stateSet, ATK_STATE_EDITABLE);
+
+ if (coreObject->isEnabled())
+ atk_state_set_add_state(stateSet, ATK_STATE_ENABLED);
+
+ if (coreObject->canSetFocusAttribute())
+ atk_state_set_add_state(stateSet, ATK_STATE_FOCUSABLE);
+
+ if (coreObject->isFocused())
+ atk_state_set_add_state(stateSet, ATK_STATE_FOCUSED);
+
+ // TODO: ATK_STATE_HORIZONTAL
+
+ if (coreObject->isIndeterminate())
+ atk_state_set_add_state(stateSet, ATK_STATE_INDETERMINATE);
+
+ if (coreObject->isMultiSelect())
+ atk_state_set_add_state(stateSet, ATK_STATE_MULTISELECTABLE);
+
+ // TODO: ATK_STATE_OPAQUE
+
+ if (coreObject->isPressed())
+ atk_state_set_add_state(stateSet, ATK_STATE_PRESSED);
+
+ // TODO: ATK_STATE_SELECTABLE_TEXT
+
+ // TODO: ATK_STATE_SENSITIVE
+
+ if (coreObject->isSelected())
+ atk_state_set_add_state(stateSet, ATK_STATE_SELECTED);
+
+ if (!coreObject->isOffScreen())
+ atk_state_set_add_state(stateSet, ATK_STATE_SHOWING);
+
+ // Mutually exclusive, so we group these two
+ if (coreObject->roleValue() == TextFieldRole)
+ atk_state_set_add_state(stateSet, ATK_STATE_SINGLE_LINE);
+ else if (coreObject->roleValue() == TextAreaRole)
+ atk_state_set_add_state(stateSet, ATK_STATE_MULTI_LINE);
+
+ // TODO: ATK_STATE_SENSITIVE
+
+ // TODO: ATK_STATE_VERTICAL
+
+ if (coreObject->isVisited())
+ atk_state_set_add_state(stateSet, ATK_STATE_VISITED);
+}
+
+static gpointer webkit_accessible_parent_class = NULL;
+
+static AtkStateSet* webkit_accessible_ref_state_set(AtkObject* object)
+{
+ AtkStateSet* stateSet = ATK_OBJECT_CLASS(webkit_accessible_parent_class)->ref_state_set(object);
+ AccessibilityObject* coreObject = core(object);
+
+ if (coreObject == fallbackObject()) {
+ atk_state_set_add_state(stateSet, ATK_STATE_DEFUNCT);
+ return stateSet;
+ }
+
+ setAtkStateSetFromCoreObject(coreObject, stateSet);
+
+ return stateSet;
+}
+
+static void webkit_accessible_init(AtkObject* object, gpointer data)
+{
+ if (ATK_OBJECT_CLASS(webkit_accessible_parent_class)->initialize)
+ ATK_OBJECT_CLASS(webkit_accessible_parent_class)->initialize(object, data);
+
+ WEBKIT_ACCESSIBLE(object)->m_object = reinterpret_cast<AccessibilityObject*>(data);
+}
+
+static void webkit_accessible_finalize(GObject* object)
+{
+ // This is a good time to clear the return buffer.
+ returnString(String());
+
+ if (G_OBJECT_CLASS(webkit_accessible_parent_class)->finalize)
+ G_OBJECT_CLASS(webkit_accessible_parent_class)->finalize(object);
+}
+
+static void webkit_accessible_class_init(AtkObjectClass* klass)
+{
+ GObjectClass* gobjectClass = G_OBJECT_CLASS(klass);
+
+ webkit_accessible_parent_class = g_type_class_peek_parent(klass);
+
+ gobjectClass->finalize = webkit_accessible_finalize;
+
+ klass->initialize = webkit_accessible_init;
+ klass->get_name = webkit_accessible_get_name;
+ klass->get_description = webkit_accessible_get_description;
+ klass->get_parent = webkit_accessible_get_parent;
+ klass->get_n_children = webkit_accessible_get_n_children;
+ klass->ref_child = webkit_accessible_ref_child;
+ klass->get_role = webkit_accessible_get_role;
+ klass->ref_state_set = webkit_accessible_ref_state_set;
+}
+
+GType
+webkit_accessible_get_type(void)
+{
+ static volatile gsize type_volatile = 0;
+
+ if (g_once_init_enter(&type_volatile)) {
+ static const GTypeInfo tinfo = {
+ sizeof(WebKitAccessibleClass),
+ (GBaseInitFunc)NULL,
+ (GBaseFinalizeFunc)NULL,
+ (GClassInitFunc)webkit_accessible_class_init,
+ (GClassFinalizeFunc)NULL,
+ NULL, /* class data */
+ sizeof(WebKitAccessible), /* instance size */
+ 0, /* nb preallocs */
+ (GInstanceInitFunc)NULL,
+ NULL /* value table */
+ };
+
+ GType type = g_type_register_static(ATK_TYPE_OBJECT,
+ "WebKitAccessible", &tinfo, GTypeFlags(0));
+ g_once_init_leave(&type_volatile, type);
+ }
+
+ return type_volatile;
+}
+
+static gboolean webkit_accessible_action_do_action(AtkAction* action, gint i)
+{
+ g_return_val_if_fail(i == 0, FALSE);
+ return core(action)->performDefaultAction();
+}
+
+static gint webkit_accessible_action_get_n_actions(AtkAction* action)
+{
+ return 1;
+}
+
+static const gchar* webkit_accessible_action_get_description(AtkAction* action, gint i)
+{
+ g_return_val_if_fail(i == 0, NULL);
+ // TODO: Need a way to provide/localize action descriptions.
+ notImplemented();
+ return "";
+}
+
+static const gchar* webkit_accessible_action_get_keybinding(AtkAction* action, gint i)
+{
+ g_return_val_if_fail(i == 0, NULL);
+ // FIXME: Construct a proper keybinding string.
+ return returnString(core(action)->accessKey().string());
+}
+
+static const gchar* webkit_accessible_action_get_name(AtkAction* action, gint i)
+{
+ g_return_val_if_fail(i == 0, NULL);
+ return returnString(core(action)->actionVerb());
+}
+
+static void atk_action_interface_init(AtkActionIface* iface)
+{
+ iface->do_action = webkit_accessible_action_do_action;
+ iface->get_n_actions = webkit_accessible_action_get_n_actions;
+ iface->get_description = webkit_accessible_action_get_description;
+ iface->get_keybinding = webkit_accessible_action_get_keybinding;
+ iface->get_name = webkit_accessible_action_get_name;
+}
+
+// Text
+
+static gchar* webkit_accessible_text_get_text(AtkText* text, gint startOffset, gint endOffset)
+{
+ AccessibilityObject* coreObject = core(text);
+ String ret;
+ unsigned start = startOffset;
+ int length = endOffset - startOffset;
+
+ if (coreObject->isTextControl())
+ ret = coreObject->doAXStringForRange(PlainTextRange(start, length));
+ else
+ ret = coreObject->textUnderElement().substring(start, length);
+
+ return g_strdup(ret.utf8().data());
+}
+
+enum GetTextFunctionType {
+ AfterOffset,
+ AtOffset,
+ BeforeOffset
+};
+
+typedef bool (*isCharacterAttribute) (PangoLogAttr* attr);
+
+static inline bool isWordStart(PangoLogAttr* attr)
+{
+ return attr->is_word_start;
+}
+
+static inline bool isWordEnd(PangoLogAttr* attr)
+{
+ return attr->is_word_end;
+}
+
+static inline bool isSentenceStart(PangoLogAttr* attr)
+{
+ return attr->is_sentence_start;
+}
+
+static inline bool isSentenceEnd(PangoLogAttr* attr)
+{
+ return attr->is_sentence_end;
+}
+
+enum Direction {
+ DirectionForward,
+ DirectionBackwards
+};
+
+static bool findCharacterAttribute(isCharacterAttribute predicateFunction, PangoLogAttr* attributes, Direction direction, int startOffset, int attrsLength, int* resultOffset)
+{
+ int advanceBy = direction == DirectionForward ? 1 : -1;
+
+ *resultOffset = -1;
+
+ for (int i = startOffset; i >= 0 && i < attrsLength; i += advanceBy) {
+ if (predicateFunction(attributes + i)) {
+ *resultOffset = i;
+ return true;
+ }
+ }
+
+ return false;
+}
+
+static bool findCharacterAttributeSkip(isCharacterAttribute predicateFunction, unsigned skip, PangoLogAttr* attributes, Direction direction, int startOffset, int attrsLength, int* resultOffset)
+{
+ int tmpOffset;
+
+ bool retValue = findCharacterAttribute(predicateFunction, attributes, direction, startOffset, attrsLength, &tmpOffset);
+ if (skip == 0) {
+ *resultOffset = tmpOffset;
+ return retValue;
+ }
+
+ if (direction == DirectionForward)
+ tmpOffset++;
+ else
+ tmpOffset--;
+
+ return findCharacterAttributeSkip(predicateFunction, skip - 1, attributes, direction, tmpOffset, attrsLength, resultOffset);
+}
+
+static isCharacterAttribute oppositePredicate(isCharacterAttribute predicate)
+{
+ if (predicate == isWordStart)
+ return isWordEnd;
+ if (predicate == isWordEnd)
+ return isWordStart;
+ if (predicate == isSentenceStart)
+ return isSentenceEnd;
+ if (predicate == isSentenceEnd)
+ return isSentenceStart;
+
+ g_assert_not_reached();
+}
+
+static gchar* getTextHelper(GetTextFunctionType getTextFunctionType, AtkText* textObject, gint offset, AtkTextBoundary boundaryType, gint* startOffset, gint* endOffset)
+{
+ AccessibilityObject* coreObject = core(textObject);
+ String text;
+
+ *startOffset = *endOffset = -1;
+
+ if (coreObject->isTextControl())
+ text = coreObject->text();
+ else
+ text = coreObject->textUnderElement();
+
+ char* cText = g_strdup(text.utf8().data());
+ glong textLength = g_utf8_strlen(cText, -1);
+
+ if (boundaryType == ATK_TEXT_BOUNDARY_CHAR) {
+ int effectiveOffset;
+
+ switch (getTextFunctionType) {
+ case AfterOffset:
+ effectiveOffset = offset + 1;
+ break;
+ case BeforeOffset:
+ effectiveOffset = offset - 1;
+ break;
+ case AtOffset:
+ effectiveOffset = offset;
+ break;
+ default:
+ g_assert_not_reached();
+ }
+
+ *startOffset = effectiveOffset;
+ *endOffset = effectiveOffset + 1;
+ } else {
+ PangoLogAttr* attrs = g_new(PangoLogAttr, textLength + 1);
+ PangoLanguage* language = pango_language_get_default();
+ pango_get_log_attrs(cText, -1, -1, language, attrs, textLength + 1);
+
+ isCharacterAttribute predicate;
+
+ if (boundaryType == ATK_TEXT_BOUNDARY_WORD_START)
+ predicate = isWordStart;
+ else if (boundaryType == ATK_TEXT_BOUNDARY_WORD_END)
+ predicate = isWordEnd;
+ else if (boundaryType == ATK_TEXT_BOUNDARY_SENTENCE_START)
+ predicate = isSentenceStart;
+ else if (boundaryType == ATK_TEXT_BOUNDARY_SENTENCE_END)
+ predicate = isSentenceEnd;
+ else
+ // FIXME: bail out for now, since we are missing the LINE
+ // boundary implementations
+ goto out;
+
+ switch (boundaryType) {
+ case ATK_TEXT_BOUNDARY_WORD_START:
+ case ATK_TEXT_BOUNDARY_SENTENCE_START:
+ if (getTextFunctionType == AfterOffset) {
+ // Take the item after the current one in any case
+ findCharacterAttribute(predicate, attrs, DirectionForward, offset + 1, textLength + 1, startOffset);
+ findCharacterAttributeSkip(predicate, 1, attrs, DirectionForward, offset + 1, textLength + 1, endOffset);
+ } else if (getTextFunctionType == AtOffset) {
+ // Take the item at point if the offset is in an item or
+ // the item before otherwise
+ findCharacterAttribute(predicate, attrs, DirectionBackwards, offset, textLength + 1, startOffset);
+ if (!findCharacterAttribute(predicate, attrs, DirectionForward, offset + 1, textLength + 1, endOffset)) {
+ findCharacterAttribute(oppositePredicate(predicate), attrs, DirectionForward, offset + 1, textLength + 1, endOffset);
+ // We want to include the actual end boundary
+ // here, since *_START would have done so. Advance
+ // until the end of the string if possible
+ if (*endOffset != -1 && *endOffset < textLength)
+ *endOffset = textLength;
+ }
+ } else {
+ // Take the item before the point if the offset is in an
+ // item, or the the item before that one otherwise
+ findCharacterAttributeSkip(predicate, 1, attrs, DirectionBackwards, offset, textLength + 1, startOffset);
+ findCharacterAttribute(predicate, attrs, DirectionBackwards, offset, textLength + 1, endOffset);
+ }
+ break;
+ case ATK_TEXT_BOUNDARY_WORD_END:
+ case ATK_TEXT_BOUNDARY_SENTENCE_END:
+ if (getTextFunctionType == AfterOffset) {
+ // Take the item after the current item if the offset is
+ // in a item, or the item after that otherwise
+ findCharacterAttribute(predicate, attrs, DirectionForward, offset, textLength + 1, startOffset);
+ findCharacterAttributeSkip(predicate, 1, attrs, DirectionForward, offset, textLength + 1, endOffset);
+ } else if (getTextFunctionType == AtOffset) {
+ // Take the item at point if the offset is in a item or
+ // the item after otherwise
+ if (!findCharacterAttribute(predicate, attrs, DirectionBackwards, offset, textLength + 1, startOffset))
+ // No match before offset, take the first opposite match at or before the offset
+ findCharacterAttribute(oppositePredicate(predicate), attrs, DirectionBackwards, offset, textLength + 1, startOffset);
+ findCharacterAttribute(predicate, attrs, DirectionForward, offset + 1, textLength + 1, endOffset);
+ } else {
+ // Take the item before the point in any case
+ if (!findCharacterAttributeSkip(predicate, 1, attrs, DirectionBackwards, offset, textLength + 1, startOffset)) {
+ int tmpOffset;
+ // No match before offset, take the first opposite match at or before the offset
+ findCharacterAttribute(predicate, attrs, DirectionBackwards, offset, textLength + 1, &tmpOffset);
+ findCharacterAttribute(oppositePredicate(predicate), attrs, DirectionBackwards, tmpOffset - 1, textLength + 1, startOffset);
+ }
+ findCharacterAttribute(predicate, attrs, DirectionBackwards, offset, textLength + 1, endOffset);
+ }
+ break;
+ default:
+ g_assert_not_reached();
+ }
+
+ g_free(attrs);
+ }
+
+ out:
+ if (*startOffset < 0 || *endOffset < 0) {
+ *startOffset = *endOffset = 0;
+ return g_strdup("");
+ }
+
+ char* start = g_utf8_offset_to_pointer(cText, (glong)*startOffset);
+ char* end = g_utf8_offset_to_pointer(cText, (glong)*endOffset);
+ char* resultText = g_strndup(start, end - start);
+ g_free(cText);
+ return resultText;
+}
+
+static gchar* webkit_accessible_text_get_text_after_offset(AtkText* text, gint offset, AtkTextBoundary boundaryType, gint* startOffset, gint* endOffset)
+{
+ return getTextHelper(AfterOffset, text, offset, boundaryType, startOffset, endOffset);
+}
+
+static gchar* webkit_accessible_text_get_text_at_offset(AtkText* text, gint offset, AtkTextBoundary boundaryType, gint* startOffset, gint* endOffset)
+{
+ return getTextHelper(AtOffset, text, offset, boundaryType, startOffset, endOffset);
+}
+
+static gchar* webkit_accessible_text_get_text_before_offset(AtkText* text, gint offset, AtkTextBoundary boundaryType, gint* startOffset, gint* endOffset)
+{
+ return getTextHelper(BeforeOffset, text, offset, boundaryType, startOffset, endOffset);
+}
+
+static gunichar webkit_accessible_text_get_character_at_offset(AtkText* text, gint offset)
+{
+ notImplemented();
+ return NULL;
+}
+
+static gint webkit_accessible_text_get_caret_offset(AtkText* text)
+{
+ // TODO: Verify this for RTL text.
+ return core(text)->selection().start().offsetInContainerNode();
+}
+
+static AtkAttributeSet* webkit_accessible_text_get_run_attributes(AtkText* text, gint offset, gint* start_offset, gint* end_offset)
+{
+ notImplemented();
+ return NULL;
+}
+
+static AtkAttributeSet* webkit_accessible_text_get_default_attributes(AtkText* text)
+{
+ notImplemented();
+ return NULL;
+}
+
+static void webkit_accessible_text_get_character_extents(AtkText* text, gint offset, gint* x, gint* y, gint* width, gint* height, AtkCoordType coords)
+{
+ IntRect extents = core(text)->doAXBoundsForRange(PlainTextRange(offset, 1));
+ // FIXME: Use the AtkCoordType
+ // Requires WebCore::ScrollView::contentsToScreen() to be implemented
+
+#if 0
+ switch(coords) {
+ case ATK_XY_SCREEN:
+ extents = core(text)->document()->view()->contentsToScreen(extents);
+ break;
+ case ATK_XY_WINDOW:
+ // No-op
+ break;
+ }
+#endif
+
+ *x = extents.x();
+ *y = extents.y();
+ *width = extents.width();
+ *height = extents.height();
+}
+
+static gint webkit_accessible_text_get_character_count(AtkText* text)
+{
+ AccessibilityObject* coreObject = core(text);
+
+ if (coreObject->isTextControl())
+ return coreObject->textLength();
+ else
+ return coreObject->textUnderElement().length();
+}
+
+static gint webkit_accessible_text_get_offset_at_point(AtkText* text, gint x, gint y, AtkCoordType coords)
+{
+ // FIXME: Use the AtkCoordType
+ // TODO: Is it correct to ignore range.length?
+ IntPoint pos(x, y);
+ PlainTextRange range = core(text)->doAXRangeForPosition(pos);
+ return range.start;
+}
+
+static gint webkit_accessible_text_get_n_selections(AtkText* text)
+{
+ notImplemented();
+ return 0;
+}
+
+static gchar* webkit_accessible_text_get_selection(AtkText* text, gint selection_num, gint* start_offset, gint* end_offset)
+{
+ notImplemented();
+ return NULL;
+}
+
+static gboolean webkit_accessible_text_add_selection(AtkText* text, gint start_offset, gint end_offset)
+{
+ notImplemented();
+ return FALSE;
+}
+
+static gboolean webkit_accessible_text_remove_selection(AtkText* text, gint selection_num)
+{
+ notImplemented();
+ return FALSE;
+}
+
+static gboolean webkit_accessible_text_set_selection(AtkText* text, gint selection_num, gint start_offset, gint end_offset)
+{
+ notImplemented();
+ return FALSE;
+}
+
+static gboolean webkit_accessible_text_set_caret_offset(AtkText* text, gint offset)
+{
+ // TODO: Verify
+ //core(text)->setSelectedTextRange(PlainTextRange(offset, 0));
+ AccessibilityObject* coreObject = core(text);
+ coreObject->setSelectedVisiblePositionRange(coreObject->visiblePositionRangeForRange(PlainTextRange(offset, 0)));
+ return TRUE;
+}
+
+static void atk_text_interface_init(AtkTextIface* iface)
+{
+ iface->get_text = webkit_accessible_text_get_text;
+ iface->get_text_after_offset = webkit_accessible_text_get_text_after_offset;
+ iface->get_text_at_offset = webkit_accessible_text_get_text_at_offset;
+ iface->get_character_at_offset = webkit_accessible_text_get_character_at_offset;
+ iface->get_text_before_offset = webkit_accessible_text_get_text_before_offset;
+ iface->get_caret_offset = webkit_accessible_text_get_caret_offset;
+ iface->get_run_attributes = webkit_accessible_text_get_run_attributes;
+ iface->get_default_attributes = webkit_accessible_text_get_default_attributes;
+ iface->get_character_extents = webkit_accessible_text_get_character_extents;
+ iface->get_character_count = webkit_accessible_text_get_character_count;
+ iface->get_offset_at_point = webkit_accessible_text_get_offset_at_point;
+ iface->get_n_selections = webkit_accessible_text_get_n_selections;
+ iface->get_selection = webkit_accessible_text_get_selection;
+
+ // set methods
+ iface->add_selection = webkit_accessible_text_add_selection;
+ iface->remove_selection = webkit_accessible_text_remove_selection;
+ iface->set_selection = webkit_accessible_text_set_selection;
+ iface->set_caret_offset = webkit_accessible_text_set_caret_offset;
+}
+
+// EditableText
+
+static gboolean webkit_accessible_editable_text_set_run_attributes(AtkEditableText* text, AtkAttributeSet* attrib_set, gint start_offset, gint end_offset)
+{
+ notImplemented();
+ return FALSE;
+}
+
+static void webkit_accessible_editable_text_set_text_contents(AtkEditableText* text, const gchar* string)
+{
+ // FIXME: string nullcheck?
+ core(text)->setValue(String::fromUTF8(string));
+}
+
+static void webkit_accessible_editable_text_insert_text(AtkEditableText* text, const gchar* string, gint length, gint* position)
+{
+ // FIXME: string nullcheck?
+
+ AccessibilityObject* coreObject = core(text);
+ // FIXME: Not implemented in WebCore
+ //coreObject->setSelectedTextRange(PlainTextRange(*position, 0));
+ //coreObject->setSelectedText(String::fromUTF8(string));
+
+ if (!coreObject->document() || !coreObject->document()->frame())
+ return;
+ coreObject->setSelectedVisiblePositionRange(coreObject->visiblePositionRangeForRange(PlainTextRange(*position, 0)));
+ coreObject->setFocused(true);
+ // FIXME: We should set position to the actual inserted text length, which may be less than that requested.
+ if (coreObject->document()->frame()->editor()->insertTextWithoutSendingTextEvent(String::fromUTF8(string), false, 0))
+ *position += length;
+}
+
+static void webkit_accessible_editable_text_copy_text(AtkEditableText* text, gint start_pos, gint end_pos)
+{
+ notImplemented();
+}
+
+static void webkit_accessible_editable_text_cut_text(AtkEditableText* text, gint start_pos, gint end_pos)
+{
+ notImplemented();
+}
+
+static void webkit_accessible_editable_text_delete_text(AtkEditableText* text, gint start_pos, gint end_pos)
+{
+ AccessibilityObject* coreObject = core(text);
+ // FIXME: Not implemented in WebCore
+ //coreObject->setSelectedTextRange(PlainTextRange(start_pos, end_pos - start_pos));
+ //coreObject->setSelectedText(String());
+
+ if (!coreObject->document() || !coreObject->document()->frame())
+ return;
+ coreObject->setSelectedVisiblePositionRange(coreObject->visiblePositionRangeForRange(PlainTextRange(start_pos, end_pos - start_pos)));
+ coreObject->setFocused(true);
+ coreObject->document()->frame()->editor()->performDelete();
+}
+
+static void webkit_accessible_editable_text_paste_text(AtkEditableText* text, gint position)
+{
+ notImplemented();
+}
+
+static void atk_editable_text_interface_init(AtkEditableTextIface* iface)
+{
+ iface->set_run_attributes = webkit_accessible_editable_text_set_run_attributes;
+ iface->set_text_contents = webkit_accessible_editable_text_set_text_contents;
+ iface->insert_text = webkit_accessible_editable_text_insert_text;
+ iface->copy_text = webkit_accessible_editable_text_copy_text;
+ iface->cut_text = webkit_accessible_editable_text_cut_text;
+ iface->delete_text = webkit_accessible_editable_text_delete_text;
+ iface->paste_text = webkit_accessible_editable_text_paste_text;
+}
+
+// StreamableContent
+
+static gint webkit_accessible_streamable_content_get_n_mime_types(AtkStreamableContent* streamable)
+{
+ notImplemented();
+ return 0;
+}
+
+static G_CONST_RETURN gchar* webkit_accessible_streamable_content_get_mime_type(AtkStreamableContent* streamable, gint i)
+{
+ notImplemented();
+ return "";
+}
+
+static GIOChannel* webkit_accessible_streamable_content_get_stream(AtkStreamableContent* streamable, const gchar* mime_type)
+{
+ notImplemented();
+ return NULL;
+}
+
+static G_CONST_RETURN gchar* webkit_accessible_streamable_content_get_uri(AtkStreamableContent* streamable, const gchar* mime_type)
+{
+ notImplemented();
+ return NULL;
+}
+
+static void atk_streamable_content_interface_init(AtkStreamableContentIface* iface)
+{
+ iface->get_n_mime_types = webkit_accessible_streamable_content_get_n_mime_types;
+ iface->get_mime_type = webkit_accessible_streamable_content_get_mime_type;
+ iface->get_stream = webkit_accessible_streamable_content_get_stream;
+ iface->get_uri = webkit_accessible_streamable_content_get_uri;
+}
+
+static void contentsToAtk(AccessibilityObject* coreObject, AtkCoordType coordType, IntRect rect, gint* x, gint* y, gint* width = 0, gint* height = 0)
+{
+ FrameView* frameView = coreObject->documentFrameView();
+
+ if (frameView) {
+ switch (coordType) {
+ case ATK_XY_WINDOW:
+ rect = frameView->contentsToWindow(rect);
+ break;
+ case ATK_XY_SCREEN:
+ rect = frameView->contentsToScreen(rect);
+ break;
+ }
+ }
+
+ if (x)
+ *x = rect.x();
+ if (y)
+ *y = rect.y();
+ if (width)
+ *width = rect.width();
+ if (height)
+ *height = rect.height();
+}
+
+static IntPoint atkToContents(AccessibilityObject* coreObject, AtkCoordType coordType, gint x, gint y)
+{
+ IntPoint pos(x, y);
+
+ FrameView* frameView = coreObject->documentFrameView();
+ if (frameView) {
+ switch (coordType) {
+ case ATK_XY_SCREEN:
+ return frameView->screenToContents(pos);
+ case ATK_XY_WINDOW:
+ return frameView->windowToContents(pos);
+ }
+ }
+
+ return pos;
+}
+
+static AtkObject* webkit_accessible_component_ref_accessible_at_point(AtkComponent* component, gint x, gint y, AtkCoordType coordType)
+{
+ IntPoint pos = atkToContents(core(component), coordType, x, y);
+ AccessibilityObject* target = core(component)->doAccessibilityHitTest(pos);
+ if (!target)
+ return NULL;
+ g_object_ref(target->wrapper());
+ return target->wrapper();
+}
+
+static void webkit_accessible_component_get_extents(AtkComponent* component, gint* x, gint* y, gint* width, gint* height, AtkCoordType coordType)
+{
+ IntRect rect = core(component)->elementRect();
+ contentsToAtk(core(component), coordType, rect, x, y, width, height);
+}
+
+static gboolean webkit_accessible_component_grab_focus(AtkComponent* component)
+{
+ core(component)->setFocused(true);
+ return core(component)->isFocused();
+}
+
+static void atk_component_interface_init(AtkComponentIface *iface)
+{
+ iface->ref_accessible_at_point = webkit_accessible_component_ref_accessible_at_point;
+ iface->get_extents = webkit_accessible_component_get_extents;
+ iface->grab_focus = webkit_accessible_component_grab_focus;
+}
+
+// Image
+
+static void webkit_accessible_image_get_image_position(AtkImage* image, gint* x, gint* y, AtkCoordType coordType)
+{
+ IntRect rect = core(image)->elementRect();
+ contentsToAtk(core(image), coordType, rect, x, y);
+}
+
+static const gchar* webkit_accessible_image_get_image_description(AtkImage* image)
+{
+ return returnString(core(image)->accessibilityDescription());
+}
+
+static void webkit_accessible_image_get_image_size(AtkImage* image, gint* width, gint* height)
+{
+ IntSize size = core(image)->size();
+
+ if (width)
+ *width = size.width();
+ if (height)
+ *height = size.height();
+}
+
+static void atk_image_interface_init(AtkImageIface* iface)
+{
+ iface->get_image_position = webkit_accessible_image_get_image_position;
+ iface->get_image_description = webkit_accessible_image_get_image_description;
+ iface->get_image_size = webkit_accessible_image_get_image_size;
+}
+
+static const GInterfaceInfo AtkInterfacesInitFunctions[] = {
+ {(GInterfaceInitFunc)atk_action_interface_init,
+ (GInterfaceFinalizeFunc) NULL, NULL},
+ {(GInterfaceInitFunc)atk_streamable_content_interface_init,
+ (GInterfaceFinalizeFunc) NULL, NULL},
+ {(GInterfaceInitFunc)atk_editable_text_interface_init,
+ (GInterfaceFinalizeFunc) NULL, NULL},
+ {(GInterfaceInitFunc)atk_text_interface_init,
+ (GInterfaceFinalizeFunc) NULL, NULL},
+ {(GInterfaceInitFunc)atk_component_interface_init,
+ (GInterfaceFinalizeFunc) NULL, NULL},
+ {(GInterfaceInitFunc)atk_image_interface_init,
+ (GInterfaceFinalizeFunc) NULL, NULL}
+};
+
+enum WAIType {
+ WAI_ACTION,
+ WAI_STREAMABLE,
+ WAI_EDITABLE_TEXT,
+ WAI_TEXT,
+ WAI_COMPONENT,
+ WAI_IMAGE
+};
+
+static GType GetAtkInterfaceTypeFromWAIType(WAIType type)
+{
+ switch (type) {
+ case WAI_ACTION:
+ return ATK_TYPE_ACTION;
+ case WAI_STREAMABLE:
+ return ATK_TYPE_STREAMABLE_CONTENT;
+ case WAI_EDITABLE_TEXT:
+ return ATK_TYPE_EDITABLE_TEXT;
+ case WAI_TEXT:
+ return ATK_TYPE_TEXT;
+ case WAI_COMPONENT:
+ return ATK_TYPE_COMPONENT;
+ case WAI_IMAGE:
+ return ATK_TYPE_IMAGE;
+ }
+
+ return G_TYPE_INVALID;
+}
+
+static guint16 getInterfaceMaskFromObject(AccessibilityObject* coreObject)
+{
+ guint16 interfaceMask = 0;
+
+ // Streamable is always supported (FIXME: This is wrong)
+ interfaceMask |= 1 << WAI_STREAMABLE;
+
+ // Component interface is always supported
+ interfaceMask |= 1 << WAI_COMPONENT;
+
+ // Action
+ if (!coreObject->actionVerb().isEmpty())
+ interfaceMask |= 1 << WAI_ACTION;
+
+ // Text & Editable Text
+ AccessibilityRole role = coreObject->roleValue();
+
+ if (role == StaticTextRole)
+ interfaceMask |= 1 << WAI_TEXT;
+
+ if (coreObject->isAccessibilityRenderObject() && coreObject->isTextControl()) {
+ if (coreObject->isReadOnly())
+ interfaceMask |= 1 << WAI_TEXT;
+ else
+ interfaceMask |= 1 << WAI_EDITABLE_TEXT;
+ }
+
+ // Image
+ if (coreObject->isImage())
+ interfaceMask |= 1 << WAI_IMAGE;
+
+ return interfaceMask;
+}
+
+static const char* getUniqueAccessibilityTypeName(guint16 interfaceMask)
+{
+#define WAI_TYPE_NAME_LEN (30) /* Enough for prefix + 5 hex characters (max) */
+ static char name[WAI_TYPE_NAME_LEN + 1];
+
+ g_sprintf(name, "WAIType%x", interfaceMask);
+ name[WAI_TYPE_NAME_LEN] = '\0';
+
+ return name;
+}
+
+static GType getAccessibilityTypeFromObject(AccessibilityObject* coreObject)
+{
+ static const GTypeInfo typeInfo = {
+ sizeof(WebKitAccessibleClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) NULL,
+ (GClassFinalizeFunc) NULL,
+ NULL, /* class data */
+ sizeof(WebKitAccessible), /* instance size */
+ 0, /* nb preallocs */
+ (GInstanceInitFunc) NULL,
+ NULL /* value table */
+ };
+
+ guint16 interfaceMask = getInterfaceMaskFromObject(coreObject);
+ const char* atkTypeName = getUniqueAccessibilityTypeName(interfaceMask);
+ GType type = g_type_from_name(atkTypeName);
+ if (type)
+ return type;
+
+ type = g_type_register_static(WEBKIT_TYPE_ACCESSIBLE,
+ atkTypeName,
+ &typeInfo, GTypeFlags(0));
+ for (guint i = 0; i < G_N_ELEMENTS(AtkInterfacesInitFunctions); i++) {
+ if (interfaceMask & (1 << i))
+ g_type_add_interface_static(type,
+ GetAtkInterfaceTypeFromWAIType(static_cast<WAIType>(i)),
+ &AtkInterfacesInitFunctions[i]);
+ }
+
+ return type;
+}
+
+WebKitAccessible* webkit_accessible_new(AccessibilityObject* coreObject)
+{
+ GType type = getAccessibilityTypeFromObject(coreObject);
+ AtkObject* object = static_cast<AtkObject*>(g_object_new(type, NULL));
+
+ atk_object_initialize(object, coreObject);
+
+ return WEBKIT_ACCESSIBLE(object);
+}
+
+AccessibilityObject* webkit_accessible_get_accessibility_object(WebKitAccessible* accessible)
+{
+ return accessible->m_object;
+}
+
+void webkit_accessible_detach(WebKitAccessible* accessible)
+{
+ ASSERT(accessible->m_object);
+
+ // We replace the WebCore AccessibilityObject with a fallback object that
+ // provides default implementations to avoid repetitive null-checking after
+ // detachment.
+ accessible->m_object = fallbackObject();
+}
+
+#endif // HAVE(ACCESSIBILITY)
diff --git a/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.h b/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.h
new file mode 100644
index 0000000..ecfb99e
--- /dev/null
+++ b/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2008 Nuanti Ltd.
+ *
+ * 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 AccessibilityObjectWrapperAtk_h
+#define AccessibilityObjectWrapperAtk_h
+
+#include <atk/atk.h>
+
+namespace WebCore {
+ class AccessibilityObject;
+}
+
+G_BEGIN_DECLS
+
+#define WEBKIT_TYPE_ACCESSIBLE (webkit_accessible_get_type ())
+#define WEBKIT_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WEBKIT_TYPE_ACCESSIBLE, WebKitAccessible))
+#define WEBKIT_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WEBKIT_TYPE_ACCESSIBLE, WebKitAccessibleClass))
+#define WEBKIT_IS_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WEBKIT_TYPE_ACCESSIBLE))
+#define WEBKIT_IS_ACCESSIBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WEBKIT_TYPE_ACCESSIBLE))
+#define WEBKIT_ACCESSIBLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WEBKIT_TYPE_ACCESSIBLE, WebKitAccessibleClass))
+
+typedef struct _WebKitAccessible WebKitAccessible;
+typedef struct _WebKitAccessibleClass WebKitAccessibleClass;
+
+struct _WebKitAccessible
+{
+ AtkObject parent;
+ WebCore::AccessibilityObject* m_object;
+};
+
+struct _WebKitAccessibleClass
+{
+ AtkObjectClass parent_class;
+};
+
+GType webkit_accessible_get_type (void) G_GNUC_CONST;
+
+WebKitAccessible* webkit_accessible_new (WebCore::AccessibilityObject* core_object);
+
+WebCore::AccessibilityObject* webkit_accessible_get_accessibility_object (WebKitAccessible* accessible);
+
+void webkit_accessible_detach (WebKitAccessible* accessible);
+
+G_END_DECLS
+
+#endif // AccessibilityObjectWrapperAtk_h
diff --git a/WebCore/accessibility/mac/AXObjectCacheMac.mm b/WebCore/accessibility/mac/AXObjectCacheMac.mm
new file mode 100644
index 0000000..be7968b
--- /dev/null
+++ b/WebCore/accessibility/mac/AXObjectCacheMac.mm
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "AXObjectCache.h"
+
+#if HAVE(ACCESSIBILITY)
+
+#import "AccessibilityObject.h"
+#import "AccessibilityObjectWrapper.h"
+#import "RenderObject.h"
+#import "WebCoreViewFactory.h"
+
+#import <wtf/PassRefPtr.h>
+
+// The simple Cocoa calls in this file don't throw exceptions.
+
+namespace WebCore {
+
+void AXObjectCache::detachWrapper(AccessibilityObject* obj)
+{
+ [obj->wrapper() detach];
+ [obj->wrapper() release];
+ obj->setWrapper(0);
+}
+
+void AXObjectCache::attachWrapper(AccessibilityObject* obj)
+{
+ obj->setWrapper([[AccessibilityObjectWrapper alloc] initWithAccessibilityObject:obj]);
+}
+
+void AXObjectCache::postPlatformNotification(AccessibilityObject* obj, const String& message)
+{
+ if (!obj)
+ return;
+
+ NSAccessibilityPostNotification(obj->wrapper(), message);
+}
+
+void AXObjectCache::handleFocusedUIElementChanged()
+{
+ [[WebCoreViewFactory sharedFactory] accessibilityHandleFocusChanged];
+}
+
+}
+
+#endif // HAVE(ACCESSIBILITY)
diff --git a/WebCore/accessibility/mac/AccessibilityObjectMac.mm b/WebCore/accessibility/mac/AccessibilityObjectMac.mm
new file mode 100644
index 0000000..8f47af0
--- /dev/null
+++ b/WebCore/accessibility/mac/AccessibilityObjectMac.mm
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "AccessibilityObject.h"
+
+#if HAVE(ACCESSIBILITY)
+
+#import "AccessibilityObjectWrapper.h"
+
+namespace WebCore {
+
+bool AccessibilityObject::accessibilityIgnoreAttachment() const
+{
+ return [[wrapper() attachmentView] accessibilityIsIgnored];
+}
+
+} // WebCore
+
+#endif // HAVE(ACCESSIBILITY)
diff --git a/WebCore/accessibility/mac/AccessibilityObjectWrapper.h b/WebCore/accessibility/mac/AccessibilityObjectWrapper.h
new file mode 100644
index 0000000..3b584a9
--- /dev/null
+++ b/WebCore/accessibility/mac/AccessibilityObjectWrapper.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef AccessibilityObjectWrapper_h
+#define AccessibilityObjectWrapper_h
+
+#import <wtf/RefPtr.h>
+
+#ifdef __OBJC__
+@class WebCoreTextMarker;
+@class WebCoreTextMarkerRange;
+#else
+class WebCoreTextMarker;
+class WebCoreTextMarkerRange;
+#endif
+
+namespace WebCore {
+ class AccessibilityObject;
+ class VisiblePosition;
+}
+
+@interface AccessibilityObjectWrapper : NSObject
+{
+ WebCore::AccessibilityObject* m_object;
+}
+
+- (id)initWithAccessibilityObject:(WebCore::AccessibilityObject*)axObject;
+- (void)detach;
+- (WebCore::AccessibilityObject*)accessibilityObject;
+
+- (NSView*)attachmentView;
+
+@end
+
+#endif // AccessibilityObjectWrapper_h
diff --git a/WebCore/accessibility/mac/AccessibilityObjectWrapper.mm b/WebCore/accessibility/mac/AccessibilityObjectWrapper.mm
new file mode 100644
index 0000000..6137e68
--- /dev/null
+++ b/WebCore/accessibility/mac/AccessibilityObjectWrapper.mm
@@ -0,0 +1,2147 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "AccessibilityObjectWrapper.h"
+
+#if HAVE(ACCESSIBILITY)
+
+#import "AXObjectCache.h"
+#import "AccessibilityListBox.h"
+#import "AccessibilityList.h"
+#import "AccessibilityRenderObject.h"
+#import "AccessibilityTable.h"
+#import "AccessibilityTableCell.h"
+#import "AccessibilityTableRow.h"
+#import "AccessibilityTableColumn.h"
+#import "ColorMac.h"
+#import "Frame.h"
+#import "HTMLAnchorElement.h"
+#import "HTMLAreaElement.h"
+#import "HTMLImageElement.h"
+#import "HTMLInputElement.h"
+#import "HTMLTextAreaElement.h"
+#import "LocalizedStrings.h"
+#import "RenderTextControl.h"
+#import "RenderView.h"
+#import "RenderWidget.h"
+#import "SelectionController.h"
+#import "SimpleFontData.h"
+#import "TextIterator.h"
+#import "WebCoreFrameView.h"
+#import "WebCoreObjCExtras.h"
+#import "WebCoreViewFactory.h"
+#import "htmlediting.h"
+#import "visible_units.h"
+#import <runtime/InitializeThreading.h>
+
+using namespace WebCore;
+using namespace HTMLNames;
+using namespace std;
+
+// Cell Tables
+#ifndef NSAccessibilitySelectedCellsAttribute
+#define NSAccessibilitySelectedCellsAttribute @"AXSelectedCells"
+#endif
+
+#ifndef NSAccessibilityVisibleCellsAttribute
+#define NSAccessibilityVisibleCellsAttribute @"AXVisibleCells"
+#endif
+
+#ifndef NSAccessibilityRowHeaderUIElementsAttribute
+#define NSAccessibilityRowHeaderUIElementsAttribute @"AXRowHeaderUIElements"
+#endif
+
+#ifndef NSAccessibilityRowIndexRangeAttribute
+#define NSAccessibilityRowIndexRangeAttribute @"AXRowIndexRange"
+#endif
+
+#ifndef NSAccessibilityColumnIndexRangeAttribute
+#define NSAccessibilityColumnIndexRangeAttribute @"AXColumnIndexRange"
+#endif
+
+#ifndef NSAccessibilityCellForColumnAndRowParameterizedAttribute
+#define NSAccessibilityCellForColumnAndRowParameterizedAttribute @"AXCellForColumnAndRow"
+#endif
+
+#ifndef NSAccessibilityCellRole
+#define NSAccessibilityCellRole @"AXCell"
+#endif
+
+// Lists
+#ifndef NSAccessibilityContentListSubrole
+#define NSAccessibilityContentListSubrole @"AXContentList"
+#endif
+
+#ifndef NSAccessibilityDefinitionListSubrole
+#define NSAccessibilityDefinitionListSubrole @"AXDefinitionList"
+#endif
+
+// Miscellaneous
+#ifndef NSAccessibilityBlockQuoteLevelAttribute
+#define NSAccessibilityBlockQuoteLevelAttribute @"AXBlockQuoteLevel"
+#endif
+
+#ifndef NSAccessibilityAccessKeyAttribute
+#define NSAccessibilityAccessKeyAttribute @"AXAccessKey"
+#endif
+
+#ifdef BUILDING_ON_TIGER
+typedef unsigned NSUInteger;
+#endif
+
+@interface NSObject (WebKitAccessibilityArrayCategory)
+
+- (NSUInteger)accessibilityIndexOfChild:(id)child;
+- (NSUInteger)accessibilityArrayAttributeCount:(NSString *)attribute;
+- (NSArray *)accessibilityArrayAttributeValues:(NSString *)attribute index:(NSUInteger)index maxCount:(NSUInteger)maxCount;
+
+@end
+
+@implementation AccessibilityObjectWrapper
+
++ (void)initialize
+{
+ JSC::initializeThreading();
+#ifndef BUILDING_ON_TIGER
+ WebCoreObjCFinalizeOnMainThread(self);
+#endif
+}
+
+- (id)initWithAccessibilityObject:(AccessibilityObject*)axObject
+{
+ [super init];
+
+ m_object = axObject;
+ return self;
+}
+
+- (void)unregisterUniqueIdForUIElement
+{
+ [[WebCoreViewFactory sharedFactory] unregisterUniqueIdForUIElement:self];
+}
+
+- (void)detach
+{
+ // Send unregisterUniqueIdForUIElement unconditionally because if it is
+ // ever accidently not done (via other bugs in our AX implementation) you
+ // end up with a crash like <rdar://problem/4273149>. It is safe and not
+ // expensive to send even if the object is not registered.
+ [self unregisterUniqueIdForUIElement];
+ m_object = 0;
+}
+
+- (AccessibilityObject*)accessibilityObject
+{
+ return m_object;
+}
+
+- (NSView*)attachmentView
+{
+ ASSERT(m_object->isAttachment());
+ Widget* widget = m_object->widgetForAttachmentView();
+ if (!widget)
+ return nil;
+ return widget->platformWidget();
+}
+
+static WebCoreTextMarker* textMarkerForVisiblePosition(const VisiblePosition& visiblePos)
+{
+ if (visiblePos.isNull())
+ return nil;
+
+ Position deepPos = visiblePos.deepEquivalent();
+ Node* domNode = deepPos.node();
+ ASSERT(domNode);
+ if (!domNode)
+ return nil;
+
+ if (domNode->isHTMLElement()) {
+ InputElement* inputElement = toInputElement(static_cast<Element*>(domNode));
+ if (inputElement && inputElement->isPasswordField())
+ return nil;
+ }
+
+ // locate the renderer, which must exist for a visible dom node
+ RenderObject* renderer = domNode->renderer();
+ ASSERT(renderer);
+
+ // find or create an accessibility object for this renderer
+ AXObjectCache* cache = renderer->document()->axObjectCache();
+ RefPtr<AccessibilityObject> obj = cache->getOrCreate(renderer);
+
+ // create a text marker, adding an ID for the AccessibilityObject if needed
+ TextMarkerData textMarkerData;
+
+ // The compiler can add padding to this struct.
+ // This memory must be bzero'd so instances of TextMarkerData can be tested for byte-equivalence.
+ bzero(&textMarkerData, sizeof(TextMarkerData));
+ textMarkerData.axID = obj.get()->axObjectID();
+ textMarkerData.node = domNode;
+ textMarkerData.offset = deepPos.deprecatedEditingOffset();
+ textMarkerData.affinity = visiblePos.affinity();
+ return [[WebCoreViewFactory sharedFactory] textMarkerWithBytes:&textMarkerData length:sizeof(textMarkerData)];
+}
+
+static VisiblePosition visiblePositionForTextMarker(WebCoreTextMarker* textMarker)
+{
+ TextMarkerData textMarkerData;
+
+ if (![[WebCoreViewFactory sharedFactory] getBytes:&textMarkerData fromTextMarker:textMarker length:sizeof(textMarkerData)])
+ return VisiblePosition();
+
+ VisiblePosition visiblePos = VisiblePosition(textMarkerData.node, textMarkerData.offset, textMarkerData.affinity);
+ Position deepPos = visiblePos.deepEquivalent();
+ if (deepPos.isNull())
+ return VisiblePosition();
+
+ RenderObject* renderer = deepPos.node()->renderer();
+ if (!renderer)
+ return VisiblePosition();
+
+ AXObjectCache* cache = renderer->document()->axObjectCache();
+ if (!cache->isIDinUse(textMarkerData.axID))
+ return VisiblePosition();
+
+ if (deepPos.node() != textMarkerData.node || deepPos.deprecatedEditingOffset() != textMarkerData.offset)
+ return VisiblePosition();
+
+ return visiblePos;
+}
+
+static VisiblePosition visiblePositionForStartOfTextMarkerRange(WebCoreTextMarkerRange* textMarkerRange)
+{
+ return visiblePositionForTextMarker([[WebCoreViewFactory sharedFactory] startOfTextMarkerRange:textMarkerRange]);
+}
+
+static VisiblePosition visiblePositionForEndOfTextMarkerRange(WebCoreTextMarkerRange* textMarkerRange)
+{
+ return visiblePositionForTextMarker([[WebCoreViewFactory sharedFactory] endOfTextMarkerRange:textMarkerRange]);
+}
+
+static WebCoreTextMarkerRange* textMarkerRangeFromMarkers(WebCoreTextMarker* textMarker1, WebCoreTextMarker* textMarker2)
+{
+ if (!textMarker1 || !textMarker2)
+ return nil;
+
+ return [[WebCoreViewFactory sharedFactory] textMarkerRangeWithStart:textMarker1 end:textMarker2];
+}
+
+static void AXAttributeStringSetFont(NSMutableAttributedString* attrString, NSString* attribute, NSFont* font, NSRange range)
+{
+ NSDictionary* dict;
+
+ if (font) {
+ dict = [NSDictionary dictionaryWithObjectsAndKeys:
+ [font fontName] , NSAccessibilityFontNameKey,
+ [font familyName] , NSAccessibilityFontFamilyKey,
+ [font displayName] , NSAccessibilityVisibleNameKey,
+ [NSNumber numberWithFloat:[font pointSize]] , NSAccessibilityFontSizeKey,
+ nil];
+
+ [attrString addAttribute:attribute value:dict range:range];
+ } else
+ [attrString removeAttribute:attribute range:range];
+
+}
+
+static CGColorRef CreateCGColorIfDifferent(NSColor* nsColor, CGColorRef existingColor)
+{
+ // get color information assuming NSDeviceRGBColorSpace
+ NSColor* rgbColor = [nsColor colorUsingColorSpaceName:NSDeviceRGBColorSpace];
+ if (rgbColor == nil)
+ rgbColor = [NSColor blackColor];
+ CGFloat components[4];
+ [rgbColor getRed:&components[0] green:&components[1] blue:&components[2] alpha:&components[3]];
+
+ // create a new CGColorRef to return
+ CGColorSpaceRef cgColorSpace = CGColorSpaceCreateDeviceRGB();
+ CGColorRef cgColor = CGColorCreate(cgColorSpace, components);
+ CGColorSpaceRelease(cgColorSpace);
+
+ // check for match with existing color
+ if (existingColor && CGColorEqualToColor(cgColor, existingColor)) {
+ CGColorRelease(cgColor);
+ cgColor = 0;
+ }
+
+ return cgColor;
+}
+
+static void AXAttributeStringSetColor(NSMutableAttributedString* attrString, NSString* attribute, NSColor* color, NSRange range)
+{
+ if (color) {
+ CGColorRef existingColor = (CGColorRef) [attrString attribute:attribute atIndex:range.location effectiveRange:nil];
+ CGColorRef cgColor = CreateCGColorIfDifferent(color, existingColor);
+ if (cgColor) {
+ [attrString addAttribute:attribute value:(id)cgColor range:range];
+ CGColorRelease(cgColor);
+ }
+ } else
+ [attrString removeAttribute:attribute range:range];
+}
+
+static void AXAttributeStringSetNumber(NSMutableAttributedString* attrString, NSString* attribute, NSNumber* number, NSRange range)
+{
+ if (number)
+ [attrString addAttribute:attribute value:number range:range];
+ else
+ [attrString removeAttribute:attribute range:range];
+}
+
+static void AXAttributeStringSetStyle(NSMutableAttributedString* attrString, RenderObject* renderer, NSRange range)
+{
+ RenderStyle* style = renderer->style();
+
+ // set basic font info
+ AXAttributeStringSetFont(attrString, NSAccessibilityFontTextAttribute, style->font().primaryFont()->getNSFont(), range);
+
+ // set basic colors
+ AXAttributeStringSetColor(attrString, NSAccessibilityForegroundColorTextAttribute, nsColor(style->color()), range);
+ AXAttributeStringSetColor(attrString, NSAccessibilityBackgroundColorTextAttribute, nsColor(style->backgroundColor()), range);
+
+ // set super/sub scripting
+ EVerticalAlign alignment = style->verticalAlign();
+ if (alignment == SUB)
+ AXAttributeStringSetNumber(attrString, NSAccessibilitySuperscriptTextAttribute, [NSNumber numberWithInt:(-1)], range);
+ else if (alignment == SUPER)
+ AXAttributeStringSetNumber(attrString, NSAccessibilitySuperscriptTextAttribute, [NSNumber numberWithInt:1], range);
+ else
+ [attrString removeAttribute:NSAccessibilitySuperscriptTextAttribute range:range];
+
+ // set shadow
+ if (style->textShadow())
+ AXAttributeStringSetNumber(attrString, NSAccessibilityShadowTextAttribute, [NSNumber numberWithBool:YES], range);
+ else
+ [attrString removeAttribute:NSAccessibilityShadowTextAttribute range:range];
+
+ // set underline and strikethrough
+ int decor = style->textDecorationsInEffect();
+ if ((decor & UNDERLINE) == 0) {
+ [attrString removeAttribute:NSAccessibilityUnderlineTextAttribute range:range];
+ [attrString removeAttribute:NSAccessibilityUnderlineColorTextAttribute range:range];
+ }
+
+ if ((decor & LINE_THROUGH) == 0) {
+ [attrString removeAttribute:NSAccessibilityStrikethroughTextAttribute range:range];
+ [attrString removeAttribute:NSAccessibilityStrikethroughColorTextAttribute range:range];
+ }
+
+ if ((decor & (UNDERLINE | LINE_THROUGH)) != 0) {
+ // find colors using quirk mode approach (strict mode would use current
+ // color for all but the root line box, which would use getTextDecorationColors)
+ Color underline, overline, linethrough;
+ renderer->getTextDecorationColors(decor, underline, overline, linethrough);
+
+ if ((decor & UNDERLINE) != 0) {
+ AXAttributeStringSetNumber(attrString, NSAccessibilityUnderlineTextAttribute, [NSNumber numberWithBool:YES], range);
+ AXAttributeStringSetColor(attrString, NSAccessibilityUnderlineColorTextAttribute, nsColor(underline), range);
+ }
+
+ if ((decor & LINE_THROUGH) != 0) {
+ AXAttributeStringSetNumber(attrString, NSAccessibilityStrikethroughTextAttribute, [NSNumber numberWithBool:YES], range);
+ AXAttributeStringSetColor(attrString, NSAccessibilityStrikethroughColorTextAttribute, nsColor(linethrough), range);
+ }
+ }
+}
+
+static int blockquoteLevel(RenderObject* renderer)
+{
+ if (!renderer)
+ return 0;
+
+ int result = 0;
+ for (Node* node = renderer->node(); node; node = node->parent()) {
+ if (node->hasTagName(blockquoteTag))
+ result += 1;
+ }
+
+ return result;
+}
+
+static void AXAttributeStringSetBlockquoteLevel(NSMutableAttributedString* attrString, RenderObject* renderer, NSRange range)
+{
+ int quoteLevel = blockquoteLevel(renderer);
+
+ if (quoteLevel)
+ [attrString addAttribute:NSAccessibilityBlockQuoteLevelAttribute value:[NSNumber numberWithInt:quoteLevel] range:range];
+ else
+ [attrString removeAttribute:NSAccessibilityBlockQuoteLevelAttribute range:range];
+}
+
+static void AXAttributeStringSetSpelling(NSMutableAttributedString* attrString, Node* node, int offset, NSRange range)
+{
+ Vector<DocumentMarker> markers = node->renderer()->document()->markersForNode(node);
+ Vector<DocumentMarker>::iterator markerIt = markers.begin();
+
+ unsigned endOffset = (unsigned)offset + range.length;
+ for ( ; markerIt != markers.end(); markerIt++) {
+ DocumentMarker marker = *markerIt;
+
+ if (marker.type != DocumentMarker::Spelling)
+ continue;
+
+ if (marker.endOffset <= (unsigned)offset)
+ continue;
+
+ if (marker.startOffset > endOffset)
+ break;
+
+ // add misspelling attribute for the intersection of the marker and the range
+ int rStart = range.location + (marker.startOffset - offset);
+ int rLength = MIN(marker.endOffset, endOffset) - marker.startOffset;
+ NSRange spellRange = NSMakeRange(rStart, rLength);
+ AXAttributeStringSetNumber(attrString, NSAccessibilityMisspelledTextAttribute, [NSNumber numberWithBool:YES], spellRange);
+
+ if (marker.endOffset > endOffset + 1)
+ break;
+ }
+}
+
+static void AXAttributeStringSetHeadingLevel(NSMutableAttributedString* attrString, RenderObject* renderer, NSRange range)
+{
+ int parentHeadingLevel = AccessibilityRenderObject::headingLevel(renderer->parent()->node());
+
+ if (parentHeadingLevel)
+ [attrString addAttribute:@"AXHeadingLevel" value:[NSNumber numberWithInt:parentHeadingLevel] range:range];
+ else
+ [attrString removeAttribute:@"AXHeadingLevel" range:range];
+}
+
+static AccessibilityObject* AXLinkElementForNode(Node* node)
+{
+ RenderObject* obj = node->renderer();
+ if (!obj)
+ return 0;
+
+ RefPtr<AccessibilityObject> axObj = obj->document()->axObjectCache()->getOrCreate(obj);
+ Element* anchor = axObj->anchorElement();
+ if (!anchor)
+ return 0;
+
+ RenderObject* anchorRenderer = anchor->renderer();
+ if (!anchorRenderer)
+ return 0;
+
+ return anchorRenderer->document()->axObjectCache()->getOrCreate(anchorRenderer);
+}
+
+static void AXAttributeStringSetElement(NSMutableAttributedString* attrString, NSString* attribute, AccessibilityObject* object, NSRange range)
+{
+ if (object && object->isAccessibilityRenderObject()) {
+ // make a serialiazable AX object
+
+ RenderObject* renderer = static_cast<AccessibilityRenderObject*>(object)->renderer();
+ if (!renderer)
+ return;
+
+ Document* doc = renderer->document();
+ if (!doc)
+ return;
+
+ AXObjectCache* cache = doc->axObjectCache();
+ if (!cache)
+ return;
+
+ AXUIElementRef axElement = [[WebCoreViewFactory sharedFactory] AXUIElementForElement:object->wrapper()];
+ if (axElement) {
+ [attrString addAttribute:attribute value:(id)axElement range:range];
+ CFRelease(axElement);
+ }
+ } else
+ [attrString removeAttribute:attribute range:range];
+}
+
+static void AXAttributedStringAppendText(NSMutableAttributedString* attrString, Node* node, int offset, const UChar* chars, int length)
+{
+ // skip invisible text
+ if (!node->renderer())
+ return;
+
+ // easier to calculate the range before appending the string
+ NSRange attrStringRange = NSMakeRange([attrString length], length);
+
+ // append the string from this node
+ [[attrString mutableString] appendString:[NSString stringWithCharacters:chars length:length]];
+
+ // add new attributes and remove irrelevant inherited ones
+ // NOTE: color attributes are handled specially because -[NSMutableAttributedString addAttribute: value: range:] does not merge
+ // identical colors. Workaround is to not replace an existing color attribute if it matches what we are adding. This also means
+ // we cannot just pre-remove all inherited attributes on the appended string, so we have to remove the irrelevant ones individually.
+
+ // remove inherited attachment from prior AXAttributedStringAppendReplaced
+ [attrString removeAttribute:NSAccessibilityAttachmentTextAttribute range:attrStringRange];
+
+ // set new attributes
+ AXAttributeStringSetStyle(attrString, node->renderer(), attrStringRange);
+ AXAttributeStringSetHeadingLevel(attrString, node->renderer(), attrStringRange);
+ AXAttributeStringSetBlockquoteLevel(attrString, node->renderer(), attrStringRange);
+ AXAttributeStringSetElement(attrString, NSAccessibilityLinkTextAttribute, AXLinkElementForNode(node), attrStringRange);
+
+ // do spelling last because it tends to break up the range
+ AXAttributeStringSetSpelling(attrString, node, offset, attrStringRange);
+}
+
+static NSString* nsStringForReplacedNode(Node* replacedNode)
+{
+ // we should always be given a rendered node and a replaced node, but be safe
+ // replaced nodes are either attachments (widgets) or images
+ if (!replacedNode || !replacedNode->renderer() || !replacedNode->renderer()->isReplaced() || replacedNode->isTextNode()) {
+ ASSERT_NOT_REACHED();
+ return nil;
+ }
+
+ // create an AX object, but skip it if it is not supposed to be seen
+ RefPtr<AccessibilityObject> obj = replacedNode->renderer()->document()->axObjectCache()->getOrCreate(replacedNode->renderer());
+ if (obj->accessibilityIsIgnored())
+ return nil;
+
+ // use the attachmentCharacter to represent the replaced node
+ const UniChar attachmentChar = NSAttachmentCharacter;
+ return [NSString stringWithCharacters:&attachmentChar length:1];
+}
+
+- (NSAttributedString*)doAXAttributedStringForTextMarkerRange:(WebCoreTextMarkerRange*)textMarkerRange
+{
+ // extract the start and end VisiblePosition
+ VisiblePosition startVisiblePosition = visiblePositionForStartOfTextMarkerRange(textMarkerRange);
+ if (startVisiblePosition.isNull())
+ return nil;
+
+ VisiblePosition endVisiblePosition = visiblePositionForEndOfTextMarkerRange(textMarkerRange);
+ if (endVisiblePosition.isNull())
+ return nil;
+
+ // iterate over the range to build the AX attributed string
+ NSMutableAttributedString* attrString = [[NSMutableAttributedString alloc] init];
+ TextIterator it(makeRange(startVisiblePosition, endVisiblePosition).get());
+ while (!it.atEnd()) {
+ // locate the node and starting offset for this range
+ int exception = 0;
+ Node* node = it.range()->startContainer(exception);
+ ASSERT(node == it.range()->endContainer(exception));
+ int offset = it.range()->startOffset(exception);
+
+ // non-zero length means textual node, zero length means replaced node (AKA "attachments" in AX)
+ if (it.length() != 0) {
+ AXAttributedStringAppendText(attrString, node, offset, it.characters(), it.length());
+ } else {
+ Node* replacedNode = node->childNode(offset);
+ NSString *attachmentString = nsStringForReplacedNode(replacedNode);
+ if (attachmentString) {
+ NSRange attrStringRange = NSMakeRange([attrString length], [attachmentString length]);
+
+ // append the placeholder string
+ [[attrString mutableString] appendString:attachmentString];
+
+ // remove all inherited attributes
+ [attrString setAttributes:nil range:attrStringRange];
+
+ // add the attachment attribute
+ AccessibilityObject* obj = replacedNode->renderer()->document()->axObjectCache()->getOrCreate(replacedNode->renderer());
+ AXAttributeStringSetElement(attrString, NSAccessibilityAttachmentTextAttribute, obj, attrStringRange);
+ }
+ }
+ it.advance();
+ }
+
+ return [attrString autorelease];
+}
+
+static WebCoreTextMarkerRange* textMarkerRangeFromVisiblePositions(VisiblePosition startPosition, VisiblePosition endPosition)
+{
+ WebCoreTextMarker* startTextMarker = textMarkerForVisiblePosition(startPosition);
+ WebCoreTextMarker* endTextMarker = textMarkerForVisiblePosition(endPosition);
+ return textMarkerRangeFromMarkers(startTextMarker, endTextMarker);
+}
+
+- (NSArray*)accessibilityActionNames
+{
+ if (!m_object)
+ return nil;
+
+ m_object->updateBackingStore();
+
+ static NSArray* actionElementActions = [[NSArray alloc] initWithObjects: NSAccessibilityPressAction, NSAccessibilityShowMenuAction, nil];
+ static NSArray* defaultElementActions = [[NSArray alloc] initWithObjects: NSAccessibilityShowMenuAction, nil];
+ static NSArray* menuElementActions = [[NSArray alloc] initWithObjects: NSAccessibilityCancelAction, NSAccessibilityPressAction, nil];
+
+ NSArray *actions;
+ if (m_object->actionElement())
+ actions = actionElementActions;
+ else if (m_object->isMenuRelated())
+ actions = menuElementActions;
+ else if (m_object->isAttachment())
+ actions = [[self attachmentView] accessibilityActionNames];
+ else
+ actions = defaultElementActions;
+
+ return actions;
+}
+
+- (NSArray*)accessibilityAttributeNames
+{
+ if (!m_object)
+ return nil;
+
+ m_object->updateBackingStore();
+
+ if (m_object->isAttachment())
+ return [[self attachmentView] accessibilityAttributeNames];
+
+ static NSArray* attributes = nil;
+ static NSArray* anchorAttrs = nil;
+ static NSArray* webAreaAttrs = nil;
+ static NSArray* textAttrs = nil;
+ static NSArray* listBoxAttrs = nil;
+ static NSArray* rangeAttrs = nil;
+ static NSArray* commonMenuAttrs = nil;
+ static NSArray* menuAttrs = nil;
+ static NSArray* menuBarAttrs = nil;
+ static NSArray* menuItemAttrs = nil;
+ static NSArray* menuButtonAttrs = nil;
+ static NSArray* controlAttrs = nil;
+ static NSArray* tableAttrs = nil;
+ static NSArray* tableRowAttrs = nil;
+ static NSArray* tableColAttrs = nil;
+ static NSArray* tableCellAttrs = nil;
+ static NSArray* groupAttrs = nil;
+ static NSArray* inputImageAttrs = nil;
+ static NSArray* passwordFieldAttrs = nil;
+ NSMutableArray* tempArray;
+ if (attributes == nil) {
+ attributes = [[NSArray alloc] initWithObjects: NSAccessibilityRoleAttribute,
+ NSAccessibilitySubroleAttribute,
+ NSAccessibilityRoleDescriptionAttribute,
+ NSAccessibilityChildrenAttribute,
+ NSAccessibilityHelpAttribute,
+ NSAccessibilityParentAttribute,
+ NSAccessibilityPositionAttribute,
+ NSAccessibilitySizeAttribute,
+ NSAccessibilityTitleAttribute,
+ NSAccessibilityDescriptionAttribute,
+ NSAccessibilityValueAttribute,
+ NSAccessibilityFocusedAttribute,
+ NSAccessibilityEnabledAttribute,
+ NSAccessibilityWindowAttribute,
+ @"AXSelectedTextMarkerRange",
+ @"AXStartTextMarker",
+ @"AXEndTextMarker",
+ @"AXVisited",
+ NSAccessibilityLinkedUIElementsAttribute,
+ NSAccessibilitySelectedAttribute,
+ NSAccessibilityBlockQuoteLevelAttribute,
+ NSAccessibilityTopLevelUIElementAttribute,
+ nil];
+ }
+ if (commonMenuAttrs == nil) {
+ commonMenuAttrs = [[NSArray alloc] initWithObjects: NSAccessibilityRoleAttribute,
+ NSAccessibilityRoleDescriptionAttribute,
+ NSAccessibilityChildrenAttribute,
+ NSAccessibilityParentAttribute,
+ NSAccessibilityEnabledAttribute,
+ NSAccessibilityPositionAttribute,
+ NSAccessibilitySizeAttribute,
+ nil];
+ }
+ if (anchorAttrs == nil) {
+ tempArray = [[NSMutableArray alloc] initWithArray:attributes];
+ [tempArray addObject:NSAccessibilityURLAttribute];
+ [tempArray addObject:NSAccessibilityAccessKeyAttribute];
+ anchorAttrs = [[NSArray alloc] initWithArray:tempArray];
+ [tempArray release];
+ }
+ if (webAreaAttrs == nil) {
+ tempArray = [[NSMutableArray alloc] initWithArray:attributes];
+ [tempArray addObject:@"AXLinkUIElements"];
+ [tempArray addObject:@"AXLoaded"];
+ [tempArray addObject:@"AXLayoutCount"];
+ [tempArray addObject:NSAccessibilityURLAttribute];
+ webAreaAttrs = [[NSArray alloc] initWithArray:tempArray];
+ [tempArray release];
+ }
+ if (textAttrs == nil) {
+ tempArray = [[NSMutableArray alloc] initWithArray:attributes];
+ [tempArray addObject:NSAccessibilityNumberOfCharactersAttribute];
+ [tempArray addObject:NSAccessibilitySelectedTextAttribute];
+ [tempArray addObject:NSAccessibilitySelectedTextRangeAttribute];
+ [tempArray addObject:NSAccessibilityVisibleCharacterRangeAttribute];
+ [tempArray addObject:NSAccessibilityInsertionPointLineNumberAttribute];
+ [tempArray addObject:NSAccessibilityTitleUIElementAttribute];
+ [tempArray addObject:NSAccessibilityAccessKeyAttribute];
+ textAttrs = [[NSArray alloc] initWithArray:tempArray];
+ [tempArray release];
+ }
+ if (listBoxAttrs == nil) {
+ tempArray = [[NSMutableArray alloc] initWithArray:attributes];
+ [tempArray addObject:NSAccessibilitySelectedChildrenAttribute];
+ [tempArray addObject:NSAccessibilityVisibleChildrenAttribute];
+ [tempArray addObject:NSAccessibilityOrientationAttribute];
+ [tempArray addObject:NSAccessibilityTitleUIElementAttribute];
+ [tempArray addObject:NSAccessibilityAccessKeyAttribute];
+ listBoxAttrs = [[NSArray alloc] initWithArray:tempArray];
+ [tempArray release];
+ }
+ if (rangeAttrs == nil) {
+ tempArray = [[NSMutableArray alloc] initWithArray:attributes];
+ [tempArray addObject:NSAccessibilityTopLevelUIElementAttribute];
+ [tempArray addObject:NSAccessibilityValueAttribute];
+ [tempArray addObject:NSAccessibilityMinValueAttribute];
+ [tempArray addObject:NSAccessibilityMaxValueAttribute];
+ rangeAttrs = [[NSArray alloc] initWithArray:tempArray];
+ [tempArray release];
+ }
+ if (menuBarAttrs == nil) {
+ tempArray = [[NSMutableArray alloc] initWithArray:commonMenuAttrs];
+ [tempArray addObject:NSAccessibilitySelectedChildrenAttribute];
+ [tempArray addObject:NSAccessibilityVisibleChildrenAttribute];
+ [tempArray addObject:NSAccessibilityTitleUIElementAttribute];
+ menuBarAttrs = [[NSArray alloc] initWithArray:tempArray];
+ [tempArray release];
+ }
+ if (menuAttrs == nil) {
+ tempArray = [[NSMutableArray alloc] initWithArray:commonMenuAttrs];
+ [tempArray addObject:NSAccessibilitySelectedChildrenAttribute];
+ [tempArray addObject:NSAccessibilityVisibleChildrenAttribute];
+ [tempArray addObject:NSAccessibilityTitleUIElementAttribute];
+ menuAttrs = [[NSArray alloc] initWithArray:tempArray];
+ [tempArray release];
+ }
+ if (menuItemAttrs == nil) {
+ tempArray = [[NSMutableArray alloc] initWithArray:commonMenuAttrs];
+ [tempArray addObject:NSAccessibilityTitleAttribute];
+ [tempArray addObject:NSAccessibilityHelpAttribute];
+ [tempArray addObject:NSAccessibilitySelectedAttribute];
+ [tempArray addObject:(NSString*)kAXMenuItemCmdCharAttribute];
+ [tempArray addObject:(NSString*)kAXMenuItemCmdVirtualKeyAttribute];
+ [tempArray addObject:(NSString*)kAXMenuItemCmdGlyphAttribute];
+ [tempArray addObject:(NSString*)kAXMenuItemCmdModifiersAttribute];
+ [tempArray addObject:(NSString*)kAXMenuItemMarkCharAttribute];
+ [tempArray addObject:(NSString*)kAXMenuItemPrimaryUIElementAttribute];
+ [tempArray addObject:NSAccessibilityServesAsTitleForUIElementsAttribute];
+ menuItemAttrs = [[NSArray alloc] initWithArray:tempArray];
+ [tempArray release];
+ }
+ if (menuButtonAttrs == nil) {
+ menuButtonAttrs = [[NSArray alloc] initWithObjects:NSAccessibilityRoleAttribute,
+ NSAccessibilityRoleDescriptionAttribute,
+ NSAccessibilityParentAttribute,
+ NSAccessibilityPositionAttribute,
+ NSAccessibilitySizeAttribute,
+ NSAccessibilityWindowAttribute,
+ NSAccessibilityTopLevelUIElementAttribute,
+ NSAccessibilityEnabledAttribute,
+ NSAccessibilityFocusedAttribute,
+ NSAccessibilityTitleAttribute,
+ NSAccessibilityChildrenAttribute, nil];
+ }
+ if (controlAttrs == nil) {
+ tempArray = [[NSMutableArray alloc] initWithArray:attributes];
+ [tempArray addObject:NSAccessibilityTitleUIElementAttribute];
+ [tempArray addObject:NSAccessibilityAccessKeyAttribute];
+ controlAttrs = [[NSArray alloc] initWithArray:tempArray];
+ [tempArray release];
+ }
+ if (tableAttrs == nil) {
+ tempArray = [[NSMutableArray alloc] initWithArray:attributes];
+ [tempArray addObject:NSAccessibilityRowsAttribute];
+ [tempArray addObject:NSAccessibilityVisibleRowsAttribute];
+ [tempArray addObject:NSAccessibilityColumnsAttribute];
+ [tempArray addObject:NSAccessibilityVisibleColumnsAttribute];
+ [tempArray addObject:NSAccessibilityVisibleCellsAttribute];
+ [tempArray addObject:(NSString *)kAXColumnHeaderUIElementsAttribute];
+ [tempArray addObject:NSAccessibilityRowHeaderUIElementsAttribute];
+ [tempArray addObject:NSAccessibilityHeaderAttribute];
+ tableAttrs = [[NSArray alloc] initWithArray:tempArray];
+ [tempArray release];
+ }
+ if (tableRowAttrs == nil) {
+ tempArray = [[NSMutableArray alloc] initWithArray:attributes];
+ [tempArray addObject:NSAccessibilityIndexAttribute];
+ tableRowAttrs = [[NSArray alloc] initWithArray:tempArray];
+ [tempArray release];
+ }
+ if (tableColAttrs == nil) {
+ tempArray = [[NSMutableArray alloc] initWithArray:attributes];
+ [tempArray addObject:NSAccessibilityIndexAttribute];
+ [tempArray addObject:NSAccessibilityHeaderAttribute];
+ [tempArray addObject:NSAccessibilityRowsAttribute];
+ [tempArray addObject:NSAccessibilityVisibleRowsAttribute];
+ tableColAttrs = [[NSArray alloc] initWithArray:tempArray];
+ [tempArray release];
+ }
+ if (tableCellAttrs == nil) {
+ tempArray = [[NSMutableArray alloc] initWithArray:attributes];
+ [tempArray addObject:NSAccessibilityRowIndexRangeAttribute];
+ [tempArray addObject:NSAccessibilityColumnIndexRangeAttribute];
+ tableCellAttrs = [[NSArray alloc] initWithArray:tempArray];
+ [tempArray release];
+ }
+ if (groupAttrs == nil) {
+ tempArray = [[NSMutableArray alloc] initWithArray:attributes];
+ [tempArray addObject:NSAccessibilityTitleUIElementAttribute];
+ groupAttrs = [[NSArray alloc] initWithArray:tempArray];
+ [tempArray release];
+ }
+ if (inputImageAttrs == nil) {
+ tempArray = [[NSMutableArray alloc] initWithArray:controlAttrs];
+ [tempArray addObject:NSAccessibilityURLAttribute];
+ [tempArray addObject:NSAccessibilityAccessKeyAttribute];
+ inputImageAttrs = [[NSArray alloc] initWithArray:tempArray];
+ [tempArray release];
+ }
+ if (passwordFieldAttrs == nil) {
+ tempArray = [[NSMutableArray alloc] initWithArray:attributes];
+ [tempArray addObject:NSAccessibilityTitleUIElementAttribute];
+ passwordFieldAttrs = [[NSArray alloc] initWithArray:tempArray];
+ [tempArray release];
+ }
+
+ if (m_object->isPasswordField())
+ return passwordFieldAttrs;
+
+ if (m_object->isWebArea())
+ return webAreaAttrs;
+
+ if (m_object->isTextControl())
+ return textAttrs;
+
+ if (m_object->isAnchor() || m_object->isImage() || m_object->isLink())
+ return anchorAttrs;
+
+ if (m_object->isDataTable())
+ return tableAttrs;
+ if (m_object->isTableRow())
+ return tableRowAttrs;
+ if (m_object->isTableColumn())
+ return tableColAttrs;
+ if (m_object->isTableCell())
+ return tableCellAttrs;
+
+ if (m_object->isListBox() || m_object->isList())
+ return listBoxAttrs;
+
+ if (m_object->isProgressIndicator() || m_object->isSlider())
+ return rangeAttrs;
+
+ if (m_object->isInputImage())
+ return inputImageAttrs;
+
+ if (m_object->isControl())
+ return controlAttrs;
+
+ if (m_object->isGroup())
+ return groupAttrs;
+
+ if (m_object->isMenu())
+ return menuAttrs;
+ if (m_object->isMenuBar())
+ return menuBarAttrs;
+ if (m_object->isMenuButton())
+ return menuButtonAttrs;
+ if (m_object->isMenuItem())
+ return menuItemAttrs;
+
+ return attributes;
+}
+
+- (VisiblePositionRange)visiblePositionRangeForTextMarkerRange:(WebCoreTextMarkerRange*) textMarkerRange
+{
+ return VisiblePositionRange(visiblePositionForStartOfTextMarkerRange(textMarkerRange), visiblePositionForEndOfTextMarkerRange(textMarkerRange));
+}
+
+- (NSArray*)renderWidgetChildren
+{
+ Widget* widget = m_object->widget();
+ if (!widget)
+ return nil;
+ return [(widget->platformWidget()) accessibilityAttributeValue: NSAccessibilityChildrenAttribute];
+}
+
+static void convertToVector(NSArray* array, AccessibilityObject::AccessibilityChildrenVector& vector)
+{
+ unsigned length = [array count];
+ vector.reserveInitialCapacity(length);
+ for (unsigned i = 0; i < length; ++i) {
+ AccessibilityObject* obj = [[array objectAtIndex:i] accessibilityObject];
+ if (obj)
+ vector.append(obj);
+ }
+}
+
+static NSMutableArray* convertToNSArray(const AccessibilityObject::AccessibilityChildrenVector& vector)
+{
+ unsigned length = vector.size();
+ NSMutableArray* array = [NSMutableArray arrayWithCapacity: length];
+ for (unsigned i = 0; i < length; ++i) {
+ AccessibilityObjectWrapper* wrapper = vector[i]->wrapper();
+ ASSERT(wrapper);
+ if (wrapper) {
+ // we want to return the attachment view instead of the object representing the attachment.
+ // otherwise, we get palindrome errors in the AX hierarchy
+ if (vector[i]->isAttachment() && [wrapper attachmentView])
+ [array addObject:[wrapper attachmentView]];
+ else
+ [array addObject:wrapper];
+ }
+ }
+ return array;
+}
+
+- (WebCoreTextMarkerRange*)textMarkerRangeForSelection
+{
+ VisibleSelection selection = m_object->selection();
+ if (selection.isNone())
+ return nil;
+ return textMarkerRangeFromVisiblePositions(selection.visibleStart(), selection.visibleEnd());
+}
+
+- (NSValue*)position
+{
+ IntRect rect = m_object->elementRect();
+
+ // The Cocoa accessibility API wants the lower-left corner.
+ NSPoint point = NSMakePoint(rect.x(), rect.bottom());
+ FrameView* frameView = m_object->documentFrameView();
+ if (frameView) {
+ NSView* view = frameView->documentView();
+ point = [[view window] convertBaseToScreen: [view convertPoint: point toView:nil]];
+ }
+
+ return [NSValue valueWithPoint: point];
+}
+
+typedef HashMap<int, NSString*> AccessibilityRoleMap;
+
+static const AccessibilityRoleMap& createAccessibilityRoleMap()
+{
+ struct RoleEntry {
+ AccessibilityRole value;
+ NSString* string;
+ };
+
+ static const RoleEntry roles[] = {
+ { UnknownRole, NSAccessibilityUnknownRole },
+ { ButtonRole, NSAccessibilityButtonRole },
+ { RadioButtonRole, NSAccessibilityRadioButtonRole },
+ { CheckBoxRole, NSAccessibilityCheckBoxRole },
+ { SliderRole, NSAccessibilitySliderRole },
+ { TabGroupRole, NSAccessibilityTabGroupRole },
+ { TextFieldRole, NSAccessibilityTextFieldRole },
+ { StaticTextRole, NSAccessibilityStaticTextRole },
+ { TextAreaRole, NSAccessibilityTextAreaRole },
+ { ScrollAreaRole, NSAccessibilityScrollAreaRole },
+ { PopUpButtonRole, NSAccessibilityPopUpButtonRole },
+ { MenuButtonRole, NSAccessibilityMenuButtonRole },
+ { TableRole, NSAccessibilityTableRole },
+ { ApplicationRole, NSAccessibilityApplicationRole },
+ { GroupRole, NSAccessibilityGroupRole },
+ { RadioGroupRole, NSAccessibilityRadioGroupRole },
+ { ListRole, NSAccessibilityListRole },
+ { ScrollBarRole, NSAccessibilityScrollBarRole },
+ { ValueIndicatorRole, NSAccessibilityValueIndicatorRole },
+ { ImageRole, NSAccessibilityImageRole },
+ { MenuBarRole, NSAccessibilityMenuBarRole },
+ { MenuRole, NSAccessibilityMenuRole },
+ { MenuItemRole, NSAccessibilityMenuItemRole },
+ { ColumnRole, NSAccessibilityColumnRole },
+ { RowRole, NSAccessibilityRowRole },
+ { ToolbarRole, NSAccessibilityToolbarRole },
+ { BusyIndicatorRole, NSAccessibilityBusyIndicatorRole },
+ { ProgressIndicatorRole, NSAccessibilityProgressIndicatorRole },
+ { WindowRole, NSAccessibilityWindowRole },
+ { DrawerRole, NSAccessibilityDrawerRole },
+ { SystemWideRole, NSAccessibilitySystemWideRole },
+ { OutlineRole, NSAccessibilityOutlineRole },
+ { IncrementorRole, NSAccessibilityIncrementorRole },
+ { BrowserRole, NSAccessibilityBrowserRole },
+ { ComboBoxRole, NSAccessibilityComboBoxRole },
+ { SplitGroupRole, NSAccessibilitySplitGroupRole },
+ { SplitterRole, NSAccessibilitySplitterRole },
+ { ColorWellRole, NSAccessibilityColorWellRole },
+ { GrowAreaRole, NSAccessibilityGrowAreaRole },
+ { SheetRole, NSAccessibilitySheetRole },
+ { HelpTagRole, NSAccessibilityHelpTagRole },
+ { MatteRole, NSAccessibilityMatteRole },
+ { RulerRole, NSAccessibilityRulerRole },
+ { RulerMarkerRole, NSAccessibilityRulerMarkerRole },
+ { LinkRole, NSAccessibilityLinkRole },
+#ifndef BUILDING_ON_TIGER
+ { DisclosureTriangleRole, NSAccessibilityDisclosureTriangleRole },
+ { GridRole, NSAccessibilityGridRole },
+#endif
+ { WebCoreLinkRole, NSAccessibilityLinkRole },
+ { ImageMapLinkRole, NSAccessibilityLinkRole },
+ { ImageMapRole, @"AXImageMap" },
+ { ListMarkerRole, @"AXListMarker" },
+ { WebAreaRole, @"AXWebArea" },
+ { HeadingRole, @"AXHeading" },
+ { ListBoxRole, NSAccessibilityListRole },
+ { ListBoxOptionRole, NSAccessibilityStaticTextRole },
+#if ACCESSIBILITY_TABLES
+ { CellRole, NSAccessibilityCellRole },
+#else
+ { CellRole, NSAccessibilityGroupRole },
+#endif
+ { TableHeaderContainerRole, NSAccessibilityGroupRole },
+ { DefinitionListDefinitionRole, NSAccessibilityGroupRole },
+ { DefinitionListTermRole, NSAccessibilityGroupRole }
+
+ };
+ AccessibilityRoleMap& roleMap = *new AccessibilityRoleMap;
+
+ const unsigned numRoles = sizeof(roles) / sizeof(roles[0]);
+ for (unsigned i = 0; i < numRoles; ++i)
+ roleMap.set(roles[i].value, roles[i].string);
+ return roleMap;
+}
+
+static NSString* roleValueToNSString(AccessibilityRole value)
+{
+ ASSERT(value);
+ static const AccessibilityRoleMap& roleMap = createAccessibilityRoleMap();
+ return roleMap.get(value);
+}
+
+- (NSString*)role
+{
+ if (m_object->isAttachment())
+ return [[self attachmentView] accessibilityAttributeValue:NSAccessibilityRoleAttribute];
+ NSString* string = roleValueToNSString(m_object->roleValue());
+ if (string != nil)
+ return string;
+ return NSAccessibilityUnknownRole;
+}
+
+- (NSString*)subrole
+{
+ if (m_object->isPasswordField())
+ return NSAccessibilitySecureTextFieldSubrole;
+
+ if (m_object->isAttachment()) {
+ NSView* attachView = [self attachmentView];
+ if ([[attachView accessibilityAttributeNames] containsObject:NSAccessibilitySubroleAttribute]) {
+ return [attachView accessibilityAttributeValue:NSAccessibilitySubroleAttribute];
+ }
+ }
+
+ if (m_object->isList()) {
+ AccessibilityList* listObject = static_cast<AccessibilityList*>(m_object);
+ if (listObject->isUnorderedList() || listObject->isOrderedList())
+ return NSAccessibilityContentListSubrole;
+ if (listObject->isDefinitionList())
+ return NSAccessibilityDefinitionListSubrole;
+ }
+
+ return nil;
+}
+
+- (NSString*)roleDescription
+{
+ if (!m_object)
+ return nil;
+
+ // attachments have the AXImage role, but a different subrole
+ if (m_object->isAttachment())
+ return [[self attachmentView] accessibilityAttributeValue:NSAccessibilityRoleDescriptionAttribute];
+
+ // FIXME 3447564: It would be better to call some AppKit API to get these strings
+ // (which would be the best way to localize them)
+
+ NSString* axRole = [self role];
+ if ([axRole isEqualToString:NSAccessibilityButtonRole])
+ return NSAccessibilityRoleDescription(NSAccessibilityButtonRole, [self subrole]);
+
+ if ([axRole isEqualToString:NSAccessibilityPopUpButtonRole])
+ return NSAccessibilityRoleDescription(NSAccessibilityPopUpButtonRole, [self subrole]);
+
+ if ([axRole isEqualToString:NSAccessibilityStaticTextRole])
+ return NSAccessibilityRoleDescription(NSAccessibilityStaticTextRole, [self subrole]);
+
+ if ([axRole isEqualToString:NSAccessibilityImageRole])
+ return NSAccessibilityRoleDescription(NSAccessibilityImageRole, [self subrole]);
+
+ if ([axRole isEqualToString:NSAccessibilityGroupRole])
+ return NSAccessibilityRoleDescription(NSAccessibilityGroupRole, [self subrole]);
+
+ if ([axRole isEqualToString:NSAccessibilityCheckBoxRole])
+ return NSAccessibilityRoleDescription(NSAccessibilityCheckBoxRole, [self subrole]);
+
+ if ([axRole isEqualToString:NSAccessibilityRadioButtonRole])
+ return NSAccessibilityRoleDescription(NSAccessibilityRadioButtonRole, [self subrole]);
+
+ if ([axRole isEqualToString:NSAccessibilityTextFieldRole])
+ return NSAccessibilityRoleDescription(NSAccessibilityTextFieldRole, [self subrole]);
+
+ if ([axRole isEqualToString:NSAccessibilityTextAreaRole])
+ return NSAccessibilityRoleDescription(NSAccessibilityTextAreaRole, [self subrole]);
+
+ if ([axRole isEqualToString:NSAccessibilityListRole])
+ return NSAccessibilityRoleDescription(NSAccessibilityListRole, [self subrole]);
+
+ if ([axRole isEqualToString:NSAccessibilityTableRole])
+ return NSAccessibilityRoleDescription(NSAccessibilityTableRole, [self subrole]);
+
+ if ([axRole isEqualToString:NSAccessibilityRowRole])
+ return NSAccessibilityRoleDescription(NSAccessibilityRowRole, [self subrole]);
+
+ if ([axRole isEqualToString:NSAccessibilityColumnRole])
+ return NSAccessibilityRoleDescription(NSAccessibilityColumnRole, [self subrole]);
+
+ if ([axRole isEqualToString:NSAccessibilityCellRole])
+ return NSAccessibilityRoleDescription(NSAccessibilityCellRole, [self subrole]);
+
+ if ([axRole isEqualToString:@"AXWebArea"])
+ return AXWebAreaText();
+
+ if ([axRole isEqualToString:@"AXLink"])
+ return AXLinkText();
+
+ if ([axRole isEqualToString:@"AXListMarker"])
+ return AXListMarkerText();
+
+ if ([axRole isEqualToString:@"AXImageMap"])
+ return AXImageMapText();
+
+ if ([axRole isEqualToString:@"AXHeading"])
+ return AXHeadingText();
+
+ if ([axRole isEqualToString:(NSString*)kAXMenuBarItemRole] ||
+ [axRole isEqualToString:NSAccessibilityMenuRole])
+ return nil;
+
+ if ([axRole isEqualToString:NSAccessibilityMenuButtonRole])
+ return NSAccessibilityRoleDescription(NSAccessibilityMenuButtonRole, [self subrole]);
+
+ return NSAccessibilityRoleDescription(NSAccessibilityUnknownRole, nil);
+}
+
+// FIXME: split up this function in a better way.
+// suggestions: Use a hash table that maps attribute names to function calls,
+// or maybe pointers to member functions
+- (id)accessibilityAttributeValue:(NSString*)attributeName
+{
+ if (!m_object)
+ return nil;
+
+ m_object->updateBackingStore();
+
+ if ([attributeName isEqualToString: NSAccessibilityRoleAttribute])
+ return [self role];
+
+ if ([attributeName isEqualToString: NSAccessibilitySubroleAttribute])
+ return [self subrole];
+
+ if ([attributeName isEqualToString: NSAccessibilityRoleDescriptionAttribute])
+ return [self roleDescription];
+
+ if ([attributeName isEqualToString: NSAccessibilityParentAttribute]) {
+ if (m_object->isAccessibilityRenderObject()) {
+ FrameView* fv = static_cast<AccessibilityRenderObject*>(m_object)->frameViewIfRenderView();
+ if (fv)
+ return fv->platformWidget();
+ }
+
+ return m_object->parentObjectUnignored()->wrapper();
+ }
+
+ if ([attributeName isEqualToString: NSAccessibilityChildrenAttribute]) {
+ if (m_object->children().isEmpty()) {
+ NSArray* children = [self renderWidgetChildren];
+ if (children != nil)
+ return children;
+ }
+ return convertToNSArray(m_object->children());
+ }
+
+ if ([attributeName isEqualToString: NSAccessibilitySelectedChildrenAttribute]) {
+ if (m_object->isListBox()) {
+ AccessibilityObject::AccessibilityChildrenVector selectedChildrenCopy;
+ m_object->selectedChildren(selectedChildrenCopy);
+ return convertToNSArray(selectedChildrenCopy);
+ }
+ return nil;
+ }
+
+ if ([attributeName isEqualToString: NSAccessibilityVisibleChildrenAttribute]) {
+ if (m_object->isListBox()) {
+ AccessibilityObject::AccessibilityChildrenVector visibleChildrenCopy;
+ m_object->visibleChildren(visibleChildrenCopy);
+ return convertToNSArray(visibleChildrenCopy);
+ }
+ else if (m_object->isList())
+ return [self accessibilityAttributeValue:NSAccessibilityChildrenAttribute];
+
+ return nil;
+ }
+
+
+ if (m_object->isWebArea()) {
+ if ([attributeName isEqualToString: @"AXLinkUIElements"]) {
+ AccessibilityObject::AccessibilityChildrenVector links;
+ static_cast<AccessibilityRenderObject*>(m_object)->getDocumentLinks(links);
+ return convertToNSArray(links);
+ }
+ if ([attributeName isEqualToString: @"AXLoaded"])
+ return [NSNumber numberWithBool: m_object->isLoaded()];
+ if ([attributeName isEqualToString: @"AXLayoutCount"])
+ return [NSNumber numberWithInt: m_object->layoutCount()];
+ }
+
+ if (m_object->isTextControl()) {
+ if ([attributeName isEqualToString: NSAccessibilityNumberOfCharactersAttribute]) {
+ int length = m_object->textLength();
+ if (length < 0)
+ return nil;
+ return [NSNumber numberWithUnsignedInt:length];
+ }
+ if ([attributeName isEqualToString: NSAccessibilitySelectedTextAttribute]) {
+ String selectedText = m_object->selectedText();
+ if (selectedText.isNull())
+ return nil;
+ return (NSString*)selectedText;
+ }
+ if ([attributeName isEqualToString: NSAccessibilitySelectedTextRangeAttribute]) {
+ PlainTextRange textRange = m_object->selectedTextRange();
+ if (textRange.isNull())
+ return nil;
+ return [NSValue valueWithRange:NSMakeRange(textRange.start, textRange.length)];
+ }
+ // TODO: Get actual visible range. <rdar://problem/4712101>
+ if ([attributeName isEqualToString: NSAccessibilityVisibleCharacterRangeAttribute])
+ return m_object->isPasswordField() ? nil : [NSValue valueWithRange: NSMakeRange(0, m_object->textLength())];
+ if ([attributeName isEqualToString: NSAccessibilityInsertionPointLineNumberAttribute]) {
+ // if selectionEnd > 0, then there is selected text and this question should not be answered
+ if (m_object->isPasswordField() || m_object->selectionEnd() > 0)
+ return nil;
+ int lineNumber = m_object->lineForPosition(m_object->visiblePositionForIndex(m_object->selectionStart(), true));
+ if (lineNumber < 0)
+ return nil;
+ return [NSNumber numberWithInt:lineNumber];
+ }
+ }
+
+ if ([attributeName isEqualToString: NSAccessibilityURLAttribute]) {
+ KURL url = m_object->url();
+ if (url.isNull())
+ return nil;
+ return (NSURL*)url;
+ }
+
+ if ([attributeName isEqualToString: @"AXVisited"])
+ return [NSNumber numberWithBool: m_object->isVisited()];
+
+ if ([attributeName isEqualToString: NSAccessibilityTitleAttribute]) {
+ if (m_object->isAttachment()) {
+ if ([[[self attachmentView] accessibilityAttributeNames] containsObject:NSAccessibilityTitleAttribute])
+ return [[self attachmentView] accessibilityAttributeValue:NSAccessibilityTitleAttribute];
+ }
+ return m_object->title();
+ }
+
+ if ([attributeName isEqualToString: NSAccessibilityDescriptionAttribute]) {
+ if (m_object->isAttachment()) {
+ if ([[[self attachmentView] accessibilityAttributeNames] containsObject:NSAccessibilityDescriptionAttribute])
+ return [[self attachmentView] accessibilityAttributeValue:NSAccessibilityDescriptionAttribute];
+ }
+ return m_object->accessibilityDescription();
+ }
+
+ if ([attributeName isEqualToString: NSAccessibilityValueAttribute]) {
+ if (m_object->isAttachment()) {
+ if ([[[self attachmentView] accessibilityAttributeNames] containsObject:NSAccessibilityValueAttribute])
+ return [[self attachmentView] accessibilityAttributeValue:NSAccessibilityValueAttribute];
+ }
+ if (m_object->isProgressIndicator() || m_object->isSlider())
+ return [NSNumber numberWithFloat:m_object->valueForRange()];
+ if (m_object->hasIntValue())
+ return [NSNumber numberWithInt:m_object->intValue()];
+ return m_object->stringValue();
+ }
+
+ if ([attributeName isEqualToString: NSAccessibilityMinValueAttribute])
+ return [NSNumber numberWithFloat:m_object->minValueForRange()];
+
+ if ([attributeName isEqualToString: NSAccessibilityMaxValueAttribute])
+ return [NSNumber numberWithFloat:m_object->maxValueForRange()];
+
+ if ([attributeName isEqualToString: NSAccessibilityHelpAttribute])
+ return m_object->helpText();
+
+ if ([attributeName isEqualToString: NSAccessibilityFocusedAttribute])
+ return [NSNumber numberWithBool: m_object->isFocused()];
+
+ if ([attributeName isEqualToString: NSAccessibilityEnabledAttribute])
+ return [NSNumber numberWithBool: m_object->isEnabled()];
+
+ if ([attributeName isEqualToString: NSAccessibilitySizeAttribute]) {
+ IntSize s = m_object->size();
+ return [NSValue valueWithSize: NSMakeSize(s.width(), s.height())];
+ }
+
+ if ([attributeName isEqualToString: NSAccessibilityPositionAttribute])
+ return [self position];
+
+ if ([attributeName isEqualToString: NSAccessibilityWindowAttribute] ||
+ [attributeName isEqualToString: NSAccessibilityTopLevelUIElementAttribute]) {
+ FrameView* fv = m_object->documentFrameView();
+ if (fv)
+ return [fv->platformWidget() window];
+ return nil;
+ }
+
+ if ([attributeName isEqualToString:NSAccessibilityAccessKeyAttribute]) {
+ AtomicString accessKey = m_object->accessKey();
+ if (accessKey.isNull())
+ return nil;
+ return accessKey;
+ }
+
+ if (m_object->isDataTable()) {
+ // TODO: distinguish between visible and non-visible rows
+ if ([attributeName isEqualToString:NSAccessibilityRowsAttribute] ||
+ [attributeName isEqualToString:NSAccessibilityVisibleRowsAttribute]) {
+ return convertToNSArray(static_cast<AccessibilityTable*>(m_object)->rows());
+ }
+ // TODO: distinguish between visible and non-visible columns
+ if ([attributeName isEqualToString:NSAccessibilityColumnsAttribute] ||
+ [attributeName isEqualToString:NSAccessibilityVisibleColumnsAttribute]) {
+ return convertToNSArray(static_cast<AccessibilityTable*>(m_object)->columns());
+ }
+
+ // HTML tables don't support these
+ if ([attributeName isEqualToString:NSAccessibilitySelectedColumnsAttribute] ||
+ [attributeName isEqualToString:NSAccessibilitySelectedRowsAttribute] ||
+ [attributeName isEqualToString:NSAccessibilitySelectedCellsAttribute])
+ return nil;
+
+ if ([attributeName isEqualToString:(NSString *)kAXColumnHeaderUIElementsAttribute]) {
+ AccessibilityObject::AccessibilityChildrenVector columnHeaders;
+ static_cast<AccessibilityTable*>(m_object)->columnHeaders(columnHeaders);
+ return convertToNSArray(columnHeaders);
+ }
+
+ if ([attributeName isEqualToString:NSAccessibilityHeaderAttribute]) {
+ AccessibilityObject* headerContainer = static_cast<AccessibilityTable*>(m_object)->headerContainer();
+ if (headerContainer)
+ return headerContainer->wrapper();
+ return nil;
+ }
+
+ if ([attributeName isEqualToString:NSAccessibilityRowHeaderUIElementsAttribute]) {
+ AccessibilityObject::AccessibilityChildrenVector rowHeaders;
+ static_cast<AccessibilityTable*>(m_object)->rowHeaders(rowHeaders);
+ return convertToNSArray(rowHeaders);
+ }
+
+ if ([attributeName isEqualToString:NSAccessibilityVisibleCellsAttribute]) {
+ AccessibilityObject::AccessibilityChildrenVector cells;
+ static_cast<AccessibilityTable*>(m_object)->cells(cells);
+ return convertToNSArray(cells);
+ }
+ }
+
+ if (m_object->isTableRow()) {
+ if ([attributeName isEqualToString:NSAccessibilityIndexAttribute])
+ return [NSNumber numberWithInt:static_cast<AccessibilityTableRow*>(m_object)->rowIndex()];
+ }
+
+ if (m_object->isTableColumn()) {
+ if ([attributeName isEqualToString:NSAccessibilityIndexAttribute])
+ return [NSNumber numberWithInt:static_cast<AccessibilityTableColumn*>(m_object)->columnIndex()];
+
+ // rows attribute for a column is the list of all the elements in that column at each row
+ if ([attributeName isEqualToString:NSAccessibilityRowsAttribute] ||
+ [attributeName isEqualToString:NSAccessibilityVisibleRowsAttribute]) {
+ return convertToNSArray(static_cast<AccessibilityTableColumn*>(m_object)->children());
+ }
+ if ([attributeName isEqualToString:NSAccessibilityHeaderAttribute]) {
+ AccessibilityObject* header = static_cast<AccessibilityTableColumn*>(m_object)->headerObject();
+ if (!header)
+ return nil;
+ return header->wrapper();
+ }
+ }
+
+ if (m_object->isTableCell()) {
+ if ([attributeName isEqualToString:NSAccessibilityRowIndexRangeAttribute]) {
+ pair<int, int> rowRange;
+ static_cast<AccessibilityTableCell*>(m_object)->rowIndexRange(rowRange);
+ return [NSValue valueWithRange:NSMakeRange(rowRange.first, rowRange.second)];
+ }
+ if ([attributeName isEqualToString:NSAccessibilityColumnIndexRangeAttribute]) {
+ pair<int, int> columnRange;
+ static_cast<AccessibilityTableCell*>(m_object)->columnIndexRange(columnRange);
+ return [NSValue valueWithRange:NSMakeRange(columnRange.first, columnRange.second)];
+ }
+ }
+
+ if ((m_object->isListBox() ||m_object->isList()) && [attributeName isEqualToString:NSAccessibilityOrientationAttribute])
+ return NSAccessibilityVerticalOrientationValue;
+
+ if ([attributeName isEqualToString: @"AXSelectedTextMarkerRange"])
+ return [self textMarkerRangeForSelection];
+
+ if (m_object->isAccessibilityRenderObject()) {
+ RenderObject* renderer = static_cast<AccessibilityRenderObject*>(m_object)->renderer();
+ if (!renderer)
+ return nil;
+
+ if ([attributeName isEqualToString: @"AXStartTextMarker"])
+ return textMarkerForVisiblePosition(startOfDocument(renderer->document()));
+ if ([attributeName isEqualToString: @"AXEndTextMarker"])
+ return textMarkerForVisiblePosition(endOfDocument(renderer->document()));
+
+ if ([attributeName isEqualToString:NSAccessibilityBlockQuoteLevelAttribute])
+ return [NSNumber numberWithInt:blockquoteLevel(renderer)];
+ } else {
+ if ([attributeName isEqualToString:NSAccessibilityBlockQuoteLevelAttribute]) {
+ AccessibilityObject* parent = m_object->parentObjectUnignored();
+ if (!parent)
+ return [NSNumber numberWithInt:0];
+ return [parent->wrapper() accessibilityAttributeValue:NSAccessibilityBlockQuoteLevelAttribute];
+ }
+ }
+
+ if ([attributeName isEqualToString: NSAccessibilityLinkedUIElementsAttribute]) {
+ AccessibilityObject::AccessibilityChildrenVector linkedUIElements;
+ m_object->linkedUIElements(linkedUIElements);
+ if (linkedUIElements.size() == 0)
+ return nil;
+ return convertToNSArray(linkedUIElements);
+ }
+
+ if ([attributeName isEqualToString: NSAccessibilitySelectedAttribute])
+ return [NSNumber numberWithBool:m_object->isSelected()];
+
+ if ([attributeName isEqualToString: NSAccessibilityServesAsTitleForUIElementsAttribute] && m_object->isMenuButton()) {
+ AccessibilityObject* uiElement = static_cast<AccessibilityRenderObject*>(m_object)->menuForMenuButton();
+ if (uiElement)
+ return [NSArray arrayWithObject:uiElement->wrapper()];
+ }
+
+ if ([attributeName isEqualToString:NSAccessibilityTitleUIElementAttribute]) {
+ AccessibilityObject* obj = m_object->titleUIElement();
+ if (obj)
+ return obj->wrapper();
+ return nil;
+ }
+
+ return nil;
+}
+
+- (id)accessibilityFocusedUIElement
+{
+ if (!m_object)
+ return nil;
+
+ m_object->updateBackingStore();
+
+ RefPtr<AccessibilityObject> focusedObj = m_object->focusedUIElement();
+
+ if (!focusedObj)
+ return nil;
+
+ return focusedObj->wrapper();
+}
+
+- (id)accessibilityHitTest:(NSPoint)point
+{
+ if (!m_object)
+ return nil;
+
+ m_object->updateBackingStore();
+
+ RefPtr<AccessibilityObject> axObject = m_object->doAccessibilityHitTest(IntPoint(point));
+ if (axObject)
+ return NSAccessibilityUnignoredAncestor(axObject->wrapper());
+ return NSAccessibilityUnignoredAncestor(self);
+}
+
+- (BOOL)accessibilityIsAttributeSettable:(NSString*)attributeName
+{
+ if (!m_object)
+ return nil;
+
+ m_object->updateBackingStore();
+
+ if ([attributeName isEqualToString: @"AXSelectedTextMarkerRange"])
+ return YES;
+
+ if ([attributeName isEqualToString: NSAccessibilityFocusedAttribute])
+ return m_object->canSetFocusAttribute();
+
+ if ([attributeName isEqualToString: NSAccessibilityValueAttribute])
+ return m_object->canSetValueAttribute();
+
+ if ([attributeName isEqualToString: NSAccessibilitySelectedAttribute])
+ return m_object->canSetSelectedAttribute();
+
+ if ([attributeName isEqualToString: NSAccessibilitySelectedChildrenAttribute])
+ return m_object->canSetSelectedChildrenAttribute();
+
+ if ([attributeName isEqualToString: NSAccessibilitySelectedTextAttribute] ||
+ [attributeName isEqualToString: NSAccessibilitySelectedTextRangeAttribute] ||
+ [attributeName isEqualToString: NSAccessibilityVisibleCharacterRangeAttribute])
+ return m_object->canSetTextRangeAttributes();
+
+ return NO;
+}
+
+// accessibilityShouldUseUniqueId is an AppKit method we override so that
+// objects will be given a unique ID, and therefore allow AppKit to know when they
+// become obsolete (e.g. when the user navigates to a new web page, making this one
+// unrendered but not deallocated because it is in the back/forward cache).
+// It is important to call NSAccessibilityUnregisterUniqueIdForUIElement in the
+// appropriate place (e.g. dealloc) to remove these non-retained references from
+// AppKit's id mapping tables. We do this in detach by calling unregisterUniqueIdForUIElement.
+//
+// Registering an object is also required for observing notifications. Only registered objects can be observed.
+- (BOOL)accessibilityIsIgnored
+{
+ if (!m_object)
+ return nil;
+
+ m_object->updateBackingStore();
+
+ if (m_object->isAttachment())
+ return [[self attachmentView] accessibilityIsIgnored];
+ return m_object->accessibilityIsIgnored();
+}
+
+- (NSArray* )accessibilityParameterizedAttributeNames
+{
+ if (!m_object)
+ return nil;
+
+ m_object->updateBackingStore();
+
+ if (m_object->isAttachment())
+ return nil;
+
+ static NSArray* paramAttrs = nil;
+ static NSArray* textParamAttrs = nil;
+ static NSArray* tableParamAttrs = nil;
+ if (paramAttrs == nil) {
+ paramAttrs = [[NSArray alloc] initWithObjects:
+ @"AXUIElementForTextMarker",
+ @"AXTextMarkerRangeForUIElement",
+ @"AXLineForTextMarker",
+ @"AXTextMarkerRangeForLine",
+ @"AXStringForTextMarkerRange",
+ @"AXTextMarkerForPosition",
+ @"AXBoundsForTextMarkerRange",
+ @"AXAttributedStringForTextMarkerRange",
+ @"AXTextMarkerRangeForUnorderedTextMarkers",
+ @"AXNextTextMarkerForTextMarker",
+ @"AXPreviousTextMarkerForTextMarker",
+ @"AXLeftWordTextMarkerRangeForTextMarker",
+ @"AXRightWordTextMarkerRangeForTextMarker",
+ @"AXLeftLineTextMarkerRangeForTextMarker",
+ @"AXRightLineTextMarkerRangeForTextMarker",
+ @"AXSentenceTextMarkerRangeForTextMarker",
+ @"AXParagraphTextMarkerRangeForTextMarker",
+ @"AXNextWordEndTextMarkerForTextMarker",
+ @"AXPreviousWordStartTextMarkerForTextMarker",
+ @"AXNextLineEndTextMarkerForTextMarker",
+ @"AXPreviousLineStartTextMarkerForTextMarker",
+ @"AXNextSentenceEndTextMarkerForTextMarker",
+ @"AXPreviousSentenceStartTextMarkerForTextMarker",
+ @"AXNextParagraphEndTextMarkerForTextMarker",
+ @"AXPreviousParagraphStartTextMarkerForTextMarker",
+ @"AXStyleTextMarkerRangeForTextMarker",
+ @"AXLengthForTextMarkerRange",
+ NSAccessibilityBoundsForRangeParameterizedAttribute,
+ nil];
+ }
+
+ if (textParamAttrs == nil) {
+ NSMutableArray* tempArray = [[NSMutableArray alloc] initWithArray:paramAttrs];
+ [tempArray addObject:(NSString*)kAXLineForIndexParameterizedAttribute];
+ [tempArray addObject:(NSString*)kAXRangeForLineParameterizedAttribute];
+ [tempArray addObject:(NSString*)kAXStringForRangeParameterizedAttribute];
+ [tempArray addObject:(NSString*)kAXRangeForPositionParameterizedAttribute];
+ [tempArray addObject:(NSString*)kAXRangeForIndexParameterizedAttribute];
+ [tempArray addObject:(NSString*)kAXBoundsForRangeParameterizedAttribute];
+ [tempArray addObject:(NSString*)kAXRTFForRangeParameterizedAttribute];
+ [tempArray addObject:(NSString*)kAXAttributedStringForRangeParameterizedAttribute];
+ [tempArray addObject:(NSString*)kAXStyleRangeForIndexParameterizedAttribute];
+ textParamAttrs = [[NSArray alloc] initWithArray:tempArray];
+ [tempArray release];
+ }
+ if (tableParamAttrs == nil) {
+ NSMutableArray* tempArray = [[NSMutableArray alloc] initWithArray:paramAttrs];
+ [tempArray addObject:NSAccessibilityCellForColumnAndRowParameterizedAttribute];
+ tableParamAttrs = [[NSArray alloc] initWithArray:tempArray];
+ [tempArray release];
+ }
+
+ if (m_object->isPasswordField())
+ return [NSArray array];
+
+ if (!m_object->isAccessibilityRenderObject())
+ return paramAttrs;
+
+ if (m_object->isTextControl())
+ return textParamAttrs;
+
+ if (m_object->isDataTable())
+ return tableParamAttrs;
+
+ if (m_object->isMenuRelated())
+ return nil;
+
+ return paramAttrs;
+}
+
+- (void)accessibilityPerformPressAction
+{
+ if (!m_object)
+ return;
+
+ m_object->updateBackingStore();
+
+ if (m_object->isAttachment())
+ [[self attachmentView] accessibilityPerformAction:NSAccessibilityPressAction];
+
+ m_object->press();
+}
+
+- (void)accessibilityPerformShowMenuAction
+{
+ // This needs to be performed in an iteration of the run loop that did not start from an AX call.
+ // If it's the same run loop iteration, the menu open notification won't be sent
+ [self performSelector:@selector(accessibilityShowContextMenu) withObject:nil afterDelay:0.0];
+}
+
+- (void)accessibilityShowContextMenu
+{
+ FrameView* frameView = m_object->documentFrameView();
+ if (!frameView)
+ return;
+
+ // simulate a click in the middle of the object
+ IntPoint clickPoint = m_object->clickPoint();
+ NSPoint nsClickPoint = NSMakePoint(clickPoint.x(), clickPoint.y());
+
+ NSView* view = nil;
+ if (m_object->isAttachment())
+ view = [self attachmentView];
+ else
+ view = frameView->documentView();
+
+ if (!view)
+ return;
+
+ NSPoint nsScreenPoint = [view convertPoint:nsClickPoint toView:nil];
+
+ // Show the contextual menu for this event.
+ NSEvent* event = [NSEvent mouseEventWithType:NSRightMouseDown location:nsScreenPoint modifierFlags:0 timestamp:0 windowNumber:[[view window] windowNumber] context:0 eventNumber:0 clickCount:1 pressure:1];
+ NSMenu* menu = [view menuForEvent:event];
+
+ if (menu)
+ [NSMenu popUpContextMenu:menu withEvent:event forView:view];
+}
+
+- (void)accessibilityPerformAction:(NSString*)action
+{
+ if (!m_object)
+ return;
+
+ m_object->updateBackingStore();
+
+ if ([action isEqualToString:NSAccessibilityPressAction])
+ [self accessibilityPerformPressAction];
+
+ else if ([action isEqualToString:NSAccessibilityShowMenuAction])
+ [self accessibilityPerformShowMenuAction];
+}
+
+- (void)accessibilitySetValue:(id)value forAttribute:(NSString*)attributeName
+{
+ if (!m_object)
+ return;
+
+ m_object->updateBackingStore();
+
+ WebCoreTextMarkerRange* textMarkerRange = nil;
+ NSNumber* number = nil;
+ NSString* string = nil;
+ NSRange range = {0, 0};
+ NSArray* array = nil;
+
+ // decode the parameter
+ if ([[WebCoreViewFactory sharedFactory] objectIsTextMarkerRange:value])
+ textMarkerRange = (WebCoreTextMarkerRange*) value;
+
+ else if ([value isKindOfClass:[NSNumber self]])
+ number = value;
+
+ else if ([value isKindOfClass:[NSString self]])
+ string = value;
+
+ else if ([value isKindOfClass:[NSValue self]])
+ range = [value rangeValue];
+
+ else if ([value isKindOfClass:[NSArray self]])
+ array = value;
+
+ // handle the command
+ if ([attributeName isEqualToString: @"AXSelectedTextMarkerRange"]) {
+ ASSERT(textMarkerRange);
+ m_object->setSelectedVisiblePositionRange([self visiblePositionRangeForTextMarkerRange:textMarkerRange]);
+ } else if ([attributeName isEqualToString: NSAccessibilityFocusedAttribute]) {
+ ASSERT(number);
+ m_object->setFocused([number intValue] != 0);
+ } else if ([attributeName isEqualToString: NSAccessibilityValueAttribute]) {
+ if (!string)
+ return;
+ m_object->setValue(string);
+ } else if ([attributeName isEqualToString: NSAccessibilitySelectedAttribute]) {
+ if (!number)
+ return;
+ m_object->setSelected([number boolValue]);
+ } else if ([attributeName isEqualToString: NSAccessibilitySelectedChildrenAttribute]) {
+ if (!array || m_object->roleValue() != ListBoxRole)
+ return;
+ AccessibilityObject::AccessibilityChildrenVector selectedChildren;
+ convertToVector(array, selectedChildren);
+ static_cast<AccessibilityListBox*>(m_object)->setSelectedChildren(selectedChildren);
+ } else if (m_object->isTextControl()) {
+ if ([attributeName isEqualToString: NSAccessibilitySelectedTextAttribute]) {
+ m_object->setSelectedText(string);
+ } else if ([attributeName isEqualToString: NSAccessibilitySelectedTextRangeAttribute]) {
+ m_object->setSelectedTextRange(PlainTextRange(range.location, range.length));
+ } else if ([attributeName isEqualToString: NSAccessibilityVisibleCharacterRangeAttribute]) {
+ m_object->makeRangeVisible(PlainTextRange(range.location, range.length));
+ }
+ }
+}
+
+static RenderObject* rendererForView(NSView* view)
+{
+ if (![view conformsToProtocol:@protocol(WebCoreFrameView)])
+ return 0;
+
+ NSView<WebCoreFrameView>* frameView = (NSView<WebCoreFrameView>*)view;
+ Frame* frame = [frameView _web_frame];
+ if (!frame)
+ return 0;
+
+ Node* node = frame->document()->ownerElement();
+ if (!node)
+ return 0;
+
+ return node->renderer();
+}
+
+- (id)_accessibilityParentForSubview:(NSView*)subview
+{
+ RenderObject* renderer = rendererForView(subview);
+ if (!renderer)
+ return nil;
+
+ AccessibilityObject* obj = renderer->document()->axObjectCache()->getOrCreate(renderer);
+ if (obj)
+ return obj->parentObjectUnignored()->wrapper();
+ return nil;
+}
+
+- (NSString*)accessibilityActionDescription:(NSString*)action
+{
+ // we have no custom actions
+ return NSAccessibilityActionDescription(action);
+}
+
+// The CFAttributedStringType representation of the text associated with this accessibility
+// object that is specified by the given range.
+- (NSAttributedString*)doAXAttributedStringForRange:(NSRange)range
+{
+ PlainTextRange textRange = PlainTextRange(range.location, range.length);
+ VisiblePositionRange visiblePosRange = m_object->visiblePositionRangeForRange(textRange);
+ return [self doAXAttributedStringForTextMarkerRange:textMarkerRangeFromVisiblePositions(visiblePosRange.start, visiblePosRange.end)];
+}
+
+// The RTF representation of the text associated with this accessibility object that is
+// specified by the given range.
+- (NSData*)doAXRTFForRange:(NSRange)range
+{
+ NSAttributedString* attrString = [self doAXAttributedStringForRange:range];
+ return [attrString RTFFromRange: NSMakeRange(0, [attrString length]) documentAttributes: nil];
+}
+
+- (id)accessibilityAttributeValue:(NSString*)attribute forParameter:(id)parameter
+{
+ WebCoreTextMarker* textMarker = nil;
+ WebCoreTextMarkerRange* textMarkerRange = nil;
+ NSNumber* number = nil;
+ NSArray* array = nil;
+ RefPtr<AccessibilityObject> uiElement = 0;
+ NSPoint point = NSZeroPoint;
+ bool pointSet = false;
+ NSRange range = {0, 0};
+ bool rangeSet = false;
+
+ // basic parameter validation
+ if (!m_object || !attribute || !parameter)
+ return nil;
+
+ m_object->updateBackingStore();
+
+ // common parameter type check/casting. Nil checks in handlers catch wrong type case.
+ // NOTE: This assumes nil is not a valid parameter, because it is indistinguishable from
+ // a parameter of the wrong type.
+ if ([[WebCoreViewFactory sharedFactory] objectIsTextMarker:parameter])
+ textMarker = (WebCoreTextMarker*) parameter;
+
+ else if ([[WebCoreViewFactory sharedFactory] objectIsTextMarkerRange:parameter])
+ textMarkerRange = (WebCoreTextMarkerRange*) parameter;
+
+ else if ([parameter isKindOfClass:[AccessibilityObjectWrapper self]])
+ uiElement = [(AccessibilityObjectWrapper*)parameter accessibilityObject];
+
+ else if ([parameter isKindOfClass:[NSNumber self]])
+ number = parameter;
+
+ else if ([parameter isKindOfClass:[NSArray self]])
+ array = parameter;
+
+ else if ([parameter isKindOfClass:[NSValue self]] && strcmp([(NSValue*)parameter objCType], @encode(NSPoint)) == 0) {
+ pointSet = true;
+ point = [(NSValue*)parameter pointValue];
+
+ } else if ([parameter isKindOfClass:[NSValue self]] && strcmp([(NSValue*)parameter objCType], @encode(NSRange)) == 0) {
+ rangeSet = true;
+ range = [(NSValue*)parameter rangeValue];
+
+ } else {
+ // got a parameter of a type we never use
+ // NOTE: No ASSERT_NOT_REACHED because this can happen accidentally
+ // while using accesstool (e.g.), forcing you to start over
+ return nil;
+ }
+
+ // Convert values to WebCore types
+ // FIXME: prepping all of these values as WebCore types is unnecessary in many
+ // cases. Re-organization of this function or performing the conversion on a
+ // need basis are possible improvements.
+ VisiblePosition visiblePos;
+ if (textMarker)
+ visiblePos = visiblePositionForTextMarker(textMarker);
+ int intNumber = [number intValue];
+ VisiblePositionRange visiblePosRange;
+ if (textMarkerRange)
+ visiblePosRange = [self visiblePositionRangeForTextMarkerRange:textMarkerRange];
+ IntPoint webCorePoint = IntPoint(point);
+ PlainTextRange plainTextRange = PlainTextRange(range.location, range.length);
+
+ // dispatch
+ if ([attribute isEqualToString: @"AXUIElementForTextMarker"])
+ return m_object->accessibilityObjectForPosition(visiblePos)->wrapper();
+
+ if ([attribute isEqualToString: @"AXTextMarkerRangeForUIElement"]) {
+ VisiblePositionRange vpRange = uiElement.get()->visiblePositionRange();
+ return (id)textMarkerRangeFromVisiblePositions(vpRange.start, vpRange.end);
+ }
+
+ if ([attribute isEqualToString: @"AXLineForTextMarker"])
+ return [NSNumber numberWithUnsignedInt:m_object->lineForPosition(visiblePos)];
+
+ if ([attribute isEqualToString: @"AXTextMarkerRangeForLine"]) {
+ VisiblePositionRange vpRange = m_object->visiblePositionRangeForLine(intNumber);
+ return (id)textMarkerRangeFromVisiblePositions(vpRange.start, vpRange.end);
+ }
+
+ if ([attribute isEqualToString: @"AXStringForTextMarkerRange"])
+ return m_object->stringForVisiblePositionRange(visiblePosRange);
+
+ if ([attribute isEqualToString: @"AXTextMarkerForPosition"])
+ return pointSet ? textMarkerForVisiblePosition(m_object->visiblePositionForPoint(webCorePoint)) : nil;
+
+ if ([attribute isEqualToString: @"AXBoundsForTextMarkerRange"]) {
+ NSRect rect = m_object->boundsForVisiblePositionRange(visiblePosRange);
+ return [NSValue valueWithRect:rect];
+ }
+
+ if ([attribute isEqualToString:NSAccessibilityBoundsForRangeParameterizedAttribute]) {
+ VisiblePosition start = m_object->visiblePositionForIndex(range.location);
+ VisiblePosition end = m_object->visiblePositionForIndex(range.location+range.length);
+ if (start.isNull() || end.isNull())
+ return nil;
+ NSRect rect = m_object->boundsForVisiblePositionRange(VisiblePositionRange(start, end));
+ return [NSValue valueWithRect:rect];
+ }
+
+ if ([attribute isEqualToString: @"AXAttributedStringForTextMarkerRange"])
+ return [self doAXAttributedStringForTextMarkerRange:textMarkerRange];
+
+ if ([attribute isEqualToString: @"AXTextMarkerRangeForUnorderedTextMarkers"]) {
+ if ([array count] < 2)
+ return nil;
+
+ WebCoreTextMarker* textMarker1 = (WebCoreTextMarker*) [array objectAtIndex:0];
+ WebCoreTextMarker* textMarker2 = (WebCoreTextMarker*) [array objectAtIndex:1];
+ if (![[WebCoreViewFactory sharedFactory] objectIsTextMarker:textMarker1]
+ || ![[WebCoreViewFactory sharedFactory] objectIsTextMarker:textMarker2])
+ return nil;
+
+ VisiblePosition visiblePos1 = visiblePositionForTextMarker(textMarker1);
+ VisiblePosition visiblePos2 = visiblePositionForTextMarker(textMarker2);
+ VisiblePositionRange vpRange = m_object->visiblePositionRangeForUnorderedPositions(visiblePos1, visiblePos2);
+ return (id)textMarkerRangeFromVisiblePositions(vpRange.start, vpRange.end);
+ }
+
+ if ([attribute isEqualToString: @"AXNextTextMarkerForTextMarker"])
+ return textMarkerForVisiblePosition(m_object->nextVisiblePosition(visiblePos));
+
+ if ([attribute isEqualToString: @"AXPreviousTextMarkerForTextMarker"])
+ return textMarkerForVisiblePosition(m_object->previousVisiblePosition(visiblePos));
+
+ if ([attribute isEqualToString: @"AXLeftWordTextMarkerRangeForTextMarker"]) {
+ VisiblePositionRange vpRange = m_object->positionOfLeftWord(visiblePos);
+ return (id)textMarkerRangeFromVisiblePositions(vpRange.start, vpRange.end);
+ }
+
+ if ([attribute isEqualToString: @"AXRightWordTextMarkerRangeForTextMarker"]) {
+ VisiblePositionRange vpRange = m_object->positionOfRightWord(visiblePos);
+ return (id)textMarkerRangeFromVisiblePositions(vpRange.start, vpRange.end);
+ }
+
+ if ([attribute isEqualToString: @"AXLeftLineTextMarkerRangeForTextMarker"]) {
+ VisiblePositionRange vpRange = m_object->leftLineVisiblePositionRange(visiblePos);
+ return (id)textMarkerRangeFromVisiblePositions(vpRange.start, vpRange.end);
+ }
+
+ if ([attribute isEqualToString: @"AXRightLineTextMarkerRangeForTextMarker"]) {
+ VisiblePositionRange vpRange = m_object->rightLineVisiblePositionRange(visiblePos);
+ return (id)textMarkerRangeFromVisiblePositions(vpRange.start, vpRange.end);
+ }
+
+ if ([attribute isEqualToString: @"AXSentenceTextMarkerRangeForTextMarker"]) {
+ VisiblePositionRange vpRange = m_object->sentenceForPosition(visiblePos);
+ return (id)textMarkerRangeFromVisiblePositions(vpRange.start, vpRange.end);
+ }
+
+ if ([attribute isEqualToString: @"AXParagraphTextMarkerRangeForTextMarker"]) {
+ VisiblePositionRange vpRange = m_object->paragraphForPosition(visiblePos);
+ return (id)textMarkerRangeFromVisiblePositions(vpRange.start, vpRange.end);
+ }
+
+ if ([attribute isEqualToString: @"AXNextWordEndTextMarkerForTextMarker"])
+ return textMarkerForVisiblePosition(m_object->nextWordEnd(visiblePos));
+
+ if ([attribute isEqualToString: @"AXPreviousWordStartTextMarkerForTextMarker"])
+ return textMarkerForVisiblePosition(m_object->previousWordStart(visiblePos));
+
+ if ([attribute isEqualToString: @"AXNextLineEndTextMarkerForTextMarker"])
+ return textMarkerForVisiblePosition(m_object->nextLineEndPosition(visiblePos));
+
+ if ([attribute isEqualToString: @"AXPreviousLineStartTextMarkerForTextMarker"])
+ return textMarkerForVisiblePosition(m_object->previousLineStartPosition(visiblePos));
+
+ if ([attribute isEqualToString: @"AXNextSentenceEndTextMarkerForTextMarker"])
+ return textMarkerForVisiblePosition(m_object->nextSentenceEndPosition(visiblePos));
+
+ if ([attribute isEqualToString: @"AXPreviousSentenceStartTextMarkerForTextMarker"])
+ return textMarkerForVisiblePosition(m_object->previousSentenceStartPosition(visiblePos));
+
+ if ([attribute isEqualToString: @"AXNextParagraphEndTextMarkerForTextMarker"])
+ return textMarkerForVisiblePosition(m_object->nextParagraphEndPosition(visiblePos));
+
+ if ([attribute isEqualToString: @"AXPreviousParagraphStartTextMarkerForTextMarker"])
+ return textMarkerForVisiblePosition(m_object->previousParagraphStartPosition(visiblePos));
+
+ if ([attribute isEqualToString: @"AXStyleTextMarkerRangeForTextMarker"]) {
+ VisiblePositionRange vpRange = m_object->styleRangeForPosition(visiblePos);
+ return (id)textMarkerRangeFromVisiblePositions(vpRange.start, vpRange.end);
+ }
+
+ if ([attribute isEqualToString: @"AXLengthForTextMarkerRange"]) {
+ int length = m_object->lengthForVisiblePositionRange(visiblePosRange);
+ if (length < 0)
+ return nil;
+ return [NSNumber numberWithInt:length];
+ }
+
+ if (m_object->isDataTable()) {
+ if ([attribute isEqualToString:NSAccessibilityCellForColumnAndRowParameterizedAttribute]) {
+ if (array == nil || [array count] != 2)
+ return nil;
+ AccessibilityTableCell* cell = static_cast<AccessibilityTable*>(m_object)->cellForColumnAndRow([[array objectAtIndex:0] unsignedIntValue], [[array objectAtIndex:1] unsignedIntValue]);
+ if (!cell)
+ return nil;
+
+ return cell->wrapper();
+ }
+ }
+
+ if (m_object->isTextControl()) {
+ if ([attribute isEqualToString: (NSString *)kAXLineForIndexParameterizedAttribute]) {
+ int lineNumber = m_object->doAXLineForIndex(intNumber);
+ if (lineNumber < 0)
+ return nil;
+ return [NSNumber numberWithUnsignedInt:lineNumber];
+ }
+
+ if ([attribute isEqualToString: (NSString *)kAXRangeForLineParameterizedAttribute]) {
+ PlainTextRange textRange = m_object->doAXRangeForLine(intNumber);
+ return [NSValue valueWithRange: NSMakeRange(textRange.start, textRange.length)];
+ }
+
+ if ([attribute isEqualToString: (NSString*)kAXStringForRangeParameterizedAttribute])
+ return rangeSet ? (id)(m_object->doAXStringForRange(plainTextRange)) : nil;
+
+ if ([attribute isEqualToString: (NSString*)kAXRangeForPositionParameterizedAttribute]) {
+ if (!pointSet)
+ return nil;
+ PlainTextRange textRange = m_object->doAXRangeForPosition(webCorePoint);
+ return [NSValue valueWithRange: NSMakeRange(textRange.start, textRange.length)];
+ }
+
+ if ([attribute isEqualToString: (NSString*)kAXRangeForIndexParameterizedAttribute]) {
+ PlainTextRange textRange = m_object->doAXRangeForIndex(intNumber);
+ return [NSValue valueWithRange: NSMakeRange(textRange.start, textRange.length)];
+ }
+
+ if ([attribute isEqualToString: (NSString*)kAXBoundsForRangeParameterizedAttribute]) {
+ if (!rangeSet)
+ return nil;
+ NSRect rect = m_object->doAXBoundsForRange(plainTextRange);
+ return [NSValue valueWithRect:rect];
+ }
+
+ if ([attribute isEqualToString: (NSString*)kAXRTFForRangeParameterizedAttribute])
+ return rangeSet ? [self doAXRTFForRange:range] : nil;
+
+ if ([attribute isEqualToString: (NSString*)kAXAttributedStringForRangeParameterizedAttribute])
+ return rangeSet ? [self doAXAttributedStringForRange:range] : nil;
+
+ if ([attribute isEqualToString: (NSString*)kAXStyleRangeForIndexParameterizedAttribute]) {
+ PlainTextRange textRange = m_object->doAXStyleRangeForIndex(intNumber);
+ return [NSValue valueWithRange: NSMakeRange(textRange.start, textRange.length)];
+ }
+ }
+
+ return nil;
+}
+
+- (BOOL)accessibilityShouldUseUniqueId
+{
+ return m_object->accessibilityShouldUseUniqueId();
+}
+
+// API that AppKit uses for faster access
+- (NSUInteger)accessibilityIndexOfChild:(id)child
+{
+ if (!m_object)
+ return NSNotFound;
+
+ m_object->updateBackingStore();
+
+ const AccessibilityObject::AccessibilityChildrenVector& children = m_object->children();
+
+ if (children.isEmpty())
+ return [[self renderWidgetChildren] indexOfObject:child];
+
+ unsigned count = children.size();
+ for (unsigned k = 0; k < count; ++k) {
+ AccessibilityObjectWrapper* wrapper = children[k]->wrapper();
+ if (wrapper == child || (children[k]->isAttachment() && [wrapper attachmentView] == child))
+ return k;
+ }
+
+ return NSNotFound;
+}
+
+- (NSUInteger)accessibilityArrayAttributeCount:(NSString *)attribute
+{
+ if (!m_object)
+ return 0;
+
+ m_object->updateBackingStore();
+
+ if ([attribute isEqualToString:NSAccessibilityChildrenAttribute]) {
+ const AccessibilityObject::AccessibilityChildrenVector& children = m_object->children();
+ if (children.isEmpty())
+ return [[self renderWidgetChildren] count];
+
+ return children.size();
+ }
+
+ return [super accessibilityArrayAttributeCount:attribute];
+}
+
+- (NSArray *)accessibilityArrayAttributeValues:(NSString *)attribute index:(NSUInteger)index maxCount:(NSUInteger)maxCount
+{
+ if (!m_object)
+ return nil;
+
+ m_object->updateBackingStore();
+
+ if ([attribute isEqualToString:NSAccessibilityChildrenAttribute]) {
+ if (m_object->children().isEmpty()) {
+ NSArray *children = [self renderWidgetChildren];
+ if (!children)
+ return nil;
+
+ NSUInteger childCount = [children count];
+ if (index >= childCount)
+ return nil;
+
+ NSUInteger arrayLength = min(childCount - index, maxCount);
+ return [children subarrayWithRange:NSMakeRange(index, arrayLength)];
+ }
+
+ const AccessibilityObject::AccessibilityChildrenVector& children = m_object->children();
+ unsigned childCount = children.size();
+ if (index >= childCount)
+ return nil;
+
+ unsigned available = min(childCount - index, maxCount);
+
+ NSMutableArray *subarray = [NSMutableArray arrayWithCapacity:available];
+ for (unsigned added = 0; added < available; ++index, ++added) {
+ AccessibilityObjectWrapper* wrapper = children[index]->wrapper();
+ if (wrapper) {
+ // The attachment view should be returned, otherwise AX palindrome errors occur.
+ if (children[index]->isAttachment() && [wrapper attachmentView])
+ [subarray addObject:[wrapper attachmentView]];
+ else
+ [subarray addObject:wrapper];
+ }
+ }
+
+ return subarray;
+ }
+
+ return [super accessibilityArrayAttributeValues:attribute index:index maxCount:maxCount];
+}
+
+@end
+
+#endif // HAVE(ACCESSIBILITY)
diff --git a/WebCore/accessibility/qt/AccessibilityObjectQt.cpp b/WebCore/accessibility/qt/AccessibilityObjectQt.cpp
new file mode 100644
index 0000000..1710027
--- /dev/null
+++ b/WebCore/accessibility/qt/AccessibilityObjectQt.cpp
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2008 Apple Ltd.
+ *
+ * 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 "AccessibilityObject.h"
+
+#if HAVE(ACCESSIBILITY)
+
+namespace WebCore {
+
+bool AccessibilityObject::accessibilityIgnoreAttachment() const
+{
+ return false;
+}
+
+} // namespace WebCore
+
+#endif // HAVE(ACCESSIBILITY)
diff --git a/WebCore/accessibility/win/AXObjectCacheWin.cpp b/WebCore/accessibility/win/AXObjectCacheWin.cpp
new file mode 100644
index 0000000..e39d5a5
--- /dev/null
+++ b/WebCore/accessibility/win/AXObjectCacheWin.cpp
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include "config.h"
+#include "AXObjectCache.h"
+
+#include "AccessibilityObject.h"
+
+namespace WebCore {
+
+void AXObjectCache::detachWrapper(AccessibilityObject* obj)
+{
+ // On Windows, AccessibilityObjects are created when get_accChildCount is
+ // called, but they are not wrapped until get_accChild is called, so this
+ // object may not have a wrapper.
+ if (AccessibilityObjectWrapper* wrapper = obj->wrapper())
+ wrapper->detach();
+}
+
+void AXObjectCache::attachWrapper(AccessibilityObject*)
+{
+ // On Windows, AccessibilityObjects are wrapped when the accessibility
+ // software requests them via get_accChild.
+}
+
+void AXObjectCache::postPlatformNotification(AccessibilityObject*, const String&)
+{
+}
+
+void AXObjectCache::handleFocusedUIElementChanged()
+{
+}
+
+} // namespace WebCore
diff --git a/WebCore/accessibility/win/AccessibilityObjectWin.cpp b/WebCore/accessibility/win/AccessibilityObjectWin.cpp
new file mode 100644
index 0000000..0a386c7
--- /dev/null
+++ b/WebCore/accessibility/win/AccessibilityObjectWin.cpp
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "AccessibilityObject.h"
+
+#if HAVE(ACCESSIBILITY)
+
+namespace WebCore {
+
+bool AccessibilityObject::accessibilityIgnoreAttachment() const
+{
+ return false;
+}
+
+} // namespace WebCore
+
+#endif // HAVE(ACCESSIBILITY)
diff --git a/WebCore/accessibility/win/AccessibilityObjectWrapperWin.h b/WebCore/accessibility/win/AccessibilityObjectWrapperWin.h
new file mode 100644
index 0000000..779443c
--- /dev/null
+++ b/WebCore/accessibility/win/AccessibilityObjectWrapperWin.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#ifndef AccessibilityObjectWrapperWin_h
+#define AccessibilityObjectWrapperWin_h
+
+namespace WebCore {
+
+ class AccessibilityObject;
+
+ class AccessibilityObjectWrapper : public IUnknown {
+ public:
+ // IUnknown
+ virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject) = 0;
+ virtual ULONG STDMETHODCALLTYPE AddRef(void) = 0;
+ virtual ULONG STDMETHODCALLTYPE Release(void) = 0;
+
+ virtual void detach() = 0;
+ bool attached() const { return m_object; }
+ AccessibilityObject* accessibilityObject() const { return m_object; }
+
+ protected:
+ AccessibilityObjectWrapper(AccessibilityObject* obj) : m_object(obj) { }
+ AccessibilityObjectWrapper() : m_object(0) { }
+
+ AccessibilityObject* m_object;
+ };
+
+} // namespace WebCore
+
+#endif // AccessibilityObjectWrapperWin_h
diff --git a/WebCore/accessibility/wx/AccessibilityObjectWx.cpp b/WebCore/accessibility/wx/AccessibilityObjectWx.cpp
new file mode 100644
index 0000000..1710027
--- /dev/null
+++ b/WebCore/accessibility/wx/AccessibilityObjectWx.cpp
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2008 Apple Ltd.
+ *
+ * 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 "AccessibilityObject.h"
+
+#if HAVE(ACCESSIBILITY)
+
+namespace WebCore {
+
+bool AccessibilityObject::accessibilityIgnoreAttachment() const
+{
+ return false;
+}
+
+} // namespace WebCore
+
+#endif // HAVE(ACCESSIBILITY)