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

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

Issue 17593006: mac: Update clients of scoped_nsobject.h. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: iwyu, scoped_nsprotocol Created 7 years, 6 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 | Annotate | Revision Log
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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 DISALLOW_COPY_AND_ASSIGN(ScopedNSAnimationContextGroup); 155 DISALLOW_COPY_AND_ASSIGN(ScopedNSAnimationContextGroup);
156 }; 156 };
157 157
158 // Creates an NSImage with size |size| and bitmap image representations for both 158 // Creates an NSImage with size |size| and bitmap image representations for both
159 // 1x and 2x scale factors. |drawingHandler| is called once for every scale 159 // 1x and 2x scale factors. |drawingHandler| is called once for every scale
160 // factor. This is similar to -[NSImage imageWithSize:flipped:drawingHandler:], 160 // factor. This is similar to -[NSImage imageWithSize:flipped:drawingHandler:],
161 // but this function always evaluates drawingHandler eagerly, and it works on 161 // but this function always evaluates drawingHandler eagerly, and it works on
162 // 10.6 and 10.7. 162 // 10.6 and 10.7.
163 NSImage* CreateImageWithSize(NSSize size, 163 NSImage* CreateImageWithSize(NSSize size,
164 void (^drawingHandler)(NSSize)) { 164 void (^drawingHandler)(NSSize)) {
165 scoped_nsobject<NSImage> result([[NSImage alloc] initWithSize:size]); 165 base::scoped_nsobject<NSImage> result([[NSImage alloc] initWithSize:size]);
166 [NSGraphicsContext saveGraphicsState]; 166 [NSGraphicsContext saveGraphicsState];
167 for (ui::ScaleFactor scale_factor : ui::GetSupportedScaleFactors()) { 167 for (ui::ScaleFactor scale_factor : ui::GetSupportedScaleFactors()) {
168 float scale = GetScaleFactorScale(scale_factor); 168 float scale = GetScaleFactorScale(scale_factor);
169 NSBitmapImageRep *bmpImageRep = [[NSBitmapImageRep alloc] 169 NSBitmapImageRep *bmpImageRep = [[NSBitmapImageRep alloc]
170 initWithBitmapDataPlanes:NULL 170 initWithBitmapDataPlanes:NULL
171 pixelsWide:size.width * scale 171 pixelsWide:size.width * scale
172 pixelsHigh:size.height * scale 172 pixelsHigh:size.height * scale
173 bitsPerSample:8 173 bitsPerSample:8
174 samplesPerPixel:4 174 samplesPerPixel:4
175 hasAlpha:YES 175 hasAlpha:YES
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 tabStripModel_->ContainsIndex(modelIndex)); 1289 tabStripModel_->ContainsIndex(modelIndex));
1290 1290
1291 // Cancel any pending tab transition. 1291 // Cancel any pending tab transition.
1292 hoverTabSelector_->CancelTabTransition(); 1292 hoverTabSelector_->CancelTabTransition();
1293 1293
1294 // Take closing tabs into account. 1294 // Take closing tabs into account.
1295 NSInteger index = [self indexFromModelIndex:modelIndex]; 1295 NSInteger index = [self indexFromModelIndex:modelIndex];
1296 1296
1297 // Make a new tab. Load the contents of this tab from the nib and associate 1297 // Make a new tab. Load the contents of this tab from the nib and associate
1298 // the new controller with |contents| so it can be looked up later. 1298 // the new controller with |contents| so it can be looked up later.
1299 scoped_nsobject<TabContentsController> contentsController( 1299 base::scoped_nsobject<TabContentsController> contentsController(
1300 [[TabContentsController alloc] initWithContents:contents]); 1300 [[TabContentsController alloc] initWithContents:contents]);
1301 [tabContentsArray_ insertObject:contentsController atIndex:index]; 1301 [tabContentsArray_ insertObject:contentsController atIndex:index];
1302 1302
1303 // Make a new tab and add it to the strip. Keep track of its controller. 1303 // Make a new tab and add it to the strip. Keep track of its controller.
1304 TabController* newController = [self newTab]; 1304 TabController* newController = [self newTab];
1305 [newController setMini:tabStripModel_->IsMiniTab(modelIndex)]; 1305 [newController setMini:tabStripModel_->IsMiniTab(modelIndex)];
1306 [newController setPinned:tabStripModel_->IsTabPinned(modelIndex)]; 1306 [newController setPinned:tabStripModel_->IsTabPinned(modelIndex)];
1307 [newController setApp:tabStripModel_->IsAppTab(modelIndex)]; 1307 [newController setApp:tabStripModel_->IsAppTab(modelIndex)];
1308 [newController setUrl:contents->GetURL()]; 1308 [newController setUrl:contents->GetURL()];
1309 [tabArray_ insertObject:newController atIndex:index]; 1309 [tabArray_ insertObject:newController atIndex:index];
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 previousContents:(content::WebContents*)oldContents 1403 previousContents:(content::WebContents*)oldContents
1404 atIndex:(NSInteger)modelIndex { 1404 atIndex:(NSInteger)modelIndex {
1405 NSInteger index = [self indexFromModelIndex:modelIndex]; 1405 NSInteger index = [self indexFromModelIndex:modelIndex];
1406 TabContentsController* oldController = 1406 TabContentsController* oldController =
1407 [tabContentsArray_ objectAtIndex:index]; 1407 [tabContentsArray_ objectAtIndex:index];
1408 DCHECK_EQ(oldContents, [oldController webContents]); 1408 DCHECK_EQ(oldContents, [oldController webContents]);
1409 1409
1410 // Simply create a new TabContentsController for |newContents| and place it 1410 // Simply create a new TabContentsController for |newContents| and place it
1411 // into the array, replacing |oldContents|. An ActiveTabChanged notification 1411 // into the array, replacing |oldContents|. An ActiveTabChanged notification
1412 // will follow, at which point we will install the new view. 1412 // will follow, at which point we will install the new view.
1413 scoped_nsobject<TabContentsController> newController( 1413 base::scoped_nsobject<TabContentsController> newController(
1414 [[TabContentsController alloc] initWithContents:newContents]); 1414 [[TabContentsController alloc] initWithContents:newContents]);
1415 1415
1416 // Bye bye, |oldController|. 1416 // Bye bye, |oldController|.
1417 [tabContentsArray_ replaceObjectAtIndex:index withObject:newController]; 1417 [tabContentsArray_ replaceObjectAtIndex:index withObject:newController];
1418 1418
1419 // Fake a tab changed notification to force tab titles and favicons to update. 1419 // Fake a tab changed notification to force tab titles and favicons to update.
1420 [self tabChangedWithContents:newContents 1420 [self tabChangedWithContents:newContents
1421 atIndex:modelIndex 1421 atIndex:modelIndex
1422 changeType:TabStripModelObserver::ALL]; 1422 changeType:TabStripModelObserver::ALL];
1423 } 1423 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1484 [closingControllers_ addObject:closingTab]; 1484 [closingControllers_ addObject:closingTab];
1485 1485
1486 // Mark the tab as closing. This prevents it from generating any drags or 1486 // Mark the tab as closing. This prevents it from generating any drags or
1487 // selections while it's animating closed. 1487 // selections while it's animating closed.
1488 [[closingTab tabView] setClosing:YES]; 1488 [[closingTab tabView] setClosing:YES];
1489 1489
1490 // Register delegate (owned by the animation system). 1490 // Register delegate (owned by the animation system).
1491 NSView* tabView = [closingTab view]; 1491 NSView* tabView = [closingTab view];
1492 CAAnimation* animation = [[tabView animationForKey:@"frameOrigin"] copy]; 1492 CAAnimation* animation = [[tabView animationForKey:@"frameOrigin"] copy];
1493 [animation autorelease]; 1493 [animation autorelease];
1494 scoped_nsobject<TabCloseAnimationDelegate> delegate( 1494 base::scoped_nsobject<TabCloseAnimationDelegate> delegate(
1495 [[TabCloseAnimationDelegate alloc] initWithTabStrip:self 1495 [[TabCloseAnimationDelegate alloc] initWithTabStrip:self
1496 tabController:closingTab]); 1496 tabController:closingTab]);
1497 [animation setDelegate:delegate.get()]; // Retains delegate. 1497 [animation setDelegate:delegate.get()]; // Retains delegate.
1498 NSMutableDictionary* animationDictionary = 1498 NSMutableDictionary* animationDictionary =
1499 [NSMutableDictionary dictionaryWithDictionary:[tabView animations]]; 1499 [NSMutableDictionary dictionaryWithDictionary:[tabView animations]];
1500 [animationDictionary setObject:animation forKey:@"frameOrigin"]; 1500 [animationDictionary setObject:animation forKey:@"frameOrigin"];
1501 [tabView setAnimations:animationDictionary]; 1501 [tabView setAnimations:animationDictionary];
1502 1502
1503 // Periscope down! Animate the tab. 1503 // Periscope down! Animate the tab.
1504 NSRect newFrame = [tabView frame]; 1504 NSRect newFrame = [tabView frame];
1505 newFrame = NSOffsetRect(newFrame, 0, -newFrame.size.height); 1505 newFrame = NSOffsetRect(newFrame, 0, -newFrame.size.height);
1506 ScopedNSAnimationContextGroup animationGroup(true); 1506 ScopedNSAnimationContextGroup animationGroup(true);
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1739 - (void)tabMovedWithContents:(content::WebContents*)contents 1739 - (void)tabMovedWithContents:(content::WebContents*)contents
1740 fromIndex:(NSInteger)modelFrom 1740 fromIndex:(NSInteger)modelFrom
1741 toIndex:(NSInteger)modelTo { 1741 toIndex:(NSInteger)modelTo {
1742 // Take closing tabs into account. 1742 // Take closing tabs into account.
1743 NSInteger from = [self indexFromModelIndex:modelFrom]; 1743 NSInteger from = [self indexFromModelIndex:modelFrom];
1744 NSInteger to = [self indexFromModelIndex:modelTo]; 1744 NSInteger to = [self indexFromModelIndex:modelTo];
1745 1745
1746 // Cancel any pending tab transition. 1746 // Cancel any pending tab transition.
1747 hoverTabSelector_->CancelTabTransition(); 1747 hoverTabSelector_->CancelTabTransition();
1748 1748
1749 scoped_nsobject<TabContentsController> movedTabContentsController( 1749 base::scoped_nsobject<TabContentsController> movedTabContentsController(
1750 [[tabContentsArray_ objectAtIndex:from] retain]); 1750 [[tabContentsArray_ objectAtIndex:from] retain]);
1751 [tabContentsArray_ removeObjectAtIndex:from]; 1751 [tabContentsArray_ removeObjectAtIndex:from];
1752 [tabContentsArray_ insertObject:movedTabContentsController.get() 1752 [tabContentsArray_ insertObject:movedTabContentsController.get()
1753 atIndex:to]; 1753 atIndex:to];
1754 scoped_nsobject<TabController> movedTabController( 1754 base::scoped_nsobject<TabController> movedTabController(
1755 [[tabArray_ objectAtIndex:from] retain]); 1755 [[tabArray_ objectAtIndex:from] retain]);
1756 DCHECK([movedTabController isKindOfClass:[TabController class]]); 1756 DCHECK([movedTabController isKindOfClass:[TabController class]]);
1757 [tabArray_ removeObjectAtIndex:from]; 1757 [tabArray_ removeObjectAtIndex:from];
1758 [tabArray_ insertObject:movedTabController.get() atIndex:to]; 1758 [tabArray_ insertObject:movedTabController.get() atIndex:to];
1759 1759
1760 // The tab moved, which means that the mini-tab state may have changed. 1760 // The tab moved, which means that the mini-tab state may have changed.
1761 if (tabStripModel_->IsMiniTab(modelTo) != [movedTabController mini]) 1761 if (tabStripModel_->IsMiniTab(modelTo) != [movedTabController mini])
1762 [self tabMiniStateChangedWithContents:contents atIndex:modelTo]; 1762 [self tabMiniStateChangedWithContents:contents atIndex:modelTo];
1763 1763
1764 [self layoutTabs]; 1764 [self layoutTabs];
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
2300 NSView* GetSheetParentViewForWebContents(WebContents* web_contents) { 2300 NSView* GetSheetParentViewForWebContents(WebContents* web_contents) {
2301 // View hierarchy of the contents view: 2301 // View hierarchy of the contents view:
2302 // NSView -- switchView, same for all tabs 2302 // NSView -- switchView, same for all tabs
2303 // +- NSView -- TabContentsController's view 2303 // +- NSView -- TabContentsController's view
2304 // +- TabContentsViewCocoa 2304 // +- TabContentsViewCocoa
2305 // 2305 //
2306 // Changing it? Do not forget to modify 2306 // Changing it? Do not forget to modify
2307 // -[TabStripController swapInTabAtIndex:] too. 2307 // -[TabStripController swapInTabAtIndex:] too.
2308 return [web_contents->GetView()->GetNativeView() superview]; 2308 return [web_contents->GetView()->GetNativeView() superview];
2309 } 2309 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698