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 "app/l10n_util_mac.h" | 7 #include "app/l10n_util_mac.h" |
8 #include "base/mac_util.h" | 8 #include "base/mac_util.h" |
9 #include "base/scoped_nsdisable_screen_updates.h" | 9 #include "base/scoped_nsdisable_screen_updates.h" |
10 #import "base/scoped_nsobject.h" | 10 #import "base/scoped_nsobject.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 #include "chrome/browser/net/url_fixer_upper.h" | 46 #include "chrome/browser/net/url_fixer_upper.h" |
47 #include "chrome/browser/sync/profile_sync_service.h" | 47 #include "chrome/browser/sync/profile_sync_service.h" |
48 #include "chrome/browser/sync/sync_ui_util_mac.h" | 48 #include "chrome/browser/sync/sync_ui_util_mac.h" |
49 #include "chrome/common/pref_names.h" | 49 #include "chrome/common/pref_names.h" |
50 #include "chrome/common/pref_service.h" | 50 #include "chrome/common/pref_service.h" |
51 #include "grit/generated_resources.h" | 51 #include "grit/generated_resources.h" |
52 #include "grit/locale_settings.h" | 52 #include "grit/locale_settings.h" |
53 #include "grit/theme_resources.h" | 53 #include "grit/theme_resources.h" |
54 #import "third_party/GTM/AppKit/GTMTheme.h" | 54 #import "third_party/GTM/AppKit/GTMTheme.h" |
55 | 55 |
| 56 // ORGANIZATION: This is a big file. It is (in principle) organized as follows |
| 57 // (in order): |
| 58 // 1. Interfaces, including for our private methods. Very short, one-time-use |
| 59 // classes may include an implementation immediately after their interface. |
| 60 // 2. The general implementation section, ordered as follows: |
| 61 // i. Public methods and overrides. |
| 62 // ii. Overrides/implementations of undocumented methods. |
| 63 // iii. Delegate methods for various protocols, formal and informal, to which |
| 64 // |BrowserWindowController| conforms. |
| 65 // 3. The private implementation section (|BrowserWindowController (Private)|). |
| 66 // 4. Implementation for |GTMTheme (BrowserThemeProviderInitialization)|. |
| 67 // |
| 68 // Not all of the above guidelines are followed and more (re-)organization is |
| 69 // needed. BUT PLEASE TRY TO KEEP THIS FILE ORGANIZED. I'd rather re-organize as |
| 70 // little as possible, since doing so messes up the file's history. |
| 71 // |
| 72 // TODO(viettrungluu): (re-)organize some more, possibly split into separate |
| 73 // files? |
| 74 |
56 // Notes on self-inflicted (not user-inflicted) window resizing and moving: | 75 // Notes on self-inflicted (not user-inflicted) window resizing and moving: |
57 // | 76 // |
58 // When the bookmark bar goes from hidden to shown (on a non-NTP) page, or when | 77 // When the bookmark bar goes from hidden to shown (on a non-NTP) page, or when |
59 // the download shelf goes from hidden to shown, we grow the window downwards in | 78 // the download shelf goes from hidden to shown, we grow the window downwards in |
60 // order to maintain a constant content area size. When either goes from shown | 79 // order to maintain a constant content area size. When either goes from shown |
61 // to hidden, we consequently shrink the window from the bottom, also to keep | 80 // to hidden, we consequently shrink the window from the bottom, also to keep |
62 // the content area size constant. To keep things simple, if the window is not | 81 // the content area size constant. To keep things simple, if the window is not |
63 // entirely on-screen, we don't grow/shrink the window. | 82 // entirely on-screen, we don't grow/shrink the window. |
64 // | 83 // |
65 // The complications come in when there isn't enough room (on screen) below the | 84 // The complications come in when there isn't enough room (on screen) below the |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 139 |
121 // We need to adjust where sheets come out of the window, as by default they | 140 // We need to adjust where sheets come out of the window, as by default they |
122 // erupt from the omnibox, which is rather weird. | 141 // erupt from the omnibox, which is rather weird. |
123 - (NSRect)window:(NSWindow*)window | 142 - (NSRect)window:(NSWindow*)window |
124 willPositionSheet:(NSWindow*)sheet | 143 willPositionSheet:(NSWindow*)sheet |
125 usingRect:(NSRect)defaultSheetRect; | 144 usingRect:(NSRect)defaultSheetRect; |
126 | 145 |
127 // Assign a theme to the window. | 146 // Assign a theme to the window. |
128 - (void)setTheme; | 147 - (void)setTheme; |
129 | 148 |
130 // Repositions the windows subviews. | 149 // Repositions the window's subviews. From the top down: toolbar, normal |
| 150 // bookmark bar (if shown), infobar, NTP detached bookmark bar (if shown), |
| 151 // content area, download shelf (if any). |
131 - (void)layoutSubviews; | 152 - (void)layoutSubviews; |
132 | 153 |
| 154 // Lays out the toolbar (or just location bar for popups) at the given maximum |
| 155 // y-coordinate, with the given width; returns the new maximum y (below the |
| 156 // toolbar). |
| 157 - (CGFloat)layoutToolbarAtMaxY:(CGFloat)maxY width:(CGFloat)width; |
| 158 |
| 159 // Lays out the bookmark bar at the given maximum y-coordinate, with the given |
| 160 // width; returns the new maximum y (below the bookmark bar). Note that one must |
| 161 // call it with the appropriate |maxY| which depends on whether or not the |
| 162 // bookmark bar is shown as the NTP bubble or not (use |
| 163 // |-placeBookmarkBarBelowInfoBar|). |
| 164 - (CGFloat)layoutBookmarkBarAtMaxY:(CGFloat)maxY width:(CGFloat)width; |
| 165 |
| 166 // Lays out the infobar at the given maximum y-coordinate, with the given width; |
| 167 // returns the new maximum y (below the infobar). |
| 168 - (CGFloat)layoutInfoBarAtMaxY:(CGFloat)maxY width:(CGFloat)width; |
| 169 |
| 170 // Returns YES if the bookmark bar should be placed below the infobar, NO |
| 171 // otherwise. |
| 172 - (BOOL)placeBookmarkBarBelowInfoBar; |
| 173 |
| 174 // Lays out the download shelf, if there is one, at the given minimum |
| 175 // y-coordinate, with the given width; returns the new minimum y (above the |
| 176 // download shelf). This is safe to call even if there is no download shelf. |
| 177 - (CGFloat)layoutDownloadShelfAtMinY:(CGFloat)minY width:(CGFloat)width; |
| 178 |
| 179 // Lays out the tab content area between the given minimum and maximum |
| 180 // y-coordinates, with the given width. |
| 181 - (void)layoutTabContentAreaAtMinY:(CGFloat)minY |
| 182 maxY:(CGFloat)maxY |
| 183 width:(CGFloat)width; |
| 184 |
133 // Should we show the normal bookmark bar? | 185 // Should we show the normal bookmark bar? |
134 - (BOOL)shouldShowBookmarkBar; | 186 - (BOOL)shouldShowBookmarkBar; |
135 | 187 |
136 // Is the current page one for which the bookmark should be shown detached *if* | 188 // Is the current page one for which the bookmark should be shown detached *if* |
137 // the normal bookmark bar is not shown? | 189 // the normal bookmark bar is not shown? |
138 - (BOOL)shouldShowDetachedBookmarkBar; | 190 - (BOOL)shouldShowDetachedBookmarkBar; |
139 | 191 |
140 // Sets the toolbar's height to a value appropriate for the given compression. | 192 // Sets the toolbar's height to a value appropriate for the given compression. |
141 // Also adjusts the bookmark bar's height by the opposite amount in order to | 193 // Also adjusts the bookmark bar's height by the opposite amount in order to |
142 // keep the total height of the two views constant. | 194 // keep the total height of the two views constant. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 278 |
227 // Create a controller for the toolbar, giving it the toolbar model object | 279 // Create a controller for the toolbar, giving it the toolbar model object |
228 // and the toolbar view from the nib. The controller will handle | 280 // and the toolbar view from the nib. The controller will handle |
229 // registering for the appropriate command state changes from the back-end. | 281 // registering for the appropriate command state changes from the back-end. |
230 toolbarController_.reset([[ToolbarController alloc] | 282 toolbarController_.reset([[ToolbarController alloc] |
231 initWithModel:browser->toolbar_model() | 283 initWithModel:browser->toolbar_model() |
232 commands:browser->command_updater() | 284 commands:browser->command_updater() |
233 profile:browser->profile() | 285 profile:browser->profile() |
234 browser:browser | 286 browser:browser |
235 resizeDelegate:self]); | 287 resizeDelegate:self]); |
236 // If we are a pop-up, we have a titlebar and no toolbar. | 288 [toolbarController_ setHasToolbar:[self hasToolbar] |
237 if (!browser_->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) && | 289 hasLocationBar:[self hasLocationBar]]; |
238 browser_->SupportsWindowFeature(Browser::FEATURE_TITLEBAR)) { | |
239 [toolbarController_ setHasToolbar:NO]; | |
240 } | |
241 [[[self window] contentView] addSubview:[toolbarController_ view]]; | 290 [[[self window] contentView] addSubview:[toolbarController_ view]]; |
242 | 291 |
243 // Create a sub-controller for the bookmark bar. | 292 // Create a sub-controller for the bookmark bar. |
244 bookmarkBarController_.reset( | 293 bookmarkBarController_.reset( |
245 [[BookmarkBarController alloc] | 294 [[BookmarkBarController alloc] |
246 initWithBrowser:browser_.get() | 295 initWithBrowser:browser_.get() |
247 initialWidth:NSWidth([[[self window] contentView] frame]) | 296 initialWidth:NSWidth([[[self window] contentView] frame]) |
248 delegate:self | 297 delegate:self |
249 resizeDelegate:self]); | 298 resizeDelegate:self]); |
250 | 299 |
251 // Add bookmark bar to the view hierarchy. This also triggers the | 300 // Add bookmark bar to the view hierarchy, which also triggers the nib load. |
252 // nib load. The bookmark bar is defined (in the nib) to be | 301 // The bookmark bar is defined (in the nib) to be bottom-aligned to its |
253 // bottom-aligned to it's parent view (among other things), so | 302 // parent view (among other things), so position and resize properties don't |
254 // position and resize properties don't need to be set. | 303 // need to be set. |
255 [[[self window] contentView] addSubview:[bookmarkBarController_ view] | 304 [[[self window] contentView] addSubview:[bookmarkBarController_ view] |
256 positioned:NSWindowBelow | 305 positioned:NSWindowBelow |
257 relativeTo:[toolbarController_ view]]; | 306 relativeTo:[toolbarController_ view]]; |
258 | 307 [bookmarkBarController_ setBookmarkBarEnabled:[self supportsBookmarkBar]]; |
259 // Disable the bookmark bar if this window doesn't support them. | |
260 if (!browser_->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR)) { | |
261 [bookmarkBarController_ setBookmarkBarEnabled:NO]; | |
262 } | |
263 | 308 |
264 // We don't want to try and show the bar before it gets placed in its parent | 309 // We don't want to try and show the bar before it gets placed in its parent |
265 // view, so this step shoudn't be inside the bookmark bar controller's | 310 // view, so this step shoudn't be inside the bookmark bar controller's |
266 // |-awakeFromNib|. | 311 // |-awakeFromNib|. |
267 [self updateBookmarkBarVisibilityWithAnimation:NO]; | 312 [self updateBookmarkBarVisibilityWithAnimation:NO]; |
268 | 313 |
269 // Force a relayout of all the various bars. | 314 // Force a relayout of all the various bars. |
270 [self layoutSubviews]; | 315 [self layoutSubviews]; |
271 | 316 |
272 // Create the bridge for the status bubble. | 317 // Create the bridge for the status bubble. |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 // command_updater doesn't support the command. This may or may not be an issue, | 790 // command_updater doesn't support the command. This may or may not be an issue, |
746 // too early to tell. | 791 // too early to tell. |
747 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { | 792 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { |
748 SEL action = [item action]; | 793 SEL action = [item action]; |
749 BOOL enable = NO; | 794 BOOL enable = NO; |
750 if (action == @selector(commandDispatch:) || | 795 if (action == @selector(commandDispatch:) || |
751 action == @selector(commandDispatchUsingKeyModifiers:)) { | 796 action == @selector(commandDispatchUsingKeyModifiers:)) { |
752 NSInteger tag = [item tag]; | 797 NSInteger tag = [item tag]; |
753 if (browser_->command_updater()->SupportsCommand(tag)) { | 798 if (browser_->command_updater()->SupportsCommand(tag)) { |
754 // Generate return value (enabled state) | 799 // Generate return value (enabled state) |
755 enable = browser_->command_updater()->IsCommandEnabled(tag) ? YES : NO; | 800 enable = browser_->command_updater()->IsCommandEnabled(tag); |
756 switch (tag) { | 801 switch (tag) { |
757 case IDC_CLOSE_TAB: | 802 case IDC_CLOSE_TAB: |
758 // Disable "close tab" if we're not the key window or if there's only | 803 // Disable "close tab" if we're not the key window or if there's only |
759 // one tab. | 804 // one tab. |
760 enable &= [self numberOfTabs] > 1 && [[self window] isKeyWindow]; | 805 enable &= [self numberOfTabs] > 1 && [[self window] isKeyWindow]; |
761 break; | 806 break; |
762 case IDC_RESTORE_TAB: | 807 case IDC_RESTORE_TAB: |
763 // We have to ask the Browser manually if we can restore. The | 808 // We have to ask the Browser manually if we can restore. The |
764 // command updater doesn't know. | 809 // command updater doesn't know. |
765 enable &= browser_->CanRestoreTab(); | 810 enable &= browser_->CanRestoreTab(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 - (void)commandDispatch:(id)sender { | 847 - (void)commandDispatch:(id)sender { |
803 NSInteger tag = [sender tag]; | 848 NSInteger tag = [sender tag]; |
804 switch (tag) { | 849 switch (tag) { |
805 case IDC_RELOAD: | 850 case IDC_RELOAD: |
806 if ([sender isKindOfClass:[NSButton class]]) { | 851 if ([sender isKindOfClass:[NSButton class]]) { |
807 // We revert the bar when the reload button is pressed, but don't when | 852 // We revert the bar when the reload button is pressed, but don't when |
808 // Command+r is pressed (Issue 15464). Unlike the event handler function | 853 // Command+r is pressed (Issue 15464). Unlike the event handler function |
809 // for Windows (ToolbarView::ButtonPressed()), this function handles | 854 // for Windows (ToolbarView::ButtonPressed()), this function handles |
810 // both reload button press event and Command+r press event. Thus the | 855 // both reload button press event and Command+r press event. Thus the |
811 // 'isKindofClass' check is necessary. | 856 // 'isKindofClass' check is necessary. |
812 [self locationBar]->Revert(); | 857 [self locationBarBridge]->Revert(); |
813 } | 858 } |
814 break; | 859 break; |
815 } | 860 } |
816 browser_->ExecuteCommand(tag); | 861 browser_->ExecuteCommand(tag); |
817 } | 862 } |
818 | 863 |
819 // Same as |-commandDispatch:|, but executes commands using a disposition | 864 // Same as |-commandDispatch:|, but executes commands using a disposition |
820 // determined by the key flags. | 865 // determined by the key flags. |
821 - (void)commandDispatchUsingKeyModifiers:(id)sender { | 866 - (void)commandDispatchUsingKeyModifiers:(id)sender { |
822 NSInteger tag = [sender tag]; | 867 NSInteger tag = [sender tag]; |
(...skipping 11 matching lines...) Expand all Loading... |
834 // StatusBubble delegate method: tell the status bubble how far above the bottom | 879 // StatusBubble delegate method: tell the status bubble how far above the bottom |
835 // of the window it should position itself. | 880 // of the window it should position itself. |
836 - (float)verticalOffsetForStatusBubble { | 881 - (float)verticalOffsetForStatusBubble { |
837 return verticalOffsetForStatusBubble_; | 882 return verticalOffsetForStatusBubble_; |
838 } | 883 } |
839 | 884 |
840 - (GTMWindowSheetController*)sheetController { | 885 - (GTMWindowSheetController*)sheetController { |
841 return [tabStripController_ sheetController]; | 886 return [tabStripController_ sheetController]; |
842 } | 887 } |
843 | 888 |
844 - (LocationBar*)locationBar { | 889 - (LocationBar*)locationBarBridge { |
845 return [toolbarController_ locationBar]; | 890 return [toolbarController_ locationBarBridge]; |
846 } | 891 } |
847 | 892 |
848 - (StatusBubbleMac*)statusBubble { | 893 - (StatusBubbleMac*)statusBubble { |
849 return statusBubble_; | 894 return statusBubble_; |
850 } | 895 } |
851 | 896 |
852 - (void)updateToolbarWithContents:(TabContents*)tab | 897 - (void)updateToolbarWithContents:(TabContents*)tab |
853 shouldRestoreState:(BOOL)shouldRestore { | 898 shouldRestoreState:(BOOL)shouldRestore { |
854 [toolbarController_ updateToolbarWithContents:tab | 899 [toolbarController_ updateToolbarWithContents:tab |
855 shouldRestoreState:shouldRestore]; | 900 shouldRestoreState:shouldRestore]; |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1109 [bookmarkBarController_ setBookmarkBarEnabled:NO]; | 1154 [bookmarkBarController_ setBookmarkBarEnabled:NO]; |
1110 // Make room for more content area. | 1155 // Make room for more content area. |
1111 [[toolbarController_ view] removeFromSuperview]; | 1156 [[toolbarController_ view] removeFromSuperview]; |
1112 // Hide the menubar, and allow it to un-hide when moving the mouse | 1157 // Hide the menubar, and allow it to un-hide when moving the mouse |
1113 // to the top of the screen. Does this eliminate the need for an | 1158 // to the top of the screen. Does this eliminate the need for an |
1114 // info bubble describing how to exit fullscreen mode? | 1159 // info bubble describing how to exit fullscreen mode? |
1115 mac_util::RequestFullScreen(); | 1160 mac_util::RequestFullScreen(); |
1116 } else { | 1161 } else { |
1117 mac_util::ReleaseFullScreen(); | 1162 mac_util::ReleaseFullScreen(); |
1118 [[[self window] contentView] addSubview:[toolbarController_ view]]; | 1163 [[[self window] contentView] addSubview:[toolbarController_ view]]; |
1119 if (browser_->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR)) { | 1164 [bookmarkBarController_ setBookmarkBarEnabled:[self supportsBookmarkBar]]; |
1120 [bookmarkBarController_ setBookmarkBarEnabled:YES]; | |
1121 } | |
1122 } | 1165 } |
1123 | 1166 |
1124 // Force a relayout. | 1167 // Force a relayout. |
1125 [self layoutSubviews]; | 1168 [self layoutSubviews]; |
1126 } | 1169 } |
1127 | 1170 |
1128 - (NSWindow*)fullscreenWindow { | 1171 - (NSWindow*)fullscreenWindow { |
1129 return [[[FullscreenWindow alloc] initForScreen:[[self window] screen]] | 1172 return [[[FullscreenWindow alloc] initForScreen:[[self window] screen]] |
1130 autorelease]; | 1173 autorelease]; |
1131 } | 1174 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1180 | 1223 |
1181 - (NSInteger)numberOfTabs { | 1224 - (NSInteger)numberOfTabs { |
1182 return browser_->tabstrip_model()->count(); | 1225 return browser_->tabstrip_model()->count(); |
1183 } | 1226 } |
1184 | 1227 |
1185 - (NSString*)selectedTabTitle { | 1228 - (NSString*)selectedTabTitle { |
1186 TabContents* contents = browser_->tabstrip_model()->GetSelectedTabContents(); | 1229 TabContents* contents = browser_->tabstrip_model()->GetSelectedTabContents(); |
1187 return base::SysUTF16ToNSString(contents->GetTitle()); | 1230 return base::SysUTF16ToNSString(contents->GetTitle()); |
1188 } | 1231 } |
1189 | 1232 |
1190 // TYPE_POPUP is not normal (e.g. no tab strip) | 1233 - (BOOL)supportsWindowFeature:(int)feature { |
| 1234 return browser_->SupportsWindowFeature( |
| 1235 static_cast<Browser::WindowFeature>(feature)); |
| 1236 } |
| 1237 |
| 1238 // (Override of |TabWindowController| method.) |
| 1239 - (BOOL)hasTabStrip { |
| 1240 return [self supportsWindowFeature:Browser::FEATURE_TABSTRIP]; |
| 1241 } |
| 1242 |
| 1243 - (BOOL)hasTitleBar { |
| 1244 return [self supportsWindowFeature:Browser::FEATURE_TITLEBAR]; |
| 1245 } |
| 1246 |
| 1247 - (BOOL)hasToolbar { |
| 1248 return [self supportsWindowFeature:Browser::FEATURE_TOOLBAR]; |
| 1249 } |
| 1250 |
| 1251 - (BOOL)hasLocationBar { |
| 1252 return [self supportsWindowFeature:Browser::FEATURE_LOCATIONBAR]; |
| 1253 } |
| 1254 |
| 1255 - (BOOL)supportsBookmarkBar { |
| 1256 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
| 1257 } |
| 1258 |
1191 - (BOOL)isNormalWindow { | 1259 - (BOOL)isNormalWindow { |
1192 if (browser_->type() == Browser::TYPE_NORMAL) | 1260 return browser_->type() == Browser::TYPE_NORMAL; |
1193 return YES; | |
1194 return NO; | |
1195 } | 1261 } |
1196 | 1262 |
1197 - (void)selectTabWithContents:(TabContents*)newContents | 1263 - (void)selectTabWithContents:(TabContents*)newContents |
1198 previousContents:(TabContents*)oldContents | 1264 previousContents:(TabContents*)oldContents |
1199 atIndex:(NSInteger)index | 1265 atIndex:(NSInteger)index |
1200 userGesture:(bool)wasUserGesture { | 1266 userGesture:(bool)wasUserGesture { |
1201 DCHECK(oldContents != newContents); | 1267 DCHECK(oldContents != newContents); |
1202 | 1268 |
1203 // Update various elements that are interested in knowing the current | 1269 // Update various elements that are interested in knowing the current |
1204 // TabContents. | 1270 // TabContents. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1323 profile:browser_->profile() | 1389 profile:browser_->profile() |
1324 parent:node->GetParent() | 1390 parent:node->GetParent() |
1325 node:node | 1391 node:node |
1326 configuration:BookmarkEditor::SHOW_TREE | 1392 configuration:BookmarkEditor::SHOW_TREE |
1327 handler:NULL] | 1393 handler:NULL] |
1328 runAsModalSheet]; | 1394 runAsModalSheet]; |
1329 } | 1395 } |
1330 } | 1396 } |
1331 } | 1397 } |
1332 | 1398 |
| 1399 // If the browser is in incognito mode, install the image view to decorate |
| 1400 // the window at the upper right. Use the same base y coordinate as the |
| 1401 // tab strip. |
| 1402 - (void)installIncognitoBadge { |
| 1403 if (!browser_->profile()->IsOffTheRecord()) |
| 1404 return; |
| 1405 // Don't install if we're not a normal browser (ie, a popup). |
| 1406 if (![self isNormalWindow]) |
| 1407 return; |
| 1408 |
| 1409 static const float kOffset = 4; |
| 1410 NSString* incognitoPath = [mac_util::MainAppBundle() |
| 1411 pathForResource:@"otr_icon" |
| 1412 ofType:@"pdf"]; |
| 1413 scoped_nsobject<NSImage> incognitoImage( |
| 1414 [[NSImage alloc] initWithContentsOfFile:incognitoPath]); |
| 1415 const NSSize imageSize = [incognitoImage size]; |
| 1416 NSRect tabFrame = [[self tabStripView] frame]; |
| 1417 NSRect incognitoFrame = tabFrame; |
| 1418 incognitoFrame.origin.x = NSMaxX(incognitoFrame) - imageSize.width - |
| 1419 kOffset; |
| 1420 incognitoFrame.size = imageSize; |
| 1421 scoped_nsobject<IncognitoImageView> incognitoView( |
| 1422 [[IncognitoImageView alloc] initWithFrame:incognitoFrame]); |
| 1423 [incognitoView setImage:incognitoImage.get()]; |
| 1424 [incognitoView setWantsLayer:YES]; |
| 1425 [incognitoView setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; |
| 1426 scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]); |
| 1427 [shadow.get() setShadowColor:[NSColor colorWithCalibratedWhite:0.0 |
| 1428 alpha:0.5]]; |
| 1429 [shadow.get() setShadowOffset:NSMakeSize(0, -1)]; |
| 1430 [shadow setShadowBlurRadius:2.0]; |
| 1431 [incognitoView setShadow:shadow]; |
| 1432 |
| 1433 // Shrink the tab strip's width so there's no overlap and install the |
| 1434 // view. |
| 1435 tabFrame.size.width -= incognitoFrame.size.width + kOffset; |
| 1436 [[self tabStripView] setFrame:tabFrame]; |
| 1437 [[[[self window] contentView] superview] addSubview:incognitoView.get()]; |
| 1438 } |
| 1439 |
| 1440 // Undocumented method for multi-touch gestures in 10.5. Future OS's will |
| 1441 // likely add a public API, but the worst that will happen is that this will |
| 1442 // turn into dead code and just won't get called. |
| 1443 - (void)swipeWithEvent:(NSEvent*)event { |
| 1444 // Map forwards and backwards to history; left is positive, right is negative. |
| 1445 unsigned int command = 0; |
| 1446 if ([event deltaX] > 0.5) |
| 1447 command = IDC_BACK; |
| 1448 else if ([event deltaX] < -0.5) |
| 1449 command = IDC_FORWARD; |
| 1450 else if ([event deltaY] > 0.5) |
| 1451 ; // TODO(pinkerton): figure out page-up |
| 1452 else if ([event deltaY] < -0.5) |
| 1453 ; // TODO(pinkerton): figure out page-down |
| 1454 |
| 1455 // Ensure the command is valid first (ExecuteCommand() won't do that) and |
| 1456 // then make it so. |
| 1457 if (browser_->command_updater()->IsCommandEnabled(command)) |
| 1458 browser_->ExecuteCommand(command); |
| 1459 } |
| 1460 |
1333 // Delegate method called when window is resized. | 1461 // Delegate method called when window is resized. |
1334 - (void)windowDidResize:(NSNotification*)notification { | 1462 - (void)windowDidResize:(NSNotification*)notification { |
1335 // Resize (and possibly move) the status bubble. Note that we may get called | 1463 // Resize (and possibly move) the status bubble. Note that we may get called |
1336 // when the status bubble does not exist. | 1464 // when the status bubble does not exist. |
1337 if (statusBubble_) { | 1465 if (statusBubble_) { |
1338 statusBubble_->UpdateSizeAndPosition(); | 1466 statusBubble_->UpdateSizeAndPosition(); |
1339 } | 1467 } |
1340 } | 1468 } |
1341 | 1469 |
1342 // Handle the openLearnMoreAboutCrashLink: action from SadTabController when | 1470 // Handle the openLearnMoreAboutCrashLink: action from SadTabController when |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1376 [self resetWindowGrowthState]; | 1504 [self resetWindowGrowthState]; |
1377 } | 1505 } |
1378 | 1506 |
1379 // Delegate method called when window will be resized; not called for | 1507 // Delegate method called when window will be resized; not called for |
1380 // |-setFrame:display:|. | 1508 // |-setFrame:display:|. |
1381 - (NSSize)windowWillResize:(NSWindow*)sender toSize:(NSSize)frameSize { | 1509 - (NSSize)windowWillResize:(NSWindow*)sender toSize:(NSSize)frameSize { |
1382 [self resetWindowGrowthState]; | 1510 [self resetWindowGrowthState]; |
1383 return frameSize; | 1511 return frameSize; |
1384 } | 1512 } |
1385 | 1513 |
| 1514 // Delegate method: see |NSWindowDelegate| protocol. |
| 1515 - (id)windowWillReturnFieldEditor:(NSWindow*)sender toObject:(id)obj { |
| 1516 // Ask the toolbar controller if it wants to return a custom field editor |
| 1517 // for the specific object. |
| 1518 return [toolbarController_ customFieldEditorForObject:obj]; |
| 1519 } |
| 1520 |
1386 // (Needed for |BookmarkBarControllerDelegate| protocol.) | 1521 // (Needed for |BookmarkBarControllerDelegate| protocol.) |
1387 - (void)bookmarkBar:(BookmarkBarController*)controller | 1522 - (void)bookmarkBar:(BookmarkBarController*)controller |
1388 didChangeFromState:(bookmarks::VisualState)oldState | 1523 didChangeFromState:(bookmarks::VisualState)oldState |
1389 toState:(bookmarks::VisualState)newState { | 1524 toState:(bookmarks::VisualState)newState { |
1390 [toolbarController_ | 1525 [toolbarController_ |
1391 setDividerOpacity:[bookmarkBarController_ toolbarDividerOpacity]]; | 1526 setDividerOpacity:[bookmarkBarController_ toolbarDividerOpacity]]; |
1392 [self adjustToolbarAndBookmarkBarForCompression: | 1527 [self adjustToolbarAndBookmarkBarForCompression: |
1393 [controller getDesiredToolbarHeightCompression]]; | 1528 [controller getDesiredToolbarHeightCompression]]; |
1394 } | 1529 } |
1395 | 1530 |
(...skipping 25 matching lines...) Expand all Loading... |
1421 } | 1556 } |
1422 | 1557 |
1423 - (void)hideDropURLsIndicator { | 1558 - (void)hideDropURLsIndicator { |
1424 [tabStripController_ hideDropURLsIndicator]; | 1559 [tabStripController_ hideDropURLsIndicator]; |
1425 } | 1560 } |
1426 | 1561 |
1427 @end | 1562 @end |
1428 | 1563 |
1429 @implementation BrowserWindowController (Private) | 1564 @implementation BrowserWindowController (Private) |
1430 | 1565 |
1431 // If the browser is in incognito mode, install the image view to decorate | |
1432 // the window at the upper right. Use the same base y coordinate as the | |
1433 // tab strip. | |
1434 - (void)installIncognitoBadge { | |
1435 if (!browser_->profile()->IsOffTheRecord()) | |
1436 return; | |
1437 // Don't install if we're not a normal browser (ie, a popup). | |
1438 if (![self isNormalWindow]) | |
1439 return; | |
1440 | |
1441 static const float kOffset = 4; | |
1442 NSString* incognitoPath = [mac_util::MainAppBundle() | |
1443 pathForResource:@"otr_icon" | |
1444 ofType:@"pdf"]; | |
1445 scoped_nsobject<NSImage> incognitoImage( | |
1446 [[NSImage alloc] initWithContentsOfFile:incognitoPath]); | |
1447 const NSSize imageSize = [incognitoImage size]; | |
1448 NSRect tabFrame = [[self tabStripView] frame]; | |
1449 NSRect incognitoFrame = tabFrame; | |
1450 incognitoFrame.origin.x = NSMaxX(incognitoFrame) - imageSize.width - | |
1451 kOffset; | |
1452 incognitoFrame.size = imageSize; | |
1453 scoped_nsobject<IncognitoImageView> incognitoView( | |
1454 [[IncognitoImageView alloc] initWithFrame:incognitoFrame]); | |
1455 [incognitoView setImage:incognitoImage.get()]; | |
1456 [incognitoView setWantsLayer:YES]; | |
1457 [incognitoView setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; | |
1458 scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]); | |
1459 [shadow.get() setShadowColor:[NSColor colorWithCalibratedWhite:0.0 | |
1460 alpha:0.5]]; | |
1461 [shadow.get() setShadowOffset:NSMakeSize(0, -1)]; | |
1462 [shadow setShadowBlurRadius:2.0]; | |
1463 [incognitoView setShadow:shadow]; | |
1464 | |
1465 // Shrink the tab strip's width so there's no overlap and install the | |
1466 // view. | |
1467 tabFrame.size.width -= incognitoFrame.size.width + kOffset; | |
1468 [[self tabStripView] setFrame:tabFrame]; | |
1469 [[[[self window] contentView] superview] addSubview:incognitoView.get()]; | |
1470 } | |
1471 | |
1472 - (void)saveWindowPositionIfNeeded { | 1566 - (void)saveWindowPositionIfNeeded { |
1473 if (browser_ != BrowserList::GetLastActive()) | 1567 if (browser_ != BrowserList::GetLastActive()) |
1474 return; | 1568 return; |
1475 | 1569 |
1476 if (!g_browser_process || !g_browser_process->local_state() || | 1570 if (!g_browser_process || !g_browser_process->local_state() || |
1477 !browser_->ShouldSaveWindowPlacement()) | 1571 !browser_->ShouldSaveWindowPlacement()) |
1478 return; | 1572 return; |
1479 | 1573 |
1480 [self saveWindowPositionToPrefs:g_browser_process->local_state()]; | 1574 [self saveWindowPositionToPrefs:g_browser_process->local_state()]; |
1481 } | 1575 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1530 defaultSheetRect.origin.y = toolbarFrame.origin.y; | 1624 defaultSheetRect.origin.y = toolbarFrame.origin.y; |
1531 break; | 1625 break; |
1532 } | 1626 } |
1533 case bookmarks::kInvalidState: | 1627 case bookmarks::kInvalidState: |
1534 default: | 1628 default: |
1535 NOTREACHED(); | 1629 NOTREACHED(); |
1536 } | 1630 } |
1537 return defaultSheetRect; | 1631 return defaultSheetRect; |
1538 } | 1632 } |
1539 | 1633 |
1540 // Undocumented method for multi-touch gestures in 10.5. Future OS's will | |
1541 // likely add a public API, but the worst that will happen is that this will | |
1542 // turn into dead code and just won't get called. | |
1543 - (void)swipeWithEvent:(NSEvent*)event { | |
1544 // Map forwards and backwards to history; left is positive, right is negative. | |
1545 unsigned int command = 0; | |
1546 if ([event deltaX] > 0.5) | |
1547 command = IDC_BACK; | |
1548 else if ([event deltaX] < -0.5) | |
1549 command = IDC_FORWARD; | |
1550 else if ([event deltaY] > 0.5) | |
1551 ; // TODO(pinkerton): figure out page-up | |
1552 else if ([event deltaY] < -0.5) | |
1553 ; // TODO(pinkerton): figure out page-down | |
1554 | |
1555 // Ensure the command is valid first (ExecuteCommand() won't do that) and | |
1556 // then make it so. | |
1557 if (browser_->command_updater()->IsCommandEnabled(command)) | |
1558 browser_->ExecuteCommand(command); | |
1559 } | |
1560 | |
1561 - (id)windowWillReturnFieldEditor:(NSWindow*)sender toObject:(id)obj { | |
1562 // Ask the toolbar controller if it wants to return a custom field editor | |
1563 // for the specific object. | |
1564 return [toolbarController_ customFieldEditorForObject:obj]; | |
1565 } | |
1566 | |
1567 - (void)setTheme { | 1634 - (void)setTheme { |
1568 ThemeProvider* theme_provider = browser_->profile()->GetThemeProvider(); | 1635 ThemeProvider* theme_provider = browser_->profile()->GetThemeProvider(); |
1569 BrowserThemeProvider* browser_theme_provider = | 1636 BrowserThemeProvider* browser_theme_provider = |
1570 static_cast<BrowserThemeProvider*>(theme_provider); | 1637 static_cast<BrowserThemeProvider*>(theme_provider); |
1571 if (browser_theme_provider) { | 1638 if (browser_theme_provider) { |
1572 bool offtheRecord = browser_->profile()->IsOffTheRecord(); | 1639 bool offtheRecord = browser_->profile()->IsOffTheRecord(); |
1573 GTMTheme* theme = | 1640 GTMTheme* theme = |
1574 [GTMTheme themeWithBrowserThemeProvider:browser_theme_provider | 1641 [GTMTheme themeWithBrowserThemeProvider:browser_theme_provider |
1575 isOffTheRecord:offtheRecord]; | 1642 isOffTheRecord:offtheRecord]; |
1576 theme_.reset([theme retain]); | 1643 theme_.reset([theme retain]); |
1577 } | 1644 } |
1578 } | 1645 } |
1579 | 1646 |
1580 // Private method to layout browser window subviews. Positions the toolbar and | |
1581 // the infobar above the tab content area. Positions the download shelf below | |
1582 // the tab content area. If the toolbar is not a child of the contentview, this | |
1583 // method will not leave room for it. If we are currently running in fullscreen | |
1584 // mode, or if the tabstrip is not a descendant of the window, this method fills | |
1585 // the entire content area. Otherwise, this method places the topmost view | |
1586 // directly beneath the tabstrip. | |
1587 - (void)layoutSubviews { | 1647 - (void)layoutSubviews { |
1588 NSWindow* window = [self window]; | 1648 NSWindow* window = [self window]; |
1589 NSView* contentView = [window contentView]; | 1649 NSView* contentView = [window contentView]; |
1590 NSRect contentFrame = [contentView frame]; | 1650 NSRect contentFrame = [contentView frame]; |
1591 int maxY = NSMaxY(contentFrame); | 1651 CGFloat maxY = NSMaxY(contentFrame); |
1592 int minY = NSMinY(contentFrame); | 1652 CGFloat minY = NSMinY(contentFrame); |
1593 if (![self isFullscreen] && [self isNormalWindow]) { | 1653 CGFloat width = NSWidth(contentFrame); |
| 1654 if ([self hasTabStrip]) |
1594 maxY = NSMinY([[self tabStripView] frame]); | 1655 maxY = NSMinY([[self tabStripView] frame]); |
1595 } | |
1596 DCHECK_GE(maxY, minY); | 1656 DCHECK_GE(maxY, minY); |
1597 | 1657 |
1598 // Suppress title drawing for normal windows (popups use normal | 1658 // Suppress title drawing if necessary. |
1599 // window title bars). | 1659 if ([window respondsToSelector:@selector(setShouldHideTitle:)]) |
1600 if ([window respondsToSelector:@selector(setShouldHideTitle:)]) { | 1660 [(id)window setShouldHideTitle:![self hasTitleBar]]; |
1601 [(id)window setShouldHideTitle:[self isNormalWindow]]; | |
1602 } | |
1603 | 1661 |
1604 // Place the toolbar at the top of the reserved area, but only if we're not in | 1662 // Place the toolbar at the top of the reserved area. |
1605 // fullscreen mode. | 1663 maxY = [self layoutToolbarAtMaxY:maxY width:width]; |
1606 NSView* toolbarView = [toolbarController_ view]; | |
1607 NSRect toolbarFrame = [toolbarView frame]; | |
1608 if (![self isFullscreen]) { | |
1609 // The toolbar is present in the window, so we make room for it. | |
1610 toolbarFrame.origin.x = 0; | |
1611 toolbarFrame.origin.y = maxY - NSHeight(toolbarFrame); | |
1612 toolbarFrame.size.width = NSWidth(contentFrame); | |
1613 maxY -= NSHeight(toolbarFrame); | |
1614 } | |
1615 [toolbarView setFrame:toolbarFrame]; | |
1616 | |
1617 // If we are currently displaying the NTP detached bookmark bar or animating | |
1618 // to/from it (from/to anything else), we display the bookmark bar below the | |
1619 // infobar. | |
1620 BOOL placeBookmarkBarBelowInfobar = | |
1621 [bookmarkBarController_ isInState:bookmarks::kDetachedState] || | |
1622 [bookmarkBarController_ isAnimatingToState:bookmarks::kDetachedState] || | |
1623 [bookmarkBarController_ isAnimatingFromState:bookmarks::kDetachedState]; | |
1624 | 1664 |
1625 // If we're not displaying the bookmark bar below the infobar, then it goes | 1665 // If we're not displaying the bookmark bar below the infobar, then it goes |
1626 // immediately below the toolbar. | 1666 // immediately below the toolbar. |
1627 if (!placeBookmarkBarBelowInfobar) { | 1667 BOOL placeBookmarkBarBelowInfoBar = [self placeBookmarkBarBelowInfoBar]; |
1628 NSView* bookmarkBarView = [bookmarkBarController_ view]; | 1668 if (!placeBookmarkBarBelowInfoBar) |
1629 [bookmarkBarView setHidden:NO]; | 1669 maxY = [self layoutBookmarkBarAtMaxY:maxY width:width]; |
1630 NSRect bookmarkBarFrame = [bookmarkBarView frame]; | |
1631 bookmarkBarFrame.origin.y = maxY - NSHeight(bookmarkBarFrame); | |
1632 bookmarkBarFrame.size.width = NSWidth(contentFrame); | |
1633 [bookmarkBarView setFrame:bookmarkBarFrame]; | |
1634 maxY -= NSHeight(bookmarkBarFrame); | |
1635 } | |
1636 | 1670 |
1637 // Place the infobar container in place below the toolbar. | 1671 // Place the infobar container in place below the toolbar. |
1638 NSView* infoBarView = [infoBarContainerController_ view]; | 1672 maxY = [self layoutInfoBarAtMaxY:maxY width:width]; |
1639 NSRect infoBarFrame = [infoBarView frame]; | |
1640 infoBarFrame.origin.y = maxY - NSHeight(infoBarFrame); | |
1641 infoBarFrame.size.width = NSWidth(contentFrame); | |
1642 [infoBarView setFrame:infoBarFrame]; | |
1643 maxY -= NSHeight(infoBarFrame); | |
1644 | 1673 |
1645 // If the bookmark bar is detached, place it at the bottom of the stack. | 1674 // If the bookmark bar is detached, place it at the bottom of the stack. |
1646 if (placeBookmarkBarBelowInfobar) { | 1675 if (placeBookmarkBarBelowInfoBar) |
1647 NSView* bookmarkBarView = [bookmarkBarController_ view]; | 1676 maxY = [self layoutBookmarkBarAtMaxY:maxY width:width]; |
1648 [bookmarkBarView setHidden:NO]; | |
1649 NSRect bookmarkBarFrame = [bookmarkBarView frame]; | |
1650 bookmarkBarFrame.origin.y = maxY - NSHeight(bookmarkBarFrame); | |
1651 bookmarkBarFrame.size.width = NSWidth(contentFrame); | |
1652 [bookmarkBarView setFrame:bookmarkBarFrame]; | |
1653 maxY -= NSHeight(bookmarkBarFrame); | |
1654 | 1677 |
1655 // TODO(viettrungluu): this really doesn't belong here. | 1678 // Place the download shelf, if any, at the bottom of the view. |
1656 [bookmarkBarController_ layoutSubviews]; | 1679 minY = [self layoutDownloadShelfAtMinY:minY width:width]; |
1657 } | |
1658 | 1680 |
1659 // If there's a download shelf, place it at the bottom of the view. | 1681 // Finally, the content area takes up all of the remaining space. |
1660 if (downloadShelfController_.get()) { | 1682 [self layoutTabContentAreaAtMinY:minY maxY:maxY width:width]; |
1661 NSView* downloadView = [downloadShelfController_ view]; | |
1662 NSRect downloadFrame = [downloadView frame]; | |
1663 downloadFrame.origin.y = minY; | |
1664 downloadFrame.size.width = NSWidth(contentFrame); | |
1665 [downloadView setFrame:downloadFrame]; | |
1666 minY += NSHeight(downloadFrame); | |
1667 } | |
1668 | |
1669 // Finally, the tabContentArea takes up all of the remaining space. | |
1670 NSView* tabContentView = [self tabContentArea]; | |
1671 NSRect tabContentFrame = [tabContentView frame]; | |
1672 tabContentFrame.origin.y = minY; | |
1673 tabContentFrame.size.height = maxY - minY; | |
1674 tabContentFrame.size.width = NSWidth(contentFrame); | |
1675 [tabContentView setFrame:tabContentFrame]; | |
1676 | 1683 |
1677 // Position the find bar relative to the infobar container. | 1684 // Position the find bar relative to the infobar container. |
1678 [findBarCocoaController_ | 1685 [findBarCocoaController_ |
1679 positionFindBarView:[infoBarContainerController_ view]]; | 1686 positionFindBarView:[infoBarContainerController_ view]]; |
1680 | 1687 |
| 1688 // Place the status bubble at the bottom of the content area. |
1681 verticalOffsetForStatusBubble_ = minY; | 1689 verticalOffsetForStatusBubble_ = minY; |
1682 | 1690 |
1683 // Normally, we don't need to tell the toolbar whether or not to show the | 1691 // Normally, we don't need to tell the toolbar whether or not to show the |
1684 // divider, but things break down during animation. | 1692 // divider, but things break down during animation. |
1685 [toolbarController_ | 1693 [toolbarController_ |
1686 setDividerOpacity:[bookmarkBarController_ toolbarDividerOpacity]]; | 1694 setDividerOpacity:[bookmarkBarController_ toolbarDividerOpacity]]; |
1687 } | 1695 } |
1688 | 1696 |
| 1697 - (CGFloat)layoutToolbarAtMaxY:(CGFloat)maxY width:(CGFloat)width { |
| 1698 NSView* toolbarView = [toolbarController_ view]; |
| 1699 NSRect toolbarFrame = [toolbarView frame]; |
| 1700 if ([self hasToolbar]) { |
| 1701 // The toolbar is present in the window, so we make room for it. |
| 1702 DCHECK(![toolbarView isHidden]); |
| 1703 toolbarFrame.origin.x = 0; |
| 1704 toolbarFrame.origin.y = maxY - NSHeight(toolbarFrame); |
| 1705 toolbarFrame.size.width = width; |
| 1706 maxY -= NSHeight(toolbarFrame); |
| 1707 } else { |
| 1708 if ([self hasLocationBar]) { |
| 1709 // Location bar is present with no toolbar. Put a border of |
| 1710 // |kLocBar...Inset| pixels around the location bar. |
| 1711 // TODO(viettrungluu): This is moderately ridiculous. The toolbar should |
| 1712 // really be aware of what its height should be (the way the toolbar |
| 1713 // compression stuff is currently set up messes things up). |
| 1714 DCHECK(![toolbarView isHidden]); |
| 1715 // TODO(viettrungluu): We can argue about the "correct" insetting; I like |
| 1716 // the following best, though arguably 0 inset is better/more correct. |
| 1717 const CGFloat kLocBarLeftRightInset = 1; |
| 1718 const CGFloat kLocBarTopInset = 0; |
| 1719 const CGFloat kLocBarBottomInset = 1; |
| 1720 toolbarFrame.origin.x = kLocBarLeftRightInset; |
| 1721 toolbarFrame.origin.y = maxY - NSHeight(toolbarFrame) - kLocBarTopInset; |
| 1722 toolbarFrame.size.width = width - 2 * kLocBarLeftRightInset; |
| 1723 maxY -= kLocBarTopInset + NSHeight(toolbarFrame) + kLocBarBottomInset; |
| 1724 } else { |
| 1725 DCHECK([toolbarView isHidden]); |
| 1726 } |
| 1727 } |
| 1728 [toolbarView setFrame:toolbarFrame]; |
| 1729 return maxY; |
| 1730 } |
| 1731 |
| 1732 - (CGFloat)layoutBookmarkBarAtMaxY:(CGFloat)maxY width:(CGFloat)width { |
| 1733 NSView* bookmarkBarView = [bookmarkBarController_ view]; |
| 1734 [bookmarkBarView setHidden:NO]; |
| 1735 NSRect bookmarkBarFrame = [bookmarkBarView frame]; |
| 1736 bookmarkBarFrame.origin.y = maxY - NSHeight(bookmarkBarFrame); |
| 1737 bookmarkBarFrame.size.width = width; |
| 1738 [bookmarkBarView setFrame:bookmarkBarFrame]; |
| 1739 maxY -= NSHeight(bookmarkBarFrame); |
| 1740 |
| 1741 // TODO(viettrungluu): Does this really belong here? Calling it shouldn't be |
| 1742 // necessary in the non-NTP case. |
| 1743 [bookmarkBarController_ layoutSubviews]; |
| 1744 |
| 1745 return maxY; |
| 1746 } |
| 1747 |
| 1748 - (CGFloat)layoutInfoBarAtMaxY:(CGFloat)maxY width:(CGFloat)width { |
| 1749 NSView* infoBarView = [infoBarContainerController_ view]; |
| 1750 NSRect infoBarFrame = [infoBarView frame]; |
| 1751 infoBarFrame.origin.y = maxY - NSHeight(infoBarFrame); |
| 1752 infoBarFrame.size.width = width; |
| 1753 [infoBarView setFrame:infoBarFrame]; |
| 1754 maxY -= NSHeight(infoBarFrame); |
| 1755 return maxY; |
| 1756 } |
| 1757 |
| 1758 - (BOOL)placeBookmarkBarBelowInfoBar { |
| 1759 // If we are currently displaying the NTP detached bookmark bar or animating |
| 1760 // to/from it (from/to anything else), we display the bookmark bar below the |
| 1761 // infobar. |
| 1762 return [bookmarkBarController_ isInState:bookmarks::kDetachedState] || |
| 1763 [bookmarkBarController_ isAnimatingToState:bookmarks::kDetachedState] || |
| 1764 [bookmarkBarController_ isAnimatingFromState:bookmarks::kDetachedState]; |
| 1765 } |
| 1766 |
| 1767 - (CGFloat)layoutDownloadShelfAtMinY:(CGFloat)minY width:(CGFloat)width { |
| 1768 if (downloadShelfController_.get()) { |
| 1769 NSView* downloadView = [downloadShelfController_ view]; |
| 1770 NSRect downloadFrame = [downloadView frame]; |
| 1771 downloadFrame.origin.y = minY; |
| 1772 downloadFrame.size.width = width; |
| 1773 [downloadView setFrame:downloadFrame]; |
| 1774 minY += NSHeight(downloadFrame); |
| 1775 } |
| 1776 return minY; |
| 1777 } |
| 1778 |
| 1779 - (void)layoutTabContentAreaAtMinY:(CGFloat)minY |
| 1780 maxY:(CGFloat)maxY |
| 1781 width:(CGFloat)width { |
| 1782 NSView* tabContentView = [self tabContentArea]; |
| 1783 NSRect tabContentFrame = [tabContentView frame]; |
| 1784 tabContentFrame.origin.y = minY; |
| 1785 tabContentFrame.size.height = maxY - minY; |
| 1786 tabContentFrame.size.width = width; |
| 1787 [tabContentView setFrame:tabContentFrame]; |
| 1788 } |
| 1789 |
1689 - (BOOL)shouldShowBookmarkBar { | 1790 - (BOOL)shouldShowBookmarkBar { |
1690 DCHECK(browser_.get()); | 1791 DCHECK(browser_.get()); |
1691 return browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) ? | 1792 return browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) ? |
1692 YES : NO; | 1793 YES : NO; |
1693 } | 1794 } |
1694 | 1795 |
1695 - (BOOL)shouldShowDetachedBookmarkBar { | 1796 - (BOOL)shouldShowDetachedBookmarkBar { |
1696 DCHECK(browser_.get()); | 1797 DCHECK(browser_.get()); |
1697 TabContents* contents = browser_->GetSelectedTabContents(); | 1798 TabContents* contents = browser_->GetSelectedTabContents(); |
1698 return (contents && contents->ShouldShowBookmarkBar()) ? YES : NO; | 1799 return (contents && contents->ShouldShowBookmarkBar()) ? YES : NO; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1867 if (frameOverlayInactiveImage) { | 1968 if (frameOverlayInactiveImage) { |
1868 [theme setValue:frameOverlayInactiveImage | 1969 [theme setValue:frameOverlayInactiveImage |
1869 forAttribute:@"overlay" | 1970 forAttribute:@"overlay" |
1870 style:GTMThemeStyleWindow | 1971 style:GTMThemeStyleWindow |
1871 state:GTMThemeStateInactiveWindow]; | 1972 state:GTMThemeStateInactiveWindow]; |
1872 } | 1973 } |
1873 | 1974 |
1874 return theme; | 1975 return theme; |
1875 } | 1976 } |
1876 @end | 1977 @end |
OLD | NEW |