| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/cocoa/browser_window_controller.h" | 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <numeric> | 8 #include <numeric> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 // Size and position the window. Note that it is not yet onscreen. Popup | 279 // Size and position the window. Note that it is not yet onscreen. Popup |
| 280 // windows may get resized later on in this function, once the actual size | 280 // windows may get resized later on in this function, once the actual size |
| 281 // of the toolbar/tabstrip is known. | 281 // of the toolbar/tabstrip is known. |
| 282 windowShim_->SetBounds(windowRect); | 282 windowShim_->SetBounds(windowRect); |
| 283 | 283 |
| 284 // Puts the incognito badge on the window frame, if necessary. | 284 // Puts the incognito badge on the window frame, if necessary. |
| 285 [self installAvatar]; | 285 [self installAvatar]; |
| 286 | 286 |
| 287 // Create a sub-controller for the docked devTools and add its view to the | 287 // Create a sub-controller for the docked devTools and add its view to the |
| 288 // hierarchy. | 288 // hierarchy. |
| 289 devToolsController_.reset( | 289 devToolsController_.reset([[DevToolsController alloc] init]); |
| 290 [[DevToolsController alloc] initWithDelegate:self]); | |
| 291 [[devToolsController_ view] setFrame:[[self tabContentArea] bounds]]; | 290 [[devToolsController_ view] setFrame:[[self tabContentArea] bounds]]; |
| 292 [[self tabContentArea] addSubview:[devToolsController_ view]]; | 291 [[self tabContentArea] addSubview:[devToolsController_ view]]; |
| 293 | 292 |
| 294 // Create the previewable contents controller. This provides the switch | 293 // Create the previewable contents controller. This provides the switch |
| 295 // view that TabStripController needs. | 294 // view that TabStripController needs. |
| 296 previewableContentsController_.reset( | 295 previewableContentsController_.reset( |
| 297 [[PreviewableContentsController alloc] init]); | 296 [[PreviewableContentsController alloc] init]); |
| 298 [[previewableContentsController_ view] | 297 [[previewableContentsController_ view] |
| 299 setFrame:[[devToolsController_ view] bounds]]; | 298 setFrame:[[devToolsController_ view] bounds]]; |
| 300 [[devToolsController_ view] | 299 [[devToolsController_ view] |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 [tabStripController_ removeConstrainedWindow:window]; | 512 [tabStripController_ removeConstrainedWindow:window]; |
| 514 } | 513 } |
| 515 | 514 |
| 516 - (BOOL)canAttachConstrainedWindow { | 515 - (BOOL)canAttachConstrainedWindow { |
| 517 return ![previewableContentsController_ isShowingPreview]; | 516 return ![previewableContentsController_ isShowingPreview]; |
| 518 } | 517 } |
| 519 | 518 |
| 520 - (void)updateDevToolsForContents:(WebContents*)contents { | 519 - (void)updateDevToolsForContents:(WebContents*)contents { |
| 521 [devToolsController_ updateDevToolsForWebContents:contents | 520 [devToolsController_ updateDevToolsForWebContents:contents |
| 522 withProfile:browser_->profile()]; | 521 withProfile:browser_->profile()]; |
| 523 [devToolsController_ ensureContentsVisible]; | |
| 524 } | 522 } |
| 525 | 523 |
| 526 - (void)setDevToolsDockToRight:(bool)dock_to_right { | 524 - (void)setDevToolsDockToRight:(bool)dock_to_right { |
| 527 [devToolsController_ setDockToRight:dock_to_right | 525 [devToolsController_ setDockToRight:dock_to_right |
| 528 withProfile:browser_->profile()]; | 526 withProfile:browser_->profile()]; |
| 529 } | 527 } |
| 530 | 528 |
| 531 // Called when the user wants to close a window or from the shutdown process. | 529 // Called when the user wants to close a window or from the shutdown process. |
| 532 // The Browser object is in control of whether or not we're allowed to close. It | 530 // The Browser object is in control of whether or not we're allowed to close. It |
| 533 // may defer closing due to several states, such as onUnload handlers needing to | 531 // may defer closing due to several states, such as onUnload handlers needing to |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1134 - (void)updateToolbarWithContents:(WebContents*)tab | 1132 - (void)updateToolbarWithContents:(WebContents*)tab |
| 1135 shouldRestoreState:(BOOL)shouldRestore { | 1133 shouldRestoreState:(BOOL)shouldRestore { |
| 1136 [toolbarController_ updateToolbarWithContents:tab | 1134 [toolbarController_ updateToolbarWithContents:tab |
| 1137 shouldRestoreState:shouldRestore]; | 1135 shouldRestoreState:shouldRestore]; |
| 1138 } | 1136 } |
| 1139 | 1137 |
| 1140 - (void)setStarredState:(BOOL)isStarred { | 1138 - (void)setStarredState:(BOOL)isStarred { |
| 1141 [toolbarController_ setStarredState:isStarred]; | 1139 [toolbarController_ setStarredState:isStarred]; |
| 1142 } | 1140 } |
| 1143 | 1141 |
| 1142 // Return the rect, in WebKit coordinates (flipped), of the window's grow box |
| 1143 // in the coordinate system of the content area of the currently selected tab. |
| 1144 // |windowGrowBox| needs to be in the window's coordinate system. |
| 1145 - (NSRect)selectedTabGrowBoxRect { |
| 1146 NSWindow* window = [self window]; |
| 1147 if (![window respondsToSelector:@selector(_growBoxRect)]) |
| 1148 return NSZeroRect; |
| 1149 |
| 1150 // Before we return a rect, we need to convert it from window coordinates |
| 1151 // to tab content area coordinates and flip the coordinate system. |
| 1152 NSRect growBoxRect = |
| 1153 [[self tabContentArea] convertRect:[window _growBoxRect] fromView:nil]; |
| 1154 growBoxRect.origin.y = |
| 1155 [[self tabContentArea] frame].size.height - growBoxRect.size.height - |
| 1156 growBoxRect.origin.y; |
| 1157 return growBoxRect; |
| 1158 } |
| 1159 |
| 1144 // Accept tabs from a BrowserWindowController with the same Profile. | 1160 // Accept tabs from a BrowserWindowController with the same Profile. |
| 1145 - (BOOL)canReceiveFrom:(TabWindowController*)source { | 1161 - (BOOL)canReceiveFrom:(TabWindowController*)source { |
| 1146 if (![source isKindOfClass:[BrowserWindowController class]]) { | 1162 if (![source isKindOfClass:[BrowserWindowController class]]) { |
| 1147 return NO; | 1163 return NO; |
| 1148 } | 1164 } |
| 1149 | 1165 |
| 1150 BrowserWindowController* realSource = | 1166 BrowserWindowController* realSource = |
| 1151 static_cast<BrowserWindowController*>(source); | 1167 static_cast<BrowserWindowController*>(source); |
| 1152 if (browser_->profile() != realSource->browser_->profile()) { | 1168 if (browser_->profile() != realSource->browser_->profile()) { |
| 1153 return NO; | 1169 return NO; |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1448 - (NSRect)regularWindowFrame { | 1464 - (NSRect)regularWindowFrame { |
| 1449 return [self isFullscreen] ? savedRegularWindowFrame_ : | 1465 return [self isFullscreen] ? savedRegularWindowFrame_ : |
| 1450 [[self window] frame]; | 1466 [[self window] frame]; |
| 1451 } | 1467 } |
| 1452 | 1468 |
| 1453 // (Override of |TabWindowController| method.) | 1469 // (Override of |TabWindowController| method.) |
| 1454 - (BOOL)hasTabStrip { | 1470 - (BOOL)hasTabStrip { |
| 1455 return [self supportsWindowFeature:Browser::FEATURE_TABSTRIP]; | 1471 return [self supportsWindowFeature:Browser::FEATURE_TABSTRIP]; |
| 1456 } | 1472 } |
| 1457 | 1473 |
| 1458 // TabContentsControllerDelegate protocol. | |
| 1459 - (void)tabContentsViewFrameWillChange:(TabContentsController*)source | |
| 1460 frameRect:(NSRect)frameRect { | |
| 1461 WebContents* contents = [source webContents]; | |
| 1462 RenderWidgetHostView* render_widget_host_view = contents ? | |
| 1463 contents->GetRenderWidgetHostView() : NULL; | |
| 1464 if (!render_widget_host_view) | |
| 1465 return; | |
| 1466 | |
| 1467 gfx::Rect reserved_rect; | |
| 1468 | |
| 1469 NSWindow* window = [self window]; | |
| 1470 if ([window respondsToSelector:@selector(_growBoxRect)]) { | |
| 1471 NSView* view = [source view]; | |
| 1472 if (view && [view superview]) { | |
| 1473 NSRect windowGrowBoxRect = [window _growBoxRect]; | |
| 1474 NSRect viewRect = [[view superview] convertRect:frameRect toView:nil]; | |
| 1475 NSRect growBoxRect = NSIntersectionRect(windowGrowBoxRect, viewRect); | |
| 1476 if (!NSIsEmptyRect(growBoxRect)) { | |
| 1477 // Before we return a rect, we need to convert it from window | |
| 1478 // coordinates to content area coordinates and flip the coordinate | |
| 1479 // system. | |
| 1480 // Superview is used here because, first, it's a frame rect, so it is | |
| 1481 // specified in the parent's coordinates and, second, view is not | |
| 1482 // positioned yet. | |
| 1483 growBoxRect = [[view superview] convertRect:growBoxRect fromView:nil]; | |
| 1484 growBoxRect.origin.y = | |
| 1485 NSHeight(frameRect) - NSHeight(growBoxRect); | |
| 1486 growBoxRect = | |
| 1487 NSOffsetRect(growBoxRect, -frameRect.origin.x, -frameRect.origin.y); | |
| 1488 | |
| 1489 reserved_rect = | |
| 1490 gfx::Rect(growBoxRect.origin.x, growBoxRect.origin.y, | |
| 1491 growBoxRect.size.width, growBoxRect.size.height); | |
| 1492 } | |
| 1493 } | |
| 1494 } | |
| 1495 | |
| 1496 render_widget_host_view->set_reserved_contents_rect(reserved_rect); | |
| 1497 } | |
| 1498 | |
| 1499 // TabStripControllerDelegate protocol. | 1474 // TabStripControllerDelegate protocol. |
| 1500 - (void)onActivateTabWithContents:(WebContents*)contents { | 1475 - (void)onActivateTabWithContents:(WebContents*)contents { |
| 1501 // Update various elements that are interested in knowing the current | 1476 // Update various elements that are interested in knowing the current |
| 1502 // WebContents. | 1477 // WebContents. |
| 1503 | 1478 |
| 1504 // Update all the UI bits. | 1479 // Update all the UI bits. |
| 1505 windowShim_->UpdateTitleBar(); | 1480 windowShim_->UpdateTitleBar(); |
| 1506 | 1481 |
| 1507 [devToolsController_ updateDevToolsForWebContents:contents | 1482 [devToolsController_ updateDevToolsForWebContents:contents |
| 1508 withProfile:browser_->profile()]; | 1483 withProfile:browser_->profile()]; |
| 1509 | 1484 |
| 1510 // Update the bookmark bar. | 1485 // Update the bookmark bar. |
| 1511 // Must do it after devtools updates, otherwise bookmark bar might | 1486 // Must do it after devtools updates, otherwise bookmark bar might |
| 1512 // call resizeView -> layoutSubviews and cause unnecessary relayout. | 1487 // call resizeView -> layoutSubviews and cause unnecessary relayout. |
| 1513 // TODO(viettrungluu): perhaps update to not terminate running animations (if | 1488 // TODO(viettrungluu): perhaps update to not terminate running animations (if |
| 1514 // applicable)? | 1489 // applicable)? |
| 1515 [self updateBookmarkBarVisibilityWithAnimation:NO]; | 1490 [self updateBookmarkBarVisibilityWithAnimation:NO]; |
| 1516 | 1491 |
| 1517 TabContentsWrapper* wrapper = | 1492 TabContentsWrapper* wrapper = |
| 1518 TabContentsWrapper::GetCurrentWrapperForContents(contents); | 1493 TabContentsWrapper::GetCurrentWrapperForContents(contents); |
| 1519 // Without the .get(), xcode fails. | 1494 // Without the .get(), xcode fails. |
| 1520 [infoBarContainerController_.get() changeTabContents:wrapper]; | 1495 [infoBarContainerController_.get() changeTabContents:wrapper]; |
| 1521 | |
| 1522 // Update devTools contents after size for all views is set. | |
| 1523 [devToolsController_ ensureContentsVisible]; | |
| 1524 } | 1496 } |
| 1525 | 1497 |
| 1526 - (void)onReplaceTabWithContents:(WebContents*)contents { | 1498 - (void)onReplaceTabWithContents:(WebContents*)contents { |
| 1527 // Simply remove the preview view if it exists; the tab strip | 1499 // Simply remove the preview view if it exists; the tab strip |
| 1528 // controller will reinstall the view as the active view. | 1500 // controller will reinstall the view as the active view. |
| 1529 [previewableContentsController_ hidePreview]; | 1501 [previewableContentsController_ hidePreview]; |
| 1530 [self updateBookmarkBarVisibilityWithAnimation:NO]; | 1502 [self updateBookmarkBarVisibilityWithAnimation:NO]; |
| 1531 } | 1503 } |
| 1532 | 1504 |
| 1533 - (void)onTabChanged:(TabStripModelObserver::TabChangeType)change | 1505 - (void)onTabChanged:(TabStripModelObserver::TabChangeType)change |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2165 | 2137 |
| 2166 - (BOOL)supportsBookmarkBar { | 2138 - (BOOL)supportsBookmarkBar { |
| 2167 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; | 2139 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
| 2168 } | 2140 } |
| 2169 | 2141 |
| 2170 - (BOOL)isTabbedWindow { | 2142 - (BOOL)isTabbedWindow { |
| 2171 return browser_->is_type_tabbed(); | 2143 return browser_->is_type_tabbed(); |
| 2172 } | 2144 } |
| 2173 | 2145 |
| 2174 @end // @implementation BrowserWindowController(WindowType) | 2146 @end // @implementation BrowserWindowController(WindowType) |
| OLD | NEW |