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

Side by Side Diff: chrome/browser/ui/cocoa/tabpose_window.mm

Issue 11305008: Remove TabContents from TabStripModelObserverBridge. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 1 month 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/tabpose_window.h" 5 #import "chrome/browser/ui/cocoa/tabpose_window.h"
6 6
7 #import <QuartzCore/QuartzCore.h> 7 #import <QuartzCore/QuartzCore.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 grayColorSpace.get(), grays, locations, arraysize(locations))); 97 grayColorSpace.get(), grays, locations, arraysize(locations)));
98 CGPoint topLeft = CGPointMake(0.0, self.bounds.size.height); 98 CGPoint topLeft = CGPointMake(0.0, self.bounds.size.height);
99 CGContextDrawLinearGradient(context, gradient.get(), topLeft, CGPointZero, 0); 99 CGContextDrawLinearGradient(context, gradient.get(), topLeft, CGPointZero, 0);
100 } 100 }
101 @end 101 @end
102 102
103 namespace tabpose { 103 namespace tabpose {
104 class ThumbnailLoader; 104 class ThumbnailLoader;
105 } 105 }
106 106
107 // A CALayer that draws a thumbnail for a TabContents object. The layer 107 // A CALayer that draws a thumbnail for a WebContents object. The layer
108 // tries to draw the WebContents's backing store directly if possible, and 108 // tries to draw the WebContents's backing store directly if possible, and
109 // requests a thumbnail bitmap from the WebContents's renderer process if not. 109 // requests a thumbnail bitmap from the WebContents's renderer process if not.
110 @interface ThumbnailLayer : CALayer { 110 @interface ThumbnailLayer : CALayer {
111 // The TabContents the thumbnail is for. 111 // The WebContents the thumbnail is for.
112 TabContents* contents_; // weak 112 content::WebContents* contents_; // weak
113 113
114 // The size the thumbnail is drawn at when zoomed in. 114 // The size the thumbnail is drawn at when zoomed in.
115 NSSize fullSize_; 115 NSSize fullSize_;
116 116
117 // Used to load a thumbnail, if required. 117 // Used to load a thumbnail, if required.
118 scoped_refptr<tabpose::ThumbnailLoader> loader_; 118 scoped_refptr<tabpose::ThumbnailLoader> loader_;
119 119
120 // If the backing store couldn't be used and a thumbnail was returned from a 120 // If the backing store couldn't be used and a thumbnail was returned from a
121 // renderer process, it's stored in |thumbnail_|. 121 // renderer process, it's stored in |thumbnail_|.
122 base::mac::ScopedCFTypeRef<CGImageRef> thumbnail_; 122 base::mac::ScopedCFTypeRef<CGImageRef> thumbnail_;
123 123
124 // True if the layer already sent a thumbnail request to a renderer. 124 // True if the layer already sent a thumbnail request to a renderer.
125 BOOL didSendLoad_; 125 BOOL didSendLoad_;
126 } 126 }
127 - (id)initWithTabContents:(TabContents*)contents 127 - (id)initWithWebContents:(content::WebContents*)contents
128 fullSize:(NSSize)fullSize; 128 fullSize:(NSSize)fullSize;
129 - (void)drawInContext:(CGContextRef)context; 129 - (void)drawInContext:(CGContextRef)context;
130 - (void)setThumbnail:(const SkBitmap&)bitmap; 130 - (void)setThumbnail:(const SkBitmap&)bitmap;
131 @end 131 @end
132 132
133 namespace tabpose { 133 namespace tabpose {
134 134
135 // ThumbnailLoader talks to the renderer process to load a thumbnail of a given 135 // ThumbnailLoader talks to the renderer process to load a thumbnail of a given
136 // RenderWidgetHost, and sends the thumbnail back to a ThumbnailLayer once it 136 // RenderWidgetHost, and sends the thumbnail back to a ThumbnailLayer once it
137 // comes back from the renderer. 137 // comes back from the renderer.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 base::Bind(&ThumbnailLoader::DidReceiveBitmap, 178 base::Bind(&ThumbnailLoader::DidReceiveBitmap,
179 weak_factory_.GetWeakPtr()), 179 weak_factory_.GetWeakPtr()),
180 page_size, 180 page_size,
181 pixel_size); 181 pixel_size);
182 } 182 }
183 183
184 } // namespace tabpose 184 } // namespace tabpose
185 185
186 @implementation ThumbnailLayer 186 @implementation ThumbnailLayer
187 187
188 - (id)initWithTabContents:(TabContents*)contents 188 - (id)initWithWebContents:(content::WebContents*)contents
189 fullSize:(NSSize)fullSize { 189 fullSize:(NSSize)fullSize {
190 CHECK(contents); 190 CHECK(contents);
191 if ((self = [super init])) { 191 if ((self = [super init])) {
192 contents_ = contents; 192 contents_ = contents;
193 fullSize_ = fullSize; 193 fullSize_ = fullSize;
194 } 194 }
195 return self; 195 return self;
196 } 196 }
197 197
198 - (void)setTabContents:(TabContents*)contents { 198 - (void)setWebContents:(content::WebContents*)contents {
199 contents_ = contents; 199 contents_ = contents;
200 } 200 }
201 201
202 - (void)setThumbnail:(const SkBitmap&)bitmap { 202 - (void)setThumbnail:(const SkBitmap&)bitmap {
203 // SkCreateCGImageRef() holds on to |bitmaps|'s memory, so this doesn't 203 // SkCreateCGImageRef() holds on to |bitmaps|'s memory, so this doesn't
204 // create a copy. The renderer always draws data in the system colorspace. 204 // create a copy. The renderer always draws data in the system colorspace.
205 thumbnail_.reset(SkCreateCGImageRefWithColorspace( 205 thumbnail_.reset(SkCreateCGImageRefWithColorspace(
206 bitmap, base::mac::GetSystemColorSpace())); 206 bitmap, base::mac::GetSystemColorSpace()));
207 loader_ = NULL; 207 loader_ = NULL;
208 [self setNeedsDisplay]; 208 [self setNeedsDisplay];
209 } 209 }
210 210
211 - (int)topOffset { 211 - (int)topOffset {
212 int topOffset = 0; 212 int topOffset = 0;
213 213
214 // Medium term, we want to show thumbs of the actual info bar views, which 214 // Medium term, we want to show thumbs of the actual info bar views, which
215 // means I need to create InfoBarControllers here. 215 // means I need to create InfoBarControllers here.
216 NSWindow* window = [contents_->web_contents()->GetNativeView() window]; 216 NSWindow* window = [contents_->GetNativeView() window];
217 NSWindowController* windowController = [window windowController]; 217 NSWindowController* windowController = [window windowController];
218 if ([windowController isKindOfClass:[BrowserWindowController class]]) { 218 if ([windowController isKindOfClass:[BrowserWindowController class]]) {
219 BrowserWindowController* bwc = 219 BrowserWindowController* bwc =
220 static_cast<BrowserWindowController*>(windowController); 220 static_cast<BrowserWindowController*>(windowController);
221 InfoBarContainerController* infoBarContainer = 221 InfoBarContainerController* infoBarContainer =
222 [bwc infoBarContainerController]; 222 [bwc infoBarContainerController];
223 // TODO(thakis|rsesek): This is not correct for background tabs with 223 // TODO(thakis|rsesek): This is not correct for background tabs with
224 // infobars as the aspect ratio will be wrong. Fix that. 224 // infobars as the aspect ratio will be wrong. Fix that.
225 topOffset += NSHeight([[infoBarContainer view] frame]) - 225 topOffset += NSHeight([[infoBarContainer view] frame]) -
226 [infoBarContainer overlappingTipHeight]; 226 [infoBarContainer overlappingTipHeight];
227 } 227 }
228 228
229 BookmarkTabHelper* bookmark_tab_helper = 229 BookmarkTabHelper* bookmark_tab_helper =
230 BookmarkTabHelper::FromWebContents(contents_->web_contents()); 230 BookmarkTabHelper::FromWebContents(contents_);
231 Profile* profile =
232 Profile::FromBrowserContext(contents_->GetBrowserContext());
231 bool always_show_bookmark_bar = 233 bool always_show_bookmark_bar =
232 contents_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); 234 profile->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar);
233 bool has_detached_bookmark_bar = 235 bool has_detached_bookmark_bar =
234 bookmark_tab_helper->ShouldShowBookmarkBar() && 236 bookmark_tab_helper->ShouldShowBookmarkBar() &&
235 !always_show_bookmark_bar; 237 !always_show_bookmark_bar;
236 if (has_detached_bookmark_bar) 238 if (has_detached_bookmark_bar)
237 topOffset += chrome::kNTPBookmarkBarHeight; 239 topOffset += chrome::kNTPBookmarkBarHeight;
238 240
239 return topOffset; 241 return topOffset;
240 } 242 }
241 243
242 - (int)bottomOffset { 244 - (int)bottomOffset {
243 int bottomOffset = 0; 245 int bottomOffset = 0;
244 DevToolsWindow* devToolsWindow = 246 DevToolsWindow* devToolsWindow =
245 DevToolsWindow::GetDockedInstanceForInspectedTab( 247 DevToolsWindow::GetDockedInstanceForInspectedTab(contents_);
246 contents_->web_contents());
247 content::WebContents* devToolsContents = devToolsWindow ? 248 content::WebContents* devToolsContents = devToolsWindow ?
248 devToolsWindow->tab_contents()->web_contents() : NULL; 249 devToolsWindow->tab_contents()->web_contents() : NULL;
249 if (devToolsContents && devToolsContents->GetRenderViewHost() && 250 if (devToolsContents && devToolsContents->GetRenderViewHost() &&
250 devToolsContents->GetRenderViewHost()->GetView()) { 251 devToolsContents->GetRenderViewHost()->GetView()) {
251 // The devtool's size might not be up-to-date, but since its height doesn't 252 // The devtool's size might not be up-to-date, but since its height doesn't
252 // change on window resize, and since most users don't use devtools, this is 253 // change on window resize, and since most users don't use devtools, this is
253 // good enough. 254 // good enough.
254 bottomOffset += devToolsContents->GetRenderViewHost()->GetView()-> 255 bottomOffset += devToolsContents->GetRenderViewHost()->GetView()->
255 GetViewBounds().height(); 256 GetViewBounds().height();
256 bottomOffset += 1; // :-( Divider line between web contents and devtools. 257 bottomOffset += 1; // :-( Divider line between web contents and devtools.
257 } 258 }
258 return bottomOffset; 259 return bottomOffset;
259 } 260 }
260 261
261 - (void)drawInContext:(CGContextRef)context { 262 - (void)drawInContext:(CGContextRef)context {
262 RenderWidgetHost* rwh = contents_->web_contents()->GetRenderViewHost(); 263 RenderWidgetHost* rwh = contents_->GetRenderViewHost();
263 // NULL if renderer crashed. 264 // NULL if renderer crashed.
264 content::RenderWidgetHostView* rwhv = rwh ? rwh->GetView() : NULL; 265 content::RenderWidgetHostView* rwhv = rwh ? rwh->GetView() : NULL;
265 if (!rwhv) { 266 if (!rwhv) {
266 // TODO(thakis): Maybe draw a sad tab layer? 267 // TODO(thakis): Maybe draw a sad tab layer?
267 [super drawInContext:context]; 268 [super drawInContext:context];
268 return; 269 return;
269 } 270 }
270 271
271 // The size of the WebContents's RenderWidgetHost might not fit to the 272 // The size of the WebContents's RenderWidgetHost might not fit to the
272 // current browser window at all, for example if the window was resized while 273 // current browser window at all, for example if the window was resized while
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 // 3. calls |set_font_metrics()| which updates the title rect 399 // 3. calls |set_font_metrics()| which updates the title rect
399 // 4. receives the title rect and puts the title on it with the font from 2. 400 // 4. receives the title rect and puts the title on it with the font from 2.
400 void set_font_metrics(CGFloat ascender, CGFloat descender); 401 void set_font_metrics(CGFloat ascender, CGFloat descender);
401 CGFloat title_font_size() const { return title_font_size_; } 402 CGFloat title_font_size() const { return title_font_size_; }
402 403
403 NSRect GetTitleStartRectRelativeTo(const Tile& tile) const; 404 NSRect GetTitleStartRectRelativeTo(const Tile& tile) const;
404 NSRect title_rect() const { return NSIntegralRect(title_rect_); } 405 NSRect title_rect() const { return NSIntegralRect(title_rect_); }
405 406
406 // Returns an unelided title. The view logic is responsible for eliding. 407 // Returns an unelided title. The view logic is responsible for eliding.
407 const string16& title() const { 408 const string16& title() const {
408 return contents_->web_contents()->GetTitle(); 409 return contents_->GetTitle();
409 } 410 }
410 411
411 TabContents* tab_contents() const { return contents_; } 412 content::WebContents* web_contents() const { return contents_; }
412 void set_tab_contents(TabContents* new_contents) { 413 void set_tab_contents(content::WebContents* new_contents) {
413 contents_ = new_contents; 414 contents_ = new_contents;
414 } 415 }
415 416
416 private: 417 private:
417 friend class TileSet; 418 friend class TileSet;
418 419
419 // The thumb rect includes infobars, detached thumbnail bar, web contents, 420 // The thumb rect includes infobars, detached thumbnail bar, web contents,
420 // and devtools. 421 // and devtools.
421 NSRect thumb_rect_; 422 NSRect thumb_rect_;
422 NSRect start_thumb_rect_; 423 NSRect start_thumb_rect_;
423 424
424 NSRect favicon_rect_; 425 NSRect favicon_rect_;
425 426
426 CGFloat title_font_size_; 427 CGFloat title_font_size_;
427 NSRect title_rect_; 428 NSRect title_rect_;
428 429
429 TabContents* contents_; // weak 430 content::WebContents* contents_; // weak
430 431
431 DISALLOW_COPY_AND_ASSIGN(Tile); 432 DISALLOW_COPY_AND_ASSIGN(Tile);
432 }; 433 };
433 434
434 NSRect Tile::GetStartRectRelativeTo(const Tile& tile) const { 435 NSRect Tile::GetStartRectRelativeTo(const Tile& tile) const {
435 NSRect rect = start_thumb_rect_; 436 NSRect rect = start_thumb_rect_;
436 rect.origin.x -= tile.start_thumb_rect_.origin.x; 437 rect.origin.x -= tile.start_thumb_rect_.origin.x;
437 rect.origin.y -= tile.start_thumb_rect_.origin.y; 438 rect.origin.y -= tile.start_thumb_rect_.origin.y;
438 return rect; 439 return rect;
439 } 440 }
440 441
441 NSRect Tile::GetFaviconStartRectRelativeTo(const Tile& tile) const { 442 NSRect Tile::GetFaviconStartRectRelativeTo(const Tile& tile) const {
442 NSRect thumb_start = GetStartRectRelativeTo(tile); 443 NSRect thumb_start = GetStartRectRelativeTo(tile);
443 CGFloat scale_to_start = NSWidth(thumb_start) / NSWidth(thumb_rect_); 444 CGFloat scale_to_start = NSWidth(thumb_start) / NSWidth(thumb_rect_);
444 NSRect rect = 445 NSRect rect =
445 ScaleRectWithOrigin(favicon_rect_, thumb_rect_.origin, scale_to_start); 446 ScaleRectWithOrigin(favicon_rect_, thumb_rect_.origin, scale_to_start);
446 rect.origin.x += NSMinX(thumb_start) - NSMinX(thumb_rect_); 447 rect.origin.x += NSMinX(thumb_start) - NSMinX(thumb_rect_);
447 rect.origin.y += NSMinY(thumb_start) - NSMinY(thumb_rect_); 448 rect.origin.y += NSMinY(thumb_start) - NSMinY(thumb_rect_);
448 return rect; 449 return rect;
449 } 450 }
450 451
451 NSImage* Tile::favicon() const { 452 NSImage* Tile::favicon() const {
452 extensions::TabHelper* extensions_tab_helper = 453 extensions::TabHelper* extensions_tab_helper =
453 extensions::TabHelper::FromWebContents(contents_->web_contents()); 454 extensions::TabHelper::FromWebContents(contents_);
454 if (extensions_tab_helper->is_app()) { 455 if (extensions_tab_helper->is_app()) {
455 SkBitmap* bitmap = extensions_tab_helper->GetExtensionAppIcon(); 456 SkBitmap* bitmap = extensions_tab_helper->GetExtensionAppIcon();
456 if (bitmap) 457 if (bitmap)
457 return gfx::SkBitmapToNSImage(*bitmap); 458 return gfx::SkBitmapToNSImage(*bitmap);
458 } 459 }
459 return mac::FaviconForTabContents(contents_); 460 return mac::FaviconForWebContents(contents_);
460 } 461 }
461 462
462 NSRect Tile::GetTitleStartRectRelativeTo(const Tile& tile) const { 463 NSRect Tile::GetTitleStartRectRelativeTo(const Tile& tile) const {
463 NSRect thumb_start = GetStartRectRelativeTo(tile); 464 NSRect thumb_start = GetStartRectRelativeTo(tile);
464 CGFloat scale_to_start = NSWidth(thumb_start) / NSWidth(thumb_rect_); 465 CGFloat scale_to_start = NSWidth(thumb_start) / NSWidth(thumb_rect_);
465 NSRect rect = 466 NSRect rect =
466 ScaleRectWithOrigin(title_rect_, thumb_rect_.origin, scale_to_start); 467 ScaleRectWithOrigin(title_rect_, thumb_rect_.origin, scale_to_start);
467 rect.origin.x += NSMinX(thumb_start) - NSMinX(thumb_rect_); 468 rect.origin.x += NSMinX(thumb_start) - NSMinX(thumb_rect_);
468 rect.origin.y += NSMinY(thumb_start) - NSMinY(thumb_rect_); 469 rect.origin.y += NSMinY(thumb_start) - NSMinY(thumb_rect_);
469 return rect; 470 return rect;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 int down_index() const; 515 int down_index() const;
515 int left_index() const; 516 int left_index() const;
516 int right_index() const; 517 int right_index() const;
517 518
518 // These return which index needs to be selected on tab / shift-tab. 519 // These return which index needs to be selected on tab / shift-tab.
519 int next_index() const; 520 int next_index() const;
520 int previous_index() const; 521 int previous_index() const;
521 522
522 // Inserts a new Tile object containing |contents| at |index|. Does no 523 // Inserts a new Tile object containing |contents| at |index|. Does no
523 // relayout. 524 // relayout.
524 void InsertTileAt(int index, TabContents* contents); 525 void InsertTileAt(int index, content::WebContents* contents);
525 526
526 // Removes the Tile object at |index|. Does no relayout. 527 // Removes the Tile object at |index|. Does no relayout.
527 void RemoveTileAt(int index); 528 void RemoveTileAt(int index);
528 529
529 // Moves the Tile object at |from_index| to |to_index|. Since this doesn't 530 // Moves the Tile object at |from_index| to |to_index|. Since this doesn't
530 // change the number of tiles, relayout can be done just by swapping the 531 // change the number of tiles, relayout can be done just by swapping the
531 // tile rectangles in the index interval [from_index, to_index], so this does 532 // tile rectangles in the index interval [from_index, to_index], so this does
532 // layout. 533 // layout.
533 void MoveTileFromTo(int from_index, int to_index); 534 void MoveTileFromTo(int from_index, int to_index);
534 535
(...skipping 23 matching lines...) Expand all
558 int count_y_; 559 int count_y_;
559 560
560 DISALLOW_COPY_AND_ASSIGN(TileSet); 561 DISALLOW_COPY_AND_ASSIGN(TileSet);
561 }; 562 };
562 563
563 void TileSet::Build(TabStripModel* source_model) { 564 void TileSet::Build(TabStripModel* source_model) {
564 selected_index_ = source_model->active_index(); 565 selected_index_ = source_model->active_index();
565 tiles_.resize(source_model->count()); 566 tiles_.resize(source_model->count());
566 for (size_t i = 0; i < tiles_.size(); ++i) { 567 for (size_t i = 0; i < tiles_.size(); ++i) {
567 tiles_[i] = new Tile; 568 tiles_[i] = new Tile;
568 tiles_[i]->contents_ = source_model->GetTabContentsAt(i); 569 tiles_[i]->contents_ = source_model->GetWebContentsAt(i);
569 } 570 }
570 } 571 }
571 572
572 void TileSet::Layout(NSRect containing_rect) { 573 void TileSet::Layout(NSRect containing_rect) {
573 int tile_count = tiles_.size(); 574 int tile_count = tiles_.size();
574 if (tile_count == 0) // Happens e.g. during test shutdown. 575 if (tile_count == 0) // Happens e.g. during test shutdown.
575 return; 576 return;
576 577
577 // Room around the tiles insde of |containing_rect|. 578 // Room around the tiles insde of |containing_rect|.
578 const int kSmallPaddingTop = 30; 579 const int kSmallPaddingTop = 30;
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 return new_index; 781 return new_index;
781 } 782 }
782 783
783 int TileSet::previous_index() const { 784 int TileSet::previous_index() const {
784 int new_index = selected_index() - 1; 785 int new_index = selected_index() - 1;
785 if (new_index < 0) 786 if (new_index < 0)
786 new_index = tiles_.size() - 1; 787 new_index = tiles_.size() - 1;
787 return new_index; 788 return new_index;
788 } 789 }
789 790
790 void TileSet::InsertTileAt(int index, TabContents* contents) { 791 void TileSet::InsertTileAt(int index, content::WebContents* contents) {
791 tiles_.insert(tiles_.begin() + index, new Tile); 792 tiles_.insert(tiles_.begin() + index, new Tile);
792 tiles_[index]->contents_ = contents; 793 tiles_[index]->contents_ = contents;
793 } 794 }
794 795
795 void TileSet::RemoveTileAt(int index) { 796 void TileSet::RemoveTileAt(int index) {
796 tiles_.erase(tiles_.begin() + index); 797 tiles_.erase(tiles_.begin() + index);
797 } 798 }
798 799
799 // Moves the Tile object at |from_index| to |to_index|. Also updates rectangles 800 // Moves the Tile object at |from_index| to |to_index|. Also updates rectangles
800 // so that the tiles stay in a left-to-right, top-to-bottom layout when walked 801 // so that the tiles stay in a left-to-right, top-to-bottom layout when walked
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 tileSet_->set_selected_index(newIndex); 969 tileSet_->set_selected_index(newIndex);
969 970
970 [self updateClosebuttonLayersVisibility]; 971 [self updateClosebuttonLayersVisibility];
971 } 972 }
972 973
973 - (void)addLayersForTile:(tabpose::Tile&)tile 974 - (void)addLayersForTile:(tabpose::Tile&)tile
974 showZoom:(BOOL)showZoom 975 showZoom:(BOOL)showZoom
975 slomo:(BOOL)slomo 976 slomo:(BOOL)slomo
976 animationDelegate:(id)animationDelegate { 977 animationDelegate:(id)animationDelegate {
977 scoped_nsobject<CALayer> layer([[ThumbnailLayer alloc] 978 scoped_nsobject<CALayer> layer([[ThumbnailLayer alloc]
978 initWithTabContents:tile.tab_contents() 979 initWithWebContents:tile.web_contents()
979 fullSize:tile.GetStartRectRelativeTo( 980 fullSize:tile.GetStartRectRelativeTo(
980 tileSet_->selected_tile()).size]); 981 tileSet_->selected_tile()).size]);
981 [layer setNeedsDisplay]; 982 [layer setNeedsDisplay];
982 983
983 NSTimeInterval interval = 984 NSTimeInterval interval =
984 kDefaultAnimationDuration * (slomo ? kSlomoFactor : 1); 985 kDefaultAnimationDuration * (slomo ? kSlomoFactor : 1);
985 986
986 // Background color as placeholder for now. 987 // Background color as placeholder for now.
987 layer.get().backgroundColor = CGColorGetConstantColor(kCGColorWhite); 988 layer.get().backgroundColor = CGColorGetConstantColor(kCGColorWhite);
988 if (showZoom) { 989 if (showZoom) {
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
1509 1510
1510 CALayer* titleLayer = [allTitleLayers_ objectAtIndex:i]; 1511 CALayer* titleLayer = [allTitleLayers_ objectAtIndex:i];
1511 AnimateCALayerFrameFromTo( 1512 AnimateCALayerFrameFromTo(
1512 titleLayer, 1513 titleLayer,
1513 NSRectFromCGRect(titleLayer.frame), 1514 NSRectFromCGRect(titleLayer.frame),
1514 tile.title_rect(), 1515 tile.title_rect(),
1515 kObserverChangeAnimationDuration, 1516 kObserverChangeAnimationDuration,
1516 nil); 1517 nil);
1517 } 1518 }
1518 1519
1519 - (void)insertTabWithContents:(TabContents*)contents 1520 - (void)insertTabWithContents:(content::WebContents*)contents
1520 atIndex:(NSInteger)index 1521 atIndex:(NSInteger)index
1521 inForeground:(bool)inForeground { 1522 inForeground:(bool)inForeground {
1522 // This happens if you cmd-click a link and then immediately open tabpose 1523 // This happens if you cmd-click a link and then immediately open tabpose
1523 // on a slowish machine. 1524 // on a slowish machine.
1524 ScopedCAActionSetDuration durationSetter(kObserverChangeAnimationDuration); 1525 ScopedCAActionSetDuration durationSetter(kObserverChangeAnimationDuration);
1525 1526
1526 // Insert new layer and relayout. 1527 // Insert new layer and relayout.
1527 tileSet_->InsertTileAt(index, contents); 1528 tileSet_->InsertTileAt(index, contents);
1528 tileSet_->Layout(containingRect_); 1529 tileSet_->Layout(containingRect_);
1529 [self addLayersForTile:tileSet_->tile_at(index) 1530 [self addLayersForTile:tileSet_->tile_at(index)
(...skipping 16 matching lines...) Expand all
1546 [self selectTileAtIndexWithoutAnimation:selectedIndex]; 1547 [self selectTileAtIndexWithoutAnimation:selectedIndex];
1547 1548
1548 // Animate everything into its new place. 1549 // Animate everything into its new place.
1549 for (int i = 0; i < tabStripModel_->count(); ++i) { 1550 for (int i = 0; i < tabStripModel_->count(); ++i) {
1550 if (i == index) // The new layer. 1551 if (i == index) // The new layer.
1551 continue; 1552 continue;
1552 [self refreshLayerFramesAtIndex:i]; 1553 [self refreshLayerFramesAtIndex:i];
1553 } 1554 }
1554 } 1555 }
1555 1556
1556 - (void)tabClosingWithContents:(TabContents*)contents 1557 - (void)tabClosingWithContents:(content::WebContents*)contents
1557 atIndex:(NSInteger)index { 1558 atIndex:(NSInteger)index {
1558 // We will also get a -tabDetachedWithContents:atIndex: notification for 1559 // We will also get a -tabDetachedWithContents:atIndex: notification for
1559 // closing tabs, so do nothing here. 1560 // closing tabs, so do nothing here.
1560 } 1561 }
1561 1562
1562 - (void)tabDetachedWithContents:(TabContents*)contents 1563 - (void)tabDetachedWithContents:(content::WebContents*)contents
1563 atIndex:(NSInteger)index { 1564 atIndex:(NSInteger)index {
1564 ScopedCAActionSetDuration durationSetter(kObserverChangeAnimationDuration); 1565 ScopedCAActionSetDuration durationSetter(kObserverChangeAnimationDuration);
1565 1566
1566 // Remove layer and relayout. 1567 // Remove layer and relayout.
1567 tileSet_->RemoveTileAt(index); 1568 tileSet_->RemoveTileAt(index);
1568 tileSet_->Layout(containingRect_); 1569 tileSet_->Layout(containingRect_);
1569 1570
1570 { 1571 {
1571 ScopedCAActionDisabler disabler; 1572 ScopedCAActionDisabler disabler;
1572 [[allThumbnailLayers_ objectAtIndex:index] removeFromSuperlayer]; 1573 [[allThumbnailLayers_ objectAtIndex:index] removeFromSuperlayer];
(...skipping 20 matching lines...) Expand all
1593 if (selectedIndex > index || selectedIndex >= tabStripModel_->count()) 1594 if (selectedIndex > index || selectedIndex >= tabStripModel_->count())
1594 selectedIndex--; 1595 selectedIndex--;
1595 if (selectedIndex >= 0) 1596 if (selectedIndex >= 0)
1596 [self selectTileAtIndexWithoutAnimation:selectedIndex]; 1597 [self selectTileAtIndexWithoutAnimation:selectedIndex];
1597 1598
1598 // Animate everything into its new place. 1599 // Animate everything into its new place.
1599 for (int i = 0; i < tabStripModel_->count(); ++i) 1600 for (int i = 0; i < tabStripModel_->count(); ++i)
1600 [self refreshLayerFramesAtIndex:i]; 1601 [self refreshLayerFramesAtIndex:i];
1601 } 1602 }
1602 1603
1603 - (void)tabMovedWithContents:(TabContents*)contents 1604 - (void)tabMovedWithContents:(content::WebContents*)contents
1604 fromIndex:(NSInteger)from 1605 fromIndex:(NSInteger)from
1605 toIndex:(NSInteger)to { 1606 toIndex:(NSInteger)to {
1606 ScopedCAActionSetDuration durationSetter(kObserverChangeAnimationDuration); 1607 ScopedCAActionSetDuration durationSetter(kObserverChangeAnimationDuration);
1607 1608
1608 // Move tile from |from| to |to|. 1609 // Move tile from |from| to |to|.
1609 tileSet_->MoveTileFromTo(from, to); 1610 tileSet_->MoveTileFromTo(from, to);
1610 1611
1611 // Move corresponding layers from |from| to |to|. 1612 // Move corresponding layers from |from| to |to|.
1612 scoped_nsobject<CALayer> thumbLayer( 1613 scoped_nsobject<CALayer> thumbLayer(
1613 [[allThumbnailLayers_ objectAtIndex:from] retain]); 1614 [[allThumbnailLayers_ objectAtIndex:from] retain]);
(...skipping 16 matching lines...) Expand all
1630 selectedIndex--; 1631 selectedIndex--;
1631 else if (to <= selectedIndex && selectedIndex < from) 1632 else if (to <= selectedIndex && selectedIndex < from)
1632 selectedIndex++; 1633 selectedIndex++;
1633 [self selectTileAtIndexWithoutAnimation:selectedIndex]; 1634 [self selectTileAtIndexWithoutAnimation:selectedIndex];
1634 1635
1635 // Update frames of the layers. 1636 // Update frames of the layers.
1636 for (int i = std::min(from, to); i <= std::max(from, to); ++i) 1637 for (int i = std::min(from, to); i <= std::max(from, to); ++i)
1637 [self refreshLayerFramesAtIndex:i]; 1638 [self refreshLayerFramesAtIndex:i];
1638 } 1639 }
1639 1640
1640 - (void)tabChangedWithContents:(TabContents*)contents 1641 - (void)tabChangedWithContents:(content::WebContents*)contents
1641 atIndex:(NSInteger)index 1642 atIndex:(NSInteger)index
1642 changeType:(TabStripModelObserver::TabChangeType)change { 1643 changeType:(TabStripModelObserver::TabChangeType)change {
1643 // Tell the window to update text, title, and thumb layers at |index| to get 1644 // Tell the window to update text, title, and thumb layers at |index| to get
1644 // their data from |contents|. |contents| can be different from the old 1645 // their data from |contents|. |contents| can be different from the old
1645 // contents at that index! 1646 // contents at that index!
1646 // While a tab is loading, this is unfortunately called quite often for 1647 // While a tab is loading, this is unfortunately called quite often for
1647 // both the "loading" and the "all" change types, so we don't really want to 1648 // both the "loading" and the "all" change types, so we don't really want to
1648 // send thumb requests to the corresponding renderer when this is called. 1649 // send thumb requests to the corresponding renderer when this is called.
1649 // For now, just make sure that we don't hold on to an invalid WebContents 1650 // For now, just make sure that we don't hold on to an invalid WebContents
1650 // object. 1651 // object.
1651 tabpose::Tile& tile = tileSet_->tile_at(index); 1652 tabpose::Tile& tile = tileSet_->tile_at(index);
1652 if (contents == tile.tab_contents()) { 1653 if (contents == tile.web_contents()) {
1653 // TODO(thakis): Install a timer to send a thumb request/update title/update 1654 // TODO(thakis): Install a timer to send a thumb request/update title/update
1654 // favicon after 20ms or so, and reset the timer every time this is called 1655 // favicon after 20ms or so, and reset the timer every time this is called
1655 // to make sure we get an updated thumb, without requesting them all over. 1656 // to make sure we get an updated thumb, without requesting them all over.
1656 return; 1657 return;
1657 } 1658 }
1658 1659
1659 tile.set_tab_contents(contents); 1660 tile.set_tab_contents(contents);
1660 ThumbnailLayer* thumbLayer = [allThumbnailLayers_ objectAtIndex:index]; 1661 ThumbnailLayer* thumbLayer = [allThumbnailLayers_ objectAtIndex:index];
1661 [thumbLayer setTabContents:contents]; 1662 [thumbLayer setWebContents:contents];
1662 } 1663 }
1663 1664
1664 - (void)tabStripModelDeleted { 1665 - (void)tabStripModelDeleted {
1665 [self close]; 1666 [self close];
1666 } 1667 }
1667 1668
1668 @end 1669 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.mm ('k') | chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698