Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm

Issue 1733173002: Mac: Make calling WebContents::WasShown/WasHidden the responsibility of the content layer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/chrome_tests_unit.gypi » ('j') | chrome/test/BUILD.gn » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/tabs/tab_strip_controller.h" 5 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
6 6
7 #import <QuartzCore/QuartzCore.h> 7 #import <QuartzCore/QuartzCore.h>
8 8
9 #include <cmath> 9 #include <cmath>
10 #include <limits> 10 #include <limits>
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 // may not be any children in the case of a tab that's been closed, in 672 // may not be any children in the case of a tab that's been closed, in
673 // which case there's no swapping going on. 673 // which case there's no swapping going on.
674 NSArray* subviews = [switchView_ subviews]; 674 NSArray* subviews = [switchView_ subviews];
675 if ([subviews count]) { 675 if ([subviews count]) {
676 NSView* oldView = [subviews objectAtIndex:0]; 676 NSView* oldView = [subviews objectAtIndex:0];
677 // Set newView frame to the oldVew frame to prevent NSSplitView hosting 677 // Set newView frame to the oldVew frame to prevent NSSplitView hosting
678 // sidebar and tab content from resizing sidebar's content view. 678 // sidebar and tab content from resizing sidebar's content view.
679 // ensureContentsVisible (see below) sets content size and autoresizing 679 // ensureContentsVisible (see below) sets content size and autoresizing
680 // properties. 680 // properties.
681 [newView setFrame:[oldView frame]]; 681 [newView setFrame:[oldView frame]];
682 [switchView_ replaceSubview:oldView with:newView]; 682 // Remove the old view first, to ensure ConstrainedWindowSheets keyed to the
683 // old WebContents are removed before adding new ones.
Avi (use Gerrit) 2016/02/29 17:27:23 As a side note, this sounds like a limitation of t
684 [oldView removeFromSuperview];
685 [switchView_ addSubview:newView];
683 } else { 686 } else {
684 [newView setFrame:[switchView_ bounds]]; 687 [newView setFrame:[switchView_ bounds]];
685 [switchView_ addSubview:newView]; 688 [switchView_ addSubview:newView];
686 } 689 }
687 690
688 // New content is in place, delegate should adjust itself accordingly. 691 // New content is in place, delegate should adjust itself accordingly.
689 [delegate_ onActivateTabWithContents:[controller webContents]]; 692 [delegate_ onActivateTabWithContents:[controller webContents]];
690 693
691 // It also restores content autoresizing properties. 694 // It also restores content autoresizing properties.
692 [controller ensureContentsVisible]; 695 [controller ensureContentsVisible];
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 reason:(int)reason { 1372 reason:(int)reason {
1370 // Take closing tabs into account. 1373 // Take closing tabs into account.
1371 if (oldContents) { 1374 if (oldContents) {
1372 int oldModelIndex = 1375 int oldModelIndex =
1373 browser_->tab_strip_model()->GetIndexOfWebContents(oldContents); 1376 browser_->tab_strip_model()->GetIndexOfWebContents(oldContents);
1374 if (oldModelIndex != -1) { // When closing a tab, the old tab may be gone. 1377 if (oldModelIndex != -1) { // When closing a tab, the old tab may be gone.
1375 NSInteger oldIndex = [self indexFromModelIndex:oldModelIndex]; 1378 NSInteger oldIndex = [self indexFromModelIndex:oldModelIndex];
1376 TabContentsController* oldController = 1379 TabContentsController* oldController =
1377 [tabContentsArray_ objectAtIndex:oldIndex]; 1380 [tabContentsArray_ objectAtIndex:oldIndex];
1378 [oldController willBecomeUnselectedTab]; 1381 [oldController willBecomeUnselectedTab];
1379 oldContents->WasHidden();
1380 } 1382 }
1381 } 1383 }
1382 1384
1383 NSUInteger activeIndex = [self indexFromModelIndex:modelIndex]; 1385 NSUInteger activeIndex = [self indexFromModelIndex:modelIndex];
1384 1386
1385 [tabArray_ enumerateObjectsUsingBlock:^(TabController* current, 1387 [tabArray_ enumerateObjectsUsingBlock:^(TabController* current,
1386 NSUInteger index, 1388 NSUInteger index,
1387 BOOL* stop) { 1389 BOOL* stop) {
1388 [current setActive:index == activeIndex]; 1390 [current setActive:index == activeIndex];
1389 }]; 1391 }];
1390 1392
1391 // Tell the new tab contents it is about to become the selected tab. Here it 1393 // Tell the new tab contents it is about to become the selected tab. Here it
1392 // can do things like make sure the toolbar is up to date. 1394 // can do things like make sure the toolbar is up to date.
1393 TabContentsController* newController = 1395 TabContentsController* newController =
1394 [tabContentsArray_ objectAtIndex:activeIndex]; 1396 [tabContentsArray_ objectAtIndex:activeIndex];
1395 [newController willBecomeSelectedTab]; 1397 [newController willBecomeSelectedTab];
1396 1398
1397 // Relayout for new tabs and to let the selected tab grow to be larger in 1399 // Relayout for new tabs and to let the selected tab grow to be larger in
1398 // size than surrounding tabs if the user has many. This also raises the 1400 // size than surrounding tabs if the user has many. This also raises the
1399 // selected tab to the top. 1401 // selected tab to the top.
1400 [self layoutTabs]; 1402 [self layoutTabs];
1401 1403
1402 // Swap in the contents for the new tab. 1404 // Swap in the contents for the new tab.
1403 [self swapInTabAtIndex:modelIndex]; 1405 [self swapInTabAtIndex:modelIndex];
1404 1406
1405 if (newContents) { 1407 if (newContents)
1406 newContents->WasShown();
1407 newContents->RestoreFocus(); 1408 newContents->RestoreFocus();
1408 }
1409 } 1409 }
1410 1410
1411 - (void)tabSelectionChanged { 1411 - (void)tabSelectionChanged {
1412 // First get the vector of indices, which is allays sorted in ascending order. 1412 // First get the vector of indices, which is allays sorted in ascending order.
1413 ui::ListSelectionModel::SelectedIndices selection( 1413 ui::ListSelectionModel::SelectedIndices selection(
1414 tabStripModel_->selection_model().selected_indices()); 1414 tabStripModel_->selection_model().selected_indices());
1415 // Iterate through all of the tabs, selecting each as necessary. 1415 // Iterate through all of the tabs, selecting each as necessary.
1416 ui::ListSelectionModel::SelectedIndices::iterator iter = selection.begin(); 1416 ui::ListSelectionModel::SelectedIndices::iterator iter = selection.begin();
1417 int i = 0; 1417 int i = 0;
1418 for (TabController* current in tabArray_.get()) { 1418 for (TabController* current in tabArray_.get()) {
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after
2407 forButtonState:image_button_cell::kHoverStateBackground]; 2407 forButtonState:image_button_cell::kHoverStateBackground];
2408 } else { 2408 } else {
2409 [[newTabButton_ cell] setImage:nil 2409 [[newTabButton_ cell] setImage:nil
2410 forButtonState:image_button_cell::kDefaultStateBackground]; 2410 forButtonState:image_button_cell::kDefaultStateBackground];
2411 [[newTabButton_ cell] setImage:nil 2411 [[newTabButton_ cell] setImage:nil
2412 forButtonState:image_button_cell::kHoverStateBackground]; 2412 forButtonState:image_button_cell::kHoverStateBackground];
2413 } 2413 }
2414 } 2414 }
2415 2415
2416 @end 2416 @end
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_tests_unit.gypi » ('j') | chrome/test/BUILD.gn » ('J')

Powered by Google App Engine
This is Rietveld 408576698