[atk] Replace deprecated call to atk_document_get_locale() in DumpRenderTree
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Jun 2013 21:39:42 +0000 (21:39 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Jun 2013 21:39:42 +0000 (21:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=115647

Patch by Eduardo Lima Mitev <elima@igalia.com> on 2013-06-12
Reviewed by Martin Robinson.

Source/WebCore:

Override the get_object_locale() method of WebkitAccessibleWrapperAtk's internal
AtkObject, to include custom implementations for AtkDocument and AtkText objects,
taking the logic as-is from AtkDocument::get_document_locale() and DumpRenderTree's
AccessibilityUIElementAtk::language(), respectively.

Apart from improving encapsulation, this avoids calling deprecated get_document_locale()
method.

No new functionality, no new tests.

* accessibility/atk/WebKitAccessibleInterfaceDocument.cpp:
(webkitAccessibleDocumentInterfaceInit): Chains implementation of
AtkDocument::get_document_locale() to AtkObject::get_object_locale().
* accessibility/atk/WebKitAccessibleWrapperAtk.cpp:
(webkitAccessibleGetObjectLocale): Add implementation of locale resolution for
objects of type AtkDocument and AtkText.
(webkitAccessibleClassInit): Override AtkObject::get_object_locale() method.

Tools:

Locale resolution is moved to WebKitAccessibleWrapperAtk using
AtkObject::get_object_locale() API. Now, implementation of
AccessibilityUIElement::language() in both DumpRenderTree and WebKitTestRunner can
be leveraged to get_object_locale() of AtkObject.

Apart from improving encapsulation, this avoids calling deprecated get_document_locale()
method.

No new functionality, no new tests.

* DumpRenderTree/atk/AccessibilityUIElementAtk.cpp:
(AccessibilityUIElement::language): Leverage locale resolution to
AtkObject::get_object_locale().
* WebKitTestRunner/InjectedBundle/atk/AccessibilityUIElementAtk.cpp:
(WTR::AccessibilityUIElement::language): Leverage locale resolution to
AtkObject::get_object_locale().

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@151524 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceDocument.cpp
Source/WebCore/accessibility/atk/WebKitAccessibleWrapperAtk.cpp
Tools/ChangeLog
Tools/DumpRenderTree/atk/AccessibilityUIElementAtk.cpp
Tools/WebKitTestRunner/InjectedBundle/atk/AccessibilityUIElementAtk.cpp

index a047e04bb0a15aa1f80bc241af41460577c5dc80..16d9f4a131d2f8fc971dd6d76027b12dc9f4774c 100644 (file)
@@ -1,3 +1,28 @@
+2013-06-12  Eduardo Lima Mitev  <elima@igalia.com>
+
+        [atk] Replace deprecated call to atk_document_get_locale() in DumpRenderTree
+        https://bugs.webkit.org/show_bug.cgi?id=115647
+
+        Reviewed by Martin Robinson.
+
+        Override the get_object_locale() method of WebkitAccessibleWrapperAtk's internal
+        AtkObject, to include custom implementations for AtkDocument and AtkText objects,
+        taking the logic as-is from AtkDocument::get_document_locale() and DumpRenderTree's
+        AccessibilityUIElementAtk::language(), respectively.
+
+        Apart from improving encapsulation, this avoids calling deprecated get_document_locale()
+        method.
+
+        No new functionality, no new tests.
+
+        * accessibility/atk/WebKitAccessibleInterfaceDocument.cpp:
+        (webkitAccessibleDocumentInterfaceInit): Chains implementation of
+        AtkDocument::get_document_locale() to AtkObject::get_object_locale().
+        * accessibility/atk/WebKitAccessibleWrapperAtk.cpp:
+        (webkitAccessibleGetObjectLocale): Add implementation of locale resolution for
+        objects of type AtkDocument and AtkText.
+        (webkitAccessibleClassInit): Override AtkObject::get_object_locale() method.
+
 2013-06-12  Zan Dobersek  <zdobersek@igalia.com>
 
         [GTK] Move more build targets for source code that's free of layer violations into libPlatform
index dac1bbbaa11aee5363529fa54d65b1499d28e3cb..f07484318d0f8618e396e98f59abc4b8e9e9b973 100644 (file)
@@ -97,12 +97,12 @@ static AtkAttributeSet* webkitAccessibleDocumentGetAttributes(AtkDocument* docum
 
 static 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 cacheAndReturnAtkProperty(ATK_OBJECT(document), AtkCachedDocumentLocale, language);
-
-    return 0;
+    // The logic to resolve locale has been moved to
+    // AtkObject::get_object_locale() virtual method. However, to avoid breaking
+    // clients expecting the deprecated AtkDocumentIface::get_document_locale()
+    // to be overriden, method is kept and chained up to
+    // AtkObject::get_object_locale(). <https://bugs.webkit.org/show_bug.cgi?id=115647>
+    return atk_object_get_object_locale(ATK_OBJECT(document));
 }
 
 void webkitAccessibleDocumentInterfaceInit(AtkDocumentIface* iface)
index e9231e6565dc8b5c4e617c1663f0966e2227bfcf..52f06acf870f2cb37d3c527d127e19837f0e66d4 100644 (file)
@@ -792,6 +792,38 @@ static void webkitAccessibleInit(AtkObject* object, gpointer data)
     accessible->priv = WEBKIT_ACCESSIBLE_GET_PRIVATE(accessible);
 }
 
+static const gchar* webkitAccessibleGetObjectLocale(AtkObject* object)
+{
+    if (ATK_IS_DOCUMENT(object)) {
+        AccessibilityObject* coreObject = core(object);
+        if (!coreObject)
+            return 0;
+
+        // TODO: Should we fall back on lang xml:lang when the following comes up empty?
+        String language = coreObject->language();
+        if (!language.isEmpty())
+            return cacheAndReturnAtkProperty(object, AtkCachedDocumentLocale, language);
+
+    } else if (ATK_IS_TEXT(object)) {
+        const gchar* locale = 0;
+
+        AtkAttributeSet* textAttributes = atk_text_get_default_attributes(ATK_TEXT(object));
+        for (GSList* attributes = textAttributes; attributes; attributes = attributes->next) {
+            AtkAttribute* atkAttribute = static_cast<AtkAttribute*>(attributes->data);
+            if (!strcmp(atkAttribute->name, atk_text_attribute_get_name(ATK_TEXT_ATTR_LANGUAGE))) {
+                locale = cacheAndReturnAtkProperty(object, AtkCachedDocumentLocale, String::fromUTF8(atkAttribute->value));
+                break;
+            }
+        }
+
+        atk_attribute_set_free(textAttributes);
+
+        return locale;
+    }
+
+    return 0;
+}
+
 static void webkitAccessibleFinalize(GObject* object)
 {
     G_OBJECT_CLASS(webkitAccessibleParentClass)->finalize(object);
@@ -816,6 +848,7 @@ static void webkitAccessibleClassInit(AtkObjectClass* klass)
     klass->get_index_in_parent = webkitAccessibleGetIndexInParent;
     klass->get_attributes = webkitAccessibleGetAttributes;
     klass->ref_relation_set = webkitAccessibleRefRelationSet;
+    klass->get_object_locale = webkitAccessibleGetObjectLocale;
 
     g_type_class_add_private(klass, sizeof(WebKitAccessiblePrivate));
 }
index c0c3f214111d1f77df34bfaf0bccfb09973f5e6b..b5b58d6aef8e9a51dbc5360f36792040364bffc6 100644 (file)
@@ -1,3 +1,27 @@
+2013-06-12  Eduardo Lima Mitev  <elima@igalia.com>
+
+        [atk] Replace deprecated call to atk_document_get_locale() in DumpRenderTree
+        https://bugs.webkit.org/show_bug.cgi?id=115647
+
+        Reviewed by Martin Robinson.
+
+        Locale resolution is moved to WebKitAccessibleWrapperAtk using
+        AtkObject::get_object_locale() API. Now, implementation of
+        AccessibilityUIElement::language() in both DumpRenderTree and WebKitTestRunner can
+        be leveraged to get_object_locale() of AtkObject.
+
+        Apart from improving encapsulation, this avoids calling deprecated get_document_locale()
+        method.
+
+        No new functionality, no new tests.
+
+        * DumpRenderTree/atk/AccessibilityUIElementAtk.cpp:
+        (AccessibilityUIElement::language): Leverage locale resolution to
+        AtkObject::get_object_locale().
+        * WebKitTestRunner/InjectedBundle/atk/AccessibilityUIElementAtk.cpp:
+        (WTR::AccessibilityUIElement::language): Leverage locale resolution to
+        AtkObject::get_object_locale().
+
 2013-06-12  Hugo Parente Lima  <hugo.lima@openbossa.org>
 
         Remove last bits of GYP from build-webkit and update-webkit scripts
index db894b59ff237d52f80a1a6d568a66f857660f6a..67a993edd33dd5300956b1d430025e17d23c7dc6 100644 (file)
@@ -432,21 +432,11 @@ JSStringRef AccessibilityUIElement::language()
     if (!m_element)
         return JSStringCreateWithCharacters(0, 0);
 
-    // In ATK, the document language is exposed as the document's locale.
-    if (atk_object_get_role(ATK_OBJECT(m_element)) == ATK_ROLE_DOCUMENT_FRAME)
-        return JSStringCreateWithUTF8CString(g_strdup_printf("AXLanguage: %s", atk_document_get_locale(ATK_DOCUMENT(m_element))));
-
-    // For all other objects, the language is exposed as an AtkText attribute.
-    if (!ATK_IS_TEXT(m_element))
+    const gchar* locale = atk_object_get_object_locale(ATK_OBJECT(m_element));
+    if (!locale)
         return JSStringCreateWithCharacters(0, 0);
 
-    for (GSList* textAttributes = atk_text_get_default_attributes(ATK_TEXT(m_element)); textAttributes; textAttributes = textAttributes->next) {
-        AtkAttribute* atkAttribute = static_cast<AtkAttribute*>(textAttributes->data);
-        if (!strcmp(atkAttribute->name, atk_text_attribute_get_name(ATK_TEXT_ATTR_LANGUAGE)))
-            return JSStringCreateWithUTF8CString(g_strdup_printf("AXLanguage: %s", atkAttribute->value));
-    }
-
-    return JSStringCreateWithCharacters(0, 0);
+    return JSStringCreateWithUTF8CString(g_strdup_printf("AXLanguage: %s", locale));
 }
 
 double AccessibilityUIElement::x()
