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

Side by Side Diff: chrome/browser/tab_contents/tab_contents_view_mac.mm

Issue 303002: Make window cycling work even if you change it to something else than cmd-` in sysprefs. (Closed)
Patch Set: Fix spelling. Created 11 years, 2 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 | « chrome/browser/renderer_host/render_widget_host_view_mac.mm ('k') | no next file » | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #import <Carbon/Carbon.h> 5 #import <Carbon/Carbon.h>
6 6
7 #include "chrome/browser/tab_contents/tab_contents_view_mac.h" 7 #include "chrome/browser/tab_contents/tab_contents_view_mac.h"
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "chrome/browser/browser.h" // TODO(beng): this dependency is awful. 11 #include "chrome/browser/browser.h" // TODO(beng): this dependency is awful.
12 #import "chrome/browser/chrome_application_mac.h"
pink (ping after 24hrs) 2009/10/20 16:14:44 i don't see why this include is needed. Why does t
Nico 2009/10/20 16:32:24 Historical reasons. http://codereview.chromium.org
12 #import "chrome/browser/cocoa/focus_tracker.h" 13 #import "chrome/browser/cocoa/focus_tracker.h"
13 #import "chrome/browser/cocoa/chrome_browser_window.h" 14 #import "chrome/browser/cocoa/chrome_browser_window.h"
14 #import "chrome/browser/cocoa/browser_window_controller.h" 15 #import "chrome/browser/cocoa/browser_window_controller.h"
15 #include "chrome/browser/global_keyboard_shortcuts_mac.h" 16 #include "chrome/browser/global_keyboard_shortcuts_mac.h"
16 #include "chrome/browser/cocoa/sad_tab_view.h" 17 #include "chrome/browser/cocoa/sad_tab_view.h"
17 #import "chrome/browser/cocoa/web_drag_source.h" 18 #import "chrome/browser/cocoa/web_drag_source.h"
18 #import "chrome/browser/cocoa/web_drop_target.h" 19 #import "chrome/browser/cocoa/web_drop_target.h"
19 #include "chrome/browser/renderer_host/render_view_host_factory.h" 20 #include "chrome/browser/renderer_host/render_view_host_factory.h"
20 #include "chrome/browser/renderer_host/render_widget_host.h" 21 #include "chrome/browser/renderer_host/render_widget_host.h"
21 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" 22 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h"
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 - (TabContents*)tabContents { 310 - (TabContents*)tabContents {
310 return tabContentsView_->tab_contents(); 311 return tabContentsView_->tab_contents();
311 } 312 }
312 313
313 - (void)processKeyboardEvent:(NativeWebKeyboardEvent*)wkEvent { 314 - (void)processKeyboardEvent:(NativeWebKeyboardEvent*)wkEvent {
314 if (wkEvent->skip_in_browser) 315 if (wkEvent->skip_in_browser)
315 return; 316 return;
316 317
317 NSEvent* event = wkEvent->os_event; 318 NSEvent* event = wkEvent->os_event;
318 319
319 if ([event type] == NSKeyDown && ([event modifierFlags] & NSCommandKeyMask)) { 320 // If this tab is no longer active, its window will be |nil|. In that case,
320 // We need to dispatch this to the menu.
321 if ([[NSApp mainMenu] performKeyEquivalent:event])
322 return;
323 }
324
325 // Cmd-` is not in the menu and it's apparently handled by |NSApp sendEvent|
326 // if the application doesn't swallow it. We do, so we need to handle this
327 // key ourself. On foreign keyboards, the "switch windows" key is not the
328 // ` key, so do this by keycode instead of |event characters|.
329 if ([event type] == NSKeyDown &&
330 [event keyCode] == kVK_ANSI_Grave &&
331 [NSApp respondsToSelector:@selector(_cycleWindowsReversed:)]) {
332 const NSUInteger kModifierMask = NSShiftKeyMask |
333 NSControlKeyMask |
334 NSAlternateKeyMask |
335 NSCommandKeyMask;
336 if (([event modifierFlags] & kModifierMask) == NSCommandKeyMask)
337 [NSApp _cycleWindowsReversed:NO];
338 else if (([event modifierFlags] & kModifierMask) ==
339 (NSCommandKeyMask | NSShiftKeyMask) &&
340 [NSApp respondsToSelector:@selector(_cycleWindowsReversed:)])
341 [NSApp _cycleWindowsReversed:YES];
342 }
343
344 // If this tab is no longer active, it's window will be |nil|. In that case,
345 // best ignore the event. 321 // best ignore the event.
346 if (![self window]) 322 if (![self window])
347 return; 323 return;
324 ChromeEventProcessingWindow* window =
325 (ChromeEventProcessingWindow*)[self window];
326 DCHECK([window isKindOfClass:[ChromeEventProcessingWindow class]]);
348 327
349 // Do not fire shortcuts on key up. 328 // Do not fire shortcuts on key up.
350 if ([event type] == NSKeyDown) { 329 if ([event type] == NSKeyDown) {
351 ChromeBrowserWindow* window = (ChromeBrowserWindow*)[self window];
352 DCHECK([window isKindOfClass:[ChromeBrowserWindow class]]);
353 if ([window handleExtraBrowserKeyboardShortcut:event]) 330 if ([window handleExtraBrowserKeyboardShortcut:event])
354 return; 331 return;
355 if ([window handleExtraWindowKeyboardShortcut:event]) 332 if ([window handleExtraWindowKeyboardShortcut:event])
356 return; 333 return;
357 } 334 }
358 335
359 if ([event type] == NSKeyDown) 336 // We need to re-dispatch the event, so that it is sent to the menu or other
360 [super keyDown:event]; 337 // cocoa mechanisms (such as the cmd-` handler).
361 else if ([event type] == NSKeyUp) 338 RenderWidgetHostViewCocoa* rwhv = static_cast<RenderWidgetHostViewCocoa*>(
362 [super keyUp:event]; 339 tabContentsView_->GetContentNativeView());
340 DCHECK([rwhv isKindOfClass:[RenderWidgetHostViewCocoa class]]);
341 [rwhv setIgnoreKeyEvents:YES];
342 [window redispatchEvent:event];
343 [rwhv setIgnoreKeyEvents:NO];
363 } 344 }
364 345
365 - (void)mouseEvent:(NSEvent *)theEvent { 346 - (void)mouseEvent:(NSEvent *)theEvent {
366 TabContents* tabContents = [self tabContents]; 347 TabContents* tabContents = [self tabContents];
367 if (tabContents->delegate()) { 348 if (tabContents->delegate()) {
368 if ([theEvent type] == NSMouseMoved) 349 if ([theEvent type] == NSMouseMoved)
369 tabContents->delegate()->ContentsMouseEvent(tabContents, true); 350 tabContents->delegate()->ContentsMouseEvent(tabContents, true);
370 if ([theEvent type] == NSMouseExited) 351 if ([theEvent type] == NSMouseExited)
371 tabContents->delegate()->ContentsMouseEvent(tabContents, false); 352 tabContents->delegate()->ContentsMouseEvent(tabContents, false);
372 } 353 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 } 448 }
468 449
469 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { 450 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
470 return [dropTarget_ performDragOperation:sender view:self]; 451 return [dropTarget_ performDragOperation:sender view:self];
471 } 452 }
472 453
473 // Tons of stuff goes here, where we grab events going on in Cocoaland and send 454 // Tons of stuff goes here, where we grab events going on in Cocoaland and send
474 // them into the C++ system. TODO(avi): all that jazz 455 // them into the C++ system. TODO(avi): all that jazz
475 456
476 @end 457 @end
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/render_widget_host_view_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698