Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 408973002: mac: Load the system hotkeys after launch. (reland) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add more unit tests. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/cocoa/system_hotkey_map_unittest.mm ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 2425 matching lines...) Expand 10 before | Expand all | Expand 10 after
2534 } 2547 }
2535 2548
2536 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent { 2549 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent {
2537 // |performKeyEquivalent:| is sent to all views of a window, not only down the 2550 // |performKeyEquivalent:| is sent to all views of a window, not only down the
2538 // responder chain (cf. "Handling Key Equivalents" in 2551 // responder chain (cf. "Handling Key Equivalents" in
2539 // http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Event Overview/HandlingKeyEvents/HandlingKeyEvents.html 2552 // http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Event Overview/HandlingKeyEvents/HandlingKeyEvents.html
2540 // ). We only want to handle key equivalents if we're first responder. 2553 // ). We only want to handle key equivalents if we're first responder.
2541 if ([[self window] firstResponder] != self) 2554 if ([[self window] firstResponder] != self)
2542 return NO; 2555 return NO;
2543 2556
2557 // If the event is reserved by the system, then do not pass it to web content.
2558 if (EventIsReservedBySystem(theEvent))
2559 return NO;
2560
2544 // If we return |NO| from this function, cocoa will send the key event to 2561 // If we return |NO| from this function, cocoa will send the key event to
2545 // the menu and only if the menu does not process the event to |keyDown:|. We 2562 // the menu and only if the menu does not process the event to |keyDown:|. We
2546 // want to send the event to a renderer _before_ sending it to the menu, so 2563 // want to send the event to a renderer _before_ sending it to the menu, so
2547 // we need to return |YES| for all events that might be swallowed by the menu. 2564 // we need to return |YES| for all events that might be swallowed by the menu.
2548 // We do not return |YES| for every keypress because we don't get |keyDown:| 2565 // We do not return |YES| for every keypress because we don't get |keyDown:|
2549 // events for keys that we handle this way. 2566 // events for keys that we handle this way.
2550 NSUInteger modifierFlags = [theEvent modifierFlags]; 2567 NSUInteger modifierFlags = [theEvent modifierFlags];
2551 if ((modifierFlags & NSCommandKeyMask) == 0) { 2568 if ((modifierFlags & NSCommandKeyMask) == 0) {
2552 // Make sure the menu does not contain key equivalents that don't 2569 // Make sure the menu does not contain key equivalents that don't
2553 // contain cmd. 2570 // contain cmd.
(...skipping 27 matching lines...) Expand all
2581 if (handled) 2598 if (handled)
2582 return kEventHandled; 2599 return kEventHandled;
2583 } 2600 }
2584 2601
2585 [self keyEvent:theEvent wasKeyEquivalent:NO]; 2602 [self keyEvent:theEvent wasKeyEquivalent:NO];
2586 return kEventHandled; 2603 return kEventHandled;
2587 } 2604 }
2588 2605
2589 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv { 2606 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv {
2590 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::keyEvent"); 2607 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::keyEvent");
2608
2609 // If the user changes the system hotkey mapping after Chrome has been
2610 // launched, then it is possible that a formerly reserved system hotkey is no
2611 // longer reserved. The hotkey would have skipped the renderer, but would
2612 // also have not been handled by the system. If this is the case, immediately
2613 // return.
2614 // TODO(erikchen): SystemHotkeyHelperMac should use the File System Events
2615 // api to monitor changes to system hotkeys. This logic will have to be
2616 // updated.
2617 // http://crbug.com/383558.
2618 if (EventIsReservedBySystem(theEvent))
2619 return;
2620
2591 DCHECK([theEvent type] != NSKeyDown || 2621 DCHECK([theEvent type] != NSKeyDown ||
2592 !equiv == !([theEvent modifierFlags] & NSCommandKeyMask)); 2622 !equiv == !([theEvent modifierFlags] & NSCommandKeyMask));
2593 2623
2594 if ([theEvent type] == NSFlagsChanged) { 2624 if ([theEvent type] == NSFlagsChanged) {
2595 // Ignore NSFlagsChanged events from the NumLock and Fn keys as 2625 // Ignore NSFlagsChanged events from the NumLock and Fn keys as
2596 // Safari does in -[WebHTMLView flagsChanged:] (of "WebHTMLView.mm"). 2626 // Safari does in -[WebHTMLView flagsChanged:] (of "WebHTMLView.mm").
2597 int keyCode = [theEvent keyCode]; 2627 int keyCode = [theEvent keyCode];
2598 if (!keyCode || keyCode == 10 || keyCode == 63) 2628 if (!keyCode || keyCode == 10 || keyCode == 63)
2599 return; 2629 return;
2600 } 2630 }
(...skipping 1373 matching lines...) Expand 10 before | Expand all | Expand 10 after
3974 4004
3975 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 4005 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3976 // regions that are not draggable. (See ControlRegionView in 4006 // regions that are not draggable. (See ControlRegionView in
3977 // native_app_window_cocoa.mm). This requires the render host view to be 4007 // native_app_window_cocoa.mm). This requires the render host view to be
3978 // draggable by default. 4008 // draggable by default.
3979 - (BOOL)mouseDownCanMoveWindow { 4009 - (BOOL)mouseDownCanMoveWindow {
3980 return YES; 4010 return YES;
3981 } 4011 }
3982 4012
3983 @end 4013 @end
OLDNEW
« no previous file with comments | « content/browser/cocoa/system_hotkey_map_unittest.mm ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698