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_linux.h" |
| 6 |
| 7 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 9 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 10 #include "content/public/browser/navigation_controller.h" |
| 11 #include "content/public/browser/web_contents.h" |
| 12 #include "ui/aura/window.h" |
| 13 #include "ui/events/event.h" |
| 14 |
| 15 BrowserCommandHandlerLinux::BrowserCommandHandlerLinux( |
| 16 BrowserView* browser_view) |
| 17 : browser_view_(browser_view) { |
| 18 aura::Window* window = browser_view_->frame()->GetNativeWindow(); |
| 19 DCHECK(window); |
| 20 if (window) |
| 21 window->AddPreTargetHandler(this); |
| 22 } |
| 23 |
| 24 BrowserCommandHandlerLinux::~BrowserCommandHandlerLinux() { |
| 25 aura::Window* window = browser_view_->frame()->GetNativeWindow(); |
| 26 if (window) |
| 27 window->RemovePreTargetHandler(this); |
| 28 } |
| 29 |
| 30 void BrowserCommandHandlerLinux::OnMouseEvent(ui::MouseEvent* event) { |
| 31 // Handle standard Linux mouse buttons for going back and forward. |
| 32 if (event->type() != ui::ET_MOUSE_PRESSED) |
| 33 return; |
| 34 |
| 35 bool back_button_pressed = |
| 36 (event->changed_button_flags() == ui::EF_BACK_MOUSE_BUTTON); |
| 37 bool forward_button_pressed = |
| 38 (event->changed_button_flags() == ui::EF_FORWARD_MOUSE_BUTTON); |
| 39 if (!back_button_pressed && !forward_button_pressed) |
| 40 return; |
| 41 |
| 42 content::WebContents* contents = |
| 43 browser_view_->browser()->tab_strip_model()->GetActiveWebContents(); |
| 44 if (!contents) |
| 45 return; |
| 46 content::NavigationController& controller = contents->GetController(); |
| 47 if (back_button_pressed && controller.CanGoBack()) |
| 48 controller.GoBack(); |
| 49 else if (forward_button_pressed && controller.CanGoForward()) |
| 50 controller.GoForward(); |
| 51 // Always consume the event, whether a navigation was successful or not. |
| 52 event->SetHandled(); |
| 53 } |
OLD | NEW |