summaryrefslogtreecommitdiffstats
path: root/ui/base
diff options
context:
space:
mode:
authorderat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-18 04:46:02 +0000
committerderat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-18 04:46:02 +0000
commit6ec7065e822ece6bc21c5d438af371e6e0c3e782 (patch)
treee39fa1ddabd2a2fa3303f3cdbc59b08af60bd6ea /ui/base
parentc9c73ad48a3b98a6c59181498e960790ea9cfdcc (diff)
downloadchromium_src-6ec7065e822ece6bc21c5d438af371e6e0c3e782.zip
chromium_src-6ec7065e822ece6bc21c5d438af371e6e0c3e782.tar.gz
chromium_src-6ec7065e822ece6bc21c5d438af371e6e0c3e782.tar.bz2
ash: Go back/forward in response to buttons 8 and 9.
This is needed on Chrome OS to support both mice with back/forward buttons and to support new events that I'll be sending from CMT (changes in progress). Tested that it can be triggered by the touchpad with the "simple scrolling direction" setting honored, and that back/forward mouse buttons work with simple scrolling ignored in that case. BUG=chromium-os:27349 TEST=manual: see above Review URL: http://codereview.chromium.org/9899002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132741 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base')
-rw-r--r--ui/base/events.h8
-rw-r--r--ui/base/win/events_win.cc12
-rw-r--r--ui/base/x/events_x.cc50
-rw-r--r--ui/base/x/events_x_unittest.cc18
4 files changed, 43 insertions, 45 deletions
diff --git a/ui/base/events.h b/ui/base/events.h
index 33fb77f..ef443be 100644
--- a/ui/base/events.h
+++ b/ui/base/events.h
@@ -189,6 +189,14 @@ UI_EXPORT bool GetGestureTimes(const base::NativeEvent& native_event,
// Enable/disable natural scrolling for touchpads.
UI_EXPORT void SetNaturalScroll(bool enabled);
+// In natural scrolling enabled for touchpads?
+UI_EXPORT bool IsNaturalScrollEnabled();
+
+// Was this event generated by a touchpad device?
+// The caller is responsible for ensuring that this is a mouse/touchpad event
+// before calling this function.
+UI_EXPORT bool IsTouchpadEvent(const base::NativeEvent& event);
+
// Returns true if event is noop.
UI_EXPORT bool IsNoopEvent(const base::NativeEvent& event);
diff --git a/ui/base/win/events_win.cc b/ui/base/win/events_win.cc
index b650e1d..9f75b6f 100644
--- a/ui/base/win/events_win.cc
+++ b/ui/base/win/events_win.cc
@@ -127,6 +127,10 @@ int MouseStateFlagsFromNative(const base::NativeEvent& native_event) {
namespace ui {
+void UpdateDeviceList() {
+ NOTIMPLEMENTED();
+}
+
EventType EventTypeFromNative(const base::NativeEvent& native_event) {
switch (native_event.message) {
case WM_KEYDOWN:
@@ -276,8 +280,14 @@ void SetNaturalScroll(bool enabled) {
NOTIMPLEMENTED();
}
-void UpdateDeviceList() {
+bool IsNaturalScrollEnabled() {
NOTIMPLEMENTED();
+ return false;
+}
+
+bool IsTouchpadEvent(const base::NativeEvent& event) {
+ NOTIMPLEMENTED();
+ return false;
}
bool IsNoopEvent(const base::NativeEvent& event) {
diff --git a/ui/base/x/events_x.cc b/ui/base/x/events_x.cc
index 8bb5aebd4..c914599 100644
--- a/ui/base/x/events_x.cc
+++ b/ui/base/x/events_x.cc
@@ -34,18 +34,8 @@ namespace {
// Scroll amount for each wheelscroll event. 53 is also the value used for GTK+.
const int kWheelScrollAmount = 53;
-const int kMinWheelButton = 4;
-#if defined(OS_CHROMEOS)
-// TODO(davemoore) For now use the button to decide how much to scroll by.
-// When we go to XI2 scroll events this won't be necessary. If this doesn't
-// happen for some reason we can better detect which devices are touchpads.
-const int kTouchpadScrollAmount = 3;
-
-// Chrome OS also uses buttons 8 and 9 for scrolling.
-const int kMaxWheelButton = 9;
-#else
-const int kMaxWheelButton = 7;
-#endif
+static const int kMinWheelButton = 4;
+static const int kMaxWheelButton = 7;
// A class to support the detection of scroll events, using X11 valuators.
class UI_EXPORT CMTEventData {
@@ -133,10 +123,20 @@ class UI_EXPORT CMTEventData {
XIFreeDeviceInfo(info_list);
}
+ bool natural_scroll_enabled() const { return natural_scroll_enabled_; }
void set_natural_scroll_enabled(bool enabled) {
natural_scroll_enabled_ = enabled;
}
+ bool IsTouchpadXInputEvent(const base::NativeEvent& native_event) {
+ if (native_event->type != GenericEvent)
+ return false;
+
+ XIDeviceEvent* xievent =
+ static_cast<XIDeviceEvent*>(native_event->xcookie.data);
+ return touchpads_[xievent->sourceid];
+ }
+
float GetNaturalScrollFactor(int deviceid) {
// Natural scroll is touchpad-only.
if (!touchpads_[deviceid])
@@ -515,6 +515,12 @@ Atom GetNoopEventAtom() {
namespace ui {
+void UpdateDeviceList() {
+ Display* display = GetXDisplay();
+ CMTEventData::GetInstance()->UpdateDeviceList(display);
+ TouchFactory::GetInstance()->UpdateDeviceList(display);
+}
+
EventType EventTypeFromNative(const base::NativeEvent& native_event) {
switch (native_event->type) {
case KeyPress:
@@ -748,19 +754,9 @@ int GetMouseWheelOffset(const base::NativeEvent& native_event) {
switch (button) {
case 4:
-#if defined(OS_CHROMEOS)
- return kTouchpadScrollAmount;
- case 8:
-#endif
return kWheelScrollAmount;
-
case 5:
-#if defined(OS_CHROMEOS)
- return -kTouchpadScrollAmount;
- case 9:
-#endif
return -kWheelScrollAmount;
-
default:
// TODO(derat): Do something for horizontal scrolls (buttons 6 and 7)?
return 0;
@@ -852,10 +848,12 @@ void SetNaturalScroll(bool enabled) {
CMTEventData::GetInstance()->set_natural_scroll_enabled(enabled);
}
-void UpdateDeviceList() {
- Display* display = GetXDisplay();
- CMTEventData::GetInstance()->UpdateDeviceList(display);
- TouchFactory::GetInstance()->UpdateDeviceList(display);
+bool IsNaturalScrollEnabled() {
+ return CMTEventData::GetInstance()->natural_scroll_enabled();
+}
+
+bool IsTouchpadEvent(const base::NativeEvent& event) {
+ return CMTEventData::GetInstance()->IsTouchpadXInputEvent(event);
}
bool IsNoopEvent(const base::NativeEvent& event) {
diff --git a/ui/base/x/events_x_unittest.cc b/ui/base/x/events_x_unittest.cc
index 65b46aa..18010a3 100644
--- a/ui/base/x/events_x_unittest.cc
+++ b/ui/base/x/events_x_unittest.cc
@@ -94,24 +94,6 @@ TEST(EventsXTest, ButtonEvents) {
EXPECT_TRUE(ui::IsMouseEvent(&event));
EXPECT_EQ(0, ui::GetMouseWheelOffset(&event));
-#if defined(OS_CHROMEOS)
- // Scroll up.
- InitButtonEvent(&event, true, location, 8, 0);
- EXPECT_EQ(ui::ET_MOUSEWHEEL, ui::EventTypeFromNative(&event));
- EXPECT_EQ(0, ui::EventFlagsFromNative(&event));
- EXPECT_EQ(location, ui::EventLocationFromNative(&event));
- EXPECT_TRUE(ui::IsMouseEvent(&event));
- EXPECT_GT(ui::GetMouseWheelOffset(&event), 0);
-
- // Scroll down.
- InitButtonEvent(&event, true, location, 9, 0);
- EXPECT_EQ(ui::ET_MOUSEWHEEL, ui::EventTypeFromNative(&event));
- EXPECT_EQ(0, ui::EventFlagsFromNative(&event));
- EXPECT_EQ(location, ui::EventLocationFromNative(&event));
- EXPECT_TRUE(ui::IsMouseEvent(&event));
- EXPECT_LT(ui::GetMouseWheelOffset(&event), 0);
-#endif
-
// TODO(derat): Test XInput code.
}