Move UserGestureHandler to shell
Rename class names to UserActionXX to avoid confusion with touch gesture and this also handles non gesture mouse button action.
This is necessary step to allow multiple root windows.

BUG=123160
TEST=none

Review URL: https://chromiumcodereview.appspot.com/10448093

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139899 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/ash/shell.cc b/ash/shell.cc
index a9f9d42f..7eac672 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -66,6 +66,7 @@
 #include "base/command_line.h"
 #include "grit/ui_resources.h"
 #include "ui/aura/client/aura_constants.h"
+#include "ui/aura/client/user_action_client.h"
 #include "ui/aura/env.h"
 #include "ui/aura/focus_manager.h"
 #include "ui/aura/layout_manager.h"
@@ -753,6 +754,11 @@
   if (!user_wallpaper_delegate_.get())
     user_wallpaper_delegate_.reset(new DummyUserWallpaperDelegate());
 
+  if (delegate_.get())
+    user_action_client_.reset(delegate_->CreateUserActionClient());
+  if (user_action_client_.get())
+    aura::client::SetUserActionClient(root_window, user_action_client_.get());
+
   InitLayoutManagers();
 
   if (!command_line->HasSwitch(switches::kAuraNoShadows)) {
diff --git a/ash/shell.h b/ash/shell.h
index 237c4945..153cd44 100644
--- a/ash/shell.h
+++ b/ash/shell.h
@@ -28,6 +28,9 @@
 class Monitor;
 class RootWindow;
 class Window;
+namespace client {
+class UserActionClient;
+}
 namespace shared {
 class InputMethodEventFilter;
 class RootWindowEventFilter;
@@ -381,6 +384,7 @@
   scoped_ptr<internal::MagnificationController> magnification_controller_;
   scoped_ptr<internal::ScreenDimmer> screen_dimmer_;
   scoped_ptr<aura::FocusManager> focus_manager_;
+  scoped_ptr<aura::client::UserActionClient> user_action_client_;
 
   // An event filter that rewrites or drops a key event.
   scoped_ptr<internal::KeyRewriterEventFilter> key_rewriter_filter_;
diff --git a/ash/shell/shell_delegate_impl.cc b/ash/shell/shell_delegate_impl.cc
index 7890551f..6dc3dc7 100644
--- a/ash/shell/shell_delegate_impl.cc
+++ b/ash/shell/shell_delegate_impl.cc
@@ -117,6 +117,9 @@
 ash::UserWallpaperDelegate* ShellDelegateImpl::CreateUserWallpaperDelegate() {
   return NULL;
 }
+aura::client::UserActionClient* ShellDelegateImpl::CreateUserActionClient() {
+  return NULL;
+}
 
 }  // namespace shell
 }  // namespace ash
diff --git a/ash/shell/shell_delegate_impl.h b/ash/shell/shell_delegate_impl.h
index 3acc893c..4534347 100644
--- a/ash/shell/shell_delegate_impl.h
+++ b/ash/shell/shell_delegate_impl.h
@@ -47,6 +47,7 @@
   virtual ash::SystemTrayDelegate* CreateSystemTrayDelegate(
       ash::SystemTray* tray) OVERRIDE;
   virtual ash::UserWallpaperDelegate* CreateUserWallpaperDelegate() OVERRIDE;
+  virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE;
 
  private:
   // Used to update Launcher. Owned by main.
diff --git a/ash/shell_delegate.h b/ash/shell_delegate.h
index d57cca3f..5bb5303 100644
--- a/ash/shell_delegate.h
+++ b/ash/shell_delegate.h
@@ -19,6 +19,9 @@
 
 namespace aura {
 class Window;
+namespace client {
+class UserActionClient;
+}
 }
 
 namespace views {
@@ -111,6 +114,9 @@
 
   // Creates a user wallpaper delegate. Shell takes ownership of the delegate.
   virtual UserWallpaperDelegate* CreateUserWallpaperDelegate() = 0;
+
+  // Creates a user action client. Shell takes ownership of the object.
+  virtual aura::client::UserActionClient* CreateUserActionClient() = 0;
 };
 
 }  // namespace ash
diff --git a/ash/test/test_shell_delegate.cc b/ash/test/test_shell_delegate.cc
index 82d98112..80a6894 100644
--- a/ash/test/test_shell_delegate.cc
+++ b/ash/test/test_shell_delegate.cc
@@ -103,5 +103,9 @@
   return NULL;
 }
 
