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

Side by Side Diff: chrome/browser/cocoa/browser_window_controller.mm

Issue 164547: Mac: make save/open dialogs operate as tab-modal sheets.... Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Painfully (but hopefully correctly) merged ToT. 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 | Annotate | Revision Log
OLDNEW
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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 190 }
191 [[[self window] contentView] addSubview:[toolbarController_ view]]; 191 [[[self window] contentView] addSubview:[toolbarController_ view]];
192 192
193 // Create a sub-controller for the bookmark bar. 193 // Create a sub-controller for the bookmark bar.
194 bookmarkBarController_.reset( 194 bookmarkBarController_.reset(
195 [[BookmarkBarController alloc] 195 [[BookmarkBarController alloc]
196 initWithBrowser:browser_.get() 196 initWithBrowser:browser_.get()
197 initialWidth:NSWidth([[[self window] contentView] frame]) 197 initialWidth:NSWidth([[[self window] contentView] frame])
198 compressDelegate:toolbarController_.get() 198 compressDelegate:toolbarController_.get()
199 resizeDelegate:self 199 resizeDelegate:self
200 urlDelegate:self]); 200 urlDelegate:self
201 commands:browser->command_updater()]);
201 202
202 // Add bookmark bar to the view hierarchy. This also triggers the 203 // Add bookmark bar to the view hierarchy. This also triggers the
203 // nib load. The bookmark bar is defined (in the nib) to be 204 // nib load. The bookmark bar is defined (in the nib) to be
204 // bottom-aligned to it's parent view (among other things), so 205 // bottom-aligned to it's parent view (among other things), so
205 // position and resize properties don't need to be set. 206 // position and resize properties don't need to be set.
206 [[[self window] contentView] addSubview:[bookmarkBarController_ view] 207 [[[self window] contentView] addSubview:[bookmarkBarController_ view]
207 positioned:NSWindowBelow 208 positioned:NSWindowBelow
208 relativeTo:[toolbarController_ view]]; 209 relativeTo:[toolbarController_ view]];
209 210
210 // Disable the bookmark bar if this window doesn't support them. 211 // Disable the bookmark bar if this window doesn't support them.
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 if (frame.size.height == height) 503 if (frame.size.height == height)
503 return; 504 return;
504 505
505 frame.size.height = height; 506 frame.size.height = height;
506 // TODO(rohitrao): Determine if calling setFrame: twice is bad. 507 // TODO(rohitrao): Determine if calling setFrame: twice is bad.
507 [view setFrame:frame]; 508 [view setFrame:frame];
508 [self layoutSubviews]; 509 [self layoutSubviews];
509 } 510 }
510 511
511 // Update a toggle state for an NSMenuItem if modified. 512 // Update a toggle state for an NSMenuItem if modified.
512 // Take care to insure |item| looks like a NSMenuItem. 513 // Take care to ensure |item| looks like a NSMenuItem.
513 // Called by validateUserInterfaceItem:. 514 // Called by validateUserInterfaceItem:.
514 - (void)updateToggleStateWithTag:(NSInteger)tag forItem:(id)item { 515 - (void)updateToggleStateWithTag:(NSInteger)tag forItem:(id)item {
515 if (![item respondsToSelector:@selector(state)] || 516 if (![item respondsToSelector:@selector(state)] ||
516 ![item respondsToSelector:@selector(setState:)]) 517 ![item respondsToSelector:@selector(setState:)])
517 return; 518 return;
518 519
519 // On Windows this logic happens in bookmark_bar_view.cc. On the 520 // On Windows this logic happens in bookmark_bar_view.cc. On the
520 // Mac we're a lot more MVC happy so we've moved it into a 521 // Mac we're a lot more MVC happy so we've moved it into a
521 // controller. To be clear, this simply updates the menu item; it 522 // controller. To be clear, this simply updates the menu item; it
522 // does not display the bookmark bar itself. 523 // does not display the bookmark bar itself.
523 if (tag == IDC_SHOW_BOOKMARK_BAR) { 524 if (tag == IDC_SHOW_BOOKMARK_BAR) {
524 bool toggled = windowShim_->IsBookmarkBarVisible(); 525 bool toggled = windowShim_->IsBookmarkBarVisible();
525 NSInteger oldState = [item state]; 526 NSInteger oldState = [item state];
526 NSInteger newState = toggled ? NSOnState : NSOffState; 527 NSInteger newState = toggled ? NSOnState : NSOffState;
527 if (oldState != newState) 528 if (oldState != newState)
528 [item setState:newState]; 529 [item setState:newState];
530 return;
529 } 531 }
530 532
531 // Update the checked/Unchecked state of items in the encoding menu. 533 // Update the checked/Unchecked state of items in the encoding menu.
532 // On Windows, this logic is part of |EncodingMenuModel| in 534 // On Windows, this logic is part of |EncodingMenuModel| in
533 // browser/views/toolbar_view.h. 535 // browser/views/toolbar_view.h.
534 EncodingMenuController encoding_controller; 536 EncodingMenuController encoding_controller;
535 if (encoding_controller.DoesCommandBelongToEncodingMenu(tag)) { 537 if (encoding_controller.DoesCommandBelongToEncodingMenu(tag)) {
536 DCHECK(browser_.get()); 538 DCHECK(browser_.get());
537 Profile *profile = browser_->profile(); 539 Profile *profile = browser_->profile();
538 DCHECK(profile); 540 DCHECK(profile);
539 TabContents* current_tab = browser_->GetSelectedTabContents(); 541 TabContents* current_tab = browser_->GetSelectedTabContents();
540 if (!current_tab) { 542 if (!current_tab)
541 return; 543 return;
542 } 544
543 const std::string encoding = current_tab->encoding(); 545 const std::string encoding = current_tab->encoding();
544
545 bool toggled = encoding_controller.IsItemChecked(profile, encoding, tag); 546 bool toggled = encoding_controller.IsItemChecked(profile, encoding, tag);
546 NSInteger oldState = [item state]; 547 NSInteger oldState = [item state];
547 NSInteger newState = toggled ? NSOnState : NSOffState; 548 NSInteger newState = toggled ? NSOnState : NSOffState;
548 if (oldState != newState) 549 if (oldState != newState)
549 [item setState:newState]; 550 [item setState:newState];
550 } 551 }
551 } 552 }
552 553
553 - (BOOL)supportsFullscreen { 554 - (BOOL)supportsFullscreen {
554 // TODO(avi, thakis): GTMWindowSheetController has no api to move 555 // TODO(avi, thakis): GTMWindowSheetController has no api to move
555 // tabsheets between windows. Until then, we have to prevent having to 556 // tabsheets between windows. Until then, we have to prevent having to
556 // move a tabsheet between windows, e.g. no fullscreen toggling 557 // move a tabsheet between windows, e.g. no fullscreen toggling
557 NSArray* a = [[tabStripController_ sheetController] viewsWithAttachedSheets]; 558 NSArray* a = [[tabStripController_ sheetController] viewsWithAttachedSheets];
558 return [a count] == 0; 559 return [a count] == 0;
559 } 560 }
560 561
561 // Called to validate menu and toolbar items when this window is key. All the 562 // Called to validate menu and toolbar items when this window is key. All the
562 // items we care about have been set with the |commandDispatch:| action and 563 // items we care about have been set with the |commandDispatch:| action and
563 // a target of FirstResponder in IB. If it's not one of those, let it 564 // a target of FirstResponder in IB. If it's not one of those, let it
564 // continue up the responder chain to be handled elsewhere. We pull out the 565 // continue up the responder chain to be handled elsewhere. We pull out the
565 // tag as the cross-platform constant to differentiate and dispatch the 566 // tag as the cross-platform constant to differentiate and dispatch the
566 // various commands. 567 // various commands.
567 // NOTE: we might have to handle state for app-wide menu items, 568 // NOTE: we might have to handle state for app-wide menu items,
568 // although we could cheat and directly ask the app controller if our 569 // although we could cheat and directly ask the app controller if our
569 // command_updater doesn't support the command. This may or may not be an issue, 570 // command_updater doesn't support the command. This may or may not be an issue,
570 // too early to tell. 571 // too early to tell.
571 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { 572 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item {
572 SEL action = [item action]; 573 SEL action = [item action];
573 BOOL enable = NO; 574 BOOL enable = NO;
575 NSInteger tag = [item tag];
574 if (action == @selector(commandDispatch:)) { 576 if (action == @selector(commandDispatch:)) {
575 NSInteger tag = [item tag];
576 if (browser_->command_updater()->SupportsCommand(tag)) { 577 if (browser_->command_updater()->SupportsCommand(tag)) {
577 // Generate return value (enabled state) 578 // Generate return value (enabled state)
578 enable = browser_->command_updater()->IsCommandEnabled(tag) ? YES : NO; 579 enable = browser_->command_updater()->IsCommandEnabled(tag) ? YES : NO;
579 switch (tag) { 580 switch (tag) {
580 case IDC_CLOSE_TAB: 581 case IDC_CLOSE_TAB:
581 // Disable "close tab" if we're not the key window or if there's only 582 // Disable "close tab" if we're not the key window or if there's only
582 // one tab. 583 // one tab.
583 enable &= [self numberOfTabs] > 1 && [[self window] isKeyWindow]; 584 enable &= [self numberOfTabs] > 1 && [[self window] isKeyWindow];
584 break; 585 break;
585 case IDC_RESTORE_TAB: 586 case IDC_RESTORE_TAB:
586 // We have to ask the Browser manually if we can restore. The 587 // We have to ask the Browser manually if we can restore. The
587 // command updater doesn't know. 588 // command updater doesn't know.
588 enable &= browser_->CanRestoreTab(); 589 enable &= browser_->CanRestoreTab() ? YES : NO;
589 break; 590 break;
590 case IDC_FULLSCREEN: 591 case IDC_FULLSCREEN:
591 enable &= [self supportsFullscreen]; 592 enable &= [self supportsFullscreen];
592 break; 593 break;
594 default:
595 // Special handling for the contents of the encoding menu; we
596 // enable/disable them en masse.
597 EncodingMenuController encoding_controller;
598 if (encoding_controller.DoesCommandBelongToEncodingMenu(tag)) {
599 enable &= browser_->command_updater()->IsCommandEnabled(
600 IDC_ENCODING_MENU_CONTENTS) ? YES : NO;
601 }
593 } 602 }
594 603
595 // If the item is toggleable, find its toggle state and 604 // If the item is toggleable, find its toggle state and
596 // try to update it. This is a little awkward, but the alternative is 605 // try to update it. This is a little awkward, but the alternative is
597 // to check after a commandDispatch, which seems worse. 606 // to check after a commandDispatch, which seems worse.
598 [self updateToggleStateWithTag:tag forItem:item]; 607 [self updateToggleStateWithTag:tag forItem:item];
599 } 608 }
609 } else {
610 // Use the command updater for enabled state anyway.
611 switch (tag) {
612 case IDC_EMAIL_PAGE_LOCATION:
613 case IDC_PRINT_PAGE_SETUP:
614 case IDC_PRINT:
615 enable = browser_->command_updater()->IsCommandEnabled(tag) ? YES : NO;
616 break;
617 default:
618 // This line intentionally left blank.
619 break;
620 }
600 } 621 }
601 return enable; 622 return enable;
602 } 623 }
603 624
604 // Called when the user picks a menu or toolbar item when this window is key. 625 // Called when the user picks a menu or toolbar item when this window is key.
605 // Calls through to the browser object to execute the command. This assumes that 626 // Calls through to the browser object to execute the command. This assumes that
606 // the command is supported and doesn't check, otherwise it would have been 627 // the command is supported and doesn't check, otherwise it would have been
607 // disabled in the UI in validateUserInterfaceItem:. 628 // disabled in the UI in validateUserInterfaceItem:.
608 - (void)commandDispatch:(id)sender { 629 - (void)commandDispatch:(id)sender {
609 NSInteger tag = [sender tag]; 630 NSInteger tag = [sender tag];
(...skipping 22 matching lines...) Expand all
632 if (browser_->command_updater()->IsCommandEnabled(command)) 653 if (browser_->command_updater()->IsCommandEnabled(command))
633 browser_->ExecuteCommand(command); 654 browser_->ExecuteCommand(command);
634 } 655 }
635 656
636 // StatusBubble delegate method: tell the status bubble how far above the bottom 657 // StatusBubble delegate method: tell the status bubble how far above the bottom
637 // of the window it should position itself. 658 // of the window it should position itself.
638 - (float)verticalOffsetForStatusBubble { 659 - (float)verticalOffsetForStatusBubble {
639 return verticalOffsetForStatusBubble_; 660 return verticalOffsetForStatusBubble_;
640 } 661 }
641 662
663 - (ToolbarController*)toolbarController {
664 return toolbarController_.get();
665 }
666
667 - (InfoBarContainerController*)infoBarContainerController {
668 return infoBarContainerController_.get();
669 }
670
642 - (GTMWindowSheetController*)sheetController { 671 - (GTMWindowSheetController*)sheetController {
643 return [tabStripController_ sheetController]; 672 return [tabStripController_ sheetController];
644 } 673 }
645 674
646 - (LocationBar*)locationBar { 675 - (LocationBar*)locationBar {
647 return [toolbarController_ locationBar]; 676 return [toolbarController_ locationBar];
648 } 677 }
649 678
650 - (StatusBubble*)statusBubble { 679 - (StatusBubble*)statusBubble {
651 return statusBubble_.get(); 680 return statusBubble_.get();
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 windowPreferences->SetInteger(L"top", bounds.y()); 1192 windowPreferences->SetInteger(L"top", bounds.y());
1164 windowPreferences->SetInteger(L"right", bounds.right()); 1193 windowPreferences->SetInteger(L"right", bounds.right());
1165 windowPreferences->SetInteger(L"bottom", bounds.bottom()); 1194 windowPreferences->SetInteger(L"bottom", bounds.bottom());
1166 windowPreferences->SetBoolean(L"maximized", false); 1195 windowPreferences->SetBoolean(L"maximized", false);
1167 windowPreferences->SetBoolean(L"always_on_top", false); 1196 windowPreferences->SetBoolean(L"always_on_top", false);
1168 } 1197 }
1169 1198
1170 - (NSRect)window:(NSWindow*)window 1199 - (NSRect)window:(NSWindow*)window
1171 willPositionSheet:(NSWindow*)sheet 1200 willPositionSheet:(NSWindow*)sheet
1172 usingRect:(NSRect)defaultSheetRect { 1201 usingRect:(NSRect)defaultSheetRect {
1202 #if 1
1173 // Any sheet should come from right above the visible content area. 1203 // Any sheet should come from right above the visible content area.
1174 NSRect toolbarFrame = [[toolbarController_ view] frame]; 1204 NSRect toolbarFrame = [[toolbarController_ view] frame];
1175 NSRect infobarFrame = [[infoBarContainerController_ view] frame]; 1205 NSRect infobarFrame = [[infoBarContainerController_ view] frame];
1176 defaultSheetRect.origin.y = toolbarFrame.origin.y - infobarFrame.size.height; 1206 defaultSheetRect.origin.y = toolbarFrame.origin.y - infobarFrame.size.height;
1177 1207 #elif 0
1208 // FIXME(viettrungluu): I had this, which I think is better than the above.
1209 // This hangs them below the toolbar (incl. bookmark bar), which is illogical
1210 // but a bit more normal-looking (not quite, since the shading doesn't match).
1211 NSView* tabContentView = [self tabContentArea];
1212 NSRect tabContentFrame = [tabContentView frame];
1213 defaultSheetRect.origin.y = tabContentFrame.origin.y +
1214 tabContentFrame.size.height;
1215 #else
1216 // This was the original, hanging window-modal sheets off the title bar, which
1217 // was logical but weird-looking.
1218 NSRect windowFrame = [window frame];
1219 defaultSheetRect.origin.y = windowFrame.size.height - 10;
1220 #endif
1178 return defaultSheetRect; 1221 return defaultSheetRect;
1179 } 1222 }
1180 1223
1181 // Undocumented method for multi-touch gestures in 10.5. Future OS's will 1224 // Undocumented method for multi-touch gestures in 10.5. Future OS's will
1182 // likely add a public API, but the worst that will happen is that this will 1225 // likely add a public API, but the worst that will happen is that this will
1183 // turn into dead code and just won't get called. 1226 // turn into dead code and just won't get called.
1184 - (void)swipeWithEvent:(NSEvent*)event { 1227 - (void)swipeWithEvent:(NSEvent*)event {
1185 // Map forwards and backwards to history; left is positive, right is negative. 1228 // Map forwards and backwards to history; left is positive, right is negative.
1186 unsigned int command = 0; 1229 unsigned int command = 0;
1187 if ([event deltaX] > 0.5) 1230 if ([event deltaX] > 0.5)
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 provider->GetNSColor(BrowserThemeProvider::COLOR_TOOLBAR); 1512 provider->GetNSColor(BrowserThemeProvider::COLOR_TOOLBAR);
1470 [theme setValue:toolbarBackgroundColor 1513 [theme setValue:toolbarBackgroundColor
1471 forAttribute:@"backgroundColor" 1514 forAttribute:@"backgroundColor"
1472 style:GTMThemeStyleToolBar 1515 style:GTMThemeStyleToolBar
1473 state:GTMThemeStateActiveWindow]; 1516 state:GTMThemeStateActiveWindow];
1474 1517
1475 return theme; 1518 return theme;
1476 } 1519 }
1477 @end 1520 @end
1478 1521
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/browser_window_controller.h ('k') | chrome/browser/cocoa/constrained_window_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698