[ATK] Modernize the for loops in ATK AX code
authorzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Jan 2014 11:02:02 +0000 (11:02 +0000)
committerzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Jan 2014 11:02:02 +0000 (11:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=127120

Reviewed by Mario Sanchez Prada.

Update the for loops to be range-based in ATK accessibility code.
This work is complementary to r161979.

* accessibility/atk/WebKitAccessibleInterfaceHypertext.cpp:
(webkitAccessibleHypertextGetLink):
* accessibility/atk/WebKitAccessibleInterfaceTable.cpp:
(webkitAccessibleTableGetColumnHeader):
(webkitAccessibleTableGetRowHeader):
* accessibility/atk/WebKitAccessibleUtil.cpp:
(accessibilityTitle):
(accessibilityDescription):
* accessibility/atk/WebKitAccessibleWrapperAtk.cpp:
(getNChildrenForTable):
(getChildForTable):
(getIndexInParentForCellInRow):

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

Source/WebCore/ChangeLog
Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceHypertext.cpp
Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceTable.cpp
Source/WebCore/accessibility/atk/WebKitAccessibleUtil.cpp
Source/WebCore/accessibility/atk/WebKitAccessibleWrapperAtk.cpp

index a27730b..a9fcc01 100644 (file)
@@ -1,5 +1,28 @@
 2014-01-17  Zan Dobersek  <zdobersek@igalia.com>
 
+        [ATK] Modernize the for loops in ATK AX code
+        https://bugs.webkit.org/show_bug.cgi?id=127120
+
+        Reviewed by Mario Sanchez Prada.
+
+        Update the for loops to be range-based in ATK accessibility code.
+        This work is complementary to r161979.
+
+        * accessibility/atk/WebKitAccessibleInterfaceHypertext.cpp:
+        (webkitAccessibleHypertextGetLink):
+        * accessibility/atk/WebKitAccessibleInterfaceTable.cpp:
+        (webkitAccessibleTableGetColumnHeader):
+        (webkitAccessibleTableGetRowHeader):
+        * accessibility/atk/WebKitAccessibleUtil.cpp:
+        (accessibilityTitle):
+        (accessibilityDescription):
+        * accessibility/atk/WebKitAccessibleWrapperAtk.cpp:
+        (getNChildrenForTable):
+        (getChildForTable):
+        (getIndexInParentForCellInRow):
+
+2014-01-17  Zan Dobersek  <zdobersek@igalia.com>
+
         [Soup] Remove unnecessary using-directives for the std namespace
         https://bugs.webkit.org/show_bug.cgi?id=127122
 
index b067836..75c045c 100644 (file)
@@ -46,8 +46,8 @@ static AtkHyperlink* webkitAccessibleHypertextGetLink(AtkHypertext* hypertext, g
         return 0;
 
     gint currentLink = -1;
-    for (unsigned i = 0; i < children.size(); i++) {
-        AccessibilityObject* coreChild = children.at(i).get();
+    for (const auto& child : children) {
+        AccessibilityObject* coreChild = child.get();
         if (!coreChild->accessibilityIsIgnored()) {
             AtkObject* axObject = coreChild->wrapper();
             if (!axObject || !ATK_IS_HYPERLINK_IMPL(axObject))
index cb7fd89..f6ed19c 100644 (file)
@@ -203,15 +203,14 @@ static AtkObject* webkitAccessibleTableGetColumnHeader(AtkTable* table, gint col
 
     AccessibilityObject* accTable = core(table);
     if (accTable->isAccessibilityRenderObject()) {
-        AccessibilityObject::AccessibilityChildrenVector allColumnHeaders;
-        toAccessibilityTable(accTable)->columnHeaders(allColumnHeaders);
-        unsigned columnCount = allColumnHeaders.size();
-        for (unsigned k = 0; k < columnCount; ++k) {
+        AccessibilityObject::AccessibilityChildrenVector columnHeaders;
+        toAccessibilityTable(accTable)->columnHeaders(columnHeaders);
+
+        for (const auto& columnHeader : columnHeaders) {
             std::pair<unsigned, unsigned> columnRange;
-            AccessibilityTableCell* cell = toAccessibilityTableCell(allColumnHeaders.at(k).get());
-            cell->columnIndexRange(columnRange);
+            toAccessibilityTableCell(columnHeader.get())->columnIndexRange(columnRange);
             if (columnRange.first <= static_cast<unsigned>(column) && static_cast<unsigned>(column) < columnRange.first + columnRange.second)
-                return allColumnHeaders[k]->wrapper();
+                return columnHeader->wrapper();
         }
     }
     return 0;
@@ -224,15 +223,14 @@ static AtkObject* webkitAccessibleTableGetRowHeader(AtkTable* table, gint row)
 
     AccessibilityObject* accTable = core(table);
     if (accTable->isAccessibilityRenderObject()) {
-        AccessibilityObject::AccessibilityChildrenVector allRowHeaders;
-        toAccessibilityTable(accTable)->rowHeaders(allRowHeaders);
-        unsigned rowCount = allRowHeaders.size();
-        for (unsigned k = 0; k < rowCount; ++k) {
+        AccessibilityObject::AccessibilityChildrenVector rowHeaders;
+        toAccessibilityTable(accTable)->rowHeaders(rowHeaders);
+
+        for (const auto& rowHeader : rowHeaders) {
             std::pair<unsigned, unsigned> rowRange;
-            AccessibilityTableCell* cell = toAccessibilityTableCell(allRowHeaders.at(k).get());
-            cell->rowIndexRange(rowRange);
+            toAccessibilityTableCell(rowHeader.get())->rowIndexRange(rowRange);
             if (rowRange.first <= static_cast<unsigned>(row) && static_cast<unsigned>(row) < rowRange.first + rowRange.second)
-                return allRowHeaders[k]->wrapper();
+                return rowHeader->wrapper();
         }
     }
     return 0;
index ab50d49..58147fa 100644 (file)
@@ -94,10 +94,7 @@ String accessibilityTitle(AccessibilityObject* coreObject)
     Vector<AccessibilityText> textOrder;
     coreObject->accessibilityText(textOrder);
 
-    unsigned length = textOrder.size();
-    for (unsigned k = 0; k < length; k++) {
-        const AccessibilityText& text = textOrder[k];
-
+    for (const AccessibilityText& text : textOrder) {
         // Once we encounter visible text, or the text from our children that should be used foremost.
         if (text.textSource == VisibleText || text.textSource == ChildrenText)
             return text.text;
@@ -116,6 +113,7 @@ String accessibilityTitle(AccessibilityObject* coreObject)
         if (text.textSource == TitleTagText && !titleTagShouldBeUsedInDescriptionField(coreObject))
             return text.text;
     }
+
     return String();
 }
 
@@ -124,11 +122,8 @@ String accessibilityDescription(AccessibilityObject* coreObject)
     Vector<AccessibilityText> textOrder;
     coreObject->accessibilityText(textOrder);
 
-    unsigned length = textOrder.size();
     bool visibleTextAvailable = false;
-    for (unsigned k = 0; k < length; k++) {
-        const AccessibilityText& text = textOrder[k];
-
+    for (const AccessibilityText& text : textOrder) {
         if (text.textSource == AlternativeText)
             return text.text;
 
index 60a9b2a..305e233 100644 (file)
@@ -321,15 +321,13 @@ static AtkObject* webkitAccessibleGetParent(AtkObject* object)
 static gint getNChildrenForTable(AccessibilityObject* coreObject)
 {
     const AccessibilityObject::AccessibilityChildrenVector& tableChildren = coreObject->children();
-    size_t tableChildrenCount = tableChildren.size();
     size_t cellsCount = 0;
 
     // Look for the actual index of the cell inside the table.
-    for (unsigned i = 0; i < tableChildrenCount; ++i) {
-        if (tableChildren[i]->isTableRow()) {
-            const AccessibilityObject::AccessibilityChildrenVector& rowChildren = tableChildren[i]->children();
-            cellsCount += rowChildren.size();
-        } else
+    for (const auto& tableChild : tableChildren) {
+        if (tableChild->isTableRow())
+            cellsCount += tableChild->children().size();
+        else
             cellsCount++;
     }
 
@@ -354,20 +352,19 @@ static gint webkitAccessibleGetNChildren(AtkObject* object)
 static AccessibilityObject* getChildForTable(AccessibilityObject* coreObject, gint index)
 {
     const AccessibilityObject::AccessibilityChildrenVector& tableChildren = coreObject->children();
-    size_t tableChildrenCount = tableChildren.size();
     size_t cellsCount = 0;
 
     // Look for the actual index of the cell inside the table.
     size_t current = static_cast<size_t>(index);
-    for (unsigned i = 0; i < tableChildrenCount; ++i) {
-        if (tableChildren[i]->isTableRow()) {
-            const AccessibilityObject::AccessibilityChildrenVector& rowChildren = tableChildren[i]->children();
+    for (const auto& tableChild : tableChildren) {
+        if (tableChild->isTableRow()) {
+            const AccessibilityObject::AccessibilityChildrenVector& rowChildren = tableChild->children();
             size_t rowChildrenCount = rowChildren.size();
             if (current < cellsCount + rowChildrenCount)
                 return rowChildren.at(current - cellsCount).get();
             cellsCount += rowChildrenCount;
         } else if (cellsCount == current)
-            return tableChildren[i].get();
+            return tableChild.get();
         else
             cellsCount++;
     }
@@ -419,18 +416,17 @@ static gint getIndexInParentForCellInRow(AccessibilityObject* coreObject)
         return -1;
 
     const AccessibilityObject::AccessibilityChildrenVector& rows = grandParent->children();
-    size_t rowsCount = rows.size();
     size_t previousCellsCount = 0;
 
     // Look for the actual index of the cell inside the table.
-    for (unsigned i = 0; i < rowsCount; ++i) {
-        if (!rows[i]->isTableRow())
+    for (const auto& row : rows) {
+        if (!row->isTableRow())
             continue;
 
-        const AccessibilityObject::AccessibilityChildrenVector& cells = rows[i]->children();
+        const AccessibilityObject::AccessibilityChildrenVector& cells = row->children();
         size_t cellsCount = cells.size();
 
-        if (rows[i] == parent) {
+        if (row == parent) {
             for (unsigned j = 0; j < cellsCount; ++j) {
                 if (cells[j] == coreObject)
                     return previousCellsCount + j;