Changeset 78978 in webkit
- Timestamp:
- Feb 18, 2011 1:40:56 AM (13 years ago)
- Location:
- trunk/Source
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r78974 r78978 1 2011-02-18 Mario Sanchez Prada <msanchez@igalia.com> 2 3 Reviewed by Martin Robinson. 4 5 [Gtk] atk_text_get_selection/atk_text_set_selection fails for list items 6 https://bugs.webkit.org/show_bug.cgi?id=53453 7 8 Ensure that atk_text_{get|set}_selection() work with list items. 9 10 * accessibility/gtk/AccessibilityObjectWrapperAtk.cpp: 11 (webkit_accessible_text_get_text): Properly handle list item 12 markers when returning the text for an object for a given interval 13 specified through the startOffset and endOffset parameters. 14 (getSelectionOffsetsForObject): Bear in mind list item markers 15 when returning the offsets for a selection over a list item. 16 (webkit_accessible_text_set_selection): Adjust offsets if needed 17 for list items with item markers. Ensure that it returns TRUE only 18 when everything went fine setting the text selection. 19 1 20 2011-02-18 Antti Koivisto <antti@apple.com> 2 21 -
trunk/Source/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp
r78789 r78978 1123 1123 { 1124 1124 AccessibilityObject* coreObject = core(text); 1125 1126 int end = endOffset; 1127 if (endOffset == -1) { 1128 end = coreObject->stringValue().length(); 1129 if (!end) 1130 end = coreObject->textUnderElement().length(); 1131 } 1132 1125 1133 String ret; 1126 unsigned start = startOffset;1127 if (endOffset == -1) {1128 endOffset = coreObject->stringValue().length();1129 if (!endOffset)1130 endOffset = coreObject->textUnderElement().length();1131 }1132 int length = endOffset - startOffset;1133 1134 1134 if (coreObject->isTextControl()) 1135 ret = coreObject->doAXStringForRange(PlainTextRange( start, length));1135 ret = coreObject->doAXStringForRange(PlainTextRange(0, endOffset)); 1136 1136 else { 1137 ret = coreObject->stringValue() .substring(start, length);1137 ret = coreObject->stringValue(); 1138 1138 if (!ret) 1139 ret = coreObject->textUnderElement() .substring(start, length);1139 ret = coreObject->textUnderElement(); 1140 1140 } 1141 1141 1142 1142 if (!ret.length()) { 1143 1143 // This can happen at least with anonymous RenderBlocks (e.g. body text amongst paragraphs) 1144 ret = String(textForObject(static_cast<AccessibilityRenderObject*>(coreObject))); 1145 if (!endOffset) 1146 endOffset = ret.length(); 1147 ret = ret.substring(start, endOffset - startOffset); 1144 ret = String(textForObject(toAccessibilityRenderObject(coreObject))); 1145 if (!end) 1146 end = ret.length(); 1148 1147 } 1149 1148 … … 1154 1153 String markerText = toRenderListItem(objRenderer)->markerTextWithSuffix(); 1155 1154 ret = objRenderer->style()->direction() == LTR ? markerText + ret : ret + markerText; 1155 if (endOffset == -1) 1156 end += markerText.length(); 1156 1157 } 1157 1158 } 1158 1159 1160 ret = ret.substring(startOffset, end - startOffset); 1159 1161 return g_strdup(ret.utf8().data()); 1160 1162 } … … 1629 1631 // Set values for start and end offsets. 1630 1632 startOffset = TextIterator::rangeLength(rangeInParent.get()); 1633 1634 // We need to adjust the offsets for the list item marker. 1635 RenderObject* renderer = toAccessibilityRenderObject(coreObject)->renderer(); 1636 if (renderer && renderer->isListItem()) { 1637 String markerText = toRenderListItem(renderer)->markerTextWithSuffix(); 1638 startOffset += markerText.length(); 1639 } 1640 1631 1641 RefPtr<Range> nodeRange = Range::create(node->document(), nodeRangeStart, nodeRangeEnd); 1632 1642 endOffset = startOffset + TextIterator::rangeLength(nodeRange.get()); … … 1685 1695 return FALSE; 1686 1696 1697 AccessibilityObject* coreObject = core(text); 1698 if (!coreObject->isAccessibilityRenderObject()) 1699 return FALSE; 1700 1687 1701 // Consider -1 and out-of-bound values and correct them to length 1688 1702 gint textCount = webkit_accessible_text_get_character_count(text); … … 1692 1706 endOffset = textCount; 1693 1707 1694 AccessibilityObject* coreObject = core(text); 1708 // We need to adjust the offsets for the list item marker. 1709 RenderObject* renderer = toAccessibilityRenderObject(coreObject)->renderer(); 1710 if (renderer && renderer->isListItem()) { 1711 String markerText = toRenderListItem(renderer)->markerTextWithSuffix(); 1712 int markerLength = markerText.length(); 1713 if (startOffset < markerLength || endOffset < markerLength) 1714 return FALSE; 1715 1716 startOffset -= markerLength; 1717 endOffset -= markerLength; 1718 } 1719 1695 1720 PlainTextRange textRange(startOffset, endOffset - startOffset); 1696 1721 VisiblePositionRange range = coreObject->visiblePositionRangeForRange(textRange); 1722 if (range.isNull()) 1723 return FALSE; 1724 1697 1725 coreObject->setSelectedVisiblePositionRange(range); 1698 1699 1726 return TRUE; 1700 1727 } -
trunk/Source/WebKit/gtk/ChangeLog
r78925 r78978 1 2011-02-18 Mario Sanchez Prada <msanchez@igalia.com> 2 3 Reviewed by Martin Robinson. 4 5 [Gtk] atk_text_get_selection/atk_text_set_selection fails for list items 6 https://bugs.webkit.org/show_bug.cgi?id=53453 7 8 Update unit test to check the fix for this bug. 9 10 * tests/testatk.c: 11 (testWebkitAtkTextSelections): Check that functions from AtkText 12 interface to set and get text selections work with list items. 13 1 14 2011-02-17 Robert Ancell <rober.ancell@gmail.com> 2 15 -
trunk/Source/WebKit/gtk/tests/testatk.c
r77817 r78978 63 63 static const char* textForCaretBrowsing = "<html><body><h1>A text header</h1><p>A paragraph <a href='http://foo.bar.baz/'>with a link</a> in the middle</p><ol><li>A list item</li></ol><select><option selected value='foo'>An option in a combo box</option></select></body></html>"; 64 64 65 static const char* textForSelections = "<html><body><p>A paragraph with plain text</p><p>A paragraph with <a href='http://webkit.org'>a link</a> in the middle</p>< /body></html>";65 static const char* textForSelections = "<html><body><p>A paragraph with plain text</p><p>A paragraph with <a href='http://webkit.org'>a link</a> in the middle</p><ol><li>A list item</li></ol><select></body></html>"; 66 66 67 67 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>"; … … 997 997 AtkText* paragraph1 = ATK_TEXT(atk_object_ref_accessible_child(object, 0)); 998 998 g_assert(ATK_IS_TEXT(paragraph1)); 999 999 1000 AtkText* paragraph2 = ATK_TEXT(atk_object_ref_accessible_child(object, 1)); 1000 1001 g_assert(ATK_IS_TEXT(paragraph2)); 1002 1001 1003 AtkText* link = ATK_TEXT(atk_object_ref_accessible_child(ATK_OBJECT(paragraph2), 0)); 1002 1004 g_assert(ATK_IS_TEXT(link)); 1005 1006 AtkObject* list = atk_object_ref_accessible_child(object, 2); 1007 g_assert(ATK_OBJECT(list)); 1008 1009 AtkText* listItem = ATK_TEXT(atk_object_ref_accessible_child(list, 0)); 1010 g_assert(ATK_IS_TEXT(listItem)); 1003 1011 1004 1012 /* First paragraph (simple text). */ … … 1097 1105 g_free (selectedText); 1098 1106 1107 /* List item */ 1108 1109 g_assert(atk_object_get_role(list) == ATK_ROLE_LIST); 1110 g_assert_cmpint(atk_object_get_n_accessible_children(list), ==, 1); 1111 1112 gchar* text = atk_text_get_text(listItem, 0, -1); 1113 g_assert_cmpstr(text, ==, "1. A list item"); 1114 g_free (text); 1115 1116 /* It's not possible to select text inside an item's marker. */ 1117 result = atk_text_set_selection (listItem, 0, 0, 9); 1118 g_assert(!result); 1119 result = atk_text_set_selection (listItem, 0, 9, 1); 1120 g_assert(!result); 1121 1122 /* It should be possible to select text inside an item's text. */ 1123 result = atk_text_set_selection (listItem, 0, 3, 9); 1124 g_assert(result); 1125 1126 g_assert_cmpint(atk_text_get_n_selections(listItem), ==, 1); 1127 selectedText = atk_text_get_selection(listItem, 0, &startOffset, &endOffset); 1128 g_assert_cmpint(startOffset, ==, 3); 1129 g_assert_cmpint(endOffset, ==, 9); 1130 g_assert_cmpstr(selectedText, ==, "A list"); 1131 g_free (selectedText); 1132 1099 1133 g_object_unref(paragraph1); 1100 1134 g_object_unref(paragraph2); 1135 g_object_unref(list); 1136 g_object_unref(listItem); 1101 1137 g_object_unref(webView); 1102 1138 }
Note: See TracChangeset
for help on using the changeset viewer.