diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-06 20:35:25 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-06 20:35:25 +0000 |
commit | 06b1d42b0ceadd4a70b7462c5c7e6adeb5a18ca4 (patch) | |
tree | 668fa900e2851fa2eca43b2e5a087dde2f17b9d7 /chrome/browser | |
parent | ca40ae55cf880d8abf4e8e9c1983d61174fe1432 (diff) | |
download | chromium_src-06b1d42b0ceadd4a70b7462c5c7e6adeb5a18ca4.zip chromium_src-06b1d42b0ceadd4a70b7462c5c7e6adeb5a18ca4.tar.gz chromium_src-06b1d42b0ceadd4a70b7462c5c7e6adeb5a18ca4.tar.bz2 |
aura: Remove client::UserActionClient.
UserActionClient is used to navigate back/forward when the back/forward on a
supported mouse-device is clicked on X11. This can instead be achieved by
installing an event-handler on the browser window.
This does change the behaviour a little on ChromeOS: clicking these navigation
buttons when the cursor is not on top of the browser window will not navigate
after this change. I have confirmed with UX that this is a desirable change.
BUG=319636
R=sky@chromium.org
Previously landed in r255385, reverted in r255398 to allow another revert in r255399.
Review URL: https://codereview.chromium.org/183853037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255416 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
12 files changed, 90 insertions, 180 deletions
diff --git a/chrome/browser/ui/ash/chrome_shell_delegate.cc b/chrome/browser/ui/ash/chrome_shell_delegate.cc index 5fe0574..bffe745 100644 --- a/chrome/browser/ui/ash/chrome_shell_delegate.cc +++ b/chrome/browser/ui/ash/chrome_shell_delegate.cc @@ -21,7 +21,6 @@ #include "chrome/browser/ui/ash/ash_keyboard_controller_proxy.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" -#include "chrome/browser/ui/ash/user_action_handler.h" #include "chrome/browser/ui/browser_commands.h" #include "chrome/common/chrome_switches.h" #include "grit/chromium_strings.h" @@ -125,10 +124,6 @@ ash::ShelfDelegate* ChromeShellDelegate::CreateShelfDelegate( return shelf_delegate_; } -aura::client::UserActionClient* ChromeShellDelegate::CreateUserActionClient() { - return new UserActionHandler; -} - ui::MenuModel* ChromeShellDelegate::CreateContextMenu( aura::Window* root, ash::ShelfItemDelegate* item_delegate, diff --git a/chrome/browser/ui/ash/chrome_shell_delegate.h b/chrome/browser/ui/ash/chrome_shell_delegate.h index c009dd7..1e8bd56 100644 --- a/chrome/browser/ui/ash/chrome_shell_delegate.h +++ b/chrome/browser/ui/ash/chrome_shell_delegate.h @@ -66,7 +66,6 @@ class ChromeShellDelegate : public ash::ShellDelegate, virtual ash::AccessibilityDelegate* CreateAccessibilityDelegate() OVERRIDE; virtual ash::NewWindowDelegate* CreateNewWindowDelegate() OVERRIDE; virtual ash::MediaDelegate* CreateMediaDelegate() OVERRIDE; - virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE; virtual ui::MenuModel* CreateContextMenu( aura::Window* root, ash::ShelfItemDelegate* item_delegate, diff --git a/chrome/browser/ui/ash/user_action_handler.cc b/chrome/browser/ui/ash/user_action_handler.cc deleted file mode 100644 index c7e61cf..0000000 --- a/chrome/browser/ui/ash/user_action_handler.cc +++ /dev/null @@ -1,54 +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 "chrome/browser/ui/ash/user_action_handler.h" - -#include "ash/wm/window_util.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/browser_finder.h" -#include "chrome/browser/ui/browser_window.h" -#include "chrome/browser/ui/tabs/tab_strip_model.h" -#include "content/public/browser/web_contents.h" - -// Returns the currently-active WebContents belonging to the active browser, or -// NULL if there's no currently-active browser. -content::WebContents* GetActiveWebContents() { - Browser* browser = chrome::FindLastActiveWithHostDesktopType( - chrome::HOST_DESKTOP_TYPE_ASH); - if (!browser) - return NULL; - if (!ash::wm::IsActiveWindow(browser->window()->GetNativeWindow())) - return NULL; - - return browser->tab_strip_model()->GetActiveWebContents(); -} - -UserActionHandler::UserActionHandler() {} - -UserActionHandler::~UserActionHandler() {} - -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(); - return true; - } - break; - } - case aura::client::UserActionClient::FORWARD: { - content::WebContents* contents = GetActiveWebContents(); - if (contents && contents->GetController().CanGoForward()) { - contents->GetController().GoForward(); - return true; - } - break; - } - default: - break; - } - return false; -} diff --git a/chrome/browser/ui/ash/user_action_handler.h b/chrome/browser/ui/ash/user_action_handler.h deleted file mode 100644 index ac3f7f0..0000000 --- a/chrome/browser/ui/ash/user_action_handler.h +++ /dev/null @@ -1,25 +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_ASH_USER_ACTION_HANDLER_H_ -#define CHROME_BROWSER_UI_ASH_USER_ACTION_HANDLER_H_ - -#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_ASH_USER_ACTION_HANDLER_H_ diff --git a/chrome/browser/ui/views/frame/browser_command_handler_x11.cc b/chrome/browser/ui/views/frame/browser_command_handler_x11.cc new file mode 100644 index 0000000..ce37fcc --- /dev/null +++ b/chrome/browser/ui/views/frame/browser_command_handler_x11.cc @@ -0,0 +1,46 @@ +// Copyright 2014 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 "chrome/browser/ui/views/frame/browser_command_handler_x11.h" + +#include <X11/Xlib.h> + +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/tabs/tab_strip_model.h" +#include "content/public/browser/navigation_controller.h" +#include "content/public/browser/web_contents.h" +#include "ui/events/event.h" +#include "ui/events/event_utils.h" + +BrowserCommandHandlerX11::BrowserCommandHandlerX11(Browser* browser) + : browser_(browser) {} + +BrowserCommandHandlerX11::~BrowserCommandHandlerX11() {} + +void BrowserCommandHandlerX11::OnMouseEvent(ui::MouseEvent* event) { + if (event->type() != ui::ET_MOUSE_PRESSED) + return; + XEvent* xevent = event->native_event(); + if (!xevent) + return; + int button = xevent->type == GenericEvent ? ui::EventButtonFromNative(xevent) + : xevent->xbutton.button; + + // Standard Linux mouse buttons for going back and forward. + const int kBackMouseButton = 8; + const int kForwardMouseButton = 9; + if (button == kBackMouseButton || button == kForwardMouseButton) { + content::WebContents* contents = + browser_->tab_strip_model()->GetActiveWebContents(); + if (!contents) + return; + content::NavigationController& controller = contents->GetController(); + if (button == kBackMouseButton && controller.CanGoBack()) + controller.GoBack(); + else if (button == kForwardMouseButton && controller.CanGoForward()) + controller.GoForward(); + // Always consume the event, whether a navigation was successful or not. + event->SetHandled(); + } +} diff --git a/chrome/browser/ui/views/frame/browser_command_handler_x11.h b/chrome/browser/ui/views/frame/browser_command_handler_x11.h new file mode 100644 index 0000000..785c16d --- /dev/null +++ b/chrome/browser/ui/views/frame/browser_command_handler_x11.h @@ -0,0 +1,26 @@ +// Copyright 2014 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_FRAME_BROWSER_COMMAND_HANDLER_X11_H_ +#define CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_COMMAND_HANDLER_X11_H_ + +#include "ui/events/event_handler.h" + +class Browser; + +class BrowserCommandHandlerX11 : public ui::EventHandler { + public: + explicit BrowserCommandHandlerX11(Browser* browser); + virtual ~BrowserCommandHandlerX11(); + + private: + // ui::EventHandler: + virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; + + Browser* browser_; + + DISALLOW_COPY_AND_ASSIGN(BrowserCommandHandlerX11); +}; + +#endif // CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_COMMAND_HANDLER_X11_H_ diff --git a/chrome/browser/ui/views/frame/browser_frame.cc b/chrome/browser/ui/views/frame/browser_frame.cc index 91f58f0..a3143f0 100644 --- a/chrome/browser/ui/views/frame/browser_frame.cc +++ b/chrome/browser/ui/views/frame/browser_frame.cc @@ -29,6 +29,7 @@ #include "ui/aura/window_event_dispatcher.h" #include "ui/base/hit_test.h" #include "ui/base/theme_provider.h" +#include "ui/events/event_handler.h" #include "ui/gfx/font_list.h" #include "ui/gfx/screen.h" #include "ui/views/controls/menu/menu_runner.h" @@ -46,6 +47,10 @@ #include "ash/session_state_delegate.h" #endif +#if defined(USE_X11) +#include "chrome/browser/ui/views/frame/browser_command_handler_x11.h" +#endif + //////////////////////////////////////////////////////////////////////////////// // BrowserFrame, public: @@ -60,9 +65,16 @@ BrowserFrame::BrowserFrame(BrowserView* browser_view) set_is_secondary_widget(false); // Don't focus anything on creation, selecting a tab will set the focus. set_focus_on_creation(false); + +#if defined(USE_X11) + browser_command_handler_.reset( + new BrowserCommandHandlerX11(browser_view_->browser())); +#endif } BrowserFrame::~BrowserFrame() { + if (browser_command_handler_ && GetNativeView()) + GetNativeView()->RemovePreTargetHandler(browser_command_handler_.get()); } // static @@ -139,6 +151,9 @@ void BrowserFrame::InitBrowserFrame() { DCHECK(non_client_view()); non_client_view()->set_context_menu_controller(this); } + + if (browser_command_handler_) + GetNativeWindow()->AddPreTargetHandler(browser_command_handler_.get()); } void BrowserFrame::SetThemeProvider(scoped_ptr<ui::ThemeProvider> provider) { diff --git a/chrome/browser/ui/views/frame/browser_frame.h b/chrome/browser/ui/views/frame/browser_frame.h index fa379b2..87bdea0 100644 --- a/chrome/browser/ui/views/frame/browser_frame.h +++ b/chrome/browser/ui/views/frame/browser_frame.h @@ -27,6 +27,7 @@ class Rect; } namespace ui { +class EventHandler; class MenuModel; class ThemeProvider; } @@ -138,6 +139,8 @@ class BrowserFrame // Whether the custom Chrome frame preference is set. BooleanPrefMember use_custom_frame_pref_; + scoped_ptr<ui::EventHandler> browser_command_handler_; + DISALLOW_COPY_AND_ASSIGN(BrowserFrame); }; diff --git a/chrome/browser/ui/views/frame/desktop_browser_frame_aura.cc b/chrome/browser/ui/views/frame/desktop_browser_frame_aura.cc index e632526..2e87976 100644 --- a/chrome/browser/ui/views/frame/desktop_browser_frame_aura.cc +++ b/chrome/browser/ui/views/frame/desktop_browser_frame_aura.cc @@ -8,7 +8,6 @@ #include "chrome/browser/ui/views/frame/browser_desktop_window_tree_host.h" #include "chrome/browser/ui/views/frame/browser_shutdown.h" #include "chrome/browser/ui/views/frame/browser_view.h" -#include "chrome/browser/ui/views/frame/desktop_user_action_handler_aura.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "ui/aura/client/aura_constants.h" @@ -68,11 +67,6 @@ void DesktopBrowserFrameAura::InitNativeWidget( browser_desktop_window_tree_host_->AsDesktopWindowTreeHost(); DesktopNativeWidgetAura::InitNativeWidget(modified_params); - user_action_client_.reset( - new DesktopUserActionHandlerAura(browser_view_->browser())); - aura::client::SetUserActionClient(GetNativeView()->GetRootWindow(), - user_action_client_.get()); - visibility_controller_.reset(new views::corewm::VisibilityController); aura::client::SetVisibilityClient(GetNativeView()->GetRootWindow(), visibility_controller_.get()); diff --git a/chrome/browser/ui/views/frame/desktop_browser_frame_aura.h b/chrome/browser/ui/views/frame/desktop_browser_frame_aura.h index edaf381..ec782b9 100644 --- a/chrome/browser/ui/views/frame/desktop_browser_frame_aura.h +++ b/chrome/browser/ui/views/frame/desktop_browser_frame_aura.h @@ -15,12 +15,6 @@ class BrowserDesktopWindowTreeHost; class BrowserFrame; class BrowserView; -namespace aura { -namespace client { -class UserActionClient; -} -} - namespace views { namespace corewm { class VisibilityController; @@ -63,7 +57,6 @@ class DesktopBrowserFrameAura : public views::DesktopNativeWidgetAura, // Owned by the RootWindow. BrowserDesktopWindowTreeHost* browser_desktop_window_tree_host_; - scoped_ptr<aura::client::UserActionClient> user_action_client_; scoped_ptr<views::corewm::VisibilityController> visibility_controller_; DISALLOW_COPY_AND_ASSIGN(DesktopBrowserFrameAura); diff --git a/chrome/browser/ui/views/frame/desktop_user_action_handler_aura.cc b/chrome/browser/ui/views/frame/desktop_user_action_handler_aura.cc deleted file mode 100644 index c2f6e98..0000000 --- a/chrome/browser/ui/views/frame/desktop_user_action_handler_aura.cc +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2013 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 "chrome/browser/ui/views/frame/desktop_user_action_handler_aura.h" - -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/tabs/tab_strip_model.h" -#include "content/public/browser/web_contents.h" - -DesktopUserActionHandlerAura::DesktopUserActionHandlerAura(Browser* browser) - : browser_(browser) { -} - -DesktopUserActionHandlerAura::~DesktopUserActionHandlerAura() {} - -bool DesktopUserActionHandlerAura::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(); - return true; - } - break; - } - case aura::client::UserActionClient::FORWARD: { - content::WebContents* contents = GetActiveWebContents(); - if (contents && contents->GetController().CanGoForward()) { - contents->GetController().GoForward(); - return true; - } - break; - } - default: - break; - } - return false; -} - -content::WebContents* -DesktopUserActionHandlerAura::GetActiveWebContents() const { - return browser_->tab_strip_model()->GetActiveWebContents(); -} diff --git a/chrome/browser/ui/views/frame/desktop_user_action_handler_aura.h b/chrome/browser/ui/views/frame/desktop_user_action_handler_aura.h deleted file mode 100644 index a3a61ee..0000000 --- a/chrome/browser/ui/views/frame/desktop_user_action_handler_aura.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2013 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_FRAME_DESKTOP_USER_ACTION_HANDLER_AURA_H_ -#define CHROME_BROWSER_UI_VIEWS_FRAME_DESKTOP_USER_ACTION_HANDLER_AURA_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "ui/aura/client/user_action_client.h" - -class Browser; - -namespace content { -class WebContents; -} - -// Handles back/forward commands on a per-browser basis. -class DesktopUserActionHandlerAura : public aura::client::UserActionClient { - public: - explicit DesktopUserActionHandlerAura(Browser* browser); - virtual ~DesktopUserActionHandlerAura(); - - // Overridden from aura::client::UserActionClient: - virtual bool OnUserAction( - aura::client::UserActionClient::Command command) OVERRIDE; - - private: - // Returns the active web contents of |browser_|. - content::WebContents* GetActiveWebContents() const; - - Browser* browser_; - - DISALLOW_COPY_AND_ASSIGN(DesktopUserActionHandlerAura); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_FRAME_DESKTOP_USER_ACTION_HANDLER_AURA_H_ |