Skip to content

Commit

Permalink
Better mouse support for metro aura
Browse files Browse the repository at this point in the history
-Wheel, r-click and l-click now discriminated
-More efficient, clean mouse event handling

Note; wheel event not properly handled. That is a bigger CL
that will come later.

BUG=151718
TEST= right click and left click
Review URL: https://codereview.chromium.org/11312025

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166034 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
cpu@chromium.org committed Nov 5, 2012
1 parent e99cd4d commit 884cef8
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 65 deletions.
6 changes: 4 additions & 2 deletions chrome/browser/metro_viewer/metro_viewer_process_host_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ void MetroViewerProcessHost::OnMouseMoved(int32 x, int32 y, int32 modifiers) {
aura::RemoteRootWindowHostWin::Instance()->OnMouseMoved(x, y, modifiers);
}

void MetroViewerProcessHost::OnMouseButton(int32 x, int32 y, int32 modifiers) {
aura::RemoteRootWindowHostWin::Instance()->OnMouseClick(x, y, modifiers);
void MetroViewerProcessHost::OnMouseButton(
int32 x, int32 y, int32 extra, ui::EventType type, ui::EventFlags flags) {
aura::RemoteRootWindowHostWin::Instance()->OnMouseButton(
x, y, extra, type, flags);
}

void MetroViewerProcessHost::OnKeyDown(uint32 vkey,
Expand Down
4 changes: 3 additions & 1 deletion chrome/browser/metro_viewer/metro_viewer_process_host_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/threading/non_thread_safe.h"
#include "ipc/ipc_listener.h"
#include "ipc/ipc_sender.h"
#include "ui/base/events/event_constants.h"
#include "ui/gfx/native_widget_types.h"

namespace IPC {
Expand All @@ -34,7 +35,8 @@ class MetroViewerProcessHost : public IPC::Listener,
void OnSetTargetSurface(gfx::NativeViewId target_surface);
void OnMouseEvent(int32 msg, WPARAM w_param, LPARAM l_param);
void OnMouseMoved(int32 x, int32 y, int32 modifiers);
void OnMouseButton(int32 x, int32 y, int32 modifiers);
void OnMouseButton(
int32 x, int32 y, int32 extra,ui::EventType type, ui::EventFlags flags);
void OnKeyDown(uint32 vkey,
uint32 repeat_count,
uint32 scan_code,
Expand Down
26 changes: 21 additions & 5 deletions content/browser/renderer_host/web_input_event_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ WebKit::WebKeyboardEvent MakeWebKeyboardEventFromNativeEvent(
WebKit::WebGestureEvent MakeWebGestureEventFromNativeEvent(
base::NativeEvent native_event);
#else
WebKit::WebMouseWheelEvent MakeWebMouseWheelEventFromAuraEvent(
ui::MouseWheelEvent* event);
WebKit::WebMouseWheelEvent MakeWebMouseWheelEventFromAuraEvent(
ui::ScrollEvent* event);
WebKit::WebKeyboardEvent MakeWebKeyboardEventFromAuraEvent(
Expand All @@ -31,7 +29,10 @@ WebKit::WebGestureEvent MakeWebGestureEventFromAuraEvent(
ui::ScrollEvent* event);
#endif

WebKit::WebMouseEvent MakeWebMouseEventFromAuraEvent(ui::MouseEvent* event);
WebKit::WebMouseEvent MakeWebMouseEventFromAuraEvent(
ui::MouseEvent* event);
WebKit::WebMouseWheelEvent MakeWebMouseWheelEventFromAuraEvent(
ui::MouseWheelEvent* event);

// General approach:
//
Expand Down Expand Up @@ -83,8 +84,9 @@ WebKit::WebMouseEvent MakeWebMouseEvent(ui::MouseEvent* event) {
WebKit::WebMouseWheelEvent MakeWebMouseWheelEvent(ui::MouseWheelEvent* event) {
#if defined(OS_WIN)
// Construct an untranslated event from the platform event data.
WebKit::WebMouseWheelEvent webkit_event =
MakeUntranslatedWebMouseWheelEventFromNativeEvent(event->native_event());
WebKit::WebMouseWheelEvent webkit_event = event->native_event().message ?
MakeUntranslatedWebMouseWheelEventFromNativeEvent(event->native_event()) :
MakeWebMouseWheelEventFromAuraEvent(event);
#else
WebKit::WebMouseWheelEvent webkit_event =
MakeWebMouseWheelEventFromAuraEvent(event);
Expand Down Expand Up @@ -220,4 +222,18 @@ WebKit::WebMouseEvent MakeWebMouseEventFromAuraEvent(ui::MouseEvent* event) {
return webkit_event;
}

WebKit::WebMouseWheelEvent MakeWebMouseWheelEventFromAuraEvent(
ui::MouseWheelEvent* event) {
WebKit::WebMouseWheelEvent webkit_event;

webkit_event.type = WebKit::WebInputEvent::MouseWheel;
webkit_event.button = WebKit::WebMouseEvent::ButtonNone;
webkit_event.modifiers = EventFlagsToWebEventModifiers(event->flags());
webkit_event.timeStampSeconds = event->time_stamp().InSecondsF();
webkit_event.deltaY = event->offset();
webkit_event.wheelTicksY = webkit_event.deltaY / kPixelsPerTick;

return webkit_event;
}

} // namespace content
3 changes: 3 additions & 0 deletions content/browser/renderer_host/web_input_event_aura.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class TouchEvent;

namespace content {

// Used for scrolling. This matches Firefox behavior.
const int kPixelsPerTick = 53;

CONTENT_EXPORT WebKit::WebMouseEvent MakeWebMouseEvent(
ui::MouseEvent* event);
CONTENT_EXPORT WebKit::WebMouseWheelEvent MakeWebMouseWheelEvent(
Expand Down
17 changes: 0 additions & 17 deletions content/browser/renderer_host/web_input_event_aurax11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ namespace content {

namespace {

// This matches Firefox behavior.
const int kPixelsPerTick = 53;

int XKeyEventToWindowsKeyCode(XKeyEvent* event) {
int windows_key_code =
ui::KeyboardCodeFromXKeyEvent(reinterpret_cast<XEvent*>(event));
Expand Down Expand Up @@ -138,20 +135,6 @@ WebKit::WebUChar GetControlCharacter(int windows_key_code, bool shift) {

} // namespace

WebKit::WebMouseWheelEvent MakeWebMouseWheelEventFromAuraEvent(
ui::MouseWheelEvent* event) {
WebKit::WebMouseWheelEvent webkit_event;

webkit_event.type = WebKit::WebInputEvent::MouseWheel;
webkit_event.button = WebKit::WebMouseEvent::ButtonNone;
webkit_event.modifiers = EventFlagsToWebEventModifiers(event->flags());
webkit_event.timeStampSeconds = event->time_stamp().InSecondsF();
webkit_event.deltaY = event->offset();
webkit_event.wheelTicksY = webkit_event.deltaY / kPixelsPerTick;

return webkit_event;
}

WebKit::WebMouseWheelEvent MakeWebMouseWheelEventFromAuraEvent(
ui::ScrollEvent* event) {
WebKit::WebMouseWheelEvent webkit_event;
Expand Down
23 changes: 15 additions & 8 deletions ui/aura/remote_root_window_host_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include "ui/base/keycodes/keyboard_code_conversion_win.h"
#include "ui/base/view_prop.h"

// From metro_viewer_messages.h we only care for the enums.
#include "ui/metro_viewer/metro_viewer_messages.h"

using std::max;
using std::min;

Expand Down Expand Up @@ -141,7 +144,6 @@ void RemoteRootWindowHostWin::OnDeviceScaleFactorChanged(
}

void RemoteRootWindowHostWin::PrepareForShutdown() {
NOTIMPLEMENTED();
}

void RemoteRootWindowHostWin::OnMouseMoved(int32 x, int32 y, int32 extra) {
Expand All @@ -150,14 +152,19 @@ void RemoteRootWindowHostWin::OnMouseMoved(int32 x, int32 y, int32 extra) {
delegate_->OnHostMouseEvent(&event);
}

void RemoteRootWindowHostWin::OnMouseClick(int32 x, int32 y, int32 extra) {
void RemoteRootWindowHostWin::OnMouseButton(
int32 x, int32 y, int32 extra, ui::EventType type, ui::EventFlags flags) {
gfx::Point location(x, y);
ui::EventType type = (extra == 1) ?
ui::ET_MOUSE_PRESSED : ui::ET_MOUSE_RELEASED;
ui::MouseEvent event(type, location, location, 0);
event.SetClickCount(1);
event.set_flags(ui::EF_LEFT_MOUSE_BUTTON);
delegate_->OnHostMouseEvent(&event);
ui::MouseEvent mouse_event(type, location, location, 0);
mouse_event.set_flags(flags);

if (type == ui::ET_MOUSEWHEEL) {
ui::MouseWheelEvent wheel_event(mouse_event, extra);
delegate_->OnHostMouseEvent(&wheel_event);
} else {
mouse_event.SetClickCount(1);
delegate_->OnHostMouseEvent(&mouse_event);
}
}

void RemoteRootWindowHostWin::OnKeyDown(uint32 vkey,
Expand Down
4 changes: 3 additions & 1 deletion ui/aura/remote_root_window_host_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "base/compiler_specific.h"
#include "ui/aura/root_window_host.h"
#include "ui/base/events/event_constants.h"
#include "ui/base/win/window_impl.h"

namespace ui {
Expand All @@ -23,7 +24,8 @@ class AURA_EXPORT RemoteRootWindowHostWin : public RootWindowHost {
static RemoteRootWindowHostWin* Create(const gfx::Rect& bounds);

void OnMouseMoved(int32 x, int32 y, int32 extra);
void OnMouseClick(int32 x, int32 y, int32 extra);
void OnMouseButton(
int32 x, int32 y, int32 extra, ui::EventType type, ui::EventFlags flags);
void OnKeyDown(uint32 vkey,
uint32 repeat_count,
uint32 scan_code,
Expand Down
5 changes: 5 additions & 0 deletions ui/base/events/event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ MouseWheelEvent::MouseWheelEvent(const ScrollEvent& scroll_event)
set_type(ET_MOUSEWHEEL);
}

MouseWheelEvent::MouseWheelEvent(const MouseEvent& mouse_event, int offset)
: MouseEvent(mouse_event), offset_(offset) {
DCHECK(type() == ET_MOUSEWHEEL);
}

#if defined(OS_WIN)
// This value matches windows WHEEL_DELTA.
// static
Expand Down
1 change: 1 addition & 0 deletions ui/base/events/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ class UI_EXPORT MouseWheelEvent : public MouseEvent {

explicit MouseWheelEvent(const base::NativeEvent& native_event);
explicit MouseWheelEvent(const ScrollEvent& scroll_event);
MouseWheelEvent(const MouseEvent& mouse_event, int offset);

template <class T>
MouseWheelEvent(const MouseWheelEvent& model,
Expand Down
14 changes: 10 additions & 4 deletions ui/metro_viewer/metro_viewer_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

#include "base/basictypes.h"
#include "ipc/ipc_message_macros.h"
#include "ui/base/events/event_constants.h"
#include "ui/gfx/native_widget_types.h"

#define IPC_MESSAGE_START MetroViewerMsgStart

IPC_ENUM_TRAITS(ui::EventType)
IPC_ENUM_TRAITS(ui::EventFlags)

// Messages sent from the viewer to the browser.

// Inform the browser of the surface to target for compositing.
Expand All @@ -21,10 +25,12 @@ IPC_MESSAGE_CONTROL3(MetroViewerHostMsg_MouseMoved,
int32, /* y-coordinate */
int32 /* modifiers */)
// Inforoms the brower that a mouse button was pressed.
IPC_MESSAGE_CONTROL3(MetroViewerHostMsg_MouseButton,
int32, /* x-coordinate */
int32, /* y-coordinate */
int32 /* modifiers */)
IPC_MESSAGE_CONTROL5(MetroViewerHostMsg_MouseButton,
int32, /* x-coordinate */
int32, /* y-coordinate */
int32, /* extra */
ui::EventType, /* event type */
ui::EventFlags /* event flags */)
// Informs the browser that a key was pressed.
IPC_MESSAGE_CONTROL4(MetroViewerHostMsg_KeyDown,
uint32, /* virtual key */
Expand Down
Loading

0 comments on commit 884cef8

Please sign in to comment.