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 #import "chrome/browser/cocoa/tab_strip_controller.h" | 5 #import "chrome/browser/cocoa/tab_strip_controller.h" |
6 | 6 |
7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 } else { | 363 } else { |
364 [switchView_ addSubview:newView]; | 364 [switchView_ addSubview:newView]; |
365 } | 365 } |
366 | 366 |
367 // Make sure the new tabs's sheets are visible (necessary when a background | 367 // Make sure the new tabs's sheets are visible (necessary when a background |
368 // tab opened a sheet while it was in the background and now becomes active). | 368 // tab opened a sheet while it was in the background and now becomes active). |
369 TabContents* newTab = tabModel_->GetTabContentsAt(modelIndex); | 369 TabContents* newTab = tabModel_->GetTabContentsAt(modelIndex); |
370 DCHECK(newTab); | 370 DCHECK(newTab); |
371 if (newTab) { | 371 if (newTab) { |
372 TabContents::ConstrainedWindowList::iterator it, end; | 372 TabContents::ConstrainedWindowList::iterator it, end; |
| 373 it = newTab->constrained_window_begin(); |
373 end = newTab->constrained_window_end(); | 374 end = newTab->constrained_window_end(); |
374 NSWindowController* controller = [[newView window] windowController]; | |
375 DCHECK([controller isKindOfClass:[BrowserWindowController class]]); | |
376 | 375 |
377 for (it = newTab->constrained_window_begin(); it != end; ++it) { | 376 // GTMWindowSheetController supports only one sheet at a time. |
| 377 if (it != end) { |
| 378 NSWindowController* controller = [[newView window] windowController]; |
| 379 DCHECK([controller isKindOfClass:[BrowserWindowController class]]); |
378 ConstrainedWindow* constrainedWindow = *it; | 380 ConstrainedWindow* constrainedWindow = *it; |
379 static_cast<ConstrainedWindowMac*>(constrainedWindow)->Realize( | 381 static_cast<ConstrainedWindowMac*>(constrainedWindow)->Realize( |
380 static_cast<BrowserWindowController*>(controller)); | 382 static_cast<BrowserWindowController*>(controller)); |
381 } | 383 } |
382 } | 384 } |
383 | 385 |
384 // Tell per-tab sheet manager about currently selected tab. | 386 // Tell per-tab sheet manager about currently selected tab. |
385 if (sheetController_.get()) { | 387 if (sheetController_.get()) { |
386 [sheetController_ setActiveView:newView]; | 388 [sheetController_ setActiveView:newView]; |
387 } | 389 } |
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1285 // Raise window... | 1287 // Raise window... |
1286 [[switchView_ window] makeKeyAndOrderFront:self]; | 1288 [[switchView_ window] makeKeyAndOrderFront:self]; |
1287 | 1289 |
1288 // ...and raise a tab with a sheet. | 1290 // ...and raise a tab with a sheet. |
1289 NSInteger index = [self modelIndexForContentsView:view]; | 1291 NSInteger index = [self modelIndexForContentsView:view]; |
1290 DCHECK(index >= 0); | 1292 DCHECK(index >= 0); |
1291 if (index >= 0) | 1293 if (index >= 0) |
1292 tabModel_->SelectTabContentsAt(index, false /* not a user gesture */); | 1294 tabModel_->SelectTabContentsAt(index, false /* not a user gesture */); |
1293 } | 1295 } |
1294 | 1296 |
1295 - (void)attachConstrainedWindow:(ConstrainedWindowMac*)window { | 1297 - (BOOL)attachConstrainedWindow:(ConstrainedWindowMac*)window { |
1296 // TODO(thakis, avi): Figure out how to make this work when tabs are dragged | 1298 // TODO(thakis, avi): Figure out how to make this work when tabs are dragged |
1297 // out or if fullscreen mode is toggled. | 1299 // out or if fullscreen mode is toggled. |
1298 | 1300 |
1299 // View hierarchy of the contents view: | 1301 // View hierarchy of the contents view: |
1300 // NSView -- switchView, same for all tabs | 1302 // NSView -- switchView, same for all tabs |
1301 // +- NSView -- TabContentsController's view | 1303 // +- NSView -- TabContentsController's view |
1302 // +- NSBox | 1304 // +- NSBox |
1303 // +- TabContentsViewCocoa | 1305 // +- TabContentsViewCocoa |
1304 // We use the TabContentsController's view in |swapInTabAtIndex|, so we have | 1306 // We use the TabContentsController's view in |swapInTabAtIndex|, so we have |
1305 // to pass it to the sheet controller here. | 1307 // to pass it to the sheet controller here. |
1306 NSView* tabContentsView = | 1308 NSView* tabContentsView = |
1307 [[window->owner()->GetNativeView() superview] superview]; | 1309 [[window->owner()->GetNativeView() superview] superview]; |
1308 window->delegate()->RunSheet([self sheetController], tabContentsView); | |
1309 | 1310 |
1310 // TODO(avi, thakis): GTMWindowSheetController has no api to move tabsheets | 1311 // TODO(avi, thakis): GTMWindowSheetController has no api to move tabsheets |
1311 // between windows. Until then, we have to prevent having to move a tabsheet | 1312 // between windows. Until then, we have to prevent having to move a tabsheet |
1312 // between windows, e.g. no tearing off of tabs. | 1313 // between windows, e.g. no tearing off of tabs. |
1313 NSInteger modelIndex = [self modelIndexForContentsView:tabContentsView]; | 1314 NSInteger modelIndex = [self modelIndexForContentsView:tabContentsView]; |
1314 NSInteger index = [self indexFromModelIndex:modelIndex]; | 1315 NSInteger index = [self indexFromModelIndex:modelIndex]; |
1315 BrowserWindowController* controller = | 1316 BrowserWindowController* controller = |
1316 (BrowserWindowController*)[[switchView_ window] windowController]; | 1317 (BrowserWindowController*)[[switchView_ window] windowController]; |
1317 DCHECK(controller != nil); | 1318 DCHECK(controller != nil); |
1318 DCHECK(index >= 0); | 1319 DCHECK(index >= 0); |
1319 if (index >= 0) { | 1320 if (index >= 0) { |
1320 [controller setTab:[self viewAtIndex:index] isDraggable:NO]; | 1321 NSView* tab = [self viewAtIndex:index]; |
| 1322 [controller setTab:tab isDraggable:NO]; |
| 1323 |
| 1324 std::deque<ConstrainedWindowMac*>& windows = constrainedWindows_[tab]; |
| 1325 std::deque<ConstrainedWindowMac*>::iterator it = |
| 1326 find(windows.begin(), windows.end(), window); |
| 1327 if (it == windows.end()) |
| 1328 constrainedWindows_[tab].push_back(window); |
| 1329 |
| 1330 if (constrainedWindows_[tab].size() == 1) { |
| 1331 [controller setTab:tab isDraggable:NO]; |
| 1332 window->SetVisible(); |
| 1333 window->delegate()->RunSheet([self sheetController], tabContentsView); |
| 1334 return YES; |
| 1335 } |
1321 } | 1336 } |
| 1337 return NO; |
1322 } | 1338 } |
1323 | 1339 |
1324 - (void)removeConstrainedWindow:(ConstrainedWindowMac*)window { | 1340 - (void)removeConstrainedWindow:(ConstrainedWindowMac*)window { |
1325 NSView* tabContentsView = | 1341 NSView* tabContentsView = |
1326 [[window->owner()->GetNativeView() superview] superview]; | 1342 [[window->owner()->GetNativeView() superview] superview]; |
1327 | 1343 |
1328 // TODO(avi, thakis): GTMWindowSheetController has no api to move tabsheets | 1344 // TODO(avi, thakis): GTMWindowSheetController has no api to move tabsheets |
1329 // between windows. Until then, we have to prevent having to move a tabsheet | 1345 // between windows. Until then, we have to prevent having to move a tabsheet |
1330 // between windows, e.g. no tearing off of tabs. | 1346 // between windows, e.g. no tearing off of tabs. |
1331 NSInteger modelIndex = [self modelIndexForContentsView:tabContentsView]; | 1347 NSInteger modelIndex = [self modelIndexForContentsView:tabContentsView]; |
1332 NSInteger index = [self indexFromModelIndex:modelIndex]; | 1348 NSInteger index = [self indexFromModelIndex:modelIndex]; |
1333 BrowserWindowController* controller = | 1349 BrowserWindowController* controller = |
1334 (BrowserWindowController*)[[switchView_ window] windowController]; | 1350 (BrowserWindowController*)[[switchView_ window] windowController]; |
1335 DCHECK(index >= 0); | 1351 DCHECK(index >= 0); |
1336 if (index >= 0) { | 1352 if (index >= 0) { |
1337 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; | 1353 NSView* tab = [self viewAtIndex:index]; |
| 1354 |
| 1355 std::deque<ConstrainedWindowMac*>& windows = constrainedWindows_[tab]; |
| 1356 std::deque<ConstrainedWindowMac*>::iterator it = |
| 1357 find(windows.begin(), windows.end(), window); |
| 1358 DCHECK(it != windows.end()); |
| 1359 |
| 1360 bool removedVisibleSheet = it == windows.begin(); |
| 1361 |
| 1362 if (it != windows.end()) |
| 1363 windows.erase(it); |
| 1364 |
| 1365 if (windows.size() == 0) { |
| 1366 [controller setTab:tab isDraggable:YES]; |
| 1367 constrainedWindows_.erase(tab); |
| 1368 } else if (removedVisibleSheet && tab == [self selectedTabView]) { |
| 1369 // Show next sheet |
| 1370 NSWindowController* controller = [[tab window] windowController]; |
| 1371 DCHECK([controller isKindOfClass:[BrowserWindowController class]]); |
| 1372 windows.front()->Realize( |
| 1373 static_cast<BrowserWindowController*>(controller)); |
| 1374 } |
1338 } | 1375 } |
1339 } | 1376 } |
1340 | 1377 |
1341 @end | 1378 @end |
OLD | NEW |