Changeset 62164 in webkit
- Timestamp:
- Jun 30, 2010 1:12:01 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r62163 r62164 1 2010-06-30 José Millán Soto <jmillan@igalia.com> 2 3 Reviewed by Xan Lopez. 4 5 [Gtk] Text attributes not exposed 6 https://bugs.webkit.org/show_bug.cgi?id=25528 7 8 Implemented the get_run_attributes and get_default_attributes 9 functions for the ATK_TEXT role. 10 11 * accessibility/gtk/AccessibilityObjectWrapperAtk.cpp: 12 (getAttributeSetForAccessibilityObject): 13 (compareAttribute): 14 (attributeSetDifference): 15 (accessibilityObjectLength): 16 (getAccessibilityObjectForOffset): 17 (getRunAttributesFromAccesibilityObject): 18 (webkit_accessible_text_get_run_attributes): 19 (webkit_accessible_text_get_default_attributes): 20 1 21 2010-06-30 Yuta Kitamura <yutak@chromium.org> 2 22 -
trunk/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp
r61884 r62164 48 48 #include "Frame.h" 49 49 #include "FrameView.h" 50 #include "GOwnPtr.h" 50 51 #include "HostWindow.h" 51 52 #include "HTMLNames.h" … … 1006 1007 } 1007 1008 1008 static AtkAttributeSet* webkit_accessible_text_get_run_attributes(AtkText* text, gint offset, gint* start_offset, gint* end_offset) 1009 { 1010 notImplemented(); 1011 return 0; 1009 static AtkAttributeSet* getAttributeSetForAccessibilityObject(const AccessibilityObject* object) 1010 { 1011 if (!object->isAccessibilityRenderObject()) 1012 return 0; 1013 1014 RenderObject* renderer = static_cast<const AccessibilityRenderObject*>(object)->renderer(); 1015 RenderStyle* style = renderer->style(); 1016 1017 AtkAttributeSet* result = 0; 1018 GOwnPtr<gchar> buffer(g_strdup_printf("%i", style->fontSize())); 1019 result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_SIZE), buffer.get()); 1020 1021 Color bgColor = style->visitedDependentColor(CSSPropertyBackgroundColor); 1022 if (bgColor.isValid()) { 1023 buffer.set(g_strdup_printf("%i,%i,%i", 1024 bgColor.red(), bgColor.green(), bgColor.blue())); 1025 result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_BG_COLOR), buffer.get()); 1026 } 1027 1028 Color fgColor = style->visitedDependentColor(CSSPropertyColor); 1029 if (fgColor.isValid()) { 1030 buffer.set(g_strdup_printf("%i,%i,%i", 1031 fgColor.red(), fgColor.green(), fgColor.blue())); 1032 result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_FG_COLOR), buffer.get()); 1033 } 1034 1035 int baselinePosition; 1036 bool includeRise = true; 1037 switch (style->verticalAlign()) { 1038 case SUB: 1039 baselinePosition = -1 * renderer->baselinePosition(true); 1040 break; 1041 case SUPER: 1042 baselinePosition = renderer->baselinePosition(true); 1043 break; 1044 case BASELINE: 1045 baselinePosition = 0; 1046 break; 1047 default: 1048 includeRise = false; 1049 break; 1050 } 1051 1052 if (includeRise) { 1053 buffer.set(g_strdup_printf("%i", baselinePosition)); 1054 result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_RISE), buffer.get()); 1055 } 1056 1057 int indentation = style->textIndent().calcValue(object->size().width()); 1058 if (indentation != undefinedLength) { 1059 buffer.set(g_strdup_printf("%i", indentation)); 1060 result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_INDENT), buffer.get()); 1061 } 1062 1063 String fontFamilyName = style->font().family().family().string(); 1064 if (fontFamilyName.left(8) == "-webkit-") 1065 fontFamilyName = fontFamilyName.substring(8); 1066 1067 result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_FAMILY_NAME), fontFamilyName.utf8().data()); 1068 1069 int fontWeight = -1; 1070 switch (style->font().weight()) { 1071 case FontWeight100: 1072 fontWeight = 100; 1073 break; 1074 case FontWeight200: 1075 fontWeight = 200; 1076 break; 1077 case FontWeight300: 1078 fontWeight = 300; 1079 break; 1080 case FontWeight400: 1081 fontWeight = 400; 1082 break; 1083 case FontWeight500: 1084 fontWeight = 500; 1085 break; 1086 case FontWeight600: 1087 fontWeight = 600; 1088 break; 1089 case FontWeight700: 1090 fontWeight = 700; 1091 break; 1092 case FontWeight800: 1093 fontWeight = 800; 1094 break; 1095 case FontWeight900: 1096 fontWeight = 900; 1097 } 1098 if (fontWeight > 0) { 1099 buffer.set(g_strdup_printf("%i", fontWeight)); 1100 result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_WEIGHT), buffer.get()); 1101 } 1102 1103 switch (style->textAlign()) { 1104 case TAAUTO: 1105 break; 1106 case LEFT: 1107 case WEBKIT_LEFT: 1108 result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_JUSTIFICATION), "left"); 1109 break; 1110 case RIGHT: 1111 case WEBKIT_RIGHT: 1112 result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_JUSTIFICATION), "right"); 1113 break; 1114 case CENTER: 1115 case WEBKIT_CENTER: 1116 result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_JUSTIFICATION), "center"); 1117 break; 1118 case JUSTIFY: 1119 result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_JUSTIFICATION), "fill"); 1120 } 1121 1122 result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_UNDERLINE), (style->textDecoration() & UNDERLINE) ? "single" : "none"); 1123 1124 result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_STYLE), style->font().italic() ? "italic" : "normal"); 1125 1126 result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_STRIKETHROUGH), (style->textDecoration() & LINE_THROUGH) ? "true" : "false"); 1127 1128 result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_INVISIBLE), (style->visibility() == HIDDEN) ? "true" : "false"); 1129 1130 result = addAttributeToSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_EDITABLE), object->isReadOnly() ? "false" : "true"); 1131 1132 return result; 1133 } 1134 1135 static gint compareAttribute(const AtkAttribute* a, const AtkAttribute* b) 1136 { 1137 return g_strcmp0(a->name, b->name) || g_strcmp0(a->value, b->value); 1138 } 1139 1140 // Returns an AtkAttributeSet with the elements of a1 which are either 1141 // not present or different in a2. Neither a1 nor a2 should be used 1142 // after calling this function. 1143 static AtkAttributeSet* attributeSetDifference(AtkAttributeSet* a1, AtkAttributeSet* a2) 1144 { 1145 if (!a2) 1146 return a1; 1147 1148 AtkAttributeSet* i = a1; 1149 AtkAttributeSet* found; 1150 AtkAttributeSet* toDelete = 0; 1151 1152 while (i) { 1153 found = g_slist_find_custom(a2, i->data, (GCompareFunc)compareAttribute); 1154 if (found) { 1155 AtkAttributeSet* t = i->next; 1156 toDelete = g_slist_prepend(toDelete, i->data); 1157 a1 = g_slist_delete_link(a1, i); 1158 i = t; 1159 } else 1160 i = i->next; 1161 } 1162 1163 atk_attribute_set_free(a2); 1164 atk_attribute_set_free(toDelete); 1165 return a1; 1166 } 1167 1168 static guint accessibilityObjectLength(const AccessibilityObject* object) 1169 { 1170 GOwnPtr<gchar> text(webkit_accessible_text_get_text(ATK_TEXT(object->wrapper()), 0, -1)); 1171 return g_utf8_strlen(text.get(), -1); 1172 } 1173 1174 static const AccessibilityObject* getAccessibilityObjectForOffset(const AccessibilityObject* object, guint offset, gint* startOffset, gint* endOffset) 1175 { 1176 const AccessibilityObject* result; 1177 guint length = accessibilityObjectLength(object); 1178 if (length > offset) { 1179 *startOffset = 0; 1180 *endOffset = length; 1181 result = object; 1182 } else { 1183 *startOffset = -1; 1184 *endOffset = -1; 1185 result = 0; 1186 } 1187 1188 if (!object->firstChild()) 1189 return result; 1190 1191 AccessibilityObject* child = object->firstChild(); 1192 guint currentOffset = 0; 1193 guint childPosition = 0; 1194 while (child && currentOffset <= offset) { 1195 guint childLength = accessibilityObjectLength(child); 1196 currentOffset = childLength + childPosition; 1197 if (currentOffset > offset) { 1198 gint childStartOffset; 1199 gint childEndOffset; 1200 const AccessibilityObject* grandChild = getAccessibilityObjectForOffset(child, offset-childPosition, &childStartOffset, &childEndOffset); 1201 if (childStartOffset >= 0) { 1202 *startOffset = childStartOffset + childPosition; 1203 *endOffset = childEndOffset + childPosition; 1204 result = grandChild; 1205 } 1206 } else { 1207 childPosition += childLength; 1208 child = child->nextSibling(); 1209 } 1210 } 1211 return result; 1212 } 1213 1214 static AtkAttributeSet* getRunAttributesFromAccesibilityObject(const AccessibilityObject* element, gint offset, gint* startOffset, gint* endOffset) 1215 { 1216 const AccessibilityObject *child = getAccessibilityObjectForOffset(element, offset, startOffset, endOffset); 1217 if (!child) { 1218 *startOffset = -1; 1219 *endOffset = -1; 1220 return 0; 1221 } 1222 1223 AtkAttributeSet* defaultAttributes = getAttributeSetForAccessibilityObject(element); 1224 AtkAttributeSet* childAttributes = getAttributeSetForAccessibilityObject(child); 1225 1226 return attributeSetDifference(childAttributes, defaultAttributes); 1227 } 1228 1229 static AtkAttributeSet* webkit_accessible_text_get_run_attributes(AtkText* text, gint offset, gint* startOffset, gint* endOffset) 1230 { 1231 AccessibilityObject* coreObject = core(text); 1232 AtkAttributeSet* result; 1233 1234 if (!coreObject) { 1235 *startOffset = 0; 1236 *endOffset = atk_text_get_character_count(text); 1237 return 0; 1238 } 1239 1240 if (offset == -1) 1241 offset = atk_text_get_caret_offset(text); 1242 1243 result = getRunAttributesFromAccesibilityObject(coreObject, offset, startOffset, endOffset); 1244 1245 if (*startOffset < 0) { 1246 *startOffset = offset; 1247 *endOffset = offset; 1248 } 1249 1250 return result; 1012 1251 } 1013 1252 1014 1253 static AtkAttributeSet* webkit_accessible_text_get_default_attributes(AtkText* text) 1015 1254 { 1016 notImplemented(); 1017 return 0; 1255 AccessibilityObject* coreObject = core(text); 1256 if (!coreObject || !coreObject->isAccessibilityRenderObject()) 1257 return 0; 1258 1259 return getAttributeSetForAccessibilityObject(coreObject); 1018 1260 } 1019 1261 -
trunk/WebKit/gtk/ChangeLog
r62027 r62164 1 2010-06-30 José Millán Soto <jmillan@igalia.com> 2 3 Reviewed by Xan Lopez. 4 5 [Gtk] Text attributes not exposed 6 https://bugs.webkit.org/show_bug.cgi?id=25528 7 8 Added new tests for accessible text attributes 9 10 * tests/testatk.c: 11 (compAtkAttribute): 12 (compAtkAttributeName): 13 (atkAttributeSetAttributeHasValue): 14 (atkAttributeSetAreEqual): 15 (testWebkitAtkTextAttributes): 16 (main): 17 1 18 2010-06-28 Xan Lopez <xlopez@igalia.com> 2 19 -
trunk/WebKit/gtk/tests/testatk.c
r61893 r62164 43 43 static const char* contentsInTableWithHeaders = "<html><body><table><tr><th>foo</th><th>bar</th><th colspan='2'>baz</th></tr><tr><th>qux</th><td>1</td><td>2</td><td>3</td></tr><tr><th rowspan='2'>quux</th><td>4</td><td>5</td><td>6</td></tr><tr><td>6</td><td>7</td><td>8</td></tr><tr><th>corge</th><td>9</td><td>10</td><td>11</td></tr></table><table><tr><td>1</td><td>2</td></tr><tr><td>3</td><td>4</td></tr></table></body></html>"; 44 44 45 static const char* textWithAttributes = "<html><head><style>.st1 {font-family: monospace; color:rgb(120,121,122);} .st2 {text-decoration:underline; background-color:rgb(80,81,82);}</style></head><body><p style=\"font-size:14; text-align:right;\">This is the <i>first</i><b> sentence of this text.</b></p><p class=\"st1\">This sentence should have an style applied <span class=\"st2\">and this part should have another one</span>.</p><p>x<sub>1</sub><sup>2</sup>=x<sub>2</sub><sup>3</sup></p><p style=\"text-align:center;\">This sentence is the <strike>last</strike> one.</p></body></html>"; 46 45 47 static gboolean bail_out(GMainLoop* loop) 46 48 { … … 571 573 g_object_unref(table); 572 574 g_object_unref(webView); 575 } 576 577 static gint compAtkAttribute(AtkAttribute* a1, AtkAttribute* a2) 578 { 579 gint strcmpVal; 580 strcmpVal = g_strcmp0(a1->name, a2->name); 581 if (strcmpVal) 582 return strcmpVal; 583 return g_strcmp0(a1->value, a2->value); 584 } 585 586 static gint compAtkAttributeName(AtkAttribute* a1, AtkAttribute* a2) 587 { 588 return g_strcmp0(a1->name, a2->name); 589 } 590 591 static gboolean atkAttributeSetAttributeHasValue(AtkAttributeSet* set, AtkTextAttribute attribute, const gchar* value) 592 { 593 GSList *element; 594 AtkAttribute at; 595 gboolean result; 596 at.name = (gchar *)atk_text_attribute_get_name(attribute); 597 element = g_slist_find_custom(set, &at, (GCompareFunc)compAtkAttributeName); 598 result = element && !g_strcmp0(((AtkAttribute*)(element->data))->value, value); 599 return result; 600 } 601 602 static gboolean atkAttributeSetAreEqual(AtkAttributeSet* set1, AtkAttributeSet* set2) 603 { 604 if (!set1) 605 return !set2; 606 607 set1 = g_slist_sort(set1, (GCompareFunc)compAtkAttribute); 608 set2 = g_slist_sort(set2, (GCompareFunc)compAtkAttribute); 609 610 while (set1) { 611 if (!set2 || compAtkAttribute(set1->data, set2->data)) 612 return FALSE; 613 614 set1 = set1->next; 615 set2 = set2->next; 616 } 617 618 return (!set2); 619 } 620 621 static void testWebkitAtkTextAttributes(void) 622 { 623 WebKitWebView* webView; 624 AtkObject* obj; 625 AtkObject* child; 626 GMainLoop* loop; 627 AtkText* childText; 628 AtkAttributeSet* set1; 629 AtkAttributeSet* set2; 630 AtkAttributeSet* set3; 631 AtkAttributeSet* set4; 632 gint startOffset, endOffset; 633 634 webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); 635 g_object_ref_sink(webView); 636 GtkAllocation alloc = { 0, 0, 800, 600 }; 637 gtk_widget_size_allocate(GTK_WIDGET(webView), &alloc); 638 639 webkit_web_view_load_string(webView, textWithAttributes, NULL, NULL, NULL); 640 loop = g_main_loop_new(NULL, TRUE); 641 642 g_idle_add((GSourceFunc)bail_out, loop); 643 g_main_loop_run(loop); 644 645 obj = gtk_widget_get_accessible(GTK_WIDGET(webView)); 646 g_assert(obj); 647 648 child = atk_object_ref_accessible_child(obj, 0); 649 g_assert(child && ATK_IS_TEXT(child)); 650 childText = ATK_TEXT(child); 651 set1 = atk_text_get_run_attributes(childText, 0, &startOffset, &endOffset); 652 g_assert_cmpint(startOffset, ==, 0); 653 g_assert_cmpint(endOffset, ==, 12); 654 g_assert(atkAttributeSetAreEqual(set1, NULL)); 655 656 set2 = atk_text_get_run_attributes(childText, 15, &startOffset, &endOffset); 657 g_assert_cmpint(startOffset, ==, 12); 658 g_assert_cmpint(endOffset, ==, 17); 659 g_assert(atkAttributeSetAttributeHasValue(set2, ATK_TEXT_ATTR_STYLE, "italic")); 660 661 set3 = atk_text_get_run_attributes(childText, 17, &startOffset, &endOffset); 662 g_assert_cmpint(startOffset, ==, 17); 663 g_assert_cmpint(endOffset, ==, 40); 664 g_assert(atkAttributeSetAttributeHasValue(set3, ATK_TEXT_ATTR_WEIGHT, "700")); 665 666 set4 = atk_text_get_default_attributes(childText); 667 g_assert(atkAttributeSetAttributeHasValue(set4, ATK_TEXT_ATTR_STYLE, "normal")); 668 g_assert(atkAttributeSetAttributeHasValue(set4, ATK_TEXT_ATTR_JUSTIFICATION, "right")); 669 g_assert(atkAttributeSetAttributeHasValue(set4, ATK_TEXT_ATTR_SIZE, "14")); 670 atk_attribute_set_free(set1); 671 atk_attribute_set_free(set2); 672 atk_attribute_set_free(set3); 673 atk_attribute_set_free(set4); 674 675 child = atk_object_ref_accessible_child(obj, 1); 676 g_assert(child && ATK_IS_TEXT(child)); 677 childText = ATK_TEXT(child); 678 679 set1 = atk_text_get_default_attributes(childText); 680 g_assert(atkAttributeSetAttributeHasValue(set1, ATK_TEXT_ATTR_FAMILY_NAME, "monospace")); 681 g_assert(atkAttributeSetAttributeHasValue(set1, ATK_TEXT_ATTR_STYLE, "normal")); 682 g_assert(atkAttributeSetAttributeHasValue(set1, ATK_TEXT_ATTR_STRIKETHROUGH, "false")); 683 g_assert(atkAttributeSetAttributeHasValue(set1, ATK_TEXT_ATTR_WEIGHT, "400")); 684 g_assert(atkAttributeSetAttributeHasValue(set1, ATK_TEXT_ATTR_FG_COLOR, "120,121,122")); 685 686 set2 = atk_text_get_run_attributes(childText, 43, &startOffset, &endOffset); 687 g_assert_cmpint(startOffset, ==, 43); 688 g_assert_cmpint(endOffset, ==, 80); 689 // Checks that default attributes of text are not returned when called to atk_text_get_run_attributes 690 g_assert(!atkAttributeSetAttributeHasValue(set2, ATK_TEXT_ATTR_FG_COLOR, "120,121,122")); 691 g_assert(atkAttributeSetAttributeHasValue(set2, ATK_TEXT_ATTR_UNDERLINE, "single")); 692 g_assert(atkAttributeSetAttributeHasValue(set2, ATK_TEXT_ATTR_BG_COLOR, "80,81,82")); 693 atk_attribute_set_free(set1); 694 atk_attribute_set_free(set2); 695 696 child = atk_object_ref_accessible_child(obj, 2); 697 g_assert(child && ATK_IS_TEXT(child)); 698 childText = ATK_TEXT(child); 699 700 set1 = atk_text_get_run_attributes(childText, 0, &startOffset, &endOffset); 701 set2 = atk_text_get_run_attributes(childText, 3, &startOffset, &endOffset); 702 g_assert(atkAttributeSetAreEqual(set1, set2)); 703 atk_attribute_set_free(set2); 704 705 set2 = atk_text_get_run_attributes(childText, 1, &startOffset, &endOffset); 706 set3 = atk_text_get_run_attributes(childText, 5, &startOffset, &endOffset); 707 g_assert(atkAttributeSetAreEqual(set2, set3)); 708 g_assert(!atkAttributeSetAreEqual(set1, set2)); 709 atk_attribute_set_free(set3); 710 711 set3 = atk_text_get_run_attributes(childText, 2, &startOffset, &endOffset); 712 set4 = atk_text_get_run_attributes(childText, 6, &startOffset, &endOffset); 713 g_assert(atkAttributeSetAreEqual(set3, set4)); 714 g_assert(!atkAttributeSetAreEqual(set1, set3)); 715 g_assert(!atkAttributeSetAreEqual(set2, set3)); 716 atk_attribute_set_free(set1); 717 atk_attribute_set_free(set2); 718 atk_attribute_set_free(set3); 719 atk_attribute_set_free(set4); 720 721 child = atk_object_ref_accessible_child(obj, 3); 722 g_assert(child && ATK_IS_TEXT(child)); 723 childText = ATK_TEXT(child); 724 set1 = atk_text_get_run_attributes(childText, 24, &startOffset, &endOffset); 725 g_assert_cmpint(startOffset, ==, 21); 726 g_assert_cmpint(endOffset, ==, 25); 727 g_assert(atkAttributeSetAttributeHasValue(set1, ATK_TEXT_ATTR_STRIKETHROUGH, "true")); 728 729 set2 = atk_text_get_run_attributes(childText, 25, &startOffset, &endOffset); 730 g_assert_cmpint(startOffset, ==, 25); 731 g_assert_cmpint(endOffset, ==, 30); 732 g_assert(atkAttributeSetAreEqual(set2, NULL)); 733 734 set3 = atk_text_get_default_attributes(childText); 735 g_assert(atkAttributeSetAttributeHasValue(set3, ATK_TEXT_ATTR_JUSTIFICATION, "center")); 736 atk_attribute_set_free(set1); 737 atk_attribute_set_free(set2); 738 atk_attribute_set_free(set3); 573 739 } 574 740 … … 588 754 g_test_add_func("/webkit/atk/getTextInTable", testWebkitAtkGetTextInTable); 589 755 g_test_add_func("/webkit/atk/getHeadersInTable", testWebkitAtkGetHeadersInTable); 756 g_test_add_func("/webkit/atk/textAttributes", testWebkitAtkTextAttributes); 590 757 return g_test_run (); 591 758 }
Note: See TracChangeset
for help on using the changeset viewer.