Fix variable shadowing in ui/gfx and enable the warning

Attempts to use ui/gfx code in content failed because of
variable/enum shadowing. The main problem is fixed in
https://chromium-review.googlesource.com/c/chromium/src/+/1424799

This fixes the remaining problems and enables the shadowing
warning to prevent future problems of the same kind. All the
problems are of the trivial kind, with inner blocks reusing
either the name of a variable or the name of an argument,
be it |cluster|, |font|, |i|, |path|, |alpha| or |line|. In one
case the fix was to delete an unused local variable.

Bug: 923078,794619
Change-Id: Iae8bb768c49332cbe610860e06fea9d7aebc7a4b
Reviewed-on: https://chromium-review.googlesource.com/c/1421104
Commit-Queue: Daniel Bratell <bratell@opera.com>
Reviewed-by: Alexei Svitkine <asvitkine@chromium.org>
Reviewed-by: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625635}
diff --git a/components/url_formatter/BUILD.gn b/components/url_formatter/BUILD.gn
index 85e0992f..53368d11 100644
--- a/components/url_formatter/BUILD.gn
+++ b/components/url_formatter/BUILD.gn
@@ -21,8 +21,12 @@
     "url_formatter_android.cc",
   ]
 
-  # TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
-  configs += [ "//build/config/compiler:no_size_t_to_int_warning" ]
+  configs += [
+    # TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
+    "//build/config/compiler:no_size_t_to_int_warning",
+
+    "//build/config/compiler:noshadowing",
+  ]
 
   deps = [
     "//base",
diff --git a/ui/gfx/BUILD.gn b/ui/gfx/BUILD.gn
index 813a8f33..b930ab44 100644
--- a/ui/gfx/BUILD.gn
+++ b/ui/gfx/BUILD.gn
@@ -228,6 +228,7 @@
 
   configs += [
     "//build/config:precompiled_headers",
+    "//build/config/compiler:noshadowing",
     "//build/config/compiler:wexit_time_destructors",
   ]
 
diff --git a/ui/gfx/color_analysis.cc b/ui/gfx/color_analysis.cc
index a23a9ad..087069e 100644
--- a/ui/gfx/color_analysis.cc
+++ b/ui/gfx/color_analysis.cc
@@ -541,8 +541,8 @@
     clusters.resize(kNumberOfClusters, KMeanCluster());
 
     // Pick a starting point for each cluster
-    auto cluster = clusters.begin();
-    while (cluster != clusters.end()) {
+    auto new_cluster = clusters.begin();
+    while (new_cluster != clusters.end()) {
       // Try up to 10 times to find a unique color. If no unique color can be
       // found, destroy this cluster.
       bool color_unique = false;
@@ -562,9 +562,9 @@
         // Loop through the previous clusters and check to see if we have seen
         // this color before.
         color_unique = true;
-        for (auto cluster_check = clusters.begin(); cluster_check != cluster;
-             ++cluster_check) {
-          if (cluster_check->IsAtCentroid(r, g, b)) {
+        for (auto cluster = clusters.begin(); cluster != new_cluster;
+             ++cluster) {
+          if (cluster->IsAtCentroid(r, g, b)) {
             color_unique = false;
             break;
           }
@@ -573,19 +573,19 @@
         // If we have a unique color set the center of the cluster to
         // that color.
         if (color_unique) {
-          cluster->SetCentroid(r, g, b);
+          new_cluster->SetCentroid(r, g, b);
           break;
         }
       }
 
       // If we don't have a unique color erase this cluster.
       if (!color_unique) {
-        cluster = clusters.erase(cluster);
+        new_cluster = clusters.erase(new_cluster);
       } else {
         // Have to increment the iterator here, otherwise the increment in the
         // for loop will skip a cluster due to the erase if the color wasn't
         // unique.
-        ++cluster;
+        ++new_cluster;
       }
     }
 
diff --git a/ui/gfx/font_fallback_mac.mm b/ui/gfx/font_fallback_mac.mm
index 6a4d66f1..071b59f 100644
--- a/ui/gfx/font_fallback_mac.mm
+++ b/ui/gfx/font_fallback_mac.mm
@@ -60,10 +60,10 @@
     CTFontDescriptorRef descriptor =
         base::mac::CFCastStrict<CTFontDescriptorRef>(
             CFArrayGetValueAtIndex(cascade_list, i));
-    base::ScopedCFTypeRef<CTFontRef> font(
+    base::ScopedCFTypeRef<CTFontRef> fallback_font(
         CTFontCreateWithFontDescriptor(descriptor, 0.0, nullptr));
-    if (font.get())
-      fallback_fonts.push_back(Font(static_cast<NSFont*>(font.get())));
+    if (fallback_font.get())
+      fallback_fonts.push_back(Font(static_cast<NSFont*>(fallback_font.get())));
   }
 
   if (fallback_fonts.empty())
diff --git a/ui/gfx/font_fallback_win.cc b/ui/gfx/font_fallback_win.cc
index 3da6eee..6d6fe87 100644
--- a/ui/gfx/font_fallback_win.cc
+++ b/ui/gfx/font_fallback_win.cc
@@ -111,10 +111,10 @@
     if (!font_name.empty()) {
       AppendFont(font_name, font.GetFontSize(), linked_fonts);
     } else if (!filename.empty()) {
-      std::vector<std::string> font_names;
-      GetFontNamesFromFilename(filename, font_map, &font_names);
-      for (size_t i = 0; i < font_names.size(); ++i)
-        AppendFont(font_names[i], font.GetFontSize(), linked_fonts);
+      std::vector<std::string> filename_fonts;
+      GetFontNamesFromFilename(filename, font_map, &filename_fonts);
+      for (const std::string& filename_font : filename_fonts)
+        AppendFont(filename_font, font.GetFontSize(), linked_fonts);
     }
   }
 
diff --git a/ui/gfx/paint_vector_icon.cc b/ui/gfx/paint_vector_icon.cc
index 749ba772..d6b4b83 100644
--- a/ui/gfx/paint_vector_icon.cc
+++ b/ui/gfx/paint_vector_icon.cc
@@ -210,9 +210,6 @@
                int dip_size,
                SkColor color,
                const base::TimeDelta& elapsed_time) {
-  SkPath path;
-  path.setFillType(SkPath::kEvenOdd_FillType);
-
   int canvas_size = kReferenceSizeDip;
   std::vector<SkPath> paths;
   std::vector<cc::PaintFlags> flags_array;
diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h
index 94db79c..18e57f9 100644
--- a/ui/gfx/render_text.h
+++ b/ui/gfx/render_text.h
@@ -100,7 +100,7 @@
   SkColor color() const { return color_->second; }
   BaselineStyle baseline() const { return baseline_->second; }
   int font_size_override() const { return font_size_override_->second; }
-  bool style(TextStyle s) const { return style_[static_cast<int>(s)]->second; }
+  bool style(TextStyle s) const { return style_[s]->second; }
   Font::Weight weight() const { return weight_->second; }
 
   // Get the intersecting range of the current iterator set.
diff --git a/ui/gfx/skbitmap_operations.cc b/ui/gfx/skbitmap_operations.cc
index 25bd1816..3c01612 100644
--- a/ui/gfx/skbitmap_operations.cc
+++ b/ui/gfx/skbitmap_operations.cc
@@ -107,8 +107,8 @@
     uint32_t* dst_row = masked.getAddr32(0, y);
 
     for (int x = 0; x < masked.width(); ++x) {
-      unsigned alpha = SkGetPackedA32(alpha_row[x]);
-      unsigned scale = SkAlpha255To256(alpha);
+      unsigned alpha32 = SkGetPackedA32(alpha_row[x]);
+      unsigned scale = SkAlpha255To256(alpha32);
       dst_row[x] = SkAlphaMulQ(rgb_row[x], scale);
     }
   }
diff --git a/ui/gfx/text_elider.cc b/ui/gfx/text_elider.cc
index 3dfeebc0..085fc3c 100644
--- a/ui/gfx/text_elider.cc
+++ b/ui/gfx/text_elider.cc
@@ -651,9 +651,9 @@
         if (lines_added) {
           if (truncate) {
             // Trim trailing whitespace from the line that was added.
-            const size_t line = lines_->size() - lines_added;
-            base::TrimWhitespace(lines_->at(line), base::TRIM_TRAILING,
-                                 &lines_->at(line));
+            const size_t new_line = lines_->size() - lines_added;
+            base::TrimWhitespace(lines_->at(new_line), base::TRIM_TRAILING,
+                                 &lines_->at(new_line));
           }
           if (base::ContainsOnlyChars(word, base::kWhitespaceUTF16)) {
             // Skip the first space if the previous line was carried over.