OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/tabpose_window.h" | 5 #import "chrome/browser/cocoa/tabpose_window.h" |
6 | 6 |
7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
8 | 8 |
9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
10 #include "base/mac_util.h" | 10 #include "base/mac_util.h" |
11 #include "base/mac/scoped_cftyperef.h" | 11 #include "base/mac/scoped_cftyperef.h" |
12 #include "base/scoped_callback_factory.h" | 12 #include "base/scoped_callback_factory.h" |
13 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
14 #include "chrome/app/chrome_command_ids.h" | 14 #include "chrome/app/chrome_command_ids.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #import "chrome/browser/cocoa/bookmarks/bookmark_bar_constants.h" | 16 #import "chrome/browser/cocoa/bookmarks/bookmark_bar_constants.h" |
17 #import "chrome/browser/cocoa/browser_window_controller.h" | 17 #import "chrome/browser/cocoa/browser_window_controller.h" |
18 #import "chrome/browser/cocoa/tab_strip_controller.h" | 18 #import "chrome/browser/cocoa/tab_strip_controller.h" |
19 #import "chrome/browser/cocoa/tab_strip_model_observer_bridge.h" | 19 #import "chrome/browser/cocoa/tab_strip_model_observer_bridge.h" |
20 #import "chrome/browser/debugger/devtools_window.h" | 20 #import "chrome/browser/debugger/devtools_window.h" |
21 #include "chrome/browser/prefs/pref_service.h" | 21 #include "chrome/browser/prefs/pref_service.h" |
22 #include "chrome/browser/renderer_host/backing_store_mac.h" | 22 #include "chrome/browser/renderer_host/backing_store_mac.h" |
23 #include "chrome/browser/renderer_host/render_view_host.h" | 23 #include "chrome/browser/renderer_host/render_view_host.h" |
24 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" | 24 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" |
25 #include "chrome/browser/tab_contents/tab_contents.h" | 25 #include "chrome/browser/tab_contents/tab_contents.h" |
| 26 #include "chrome/browser/tab_contents_wrapper.h" |
26 #include "chrome/browser/tab_contents/thumbnail_generator.h" | 27 #include "chrome/browser/tab_contents/thumbnail_generator.h" |
| 28 #include "chrome/browser/tab_contents_wrapper.h" |
27 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
28 #include "grit/app_resources.h" | 30 #include "grit/app_resources.h" |
29 #include "skia/ext/skia_utils_mac.h" | 31 #include "skia/ext/skia_utils_mac.h" |
30 #include "third_party/skia/include/utils/mac/SkCGUtils.h" | 32 #include "third_party/skia/include/utils/mac/SkCGUtils.h" |
31 | 33 |
32 const int kTopGradientHeight = 15; | 34 const int kTopGradientHeight = 15; |
33 | 35 |
34 NSString* const kAnimationIdKey = @"AnimationId"; | 36 NSString* const kAnimationIdKey = @"AnimationId"; |
35 NSString* const kAnimationIdFadeIn = @"FadeIn"; | 37 NSString* const kAnimationIdFadeIn = @"FadeIn"; |
36 NSString* const kAnimationIdFadeOut = @"FadeOut"; | 38 NSString* const kAnimationIdFadeOut = @"FadeOut"; |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 int count_y_; | 517 int count_y_; |
516 | 518 |
517 DISALLOW_COPY_AND_ASSIGN(TileSet); | 519 DISALLOW_COPY_AND_ASSIGN(TileSet); |
518 }; | 520 }; |
519 | 521 |
520 void TileSet::Build(TabStripModel* source_model) { | 522 void TileSet::Build(TabStripModel* source_model) { |
521 selected_index_ = source_model->selected_index(); | 523 selected_index_ = source_model->selected_index(); |
522 tiles_.resize(source_model->count()); | 524 tiles_.resize(source_model->count()); |
523 for (size_t i = 0; i < tiles_.size(); ++i) { | 525 for (size_t i = 0; i < tiles_.size(); ++i) { |
524 tiles_[i] = new Tile; | 526 tiles_[i] = new Tile; |
525 tiles_[i]->contents_ = source_model->GetTabContentsAt(i); | 527 tiles_[i]->contents_ = source_model->GetTabContentsAt(i)->tab_contents(); |
526 } | 528 } |
527 } | 529 } |
528 | 530 |
529 void TileSet::Layout(NSRect containing_rect) { | 531 void TileSet::Layout(NSRect containing_rect) { |
530 int tile_count = tiles_.size(); | 532 int tile_count = tiles_.size(); |
531 if (tile_count == 0) // Happens e.g. during test shutdown. | 533 if (tile_count == 0) // Happens e.g. during test shutdown. |
532 return; | 534 return; |
533 | 535 |
534 // Room around the tiles insde of |containing_rect|. | 536 // Room around the tiles insde of |containing_rect|. |
535 const int kSmallPaddingTop = 30; | 537 const int kSmallPaddingTop = 30; |
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1274 const tabpose::Tile& tile = tileSet_->tile_at(i); | 1276 const tabpose::Tile& tile = tileSet_->tile_at(i); |
1275 | 1277 |
1276 CALayer* faviconLayer = [allFaviconLayers_ objectAtIndex:i]; | 1278 CALayer* faviconLayer = [allFaviconLayers_ objectAtIndex:i]; |
1277 faviconLayer.frame = NSRectToCGRect(tile.favicon_rect()); | 1279 faviconLayer.frame = NSRectToCGRect(tile.favicon_rect()); |
1278 CALayer* titleLayer = [allTitleLayers_ objectAtIndex:i]; | 1280 CALayer* titleLayer = [allTitleLayers_ objectAtIndex:i]; |
1279 titleLayer.frame = NSRectToCGRect(tile.title_rect()); | 1281 titleLayer.frame = NSRectToCGRect(tile.title_rect()); |
1280 CALayer* thumbLayer = [allThumbnailLayers_ objectAtIndex:i]; | 1282 CALayer* thumbLayer = [allThumbnailLayers_ objectAtIndex:i]; |
1281 thumbLayer.frame = NSRectToCGRect(tile.thumb_rect()); | 1283 thumbLayer.frame = NSRectToCGRect(tile.thumb_rect()); |
1282 } | 1284 } |
1283 | 1285 |
1284 - (void)insertTabWithContents:(TabContents*)contents | 1286 - (void)insertTabWithContents:(TabContentsWrapper*)contents |
1285 atIndex:(NSInteger)index | 1287 atIndex:(NSInteger)index |
1286 inForeground:(bool)inForeground { | 1288 inForeground:(bool)inForeground { |
1287 // This happens if you cmd-click a link and then immediately open tabpose | 1289 // This happens if you cmd-click a link and then immediately open tabpose |
1288 // on a slowish machine. | 1290 // on a slowish machine. |
1289 ScopedCAActionSetDuration durationSetter(kObserverChangeAnimationDuration); | 1291 ScopedCAActionSetDuration durationSetter(kObserverChangeAnimationDuration); |
1290 | 1292 |
1291 // Insert new layer and relayout. | 1293 // Insert new layer and relayout. |
1292 tileSet_->InsertTileAt(index, contents); | 1294 tileSet_->InsertTileAt(index, contents->tab_contents()); |
1293 tileSet_->Layout(containingRect_); | 1295 tileSet_->Layout(containingRect_); |
1294 [self addLayersForTile:tileSet_->tile_at(index) | 1296 [self addLayersForTile:tileSet_->tile_at(index) |
1295 showZoom:NO | 1297 showZoom:NO |
1296 slomo:NO | 1298 slomo:NO |
1297 animationDelegate:nil]; | 1299 animationDelegate:nil]; |
1298 | 1300 |
1299 // Update old layers. | 1301 // Update old layers. |
1300 DCHECK_EQ(tabStripModel_->count(), | 1302 DCHECK_EQ(tabStripModel_->count(), |
1301 static_cast<int>([allThumbnailLayers_ count])); | 1303 static_cast<int>([allThumbnailLayers_ count])); |
1302 DCHECK_EQ(tabStripModel_->count(), | 1304 DCHECK_EQ(tabStripModel_->count(), |
1303 static_cast<int>([allTitleLayers_ count])); | 1305 static_cast<int>([allTitleLayers_ count])); |
1304 DCHECK_EQ(tabStripModel_->count(), | 1306 DCHECK_EQ(tabStripModel_->count(), |
1305 static_cast<int>([allFaviconLayers_ count])); | 1307 static_cast<int>([allFaviconLayers_ count])); |
1306 | 1308 |
1307 for (int i = 0; i < tabStripModel_->count(); ++i) { | 1309 for (int i = 0; i < tabStripModel_->count(); ++i) { |
1308 if (i == index) // The new layer. | 1310 if (i == index) // The new layer. |
1309 continue; | 1311 continue; |
1310 [self refreshLayerFramesAtIndex:i]; | 1312 [self refreshLayerFramesAtIndex:i]; |
1311 } | 1313 } |
1312 | 1314 |
1313 // Update selection. | 1315 // Update selection. |
1314 int selectedIndex = tileSet_->selected_index(); | 1316 int selectedIndex = tileSet_->selected_index(); |
1315 if (selectedIndex >= index) | 1317 if (selectedIndex >= index) |
1316 selectedIndex++; | 1318 selectedIndex++; |
1317 [self selectTileAtIndex:selectedIndex]; | 1319 [self selectTileAtIndex:selectedIndex]; |
1318 } | 1320 } |
1319 | 1321 |
1320 - (void)tabClosingWithContents:(TabContents*)contents | 1322 - (void)tabClosingWithContents:(TabContentsWrapper*)contents |
1321 atIndex:(NSInteger)index { | 1323 atIndex:(NSInteger)index { |
1322 // We will also get a -tabDetachedWithContents:atIndex: notification for | 1324 // We will also get a -tabDetachedWithContents:atIndex: notification for |
1323 // closing tabs, so do nothing here. | 1325 // closing tabs, so do nothing here. |
1324 } | 1326 } |
1325 | 1327 |
1326 - (void)tabDetachedWithContents:(TabContents*)contents | 1328 - (void)tabDetachedWithContents:(TabContentsWrapper*)contents |
1327 atIndex:(NSInteger)index { | 1329 atIndex:(NSInteger)index { |
1328 ScopedCAActionSetDuration durationSetter(kObserverChangeAnimationDuration); | 1330 ScopedCAActionSetDuration durationSetter(kObserverChangeAnimationDuration); |
1329 | 1331 |
1330 // Remove layer and relayout. | 1332 // Remove layer and relayout. |
1331 tileSet_->RemoveTileAt(index); | 1333 tileSet_->RemoveTileAt(index); |
1332 tileSet_->Layout(containingRect_); | 1334 tileSet_->Layout(containingRect_); |
1333 | 1335 |
1334 [[allThumbnailLayers_ objectAtIndex:index] removeFromSuperlayer]; | 1336 [[allThumbnailLayers_ objectAtIndex:index] removeFromSuperlayer]; |
1335 [allThumbnailLayers_ removeObjectAtIndex:index]; | 1337 [allThumbnailLayers_ removeObjectAtIndex:index]; |
1336 [[allTitleLayers_ objectAtIndex:index] removeFromSuperlayer]; | 1338 [[allTitleLayers_ objectAtIndex:index] removeFromSuperlayer]; |
(...skipping 16 matching lines...) Expand all Loading... |
1353 [self refreshLayerFramesAtIndex:i]; | 1355 [self refreshLayerFramesAtIndex:i]; |
1354 | 1356 |
1355 // Update selection. | 1357 // Update selection. |
1356 int selectedIndex = tileSet_->selected_index(); | 1358 int selectedIndex = tileSet_->selected_index(); |
1357 if (selectedIndex >= index) | 1359 if (selectedIndex >= index) |
1358 selectedIndex--; | 1360 selectedIndex--; |
1359 if (selectedIndex >= 0) | 1361 if (selectedIndex >= 0) |
1360 [self selectTileAtIndex:selectedIndex]; | 1362 [self selectTileAtIndex:selectedIndex]; |
1361 } | 1363 } |
1362 | 1364 |
1363 - (void)tabMovedWithContents:(TabContents*)contents | 1365 - (void)tabMovedWithContents:(TabContentsWrapper*)contents |
1364 fromIndex:(NSInteger)from | 1366 fromIndex:(NSInteger)from |
1365 toIndex:(NSInteger)to { | 1367 toIndex:(NSInteger)to { |
1366 ScopedCAActionSetDuration durationSetter(kObserverChangeAnimationDuration); | 1368 ScopedCAActionSetDuration durationSetter(kObserverChangeAnimationDuration); |
1367 | 1369 |
1368 // Move tile from |from| to |to|. | 1370 // Move tile from |from| to |to|. |
1369 tileSet_->MoveTileFromTo(from, to); | 1371 tileSet_->MoveTileFromTo(from, to); |
1370 | 1372 |
1371 // Move corresponding layers from |from| to |to|. | 1373 // Move corresponding layers from |from| to |to|. |
1372 scoped_nsobject<CALayer> thumbLayer( | 1374 scoped_nsobject<CALayer> thumbLayer( |
1373 [[allThumbnailLayers_ objectAtIndex:from] retain]); | 1375 [[allThumbnailLayers_ objectAtIndex:from] retain]); |
(...skipping 16 matching lines...) Expand all Loading... |
1390 int selectedIndex = tileSet_->selected_index(); | 1392 int selectedIndex = tileSet_->selected_index(); |
1391 if (from == selectedIndex) | 1393 if (from == selectedIndex) |
1392 selectedIndex = to; | 1394 selectedIndex = to; |
1393 else if (from < selectedIndex && selectedIndex <= to) | 1395 else if (from < selectedIndex && selectedIndex <= to) |
1394 selectedIndex--; | 1396 selectedIndex--; |
1395 else if (to <= selectedIndex && selectedIndex < from) | 1397 else if (to <= selectedIndex && selectedIndex < from) |
1396 selectedIndex++; | 1398 selectedIndex++; |
1397 [self selectTileAtIndex:selectedIndex]; | 1399 [self selectTileAtIndex:selectedIndex]; |
1398 } | 1400 } |
1399 | 1401 |
1400 - (void)tabChangedWithContents:(TabContents*)contents | 1402 - (void)tabChangedWithContents:(TabContentsWrapper*)contents |
1401 atIndex:(NSInteger)index | 1403 atIndex:(NSInteger)index |
1402 changeType:(TabStripModelObserver::TabChangeType)change { | 1404 changeType:(TabStripModelObserver::TabChangeType)change { |
1403 // Tell the window to update text, title, and thumb layers at |index| to get | 1405 // Tell the window to update text, title, and thumb layers at |index| to get |
1404 // their data from |contents|. |contents| can be different from the old | 1406 // their data from |contents|. |contents| can be different from the old |
1405 // contents at that index! | 1407 // contents at that index! |
1406 // While a tab is loading, this is unfortunately called quite often for | 1408 // While a tab is loading, this is unfortunately called quite often for |
1407 // both the "loading" and the "all" change types, so we don't really want to | 1409 // both the "loading" and the "all" change types, so we don't really want to |
1408 // send thumb requests to the corresponding renderer when this is called. | 1410 // send thumb requests to the corresponding renderer when this is called. |
1409 // For now, just make sure that we don't hold on to an invalid TabContents | 1411 // For now, just make sure that we don't hold on to an invalid TabContents |
1410 // object. | 1412 // object. |
1411 tabpose::Tile& tile = tileSet_->tile_at(index); | 1413 tabpose::Tile& tile = tileSet_->tile_at(index); |
1412 if (contents == tile.tab_contents()) { | 1414 if (contents->tab_contents() == tile.tab_contents()) { |
1413 // TODO(thakis): Install a timer to send a thumb request/update title/update | 1415 // TODO(thakis): Install a timer to send a thumb request/update title/update |
1414 // favicon after 20ms or so, and reset the timer every time this is called | 1416 // favicon after 20ms or so, and reset the timer every time this is called |
1415 // to make sure we get an updated thumb, without requesting them all over. | 1417 // to make sure we get an updated thumb, without requesting them all over. |
1416 return; | 1418 return; |
1417 } | 1419 } |
1418 | 1420 |
1419 tile.set_tab_contents(contents); | 1421 tile.set_tab_contents(contents->tab_contents()); |
1420 ThumbnailLayer* thumbLayer = [allThumbnailLayers_ objectAtIndex:index]; | 1422 ThumbnailLayer* thumbLayer = [allThumbnailLayers_ objectAtIndex:index]; |
1421 [thumbLayer setTabContents:contents]; | 1423 [thumbLayer setTabContents:contents->tab_contents()]; |
1422 } | 1424 } |
1423 | 1425 |
1424 - (void)tabStripModelDeleted { | 1426 - (void)tabStripModelDeleted { |
1425 [self close]; | 1427 [self close]; |
1426 } | 1428 } |
1427 | 1429 |
1428 @end | 1430 @end |
OLD | NEW |