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