Merge revision 1267 changes:

- Mac: Improve scroll event handling for the cefclient OSR example (issue #982).

git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/1453@1268 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2013-05-31 16:23:15 +00:00
parent 10d1018986
commit ef6a886d9e
2 changed files with 35 additions and 0 deletions

View File

@@ -29,6 +29,9 @@ class OSRBrowserProvider {
bool rotating_; bool rotating_;
bool was_last_mouse_down_on_view_; bool was_last_mouse_down_on_view_;
// Event monitor for scroll wheel end event.
id endWheelMonitor_;
} }
- (id)initWithFrame:(NSRect)frame andTransparency:(bool)transparency; - (id)initWithFrame:(NSRect)frame andTransparency:(bool)transparency;

View File

@@ -271,6 +271,7 @@ void ClientOSRHandler::SetLoading(bool isLoading) {
if (self) { if (self) {
renderer_ = new ClientOSRenderer(transparency); renderer_ = new ClientOSRenderer(transparency);
rotating_ = false; rotating_ = false;
endWheelMonitor_ = nil;
tracking_area_ = tracking_area_ =
[[NSTrackingArea alloc] initWithRect:frame [[NSTrackingArea alloc] initWithRect:frame
@@ -467,7 +468,38 @@ void ClientOSRHandler::SetLoading(bool isLoading) {
[self keyDown:event]; [self keyDown:event];
} }
- (void) shortCircuitScrollWheelEvent:(NSEvent*)event {
if ([event phase] != NSEventPhaseEnded &&
[event phase] != NSEventPhaseCancelled)
return;
[self sendScrollWheelEvet:event];
if (endWheelMonitor_) {
[NSEvent removeMonitor:endWheelMonitor_];
endWheelMonitor_ = nil;
}
}
- (void)scrollWheel:(NSEvent *)event { - (void)scrollWheel:(NSEvent *)event {
// Use an NSEvent monitor to listen for the wheel-end end. This ensures that
// the event is received even when the mouse cursor is no longer over the
// view when the scrolling ends. Also it avoids sending duplicate scroll
// events to the renderer.
if ([event respondsToSelector:@selector(phase)] &&
[event phase] == NSEventPhaseBegan && !endWheelMonitor_) {
endWheelMonitor_ =
[NSEvent addLocalMonitorForEventsMatchingMask:NSScrollWheelMask
handler:^(NSEvent* blockEvent) {
[self shortCircuitScrollWheelEvent:blockEvent];
return blockEvent;
}];
}
[self sendScrollWheelEvet:event];
}
- (void)sendScrollWheelEvet:(NSEvent *)event {
CefRefPtr<CefBrowser> browser = [self getBrowser]; CefRefPtr<CefBrowser> browser = [self getBrowser];
if (!browser) if (!browser)
return; return;