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