Bug 1317973 - Use auto type specifier for variable declarations to improve code readability and maintainability r=tnikkel
authorSylvestre Ledru <sledru@mozilla.com>
Wed, 16 Nov 2016 15:22:36 +0100
changeset 324916 9c229cf88ec224739f127082c1e8ec4c322bcd6f
parent 324915 8023e756661aad0e6d21c91229b8804c0714f006
child 324917 9f1de4aeae3a3495b6425668acbafbdf7eebb18b
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewerstnikkel
bugs1317973
milestone53.0a1
Bug 1317973 - Use auto type specifier for variable declarations to improve code readability and maintainability r=tnikkel MozReview-Commit-ID: 5RDrGaxV3E4
widget/gtk/nsWindow.cpp
widget/nsBaseDragService.cpp
widget/nsBaseWidget.cpp
widget/xremoteclient/XRemoteClient.cpp
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -655,17 +655,17 @@ SetWidgetForHierarchy(GdkWindow *aWindow
 {
     gpointer data;
     gdk_window_get_user_data(aWindow, &data);
 
     if (data != aOldWidget) {
         if (!GTK_IS_WIDGET(data))
             return;
 
-        GtkWidget* widget = static_cast<GtkWidget*>(data);
+        auto* widget = static_cast<GtkWidget*>(data);
         if (gtk_widget_get_parent(widget) != aOldWidget)
             return;
 
         // This window belongs to a child widget, which will no longer be a
         // child of aOldWidget.
         gtk_widget_reparent(widget, aNewWidget);
 
         return;
@@ -890,17 +890,17 @@ nsWindow::ReparentNativeWidget(nsIWidget
         // reparent.
         MOZ_ASSERT(gdk_window_is_destroyed(mGdkWindow),
                    "live GdkWindow with no widget");
         return;
     }
     MOZ_ASSERT(!gdk_window_is_destroyed(mGdkWindow),
                "destroyed GdkWindow with widget");
 
-    nsWindow* newParent = static_cast<nsWindow*>(aNewParent);
+    auto* newParent = static_cast<nsWindow*>(aNewParent);
     GdkWindow* newParentWindow = newParent->mGdkWindow;
     GtkWidget* newContainer = newParent->GetMozContainerWidget();
     GtkWindow* shell = GTK_WINDOW(mShell);
 
     if (shell && gtk_window_get_transient_for(shell)) {
       GtkWindow* topLevelParent =
           GTK_WINDOW(gtk_widget_get_toplevel(newContainer));
       gtk_window_set_transient_for(shell, topLevelParent);
@@ -935,17 +935,17 @@ nsWindow::ReparentNativeWidgetInternal(n
 
         if (!mIsTopLevel) {
             gdk_window_reparent(mGdkWindow, aNewParentWindow,
                                 DevicePixelsToGdkCoordRoundDown(mBounds.x),
                                 DevicePixelsToGdkCoordRoundDown(mBounds.y));
         }
     }
 
-    nsWindow* newParent = static_cast<nsWindow*>(aNewParent);
+    auto* newParent = static_cast<nsWindow*>(aNewParent);
     bool parentHasMappedToplevel =
         newParent && newParent->mHasMappedToplevel;
     if (mHasMappedToplevel != parentHasMappedToplevel) {
         SetHasMappedToplevel(parentHasMappedToplevel);
     }
 }
 
 void
@@ -1169,17 +1169,17 @@ nsWindow::Resize(double aX, double aY, d
 
 void
 nsWindow::ResizePluginSocketWidget()
 {
     // e10s specific, a eWindowType_plugin_ipc_chrome holds its own
     // nsPluginNativeWindowGtk wrapper. We are responsible for resizing
     // the embedded socket widget.
     if (mWindowType == eWindowType_plugin_ipc_chrome) {
-        nsPluginNativeWindowGtk* wrapper = (nsPluginNativeWindowGtk*)
+        auto* wrapper = (nsPluginNativeWindowGtk*)
           GetNativeData(NS_NATIVE_PLUGIN_OBJECT_PTR);
         if (wrapper) {
             wrapper->width = mBounds.width;
             wrapper->height = mBounds.height;
             wrapper->SetAllocation();
         }
     }
 }
@@ -1563,18 +1563,18 @@ nsWindow::UpdateClientOffset()
                           &length_returned,
                           (guchar **) &frame_extents) ||
         length_returned/sizeof(glong) != 4) {
         mClientOffset = nsIntPoint(0, 0);
         return;
     }
 
     // data returned is in the order left, right, top, bottom
-    int32_t left = int32_t(frame_extents[0]);
-    int32_t top = int32_t(frame_extents[2]);
+    auto left = int32_t(frame_extents[0]);
+    auto top = int32_t(frame_extents[2]);
 
     g_free(frame_extents);
 
     mClientOffset = nsIntPoint(left, top);
 }
 
 LayoutDeviceIntPoint
 nsWindow::GetClientOffset()
@@ -2551,18 +2551,18 @@ nsWindow::OnEnterNotifyEvent(GdkEventCro
 
     DispatchInputEvent(&event);
 }
 
 // XXX Is this the right test for embedding cases?
 static bool
 is_top_level_mouse_exit(GdkWindow* aWindow, GdkEventCrossing *aEvent)
 {
-    gint x = gint(aEvent->x_root);
-    gint y = gint(aEvent->y_root);
+    auto x = gint(aEvent->x_root);
+    auto y = gint(aEvent->y_root);
     GdkDisplay* display = gdk_window_get_display(aWindow);
     GdkWindow* winAtPt = gdk_display_get_window_at_pointer(display, &x, &y);
     if (!winAtPt)
         return true;
     GdkWindow* topLevelAtPt = gdk_window_get_toplevel(winAtPt);
     GdkWindow* topLevelWidget = gdk_window_get_toplevel(aWindow);
     return topLevelAtPt != topLevelWidget;
 }
@@ -3378,17 +3378,17 @@ nsWindow::ThemeChanged()
         return;
 
     // Dispatch theme change notification to all child windows
     GList *children =
         gdk_window_peek_children(mGdkWindow);
     while (children) {
         GdkWindow *gdkWin = GDK_WINDOW(children->data);
 
-        nsWindow *win = (nsWindow*) g_object_get_data(G_OBJECT(gdkWin),
+        auto *win = (nsWindow*) g_object_get_data(G_OBJECT(gdkWin),
                                                       "nsWindow");
 
         if (win && win != this) { // guard against infinite recursion
             RefPtr<nsWindow> kungFuDeathGrip = win;
             win->ThemeChanged();
         }
 
         children = children->next;
@@ -4390,17 +4390,17 @@ nsWindow::ConfigureChildren(const nsTArr
     // size information from a source other than our owner. Don't let our parent
     // update this information.
     if (mWindowType == eWindowType_plugin_ipc_chrome) {
       return NS_OK;
     }
 
     for (uint32_t i = 0; i < aConfigurations.Length(); ++i) {
         const Configuration& configuration = aConfigurations[i];
-        nsWindow* w = static_cast<nsWindow*>(configuration.mChild.get());
+        auto* w = static_cast<nsWindow*>(configuration.mChild.get());
         NS_ASSERTION(w->GetParent() == this,
                      "Configured widget is not a child");
         w->SetWindowClipRegion(configuration.mClipRegion, true);
         if (w->mBounds.Size() != configuration.mBounds.Size()) {
             w->Resize(configuration.mBounds.x, configuration.mBounds.y,
                       configuration.mBounds.width, configuration.mBounds.height,
                       true);
         } else if (w->mBounds.TopLeft() != configuration.mBounds.TopLeft()) {
@@ -4479,17 +4479,17 @@ nsWindow::ResizeTransparencyBitmap()
         return;
 
     if (mBounds.width == mTransparencyBitmapWidth &&
         mBounds.height == mTransparencyBitmapHeight)
         return;
 
     int32_t newRowBytes = GetBitmapStride(mBounds.width);
     int32_t newSize = newRowBytes * mBounds.height;
-    gchar* newBits = new gchar[newSize];
+    auto* newBits = new gchar[newSize];
     // fill new mask with "transparent", first
     memset(newBits, 0, newSize);
 
     // Now copy the intersection of the old and new areas into the new mask
     int32_t copyWidth = std::min(mBounds.width, mTransparencyBitmapWidth);
     int32_t copyHeight = std::min(mBounds.height, mTransparencyBitmapHeight);
     int32_t oldRowBytes = GetBitmapStride(mTransparencyBitmapWidth);
     int32_t copyBytes = GetBitmapStride(copyWidth);
@@ -5177,34 +5177,34 @@ nsWindow::CheckForRollup(gdouble aMouseX
         rollupWidget = rollupListener->GetRollupWidget();
     }
     if (!rollupWidget) {
         nsBaseWidget::gRollupListener = nullptr;
         return false;
     }
 
     bool retVal = false;
-    GdkWindow *currentPopup =
+    auto *currentPopup =
         (GdkWindow *)rollupWidget->GetNativeData(NS_NATIVE_WINDOW);
     if (aAlwaysRollup || !is_mouse_in_window(currentPopup, aMouseX, aMouseY)) {
         bool rollup = true;
         if (aIsWheel) {
             rollup = rollupListener->ShouldRollupOnMouseWheelEvent();
             retVal = rollupListener->ShouldConsumeOnMouseWheelEvent();
         }
         // if we're dealing with menus, we probably have submenus and
         // we don't want to rollup if the click is in a parent menu of
         // the current submenu
         uint32_t popupsToRollup = UINT32_MAX;
         if (!aAlwaysRollup) {
             AutoTArray<nsIWidget*, 5> widgetChain;
             uint32_t sameTypeCount = rollupListener->GetSubmenuWidgetChain(&widgetChain);
             for (uint32_t i=0; i<widgetChain.Length(); ++i) {
                 nsIWidget* widget = widgetChain[i];
-                GdkWindow* currWindow =
+                auto* currWindow =
                     (GdkWindow*) widget->GetNativeData(NS_NATIVE_WINDOW);
                 if (is_mouse_in_window(currWindow, aMouseX, aMouseY)) {
                   // don't roll up if the mouse event occurred within a
                   // menu of the same type. If the mouse event occurred
                   // in a menu higher than that, roll up, but pass the
                   // number of popups to Rollup so that only those of the
                   // same type close up.
                   if (i < sameTypeCount) {
@@ -5658,18 +5658,18 @@ leave_notify_event_cb(GtkWidget *widget,
                       GdkEventCrossing *event)
 {
     if (is_parent_grab_leave(event)) {
         return TRUE;
     }
 
     // bug 369599: Suppress LeaveNotify events caused by pointer grabs to
     // avoid generating spurious mouse exit events.
-    gint x = gint(event->x_root);
-    gint y = gint(event->y_root);
+    auto x = gint(event->x_root);
+    auto y = gint(event->y_root);
     GdkDisplay* display = gtk_widget_get_display(widget);
     GdkWindow* winAtPt = gdk_display_get_window_at_pointer(display, &x, &y);
     if (winAtPt == event->window) {
         return TRUE;
     }
 
     RefPtr<nsWindow> window = get_window_for_gdk_window(event->window);
     if (!window)
@@ -5782,17 +5782,17 @@ focus_out_event_cb(GtkWidget *widget, Gd
 // example), a request to make the parent window active is issued.  When the
 // parent window becomes active, keyboard events will be received.
 
 static GdkFilterReturn
 popup_take_focus_filter(GdkXEvent *gdk_xevent,
                         GdkEvent *event,
                         gpointer data)
 {
-    XEvent* xevent = static_cast<XEvent*>(gdk_xevent);
+    auto* xevent = static_cast<XEvent*>(gdk_xevent);
     if (xevent->type != ClientMessage)
         return GDK_FILTER_CONTINUE;
 
     XClientMessageEvent& xclient = xevent->xclient;
     if (xclient.message_type != gdk_x11_get_xatom_by_name("WM_PROTOCOLS"))
         return GDK_FILTER_CONTINUE;
 
     Atom atom = xclient.data.l[0];
@@ -6281,17 +6281,17 @@ get_inner_gdk_window (GdkWindow *aWindow
                       gint x, gint y,
                       gint *retx, gint *rety)
 {
     gint cx, cy, cw, ch;
     GList *children = gdk_window_peek_children(aWindow);
     for (GList *child = g_list_last(children);
          child;
          child = g_list_previous(child)) {
-        GdkWindow *childWindow = (GdkWindow *) child->data;
+        auto *childWindow = (GdkWindow *) child->data;
         if (get_window_for_gdk_window(childWindow)) {
 #if (MOZ_WIDGET_GTK == 2)
             gdk_window_get_geometry(childWindow, &cx, &cy, &cw, &ch, nullptr);
 #else
             gdk_window_get_geometry(childWindow, &cx, &cy, &cw, &ch);
 #endif
             if ((cx < x) && (x < (cx + cw)) &&
                 (cy < y) && (y < (cy + ch)) &&
--- a/widget/nsBaseDragService.cpp
+++ b/widget/nsBaseDragService.cpp
@@ -554,18 +554,17 @@ nsBaseDragService::DrawDrag(nsIDOMNode* 
     return NS_ERROR_FAILURE;
 
   *aPresContext = presShell->GetPresContext();
 
   nsCOMPtr<nsIFrameLoaderOwner> flo = do_QueryInterface(dragNode);
   if (flo) {
     RefPtr<nsFrameLoader> fl = flo->GetFrameLoader();
     if (fl) {
-      mozilla::dom::TabParent* tp =
-        static_cast<mozilla::dom::TabParent*>(fl->GetRemoteBrowser());
+      auto* tp = static_cast<mozilla::dom::TabParent*>(fl->GetRemoteBrowser());
       if (tp && tp->TakeDragVisualization(*aSurface, aScreenDragRect)) {
         if (mImage) {
           // Just clear the surface if chrome has overridden it with an image.
           *aSurface = nullptr;
         }
 
         return NS_OK;
       }
--- a/widget/nsBaseWidget.cpp
+++ b/widget/nsBaseWidget.cpp
@@ -690,17 +690,17 @@ void nsBaseWidget::SetZIndex(int32_t aZI
 {
   // Hold a ref to ourselves just in case, since we're going to remove
   // from our parent.
   nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
 
   mZIndex = aZIndex;
 
   // reorder this child in its parent's list.
-  nsBaseWidget* parent = static_cast<nsBaseWidget*>(GetParent());
+  auto* parent = static_cast<nsBaseWidget*>(GetParent());
   if (parent) {
     parent->RemoveChild(this);
     // Scope sib outside the for loop so we can check it afterward
     nsIWidget* sib = parent->GetFirstChild();
     for ( ; sib; sib = sib->GetNextSibling()) {
       int32_t childZIndex = GetZIndex();
       if (aZIndex < childZIndex) {
         // Insert ourselves before sib
@@ -2026,17 +2026,17 @@ nsIWidget::SynthesizeNativeTouchTap(Layo
   notifier.SkipNotification();  // we'll do it in the long-tap callback
   return NS_OK;
 }
 
 // static
 void
 nsIWidget::OnLongTapTimerCallback(nsITimer* aTimer, void* aClosure)
 {
-  nsIWidget *self = static_cast<nsIWidget *>(aClosure);
+  auto *self = static_cast<nsIWidget *>(aClosure);
 
   if ((self->mLongTapTouchPoint->mStamp + self->mLongTapTouchPoint->mDuration) >
       TimeStamp::Now()) {
 #ifdef XP_WIN
     // Windows needs us to keep pumping feedback to the digitizer, so update
     // the pointer id with the same position.
     self->SynthesizeNativeTouchPoint(self->mLongTapTouchPoint->mPointerId,
                                      TOUCH_CONTACT,
--- a/widget/xremoteclient/XRemoteClient.cpp
+++ b/widget/xremoteclient/XRemoteClient.cpp
@@ -637,24 +637,24 @@ XRemoteClient::DoSendCommandLine(Window 
   for (int i = 0; i < argc; ++i) {
     int32_t len = strlen(argv[i]);
     if (i == 0 && aDesktopStartupID) {
       len += sizeof(desktopStartupPrefix) - 1 + strlen(aDesktopStartupID);
     }
     argvlen += len;
   }
 
-  int32_t* buffer = (int32_t*) malloc(argvlen + argc + 1 +
+  auto* buffer = (int32_t*) malloc(argvlen + argc + 1 +
                                       sizeof(int32_t) * (argc + 1));
   if (!buffer)
     return NS_ERROR_OUT_OF_MEMORY;
 
   buffer[0] = TO_LITTLE_ENDIAN32(argc);
 
-  char *bufend = (char*) (buffer + argc + 1);
+  auto *bufend = (char*) (buffer + argc + 1);
 
   bufend = estrcpy(cwdbuf, bufend);
 
   for (int i = 0; i < argc; ++i) {
     buffer[i + 1] = TO_LITTLE_ENDIAN32(bufend - ((char*) buffer));
     bufend = estrcpy(argv[i], bufend);
     if (i == 0 && aDesktopStartupID) {
       bufend = estrcpy(desktopStartupPrefix, bufend - 1);