| 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> |
| 6 |
| 5 #include "base/mac_util.h" | 7 #include "base/mac_util.h" |
| 6 #include "base/scoped_nsdisable_screen_updates.h" | 8 #include "base/scoped_nsdisable_screen_updates.h" |
| 7 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 8 #include "chrome/app/chrome_dll_resource.h" // IDC_* | 10 #include "chrome/app/chrome_dll_resource.h" // IDC_* |
| 9 #include "chrome/browser/browser.h" | 11 #include "chrome/browser/browser.h" |
| 10 #include "chrome/browser/browser_list.h" | 12 #include "chrome/browser/browser_list.h" |
| 11 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/encoding_menu_controller.h" | 14 #include "chrome/browser/encoding_menu_controller.h" |
| 13 #include "chrome/browser/profile.h" | 15 #include "chrome/browser/profile.h" |
| 14 #include "chrome/browser/tab_contents/tab_contents.h" | 16 #include "chrome/browser/tab_contents/tab_contents.h" |
| 15 #include "chrome/browser/tab_contents/tab_contents_view.h" | 17 #include "chrome/browser/tab_contents/tab_contents_view.h" |
| 16 #include "chrome/browser/tabs/tab_strip_model.h" | 18 #include "chrome/browser/tabs/tab_strip_model.h" |
| 17 #import "chrome/browser/cocoa/bookmark_bar_controller.h" | 19 #import "chrome/browser/cocoa/bookmark_bar_controller.h" |
| 18 #import "chrome/browser/cocoa/browser_window_cocoa.h" | 20 #import "chrome/browser/cocoa/browser_window_cocoa.h" |
| 19 #import "chrome/browser/cocoa/browser_window_controller.h" | 21 #import "chrome/browser/cocoa/browser_window_controller.h" |
| 20 #import "chrome/browser/cocoa/download_shelf_controller.h" | 22 #import "chrome/browser/cocoa/download_shelf_controller.h" |
| 21 #import "chrome/browser/cocoa/find_bar_cocoa_controller.h" | 23 #import "chrome/browser/cocoa/find_bar_cocoa_controller.h" |
| 22 #include "chrome/browser/cocoa/find_bar_bridge.h" | 24 #include "chrome/browser/cocoa/find_bar_bridge.h" |
| 25 #import "chrome/browser/cocoa/fullscreen_window.h" |
| 23 #import "chrome/browser/cocoa/status_bubble_mac.h" | 26 #import "chrome/browser/cocoa/status_bubble_mac.h" |
| 24 #import "chrome/browser/cocoa/tab_strip_model_observer_bridge.h" | 27 #import "chrome/browser/cocoa/tab_strip_model_observer_bridge.h" |
| 25 #import "chrome/browser/cocoa/tab_strip_view.h" | 28 #import "chrome/browser/cocoa/tab_strip_view.h" |
| 26 #import "chrome/browser/cocoa/tab_strip_controller.h" | 29 #import "chrome/browser/cocoa/tab_strip_controller.h" |
| 27 #import "chrome/browser/cocoa/tab_view.h" | 30 #import "chrome/browser/cocoa/tab_view.h" |
| 28 #import "chrome/browser/cocoa/toolbar_controller.h" | 31 #import "chrome/browser/cocoa/toolbar_controller.h" |
| 29 #include "chrome/common/pref_service.h" | 32 #include "chrome/common/pref_service.h" |
| 30 | 33 |
| 31 namespace { | 34 namespace { |
| 32 | 35 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 46 | 49 |
| 47 - (void)setBottomCornerRounded:(BOOL)rounded; | 50 - (void)setBottomCornerRounded:(BOOL)rounded; |
| 48 | 51 |
| 49 - (NSRect)_growBoxRect; | 52 - (NSRect)_growBoxRect; |
| 50 @end | 53 @end |
| 51 | 54 |
| 52 | 55 |
| 53 @interface BrowserWindowController(Private) | 56 @interface BrowserWindowController(Private) |
| 54 | 57 |
| 55 - (void)positionToolbar; | 58 - (void)positionToolbar; |
| 59 - (void)removeToolbar; |
| 56 - (void)installIncognitoBadge; | 60 - (void)installIncognitoBadge; |
| 57 | 61 |
| 58 // Leopard's gradient heuristic gets confused by our tabs and makes the title | 62 // Leopard's gradient heuristic gets confused by our tabs and makes the title |
| 59 // gradient jump when creating a tab that is less than a tab width from the | 63 // gradient jump when creating a tab that is less than a tab width from the |
| 60 // right side of the screen. This function disables Leopard's gradient | 64 // right side of the screen. This function disables Leopard's gradient |
| 61 // heuristic. | 65 // heuristic. |
| 62 - (void)fixWindowGradient; | 66 - (void)fixWindowGradient; |
| 63 | 67 |
| 64 // Called by the Notification Center whenever the tabContentArea's | 68 // Called by the Notification Center whenever the tabContentArea's |
| 65 // frame changes. Re-positions the bookmark bar and the find bar. | 69 // frame changes. Re-positions the bookmark bar and the find bar. |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 - (void)addFindBar:(FindBarCocoaController*)findBarCocoaController { | 604 - (void)addFindBar:(FindBarCocoaController*)findBarCocoaController { |
| 601 // Shouldn't call addFindBar twice. | 605 // Shouldn't call addFindBar twice. |
| 602 DCHECK(!findBarCocoaController_.get()); | 606 DCHECK(!findBarCocoaController_.get()); |
| 603 | 607 |
| 604 // Create a controller for the findbar. | 608 // Create a controller for the findbar. |
| 605 findBarCocoaController_.reset([findBarCocoaController retain]); | 609 findBarCocoaController_.reset([findBarCocoaController retain]); |
| 606 [[[self window] contentView] addSubview:[findBarCocoaController_ view]]; | 610 [[[self window] contentView] addSubview:[findBarCocoaController_ view]]; |
| 607 [findBarCocoaController_ positionFindBarView:[self tabContentArea]]; | 611 [findBarCocoaController_ positionFindBarView:[self tabContentArea]]; |
| 608 } | 612 } |
| 609 | 613 |
| 614 // Adjust the UI for fullscreen mode. E.g. when going fullscreen, |
| 615 // remove the toolbar. When stopping fullscreen, add it back in. |
| 616 - (void)adjustUIForFullscreen:(BOOL)fullscreen { |
| 617 if (fullscreen) { |
| 618 // Disable showing of the bookmark bar. This does not toggle the |
| 619 // preference. |
| 620 [bookmarkBarController_ setBookmarkBarEnabled:NO]; |
| 621 // Make room for more content area. |
| 622 [self removeToolbar]; |
| 623 // Hide the menubar, and allow it to un-hide when moving the mouse |
| 624 // to the top of the screen. Does this eliminate the need for an |
| 625 // info bubble describing how to exit fullscreen mode? |
| 626 SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar); |
| 627 } else { |
| 628 SetSystemUIMode(kUIModeNormal, 0); |
| 629 [self positionToolbar]; |
| 630 [bookmarkBarController_ setBookmarkBarEnabled:YES]; |
| 631 } |
| 632 } |
| 633 |
| 634 - (NSWindow*)fullscreenWindow { |
| 635 return [[[FullscreenWindow alloc] initForScreen:[[self window] screen]] |
| 636 autorelease]; |
| 637 } |
| 638 |
| 639 - (void)setFullscreen:(BOOL)fullscreen { |
| 640 fullscreen_ = fullscreen; |
| 641 if (fullscreen) { |
| 642 // Minimize our UI |
| 643 [self adjustUIForFullscreen:fullscreen]; |
| 644 // Move content to a new fullscreen window |
| 645 NSView* content = [[self window] contentView]; |
| 646 fullscreen_window_.reset([[self fullscreenWindow] retain]); |
| 647 [content removeFromSuperview]; |
| 648 [fullscreen_window_ setContentView:content]; |
| 649 [self setWindow:fullscreen_window_.get()]; |
| 650 // Show one window, hide the other. |
| 651 [fullscreen_window_ makeKeyAndOrderFront:self]; |
| 652 [content setNeedsDisplay:YES]; |
| 653 [window_ orderOut:self]; |
| 654 } else { |
| 655 [self adjustUIForFullscreen:fullscreen]; |
| 656 NSView* content = [fullscreen_window_ contentView]; |
| 657 [content removeFromSuperview]; |
| 658 [window_ setContentView:content]; |
| 659 [self setWindow:window_.get()]; |
| 660 [window_ makeKeyAndOrderFront:self]; |
| 661 [content setNeedsDisplay:YES]; |
| 662 [fullscreen_window_ close]; |
| 663 fullscreen_window_.reset(nil); |
| 664 } |
| 665 } |
| 666 |
| 667 - (BOOL)isFullscreen { |
| 668 return fullscreen_; |
| 669 } |
| 670 |
| 610 // Called by the bookmark bar to open a URL. | 671 // Called by the bookmark bar to open a URL. |
| 611 - (void)openBookmarkURL:(const GURL&)url | 672 - (void)openBookmarkURL:(const GURL&)url |
| 612 disposition:(WindowOpenDisposition)disposition { | 673 disposition:(WindowOpenDisposition)disposition { |
| 613 TabContents* tab_contents = browser_->GetSelectedTabContents(); | 674 TabContents* tab_contents = browser_->GetSelectedTabContents(); |
| 614 DCHECK(tab_contents); | 675 DCHECK(tab_contents); |
| 615 tab_contents->OpenURL(url, GURL(), disposition, | 676 tab_contents->OpenURL(url, GURL(), disposition, |
| 616 PageTransition::AUTO_BOOKMARK); | 677 PageTransition::AUTO_BOOKMARK); |
| 617 } | 678 } |
| 618 | 679 |
| 619 - (NSInteger)numberOfTabs { | 680 - (NSInteger)numberOfTabs { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 loadingOnly:(BOOL)loading { | 715 loadingOnly:(BOOL)loading { |
| 655 // Update titles if this is the currently selected tab. | 716 // Update titles if this is the currently selected tab. |
| 656 if (index == browser_->tabstrip_model()->selected_index()) | 717 if (index == browser_->tabstrip_model()->selected_index()) |
| 657 windowShim_->UpdateTitleBar(); | 718 windowShim_->UpdateTitleBar(); |
| 658 } | 719 } |
| 659 | 720 |
| 660 @end | 721 @end |
| 661 | 722 |
| 662 @implementation BrowserWindowController (Private) | 723 @implementation BrowserWindowController (Private) |
| 663 | 724 |
| 664 // Position |toolbarView_| below the tab strip, but not as a sibling. The | 725 // If |add| is YES: |
| 665 // toolbar is part of the window's contentView, mainly because we want the | 726 // Position |toolbarView_| below the tab strip, but not as a |
| 666 // opacity during drags to be the same as the web content. | 727 // sibling. The toolbar is part of the window's contentView, mainly |
| 667 - (void)positionToolbar { | 728 // because we want the opacity during drags to be the same as the web |
| 729 // content. This can be used for either the initial add or a |
| 730 // reposition. |
| 731 // If |add| is NO: |
| 732 // Remove the toolbar from it's parent view (the window's content view). |
| 733 // Called when going fullscreen and we need to minimize UI. |
| 734 - (void)positionOrRemoveToolbar:(BOOL)add { |
| 668 NSView* contentView = [self tabContentArea]; | 735 NSView* contentView = [self tabContentArea]; |
| 669 NSRect contentFrame = [contentView frame]; | 736 NSRect contentFrame = [contentView frame]; |
| 670 NSView* toolbarView = [toolbarController_ view]; | 737 NSView* toolbarView = [toolbarController_ view]; |
| 671 NSRect toolbarFrame = [toolbarView frame]; | 738 NSRect toolbarFrame = [toolbarView frame]; |
| 672 | 739 |
| 673 // Shrink the content area by the height of the toolbar. | 740 // Shrink or grow the content area by the height of the toolbar. |
| 674 contentFrame.size.height -= toolbarFrame.size.height; | 741 if (add) |
| 742 contentFrame.size.height -= toolbarFrame.size.height; |
| 743 else |
| 744 contentFrame.size.height += toolbarFrame.size.height; |
| 675 [contentView setFrame:contentFrame]; | 745 [contentView setFrame:contentFrame]; |
| 676 | 746 |
| 677 // Move the toolbar above the content area, within the window's content view | 747 if (add) { |
| 678 // (as opposed to the tab strip, which is a sibling). | 748 // Move the toolbar above the content area, within the window's content view |
| 679 toolbarFrame.origin.y = NSMaxY(contentFrame); | 749 // (as opposed to the tab strip, which is a sibling). |
| 680 toolbarFrame.origin.x = 0; | 750 toolbarFrame.origin.y = NSMaxY(contentFrame); |
| 681 toolbarFrame.size.width = contentFrame.size.width; | 751 toolbarFrame.origin.x = 0; |
| 682 [toolbarView setFrame:toolbarFrame]; | 752 toolbarFrame.size.width = contentFrame.size.width; |
| 683 [[[self window] contentView] addSubview:toolbarView]; | 753 [toolbarView setFrame:toolbarFrame]; |
| 754 [[[self window] contentView] addSubview:toolbarView]; |
| 755 } else { |
| 756 [toolbarView removeFromSuperview]; |
| 757 } |
| 758 } |
| 759 |
| 760 - (void)positionToolbar { |
| 761 [self positionOrRemoveToolbar:YES]; |
| 762 } |
| 763 |
| 764 - (void)removeToolbar { |
| 765 [self positionOrRemoveToolbar:NO]; |
| 684 } | 766 } |
| 685 | 767 |
| 686 // If the browser is in incognito mode, install the image view to decordate | 768 // If the browser is in incognito mode, install the image view to decordate |
| 687 // the window at the upper right. Use the same base y coordinate as the | 769 // the window at the upper right. Use the same base y coordinate as the |
| 688 // tab strip. | 770 // tab strip. |
| 689 - (void)installIncognitoBadge { | 771 - (void)installIncognitoBadge { |
| 690 if (!browser_->profile()->IsOffTheRecord()) | 772 if (!browser_->profile()->IsOffTheRecord()) |
| 691 return; | 773 return; |
| 692 | 774 |
| 693 NSString *incognitoPath = [mac_util::MainAppBundle() | 775 NSString *incognitoPath = [mac_util::MainAppBundle() |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 browser_->ExecuteCommand(command); | 885 browser_->ExecuteCommand(command); |
| 804 } | 886 } |
| 805 | 887 |
| 806 - (id)windowWillReturnFieldEditor:(NSWindow*)sender toObject:(id)obj { | 888 - (id)windowWillReturnFieldEditor:(NSWindow*)sender toObject:(id)obj { |
| 807 // Ask the toolbar controller if it wants to return a custom field editor | 889 // Ask the toolbar controller if it wants to return a custom field editor |
| 808 // for the specific object. | 890 // for the specific object. |
| 809 return [toolbarController_ customFieldEditorForObject:obj]; | 891 return [toolbarController_ customFieldEditorForObject:obj]; |
| 810 } | 892 } |
| 811 | 893 |
| 812 @end | 894 @end |
| OLD | NEW |