+aura::client::UserActionClient* TestShellDelegate::CreateUserActionClient() {
+  return NULL;
+}
+
 }  // namespace test
 }  // namespace ash
diff --git a/ash/test/test_shell_delegate.h b/ash/test/test_shell_delegate.h
index 5ca9759..f9d6113 100644
--- a/ash/test/test_shell_delegate.h
+++ b/ash/test/test_shell_delegate.h
@@ -42,6 +42,7 @@
       ash::LauncherModel* model) OVERRIDE;
   virtual SystemTrayDelegate* CreateSystemTrayDelegate(SystemTray* t) OVERRIDE;
   virtual UserWallpaperDelegate* CreateUserWallpaperDelegate() OVERRIDE;
+  virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE;
 
  private:
   bool locked_;
diff --git a/chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.cc b/chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.cc
index f379e118..2bd5eeb 100644
--- a/chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.cc
+++ b/chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.cc
@@ -19,10 +19,8 @@
 #include "chrome/browser/ui/views/ash/chrome_shell_delegate.h"
 #include "chrome/browser/ui/views/ash/key_rewriter.h"
 #include "chrome/browser/ui/views/ash/screenshot_taker.h"
-#include "chrome/browser/ui/views/ash/user_gesture_handler.h"
 #include "chrome/common/chrome_switches.h"
 #include "ui/aura/aura_switches.h"
-#include "ui/aura/client/user_gesture_client.h"
 #include "ui/aura/env.h"
 #include "ui/aura/monitor_manager.h"
 #include "ui/aura/root_window.h"
@@ -87,9 +85,6 @@
     browser::StartKeepAlive();
   }
 #endif
-  gesture_handler_.reset(new UserGestureHandler);
-  aura::client::SetUserGestureClient(
-      ash::Shell::GetPrimaryRootWindow(), gesture_handler_.get());
   ash::Shell::GetPrimaryRootWindow()->ShowRootWindow();
 }
 
diff --git a/chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h b/chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h
index 540fba6..f32fee46 100644
--- a/chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h
+++ b/chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h
@@ -8,11 +8,8 @@
 
 #include "base/basictypes.h"
 #include "base/compiler_specific.h"
-#include "base/memory/scoped_ptr.h"
 #include "chrome/browser/chrome_browser_main_extra_parts.h"
 
-class UserGestureHandler;
-
 class ChromeBrowserMainExtraPartsAsh : public ChromeBrowserMainExtraParts {
  public:
   ChromeBrowserMainExtraPartsAsh();
@@ -24,8 +21,6 @@
   virtual void PostMainMessageLoopRun() OVERRIDE;
 
  private:
-  scoped_ptr<UserGestureHandler> gesture_handler_;
-
   DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainExtraPartsAsh);
 };
 
diff --git a/chrome/browser/ui/views/ash/chrome_shell_delegate.cc b/chrome/browser/ui/views/ash/chrome_shell_delegate.cc
index fb0c0a4..0d4cea98 100644
--- a/chrome/browser/ui/views/ash/chrome_shell_delegate.cc
+++ b/chrome/browser/ui/views/ash/chrome_shell_delegate.cc
@@ -20,6 +20,7 @@
 #include "chrome/browser/ui/browser_list.h"
 #include "chrome/browser/ui/views/ash/app_list/app_list_view_delegate.h"
 #include "chrome/browser/ui/views/ash/launcher/chrome_launcher_controller.h"
+#include "chrome/browser/ui/views/ash/user_action_handler.h"
 #include "chrome/browser/ui/views/ash/window_positioner.h"
 #include "chrome/browser/ui/views/frame/browser_view.h"
 #include "chrome/common/chrome_notification_types.h"
@@ -29,6 +30,7 @@
 #include "content/public/browser/user_metrics.h"
 #include "content/public/browser/web_contents.h"
 #include "grit/generated_resources.h"
+#include "ui/aura/client/user_action_client.h"
 #include "ui/aura/window.h"
 
 #if defined(OS_CHROMEOS)
@@ -288,6 +290,10 @@
 #endif
 }
 
