Added: trunk/Source/WebCore/accessibility/gtk/WebKitAccessibleInterfaceDocument.cpp (0 => 105721)
--- trunk/Source/WebCore/accessibility/gtk/WebKitAccessibleInterfaceDocument.cpp (rev 0)
+++ trunk/Source/WebCore/accessibility/gtk/WebKitAccessibleInterfaceDocument.cpp 2012-01-24 11:40:44 UTC (rev 105721)
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2008 Nuanti Ltd.
+ * Copyright (C) 2009 Jan Alonzo
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * Portions from Mozilla a11y, copyright as follows:
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Sun Microsystems, Inc.
+ * Portions created by the Initial Developer are Copyright (C) 2002
+ * the Initial Developer. All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebKitAccessibleInterfaceDocument.h"
+
+#include "AccessibilityObject.h"
+#include "Document.h"
+#include "DocumentType.h"
+#include "WebKitAccessibleUtil.h"
+#include "WebKitAccessibleWrapperAtk.h"
+
+using namespace WebCore;
+
+static AccessibilityObject* core(AtkDocument* document)
+{
+ if (!WEBKIT_IS_ACCESSIBLE(document))
+ return 0;
+
+ return webkitAccessibleGetAccessibilityObject(WEBKIT_ACCESSIBLE(document));
+}
+
+static const gchar* documentAttributeValue(AtkDocument* document, const gchar* attribute)
+{
+ Document* coreDocument = core(document)->document();
+ if (!coreDocument)
+ return 0;
+
+ String value = String();
+ if (!g_ascii_strcasecmp(attribute, "DocType") && coreDocument->doctype())
+ value = coreDocument->doctype()->name();
+ else if (!g_ascii_strcasecmp(attribute, "Encoding"))
+ value = coreDocument->charset();
+ else if (!g_ascii_strcasecmp(attribute, "URI"))
+ value = coreDocument->documentURI();
+
+ if (!value.isEmpty())
+ return returnString(value);
+
+ return 0;
+}
+
+void webkitAccessibleDocumentInterfaceInit(AtkDocumentIface* iface)
+{
+ iface->get_document_attribute_value = webkitAccessibleDocumentGetAttributeValue;
+ iface->get_document_attributes = webkitAccessibleDocumentGetAttributes;
+ iface->get_document_locale = webkitAccessibleDocumentGetLocale;
+}
+
+const gchar* webkitAccessibleDocumentGetAttributeValue(AtkDocument* document, const gchar* attribute)
+{
+ return documentAttributeValue(document, attribute);
+}
+
+AtkAttributeSet* webkitAccessibleDocumentGetAttributes(AtkDocument* document)
+{
+ AtkAttributeSet* attributeSet = 0;
+ const gchar* attributes[] = { "DocType", "Encoding", "URI" };
+
+ for (unsigned i = 0; i < G_N_ELEMENTS(attributes); i++) {
+ const gchar* value = documentAttributeValue(document, attributes[i]);
+ if (value)
+ attributeSet = addToAtkAttributeSet(attributeSet, attributes[i], value);
+ }
+
+ return attributeSet;
+}
+
+const gchar* webkitAccessibleDocumentGetLocale(AtkDocument* document)
+{
+ // TODO: Should we fall back on lang xml:lang when the following comes up empty?
+ String language = core(document)->language();
+ if (!language.isEmpty())
+ return returnString(language);
+
+ return 0;
+}
Modified: trunk/Source/WebCore/accessibility/gtk/WebKitAccessibleWrapperAtk.cpp (105720 => 105721)
--- trunk/Source/WebCore/accessibility/gtk/WebKitAccessibleWrapperAtk.cpp 2012-01-24 11:29:01 UTC (rev 105720)
+++ trunk/Source/WebCore/accessibility/gtk/WebKitAccessibleWrapperAtk.cpp 2012-01-24 11:40:44 UTC (rev 105721)
@@ -65,6 +65,7 @@
#include "WebKitAccessibleHyperlink.h"
#include "WebKitAccessibleInterfaceAction.h"
#include "WebKitAccessibleInterfaceComponent.h"
+#include "WebKitAccessibleInterfaceDocument.h"
#include "WebKitAccessibleUtil.h"
#include "htmlediting.h"
#include "visible_units.h"
@@ -141,11 +142,6 @@
return core(ATK_OBJECT(hypertext));
}
-static AccessibilityObject* core(AtkDocument* document)
-{
- return core(ATK_OBJECT(document));
-}
-
static AccessibilityObject* core(AtkValue* value)
{
return core(ATK_OBJECT(value));
@@ -467,20 +463,10 @@
return -1;
}
-static AtkAttributeSet* addAttributeToSet(AtkAttributeSet* attributeSet, const char* name, const char* value)
-{
- AtkAttribute* attribute = static_cast<AtkAttribute*>(g_malloc(sizeof(AtkAttribute)));
- attribute->name = g_strdup(name);
- attribute->value = g_strdup(value);
- attributeSet = g_slist_prepend(attributeSet, attribute);
-
- return attributeSet;
-}
-
static AtkAttributeSet* webkit_accessible_get_attributes(AtkObject* object)
{
AtkAttributeSet* attributeSet = 0;
- attributeSet = addAttributeToSet(attributeSet, "toolkit", "WebKitGtk");
+ attributeSet = addToAtkAttributeSet(attributeSet, "toolkit", "WebKitGtk");
AccessibilityObject* coreObject = core(object);
if (!coreObject)
@@ -489,13 +475,13 @@
int headingLevel = coreObject->headingLevel();
if (headingLevel) {
String value = String::number(headingLevel);
- attributeSet = addAttributeToSet(attributeSet, "level", value.utf8().data());
+ attributeSet = addToAtkAttributeSet(attributeSet, "level", value.utf8().data());
}
// Set the 'layout-guess' attribute to help Assistive
// Technologies know when an exposed table is not data table.
if (coreObject->isAccessibilityTable() && !coreObject->isDataTable())
- attributeSet = addAttributeToSet(attributeSet, "layout-guess", "true");
+ attributeSet = addToAtkAttributeSet(attributeSet, "layout-guess", "true");
return attributeSet;
}
@@ -1330,20 +1316,20 @@
AtkAttributeSet* result = 0;
GOwnPtr<gchar> buffer(g_strdup_printf("%i", style->fontSize()));
- result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_SIZE), buffer.get());
+ result = addToAtkAttributeSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_SIZE), buffer.get());
Color bgColor = style->visitedDependentColor(CSSPropertyBackgroundColor);
if (bgColor.isValid()) {
buffer.set(g_strdup_printf("%i,%i,%i",
bgColor.red(), bgColor.green(), bgColor.blue()));
- result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_BG_COLOR), buffer.get());
+ result = addToAtkAttributeSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_BG_COLOR), buffer.get());
}
Color fgColor = style->visitedDependentColor(CSSPropertyColor);
if (fgColor.isValid()) {
buffer.set(g_strdup_printf("%i,%i,%i",
fgColor.red(), fgColor.green(), fgColor.blue()));
- result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_FG_COLOR), buffer.get());
+ result = addToAtkAttributeSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_FG_COLOR), buffer.get());
}
int baselinePosition;
@@ -1365,20 +1351,20 @@
if (includeRise) {
buffer.set(g_strdup_printf("%i", baselinePosition));
- result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_RISE), buffer.get());
+ result = addToAtkAttributeSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_RISE), buffer.get());
}
if (!style->textIndent().isUndefined()) {
int indentation = style->textIndent().calcValue(object->size().width());
buffer.set(g_strdup_printf("%i", indentation));
- result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_INDENT), buffer.get());
+ result = addToAtkAttributeSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_INDENT), buffer.get());
}
String fontFamilyName = style->font().family().family().string();
if (fontFamilyName.left(8) == "-webkit-")
fontFamilyName = fontFamilyName.substring(8);
- result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_FAMILY_NAME), fontFamilyName.utf8().data());
+ result = addToAtkAttributeSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_FAMILY_NAME), fontFamilyName.utf8().data());
int fontWeight = -1;
switch (style->font().weight()) {
@@ -1411,7 +1397,7 @@
}
if (fontWeight > 0) {
buffer.set(g_strdup_printf("%i", fontWeight));
- result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_WEIGHT), buffer.get());
+ result = addToAtkAttributeSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_WEIGHT), buffer.get());
}
switch (style->textAlign()) {
@@ -1421,29 +1407,29 @@
break;
case LEFT:
case WEBKIT_LEFT:
- result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_JUSTIFICATION), "left");
+ result = addToAtkAttributeSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_JUSTIFICATION), "left");
break;
case RIGHT:
case WEBKIT_RIGHT:
- result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_JUSTIFICATION), "right");
+ result = addToAtkAttributeSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_JUSTIFICATION), "right");
break;
case CENTER:
case WEBKIT_CENTER:
- result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_JUSTIFICATION), "center");
+ result = addToAtkAttributeSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_JUSTIFICATION), "center");
break;
case JUSTIFY:
- result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_JUSTIFICATION), "fill");
+ result = addToAtkAttributeSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_JUSTIFICATION), "fill");
}
- result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_UNDERLINE), (style->textDecoration() & UNDERLINE) ? "single" : "none");
+ result = addToAtkAttributeSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_UNDERLINE), (style->textDecoration() & UNDERLINE) ? "single" : "none");
- result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_STYLE), style->font().italic() ? "italic" : "normal");
+ result = addToAtkAttributeSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_STYLE), style->font().italic() ? "italic" : "normal");
- result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_STRIKETHROUGH), (style->textDecoration() & LINE_THROUGH) ? "true" : "false");
+ result = addToAtkAttributeSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_STRIKETHROUGH), (style->textDecoration() & LINE_THROUGH) ? "true" : "false");
- result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_INVISIBLE), (style->visibility() == HIDDEN) ? "true" : "false");
+ result = addToAtkAttributeSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_INVISIBLE), (style->visibility() == HIDDEN) ? "true" : "false");
- result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_EDITABLE), object->isReadOnly() ? "false" : "true");
+ result = addToAtkAttributeSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_EDITABLE), object->isReadOnly() ? "false" : "true");
return result;
}
@@ -2249,63 +2235,6 @@
iface->get_hyperlink = webkitAccessibleHyperlinkImplGetHyperlink;
}
-static const gchar* documentAttributeValue(AtkDocument* document, const gchar* attribute)
-{
- Document* coreDocument = core(document)->document();
- if (!coreDocument)
- return 0;
-
- String value = String();
- if (!g_ascii_strcasecmp(attribute, "DocType") && coreDocument->doctype())
- value = coreDocument->doctype()->name();
- else if (!g_ascii_strcasecmp(attribute, "Encoding"))
- value = coreDocument->charset();
- else if (!g_ascii_strcasecmp(attribute, "URI"))
- value = coreDocument->documentURI();
- if (!value.isEmpty())
- return returnString(value);
-
- return 0;
-}
-
-static const gchar* webkit_accessible_document_get_attribute_value(AtkDocument* document, const gchar* attribute)
-{
- return documentAttributeValue(document, attribute);
-}
-
-static AtkAttributeSet* webkit_accessible_document_get_attributes(AtkDocument* document)
-{
- AtkAttributeSet* attributeSet = 0;
- const gchar* attributes[] = { "DocType", "Encoding", "URI" };
-
- for (unsigned i = 0; i < G_N_ELEMENTS(attributes); i++) {
- const gchar* value = documentAttributeValue(document, attributes[i]);
- if (value)
- attributeSet = addAttributeToSet(attributeSet, attributes[i], value);
- }
-
- return attributeSet;
-}
-
-static const gchar* webkit_accessible_document_get_locale(AtkDocument* document)
-{
-
- // TODO: Should we fall back on lang xml:lang when the following comes up empty?
- String language = core(document)->language();
- if (!language.isEmpty())
- return returnString(language);
-
- return 0;
-}
-
-static void atk_document_interface_init(AtkDocumentIface* iface)
-{
- iface->get_document_attribute_value = webkit_accessible_document_get_attribute_value;
- iface->get_document_attributes = webkit_accessible_document_get_attributes;
- iface->get_document_locale = webkit_accessible_document_get_locale;
-}
-
-
static void webkitAccessibleValueGetCurrentValue(AtkValue* value, GValue* gValue)
{
memset(gValue, 0, sizeof(GValue));
@@ -2379,8 +2308,7 @@
(GInterfaceFinalizeFunc) 0, 0},
{(GInterfaceInitFunc)atkHyperlinkImplInterfaceInit,
(GInterfaceFinalizeFunc) 0, 0},
- {(GInterfaceInitFunc)atk_document_interface_init,
- (GInterfaceFinalizeFunc) 0, 0},
+ {reinterpret_cast<GInterfaceInitFunc>(webkitAccessibleDocumentInterfaceInit), 0, 0},
{(GInterfaceInitFunc)atkValueInterfaceInit,
(GInterfaceFinalizeFunc) 0, 0}
};