Changeset 71026 in webkit
- Timestamp:
- Nov 1, 2010 8:05:36 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r71017 r71026 1 2010-11-01 Mario Sanchez Prada <msanchez@igalia.com> 2 3 Reviewed by Martin Robinson. 4 5 [Gtk] AtkHyperlink needs to be implemented 6 https://bugs.webkit.org/show_bug.cgi?id=33785 7 8 Implemented the AtkHyperlink/AtkHypertext stuff in the GTK port. 9 10 Even thought these kind of tasks are usually about implementing an 11 interface, in this case it was needed to implement some more 12 things due to the fact that AtkHyperlink is neither an interface 13 nor an AtkObject, but just an abstract class child of GObject that 14 needs to be redefined in a specific subclass of that one. On top 15 of that, it was needed to implement the AtkAction interface as 16 well for that new class, so exposed hyperlinks can work as 17 expected with Assistive Technologies based on ATK. 18 19 Furthermore, as there's no mechanism to get an instance of that 20 AtkHyperlink other than doing it through an AtkObject implementing 21 the AtkHypertext interface, it was needed to also add the code to 22 implement that one, so it makes possible to ask for the 23 'hyperlinks' under an 'hypertext' accessible object. 24 25 Finally, to complete the implementation of all this stuff and make 26 it all consistent, it was needed as well to implement the 27 AtkHyperlinkImpl interface (providing just one method only) so 28 that allows retrieving the AtkHyperlink object associated to an 29 AtkObject implementing such an interface. 30 31 * GNUmakefile.am: Add the new WebKitAccessibleHyperlink.[h|cpp] 32 files to the sources list for the GTK port. 33 34 * accessibility/gtk/AccessibilityObjectWrapperAtk.cpp: 35 (core): New function to return the core accessibility object 36 related to an AtkObject implementing the AtkHypertext interface. 37 (webkitAccessibleHypertextGetLink): New, part of the 38 implementation of the AtkHypertext interface. 39 (webkitAccessibleHypertextGetNLinks): New, likewise. 40 (webkitAccessibleHypertextGetLinkIndex): New, likewise. 41 (atkHypertextInterfaceInit): New, initialize the AtkHypertext 42 interface. 43 (webkitAccessibleHyperlinkImplGetHyperlink): New, part of the 44 implementation of the AtkHyperlinkImpl interface. 45 (atkHyperlinkImplInterfaceInit): New, initialize the 46 AtkHyperlinkImpl interface. 47 (GetAtkInterfaceTypeFromWAIType): Add ATK_TYPE_HYPERTEXT and 48 ATK_TYPE_HYPERLINK_IMPL to the list of recognized types. 49 (getInterfaceMaskFromObject): Decide when it's needed to add 50 WAI_HYPERTEXT and WAI_HYPERLINK to the interface mask. 51 52 * accessibility/gtk/WebKitAccessibleHyperlink.h: Added. 53 * accessibility/gtk/WebKitAccessibleHyperlink.cpp: Added. 54 (returnString): Return (const char*) from String variables. 55 (core): Return the associated AccessibilityObject. 56 (webkitAccessibleHyperlinkActionDoAction): Part of the 57 implementation of the AtkAction interface. 58 (webkitAccessibleHyperlinkActionGetNActions): Likewise. 59 (webkitAccessibleHyperlinkActionGetDescription): Likewise. 60 (webkitAccessibleHyperlinkActionGetKeybinding): Likewise. 61 (webkitAccessibleHyperlinkActionGetName): Likewise. 62 (atkActionInterfaceInit): Initialize the AtkAction interface. 63 (getRangeLengthForObject): Returns the length for a given Range, 64 considering special cases (e.g. List item markers). 65 (webkitAccessibleHyperlinkGetURI): Implementation of one of the 66 methods in the AtkHyperlink abstract class. 67 (webkitAccessibleHyperlinkGetObject): Likewise. 68 (webkitAccessibleHyperlinkGetStartIndex): Likewise. 69 (webkitAccessibleHyperlinkGetEndIndex): Likewise. 70 (webkitAccessibleHyperlinkIsValid): Likewise. 71 (webkitAccessibleHyperlinkGetNAnchors): Likewise. 72 (webkitAccessibleHyperlinkIsSelectedLink): Likewise. 73 (webkitAccessibleHyperlinkGetProperty): Getter method. 74 (webkitAccessibleHyperlinkSetProperty): Setter method. 75 (webkitAccessibleHyperlinkFinalize): Finalize method. 76 (webkitAccessibleHyperlinkClassInit): Initialize the 77 WebKitAccessibleHyperlink class. 78 (webkitAccessibleHyperlinkInit): Initialize the 79 WebKitAccessibleHyperlink instance. 80 (webkitAccessibleHyperlinkGetType): Implementation of the 81 get_type() function for the WebKitAccessibleHyperlink class. 82 (webkitAccessibleHyperlinkNew): Returns an instance of the class 83 associated to a given AtkHyperlinkImpl object. 84 (webkitAccessibleHyperlinkGetAccessibilityObject): Public function 85 returning the AccessibilityObject associated to the instance of 86 the WebKitAccessibleHyperlink class. 87 1 88 2010-11-01 Pavel Feldman <pfeldman@chromium.org> 2 89 -
trunk/WebCore/GNUmakefile.am
r71009 r71026 3497 3497 WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.h \ 3498 3498 WebCore/accessibility/gtk/AXObjectCacheAtk.cpp \ 3499 WebCore/accessibility/gtk/WebKitAccessibleHyperlink.h \ 3500 WebCore/accessibility/gtk/WebKitAccessibleHyperlink.cpp \ 3499 3501 WebCore/bindings/js/ScriptControllerGtk.cpp \ 3500 3502 WebCore/page/gtk/DragControllerGtk.cpp \ -
trunk/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp
r70634 r71026 61 61 #include "TextEncoding.h" 62 62 #include "TextIterator.h" 63 #include <wtf/text/CString.h> 64 #include <wtf/text/AtomicString.h> 63 #include "WebKitAccessibleHyperlink.h" 65 64 66 65 #include <atk/atk.h> … … 69 68 #include <libgail-util/gail-util.h> 70 69 #include <pango/pango.h> 70 #include <wtf/text/AtomicString.h> 71 #include <wtf/text/CString.h> 71 72 72 73 using namespace WebCore; … … 142 143 { 143 144 return core(ATK_OBJECT(table)); 145 } 146 147 static AccessibilityObject* core(AtkHypertext* hypertext) 148 { 149 return core(ATK_OBJECT(hypertext)); 144 150 } 145 151 … … 1955 1961 } 1956 1962 1963 static AtkHyperlink* webkitAccessibleHypertextGetLink(AtkHypertext* hypertext, gint index) 1964 { 1965 AccessibilityObject::AccessibilityChildrenVector children = core(hypertext)->children(); 1966 if (index < 0 || static_cast<unsigned>(index) >= children.size()) 1967 return 0; 1968 1969 gint currentLink = -1; 1970 for (unsigned i = 0; i < children.size(); i++) { 1971 AccessibilityObject* coreChild = children.at(i).get(); 1972 if (!coreChild->accessibilityIsIgnored() && coreChild->isLink()) { 1973 currentLink++; 1974 if (index != currentLink) 1975 continue; 1976 1977 AtkObject* axObject = coreChild->wrapper(); 1978 if (!axObject || !ATK_IS_HYPERLINK_IMPL(axObject)) 1979 return 0; 1980 1981 return atk_hyperlink_impl_get_hyperlink(ATK_HYPERLINK_IMPL(axObject)); 1982 } 1983 } 1984 1985 return 0; 1986 } 1987 1988 static gint webkitAccessibleHypertextGetNLinks(AtkHypertext* hypertext) 1989 { 1990 AccessibilityObject::AccessibilityChildrenVector children = core(hypertext)->children(); 1991 if (!children.size()) 1992 return 0; 1993 1994 gint linksFound = 0; 1995 for (size_t i = 0; i < children.size(); i++) { 1996 AccessibilityObject* coreChild = children.at(i).get(); 1997 if (!coreChild->accessibilityIsIgnored() && coreChild->isLink()) 1998 linksFound++; 1999 } 2000 2001 return linksFound; 2002 } 2003 2004 static gint webkitAccessibleHypertextGetLinkIndex(AtkHypertext* hypertext, gint charIndex) 2005 { 2006 size_t linksCount = webkitAccessibleHypertextGetNLinks(hypertext); 2007 if (!linksCount) 2008 return -1; 2009 2010 for (size_t i = 0; i < linksCount; i++) { 2011 AtkHyperlink* hyperlink = ATK_HYPERLINK(webkitAccessibleHypertextGetLink(hypertext, i)); 2012 gint startIndex = atk_hyperlink_get_start_index(hyperlink); 2013 gint endIndex = atk_hyperlink_get_end_index(hyperlink); 2014 2015 // Check if the char index in the link's offset range 2016 if (startIndex <= charIndex && charIndex < endIndex) 2017 return i; 2018 } 2019 2020 // Not found if reached 2021 return -1; 2022 } 2023 2024 static void atkHypertextInterfaceInit(AtkHypertextIface* iface) 2025 { 2026 iface->get_link = webkitAccessibleHypertextGetLink; 2027 iface->get_n_links = webkitAccessibleHypertextGetNLinks; 2028 iface->get_link_index = webkitAccessibleHypertextGetLinkIndex; 2029 } 2030 2031 static AtkHyperlink* webkitAccessibleHyperlinkImplGetHyperlink(AtkHyperlinkImpl* hyperlink) 2032 { 2033 AtkHyperlink* hyperlinkObject = ATK_HYPERLINK(g_object_get_data(G_OBJECT(hyperlink), "hyperlink-object")); 2034 if (!hyperlinkObject) { 2035 hyperlinkObject = ATK_HYPERLINK(webkitAccessibleHyperlinkNew(hyperlink)); 2036 g_object_set_data(G_OBJECT(hyperlink), "hyperlink-object", hyperlinkObject); 2037 } 2038 return hyperlinkObject; 2039 } 2040 2041 static void atkHyperlinkImplInterfaceInit(AtkHyperlinkImplIface* iface) 2042 { 2043 iface->get_hyperlink = webkitAccessibleHyperlinkImplGetHyperlink; 2044 } 2045 1957 2046 static const gchar* documentAttributeValue(AtkDocument* document, const gchar* attribute) 1958 2047 { … … 2026 2115 {(GInterfaceInitFunc)atk_table_interface_init, 2027 2116 (GInterfaceFinalizeFunc) 0, 0}, 2117 {(GInterfaceInitFunc)atkHypertextInterfaceInit, 2118 (GInterfaceFinalizeFunc) 0, 0}, 2119 {(GInterfaceInitFunc)atkHyperlinkImplInterfaceInit, 2120 (GInterfaceFinalizeFunc) 0, 0}, 2028 2121 {(GInterfaceInitFunc)atk_document_interface_init, 2029 2122 (GInterfaceFinalizeFunc) 0, 0} … … 2038 2131 WAI_IMAGE, 2039 2132 WAI_TABLE, 2133 WAI_HYPERTEXT, 2134 WAI_HYPERLINK, 2040 2135 WAI_DOCUMENT 2041 2136 }; … … 2043 2138 static GType GetAtkInterfaceTypeFromWAIType(WAIType type) 2044 2139 { 2045 switch (type) { 2046 case WAI_ACTION: 2047 return ATK_TYPE_ACTION; 2048 case WAI_SELECTION: 2049 return ATK_TYPE_SELECTION; 2050 case WAI_EDITABLE_TEXT: 2051 return ATK_TYPE_EDITABLE_TEXT; 2052 case WAI_TEXT: 2053 return ATK_TYPE_TEXT; 2054 case WAI_COMPONENT: 2055 return ATK_TYPE_COMPONENT; 2056 case WAI_IMAGE: 2057 return ATK_TYPE_IMAGE; 2058 case WAI_TABLE: 2059 return ATK_TYPE_TABLE; 2060 case WAI_DOCUMENT: 2061 return ATK_TYPE_DOCUMENT; 2062 } 2063 2064 return G_TYPE_INVALID; 2140 switch (type) { 2141 case WAI_ACTION: 2142 return ATK_TYPE_ACTION; 2143 case WAI_SELECTION: 2144 return ATK_TYPE_SELECTION; 2145 case WAI_EDITABLE_TEXT: 2146 return ATK_TYPE_EDITABLE_TEXT; 2147 case WAI_TEXT: 2148 return ATK_TYPE_TEXT; 2149 case WAI_COMPONENT: 2150 return ATK_TYPE_COMPONENT; 2151 case WAI_IMAGE: 2152 return ATK_TYPE_IMAGE; 2153 case WAI_TABLE: 2154 return ATK_TYPE_TABLE; 2155 case WAI_HYPERTEXT: 2156 return ATK_TYPE_HYPERTEXT; 2157 case WAI_HYPERLINK: 2158 return ATK_TYPE_HYPERLINK_IMPL; 2159 case WAI_DOCUMENT: 2160 return ATK_TYPE_DOCUMENT; 2161 } 2162 2163 return G_TYPE_INVALID; 2065 2164 } 2066 2165 … … 2072 2171 interfaceMask |= 1 << WAI_COMPONENT; 2073 2172 2173 AccessibilityRole role = coreObject->roleValue(); 2174 2074 2175 // Action 2075 if (!coreObject->actionVerb().isEmpty()) 2176 if (!coreObject->actionVerb().isEmpty()) { 2076 2177 interfaceMask |= 1 << WAI_ACTION; 2178 2179 if (!coreObject->accessibilityIsIgnored() && coreObject->isLink()) 2180 interfaceMask |= 1 << WAI_HYPERLINK; 2181 } 2077 2182 2078 2183 // Selection … … 2081 2186 2082 2187 // Text & Editable Text 2083 AccessibilityRole role = coreObject->roleValue();2084 2085 2188 if (role == StaticTextRole) 2086 2189 interfaceMask |= 1 << WAI_TEXT; 2087 else if (coreObject->isAccessibilityRenderObject()) 2190 else if (coreObject->isAccessibilityRenderObject()) { 2088 2191 if (coreObject->isTextControl()) { 2089 2192 interfaceMask |= 1 << WAI_TEXT; … … 2093 2196 AccessibilityRenderObject* axRenderObject = static_cast<AccessibilityRenderObject*>(coreObject); 2094 2197 RenderObject* renderer = axRenderObject->renderer(); 2095 if (role != TableRole && renderer && renderer->childrenInline()) 2096 interfaceMask |= 1 << WAI_TEXT; 2097 else if (role == ListItemRole) { 2098 // Add the TEXT interface for list items whose 2099 // first accessible child has a text renderer 2198 if (role != TableRole) { 2199 interfaceMask |= 1 << WAI_HYPERTEXT; 2200 if (renderer && renderer->childrenInline()) 2201 interfaceMask |= 1 << WAI_TEXT; 2202 } 2203 2204 // Add the TEXT interface for list items whose 2205 // first accessible child has a text renderer 2206 if (role == ListItemRole) { 2100 2207 AccessibilityObject::AccessibilityChildrenVector children = axRenderObject->children(); 2101 2208 if (children.size()) { … … 2105 2212 } 2106 2213 } 2214 } 2107 2215 2108 2216 // Image -
trunk/WebKit/gtk/ChangeLog
r70983 r71026 1 2010-11-01 Mario Sanchez Prada <msanchez@igalia.com> 2 3 Reviewed by Martin Robinson. 4 5 [Gtk] AtkHyperlink needs to be implemented 6 https://bugs.webkit.org/show_bug.cgi?id=33785 7 8 New test to ensure the AtkHypertext/AtkHyperlink stuff works. 9 10 * tests/testatk.c: 11 (testWebkitAtkHypertextAndHyperlinks): New test, checking both the 12 implementation of the AtkHypertext interface, the subclass of the 13 AtkHyperlink abstract class, and the implementation of the 14 AtkAction interface in that subclass. 15 (main): Added the new unit test. 16 1 17 2010-10-30 Xan Lopez <xlopez@igalia.com> 2 18 -
trunk/WebKit/gtk/tests/testatk.c
r70639 r71026 47 47 static const char* formWithTextInputs = "<html><body><form><input type='text' name='entry' /></form></body></html>"; 48 48 49 static const char* hypertextAndHyperlinks = "<html><body><p>A paragraph with no links at all</p><p><a href='http://foo.bar.baz/'>A line</a> with <a href='http://bar.baz.foo/'>a link in the middle</a> as well as at the beginning and <a href='http://baz.foo.bar/'>at the end</a></p></body></html>"; 50 49 51 static const char* layoutAndDataTables = "<html><body><table><tr><th>Odd</th><th>Even</th></tr><tr><td>1</td><td>2</td></tr></table><table><tr><td>foo</td><td>bar</td></tr></table></body></html>"; 50 52 … … 1071 1073 } 1072 1074 1075 static void testWebkitAtkHypertextAndHyperlinks(void) 1076 { 1077 WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); 1078 g_object_ref_sink(webView); 1079 GtkAllocation alloc = { 0, 0, 800, 600 }; 1080 gtk_widget_size_allocate(GTK_WIDGET(webView), &alloc); 1081 webkit_web_view_load_string(webView, hypertextAndHyperlinks, 0, 0, 0); 1082 1083 // Manually spin the main context to get the accessible objects 1084 while (g_main_context_pending(0)) 1085 g_main_context_iteration(0, TRUE); 1086 1087 AtkObject* obj = gtk_widget_get_accessible(GTK_WIDGET(webView)); 1088 g_assert(obj); 1089 1090 AtkObject* paragraph1 = atk_object_ref_accessible_child(obj, 0); 1091 g_assert(ATK_OBJECT(paragraph1)); 1092 g_assert(atk_object_get_role(paragraph1) == ATK_ROLE_PARAGRAPH); 1093 g_assert(ATK_IS_HYPERTEXT(paragraph1)); 1094 1095 // No links in the first paragraph 1096 gint nLinks = atk_hypertext_get_n_links(ATK_HYPERTEXT(paragraph1)); 1097 g_assert_cmpint(nLinks, ==, 0); 1098 1099 AtkObject* paragraph2 = atk_object_ref_accessible_child(obj, 1); 1100 g_assert(ATK_OBJECT(paragraph2)); 1101 g_assert(atk_object_get_role(paragraph2) == ATK_ROLE_PARAGRAPH); 1102 g_assert(ATK_IS_HYPERTEXT(paragraph2)); 1103 1104 // Check links in the second paragraph 1105 nLinks = atk_hypertext_get_n_links(ATK_HYPERTEXT(paragraph2)); 1106 g_assert_cmpint(nLinks, ==, 3); 1107 1108 AtkHyperlink* hLink1 = atk_hypertext_get_link(ATK_HYPERTEXT(paragraph2), 0); 1109 g_assert(ATK_HYPERLINK(hLink1)); 1110 AtkObject* hLinkObject1 = atk_hyperlink_get_object(hLink1, 0); 1111 g_assert(ATK_OBJECT(hLinkObject1)); 1112 g_assert(atk_object_get_role(hLinkObject1) == ATK_ROLE_LINK); 1113 g_assert_cmpint(atk_hyperlink_get_start_index(hLink1), ==, 0); 1114 g_assert_cmpint(atk_hyperlink_get_end_index(hLink1), ==, 6); 1115 g_assert_cmpint(atk_hyperlink_get_n_anchors(hLink1), ==, 1); 1116 g_assert_cmpstr(atk_hyperlink_get_uri(hLink1, 0), ==, "http://foo.bar.baz/"); 1117 1118 AtkHyperlink* hLink2 = atk_hypertext_get_link(ATK_HYPERTEXT(paragraph2), 1); 1119 g_assert(ATK_HYPERLINK(hLink2)); 1120 AtkObject* hLinkObject2 = atk_hyperlink_get_object(hLink2, 0); 1121 g_assert(ATK_OBJECT(hLinkObject2)); 1122 g_assert(atk_object_get_role(hLinkObject2) == ATK_ROLE_LINK); 1123 g_assert_cmpint(atk_hyperlink_get_start_index(hLink2), ==, 12); 1124 g_assert_cmpint(atk_hyperlink_get_end_index(hLink2), ==, 32); 1125 g_assert_cmpint(atk_hyperlink_get_n_anchors(hLink2), ==, 1); 1126 g_assert_cmpstr(atk_hyperlink_get_uri(hLink2, 0), ==, "http://bar.baz.foo/"); 1127 1128 AtkHyperlink* hLink3 = atk_hypertext_get_link(ATK_HYPERTEXT(paragraph2), 2); 1129 g_assert(ATK_HYPERLINK(hLink3)); 1130 AtkObject* hLinkObject3 = atk_hyperlink_get_object(hLink3, 0); 1131 g_assert(ATK_OBJECT(hLinkObject3)); 1132 g_assert(atk_object_get_role(hLinkObject3) == ATK_ROLE_LINK); 1133 g_assert_cmpint(atk_hyperlink_get_start_index(hLink3), ==, 65); 1134 g_assert_cmpint(atk_hyperlink_get_end_index(hLink3), ==, 75); 1135 g_assert_cmpint(atk_hyperlink_get_n_anchors(hLink3), ==, 1); 1136 g_assert_cmpstr(atk_hyperlink_get_uri(hLink3, 0), ==, "http://baz.foo.bar/"); 1137 1138 // Finally check the AtkAction interface for a given AtkHyperlink 1139 g_assert(ATK_IS_ACTION(hLink1)); 1140 g_assert_cmpint(atk_action_get_n_actions(ATK_ACTION(hLink1)), ==, 1); 1141 g_assert_cmpstr(atk_action_get_keybinding(ATK_ACTION(hLink1), 0), ==, ""); 1142 g_assert_cmpstr(atk_action_get_name(ATK_ACTION(hLink1), 0), ==, "jump"); 1143 g_assert(atk_action_do_action(ATK_ACTION(hLink1), 0)); 1144 1145 g_object_unref(paragraph1); 1146 g_object_unref(paragraph2); 1147 g_object_unref(webView); 1148 } 1149 1073 1150 static void testWebkitAtkListsOfItems(void) 1074 1151 { … … 1223 1300 g_test_add_func("/webkit/atk/textSelections", testWekitAtkTextSelections); 1224 1301 g_test_add_func("/webkit/atk/getExtents", testWebkitAtkGetExtents); 1302 g_test_add_func("/webkit/atk/hypertextAndHyperlinks", testWebkitAtkHypertextAndHyperlinks); 1225 1303 g_test_add_func("/webkit/atk/layoutAndDataTables", testWebkitAtkLayoutAndDataTables); 1226 1304 g_test_add_func("/webkit/atk/linksWithInlineImages", testWebkitAtkLinksWithInlineImages);
Note: See TracChangeset
for help on using the changeset viewer.