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