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