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 | 10 |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "base/mac/sdk_forward_declarations.h" | 21 #include "base/mac/sdk_forward_declarations.h" |
22 #include "base/message_loop/message_loop.h" | 22 #include "base/message_loop/message_loop.h" |
23 #include "base/metrics/histogram.h" | 23 #include "base/metrics/histogram.h" |
24 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
25 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
26 #include "base/strings/sys_string_conversions.h" | 26 #include "base/strings/sys_string_conversions.h" |
27 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
28 #include "base/sys_info.h" | 28 #include "base/sys_info.h" |
29 #import "content/browser/accessibility/browser_accessibility_cocoa.h" | 29 #import "content/browser/accessibility/browser_accessibility_cocoa.h" |
30 #include "content/browser/accessibility/browser_accessibility_manager_mac.h" | 30 #include "content/browser/accessibility/browser_accessibility_manager_mac.h" |
31 #import "content/browser/cocoa/system_hotkey_helper_mac.h" | |
32 #import "content/browser/cocoa/system_hotkey_map.h" | |
31 #include "content/browser/compositor/resize_lock.h" | 33 #include "content/browser/compositor/resize_lock.h" |
32 #include "content/browser/frame_host/frame_tree.h" | 34 #include "content/browser/frame_host/frame_tree.h" |
33 #include "content/browser/frame_host/frame_tree_node.h" | 35 #include "content/browser/frame_host/frame_tree_node.h" |
34 #include "content/browser/frame_host/render_frame_host_impl.h" | 36 #include "content/browser/frame_host/render_frame_host_impl.h" |
35 #include "content/browser/gpu/compositor_util.h" | 37 #include "content/browser/gpu/compositor_util.h" |
36 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h" | 38 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h" |
37 #include "content/browser/renderer_host/compositing_iosurface_layer_mac.h" | 39 #include "content/browser/renderer_host/compositing_iosurface_layer_mac.h" |
38 #include "content/browser/renderer_host/compositing_iosurface_mac.h" | 40 #include "content/browser/renderer_host/compositing_iosurface_mac.h" |
39 #include "content/browser/renderer_host/render_widget_helper.h" | 41 #include "content/browser/renderer_host/render_widget_helper.h" |
40 #include "content/browser/renderer_host/render_view_host_impl.h" | 42 #include "content/browser/renderer_host/render_view_host_impl.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 using content::RenderWidgetHostViewMac; | 91 using content::RenderWidgetHostViewMac; |
90 using content::RenderWidgetHostViewMacEditCommandHelper; | 92 using content::RenderWidgetHostViewMacEditCommandHelper; |
91 using content::TextInputClientMac; | 93 using content::TextInputClientMac; |
92 using content::WebContents; | 94 using content::WebContents; |
93 using blink::WebInputEvent; | 95 using blink::WebInputEvent; |
94 using blink::WebInputEventFactory; | 96 using blink::WebInputEventFactory; |
95 using blink::WebMouseEvent; | 97 using blink::WebMouseEvent; |
96 using blink::WebMouseWheelEvent; | 98 using blink::WebMouseWheelEvent; |
97 using blink::WebGestureEvent; | 99 using blink::WebGestureEvent; |
98 | 100 |
101 namespace { | |
102 | |
103 // Whether a keyboard event has been reserved by OSX. | |
104 BOOL EventIsReservedBySystem(NSEvent* event) { | |
105 content::SystemHotkeyHelperMac* helper = | |
106 content::SystemHotkeyHelperMac::GetInstance(); | |
107 return helper->map()->IsEventReserved(event); | |
108 } | |
109 | |
110 } // namespace | |
111 | |
99 // These are not documented, so use only after checking -respondsToSelector:. | 112 // These are not documented, so use only after checking -respondsToSelector:. |
100 @interface NSApplication (UndocumentedSpeechMethods) | 113 @interface NSApplication (UndocumentedSpeechMethods) |
101 - (void)speakString:(NSString*)string; | 114 - (void)speakString:(NSString*)string; |
102 - (void)stopSpeaking:(id)sender; | 115 - (void)stopSpeaking:(id)sender; |
103 - (BOOL)isSpeaking; | 116 - (BOOL)isSpeaking; |
104 @end | 117 @end |
105 | 118 |
106 // Declare things that are part of the 10.7 SDK. | 119 // Declare things that are part of the 10.7 SDK. |
107 #if !defined(MAC_OS_X_VERSION_10_7) || \ | 120 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
108 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | 121 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
(...skipping 2401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2510 } | 2523 } |
2511 | 2524 |
2512 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent { | 2525 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent { |
2513 // |performKeyEquivalent:| is sent to all views of a window, not only down the | 2526 // |performKeyEquivalent:| is sent to all views of a window, not only down the |
2514 // responder chain (cf. "Handling Key Equivalents" in | 2527 // responder chain (cf. "Handling Key Equivalents" in |
2515 // http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Event Overview/HandlingKeyEvents/HandlingKeyEvents.html | 2528 // http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Event Overview/HandlingKeyEvents/HandlingKeyEvents.html |
2516 // ). We only want to handle key equivalents if we're first responder. | 2529 // ). We only want to handle key equivalents if we're first responder. |
2517 if ([[self window] firstResponder] != self) | 2530 if ([[self window] firstResponder] != self) |
2518 return NO; | 2531 return NO; |
2519 | 2532 |
2533 // If the event is reserved by the system, then do not pass it to web content. | |
2534 if (EventIsReservedBySystem(theEvent)) | |
2535 return NO; | |
2536 | |
2520 // If we return |NO| from this function, cocoa will send the key event to | 2537 // If we return |NO| from this function, cocoa will send the key event to |
2521 // the menu and only if the menu does not process the event to |keyDown:|. We | 2538 // the menu and only if the menu does not process the event to |keyDown:|. We |
2522 // want to send the event to a renderer _before_ sending it to the menu, so | 2539 // want to send the event to a renderer _before_ sending it to the menu, so |
2523 // we need to return |YES| for all events that might be swallowed by the menu. | 2540 // we need to return |YES| for all events that might be swallowed by the menu. |
2524 // We do not return |YES| for every keypress because we don't get |keyDown:| | 2541 // We do not return |YES| for every keypress because we don't get |keyDown:| |
2525 // events for keys that we handle this way. | 2542 // events for keys that we handle this way. |
2526 NSUInteger modifierFlags = [theEvent modifierFlags]; | 2543 NSUInteger modifierFlags = [theEvent modifierFlags]; |
2527 if ((modifierFlags & NSCommandKeyMask) == 0) { | 2544 if ((modifierFlags & NSCommandKeyMask) == 0) { |
2528 // Make sure the menu does not contain key equivalents that don't | 2545 // Make sure the menu does not contain key equivalents that don't |
2529 // contain cmd. | 2546 // contain cmd. |
(...skipping 27 matching lines...) Expand all Loading... | |
2557 if (handled) | 2574 if (handled) |
2558 return kEventHandled; | 2575 return kEventHandled; |
2559 } | 2576 } |
2560 | 2577 |
2561 [self keyEvent:theEvent wasKeyEquivalent:NO]; | 2578 [self keyEvent:theEvent wasKeyEquivalent:NO]; |
2562 return kEventHandled; | 2579 return kEventHandled; |
2563 } | 2580 } |
2564 | 2581 |
2565 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv { | 2582 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv { |
2566 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::keyEvent"); | 2583 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::keyEvent"); |
2584 | |
2585 // If the user changes the system hotkey mapping after Chrome has been | |
2586 // launched, then it is possible that a formerly reserved system hotkey is no | |
2587 // longer reserved. The hotkey would have skipped the renderer, but would | |
2588 // also have not been handled by the system. If this is the case, immediately | |
2589 // return. | |
2590 // TODO(erikchen): SystemHotkeyHelperMac should use FS api to monitor changes | |
Robert Sesek
2014/07/08 13:40:01
"FS api" ? Don't use abbreviations in comments.
erikchen
2014/07/10 02:07:32
Done.
| |
2591 // to system hotkeys. This logic will have to be updated. | |
2592 // http://crbug.com/383558. | |
2593 if (EventIsReservedBySystem(theEvent)) | |
2594 return; | |
2595 | |
2567 DCHECK([theEvent type] != NSKeyDown || | 2596 DCHECK([theEvent type] != NSKeyDown || |
2568 !equiv == !([theEvent modifierFlags] & NSCommandKeyMask)); | 2597 !equiv == !([theEvent modifierFlags] & NSCommandKeyMask)); |
2569 | 2598 |
2570 if ([theEvent type] == NSFlagsChanged) { | 2599 if ([theEvent type] == NSFlagsChanged) { |
2571 // Ignore NSFlagsChanged events from the NumLock and Fn keys as | 2600 // Ignore NSFlagsChanged events from the NumLock and Fn keys as |
2572 // Safari does in -[WebHTMLView flagsChanged:] (of "WebHTMLView.mm"). | 2601 // Safari does in -[WebHTMLView flagsChanged:] (of "WebHTMLView.mm"). |
2573 int keyCode = [theEvent keyCode]; | 2602 int keyCode = [theEvent keyCode]; |
2574 if (!keyCode || keyCode == 10 || keyCode == 63) | 2603 if (!keyCode || keyCode == 10 || keyCode == 63) |
2575 return; | 2604 return; |
2576 } | 2605 } |
(...skipping 1373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3950 | 3979 |
3951 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3980 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
3952 // regions that are not draggable. (See ControlRegionView in | 3981 // regions that are not draggable. (See ControlRegionView in |
3953 // native_app_window_cocoa.mm). This requires the render host view to be | 3982 // native_app_window_cocoa.mm). This requires the render host view to be |
3954 // draggable by default. | 3983 // draggable by default. |
3955 - (BOOL)mouseDownCanMoveWindow { | 3984 - (BOOL)mouseDownCanMoveWindow { |
3956 return YES; | 3985 return YES; |
3957 } | 3986 } |
3958 | 3987 |
3959 @end | 3988 @end |
OLD | NEW |