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/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 11 #include "chrome/browser/ui/views/frame/browser_view.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(BrowserView* browser_view) |
17 : browser_(browser) {} | 19 : browser_view_(browser_view) { |
| 20 aura::Window* window = browser_view_->frame()->GetNativeWindow(); |
| 21 DCHECK(window); |
| 22 if (window) |
| 23 window->AddPreTargetHandler(this); |
| 24 } |
18 | 25 |
19 BrowserCommandHandlerX11::~BrowserCommandHandlerX11() {} | 26 BrowserCommandHandlerX11::~BrowserCommandHandlerX11() { |
| 27 aura::Window* window = browser_view_->frame()->GetNativeWindow(); |
| 28 if (window) |
| 29 window->RemovePreTargetHandler(this); |
| 30 } |
20 | 31 |
21 void BrowserCommandHandlerX11::OnMouseEvent(ui::MouseEvent* event) { | 32 void BrowserCommandHandlerX11::OnMouseEvent(ui::MouseEvent* event) { |
22 if (event->type() != ui::ET_MOUSE_PRESSED) | 33 if (event->type() != ui::ET_MOUSE_PRESSED) |
23 return; | 34 return; |
24 XEvent* xevent = event->native_event(); | 35 XEvent* xevent = event->native_event(); |
25 if (!xevent) | 36 if (!xevent) |
26 return; | 37 return; |
27 int button = xevent->type == GenericEvent ? ui::EventButtonFromNative(xevent) | 38 int button = xevent->type == GenericEvent ? ui::EventButtonFromNative(xevent) |
28 : xevent->xbutton.button; | 39 : xevent->xbutton.button; |
29 | 40 |
30 // Standard Linux mouse buttons for going back and forward. | 41 // Standard Linux mouse buttons for going back and forward. |
31 const int kBackMouseButton = 8; | 42 const int kBackMouseButton = 8; |
32 const int kForwardMouseButton = 9; | 43 const int kForwardMouseButton = 9; |
33 if (button == kBackMouseButton || button == kForwardMouseButton) { | 44 if (button == kBackMouseButton || button == kForwardMouseButton) { |
34 content::WebContents* contents = | 45 content::WebContents* contents = |
35 browser_->tab_strip_model()->GetActiveWebContents(); | 46 browser_view_->browser()->tab_strip_model()->GetActiveWebContents(); |
36 if (!contents) | 47 if (!contents) |
37 return; | 48 return; |
38 content::NavigationController& controller = contents->GetController(); | 49 content::NavigationController& controller = contents->GetController(); |
39 if (button == kBackMouseButton && controller.CanGoBack()) | 50 if (button == kBackMouseButton && controller.CanGoBack()) |
40 controller.GoBack(); | 51 controller.GoBack(); |
41 else if (button == kForwardMouseButton && controller.CanGoForward()) | 52 else if (button == kForwardMouseButton && controller.CanGoForward()) |
42 controller.GoForward(); | 53 controller.GoForward(); |
43 // Always consume the event, whether a navigation was successful or not. | 54 // Always consume the event, whether a navigation was successful or not. |
44 event->SetHandled(); | 55 event->SetHandled(); |
45 } | 56 } |
46 } | 57 } |
OLD | NEW |