| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
| 6 | 6 |
| 7 #import <objc/runtime.h> | 7 #import <objc/runtime.h> |
| 8 #include <OpenGL/gl.h> | 8 #include <OpenGL/gl.h> |
| 9 #include <QuartzCore/QuartzCore.h> | 9 #include <QuartzCore/QuartzCore.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| 11 | 11 |
| 12 #include <limits> | 12 #include <limits> |
| 13 #include <utility> | 13 #include <utility> |
| 14 | 14 |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/callback_helpers.h" | 16 #include "base/callback_helpers.h" |
| 17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/debug/crash_logging.h" | 18 #include "base/debug/crash_logging.h" |
| 19 #include "base/logging.h" | 19 #include "base/logging.h" |
| 20 #include "base/mac/mac_util.h" | |
| 21 #include "base/mac/scoped_cftyperef.h" | 20 #include "base/mac/scoped_cftyperef.h" |
| 22 #import "base/mac/scoped_nsobject.h" | 21 #import "base/mac/scoped_nsobject.h" |
| 23 #include "base/mac/sdk_forward_declarations.h" | 22 #include "base/mac/sdk_forward_declarations.h" |
| 24 #include "base/memory/ref_counted.h" | 23 #include "base/memory/ref_counted.h" |
| 25 #include "base/message_loop/message_loop.h" | 24 #include "base/message_loop/message_loop.h" |
| 26 #include "base/metrics/histogram.h" | 25 #include "base/metrics/histogram.h" |
| 27 #include "base/numerics/safe_conversions.h" | 26 #include "base/numerics/safe_conversions.h" |
| 28 #include "base/strings/string_util.h" | 27 #include "base/strings/string_util.h" |
| 29 #include "base/strings/stringprintf.h" | 28 #include "base/strings/stringprintf.h" |
| 30 #include "base/strings/sys_string_conversions.h" | 29 #include "base/strings/sys_string_conversions.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 138 |
| 140 } // namespace | 139 } // namespace |
| 141 | 140 |
| 142 // These are not documented, so use only after checking -respondsToSelector:. | 141 // These are not documented, so use only after checking -respondsToSelector:. |
| 143 @interface NSApplication (UndocumentedSpeechMethods) | 142 @interface NSApplication (UndocumentedSpeechMethods) |
| 144 - (void)speakString:(NSString*)string; | 143 - (void)speakString:(NSString*)string; |
| 145 - (void)stopSpeaking:(id)sender; | 144 - (void)stopSpeaking:(id)sender; |
| 146 - (BOOL)isSpeaking; | 145 - (BOOL)isSpeaking; |
| 147 @end | 146 @end |
| 148 | 147 |
| 149 // This method will return YES for OS X versions 10.7.3 and later, and NO | |
| 150 // otherwise. | |
| 151 // Used to prevent a crash when building with the 10.7 SDK and accessing the | |
| 152 // notification below. See: http://crbug.com/260595. | |
| 153 static BOOL SupportsBackingPropertiesChangedNotification() { | |
| 154 // windowDidChangeBackingProperties: method has been added to the | |
| 155 // NSWindowDelegate protocol in 10.7.3, at the same time as the | |
| 156 // NSWindowDidChangeBackingPropertiesNotification notification was added. | |
| 157 // If the protocol contains this method description, the notification should | |
| 158 // be supported as well. | |
| 159 Protocol* windowDelegateProtocol = NSProtocolFromString(@"NSWindowDelegate"); | |
| 160 struct objc_method_description methodDescription = | |
| 161 protocol_getMethodDescription( | |
| 162 windowDelegateProtocol, | |
| 163 @selector(windowDidChangeBackingProperties:), | |
| 164 NO, | |
| 165 YES); | |
| 166 | |
| 167 // If the protocol does not contain the method, the returned method | |
| 168 // description is {NULL, NULL} | |
| 169 return methodDescription.name != NULL || methodDescription.types != NULL; | |
| 170 } | |
| 171 | |
| 172 // Private methods: | 148 // Private methods: |
| 173 @interface RenderWidgetHostViewCocoa () | 149 @interface RenderWidgetHostViewCocoa () |
| 174 @property(nonatomic, assign) NSRange selectedRange; | 150 @property(nonatomic, assign) NSRange selectedRange; |
| 175 @property(nonatomic, assign) NSRange markedRange; | 151 @property(nonatomic, assign) NSRange markedRange; |
| 176 | 152 |
| 177 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; | 153 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; |
| 178 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; | 154 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; |
| 179 - (void)processedWheelEvent:(const blink::WebMouseWheelEvent&)event | 155 - (void)processedWheelEvent:(const blink::WebMouseWheelEvent&)event |
| 180 consumed:(BOOL)consumed; | 156 consumed:(BOOL)consumed; |
| 181 - (void)processedGestureScrollEvent:(const blink::WebGestureEvent&)event | 157 - (void)processedGestureScrollEvent:(const blink::WebGestureEvent&)event |
| (...skipping 2162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2344 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent]) | 2320 if ([RenderWidgetHostViewCocoa shouldAutohideCursorForEvent:theEvent]) |
| 2345 [NSCursor setHiddenUntilMouseMoves:YES]; | 2321 [NSCursor setHiddenUntilMouseMoves:YES]; |
| 2346 } | 2322 } |
| 2347 | 2323 |
| 2348 - (void)forceTouchEvent:(NSEvent*)theEvent { | 2324 - (void)forceTouchEvent:(NSEvent*)theEvent { |
| 2349 if (ui::ForceClickInvokesQuickLook()) | 2325 if (ui::ForceClickInvokesQuickLook()) |
| 2350 [self quickLookWithEvent:theEvent]; | 2326 [self quickLookWithEvent:theEvent]; |
| 2351 } | 2327 } |
| 2352 | 2328 |
| 2353 - (void)shortCircuitScrollWheelEvent:(NSEvent*)event { | 2329 - (void)shortCircuitScrollWheelEvent:(NSEvent*)event { |
| 2354 DCHECK(base::mac::IsOSLionOrLater()); | |
| 2355 | |
| 2356 if ([event phase] != NSEventPhaseEnded && | 2330 if ([event phase] != NSEventPhaseEnded && |
| 2357 [event phase] != NSEventPhaseCancelled) { | 2331 [event phase] != NSEventPhaseCancelled) { |
| 2358 return; | 2332 return; |
| 2359 } | 2333 } |
| 2360 | 2334 |
| 2361 if (renderWidgetHostView_->render_widget_host_) { | 2335 if (renderWidgetHostView_->render_widget_host_) { |
| 2362 // History-swiping is not possible if the logic reaches this point. | 2336 // History-swiping is not possible if the logic reaches this point. |
| 2363 // Allow rubber-banding in both directions. | 2337 // Allow rubber-banding in both directions. |
| 2364 bool canRubberbandLeft = true; | 2338 bool canRubberbandLeft = true; |
| 2365 bool canRubberbandRight = true; | 2339 bool canRubberbandRight = true; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2511 [responderDelegate_ respondsToSelector:@selector(handleEvent:)]) { | 2485 [responderDelegate_ respondsToSelector:@selector(handleEvent:)]) { |
| 2512 BOOL handled = [responderDelegate_ handleEvent:event]; | 2486 BOOL handled = [responderDelegate_ handleEvent:event]; |
| 2513 if (handled) | 2487 if (handled) |
| 2514 return; | 2488 return; |
| 2515 } | 2489 } |
| 2516 | 2490 |
| 2517 // Use an NSEvent monitor to listen for the wheel-end end. This ensures that | 2491 // Use an NSEvent monitor to listen for the wheel-end end. This ensures that |
| 2518 // the event is received even when the mouse cursor is no longer over the view | 2492 // the event is received even when the mouse cursor is no longer over the view |
| 2519 // when the scrolling ends (e.g. if the tab was switched). This is necessary | 2493 // when the scrolling ends (e.g. if the tab was switched). This is necessary |
| 2520 // for ending rubber-banding in such cases. | 2494 // for ending rubber-banding in such cases. |
| 2521 if (base::mac::IsOSLionOrLater() && [event phase] == NSEventPhaseBegan && | 2495 if ([event phase] == NSEventPhaseBegan && !endWheelMonitor_) { |
| 2522 !endWheelMonitor_) { | |
| 2523 endWheelMonitor_ = | 2496 endWheelMonitor_ = |
| 2524 [NSEvent addLocalMonitorForEventsMatchingMask:NSScrollWheelMask | 2497 [NSEvent addLocalMonitorForEventsMatchingMask:NSScrollWheelMask |
| 2525 handler:^(NSEvent* blockEvent) { | 2498 handler:^(NSEvent* blockEvent) { |
| 2526 [self shortCircuitScrollWheelEvent:blockEvent]; | 2499 [self shortCircuitScrollWheelEvent:blockEvent]; |
| 2527 return blockEvent; | 2500 return blockEvent; |
| 2528 }]; | 2501 }]; |
| 2529 } | 2502 } |
| 2530 | 2503 |
| 2531 // This is responsible for content scrolling! | 2504 // This is responsible for content scrolling! |
| 2532 if (renderWidgetHostView_->render_widget_host_) { | 2505 if (renderWidgetHostView_->render_widget_host_) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2575 updateEvent.data.pinchUpdate.zoomDisabled = !pinchHasReachedZoomThreshold_; | 2548 updateEvent.data.pinchUpdate.zoomDisabled = !pinchHasReachedZoomThreshold_; |
| 2576 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(updateEvent); | 2549 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(updateEvent); |
| 2577 } | 2550 } |
| 2578 | 2551 |
| 2579 - (void)viewWillMoveToWindow:(NSWindow*)newWindow { | 2552 - (void)viewWillMoveToWindow:(NSWindow*)newWindow { |
| 2580 NSWindow* oldWindow = [self window]; | 2553 NSWindow* oldWindow = [self window]; |
| 2581 | 2554 |
| 2582 NSNotificationCenter* notificationCenter = | 2555 NSNotificationCenter* notificationCenter = |
| 2583 [NSNotificationCenter defaultCenter]; | 2556 [NSNotificationCenter defaultCenter]; |
| 2584 | 2557 |
| 2585 // Backing property notifications crash on 10.6 when building with the 10.7 | |
| 2586 // SDK, see http://crbug.com/260595. | |
| 2587 static BOOL supportsBackingPropertiesNotification = | |
| 2588 SupportsBackingPropertiesChangedNotification(); | |
| 2589 | |
| 2590 if (oldWindow) { | 2558 if (oldWindow) { |
| 2591 if (supportsBackingPropertiesNotification) { | 2559 [notificationCenter |
| 2592 [notificationCenter | 2560 removeObserver:self |
| 2593 removeObserver:self | 2561 name:NSWindowDidChangeBackingPropertiesNotification |
| 2594 name:NSWindowDidChangeBackingPropertiesNotification | 2562 object:oldWindow]; |
| 2595 object:oldWindow]; | |
| 2596 } | |
| 2597 [notificationCenter | 2563 [notificationCenter |
| 2598 removeObserver:self | 2564 removeObserver:self |
| 2599 name:NSWindowDidMoveNotification | 2565 name:NSWindowDidMoveNotification |
| 2600 object:oldWindow]; | 2566 object:oldWindow]; |
| 2601 [notificationCenter | 2567 [notificationCenter |
| 2602 removeObserver:self | 2568 removeObserver:self |
| 2603 name:NSWindowDidEndLiveResizeNotification | 2569 name:NSWindowDidEndLiveResizeNotification |
| 2604 object:oldWindow]; | 2570 object:oldWindow]; |
| 2605 [notificationCenter | 2571 [notificationCenter |
| 2606 removeObserver:self | 2572 removeObserver:self |
| 2607 name:NSWindowDidBecomeKeyNotification | 2573 name:NSWindowDidBecomeKeyNotification |
| 2608 object:oldWindow]; | 2574 object:oldWindow]; |
| 2609 [notificationCenter | 2575 [notificationCenter |
| 2610 removeObserver:self | 2576 removeObserver:self |
| 2611 name:NSWindowDidResignKeyNotification | 2577 name:NSWindowDidResignKeyNotification |
| 2612 object:oldWindow]; | 2578 object:oldWindow]; |
| 2613 } | 2579 } |
| 2614 if (newWindow) { | 2580 if (newWindow) { |
| 2615 if (supportsBackingPropertiesNotification) { | 2581 [notificationCenter |
| 2616 [notificationCenter | 2582 addObserver:self |
| 2617 addObserver:self | 2583 selector:@selector(windowDidChangeBackingProperties:) |
| 2618 selector:@selector(windowDidChangeBackingProperties:) | 2584 name:NSWindowDidChangeBackingPropertiesNotification |
| 2619 name:NSWindowDidChangeBackingPropertiesNotification | 2585 object:newWindow]; |
| 2620 object:newWindow]; | |
| 2621 } | |
| 2622 [notificationCenter | 2586 [notificationCenter |
| 2623 addObserver:self | 2587 addObserver:self |
| 2624 selector:@selector(windowChangedGlobalFrame:) | 2588 selector:@selector(windowChangedGlobalFrame:) |
| 2625 name:NSWindowDidMoveNotification | 2589 name:NSWindowDidMoveNotification |
| 2626 object:newWindow]; | 2590 object:newWindow]; |
| 2627 [notificationCenter | 2591 [notificationCenter |
| 2628 addObserver:self | 2592 addObserver:self |
| 2629 selector:@selector(windowChangedGlobalFrame:) | 2593 selector:@selector(windowChangedGlobalFrame:) |
| 2630 name:NSWindowDidEndLiveResizeNotification | 2594 name:NSWindowDidEndLiveResizeNotification |
| 2631 object:newWindow]; | 2595 object:newWindow]; |
| (...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3439 | 3403 |
| 3440 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3404 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3441 // regions that are not draggable. (See ControlRegionView in | 3405 // regions that are not draggable. (See ControlRegionView in |
| 3442 // native_app_window_cocoa.mm). This requires the render host view to be | 3406 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3443 // draggable by default. | 3407 // draggable by default. |
| 3444 - (BOOL)mouseDownCanMoveWindow { | 3408 - (BOOL)mouseDownCanMoveWindow { |
| 3445 return YES; | 3409 return YES; |
| 3446 } | 3410 } |
| 3447 | 3411 |
| 3448 @end | 3412 @end |
| OLD | NEW |