OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #import "chrome/browser/cocoa/browser_window_controller.h" | 5 #import "chrome/browser/cocoa/browser_window_controller.h" |
6 | 6 |
7 #include <Carbon/Carbon.h> | 7 #include <Carbon/Carbon.h> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/l10n_util_mac.h" | 10 #include "app/l10n_util_mac.h" |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 // windows may get resized later on in this function, once the actual size | 231 // windows may get resized later on in this function, once the actual size |
232 // of the toolbar/tabstrip is known. | 232 // of the toolbar/tabstrip is known. |
233 windowShim_->SetBounds(windowRect); | 233 windowShim_->SetBounds(windowRect); |
234 | 234 |
235 // Puts the incognito badge on the window frame, if necessary. | 235 // Puts the incognito badge on the window frame, if necessary. |
236 [self installIncognitoBadge]; | 236 [self installIncognitoBadge]; |
237 | 237 |
238 // Create a sub-controller for the docked devTools and add its view to the | 238 // Create a sub-controller for the docked devTools and add its view to the |
239 // hierarchy. This must happen before the sidebar controller is | 239 // hierarchy. This must happen before the sidebar controller is |
240 // instantiated. | 240 // instantiated. |
241 devToolsController_.reset([[DevToolsController alloc] init]); | 241 devToolsController_.reset( |
| 242 [[DevToolsController alloc] initWithDelegate:self]); |
242 [[devToolsController_ view] setFrame:[[self tabContentArea] bounds]]; | 243 [[devToolsController_ view] setFrame:[[self tabContentArea] bounds]]; |
243 [[self tabContentArea] addSubview:[devToolsController_ view]]; | 244 [[self tabContentArea] addSubview:[devToolsController_ view]]; |
244 | 245 |
245 // Create a sub-controller for the docked sidebar and add its view to the | 246 // Create a sub-controller for the docked sidebar and add its view to the |
246 // hierarchy. This must happen before the previewable contents controller | 247 // hierarchy. This must happen before the previewable contents controller |
247 // is instantiated. | 248 // is instantiated. |
248 sidebarController_.reset([[SidebarController alloc] init]); | 249 sidebarController_.reset([[SidebarController alloc] initWithDelegate:self]); |
249 [[sidebarController_ view] setFrame:[[devToolsController_ view] bounds]]; | 250 [[sidebarController_ view] setFrame:[[devToolsController_ view] bounds]]; |
250 [[devToolsController_ view] addSubview:[sidebarController_ view]]; | 251 [[devToolsController_ view] addSubview:[sidebarController_ view]]; |
251 | 252 |
252 // Create the previewable contents controller. This provides the switch | 253 // Create the previewable contents controller. This provides the switch |
253 // view that TabStripController needs. | 254 // view that TabStripController needs. |
254 previewableContentsController_.reset( | 255 previewableContentsController_.reset( |
255 [[PreviewableContentsController alloc] init]); | 256 [[PreviewableContentsController alloc] init]); |
256 [[previewableContentsController_ view] | 257 [[previewableContentsController_ view] |
257 setFrame:[[sidebarController_ view] bounds]]; | 258 setFrame:[[sidebarController_ view] bounds]]; |
258 [[sidebarController_ view] | 259 [[sidebarController_ view] |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 - (void)attachConstrainedWindow:(ConstrainedWindowMac*)window { | 436 - (void)attachConstrainedWindow:(ConstrainedWindowMac*)window { |
436 [tabStripController_ attachConstrainedWindow:window]; | 437 [tabStripController_ attachConstrainedWindow:window]; |
437 } | 438 } |
438 | 439 |
439 - (void)removeConstrainedWindow:(ConstrainedWindowMac*)window { | 440 - (void)removeConstrainedWindow:(ConstrainedWindowMac*)window { |
440 [tabStripController_ removeConstrainedWindow:window]; | 441 [tabStripController_ removeConstrainedWindow:window]; |
441 } | 442 } |
442 | 443 |
443 - (void)updateDevToolsForContents:(TabContents*)contents { | 444 - (void)updateDevToolsForContents:(TabContents*)contents { |
444 [devToolsController_ updateDevToolsForTabContents:contents]; | 445 [devToolsController_ updateDevToolsForTabContents:contents]; |
| 446 [devToolsController_ ensureContentsVisible]; |
445 } | 447 } |
446 | 448 |
447 - (void)updateSidebarForContents:(TabContents*)contents { | 449 - (void)updateSidebarForContents:(TabContents*)contents { |
448 [sidebarController_ updateSidebarForTabContents:contents]; | 450 [sidebarController_ updateSidebarForTabContents:contents]; |
| 451 [sidebarController_ ensureContentsVisible]; |
449 } | 452 } |
450 | 453 |
451 // Called when the user wants to close a window or from the shutdown process. | 454 // Called when the user wants to close a window or from the shutdown process. |
452 // The Browser object is in control of whether or not we're allowed to close. It | 455 // The Browser object is in control of whether or not we're allowed to close. It |
453 // may defer closing due to several states, such as onUnload handlers needing to | 456 // may defer closing due to several states, such as onUnload handlers needing to |
454 // be fired. If closing is deferred, the Browser will handle the processing | 457 // be fired. If closing is deferred, the Browser will handle the processing |
455 // required to get us to the closing state and (by watching for all the tabs | 458 // required to get us to the closing state and (by watching for all the tabs |
456 // going away) will again call to close the window when it's finally ready. | 459 // going away) will again call to close the window when it's finally ready. |
457 - (BOOL)windowShouldClose:(id)sender { | 460 - (BOOL)windowShouldClose:(id)sender { |
458 // Disable updates while closing all tabs to avoid flickering. | 461 // Disable updates while closing all tabs to avoid flickering. |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 - (void)updateToolbarWithContents:(TabContents*)tab | 1039 - (void)updateToolbarWithContents:(TabContents*)tab |
1037 shouldRestoreState:(BOOL)shouldRestore { | 1040 shouldRestoreState:(BOOL)shouldRestore { |
1038 [toolbarController_ updateToolbarWithContents:tab | 1041 [toolbarController_ updateToolbarWithContents:tab |
1039 shouldRestoreState:shouldRestore]; | 1042 shouldRestoreState:shouldRestore]; |
1040 } | 1043 } |
1041 | 1044 |
1042 - (void)setStarredState:(BOOL)isStarred { | 1045 - (void)setStarredState:(BOOL)isStarred { |
1043 [toolbarController_ setStarredState:isStarred]; | 1046 [toolbarController_ setStarredState:isStarred]; |
1044 } | 1047 } |
1045 | 1048 |
1046 // Return the rect, in WebKit coordinates (flipped), of the window's grow box | |
1047 // in the coordinate system of the content area of the currently selected tab. | |
1048 // |windowGrowBox| needs to be in the window's coordinate system. | |
1049 - (NSRect)selectedTabGrowBoxRect { | |
1050 NSWindow* window = [self window]; | |
1051 if (![window respondsToSelector:@selector(_growBoxRect)]) | |
1052 return NSZeroRect; | |
1053 | |
1054 // Before we return a rect, we need to convert it from window coordinates | |
1055 // to tab content area coordinates and flip the coordinate system. | |
1056 NSRect growBoxRect = | |
1057 [[self tabContentArea] convertRect:[window _growBoxRect] fromView:nil]; | |
1058 growBoxRect.origin.y = | |
1059 [[self tabContentArea] frame].size.height - growBoxRect.size.height - | |
1060 growBoxRect.origin.y; | |
1061 return growBoxRect; | |
1062 } | |
1063 | |
1064 // Accept tabs from a BrowserWindowController with the same Profile. | 1049 // Accept tabs from a BrowserWindowController with the same Profile. |
1065 - (BOOL)canReceiveFrom:(TabWindowController*)source { | 1050 - (BOOL)canReceiveFrom:(TabWindowController*)source { |
1066 if (![source isKindOfClass:[BrowserWindowController class]]) { | 1051 if (![source isKindOfClass:[BrowserWindowController class]]) { |
1067 return NO; | 1052 return NO; |
1068 } | 1053 } |
1069 | 1054 |
1070 BrowserWindowController* realSource = | 1055 BrowserWindowController* realSource = |
1071 static_cast<BrowserWindowController*>(source); | 1056 static_cast<BrowserWindowController*>(source); |
1072 if (browser_->profile() != realSource->browser_->profile()) { | 1057 if (browser_->profile() != realSource->browser_->profile()) { |
1073 return NO; | 1058 return NO; |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1343 - (NSRect)regularWindowFrame { | 1328 - (NSRect)regularWindowFrame { |
1344 return [self isFullscreen] ? [savedRegularWindow_ frame] : | 1329 return [self isFullscreen] ? [savedRegularWindow_ frame] : |
1345 [[self window] frame]; | 1330 [[self window] frame]; |
1346 } | 1331 } |
1347 | 1332 |
1348 // (Override of |TabWindowController| method.) | 1333 // (Override of |TabWindowController| method.) |
1349 - (BOOL)hasTabStrip { | 1334 - (BOOL)hasTabStrip { |
1350 return [self supportsWindowFeature:Browser::FEATURE_TABSTRIP]; | 1335 return [self supportsWindowFeature:Browser::FEATURE_TABSTRIP]; |
1351 } | 1336 } |
1352 | 1337 |
| 1338 // TabContentsViewControllerDelegate protocol. |
| 1339 - (void)tabContentsViewFrameWillChange:(TabContentsViewController*)source |
| 1340 frameRect:(NSRect)frameRect { |
| 1341 TabContents* contents = [source tabContents]; |
| 1342 RenderWidgetHostView* render_widget_host_view = contents ? |
| 1343 contents->GetRenderWidgetHostView() : NULL; |
| 1344 if (!render_widget_host_view) |
| 1345 return; |
| 1346 |
| 1347 gfx::Rect reserved_rect; |
| 1348 |
| 1349 NSWindow* window = [self window]; |
| 1350 if ([window respondsToSelector:@selector(_growBoxRect)]) { |
| 1351 NSView* view = [source view]; |
| 1352 NSRect windowGrowBoxRect = [window _growBoxRect]; |
| 1353 NSRect viewRect = [[view superview] convertRect:frameRect toView:nil]; |
| 1354 NSRect growBoxRect = NSIntersectionRect(windowGrowBoxRect, viewRect); |
| 1355 if (!NSIsEmptyRect(growBoxRect)) { |
| 1356 // Before we return a rect, we need to convert it from window coordinates |
| 1357 // to content area coordinates and flip the coordinate system. |
| 1358 // Superview is used here because, first, it's a frame rect, so it is |
| 1359 // specified in the parent's coordinates and, second, view is not |
| 1360 // positioned yet. |
| 1361 growBoxRect = [[view superview] convertRect:growBoxRect fromView:nil]; |
| 1362 growBoxRect.origin.y = |
| 1363 NSHeight(frameRect) - NSHeight(growBoxRect); |
| 1364 growBoxRect = |
| 1365 NSOffsetRect(growBoxRect, -frameRect.origin.x, -frameRect.origin.y); |
| 1366 |
| 1367 reserved_rect = |
| 1368 gfx::Rect(growBoxRect.origin.x, growBoxRect.origin.y, |
| 1369 growBoxRect.size.width, growBoxRect.size.height); |
| 1370 } |
| 1371 } |
| 1372 |
| 1373 render_widget_host_view->set_reserved_contents_rect(reserved_rect); |
| 1374 } |
| 1375 |
1353 // TabStripControllerDelegate protocol. | 1376 // TabStripControllerDelegate protocol. |
1354 - (void)onSelectTabWithContents:(TabContents*)contents { | 1377 - (void)onSelectTabWithContents:(TabContents*)contents { |
1355 // Update various elements that are interested in knowing the current | 1378 // Update various elements that are interested in knowing the current |
1356 // TabContents. | 1379 // TabContents. |
1357 | 1380 |
1358 // Update all the UI bits. | 1381 // Update all the UI bits. |
1359 windowShim_->UpdateTitleBar(); | 1382 windowShim_->UpdateTitleBar(); |
1360 | 1383 |
1361 [self updateSidebarForContents:contents]; | 1384 [sidebarController_ updateSidebarForTabContents:contents]; |
1362 [self updateDevToolsForContents:contents]; | 1385 [devToolsController_ updateDevToolsForTabContents:contents]; |
1363 | 1386 |
1364 // Update the bookmark bar. | 1387 // Update the bookmark bar. |
1365 // Must do it after sidebar and devtools update, otherwise bookmark bar might | 1388 // Must do it after sidebar and devtools update, otherwise bookmark bar might |
1366 // call resizeView -> layoutSubviews and cause unnecessary relayout. | 1389 // call resizeView -> layoutSubviews and cause unnecessary relayout. |
1367 // TODO(viettrungluu): perhaps update to not terminate running animations (if | 1390 // TODO(viettrungluu): perhaps update to not terminate running animations (if |
1368 // applicable)? | 1391 // applicable)? |
1369 [self updateBookmarkBarVisibilityWithAnimation:NO]; | 1392 [self updateBookmarkBarVisibilityWithAnimation:NO]; |
1370 | 1393 |
1371 [infoBarContainerController_ changeTabContents:contents]; | 1394 [infoBarContainerController_ changeTabContents:contents]; |
| 1395 |
| 1396 // Update devTools and sidebar contents after size for all views is set. |
| 1397 [sidebarController_ ensureContentsVisible]; |
| 1398 [devToolsController_ ensureContentsVisible]; |
1372 } | 1399 } |
1373 | 1400 |
1374 - (void)onReplaceTabWithContents:(TabContents*)contents { | 1401 - (void)onReplaceTabWithContents:(TabContents*)contents { |
1375 // This is only called when instant results are committed. Simply remove the | 1402 // This is only called when instant results are committed. Simply remove the |
1376 // preview view; the tab strip controller will reinstall the view as the | 1403 // preview view; the tab strip controller will reinstall the view as the |
1377 // active view. | 1404 // active view. |
1378 [previewableContentsController_ hidePreview]; | 1405 [previewableContentsController_ hidePreview]; |
1379 [self updateBookmarkBarVisibilityWithAnimation:NO]; | 1406 [self updateBookmarkBarVisibilityWithAnimation:NO]; |
1380 } | 1407 } |
1381 | 1408 |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2013 | 2040 |
2014 - (BOOL)supportsBookmarkBar { | 2041 - (BOOL)supportsBookmarkBar { |
2015 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; | 2042 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
2016 } | 2043 } |
2017 | 2044 |
2018 - (BOOL)isNormalWindow { | 2045 - (BOOL)isNormalWindow { |
2019 return browser_->type() == Browser::TYPE_NORMAL; | 2046 return browser_->type() == Browser::TYPE_NORMAL; |
2020 } | 2047 } |
2021 | 2048 |
2022 @end // @implementation BrowserWindowController(WindowType) | 2049 @end // @implementation BrowserWindowController(WindowType) |
OLD | NEW |