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" |
11 #include "chrome/app/chrome_dll_resource.h" // IDC_* | 11 #include "chrome/app/chrome_dll_resource.h" // IDC_* |
12 #include "chrome/browser/browser.h" | 12 #include "chrome/browser/browser.h" |
13 #include "chrome/browser/browser_list.h" | 13 #include "chrome/browser/browser_list.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/encoding_menu_controller.h" | 15 #include "chrome/browser/encoding_menu_controller.h" |
16 #include "chrome/browser/profile.h" | 16 #include "chrome/browser/profile.h" |
17 #include "chrome/browser/tab_contents/tab_contents.h" | 17 #include "chrome/browser/tab_contents/tab_contents.h" |
18 #include "chrome/browser/tab_contents/tab_contents_view.h" | 18 #include "chrome/browser/tab_contents/tab_contents_view.h" |
19 #include "chrome/browser/tabs/tab_strip_model.h" | 19 #include "chrome/browser/tabs/tab_strip_model.h" |
20 #import "chrome/browser/cocoa/bookmark_bar_controller.h" | 20 #import "chrome/browser/cocoa/bookmark_bar_controller.h" |
21 #import "chrome/browser/cocoa/browser_window_cocoa.h" | 21 #import "chrome/browser/cocoa/browser_window_cocoa.h" |
22 #import "chrome/browser/cocoa/browser_window_controller.h" | 22 #import "chrome/browser/cocoa/browser_window_controller.h" |
23 #import "chrome/browser/cocoa/download_shelf_controller.h" | 23 #import "chrome/browser/cocoa/download_shelf_controller.h" |
24 #import "chrome/browser/cocoa/find_bar_cocoa_controller.h" | 24 #import "chrome/browser/cocoa/find_bar_cocoa_controller.h" |
25 #include "chrome/browser/cocoa/find_bar_bridge.h" | 25 #include "chrome/browser/cocoa/find_bar_bridge.h" |
26 #import "chrome/browser/cocoa/fullscreen_window.h" | 26 #import "chrome/browser/cocoa/fullscreen_window.h" |
| 27 #import "chrome/browser/cocoa/infobar_container_controller.h" |
27 #import "chrome/browser/cocoa/status_bubble_mac.h" | 28 #import "chrome/browser/cocoa/status_bubble_mac.h" |
28 #import "chrome/browser/cocoa/tab_strip_model_observer_bridge.h" | 29 #import "chrome/browser/cocoa/tab_strip_model_observer_bridge.h" |
29 #import "chrome/browser/cocoa/tab_strip_view.h" | 30 #import "chrome/browser/cocoa/tab_strip_view.h" |
30 #import "chrome/browser/cocoa/tab_strip_controller.h" | 31 #import "chrome/browser/cocoa/tab_strip_controller.h" |
31 #import "chrome/browser/cocoa/tab_view.h" | 32 #import "chrome/browser/cocoa/tab_view.h" |
32 #import "chrome/browser/cocoa/toolbar_controller.h" | 33 #import "chrome/browser/cocoa/toolbar_controller.h" |
33 #import "chrome/browser/browser_theme_provider.h" | 34 #import "chrome/browser/browser_theme_provider.h" |
34 #include "chrome/common/pref_service.h" | 35 #include "chrome/common/pref_service.h" |
35 #import "chrome/browser/cocoa/background_gradient_view.h" | 36 #import "chrome/browser/cocoa/background_gradient_view.h" |
36 #import "third_party/GTM/AppKit/GTMTheme.h" | 37 #import "third_party/GTM/AppKit/GTMTheme.h" |
(...skipping 20 matching lines...) Expand all Loading... |
57 - (void)setContentBorderThickness:(CGFloat)b forEdge:(NSRectEdge)e; | 58 - (void)setContentBorderThickness:(CGFloat)b forEdge:(NSRectEdge)e; |
58 | 59 |
59 - (void)setBottomCornerRounded:(BOOL)rounded; | 60 - (void)setBottomCornerRounded:(BOOL)rounded; |
60 | 61 |
61 - (NSRect)_growBoxRect; | 62 - (NSRect)_growBoxRect; |
62 @end | 63 @end |
63 | 64 |
64 | 65 |
65 @interface BrowserWindowController(Private) | 66 @interface BrowserWindowController(Private) |
66 | 67 |
| 68 - (void)positionInfoBar; |
67 - (void)positionToolbar; | 69 - (void)positionToolbar; |
68 - (void)removeToolbar; | 70 - (void)removeToolbar; |
69 - (void)installIncognitoBadge; | 71 - (void)installIncognitoBadge; |
70 | 72 |
71 // Leopard's gradient heuristic gets confused by our tabs and makes the title | 73 // Leopard's gradient heuristic gets confused by our tabs and makes the title |
72 // gradient jump when creating a tab that is less than a tab width from the | 74 // gradient jump when creating a tab that is less than a tab width from the |
73 // right side of the screen. This function disables Leopard's gradient | 75 // right side of the screen. This function disables Leopard's gradient |
74 // heuristic. | 76 // heuristic. |
75 - (void)fixWindowGradient; | 77 - (void)fixWindowGradient; |
76 | 78 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // Retain it per the comment in the header. | 130 // Retain it per the comment in the header. |
129 window_.reset([[self window] retain]); | 131 window_.reset([[self window] retain]); |
130 | 132 |
131 // Sets the window to not have rounded corners, which prevents | 133 // Sets the window to not have rounded corners, which prevents |
132 // the resize control from being inset slightly and looking ugly. | 134 // the resize control from being inset slightly and looking ugly. |
133 if ([window_ respondsToSelector:@selector(setBottomCornerRounded:)]) | 135 if ([window_ respondsToSelector:@selector(setBottomCornerRounded:)]) |
134 [window_ setBottomCornerRounded:NO]; | 136 [window_ setBottomCornerRounded:NO]; |
135 | 137 |
136 [self setTheme]; | 138 [self setTheme]; |
137 | 139 |
138 // Register ourselves for frame changed notifications from the | |
139 // tabContentArea. | |
140 [[NSNotificationCenter defaultCenter] | |
141 addObserver:self | |
142 selector:@selector(tabContentAreaFrameChanged:) | |
143 name:nil | |
144 object:[self tabContentArea]]; | |
145 | |
146 // Get the most appropriate size for the window, then enforce the | 140 // Get the most appropriate size for the window, then enforce the |
147 // minimum width and height. The window shim will handle flipping | 141 // minimum width and height. The window shim will handle flipping |
148 // the coordinates for us so we can use it to save some code. | 142 // the coordinates for us so we can use it to save some code. |
149 // Note that this may leave a significant portion of the window | 143 // Note that this may leave a significant portion of the window |
150 // offscreen, but there will always be enough window onscreen to | 144 // offscreen, but there will always be enough window onscreen to |
151 // drag the whole window back into view. | 145 // drag the whole window back into view. |
152 NSSize minSize = [[self window] minSize]; | 146 NSSize minSize = [[self window] minSize]; |
153 gfx::Rect windowRect = browser_->GetSavedWindowBounds(); | 147 gfx::Rect windowRect = browser_->GetSavedWindowBounds(); |
154 if (windowRect.width() < minSize.width) | 148 if (windowRect.width() < minSize.width) |
155 windowRect.set_width(minSize.width); | 149 windowRect.set_width(minSize.width); |
156 if (windowRect.height() < minSize.height) | 150 if (windowRect.height() < minSize.height) |
157 windowRect.set_height(minSize.height); | 151 windowRect.set_height(minSize.height); |
158 windowShim_->SetBounds(windowRect); | 152 windowShim_->SetBounds(windowRect); |
159 | 153 |
160 // Create a controller for the tab strip, giving it the model object for | 154 // Create a controller for the tab strip, giving it the model object for |
161 // this window's Browser and the tab strip view. The controller will handle | 155 // this window's Browser and the tab strip view. The controller will handle |
162 // registering for the appropriate tab notifications from the back-end and | 156 // registering for the appropriate tab notifications from the back-end and |
163 // managing the creation of new tabs. | 157 // managing the creation of new tabs. |
164 tabStripController_.reset([[TabStripController alloc] | 158 tabStripController_.reset([[TabStripController alloc] |
165 initWithView:[self tabStripView] | 159 initWithView:[self tabStripView] |
166 switchView:[self tabContentArea] | 160 switchView:[self tabContentArea] |
167 model:browser_->tabstrip_model()]); | 161 model:browser_->tabstrip_model()]); |
168 | 162 |
169 // Puts the incognito badge on the window frame, if necessary. | 163 // Puts the incognito badge on the window frame, if necessary. |
170 [self installIncognitoBadge]; | 164 [self installIncognitoBadge]; |
171 | 165 |
| 166 // Create the infobar container view, so we can pass it to the |
| 167 // ToolbarController, but do not position the view until after the |
| 168 // toolbar is in place, as positionToolbar will move the tab content area. |
| 169 infoBarContainerController_.reset( |
| 170 [[InfoBarContainerController alloc] |
| 171 initWithTabStripModel:(browser_->tabstrip_model()) |
| 172 browserWindowController:self]); |
| 173 |
172 // Create a controller for the toolbar, giving it the toolbar model object | 174 // Create a controller for the toolbar, giving it the toolbar model object |
173 // and the toolbar view from the nib. The controller will handle | 175 // and the toolbar view from the nib. The controller will handle |
174 // registering for the appropriate command state changes from the back-end. | 176 // registering for the appropriate command state changes from the back-end. |
175 toolbarController_.reset([[ToolbarController alloc] | 177 toolbarController_.reset([[ToolbarController alloc] |
176 initWithModel:browser->toolbar_model() | 178 initWithModel:browser->toolbar_model() |
177 commands:browser->command_updater() | 179 commands:browser->command_updater() |
178 profile:browser->profile() | 180 profile:browser->profile() |
179 webContentView:[self tabContentArea] | 181 webContentView:[self tabContentArea] |
| 182 infoBarsView:[infoBarContainerController_ view] |
180 bookmarkDelegate:self]); | 183 bookmarkDelegate:self]); |
181 [self positionToolbar]; | 184 [self positionToolbar]; |
182 [self fixWindowGradient]; | 185 [self fixWindowGradient]; |
183 | 186 |
| 187 // Put the infobar container view into the window above the |
| 188 // tabcontentarea. There are no infobars when starting up, so its |
| 189 // initial height is 0. |
| 190 [self positionInfoBar]; |
| 191 |
| 192 // Register ourselves for frame changed notifications from the |
| 193 // tabContentArea. This has to come after all of the resizing and |
| 194 // positioning above. |
| 195 [[NSNotificationCenter defaultCenter] |
| 196 addObserver:self |
| 197 selector:@selector(tabContentAreaFrameChanged:) |
| 198 name:nil |
| 199 object:[self tabContentArea]]; |
| 200 |
184 // Create the bridge for the status bubble. | 201 // Create the bridge for the status bubble. |
185 statusBubble_.reset(new StatusBubbleMac([self window])); | 202 statusBubble_.reset(new StatusBubbleMac([self window])); |
186 | 203 |
187 #if 0 | 204 #if 0 |
188 // Move all buttons down two pixels for visual balance. | 205 // Move all buttons down two pixels for visual balance. |
189 // TODO(alcor): remove this if we can't prevent window resize from breaking. | 206 // TODO(alcor): remove this if we can't prevent window resize from breaking. |
190 NSArray* buttons = | 207 NSArray* buttons = |
191 [NSArray arrayWithObjects: | 208 [NSArray arrayWithObjects: |
192 [[self window] standardWindowButton:NSWindowCloseButton], | 209 [[self window] standardWindowButton:NSWindowCloseButton], |
193 [[self window] standardWindowButton:NSWindowZoomButton], | 210 [[self window] standardWindowButton:NSWindowZoomButton], |
(...skipping 11 matching lines...) Expand all Loading... |
205 browser_->CloseAllTabs(); | 222 browser_->CloseAllTabs(); |
206 [downloadShelfController_ exiting]; | 223 [downloadShelfController_ exiting]; |
207 | 224 |
208 // Under certain testing configurations we may not actually own the browser. | 225 // Under certain testing configurations we may not actually own the browser. |
209 if (ownsBrowser_ == NO) | 226 if (ownsBrowser_ == NO) |
210 browser_.release(); | 227 browser_.release(); |
211 // Since |window_| outlives our obj-c shutdown sequence, clear out the | 228 // Since |window_| outlives our obj-c shutdown sequence, clear out the |
212 // delegate so nothing tries to call us back in the meantime as part of | 229 // delegate so nothing tries to call us back in the meantime as part of |
213 // window destruction. | 230 // window destruction. |
214 [window_ setDelegate:nil]; | 231 [window_ setDelegate:nil]; |
| 232 |
| 233 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
215 [super dealloc]; | 234 [super dealloc]; |
216 } | 235 } |
217 | 236 |
218 // Access the C++ bridge between the NSWindow and the rest of Chromium | 237 // Access the C++ bridge between the NSWindow and the rest of Chromium |
219 - (BrowserWindow*)browserWindow { | 238 - (BrowserWindow*)browserWindow { |
220 return windowShim_.get(); | 239 return windowShim_.get(); |
221 } | 240 } |
222 | 241 |
223 - (void)destroyBrowser { | 242 - (void)destroyBrowser { |
224 [NSApp removeWindowsItem:[self window]]; | 243 [NSApp removeWindowsItem:[self window]]; |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 - (void)selectTabWithContents:(TabContents*)newContents | 763 - (void)selectTabWithContents:(TabContents*)newContents |
745 previousContents:(TabContents*)oldContents | 764 previousContents:(TabContents*)oldContents |
746 atIndex:(NSInteger)index | 765 atIndex:(NSInteger)index |
747 userGesture:(bool)wasUserGesture { | 766 userGesture:(bool)wasUserGesture { |
748 DCHECK(oldContents != newContents); | 767 DCHECK(oldContents != newContents); |
749 | 768 |
750 // Update various elements that are interested in knowing the current | 769 // Update various elements that are interested in knowing the current |
751 // TabContents. | 770 // TabContents. |
752 #if 0 | 771 #if 0 |
753 // TODO(pinkerton):Update as more things become window-specific | 772 // TODO(pinkerton):Update as more things become window-specific |
754 infobar_container_->ChangeTabContents(new_contents); | |
755 contents_container_->SetTabContents(new_contents); | 773 contents_container_->SetTabContents(new_contents); |
756 #endif | 774 #endif |
757 | 775 |
758 // Update all the UI bits. | 776 // Update all the UI bits. |
759 windowShim_->UpdateTitleBar(); | 777 windowShim_->UpdateTitleBar(); |
760 #if 0 | 778 #if 0 |
761 // TODO(pinkerton):Update as more things become window-specific | 779 // TODO(pinkerton):Update as more things become window-specific |
762 toolbar_->SetProfile(new_contents->profile()); | 780 toolbar_->SetProfile(new_contents->profile()); |
763 UpdateToolbar(new_contents, true); | 781 UpdateToolbar(new_contents, true); |
764 UpdateUIForContents(new_contents); | 782 UpdateUIForContents(new_contents); |
765 #endif | 783 #endif |
766 } | 784 } |
767 | 785 |
768 - (void)tabChangedWithContents:(TabContents*)contents | 786 - (void)tabChangedWithContents:(TabContents*)contents |
769 atIndex:(NSInteger)index | 787 atIndex:(NSInteger)index |
770 loadingOnly:(BOOL)loading { | 788 loadingOnly:(BOOL)loading { |
771 // Update titles if this is the currently selected tab. | 789 // Update titles if this is the currently selected tab. |
772 if (index == browser_->tabstrip_model()->selected_index()) | 790 if (index == browser_->tabstrip_model()->selected_index()) |
773 windowShim_->UpdateTitleBar(); | 791 windowShim_->UpdateTitleBar(); |
774 } | 792 } |
775 | 793 |
776 - (void)userChangedTheme { | 794 - (void)userChangedTheme { |
777 [self setTheme]; | 795 [self setTheme]; |
778 [self applyTheme]; | 796 [self applyTheme]; |
779 } | 797 } |
780 | 798 |
| 799 // TODO(rohitrao, jrg): Move this logic out of BrowserWindowController? |
| 800 - (void)infoBarResized:(float)newHeight { |
| 801 // The top edge of the infobar is fixed. |
| 802 NSView* infoBarView = [infoBarContainerController_ view]; |
| 803 NSRect infoBarFrame = [infoBarView frame]; |
| 804 int maxY = NSMaxY(infoBarFrame); |
| 805 int minY = maxY - newHeight; |
| 806 |
| 807 [infoBarView setFrame:NSMakeRect(infoBarFrame.origin.x, minY, |
| 808 infoBarFrame.size.width, newHeight)]; |
| 809 |
| 810 NSRect contentFrame = [[self tabContentArea] frame]; |
| 811 contentFrame.size.height = minY - contentFrame.origin.y; |
| 812 [[self tabContentArea] setFrame:contentFrame]; |
| 813 } |
| 814 |
781 - (GTMTheme *)gtm_themeForWindow:(NSWindow*)window { | 815 - (GTMTheme *)gtm_themeForWindow:(NSWindow*)window { |
782 return theme_ ? theme_ : [GTMTheme defaultTheme]; | 816 return theme_ ? theme_ : [GTMTheme defaultTheme]; |
783 } | 817 } |
784 | 818 |
785 @end | 819 @end |
786 | 820 |
787 @implementation BrowserWindowController (Private) | 821 @implementation BrowserWindowController (Private) |
788 | 822 |
| 823 // TODO(rohitrao, jrg): Move this logic out of BrowserWindowController? |
| 824 - (void)positionInfoBar { |
| 825 NSView* infoBarView = [infoBarContainerController_ view]; |
| 826 NSRect infoBarFrame = [[self tabContentArea] frame]; |
| 827 infoBarFrame.origin.y = NSMaxY(infoBarFrame); |
| 828 infoBarFrame.size.height = 0; |
| 829 [infoBarView setFrame:infoBarFrame]; |
| 830 [[[self window] contentView] addSubview:infoBarView]; |
| 831 } |
| 832 |
789 // If |add| is YES: | 833 // If |add| is YES: |
790 // Position |toolbarView_| below the tab strip, but not as a | 834 // Position |toolbarView_| below the tab strip, but not as a |
791 // sibling. The toolbar is part of the window's contentView, mainly | 835 // sibling. The toolbar is part of the window's contentView, mainly |
792 // because we want the opacity during drags to be the same as the web | 836 // because we want the opacity during drags to be the same as the web |
793 // content. This can be used for either the initial add or a | 837 // content. This can be used for either the initial add or a |
794 // reposition. | 838 // reposition. |
795 // If |add| is NO: | 839 // If |add| is NO: |
796 // Remove the toolbar from it's parent view (the window's content view). | 840 // Remove the toolbar from it's parent view (the window's content view). |
797 // Called when going fullscreen and we need to minimize UI. | 841 // Called when going fullscreen and we need to minimize UI. |
798 - (void)positionOrRemoveToolbar:(BOOL)add { | 842 - (void)positionOrRemoveToolbar:(BOOL)add { |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 NSColor* toolbarButtonBorderColor = toolbarButtonIconColor; | 1105 NSColor* toolbarButtonBorderColor = toolbarButtonIconColor; |
1062 [theme setValue:toolbarButtonBorderColor | 1106 [theme setValue:toolbarButtonBorderColor |
1063 forAttribute:@"borderColor" | 1107 forAttribute:@"borderColor" |
1064 style:GTMThemeStyleToolBar | 1108 style:GTMThemeStyleToolBar |
1065 state:YES]; | 1109 state:YES]; |
1066 | 1110 |
1067 return theme; | 1111 return theme; |
1068 } | 1112 } |
1069 @end | 1113 @end |
1070 | 1114 |
OLD | NEW |