index 456b1322e65b4fa1405e2c751cd0891a9f41bd62..0165ffde055e8770d31cee2ee0d650cdad6d7226 100644 (file)
@@ -618,29 +618,11 @@ JSRetainPtr<JSStringRef> AccessibilityUIElement::language()
     if (!m_element || !ATK_IS_OBJECT(m_element.get()))
         return JSStringCreateWithCharacters(0, 0);
 
-    GOwnPtr<gchar> language;
-    // In ATK, the document language is exposed as the document's locale.
-    if (atk_object_get_role(ATK_OBJECT(m_element.get())) == ATK_ROLE_DOCUMENT_FRAME) {
-        language.set(g_strdup_printf("AXLanguage: %s", atk_document_get_locale(ATK_DOCUMENT(m_element.get()))));
-        return JSStringCreateWithUTF8CString(language.get());
-    }
-
-    // For all other objects, the language is exposed as an AtkText attribute.
-    if (!ATK_IS_TEXT(m_element.get()))
+    const gchar* locale = atk_object_get_object_locale(ATK_OBJECT(m_element.get()));
+    if (!locale)
         return JSStringCreateWithCharacters(0, 0);
 
-    GOwnPtr<GSList> textAttributes(atk_text_get_default_attributes(ATK_TEXT(m_element.get())));
-    for (GSList* attributes = textAttributes.get(); attributes; attributes = attributes->next) {
-        AtkAttribute* atkAttribute = static_cast<AtkAttribute*>(attributes->data);
-        if (!strcmp(atkAttribute->name, atk_text_attribute_get_name(ATK_TEXT_ATTR_LANGUAGE))) {
-            language.set(g_strdup_printf("AXLanguage: %s", atkAttribute->value));
-            break;
-        }
-    }
-
-    attributesClear(textAttributes.get());
-
-    return JSStringCreateWithUTF8CString(language.get());
+    return JSStringCreateWithUTF8CString(g_strdup_printf("AXLanguage: %s", locale));
 }
 
 JSRetainPtr<JSStringRef> AccessibilityUIElement::helpText() const