diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-22 18:42:38 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-22 18:42:38 +0000 |
commit | 6b031fded2df8357b804f08fe84503b5b1adbb8d (patch) | |
tree | d7a8ececabab8a0643d18354a96f90d9bf146eba | |
parent | bc04b24f04d8afd339c24d9f214481377de2aa56 (diff) | |
download | chromium_src-6b031fded2df8357b804f08fe84503b5b1adbb8d.zip chromium_src-6b031fded2df8357b804f08fe84503b5b1adbb8d.tar.gz chromium_src-6b031fded2df8357b804f08fe84503b5b1adbb8d.tar.bz2 |
Fix mouse-wheel scrolling and shifted/capslocked keyevents for touchui.
BUG=None
TEST=Mouse wheel should work in a webpage, and shift+a should show up as 'A' in a textfield. Caps-lock should also work.
Review URL: http://codereview.chromium.org/4341001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66977 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view_gtk.cc | 1 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view_views.cc | 41 | ||||
-rw-r--r-- | views/event.h | 4 | ||||
-rw-r--r-- | views/event_x.cc | 10 | ||||
-rw-r--r-- | views/focus/accelerator_handler_touch.cc | 18 |
5 files changed, 56 insertions, 18 deletions
diff --git a/chrome/browser/renderer_host/render_widget_host_view_gtk.cc b/chrome/browser/renderer_host/render_widget_host_view_gtk.cc index bbbe456..414c540 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_gtk.cc +++ b/chrome/browser/renderer_host/render_widget_host_view_gtk.cc @@ -366,6 +366,7 @@ class RenderWidgetHostViewGtkWidget { static float GetScrollPixelsPerTick() { static float scroll_pixels = -1; if (scroll_pixels < 0) { + // TODO(brettw): Remove the command line switch (crbug.com/63525) scroll_pixels = kDefaultScrollPixelsPerTick; CommandLine* command_line = CommandLine::ForCurrentProcess(); std::string scroll_pixels_option = diff --git a/chrome/browser/renderer_host/render_widget_host_view_views.cc b/chrome/browser/renderer_host/render_widget_host_view_views.cc index 014c7fd..f5cdaeb 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_views.cc +++ b/chrome/browser/renderer_host/render_widget_host_view_views.cc @@ -45,10 +45,24 @@ int WebInputEventFlagsFromViewsEvent(const views::Event& event) { modifiers |= WebKit::WebInputEvent::ControlKey; if (event.IsAltDown()) modifiers |= WebKit::WebInputEvent::AltKey; + if (event.IsCapsLockDown()) + modifiers |= WebKit::WebInputEvent::CapsLockOn; return modifiers; } +void InitializeWebMouseEventFromViewsEvent(const views::LocatedEvent& e, + const gfx::Point& origin, + WebKit::WebMouseEvent* wmevent) { + wmevent->timeStampSeconds = base::Time::Now().ToDoubleT(); + wmevent->modifiers = WebInputEventFlagsFromViewsEvent(e); + + wmevent->windowX = wmevent->x = e.x(); + wmevent->windowY = wmevent->y = e.y(); + wmevent->globalX = wmevent->x + origin.x(); + wmevent->globalY = wmevent->y + origin.y(); +} + } // namespace // static @@ -397,8 +411,18 @@ void RenderWidgetHostViewViews::OnMouseExited(const views::MouseEvent& event) { } bool RenderWidgetHostViewViews::OnMouseWheel(const views::MouseWheelEvent& e) { - NOTIMPLEMENTED(); - return false; + WebMouseWheelEvent wmwe; + InitializeWebMouseEventFromViewsEvent(e, GetPosition(), &wmwe); + + wmwe.type = WebKit::WebInputEvent::MouseWheel; + wmwe.button = WebKit::WebMouseEvent::ButtonNone; + + // TODO(sadrul): How do we determine if it's a horizontal scroll? + wmwe.deltaY = e.GetOffset(); + wmwe.wheelTicksY = wmwe.deltaY > 0 ? 1 : -1; + + GetRenderWidgetHost()->ForwardWheelEvent(wmwe); + return true; } bool RenderWidgetHostViewViews::OnKeyPressed(const views::KeyEvent &e) { @@ -412,7 +436,8 @@ bool RenderWidgetHostViewViews::OnKeyPressed(const views::KeyEvent &e) { wke.text[0] = wke.unmodifiedText[0] = static_cast<unsigned short>(gdk_keyval_to_unicode( - app::GdkKeyCodeForWindowsKeyCode(e.GetKeyCode(), false /*shift*/))); + app::GdkKeyCodeForWindowsKeyCode(e.GetKeyCode(), + e.IsShiftDown() ^ e.IsCapsLockDown()))); wke.modifiers = WebInputEventFlagsFromViewsEvent(e); ForwardKeyboardEvent(wke); @@ -514,15 +539,7 @@ bool RenderWidgetHostViewViews::ContainsNativeView( WebKit::WebMouseEvent RenderWidgetHostViewViews::WebMouseEventFromViewsEvent( const views::MouseEvent& event) { WebKit::WebMouseEvent wmevent; - - wmevent.timeStampSeconds = base::Time::Now().ToDoubleT(); - wmevent.windowX = wmevent.x = event.x(); - wmevent.windowY = wmevent.y = event.y(); - int x, y; - gdk_window_get_origin(GetNativeView()->window, &x, &y); - wmevent.globalX = wmevent.x + x; - wmevent.globalY = wmevent.y + y; - wmevent.modifiers = WebInputEventFlagsFromViewsEvent(event); + InitializeWebMouseEventFromViewsEvent(event, GetPosition(), &wmevent); // Setting |wmevent.button| is not necessary for -move events, but it is // necessary for -clicks and -drags. diff --git a/views/event.h b/views/event.h index 89909b5..ab9abf3 100644 --- a/views/event.h +++ b/views/event.h @@ -381,6 +381,10 @@ class MouseWheelEvent : public LocatedEvent { offset_(offset) { } +#if defined(TOUCH_UI) + explicit MouseWheelEvent(XEvent* xev); +#endif + int GetOffset() const { return offset_; } diff --git a/views/event_x.cc b/views/event_x.cc index 7f6e7b1..60b0d2f 100644 --- a/views/event_x.cc +++ b/views/event_x.cc @@ -25,6 +25,8 @@ int GetEventFlagsFromXState(unsigned int state) { flags |= Event::EF_SHIFT_DOWN; if (state & Mod1Mask) flags |= Event::EF_ALT_DOWN; + if (state & LockMask) + flags |= Event::EF_CAPS_LOCK_DOWN; if (state & Button1Mask) flags |= Event::EF_LEFT_BUTTON_DOWN; if (state & Button2Mask) @@ -172,4 +174,12 @@ MouseEvent::MouseEvent(XEvent* xev) GetMouseEventFlags(xev)) { } +MouseWheelEvent::MouseWheelEvent(XEvent* xev) + : LocatedEvent(Event::ET_MOUSEWHEEL, + GetMouseEventLocation(xev), + GetEventFlagsFromXState(xev->xbutton.state)), + offset_(xev->xbutton.button == 4 ? 53 : -53) { // '53' is also the value + // used for GTK+. +} + } // namespace views diff --git a/views/focus/accelerator_handler_touch.cc b/views/focus/accelerator_handler_touch.cc index a07b977..aa971d5 100644 --- a/views/focus/accelerator_handler_touch.cc +++ b/views/focus/accelerator_handler_touch.cc @@ -132,13 +132,19 @@ bool DispatchXEvent(XEvent* xev) { case ButtonPress: case ButtonRelease: { - MouseEvent mouseev(xev); - if (xev->type == ButtonPress) { - return root->OnMousePressed(mouseev); + if (xev->xbutton.button == 4 || xev->xbutton.button == 5) { + // Scrolling the wheel triggers button press/release events. + MouseWheelEvent wheelev(xev); + return root->ProcessMouseWheelEvent(wheelev); } else { - root->OnMouseReleased(mouseev, false); - return true; // Assume the event has been processed to make sure we - // don't process it twice. + MouseEvent mouseev(xev); + if (xev->type == ButtonPress) { + return root->OnMousePressed(mouseev); + } else { + root->OnMouseReleased(mouseev, false); + return true; // Assume the event has been processed to make sure we + // don't process it twice. + } } } |