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

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_cocoa.mm

Issue 7747011: Revert 98112 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/ui/cocoa/browser_window_cocoa.h" 5 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/sys_string_conversions.h" 10 #include "base/sys_string_conversions.h"
11 #include "chrome/app/chrome_command_ids.h" 11 #include "chrome/app/chrome_command_ids.h"
12 #include "chrome/browser/bookmarks/bookmark_utils.h" 12 #include "chrome/browser/bookmarks/bookmark_utils.h"
13 #include "chrome/browser/download/download_shelf.h" 13 #include "chrome/browser/download/download_shelf.h"
14 #include "chrome/browser/global_keyboard_shortcuts_mac.h"
14 #include "chrome/browser/page_info_window.h" 15 #include "chrome/browser/page_info_window.h"
15 #include "chrome/browser/prefs/pref_service.h" 16 #include "chrome/browser/prefs/pref_service.h"
16 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/sidebar/sidebar_container.h" 18 #include "chrome/browser/sidebar/sidebar_container.h"
18 #include "chrome/browser/sidebar/sidebar_manager.h" 19 #include "chrome/browser/sidebar/sidebar_manager.h"
19 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_list.h" 21 #include "chrome/browser/ui/browser_list.h"
21 #import "chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller.h" 22 #import "chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller.h"
22 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 23 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
23 #import "chrome/browser/ui/cocoa/browser_window_utils.h"
24 #import "chrome/browser/ui/cocoa/bug_report_window_controller.h" 24 #import "chrome/browser/ui/cocoa/bug_report_window_controller.h"
25 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" 25 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
26 #import "chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.h" 26 #import "chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.h"
27 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" 27 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h"
28 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" 28 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
29 #import "chrome/browser/ui/cocoa/html_dialog_window_controller.h" 29 #import "chrome/browser/ui/cocoa/html_dialog_window_controller.h"
30 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" 30 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
31 #import "chrome/browser/ui/cocoa/nsmenuitem_additions.h" 31 #import "chrome/browser/ui/cocoa/nsmenuitem_additions.h"
32 #include "chrome/browser/ui/cocoa/repost_form_warning_mac.h" 32 #include "chrome/browser/ui/cocoa/repost_form_warning_mac.h"
33 #include "chrome/browser/ui/cocoa/restart_browser.h" 33 #include "chrome/browser/ui/cocoa/restart_browser.h"
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 bool show_history) { 442 bool show_history) {
443 browser::ShowPageInfoBubble(window(), profile, url, ssl, show_history); 443 browser::ShowPageInfoBubble(window(), profile, url, ssl, show_history);
444 } 444 }
445 445
446 void BrowserWindowCocoa::ShowAppMenu() { 446 void BrowserWindowCocoa::ShowAppMenu() {
447 // No-op. Mac doesn't support showing the menus via alt keys. 447 // No-op. Mac doesn't support showing the menus via alt keys.
448 } 448 }
449 449
450 bool BrowserWindowCocoa::PreHandleKeyboardEvent( 450 bool BrowserWindowCocoa::PreHandleKeyboardEvent(
451 const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) { 451 const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) {
452 if (![BrowserWindowUtils shouldHandleKeyboardEvent:event]) 452 if (event.skip_in_browser || event.type == NativeWebKeyboardEvent::Char)
453 return false; 453 return false;
454 454
455 int id = [BrowserWindowUtils getCommandId:event]; 455 DCHECK(event.os_event != NULL);
456 int id = GetCommandId(event);
456 if (id == -1) 457 if (id == -1)
457 return false; 458 return false;
458 459
459 if (browser_->IsReservedCommandOrKey(id, event)) { 460 if (browser_->IsReservedCommandOrKey(id, event))
460 return [BrowserWindowUtils handleKeyboardEvent:event.os_event 461 return HandleKeyboardEventInternal(event.os_event);
461 inWindow:window()];
462 }
463 462
464 DCHECK(is_keyboard_shortcut); 463 DCHECK(is_keyboard_shortcut != NULL);
465 *is_keyboard_shortcut = true; 464 *is_keyboard_shortcut = true;
465
466 return false; 466 return false;
467 } 467 }
468 468
469 void BrowserWindowCocoa::HandleKeyboardEvent( 469 void BrowserWindowCocoa::HandleKeyboardEvent(
470 const NativeWebKeyboardEvent& event) { 470 const NativeWebKeyboardEvent& event) {
471 if ([BrowserWindowUtils shouldHandleKeyboardEvent:event]) 471 if (event.skip_in_browser || event.type == NativeWebKeyboardEvent::Char)
472 [BrowserWindowUtils handleKeyboardEvent:event.os_event inWindow:window()]; 472 return;
473
474 DCHECK(event.os_event != NULL);
475 HandleKeyboardEventInternal(event.os_event);
476 }
477
478 @interface MenuWalker : NSObject
479 + (NSMenuItem*)itemForKeyEquivalent:(NSEvent*)key
480 menu:(NSMenu*)menu;
481 @end
482
483 @implementation MenuWalker
484 + (NSMenuItem*)itemForKeyEquivalent:(NSEvent*)key
485 menu:(NSMenu*)menu {
486 NSMenuItem* result = nil;
487
488 for (NSMenuItem *item in [menu itemArray]) {
489 NSMenu* submenu = [item submenu];
490 if (submenu) {
491 if (submenu != [NSApp servicesMenu])
492 result = [self itemForKeyEquivalent:key
493 menu:submenu];
494 } else if ([item cr_firesForKeyEventIfEnabled:key]) {
495 result = item;
496 }
497
498 if (result)
499 break;
500 }
501
502 return result;
503 }
504 @end
505
506 int BrowserWindowCocoa::GetCommandId(const NativeWebKeyboardEvent& event) {
507 if ([event.os_event type] != NSKeyDown)
508 return -1;
509
510 // Look in menu.
511 NSMenuItem* item = [MenuWalker itemForKeyEquivalent:event.os_event
512 menu:[NSApp mainMenu]];
513
514 if (item && [item action] == @selector(commandDispatch:) && [item tag] > 0)
515 return [item tag];
516
517 // "Close window" doesn't use the |commandDispatch:| mechanism. Menu items
518 // that do not correspond to IDC_ constants need no special treatment however,
519 // as they can't be blacklisted in |Browser::IsReservedCommandOrKey()| anyhow.
520 if (item && [item action] == @selector(performClose:))
521 return IDC_CLOSE_WINDOW;
522
523 // "Exit" doesn't use the |commandDispatch:| mechanism either.
524 if (item && [item action] == @selector(terminate:))
525 return IDC_EXIT;
526
527 // Look in secondary keyboard shortcuts.
528 NSUInteger modifiers = [event.os_event modifierFlags];
529 const bool cmdKey = (modifiers & NSCommandKeyMask) != 0;
530 const bool shiftKey = (modifiers & NSShiftKeyMask) != 0;
531 const bool cntrlKey = (modifiers & NSControlKeyMask) != 0;
532 const bool optKey = (modifiers & NSAlternateKeyMask) != 0;
533 const int keyCode = [event.os_event keyCode];
534 const unichar keyChar = KeyCharacterForEvent(event.os_event);
535
536 int cmdNum = CommandForWindowKeyboardShortcut(
537 cmdKey, shiftKey, cntrlKey, optKey, keyCode, keyChar);
538 if (cmdNum != -1)
539 return cmdNum;
540
541 cmdNum = CommandForBrowserKeyboardShortcut(
542 cmdKey, shiftKey, cntrlKey, optKey, keyCode, keyChar);
543 if (cmdNum != -1)
544 return cmdNum;
545
546 return -1;
547 }
548
549 bool BrowserWindowCocoa::HandleKeyboardEventInternal(NSEvent* event) {
550 ChromeEventProcessingWindow* event_window =
551 static_cast<ChromeEventProcessingWindow*>(window());
552 DCHECK([event_window isKindOfClass:[ChromeEventProcessingWindow class]]);
553
554 // Do not fire shortcuts on key up.
555 if ([event type] == NSKeyDown) {
556 // Send the event to the menu before sending it to the browser/window
557 // shortcut handling, so that if a user configures cmd-left to mean
558 // "previous tab", it takes precedence over the built-in "history back"
559 // binding. Other than that, the |-redispatchKeyEvent:| call would take care
560 // of invoking the original menu item shortcut as well.
561
562 if ([[NSApp mainMenu] performKeyEquivalent:event])
563 return true;
564
565 if ([event_window handleExtraBrowserKeyboardShortcut:event])
566 return true;
567
568 if ([event_window handleExtraWindowKeyboardShortcut:event])
569 return true;
570
571 if ([event_window handleDelayedWindowKeyboardShortcut:event])
572 return true;
573 }
574
575 return [event_window redispatchKeyEvent:event];
473 } 576 }
474 577
475 void BrowserWindowCocoa::ShowCreateWebAppShortcutsDialog( 578 void BrowserWindowCocoa::ShowCreateWebAppShortcutsDialog(
476 TabContentsWrapper* tab_contents) { 579 TabContentsWrapper* tab_contents) {
477 NOTIMPLEMENTED(); 580 NOTIMPLEMENTED();
478 } 581 }
479 582
480 void BrowserWindowCocoa::ShowCreateChromeAppShortcutsDialog( 583 void BrowserWindowCocoa::ShowCreateChromeAppShortcutsDialog(
481 Profile* profile, const Extension* app) { 584 Profile* profile, const Extension* app) {
482 NOTIMPLEMENTED(); 585 NOTIMPLEMENTED();
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 681
579 NSWindow* BrowserWindowCocoa::window() const { 682 NSWindow* BrowserWindowCocoa::window() const {
580 return [controller_ window]; 683 return [controller_ window];
581 } 684 }
582 685
583 void BrowserWindowCocoa::UpdateSidebarForContents(TabContents* tab_contents) { 686 void BrowserWindowCocoa::UpdateSidebarForContents(TabContents* tab_contents) {
584 if (tab_contents == browser_->GetSelectedTabContents()) { 687 if (tab_contents == browser_->GetSelectedTabContents()) {
585 [controller_ updateSidebarForContents:tab_contents]; 688 [controller_ updateSidebarForContents:tab_contents];
586 } 689 }
587 } 690 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_cocoa.h ('k') | chrome/browser/ui/cocoa/browser_window_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698