| 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 <Carbon/Carbon.h> | 5 #include <Carbon/Carbon.h> |
| 6 | 6 |
| 7 #include "base/mac_util.h" | 7 #include "base/mac_util.h" |
| 8 #include "base/scoped_nsdisable_screen_updates.h" | 8 #include "base/scoped_nsdisable_screen_updates.h" |
| 9 #import "base/scoped_nsobject.h" | 9 #import "base/scoped_nsobject.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 | 542 |
| 543 - (BOOL)supportsFullscreen { | 543 - (BOOL)supportsFullscreen { |
| 544 // TODO(avi, thakis): GTMWindowSheetController has no api to move | 544 // TODO(avi, thakis): GTMWindowSheetController has no api to move |
| 545 // tabsheets between windows. Until then, we have to prevent having to | 545 // tabsheets between windows. Until then, we have to prevent having to |
| 546 // move a tabsheet between windows, e.g. no fullscreen toggling | 546 // move a tabsheet between windows, e.g. no fullscreen toggling |
| 547 NSArray* a = [[tabStripController_ sheetController] viewsWithAttachedSheets]; | 547 NSArray* a = [[tabStripController_ sheetController] viewsWithAttachedSheets]; |
| 548 return [a count] == 0; | 548 return [a count] == 0; |
| 549 } | 549 } |
| 550 | 550 |
| 551 // Called to validate menu and toolbar items when this window is key. All the | 551 // Called to validate menu and toolbar items when this window is key. All the |
| 552 // items we care about have been set with the |commandDispatch:| action and | 552 // items we care about have been set with the |-commandDispatch:| or |
| 553 // a target of FirstResponder in IB. If it's not one of those, let it | 553 // |-commandDispatchUsingKeyModifiers:| actions and a target of FirstResponder |
| 554 // continue up the responder chain to be handled elsewhere. We pull out the | 554 // in IB. If it's not one of those, let it continue up the responder chain to be |
| 555 // tag as the cross-platform constant to differentiate and dispatch the | 555 // handled elsewhere. We pull out the tag as the cross-platform constant to |
| 556 // various commands. | 556 // differentiate and dispatch the various commands. |
| 557 // NOTE: we might have to handle state for app-wide menu items, | 557 // NOTE: we might have to handle state for app-wide menu items, |
| 558 // although we could cheat and directly ask the app controller if our | 558 // although we could cheat and directly ask the app controller if our |
| 559 // command_updater doesn't support the command. This may or may not be an issue, | 559 // command_updater doesn't support the command. This may or may not be an issue, |
| 560 // too early to tell. | 560 // too early to tell. |
| 561 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { | 561 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { |
| 562 SEL action = [item action]; | 562 SEL action = [item action]; |
| 563 BOOL enable = NO; | 563 BOOL enable = NO; |
| 564 if (action == @selector(commandDispatch:)) { | 564 if (action == @selector(commandDispatch:) || |
| 565 action == @selector(commandDispatchUsingKeyModifiers:)) { |
| 565 NSInteger tag = [item tag]; | 566 NSInteger tag = [item tag]; |
| 566 if (browser_->command_updater()->SupportsCommand(tag)) { | 567 if (browser_->command_updater()->SupportsCommand(tag)) { |
| 567 // Generate return value (enabled state) | 568 // Generate return value (enabled state) |
| 568 enable = browser_->command_updater()->IsCommandEnabled(tag) ? YES : NO; | 569 enable = browser_->command_updater()->IsCommandEnabled(tag) ? YES : NO; |
| 569 switch (tag) { | 570 switch (tag) { |
| 570 case IDC_CLOSE_TAB: | 571 case IDC_CLOSE_TAB: |
| 571 // Disable "close tab" if we're not the key window or if there's only | 572 // Disable "close tab" if we're not the key window or if there's only |
| 572 // one tab. | 573 // one tab. |
| 573 enable &= [self numberOfTabs] > 1 && [[self window] isKeyWindow]; | 574 enable &= [self numberOfTabs] > 1 && [[self window] isKeyWindow]; |
| 574 break; | 575 break; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 591 return enable; | 592 return enable; |
| 592 } | 593 } |
| 593 | 594 |
| 594 // Called when the user picks a menu or toolbar item when this window is key. | 595 // Called when the user picks a menu or toolbar item when this window is key. |
| 595 // Calls through to the browser object to execute the command. This assumes that | 596 // Calls through to the browser object to execute the command. This assumes that |
| 596 // the command is supported and doesn't check, otherwise it would have been | 597 // the command is supported and doesn't check, otherwise it would have been |
| 597 // disabled in the UI in validateUserInterfaceItem:. | 598 // disabled in the UI in validateUserInterfaceItem:. |
| 598 - (void)commandDispatch:(id)sender { | 599 - (void)commandDispatch:(id)sender { |
| 599 NSInteger tag = [sender tag]; | 600 NSInteger tag = [sender tag]; |
| 600 switch (tag) { | 601 switch (tag) { |
| 601 case IDC_FORWARD: | |
| 602 case IDC_BACK: | |
| 603 // For this, we need to check the key flags to figure out where to open | |
| 604 // the history item. Note that |Revert()| isn't needed, since any | |
| 605 // navigation in the current tab will reset the location bar's contents. | |
| 606 browser_->ExecuteCommandWithDisposition(tag, | |
| 607 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent])); | |
| 608 return; | |
| 609 case IDC_RELOAD: | 602 case IDC_RELOAD: |
| 610 if ([sender isKindOfClass:[NSButton class]]) { | 603 if ([sender isKindOfClass:[NSButton class]]) { |
| 611 // We revert the bar when the reload button is pressed, but don't when | 604 // We revert the bar when the reload button is pressed, but don't when |
| 612 // Command+r is pressed (Issue 15464). Unlike the event handler function | 605 // Command+r is pressed (Issue 15464). Unlike the event handler function |
| 613 // for Windows (ToolbarView::ButtonPressed()), this function handles | 606 // for Windows (ToolbarView::ButtonPressed()), this function handles |
| 614 // both reload button press event and Command+r press event. Thus the | 607 // both reload button press event and Command+r press event. Thus the |
| 615 // 'isKindofClass' check is necessary. | 608 // 'isKindofClass' check is necessary. |
| 616 [self locationBar]->Revert(); | 609 [self locationBar]->Revert(); |
| 617 } | 610 } |
| 618 break; | 611 break; |
| 619 } | 612 } |
| 620 browser_->ExecuteCommand(tag); | 613 browser_->ExecuteCommand(tag); |
| 621 } | 614 } |
| 622 | 615 |
| 616 // Same as |-commandDispatch:|, but executes commands using a disposition |
| 617 // determined by the key flags. |
| 618 - (void)commandDispatchUsingKeyModifiers:(id)sender { |
| 619 NSInteger tag = [sender tag]; |
| 620 browser_->ExecuteCommandWithDisposition(tag, |
| 621 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent])); |
| 622 } |
| 623 |
| 623 // Called when another part of the internal codebase needs to execute a | 624 // Called when another part of the internal codebase needs to execute a |
| 624 // command. | 625 // command. |
| 625 - (void)executeCommand:(int)command { | 626 - (void)executeCommand:(int)command { |
| 626 if (browser_->command_updater()->IsCommandEnabled(command)) | 627 if (browser_->command_updater()->IsCommandEnabled(command)) |
| 627 browser_->ExecuteCommand(command); | 628 browser_->ExecuteCommand(command); |
| 628 } | 629 } |
| 629 | 630 |
| 630 // StatusBubble delegate method: tell the status bubble how far above the bottom | 631 // StatusBubble delegate method: tell the status bubble how far above the bottom |
| 631 // of the window it should position itself. | 632 // of the window it should position itself. |
| 632 - (float)verticalOffsetForStatusBubble { | 633 - (float)verticalOffsetForStatusBubble { |
| (...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1550 if (frameOverlayInactiveImage) { | 1551 if (frameOverlayInactiveImage) { |
| 1551 [theme setValue:frameOverlayInactiveImage | 1552 [theme setValue:frameOverlayInactiveImage |
| 1552 forAttribute:@"overlay" | 1553 forAttribute:@"overlay" |
| 1553 style:GTMThemeStyleWindow | 1554 style:GTMThemeStyleWindow |
| 1554 state:GTMThemeStateInactiveWindow]; | 1555 state:GTMThemeStateInactiveWindow]; |
| 1555 } | 1556 } |
| 1556 | 1557 |
| 1557 return theme; | 1558 return theme; |
| 1558 } | 1559 } |
| 1559 @end | 1560 @end |
| OLD | NEW |