| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/cocoa/browser_window_controller.h" | 5 #import "chrome/browser/cocoa/browser_window_controller.h" |
| 6 | 6 |
| 7 #include <Carbon/Carbon.h> | 7 #include <Carbon/Carbon.h> |
| 8 | 8 |
| 9 #include "app/l10n_util_mac.h" | 9 #include "app/l10n_util_mac.h" |
| 10 #include "base/mac_util.h" | 10 #include "base/mac_util.h" |
| (...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 // Identify the actual BWC to which the command should be dispatched. It might | 911 // Identify the actual BWC to which the command should be dispatched. It might |
| 912 // belong to a background window, yet this controller gets it because it is | 912 // belong to a background window, yet this controller gets it because it is |
| 913 // the foreground window's controller and thus in the responder chain. Some | 913 // the foreground window's controller and thus in the responder chain. Some |
| 914 // senders don't have this problem (for example, menus only operate on the | 914 // senders don't have this problem (for example, menus only operate on the |
| 915 // foreground window), so this is only an issue for senders that are part of | 915 // foreground window), so this is only an issue for senders that are part of |
| 916 // windows. | 916 // windows. |
| 917 BrowserWindowController* targetController = self; | 917 BrowserWindowController* targetController = self; |
| 918 if ([sender respondsToSelector:@selector(window)]) | 918 if ([sender respondsToSelector:@selector(window)]) |
| 919 targetController = [[sender window] windowController]; | 919 targetController = [[sender window] windowController]; |
| 920 DCHECK([targetController isKindOfClass:[BrowserWindowController class]]); | 920 DCHECK([targetController isKindOfClass:[BrowserWindowController class]]); |
| 921 NSInteger tag = [sender tag]; | |
| 922 switch (tag) { | |
| 923 case IDC_RELOAD: | |
| 924 if ([sender isKindOfClass:[NSButton class]]) { | |
| 925 // We revert the bar when the reload button is pressed, but don't when | |
| 926 // Command+r is pressed (Issue 15464). Unlike the event handler function | |
| 927 // for Windows (ToolbarView::ButtonPressed()), this function handles | |
| 928 // both reload button press event and Command+r press event. Thus the | |
| 929 // 'isKindofClass' check is necessary. | |
| 930 [targetController locationBarBridge]->Revert(); | |
| 931 } | |
| 932 NSUInteger modifierFlags = [[NSApp currentEvent] modifierFlags]; | |
| 933 if (modifierFlags & NSShiftKeyMask) { | |
| 934 tag = IDC_RELOAD_IGNORING_CACHE; | |
| 935 } | |
| 936 break; | |
| 937 } | |
| 938 DCHECK(targetController->browser_.get()); | 921 DCHECK(targetController->browser_.get()); |
| 939 targetController->browser_->ExecuteCommand(tag); | 922 targetController->browser_->ExecuteCommand([sender tag]); |
| 940 } | 923 } |
| 941 | 924 |
| 942 // Same as |-commandDispatch:|, but executes commands using a disposition | 925 // Same as |-commandDispatch:|, but executes commands using a disposition |
| 943 // determined by the key flags. If the window is in the background and the | 926 // determined by the key flags. If the window is in the background and the |
| 944 // command key is down, ignore the command key, but process any other modifiers. | 927 // command key is down, ignore the command key, but process any other modifiers. |
| 945 - (void)commandDispatchUsingKeyModifiers:(id)sender { | 928 - (void)commandDispatchUsingKeyModifiers:(id)sender { |
| 946 DCHECK(sender); | 929 DCHECK(sender); |
| 947 // See comment above for why we do this. | 930 // See comment above for why we do this. |
| 948 BrowserWindowController* targetController = self; | 931 BrowserWindowController* targetController = self; |
| 949 if ([sender respondsToSelector:@selector(window)]) | 932 if ([sender respondsToSelector:@selector(window)]) |
| 950 targetController = [[sender window] windowController]; | 933 targetController = [[sender window] windowController]; |
| 951 DCHECK([targetController isKindOfClass:[BrowserWindowController class]]); | 934 DCHECK([targetController isKindOfClass:[BrowserWindowController class]]); |
| 952 NSInteger tag = [sender tag]; | 935 NSInteger command = [sender tag]; |
| 953 DCHECK(targetController->browser_.get()); | |
| 954 NSUInteger modifierFlags = [[NSApp currentEvent] modifierFlags]; | 936 NSUInteger modifierFlags = [[NSApp currentEvent] modifierFlags]; |
| 937 if ((command == IDC_RELOAD) && (modifierFlags & NSShiftKeyMask)) { |
| 938 command = IDC_RELOAD_IGNORING_CACHE; |
| 939 // Mask off shift so it isn't interpreted as affecting the disposition |
| 940 // below. |
| 941 modifierFlags &= ~NSShiftKeyMask; |
| 942 } |
| 955 if (![[sender window] isMainWindow]) { | 943 if (![[sender window] isMainWindow]) { |
| 956 // Remove the command key from the flags, it means "keep the window in | 944 // Remove the command key from the flags, it means "keep the window in |
| 957 // the background" in this case. | 945 // the background" in this case. |
| 958 modifierFlags &= ~NSCommandKeyMask; | 946 modifierFlags &= ~NSCommandKeyMask; |
| 959 } | 947 } |
| 960 targetController->browser_->ExecuteCommandWithDisposition(tag, | 948 WindowOpenDisposition disposition = |
| 961 event_utils::WindowOpenDispositionFromNSEventWithFlags( | 949 event_utils::WindowOpenDispositionFromNSEventWithFlags( |
| 962 [NSApp currentEvent], modifierFlags)); | 950 [NSApp currentEvent], modifierFlags); |
| 951 switch (command) { |
| 952 case IDC_BACK: |
| 953 case IDC_FORWARD: |
| 954 case IDC_RELOAD: |
| 955 case IDC_RELOAD_IGNORING_CACHE: |
| 956 if (disposition == CURRENT_TAB) { |
| 957 // Forcibly reset the location bar, since otherwise it won't discard any |
| 958 // ongoing user edits, since it doesn't realize this is a user-initiated |
| 959 // action. |
| 960 [targetController locationBarBridge]->Revert(); |
| 961 } |
| 962 } |
| 963 DCHECK(targetController->browser_.get()); |
| 964 targetController->browser_->ExecuteCommandWithDisposition(command, |
| 965 disposition); |
| 963 } | 966 } |
| 964 | 967 |
| 965 // Called when another part of the internal codebase needs to execute a | 968 // Called when another part of the internal codebase needs to execute a |
| 966 // command. | 969 // command. |
| 967 - (void)executeCommand:(int)command { | 970 - (void)executeCommand:(int)command { |
| 968 if (browser_->command_updater()->IsCommandEnabled(command)) | 971 if (browser_->command_updater()->IsCommandEnabled(command)) |
| 969 browser_->ExecuteCommand(command); | 972 browser_->ExecuteCommand(command); |
| 970 } | 973 } |
| 971 | 974 |
| 972 // StatusBubble delegate method: tell the status bubble how far above the bottom | 975 // StatusBubble delegate method: tell the status bubble how far above the bottom |
| (...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1857 | 1860 |
| 1858 - (BOOL)supportsBookmarkBar { | 1861 - (BOOL)supportsBookmarkBar { |
| 1859 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; | 1862 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
| 1860 } | 1863 } |
| 1861 | 1864 |
| 1862 - (BOOL)isNormalWindow { | 1865 - (BOOL)isNormalWindow { |
| 1863 return browser_->type() == Browser::TYPE_NORMAL; | 1866 return browser_->type() == Browser::TYPE_NORMAL; |
| 1864 } | 1867 } |
| 1865 | 1868 |
| 1866 @end // @implementation BrowserWindowController(WindowType) | 1869 @end // @implementation BrowserWindowController(WindowType) |
| OLD | NEW |