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