Mac: Improve scroll event handling for the cefclient OSR example (issue #982).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1267 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
468eee6560
commit
300847a38a
|
@ -29,6 +29,9 @@ class OSRBrowserProvider {
|
|||
bool rotating_;
|
||||
|
||||
bool was_last_mouse_down_on_view_;
|
||||
|
||||
// Event monitor for scroll wheel end event.
|
||||
id endWheelMonitor_;
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(NSRect)frame andTransparency:(bool)transparency;
|
||||
|
|
|
@ -271,6 +271,7 @@ void ClientOSRHandler::SetLoading(bool isLoading) {
|
|||
if (self) {
|
||||
renderer_ = new ClientOSRenderer(transparency);
|
||||
rotating_ = false;
|
||||
endWheelMonitor_ = nil;
|
||||
|
||||
tracking_area_ =
|
||||
[[NSTrackingArea alloc] initWithRect:frame
|
||||
|
@ -467,7 +468,38 @@ void ClientOSRHandler::SetLoading(bool isLoading) {
|
|||
[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 {
|
||||
// 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];
|
||||
if (!browser)
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue