Title: [157628] trunk/Source/WebCore
Revision
157628
Author
[email protected]
Date
2013-10-18 03:15:13 -0700 (Fri, 18 Oct 2013)

Log Message

[ATK] Simplify implementation of atk_text_get_text
https://bugs.webkit.org/show_bug.cgi?id=122644

Reviewed by Chris Fleizach.

Simplified code so we only call textUnderElement() directly once
and only when needed. Also, moved the specific code for ColorWell
objects up to the beginning of that function, so we don't do any
additional efforts like computing text ranges in those cases.

No new tests are needed, just to make sure that the current layout
and unit tests are still passing, which they are.

* accessibility/atk/WebKitAccessibleInterfaceText.cpp:
(textForObject): Fixed a issue that got detected while working on
this patch, which was causing a '\n' to be artificially appended
at the end of text controls all the time.
(webkitAccessibleTextGetText): Simplified function.

* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::doAXStringForRange): Removed
the check that prevents from pass ranges exceeding the limits of
the element's text, since those will be checked anyway when
calling String::substring().

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (157627 => 157628)


--- trunk/Source/WebCore/ChangeLog	2013-10-18 09:17:16 UTC (rev 157627)
+++ trunk/Source/WebCore/ChangeLog	2013-10-18 10:15:13 UTC (rev 157628)
@@ -1,3 +1,30 @@
+2013-10-18  Mario Sanchez Prada  <[email protected]>
+
+        [ATK] Simplify implementation of atk_text_get_text
+        https://bugs.webkit.org/show_bug.cgi?id=122644
+
+        Reviewed by Chris Fleizach.
+
+        Simplified code so we only call textUnderElement() directly once
+        and only when needed. Also, moved the specific code for ColorWell
+        objects up to the beginning of that function, so we don't do any
+        additional efforts like computing text ranges in those cases.
+
+        No new tests are needed, just to make sure that the current layout
+        and unit tests are still passing, which they are.
+
+        * accessibility/atk/WebKitAccessibleInterfaceText.cpp:
+        (textForObject): Fixed a issue that got detected while working on
+        this patch, which was causing a '\n' to be artificially appended
+        at the end of text controls all the time.
+        (webkitAccessibleTextGetText): Simplified function.
+
+        * accessibility/AccessibilityRenderObject.cpp:
+        (WebCore::AccessibilityRenderObject::doAXStringForRange): Removed
+        the check that prevents from pass ranges exceeding the limits of
+        the element's text, since those will be checked anyway when
+        calling String::substring().
+
 2013-10-18  Brendan Long  <[email protected]>
 
         [GStreamer][GTK] Add GRefPtr::outPtr()

Modified: trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp (157627 => 157628)


--- trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp	2013-10-18 09:17:16 UTC (rev 157627)
+++ trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp	2013-10-18 10:15:13 UTC (rev 157628)
@@ -2094,9 +2094,6 @@
         return String();
     
     String elementText = isPasswordField() ? passwordFieldValue() : text();
-    if (range.start + range.length > elementText.length())
-        return String();
-    
     return elementText.substring(range.start, range.length);
 }
 

Modified: trunk/Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceText.cpp (157627 => 157628)


--- trunk/Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceText.cpp	2013-10-18 09:17:16 UTC (rev 157627)
+++ trunk/Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceText.cpp	2013-10-18 10:15:13 UTC (rev 157628)
@@ -148,12 +148,14 @@
         int lineNumber = 0;
         PlainTextRange range = coreObject->doAXRangeForLine(lineNumber);
         while (range.length) {
-            // When a line of text wraps in a text area, the final space is removed.
-            if (range.start + range.length < textLength)
-                range.length -= 1;
             String lineText = coreObject->doAXStringForRange(range);
             g_string_append(str, lineText.utf8().data());
-            g_string_append(str, "\n");
+
+            // When a line of text wraps in a text area, the final space
+            // after each non-final line must be replaced with a line break.
+            if (range.start + range.length < textLength)
+                g_string_overwrite_len(str, str->len - 1, "\n", 1);
+
             range = coreObject->doAXRangeForLine(++lineNumber);
         }
     } else if (coreObject->isAccessibilityRenderObject()) {
@@ -569,12 +571,13 @@
 
     AccessibilityObject* coreObject = core(text);
 
-    int end = endOffset;
-    if (endOffset == -1) {
-        end = coreObject->stringValue().length();
-        if (!end)
-            end = coreObject->textUnderElement(AccessibilityTextUnderElementMode(AccessibilityTextUnderElementMode::TextUnderElementModeIncludeAllChildren)).length();
+#if ENABLE(INPUT_TYPE_COLOR)
+    if (coreObject->roleValue() == ColorWellRole) {
+        int r, g, b;
+        coreObject->colorValue(r, g, b);
+        return g_strdup_printf("rgb %7.5f %7.5f %7.5f 1", r / 255., g / 255., b / 255.);
     }
+#endif
 
     String ret;
     if (coreObject->isTextControl())
@@ -591,30 +594,21 @@
         // is something ATs want included and we have to account for the fact that it is multibyte.
         GOwnPtr<char> objectText(textForObject(coreObject));
         ret = String::fromUTF8(objectText.get());
-        if (!end)
-            end = ret.length();
     }
 
     // Prefix a item number/bullet if needed
+    int actualEndOffset = endOffset == -1 ? ret.length() : endOffset;
     if (coreObject->roleValue() == ListItemRole) {
         RenderObject* objRenderer = coreObject->renderer();
         if (objRenderer && objRenderer->isListItem()) {
             String markerText = toRenderListItem(objRenderer)->markerTextWithSuffix();
             ret = objRenderer->style()->direction() == LTR ? markerText + ret : ret + markerText;
             if (endOffset == -1)
-                end += markerText.length();
+                actualEndOffset = ret.length() + markerText.length();
         }
     }
 
-#if ENABLE(INPUT_TYPE_COLOR)
-    if (coreObject->roleValue() == ColorWellRole) {
-        int r, g, b;
-        coreObject->colorValue(r, g, b);
-        return g_strdup_printf("rgb %7.5f %7.5f %7.5f 1", r / 255., g / 255., b / 255.);
-    }
-#endif
-
-    ret = ret.substring(startOffset, end - startOffset);
+    ret = ret.substring(startOffset, actualEndOffset - startOffset);
     return g_strdup(ret.utf8().data());
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to