| 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 <Carbon/Carbon.h> | 7 #import <Carbon/Carbon.h> |
| 8 #import <objc/runtime.h> | 8 #import <objc/runtime.h> |
| 9 #include <OpenGL/gl.h> | 9 #include <OpenGL/gl.h> |
| 10 #include <QuartzCore/QuartzCore.h> | 10 #include <QuartzCore/QuartzCore.h> |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 @interface RenderWidgetHostViewCocoa () | 143 @interface RenderWidgetHostViewCocoa () |
| 144 @property(nonatomic, assign) NSRange selectedRange; | 144 @property(nonatomic, assign) NSRange selectedRange; |
| 145 @property(nonatomic, assign) NSRange markedRange; | 145 @property(nonatomic, assign) NSRange markedRange; |
| 146 | 146 |
| 147 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; | 147 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; |
| 148 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; | 148 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; |
| 149 - (void)processedWheelEvent:(const blink::WebMouseWheelEvent&)event | 149 - (void)processedWheelEvent:(const blink::WebMouseWheelEvent&)event |
| 150 consumed:(BOOL)consumed; | 150 consumed:(BOOL)consumed; |
| 151 - (void)processedGestureScrollEvent:(const blink::WebGestureEvent&)event | 151 - (void)processedGestureScrollEvent:(const blink::WebGestureEvent&)event |
| 152 consumed:(BOOL)consumed; | 152 consumed:(BOOL)consumed; |
| 153 | 153 - (void)handleBeginGestureWithEvent:(NSEvent*)event; |
| 154 - (void)handleEndGestureWithEvent:(NSEvent*)event; |
| 154 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; | 155 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; |
| 155 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; | 156 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; |
| 156 - (void)windowChangedGlobalFrame:(NSNotification*)notification; | 157 - (void)windowChangedGlobalFrame:(NSNotification*)notification; |
| 157 - (void)windowDidBecomeKey:(NSNotification*)notification; | 158 - (void)windowDidBecomeKey:(NSNotification*)notification; |
| 158 - (void)windowDidResignKey:(NSNotification*)notification; | 159 - (void)windowDidResignKey:(NSNotification*)notification; |
| 159 - (void)updateScreenProperties; | 160 - (void)updateScreenProperties; |
| 160 - (void)setResponderDelegate: | 161 - (void)setResponderDelegate: |
| 161 (NSObject<RenderWidgetHostViewMacDelegate>*)delegate; | 162 (NSObject<RenderWidgetHostViewMacDelegate>*)delegate; |
| 162 - (void)showLookUpDictionaryOverlayInternal:(NSAttributedString*) string | 163 - (void)showLookUpDictionaryOverlayInternal:(NSAttributedString*) string |
| 163 baselinePoint:(NSPoint) baselinePoint | 164 baselinePoint:(NSPoint) baselinePoint |
| (...skipping 2107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2271 renderWidgetHostView_->render_widget_host_-> | 2272 renderWidgetHostView_->render_widget_host_-> |
| 2272 ForwardWheelEventWithLatencyInfo(webEvent, latency_info); | 2273 ForwardWheelEventWithLatencyInfo(webEvent, latency_info); |
| 2273 } | 2274 } |
| 2274 | 2275 |
| 2275 if (endWheelMonitor_) { | 2276 if (endWheelMonitor_) { |
| 2276 [NSEvent removeMonitor:endWheelMonitor_]; | 2277 [NSEvent removeMonitor:endWheelMonitor_]; |
| 2277 endWheelMonitor_ = nil; | 2278 endWheelMonitor_ = nil; |
| 2278 } | 2279 } |
| 2279 } | 2280 } |
| 2280 | 2281 |
| 2281 - (void)beginGestureWithEvent:(NSEvent*)event { | 2282 // Internal implementation for handling begin gesture events. This helper |
| 2283 // method is called via different codepaths based on OS version and SDK: |
| 2284 // - On 10.11 and later, when linking with the 10.11 SDK, it is called from |
| 2285 // |magnifyWithEvent:| when the given event's phase is NSEventPhaseBegin. |
| 2286 // - On 10.10 and earlier, or when linking with an earlier SDK, it is called |
| 2287 // by |beginGestureWithEvent:| when a gesture begins. |
| 2288 - (void)handleBeginGestureWithEvent:(NSEvent*)event { |
| 2282 [responderDelegate_ beginGestureWithEvent:event]; | 2289 [responderDelegate_ beginGestureWithEvent:event]; |
| 2283 gestureBeginEvent_.reset( | 2290 gestureBeginEvent_.reset( |
| 2284 new WebGestureEvent(WebGestureEventBuilder::Build(event, self))); | 2291 new WebGestureEvent(WebGestureEventBuilder::Build(event, self))); |
| 2285 | 2292 |
| 2286 // If the page is at the minimum zoom level, require a threshold be reached | 2293 // If the page is at the minimum zoom level, require a threshold be reached |
| 2287 // before the pinch has an effect. | 2294 // before the pinch has an effect. |
| 2288 if (renderWidgetHostView_->page_at_minimum_scale_) { | 2295 if (renderWidgetHostView_->page_at_minimum_scale_) { |
| 2289 pinchHasReachedZoomThreshold_ = false; | 2296 pinchHasReachedZoomThreshold_ = false; |
| 2290 pinchUnusedAmount_ = 1; | 2297 pinchUnusedAmount_ = 1; |
| 2291 } | 2298 } |
| 2292 } | 2299 } |
| 2293 | 2300 |
| 2294 - (void)endGestureWithEvent:(NSEvent*)event { | 2301 // Internal implementation for handling end gesture events. This helper |
| 2302 // method is called via different codepaths based on OS version and SDK: |
| 2303 // - On 10.11 and later, when linking with the 10.11 SDK, it is called from |
| 2304 // |magnifyWithEvent:| when the given event's phase is NSEventPhaseEnded. |
| 2305 // - On 10.10 and earlier, or when linking with an earlier SDK, it is called |
| 2306 // by |endGestureWithEvent:| when a gesture ends. |
| 2307 - (void)handleEndGestureWithEvent:(NSEvent*)event { |
| 2295 [responderDelegate_ endGestureWithEvent:event]; | 2308 [responderDelegate_ endGestureWithEvent:event]; |
| 2296 gestureBeginEvent_.reset(); | 2309 gestureBeginEvent_.reset(); |
| 2297 | 2310 |
| 2298 if (!renderWidgetHostView_->render_widget_host_) | 2311 if (!renderWidgetHostView_->render_widget_host_) |
| 2299 return; | 2312 return; |
| 2300 | 2313 |
| 2301 if (gestureBeginPinchSent_) { | 2314 if (gestureBeginPinchSent_) { |
| 2302 WebGestureEvent endEvent(WebGestureEventBuilder::Build(event, self)); | 2315 WebGestureEvent endEvent(WebGestureEventBuilder::Build(event, self)); |
| 2303 endEvent.setType(WebInputEvent::GesturePinchEnd); | 2316 endEvent.setType(WebInputEvent::GesturePinchEnd); |
| 2304 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(endEvent); | 2317 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(endEvent); |
| 2305 gestureBeginPinchSent_ = NO; | 2318 gestureBeginPinchSent_ = NO; |
| 2306 } | 2319 } |
| 2307 } | 2320 } |
| 2308 | 2321 |
| 2322 - (void)beginGestureWithEvent:(NSEvent*)event { |
| 2323 // This method must be handled when linking with the 10.10 SDK or earlier, or |
| 2324 // when the app is running on 10.10 or earlier. In other circumstances, the |
| 2325 // event will be handled by |magnifyWithEvent:|, so this method should do |
| 2326 // nothing. |
| 2327 bool shouldHandle = true; |
| 2328 #if defined(MAC_OS_X_VERSION_10_11) && \ |
| 2329 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_11 |
| 2330 shouldHandle = base::mac::IsAtMostOS10_10(); |
| 2331 #endif |
| 2332 |
| 2333 if (shouldHandle) { |
| 2334 [self handleBeginGestureWithEvent:event]; |
| 2335 } |
| 2336 } |
| 2337 |
| 2338 - (void)endGestureWithEvent:(NSEvent*)event { |
| 2339 // This method must be handled when linking with the 10.10 SDK or earlier, or |
| 2340 // when the app is running on 10.10 or earlier. In other circumstances, the |
| 2341 // event will be handled by |magnifyWithEvent:|, so this method should do |
| 2342 // nothing. |
| 2343 bool shouldHandle = true; |
| 2344 #if defined(MAC_OS_X_VERSION_10_11) && \ |
| 2345 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_11 |
| 2346 shouldHandle = base::mac::IsAtMostOS10_10(); |
| 2347 #endif |
| 2348 |
| 2349 if (shouldHandle) { |
| 2350 [self handleEndGestureWithEvent:event]; |
| 2351 } |
| 2352 } |
| 2353 |
| 2309 - (void)touchesMovedWithEvent:(NSEvent*)event { | 2354 - (void)touchesMovedWithEvent:(NSEvent*)event { |
| 2310 [responderDelegate_ touchesMovedWithEvent:event]; | 2355 [responderDelegate_ touchesMovedWithEvent:event]; |
| 2311 } | 2356 } |
| 2312 | 2357 |
| 2313 - (void)touchesBeganWithEvent:(NSEvent*)event { | 2358 - (void)touchesBeganWithEvent:(NSEvent*)event { |
| 2314 [responderDelegate_ touchesBeganWithEvent:event]; | 2359 [responderDelegate_ touchesBeganWithEvent:event]; |
| 2315 } | 2360 } |
| 2316 | 2361 |
| 2317 - (void)touchesCancelledWithEvent:(NSEvent*)event { | 2362 - (void)touchesCancelledWithEvent:(NSEvent*)event { |
| 2318 [responderDelegate_ touchesCancelledWithEvent:event]; | 2363 [responderDelegate_ touchesCancelledWithEvent:event]; |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2496 renderWidgetHostView_->ProcessMouseWheelEvent(webEvent, latency_info); | 2541 renderWidgetHostView_->ProcessMouseWheelEvent(webEvent, latency_info); |
| 2497 } | 2542 } |
| 2498 } | 2543 } |
| 2499 } | 2544 } |
| 2500 | 2545 |
| 2501 // Called repeatedly during a pinch gesture, with incremental change values. | 2546 // Called repeatedly during a pinch gesture, with incremental change values. |
| 2502 - (void)magnifyWithEvent:(NSEvent*)event { | 2547 - (void)magnifyWithEvent:(NSEvent*)event { |
| 2503 if (!renderWidgetHostView_->render_widget_host_) | 2548 if (!renderWidgetHostView_->render_widget_host_) |
| 2504 return; | 2549 return; |
| 2505 | 2550 |
| 2551 // When linking against the 10.11 (or later) SDK and running on 10.11 or later, |
| 2552 // check the phase of the event and specially handle the "begin" and "end" |
| 2553 // phases. |
| 2554 #if defined(MAC_OS_X_VERSION_10_11) && \ |
| 2555 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_11 |
| 2556 if (event.phase == NSEventPhaseBegan) { |
| 2557 [self handleBeginGestureWithEvent:event]; |
| 2558 return; |
| 2559 } |
| 2560 |
| 2561 if (event.phase == NSEventPhaseEnded || |
| 2562 event.phase == NSEventPhaseCancelled) { |
| 2563 [self handleEndGestureWithEvent:event]; |
| 2564 return; |
| 2565 } |
| 2566 #endif |
| 2567 |
| 2506 // If, due to nesting of multiple gestures (e.g, from multiple touch | 2568 // If, due to nesting of multiple gestures (e.g, from multiple touch |
| 2507 // devices), the beginning of the gesture has been lost, skip the remainder | 2569 // devices), the beginning of the gesture has been lost, skip the remainder |
| 2508 // of the gesture. | 2570 // of the gesture. |
| 2509 if (!gestureBeginEvent_) | 2571 if (!gestureBeginEvent_) |
| 2510 return; | 2572 return; |
| 2511 | 2573 |
| 2512 if (!pinchHasReachedZoomThreshold_) { | 2574 if (!pinchHasReachedZoomThreshold_) { |
| 2513 pinchUnusedAmount_ *= (1 + [event magnification]); | 2575 pinchUnusedAmount_ *= (1 + [event magnification]); |
| 2514 if (pinchUnusedAmount_ < 0.667 || pinchUnusedAmount_ > 1.5) | 2576 if (pinchUnusedAmount_ < 0.667 || pinchUnusedAmount_ > 1.5) |
| 2515 pinchHasReachedZoomThreshold_ = true; | 2577 pinchHasReachedZoomThreshold_ = true; |
| (...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3424 | 3486 |
| 3425 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3487 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3426 // regions that are not draggable. (See ControlRegionView in | 3488 // regions that are not draggable. (See ControlRegionView in |
| 3427 // native_app_window_cocoa.mm). This requires the render host view to be | 3489 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3428 // draggable by default. | 3490 // draggable by default. |
| 3429 - (BOOL)mouseDownCanMoveWindow { | 3491 - (BOOL)mouseDownCanMoveWindow { |
| 3430 return YES; | 3492 return YES; |
| 3431 } | 3493 } |
| 3432 | 3494 |
| 3433 @end | 3495 @end |
| OLD | NEW |