Impl OSXWindow::setMousePosition on Skia/OSX port

This commit is contained in:
David Capello 2015-10-14 09:29:14 -03:00
parent 2fe612fd00
commit 66c5e04a58
3 changed files with 27 additions and 0 deletions

View File

@ -10,6 +10,7 @@
#include <Cocoa/Cocoa.h>
#include "gfx/point.h"
#include "gfx/rect.h"
#include "gfx/size.h"
#include "she/keys.h"
@ -41,6 +42,7 @@ public:
- (void)setScale:(int)scale;
- (gfx::Size)clientSize;
- (gfx::Size)restoredSize;
- (void)setMousePosition:(const gfx::Point&)position;
@end
#endif

View File

@ -74,4 +74,23 @@
return [self clientSize];
}
- (void)setMousePosition:(const gfx::Point&)position
{
NSView* view = self.contentView;
NSPoint pt = NSMakePoint(
position.x*m_scale,
view.frame.size.height - position.y*m_scale);
pt = [view convertPoint:pt toView:view];
pt = [view convertPoint:pt toView:nil];
pt = [self convertBaseToScreen:pt];
pt.y = [[self screen] frame].size.height - pt.y;
CGPoint pos = CGPointMake(pt.x, pt.y);
CGEventRef event = CGEventCreateMouseEvent(
NULL, kCGEventMouseMoved, pos, kCGMouseButtonLeft);
CGEventPost(kCGHIDEventTap, event);
CFRelease(event);
}
@end

View File

@ -83,6 +83,10 @@ public:
[m_window setTitle:[NSString stringWithUTF8String:title.c_str()]];
}
void setMousePosition(const gfx::Point& position) {
[m_window setMousePosition:position];
}
void updateWindow(const gfx::Rect& bounds) {
[[m_window contentView] setNeedsDisplay:YES];
}
@ -338,6 +342,8 @@ void SkiaWindow::releaseMouse()
void SkiaWindow::setMousePosition(const gfx::Point& position)
{
if (m_impl)
m_impl->setMousePosition(position);
}
void SkiaWindow::setNativeMouseCursor(NativeCursor cursor)