| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/l10n_util_mac.h" | 5 #include "app/l10n_util_mac.h" |
| 6 #include "base/gfx/rect.h" | 6 #include "base/gfx/rect.h" |
| 7 #include "base/keyboard_codes.h" |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 8 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 9 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_utils.h" | 11 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 11 #include "chrome/browser/browser_list.h" | 12 #include "chrome/browser/browser_list.h" |
| 12 #include "chrome/browser/cocoa/browser_window_cocoa.h" | 13 #include "chrome/browser/cocoa/browser_window_cocoa.h" |
| 13 #import "chrome/browser/cocoa/browser_window_controller.h" | 14 #import "chrome/browser/cocoa/browser_window_controller.h" |
| 14 #import "chrome/browser/cocoa/bug_report_window_controller.h" | 15 #import "chrome/browser/cocoa/bug_report_window_controller.h" |
| 15 #import "chrome/browser/cocoa/clear_browsing_data_controller.h" | 16 #import "chrome/browser/cocoa/clear_browsing_data_controller.h" |
| 17 #import "chrome/browser/cocoa/chrome_browser_window.h" |
| 16 #import "chrome/browser/cocoa/download_shelf_controller.h" | 18 #import "chrome/browser/cocoa/download_shelf_controller.h" |
| 17 #import "chrome/browser/cocoa/html_dialog_window_controller.h" | 19 #import "chrome/browser/cocoa/html_dialog_window_controller.h" |
| 18 #import "chrome/browser/cocoa/import_settings_dialog.h" | 20 #import "chrome/browser/cocoa/import_settings_dialog.h" |
| 19 #import "chrome/browser/cocoa/keyword_editor_cocoa_controller.h" | 21 #import "chrome/browser/cocoa/keyword_editor_cocoa_controller.h" |
| 20 #import "chrome/browser/cocoa/nsmenuitem_additions.h" | 22 #import "chrome/browser/cocoa/nsmenuitem_additions.h" |
| 21 #include "chrome/browser/cocoa/page_info_window_mac.h" | 23 #include "chrome/browser/cocoa/page_info_window_mac.h" |
| 22 #include "chrome/browser/cocoa/repost_form_warning_mac.h" | 24 #include "chrome/browser/cocoa/repost_form_warning_mac.h" |
| 23 #include "chrome/browser/cocoa/status_bubble_mac.h" | 25 #include "chrome/browser/cocoa/status_bubble_mac.h" |
| 24 #include "chrome/browser/cocoa/task_manager_mac.h" | 26 #include "chrome/browser/cocoa/task_manager_mac.h" |
| 25 #import "chrome/browser/cocoa/theme_install_bubble_view.h" | 27 #import "chrome/browser/cocoa/theme_install_bubble_view.h" |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 } | 363 } |
| 362 | 364 |
| 363 void BrowserWindowCocoa::ShowPageMenu() { | 365 void BrowserWindowCocoa::ShowPageMenu() { |
| 364 // No-op. Mac doesn't support showing the menus via alt keys. | 366 // No-op. Mac doesn't support showing the menus via alt keys. |
| 365 } | 367 } |
| 366 | 368 |
| 367 void BrowserWindowCocoa::ShowAppMenu() { | 369 void BrowserWindowCocoa::ShowAppMenu() { |
| 368 // No-op. Mac doesn't support showing the menus via alt keys. | 370 // No-op. Mac doesn't support showing the menus via alt keys. |
| 369 } | 371 } |
| 370 | 372 |
| 373 bool BrowserWindowCocoa::PreHandleKeyboardEvent( |
| 374 const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) { |
| 375 if (event.skip_in_browser || event.type == NativeWebKeyboardEvent::Char) |
| 376 return false; |
| 377 |
| 378 DCHECK(event.os_event != NULL); |
| 379 int id = GetCommandId(event); |
| 380 if (id == -1) |
| 381 return false; |
| 382 |
| 383 if (browser_->IsReservedCommand(id)) |
| 384 return HandleKeyboardEventInternal(event.os_event); |
| 385 |
| 386 DCHECK(is_keyboard_shortcut != NULL); |
| 387 *is_keyboard_shortcut = true; |
| 388 |
| 389 return false; |
| 390 } |
| 391 |
| 392 void BrowserWindowCocoa::HandleKeyboardEvent( |
| 393 const NativeWebKeyboardEvent& event) { |
| 394 if (event.skip_in_browser || event.type == NativeWebKeyboardEvent::Char) |
| 395 return; |
| 396 |
| 397 DCHECK(event.os_event != NULL); |
| 398 HandleKeyboardEventInternal(event.os_event); |
| 399 } |
| 400 |
| 371 @interface MenuWalker : NSObject | 401 @interface MenuWalker : NSObject |
| 372 + (NSMenuItem*)itemForKeyEquivalent:(NSEvent*)key | 402 + (NSMenuItem*)itemForKeyEquivalent:(NSEvent*)key |
| 373 menu:(NSMenu*)menu; | 403 menu:(NSMenu*)menu; |
| 374 @end | 404 @end |
| 375 | 405 |
| 376 @implementation MenuWalker | 406 @implementation MenuWalker |
| 377 + (NSMenuItem*)itemForKeyEquivalent:(NSEvent*)key | 407 + (NSMenuItem*)itemForKeyEquivalent:(NSEvent*)key |
| 378 menu:(NSMenu*)menu { | 408 menu:(NSMenu*)menu { |
| 379 NSMenuItem* result = nil; | 409 NSMenuItem* result = nil; |
| 380 | 410 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 402 | 432 |
| 403 // Look in menu. | 433 // Look in menu. |
| 404 NSMenuItem* item = [MenuWalker itemForKeyEquivalent:event.os_event | 434 NSMenuItem* item = [MenuWalker itemForKeyEquivalent:event.os_event |
| 405 menu:[NSApp mainMenu]]; | 435 menu:[NSApp mainMenu]]; |
| 406 | 436 |
| 407 if (item && [item action] == @selector(commandDispatch:) && [item tag] > 0) | 437 if (item && [item action] == @selector(commandDispatch:) && [item tag] > 0) |
| 408 return [item tag]; | 438 return [item tag]; |
| 409 | 439 |
| 410 // "Close window" doesn't use the |commandDispatch:| mechanism. Menu items | 440 // "Close window" doesn't use the |commandDispatch:| mechanism. Menu items |
| 411 // that do not correspond to IDC_ constants need no special treatment however, | 441 // that do not correspond to IDC_ constants need no special treatment however, |
| 412 // as they can't be blacklisted in |Browser::IsReservedAccelerator()| anyhow. | 442 // as they can't be blacklisted in |Browser::IsReservedCommand()| anyhow. |
| 413 if (item && [item action] == @selector(performClose:)) | 443 if (item && [item action] == @selector(performClose:)) |
| 414 return IDC_CLOSE_WINDOW; | 444 return IDC_CLOSE_WINDOW; |
| 415 | 445 |
| 446 // "Exit" doesn't use the |commandDispatch:| mechanism either. |
| 447 if (item && [item action] == @selector(terminate:)) |
| 448 return IDC_EXIT; |
| 449 |
| 416 // Look in secondary keyboard shortcuts. | 450 // Look in secondary keyboard shortcuts. |
| 417 NSUInteger modifiers = [event.os_event modifierFlags]; | 451 NSUInteger modifiers = [event.os_event modifierFlags]; |
| 418 const bool cmdKey = (modifiers & NSCommandKeyMask) != 0; | 452 const bool cmdKey = (modifiers & NSCommandKeyMask) != 0; |
| 419 const bool shiftKey = (modifiers & NSShiftKeyMask) != 0; | 453 const bool shiftKey = (modifiers & NSShiftKeyMask) != 0; |
| 420 const bool cntrlKey = (modifiers & NSControlKeyMask) != 0; | 454 const bool cntrlKey = (modifiers & NSControlKeyMask) != 0; |
| 421 const bool optKey = (modifiers & NSAlternateKeyMask) != 0; | 455 const bool optKey = (modifiers & NSAlternateKeyMask) != 0; |
| 422 const int keyCode = [event.os_event keyCode]; | 456 const int keyCode = [event.os_event keyCode]; |
| 423 | 457 |
| 424 int cmdNum = CommandForWindowKeyboardShortcut( | 458 int cmdNum = CommandForWindowKeyboardShortcut( |
| 425 cmdKey, shiftKey, cntrlKey, optKey, keyCode); | 459 cmdKey, shiftKey, cntrlKey, optKey, keyCode); |
| 426 if (cmdNum != -1) | 460 if (cmdNum != -1) |
| 427 return cmdNum; | 461 return cmdNum; |
| 428 | 462 |
| 429 cmdNum = CommandForBrowserKeyboardShortcut( | 463 cmdNum = CommandForBrowserKeyboardShortcut( |
| 430 cmdKey, shiftKey, cntrlKey, optKey, keyCode); | 464 cmdKey, shiftKey, cntrlKey, optKey, keyCode); |
| 431 if (cmdNum != -1) | 465 if (cmdNum != -1) |
| 432 return cmdNum; | 466 return cmdNum; |
| 433 | 467 |
| 434 return -1; | 468 return -1; |
| 435 } | 469 } |
| 436 | 470 |
| 471 bool BrowserWindowCocoa::HandleKeyboardEventInternal(NSEvent* event) { |
| 472 ChromeEventProcessingWindow* event_window = |
| 473 static_cast<ChromeEventProcessingWindow*>(window_); |
| 474 DCHECK([event_window isKindOfClass:[ChromeEventProcessingWindow class]]); |
| 475 |
| 476 // Do not fire shortcuts on key up. |
| 477 if ([event type] == NSKeyDown) { |
| 478 // Send the event to the menu before sending it to the browser/window |
| 479 // shortcut handling, so that if a user configures cmd-left to mean |
| 480 // "previous tab", it takes precedence over the built-in "history back" |
| 481 // binding. Other than that, the |redispatchEvent| call would take care of |
| 482 // invoking the original menu item shortcut as well. |
| 483 if ([[NSApp mainMenu] performKeyEquivalent:event]) |
| 484 return true; |
| 485 |
| 486 if ([event_window handleExtraBrowserKeyboardShortcut:event]) |
| 487 return true; |
| 488 |
| 489 if ([event_window handleExtraWindowKeyboardShortcut:event]) |
| 490 return true; |
| 491 } |
| 492 |
| 493 return [event_window redispatchEvent:event]; |
| 494 } |
| 495 |
| 437 void BrowserWindowCocoa::ShowCreateShortcutsDialog(TabContents* tab_contents) { | 496 void BrowserWindowCocoa::ShowCreateShortcutsDialog(TabContents* tab_contents) { |
| 438 NOTIMPLEMENTED(); | 497 NOTIMPLEMENTED(); |
| 439 } | 498 } |
| 440 | 499 |
| 441 void BrowserWindowCocoa::Observe(NotificationType type, | 500 void BrowserWindowCocoa::Observe(NotificationType type, |
| 442 const NotificationSource& source, | 501 const NotificationSource& source, |
| 443 const NotificationDetails& details) { | 502 const NotificationDetails& details) { |
| 444 switch (type.value) { | 503 switch (type.value) { |
| 445 // Only the key window gets a direct toggle from the menu. | 504 // Only the key window gets a direct toggle from the menu. |
| 446 // Other windows hear about it from the notification. | 505 // Other windows hear about it from the notification. |
| 447 case NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED: | 506 case NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED: |
| 448 [controller_ updateBookmarkBarVisibilityWithAnimation:YES]; | 507 [controller_ updateBookmarkBarVisibilityWithAnimation:YES]; |
| 449 break; | 508 break; |
| 450 default: | 509 default: |
| 451 NOTREACHED(); // we don't ask for anything else! | 510 NOTREACHED(); // we don't ask for anything else! |
| 452 break; | 511 break; |
| 453 } | 512 } |
| 454 } | 513 } |
| 455 | 514 |
| 456 void BrowserWindowCocoa::DestroyBrowser() { | 515 void BrowserWindowCocoa::DestroyBrowser() { |
| 457 [controller_ destroyBrowser]; | 516 [controller_ destroyBrowser]; |
| 458 | 517 |
| 459 // at this point the controller is dead (autoreleased), so | 518 // at this point the controller is dead (autoreleased), so |
| 460 // make sure we don't try to reference it any more. | 519 // make sure we don't try to reference it any more. |
| 461 } | 520 } |
| OLD | NEW |