Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(504)

Unified Diff: ui/events/cocoa/events_mac.mm

Issue 251493002: MacViews: Implement basic NSEvent -> ui::Event conversion for Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/events/cocoa/cocoa_event_utils_unittest.mm ('k') | ui/events/cocoa/events_mac_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/cocoa/events_mac.mm
diff --git a/ui/events/events_stub.cc b/ui/events/cocoa/events_mac.mm
similarity index 43%
copy from ui/events/events_stub.cc
copy to ui/events/cocoa/events_mac.mm
index bece37acbc94fdc815e97117f29f7f3a35adc685..a8d93650b3610e402a5b7915be43d3bdec0035a8 100644
--- a/ui/events/events_stub.cc
+++ b/ui/events/cocoa/events_mac.mm
@@ -1,43 +1,99 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// 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 "ui/events/event_utils.h"
+
+#include <Cocoa/Cocoa.h>
+
#include "base/logging.h"
#include "base/time/time.h"
#include "build/build_config.h"
+#include "ui/events/cocoa/cocoa_event_utils.h"
#include "ui/events/event_utils.h"
+#import "ui/events/keycodes/keyboard_code_conversion_mac.h"
#include "ui/gfx/point.h"
#include "ui/gfx/vector2d.h"
namespace ui {
-// Stub implementations of platform-specific methods in events_util.h, built
-// on platform sthat currently do not have a complete implementation of events.
-
void UpdateDeviceList() {
NOTIMPLEMENTED();
}
EventType EventTypeFromNative(const base::NativeEvent& native_event) {
- NOTIMPLEMENTED();
+ NSEventType type = [native_event type];
+ switch (type) {
+ case NSKeyDown:
+ return ET_KEY_PRESSED;
+ case NSKeyUp:
+ return ET_KEY_RELEASED;
+ case NSLeftMouseDown:
+ case NSRightMouseDown:
+ case NSOtherMouseDown:
+ return ET_MOUSE_PRESSED;
+ case NSLeftMouseUp:
+ case NSRightMouseUp:
+ case NSOtherMouseUp:
+ return ET_MOUSE_RELEASED;
+ case NSLeftMouseDragged:
+ case NSRightMouseDragged:
+ case NSOtherMouseDragged:
+ return ET_MOUSE_DRAGGED;
+ case NSMouseMoved:
+ case NSScrollWheel:
+ return ET_MOUSEWHEEL;
+ case NSMouseEntered:
+ return ET_MOUSE_ENTERED;
+ case NSMouseExited:
+ return ET_MOUSE_EXITED;
+ case NSEventTypeSwipe:
+ return ET_SCROLL_FLING_START;
+ case NSFlagsChanged:
+ case NSAppKitDefined:
+ case NSSystemDefined:
+ case NSApplicationDefined:
+ case NSPeriodic:
+ case NSCursorUpdate:
+ case NSTabletPoint:
+ case NSTabletProximity:
+ case NSEventTypeGesture:
+ case NSEventTypeMagnify:
+ case NSEventTypeRotate:
+ case NSEventTypeBeginGesture:
+ case NSEventTypeEndGesture:
+ NOTIMPLEMENTED() << type;
+ break;
+ default:
+ NOTIMPLEMENTED() << type;
+ break;
+ }
return ET_UNKNOWN;
}
-#if !defined(OS_MACOSX)
-int EventFlagsFromNative(const base::NativeEvent& native_event) {
- NOTIMPLEMENTED();
- return 0;
+int EventFlagsFromNative(const base::NativeEvent& event) {
+ NSUInteger modifiers = [event modifierFlags];
+ return EventFlagsFromNSEventWithModifiers(event, modifiers);
}
-#endif
base::TimeDelta EventTimeFromNative(const base::NativeEvent& native_event) {
- NOTIMPLEMENTED();
- return base::TimeDelta();
+ NSTimeInterval since_system_startup = [native_event timestamp];
+ // Truncate to extract seconds before doing floating point arithmetic.
+ int64_t seconds = since_system_startup;
+ since_system_startup -= seconds;
+ int64_t microseconds = since_system_startup * 1000000;
+ return base::TimeDelta::FromSeconds(seconds) +
+ base::TimeDelta::FromMicroseconds(microseconds);
}
gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) {
- NOTIMPLEMENTED();
- return gfx::Point();
+ if (![native_event window]) {
+ NOTIMPLEMENTED(); // Point will be in screen coordinates.
+ return gfx::Point();
+ }
+ NSPoint location = [native_event locationInWindow];
+ return gfx::Point(location.x,
+ NSHeight([[native_event window] frame]) - location.y);
}
gfx::Point EventSystemLocationFromNative(
@@ -53,13 +109,41 @@ int EventButtonFromNative(const base::NativeEvent& native_event) {
int GetChangedMouseButtonFlagsFromNative(
const base::NativeEvent& native_event) {
- NOTIMPLEMENTED();
+ NSEventType type = [native_event type];
+ switch (type) {
+ case NSLeftMouseDown:
+ case NSLeftMouseUp:
+ case NSLeftMouseDragged:
+ return EF_LEFT_MOUSE_BUTTON;
+ case NSRightMouseDown:
+ case NSRightMouseUp:
+ case NSRightMouseDragged:
+ return EF_RIGHT_MOUSE_BUTTON;
+ case NSOtherMouseDown:
+ case NSOtherMouseUp:
+ case NSOtherMouseDragged:
+ return EF_MIDDLE_MOUSE_BUTTON;
+ }
return 0;
}
-gfx::Vector2d GetMouseWheelOffset(const base::NativeEvent& native_event) {
- NOTIMPLEMENTED();
- return gfx::Vector2d();
+gfx::Vector2d GetMouseWheelOffset(const base::NativeEvent& event) {
+ // Empirically, a value of 0.1 is typical for one mousewheel click. Positive
+ // values when scrolling up or to the left. Scrolling quickly results in a
+ // higher delta per click, up to about 15.0. (Quartz documentation suggests
+ // +/-10).
+ // Multiply by 1000 to vaguely approximate WHEEL_DELTA on Windows (120).
+ const CGFloat kWheelDeltaMultiplier = 1000;
+ return gfx::Vector2d(kWheelDeltaMultiplier * [event deltaX],
+ kWheelDeltaMultiplier * [event deltaY]);
+}
+
+base::NativeEvent CopyNativeEvent(const base::NativeEvent& event) {
+ return [event copy];
+}
+
+void ReleaseCopiedNativeEvent(const base::NativeEvent& event) {
+ [event release];
}
void ClearTouchIdIfReleased(const base::NativeEvent& native_event) {
@@ -133,13 +217,11 @@ bool IsTouchpadEvent(const base::NativeEvent& native_event) {
}
KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) {
- NOTIMPLEMENTED();
- return static_cast<KeyboardCode>(0);
+ return KeyboardCodeFromNSEvent(native_event);
}
const char* CodeFromNative(const base::NativeEvent& native_event) {
- NOTIMPLEMENTED();
- return "";
+ return CodeFromNSEvent(native_event);
}
} // namespace ui
« no previous file with comments | « ui/events/cocoa/cocoa_event_utils_unittest.mm ('k') | ui/events/cocoa/events_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698