+aura::client::UserActionClient* ChromeShellDelegate::CreateUserActionClient() {
+  return new UserActionHandler;
+}
+
 void ChromeShellDelegate::Observe(int type,
                                   const content::NotificationSource& source,
                                   const content::NotificationDetails& details) {
diff --git a/chrome/browser/ui/views/ash/chrome_shell_delegate.h b/chrome/browser/ui/views/ash/chrome_shell_delegate.h
index b404c56..ee0de4d 100644
--- a/chrome/browser/ui/views/ash/chrome_shell_delegate.h
+++ b/chrome/browser/ui/views/ash/chrome_shell_delegate.h
@@ -56,6 +56,7 @@
   virtual ash::SystemTrayDelegate* CreateSystemTrayDelegate(
       ash::SystemTray* tray) OVERRIDE;
   virtual ash::UserWallpaperDelegate* CreateUserWallpaperDelegate() OVERRIDE;
+  virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE;
 
   // content::NotificationObserver override:
   virtual void Observe(int type,
diff --git a/chrome/browser/ui/views/ash/user_gesture_handler.cc b/chrome/browser/ui/views/ash/user_action_handler.cc
similarity index 78%
rename from chrome/browser/ui/views/ash/user_gesture_handler.cc
rename to chrome/browser/ui/views/ash/user_action_handler.cc
index 696c769..c48bf47 100644
--- a/chrome/browser/ui/views/ash/user_gesture_handler.cc
+++ b/chrome/browser/ui/views/ash/user_action_handler.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "chrome/browser/ui/views/ash/user_gesture_handler.h"
+#include "chrome/browser/ui/views/ash/user_action_handler.h"
 
 #include "ash/wm/window_util.h"
 #include "chrome/browser/ui/browser.h"
@@ -26,14 +26,14 @@
   return wrapper->web_contents();
 }
 
-UserGestureHandler::UserGestureHandler() {}
+UserActionHandler::UserActionHandler() {}
 
-UserGestureHandler::~UserGestureHandler() {}
+UserActionHandler::~UserActionHandler() {}
 
-bool UserGestureHandler::OnUserGesture(
-    aura::client::UserGestureClient::Gesture gesture) {
-  switch (gesture) {
-    case aura::client::UserGestureClient::GESTURE_BACK: {
+bool UserActionHandler::OnUserAction(
+    aura::client::UserActionClient::Command command) {
+  switch (command) {
+    case aura::client::UserActionClient::BACK: {
       content::WebContents* contents = GetActiveWebContents();
       if (contents && contents->GetController().CanGoBack()) {
         contents->GetController().GoBack();
@@ -41,7 +41,7 @@
       }
       break;
     }
-    case aura::client::UserGestureClient::GESTURE_FORWARD: {
+    case aura::client::UserActionClient::FORWARD: {
       content::WebContents* contents = GetActiveWebContents();
       if (contents && contents->GetController().CanGoForward()) {
         contents->GetController().GoForward();
diff --git a/chrome/browser/ui/views/ash/user_action_handler.h b/chrome/browser/ui/views/ash/user_action_handler.h
new file mode 100644
index 0000000..ef343412
--- /dev/null
+++ b/chrome/browser/ui/views/ash/user_action_handler.h
@@ -0,0 +1,26 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_VIEWS_ASH_USER_ACTION_HANDLER_H_
+#define CHROME_BROWSER_UI_VIEWS_ASH_USER_ACTION_HANDLER_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/aura/client/user_action_client.h"
+
+class UserActionHandler : public aura::client::UserActionClient {
+ public:
+  UserActionHandler();
+  virtual ~UserActionHandler();
+
+  // aura::client::UserActionClient overrides:
+  virtual bool OnUserAction(
+      aura::client::UserActionClient::Command command) OVERRIDE;
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(UserActionHandler);
+};
+
+#endif  // CHROME_BROWSER_UI_VIEWS_ASH_USER_ACTION_HANDLER_H_
diff --git a/chrome/browser/ui/views/ash/user_gesture_handler.h b/chrome/browser/ui/views/ash/user_gesture_handler.h
deleted file mode 100644
index c8ff514..0000000
--- a/chrome/browser/ui/views/ash/user_gesture_handler.h
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_UI_VIEWS_ASH_USER_GESTURE_HANDLER_H_
-#define CHROME_BROWSER_UI_VIEWS_ASH_USER_GESTURE_HANDLER_H_
-#pragma once
-
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "ui/aura/client/user_gesture_client.h"
-
-class UserGestureHandler : public aura::client::UserGestureClient {
- public:
-  UserGestureHandler();
-  virtual ~UserGestureHandler();
-
-  // aura::client::UserGestureClient overrides:
-  virtual bool OnUserGesture(
-      aura::client::UserGestureClient::Gesture gesture) OVERRIDE;
-
- private:
-  DISALLOW_COPY_AND_ASSIGN(UserGestureHandler);
-};
-
-#endif  // CHROME_BROWSER_UI_VIEWS_ASH_USER_GESTURE_HANDLER_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index fe96c4f..e1efbb1d 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -3344,8 +3344,8 @@
         'browser/ui/views/ash/panel_view_aura.h',
         'browser/ui/views/ash/screenshot_taker.cc',
         'browser/ui/views/ash/screenshot_taker.h',
-        'browser/ui/views/ash/user_gesture_handler.cc',
-        'browser/ui/views/ash/user_gesture_handler.h',
+        'browser/ui/views/ash/user_action_handler.cc',
+        'browser/ui/views/ash/user_action_handler.h',
         'browser/ui/views/ash/volume_controller_chromeos.cc',
         'browser/ui/views/ash/volume_controller_chromeos.h',
         'browser/ui/views/ash/window_positioner.cc',
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp
index 327067b..1707e0f 100644
--- a/ui/aura/aura.gyp
+++ b/ui/aura/aura.gyp
@@ -47,8 +47,8 @@
         'client/stacking_client.h',
         'client/tooltip_client.cc',
         'client/tooltip_client.h',
-        'client/user_gesture_client.cc',
-        'client/user_gesture_client.h',
+        'client/user_action_client.cc',
+        'client/user_action_client.h',
         'client/visibility_client.cc',
         'client/visibility_client.h',
         'client/window_move_client.cc',
diff --git a/ui/aura/client/user_action_client.cc b/ui/aura/client/user_action_client.cc
new file mode 100644
index 0000000..cfb5fe1
--- /dev/null
+++ b/ui/aura/client/user_action_client.cc
@@ -0,0 +1,27 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/aura/client/user_action_client.h"
+
+#include "ui/aura/root_window.h"
+#include "ui/aura/window_property.h"
+
+namespace aura {
+namespace client {
+
+DEFINE_WINDOW_PROPERTY_KEY(UserActionClient*,
+                           kRootWindowUserActionClientKey,
+                           NULL);
+
+void SetUserActionClient(RootWindow* root_window, UserActionClient* client) {
+  root_window->SetProperty(kRootWindowUserActionClientKey, client);
+}
+
+UserActionClient* GetUserActionClient(RootWindow* root_window) {
+  return root_window ?
+      root_window->GetProperty(kRootWindowUserActionClientKey) : NULL;
+}
+
+}  // namespace client
+}  // namespace aura
diff --git a/ui/aura/client/user_action_client.h b/ui/aura/client/user_action_client.h
new file mode 100644
index 0000000..4f0d7d9
--- /dev/null
+++ b/ui/aura/client/user_action_client.h
@@ -0,0 +1,38 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_AURA_CLIENT_USER_ACTION_CLIENT_H_
+#define UI_AURA_CLIENT_USER_ACTION_CLIENT_H_
+#pragma once
+
+#include "ui/aura/aura_export.h"
+
+namespace aura {
+class RootWindow;
+namespace client {
+
+// An interface for handling a user action that isn't handled by the standard
+// event path.
+class AURA_EXPORT UserActionClient {
+ public:
+  enum Command {
+    BACK = 0,
+    FORWARD,
+  };
+
+  // Returns true if the command was handled and false otherwise.
+  virtual bool OnUserAction(Command command) = 0;
+
+  virtual ~UserActionClient() {}
+};
+
+// Sets/gets the client for handling user action on the specified root window.
+AURA_EXPORT void SetUserActionClient(RootWindow* root_window,
+                                     UserActionClient* client);
+AURA_EXPORT UserActionClient* GetUserActionClient(RootWindow* root_window);
+
+}  // namespace client
+}  // namespace aura
+
+#endif  // UI_AURA_CLIENT_USER_ACTION_CLIENT_H_
diff --git a/ui/aura/client/user_gesture_client.cc b/ui/aura/client/user_gesture_client.cc
deleted file mode 100644
index 78b43116..0000000
--- a/ui/aura/client/user_gesture_client.cc
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ui/aura/client/user_gesture_client.h"
-
-#include "ui/aura/root_window.h"
-#include "ui/aura/window_property.h"
-
-namespace aura {
-namespace client {
-
-DEFINE_WINDOW_PROPERTY_KEY(UserGestureClient*,
-                           kRootWindowUserGestureClientKey,
-                           NULL);
-
-void SetUserGestureClient(RootWindow* root_window, UserGestureClient* client) {
-  root_window->SetProperty(kRootWindowUserGestureClientKey, client);
-}
-
-UserGestureClient* GetUserGestureClient(RootWindow* root_window) {
-  return root_window ?
-      root_window->GetProperty(kRootWindowUserGestureClientKey) : NULL;
-}
-
-}  // namespace client
-}  // namespace aura
diff --git a/ui/aura/client/user_gesture_client.h b/ui/aura/client/user_gesture_client.h
deleted file mode 100644
index b82edbe9..0000000
--- a/ui/aura/client/user_gesture_client.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef UI_AURA_CLIENT_USER_GESTURE_CLIENT_H_
-#define UI_AURA_CLIENT_USER_GESTURE_CLIENT_H_
-#pragma once
-
-#include "ui/aura/aura_export.h"
-
-namespace aura {
-class RootWindow;
-namespace client {
-
-// An interface for handling user gestures that aren't handled by the standard
-// event path.
-class AURA_EXPORT UserGestureClient {
- public:
-  enum Gesture {
-    GESTURE_BACK = 0,
-    GESTURE_FORWARD,
-  };
-
-  // Returns true if the gesture was handled and false otherwise.
-  virtual bool OnUserGesture(Gesture gesture) = 0;
-
- protected:
-  virtual ~UserGestureClient() {}
-};
-
-// Sets/gets the client for handling gestures on the specified root window.
-AURA_EXPORT void SetUserGestureClient(RootWindow* root_window,
-                                      UserGestureClient* client);
-AURA_EXPORT UserGestureClient* GetUserGestureClient(RootWindow* root_window);
-
-}  // namespace client
-}  // namespace aura
-
-#endif  // UI_AURA_CLIENT_USER_GESTURE_CLIENT_H_
diff --git a/ui/aura/root_window_host_linux.cc b/ui/aura/root_window_host_linux.cc
index 6215f2f..5361409 100644
--- a/ui/aura/root_window_host_linux.cc
+++ b/ui/aura/root_window_host_linux.cc
@@ -18,7 +18,7 @@
 #include "base/stringprintf.h"
 #include "grit/ui_resources_standard.h"
 #include "third_party/skia/include/core/SkBitmap.h"
-#include "ui/aura/client/user_gesture_client.h"
+#include "ui/aura/client/user_action_client.h"
 #include "ui/aura/dispatcher_linux.h"
 #include "ui/aura/env.h"
 #include "ui/aura/event.h"
@@ -529,13 +529,13 @@
     case ButtonPress: {
       if (static_cast<int>(xev->xbutton.button) == kBackMouseButton ||
           static_cast<int>(xev->xbutton.button) == kForwardMouseButton) {
-        client::UserGestureClient* gesture_client =
-            client::GetUserGestureClient(root_window_);
+        client::UserActionClient* gesture_client =
+            client::GetUserActionClient(root_window_);
         if (gesture_client) {
-          gesture_client->OnUserGesture(
+          gesture_client->OnUserAction(
               static_cast<int>(xev->xbutton.button) == kBackMouseButton ?
-              client::UserGestureClient::GESTURE_BACK :
-              client::UserGestureClient::GESTURE_FORWARD);
+              client::UserActionClient::BACK :
+              client::UserActionClient::FORWARD);
         }
         break;
       }
@@ -606,16 +606,16 @@
                 static_cast<XIDeviceEvent*>(xev->xcookie.data);
             int button = xievent->detail;
             if (button == kBackMouseButton || button == kForwardMouseButton) {
-              client::UserGestureClient* gesture_client =
-                  client::GetUserGestureClient(root_window_);
+              client::UserActionClient* gesture_client =
+                  client::GetUserActionClient(root_window_);
               if (gesture_client) {
                 bool reverse_direction =
                     ui::IsTouchpadEvent(xev) && ui::IsNaturalScrollEnabled();
-                gesture_client->OnUserGesture(
+                gesture_client->OnUserAction(
                     (button == kBackMouseButton && !reverse_direction) ||
                     (button == kForwardMouseButton && reverse_direction) ?
-                    client::UserGestureClient::GESTURE_BACK :
-                    client::UserGestureClient::GESTURE_FORWARD);
+                    client::UserActionClient::BACK :
+                    client::UserActionClient::FORWARD);
               }
               break;
             }