| 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 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #include "chrome/app/chrome_dll_resource.h" // IDC_* | 10 #include "chrome/app/chrome_dll_resource.h" // IDC_* |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 151 |
| 152 // Puts the incognito badge on the window frame, if necessary. | 152 // Puts the incognito badge on the window frame, if necessary. |
| 153 [self installIncognitoBadge]; | 153 [self installIncognitoBadge]; |
| 154 | 154 |
| 155 // Create a controller for the toolbar, giving it the toolbar model object | 155 // Create a controller for the toolbar, giving it the toolbar model object |
| 156 // and the toolbar view from the nib. The controller will handle | 156 // and the toolbar view from the nib. The controller will handle |
| 157 // registering for the appropriate command state changes from the back-end. | 157 // registering for the appropriate command state changes from the back-end. |
| 158 toolbarController_.reset([[ToolbarController alloc] | 158 toolbarController_.reset([[ToolbarController alloc] |
| 159 initWithModel:browser->toolbar_model() | 159 initWithModel:browser->toolbar_model() |
| 160 commands:browser->command_updater() | 160 commands:browser->command_updater() |
| 161 profile:browser->profile()]); | 161 profile:browser->profile() |
| 162 webContentView:[self tabContentArea] |
| 163 bookmarkDelegate:self]); |
| 162 [self positionToolbar]; | 164 [self positionToolbar]; |
| 163 | 165 [self fixWindowGradient]; |
| 164 // After we've adjusted the toolbar, create a controller for the bookmark | |
| 165 // bar. It will show/hide itself based on the global preference and handle | |
| 166 // positioning itself (if visible) above the content area, which is why | |
| 167 // we need to do it after we've placed the toolbar. | |
| 168 bookmarkBarController_.reset([[BookmarkBarController alloc] | |
| 169 initWithProfile:browser_->profile() | |
| 170 contentView:[self tabContentArea] | |
| 171 delegate:self]); | |
| 172 | |
| 173 [self fixWindowGradient]; | |
| 174 | 166 |
| 175 // Create the bridge for the status bubble. | 167 // Create the bridge for the status bubble. |
| 176 statusBubble_.reset(new StatusBubbleMac([self window])); | 168 statusBubble_.reset(new StatusBubbleMac([self window])); |
| 177 } | 169 } |
| 178 return self; | 170 return self; |
| 179 } | 171 } |
| 180 | 172 |
| 181 - (void)dealloc { | 173 - (void)dealloc { |
| 182 browser_->CloseAllTabs(); | 174 browser_->CloseAllTabs(); |
| 183 // Under certain testing configurations we may not actually own the browser. | 175 // Under certain testing configurations we may not actually own the browser. |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 yStretchiness:yStretchiness]; | 567 yStretchiness:yStretchiness]; |
| 576 } | 568 } |
| 577 | 569 |
| 578 - (void)removePlaceholder { | 570 - (void)removePlaceholder { |
| 579 [tabStripController_ insertPlaceholderForTab:nil | 571 [tabStripController_ insertPlaceholderForTab:nil |
| 580 frame:NSZeroRect | 572 frame:NSZeroRect |
| 581 yStretchiness:0]; | 573 yStretchiness:0]; |
| 582 } | 574 } |
| 583 | 575 |
| 584 - (BOOL)isBookmarkBarVisible { | 576 - (BOOL)isBookmarkBarVisible { |
| 585 return [bookmarkBarController_ isBookmarkBarVisible]; | 577 return [[toolbarController_ bookmarkBarController] isBookmarkBarVisible]; |
| 586 | 578 |
| 587 } | 579 } |
| 588 | 580 |
| 589 - (void)toggleBookmarkBar { | 581 - (void)toggleBookmarkBar { |
| 590 [bookmarkBarController_ toggleBookmarkBar]; | 582 [[toolbarController_ bookmarkBarController] toggleBookmarkBar]; |
| 591 } | 583 } |
| 592 | 584 |
| 593 - (BOOL)isDownloadShelfVisible { | 585 - (BOOL)isDownloadShelfVisible { |
| 594 return downloadShelfController_ != nil && | 586 return downloadShelfController_ != nil && |
| 595 [downloadShelfController_ isVisible]; | 587 [downloadShelfController_ isVisible]; |
| 596 } | 588 } |
| 597 | 589 |
| 598 - (DownloadShelfController*)downloadShelf { | 590 - (DownloadShelfController*)downloadShelf { |
| 599 if (!downloadShelfController_.get()) { | 591 if (!downloadShelfController_.get()) { |
| 600 downloadShelfController_.reset([[DownloadShelfController alloc] | 592 downloadShelfController_.reset([[DownloadShelfController alloc] |
| (...skipping 11 matching lines...) Expand all Loading... |
| 612 [[[self window] contentView] addSubview:[findBarCocoaController_ view]]; | 604 [[[self window] contentView] addSubview:[findBarCocoaController_ view]]; |
| 613 [findBarCocoaController_ positionFindBarView:[self tabContentArea]]; | 605 [findBarCocoaController_ positionFindBarView:[self tabContentArea]]; |
| 614 } | 606 } |
| 615 | 607 |
| 616 // Adjust the UI for fullscreen mode. E.g. when going fullscreen, | 608 // Adjust the UI for fullscreen mode. E.g. when going fullscreen, |
| 617 // remove the toolbar. When stopping fullscreen, add it back in. | 609 // remove the toolbar. When stopping fullscreen, add it back in. |
| 618 - (void)adjustUIForFullscreen:(BOOL)fullscreen { | 610 - (void)adjustUIForFullscreen:(BOOL)fullscreen { |
| 619 if (fullscreen) { | 611 if (fullscreen) { |
| 620 // Disable showing of the bookmark bar. This does not toggle the | 612 // Disable showing of the bookmark bar. This does not toggle the |
| 621 // preference. | 613 // preference. |
| 622 [bookmarkBarController_ setBookmarkBarEnabled:NO]; | 614 [[toolbarController_ bookmarkBarController] setBookmarkBarEnabled:NO]; |
| 623 // Make room for more content area. | 615 // Make room for more content area. |
| 624 [self removeToolbar]; | 616 [self removeToolbar]; |
| 625 // Hide the menubar, and allow it to un-hide when moving the mouse | 617 // Hide the menubar, and allow it to un-hide when moving the mouse |
| 626 // to the top of the screen. Does this eliminate the need for an | 618 // to the top of the screen. Does this eliminate the need for an |
| 627 // info bubble describing how to exit fullscreen mode? | 619 // info bubble describing how to exit fullscreen mode? |
| 628 SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar); | 620 SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar); |
| 629 } else { | 621 } else { |
| 630 SetSystemUIMode(kUIModeNormal, 0); | 622 SetSystemUIMode(kUIModeNormal, 0); |
| 631 [self positionToolbar]; | 623 [self positionToolbar]; |
| 632 [bookmarkBarController_ setBookmarkBarEnabled:YES]; | 624 [[toolbarController_ bookmarkBarController] setBookmarkBarEnabled:YES]; |
| 633 } | 625 } |
| 634 } | 626 } |
| 635 | 627 |
| 636 - (NSWindow*)fullscreenWindow { | 628 - (NSWindow*)fullscreenWindow { |
| 637 return [[[FullscreenWindow alloc] initForScreen:[[self window] screen]] | 629 return [[[FullscreenWindow alloc] initForScreen:[[self window] screen]] |
| 638 autorelease]; | 630 autorelease]; |
| 639 } | 631 } |
| 640 | 632 |
| 641 - (void)setFullscreen:(BOOL)fullscreen { | 633 - (void)setFullscreen:(BOOL)fullscreen { |
| 642 fullscreen_ = fullscreen; | 634 fullscreen_ = fullscreen; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 [win respondsToSelector:@selector( | 806 [win respondsToSelector:@selector( |
| 815 setContentBorderThickness:forEdge:)]) { | 807 setContentBorderThickness:forEdge:)]) { |
| 816 [win setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge]; | 808 [win setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge]; |
| 817 [win setContentBorderThickness:kWindowGradientHeight forEdge:NSMaxYEdge]; | 809 [win setContentBorderThickness:kWindowGradientHeight forEdge:NSMaxYEdge]; |
| 818 } | 810 } |
| 819 } | 811 } |
| 820 | 812 |
| 821 - (void)tabContentAreaFrameChanged:(id)sender { | 813 - (void)tabContentAreaFrameChanged:(id)sender { |
| 822 // TODO(rohitrao): This is triggered by window resizes also. Make | 814 // TODO(rohitrao): This is triggered by window resizes also. Make |
| 823 // sure we aren't doing anything wasteful in those cases. | 815 // sure we aren't doing anything wasteful in those cases. |
| 824 [bookmarkBarController_ resizeBookmarkBar]; | |
| 825 | |
| 826 [downloadShelfController_ resizeDownloadShelf]; | 816 [downloadShelfController_ resizeDownloadShelf]; |
| 827 | 817 |
| 828 [findBarCocoaController_ positionFindBarView:[self tabContentArea]]; | 818 [findBarCocoaController_ positionFindBarView:[self tabContentArea]]; |
| 829 } | 819 } |
| 830 | 820 |
| 831 - (void)saveWindowPositionIfNeeded { | 821 - (void)saveWindowPositionIfNeeded { |
| 832 if (browser_ != BrowserList::GetLastActive()) | 822 if (browser_ != BrowserList::GetLastActive()) |
| 833 return; | 823 return; |
| 834 | 824 |
| 835 if (!g_browser_process || !g_browser_process->local_state() || | 825 if (!g_browser_process || !g_browser_process->local_state() || |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 return defaultSheetRect; | 861 return defaultSheetRect; |
| 872 } | 862 } |
| 873 | 863 |
| 874 // In addition to the tab strip and content area, which the superview's impl | 864 // In addition to the tab strip and content area, which the superview's impl |
| 875 // takes care of, we need to add the toolbar and bookmark bar to the | 865 // takes care of, we need to add the toolbar and bookmark bar to the |
| 876 // overlay so they draw correctly when dragging out a new window. | 866 // overlay so they draw correctly when dragging out a new window. |
| 877 - (NSArray*)viewsToMoveToOverlay { | 867 - (NSArray*)viewsToMoveToOverlay { |
| 878 NSArray* views = [super viewsToMoveToOverlay]; | 868 NSArray* views = [super viewsToMoveToOverlay]; |
| 879 NSArray* browserViews = | 869 NSArray* browserViews = |
| 880 [NSArray arrayWithObjects:[toolbarController_ view], | 870 [NSArray arrayWithObjects:[toolbarController_ view], |
| 881 [bookmarkBarController_ view], | |
| 882 nil]; | 871 nil]; |
| 883 return [views arrayByAddingObjectsFromArray:browserViews]; | 872 return [views arrayByAddingObjectsFromArray:browserViews]; |
| 884 } | 873 } |
| 885 | 874 |
| 886 // Undocumented method for multi-touch gestures in 10.5. Future OS's will | 875 // Undocumented method for multi-touch gestures in 10.5. Future OS's will |
| 887 // likely add a public API, but the worst that will happen is that this will | 876 // likely add a public API, but the worst that will happen is that this will |
| 888 // turn into dead code and just won't get called. | 877 // turn into dead code and just won't get called. |
| 889 - (void)swipeWithEvent:(NSEvent*)event { | 878 - (void)swipeWithEvent:(NSEvent*)event { |
| 890 // Map forwards and backwards to history; left is positive, right is negative. | 879 // Map forwards and backwards to history; left is positive, right is negative. |
| 891 unsigned int command = 0; | 880 unsigned int command = 0; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 904 browser_->ExecuteCommand(command); | 893 browser_->ExecuteCommand(command); |
| 905 } | 894 } |
| 906 | 895 |
| 907 - (id)windowWillReturnFieldEditor:(NSWindow*)sender toObject:(id)obj { | 896 - (id)windowWillReturnFieldEditor:(NSWindow*)sender toObject:(id)obj { |
| 908 // Ask the toolbar controller if it wants to return a custom field editor | 897 // Ask the toolbar controller if it wants to return a custom field editor |
| 909 // for the specific object. | 898 // for the specific object. |
| 910 return [toolbarController_ customFieldEditorForObject:obj]; | 899 return [toolbarController_ customFieldEditorForObject:obj]; |
| 911 } | 900 } |
| 912 | 901 |
| 913 @end | 902 @end |
| OLD | NEW |