summaryrefslogtreecommitdiffstats
path: root/src/core/browser_accessibility_qt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/browser_accessibility_qt.cpp')
-rw-r--r--src/core/browser_accessibility_qt.cpp82
1 files changed, 81 insertions, 1 deletions
diff --git a/src/core/browser_accessibility_qt.cpp b/src/core/browser_accessibility_qt.cpp
index d2710b0ea..405bafb94 100644
--- a/src/core/browser_accessibility_qt.cpp
+++ b/src/core/browser_accessibility_qt.cpp
@@ -34,6 +34,10 @@
**
****************************************************************************/
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#include "browser_accessibility_qt.h"
#include "third_party/WebKit/public/web/WebAXEnums.h"
@@ -52,6 +56,82 @@ BrowserAccessibilityQt::BrowserAccessibilityQt()
QAccessible::registerAccessibleInterface(this);
}
+// This function is taken from chromium/content/browser/accessibility/browser_accessibility_win.cc
+// see also http://www.w3.org/TR/html-aapi
+void BrowserAccessibilityQt::OnDataChanged()
+{
+ BrowserAccessibility::OnDataChanged();
+
+ // The calculation of the accessible name of an element has been
+ // standardized in the HTML to Platform Accessibility APIs Implementation
+ // Guide (http://www.w3.org/TR/html-aapi/). In order to return the
+ // appropriate accessible name on Windows, we need to apply some logic
+ // to the fields we get from WebKit.
+ //
+ // TODO(dmazzoni): move most of this logic into WebKit.
+ //
+ // WebKit gives us:
+ //
+ // name: the default name, e.g. inner text
+ // title ui element: a reference to a <label> element on the same
+ // page that labels this node.
+ // description: accessible labels that override the default name:
+ // aria-label or aria-labelledby or aria-describedby
+ // help: the value of the "title" attribute
+ //
+ // On Windows, the logic we apply lets some fields take precedence and
+ // always returns the primary name in "name" and the secondary name,
+ // if any, in "description".
+
+ int title_elem_id = GetIntAttribute(
+ ui::AX_ATTR_TITLE_UI_ELEMENT);
+ std::string help = GetStringAttribute(ui::AX_ATTR_HELP);
+ std::string description = GetStringAttribute(
+ ui::AX_ATTR_DESCRIPTION);
+
+ // WebKit annoyingly puts the title in the description if there's no other
+ // description, which just confuses the rest of the logic. Put it back.
+ // Now "help" is always the value of the "title" attribute, if present.
+ std::string title_attr;
+ if (GetHtmlAttribute("title", &title_attr) &&
+ description == title_attr &&
+ help.empty()) {
+ help = description;
+ description.clear();
+ }
+
+ // Now implement the main logic: the descripion should become the name if
+ // it's nonempty, and the help should become the description if
+ // there's no description - or the name if there's no name or description.
+ if (!description.empty()) {
+ set_name(description);
+ description.clear();
+ }
+ if (!help.empty() && description.empty()) {
+ description = help;
+ help.clear();
+ }
+ if (!description.empty() && name().empty() && !title_elem_id) {
+ set_name(description);
+ description.clear();
+ }
+
+ // If it's a text field, also consider the placeholder.
+ std::string placeholder;
+ if (GetRole() == ui::AX_ROLE_TEXT_FIELD &&
+ HasState(ui::AX_STATE_FOCUSABLE) &&
+ GetHtmlAttribute("placeholder", &placeholder)) {
+ if (name().empty() && !title_elem_id) {
+ set_name(placeholder);
+ } else if (description.empty()) {
+ description = placeholder;
+ }
+ }
+
+ SetStringAttribute(ui::AX_ATTR_DESCRIPTION, description);
+ SetStringAttribute(ui::AX_ATTR_HELP, help);
+}
+
bool BrowserAccessibilityQt::isValid() const
{
return true;
@@ -128,7 +208,7 @@ QString BrowserAccessibilityQt::text(QAccessible::Text t) const
{
switch (t) {
case QAccessible::Name:
- return toQt(GetStringAttribute(ui::AX_ATTR_NAME));
+ return toQt(name());
case QAccessible::Description:
return toQt(GetStringAttribute(ui::AX_ATTR_DESCRIPTION));
case QAccessible::Help: