OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/frame/browser_command_handler_x11.h" | 5 #include "chrome/browser/ui/views/frame/browser_command_handler_x11.h" |
6 | 6 |
7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
8 | 8 |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_window.h" |
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
11 #include "content/public/browser/navigation_controller.h" | 12 #include "content/public/browser/navigation_controller.h" |
12 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 #include "ui/aura/window.h" |
13 #include "ui/events/event.h" | 15 #include "ui/events/event.h" |
14 #include "ui/events/event_utils.h" | 16 #include "ui/events/event_utils.h" |
15 | 17 |
16 BrowserCommandHandlerX11::BrowserCommandHandlerX11(Browser* browser) | 18 BrowserCommandHandlerX11::BrowserCommandHandlerX11(Browser* browser) |
17 : browser_(browser) {} | 19 : browser_(browser) { |
| 20 browser->window()->GetNativeWindow()->AddPreTargetHandler(this); |
| 21 } |
18 | 22 |
19 BrowserCommandHandlerX11::~BrowserCommandHandlerX11() {} | 23 BrowserCommandHandlerX11::~BrowserCommandHandlerX11() { |
| 24 browser_->window()->GetNativeWindow()->RemovePreTargetHandler(this); |
| 25 } |
20 | 26 |
21 void BrowserCommandHandlerX11::OnMouseEvent(ui::MouseEvent* event) { | 27 void BrowserCommandHandlerX11::OnMouseEvent(ui::MouseEvent* event) { |
22 if (event->type() != ui::ET_MOUSE_PRESSED) | 28 if (event->type() != ui::ET_MOUSE_PRESSED) |
23 return; | 29 return; |
24 XEvent* xevent = event->native_event(); | 30 XEvent* xevent = event->native_event(); |
25 if (!xevent) | 31 if (!xevent) |
26 return; | 32 return; |
27 int button = xevent->type == GenericEvent ? ui::EventButtonFromNative(xevent) | 33 int button = xevent->type == GenericEvent ? ui::EventButtonFromNative(xevent) |
28 : xevent->xbutton.button; | 34 : xevent->xbutton.button; |
29 | 35 |
30 // Standard Linux mouse buttons for going back and forward. | 36 // Standard Linux mouse buttons for going back and forward. |
31 const int kBackMouseButton = 8; | 37 const int kBackMouseButton = 8; |
32 const int kForwardMouseButton = 9; | 38 const int kForwardMouseButton = 9; |
33 if (button == kBackMouseButton || button == kForwardMouseButton) { | 39 if (button == kBackMouseButton || button == kForwardMouseButton) { |
34 content::WebContents* contents = | 40 content::WebContents* contents = |
35 browser_->tab_strip_model()->GetActiveWebContents(); | 41 browser_->tab_strip_model()->GetActiveWebContents(); |
36 if (!contents) | 42 if (!contents) |
37 return; | 43 return; |
38 content::NavigationController& controller = contents->GetController(); | 44 content::NavigationController& controller = contents->GetController(); |
39 if (button == kBackMouseButton && controller.CanGoBack()) | 45 if (button == kBackMouseButton && controller.CanGoBack()) |
40 controller.GoBack(); | 46 controller.GoBack(); |
41 else if (button == kForwardMouseButton && controller.CanGoForward()) | 47 else if (button == kForwardMouseButton && controller.CanGoForward()) |
42 controller.GoForward(); | 48 controller.GoForward(); |
43 // Always consume the event, whether a navigation was successful or not. | 49 // Always consume the event, whether a navigation was successful or not. |
44 event->SetHandled(); | 50 event->SetHandled(); |
45 } | 51 } |
46 } | 52 } |
OLD | NEW |