| OLD | NEW |
| 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 |
| 11 #include "base/mac/mac_util.h" | 11 #include "base/mac/mac_util.h" |
| 12 #include "base/mac/scoped_cftyperef.h" | 12 #include "base/mac/scoped_cftyperef.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/sys_string_conversions.h" | 14 #include "base/sys_string_conversions.h" |
| 15 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/debugger/devtools_window.h" | 17 #include "chrome/browser/debugger/devtools_window.h" |
| 18 #include "chrome/browser/extensions/extension_tab_helper.h" | 18 #include "chrome/browser/extensions/extension_tab_helper.h" |
| 19 #include "chrome/browser/prefs/pref_service.h" | 19 #include "chrome/browser/prefs/pref_service.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/tab_contents/thumbnail_generator.h" | 21 #include "chrome/browser/tab_contents/thumbnail_generator.h" |
| 22 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | 22 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
| 23 #include "chrome/browser/ui/cocoa/animation_utils.h" | 23 #include "chrome/browser/ui/cocoa/animation_utils.h" |
| 24 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" | 24 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" |
| 25 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 25 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 26 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" | 26 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" |
| 27 #import "chrome/browser/ui/cocoa/tab_contents/favicon_util.h" | 27 #import "chrome/browser/ui/cocoa/tab_contents/favicon_util.h" |
| 28 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 28 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
| 29 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" | 29 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" |
| 30 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 30 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 31 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 32 #include "content/public/browser/render_view_host.h" | 32 #include "content/public/browser/render_view_host.h" |
| 33 #include "content/public/browser/render_widget_host_view.h" | 33 #include "content/public/browser/render_widget_host_view.h" |
| 34 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
| 35 #include "grit/theme_resources.h" | 35 #include "grit/theme_resources.h" |
| 36 #include "grit/ui_resources.h" | 36 #include "grit/ui_resources.h" |
| 37 #include "skia/ext/skia_utils_mac.h" | 37 #include "skia/ext/skia_utils_mac.h" |
| 38 #include "third_party/skia/include/utils/mac/SkCGUtils.h" | 38 #include "third_party/skia/include/utils/mac/SkCGUtils.h" |
| 39 #include "ui/base/resource/resource_bundle.h" | 39 #include "ui/base/resource/resource_bundle.h" |
| 40 #include "ui/gfx/image/image.h" | 40 #include "ui/gfx/image/image.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 TabContentsWrapper object. The layer | 107 // A CALayer that draws a thumbnail for a TabContents 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 TabContentsWrapper the thumbnail is for. | 111 // The TabContents the thumbnail is for. |
| 112 TabContentsWrapper* contents_; // weak | 112 TabContents* 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:(TabContentsWrapper*)contents | 127 - (id)initWithTabContents:(TabContents*)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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 base::Bind(&ThumbnailLoader::DidReceiveBitmap, | 189 base::Bind(&ThumbnailLoader::DidReceiveBitmap, |
| 190 weak_factory_.GetWeakPtr()), | 190 weak_factory_.GetWeakPtr()), |
| 191 page_size, | 191 page_size, |
| 192 pixel_size); | 192 pixel_size); |
| 193 } | 193 } |
| 194 | 194 |
| 195 } // namespace tabpose | 195 } // namespace tabpose |
| 196 | 196 |
| 197 @implementation ThumbnailLayer | 197 @implementation ThumbnailLayer |
| 198 | 198 |
| 199 - (id)initWithTabContents:(TabContentsWrapper*)contents | 199 - (id)initWithTabContents:(TabContents*)contents |
| 200 fullSize:(NSSize)fullSize { | 200 fullSize:(NSSize)fullSize { |
| 201 CHECK(contents); | 201 CHECK(contents); |
| 202 if ((self = [super init])) { | 202 if ((self = [super init])) { |
| 203 contents_ = contents; | 203 contents_ = contents; |
| 204 fullSize_ = fullSize; | 204 fullSize_ = fullSize; |
| 205 } | 205 } |
| 206 return self; | 206 return self; |
| 207 } | 207 } |
| 208 | 208 |
| 209 - (void)setTabContents:(TabContentsWrapper*)contents { | 209 - (void)setTabContents:(TabContents*)contents { |
| 210 contents_ = contents; | 210 contents_ = contents; |
| 211 } | 211 } |
| 212 | 212 |
| 213 - (void)setThumbnail:(const SkBitmap&)bitmap { | 213 - (void)setThumbnail:(const SkBitmap&)bitmap { |
| 214 // SkCreateCGImageRef() holds on to |bitmaps|'s memory, so this doesn't | 214 // SkCreateCGImageRef() holds on to |bitmaps|'s memory, so this doesn't |
| 215 // create a copy. The renderer always draws data in the system colorspace. | 215 // create a copy. The renderer always draws data in the system colorspace. |
| 216 thumbnail_.reset(SkCreateCGImageRefWithColorspace( | 216 thumbnail_.reset(SkCreateCGImageRefWithColorspace( |
| 217 bitmap, base::mac::GetSystemColorSpace())); | 217 bitmap, base::mac::GetSystemColorSpace())); |
| 218 loader_ = NULL; | 218 loader_ = NULL; |
| 219 [self setNeedsDisplay]; | 219 [self setNeedsDisplay]; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 243 contents_->bookmark_tab_helper()->ShouldShowBookmarkBar() && | 243 contents_->bookmark_tab_helper()->ShouldShowBookmarkBar() && |
| 244 !always_show_bookmark_bar; | 244 !always_show_bookmark_bar; |
| 245 if (has_detached_bookmark_bar) | 245 if (has_detached_bookmark_bar) |
| 246 topOffset += bookmarks::kNTPBookmarkBarHeight; | 246 topOffset += bookmarks::kNTPBookmarkBarHeight; |
| 247 | 247 |
| 248 return topOffset; | 248 return topOffset; |
| 249 } | 249 } |
| 250 | 250 |
| 251 - (int)bottomOffset { | 251 - (int)bottomOffset { |
| 252 int bottomOffset = 0; | 252 int bottomOffset = 0; |
| 253 TabContentsWrapper* devToolsContents = | 253 TabContents* devToolsContents = |
| 254 DevToolsWindow::GetDevToolsContents(contents_->web_contents()); | 254 DevToolsWindow::GetDevToolsContents(contents_->web_contents()); |
| 255 if (devToolsContents && devToolsContents->web_contents() && | 255 if (devToolsContents && devToolsContents->web_contents() && |
| 256 devToolsContents->web_contents()->GetRenderViewHost() && | 256 devToolsContents->web_contents()->GetRenderViewHost() && |
| 257 devToolsContents->web_contents()->GetRenderViewHost()->GetView()) { | 257 devToolsContents->web_contents()->GetRenderViewHost()->GetView()) { |
| 258 // The devtool's size might not be up-to-date, but since its height doesn't | 258 // The devtool's size might not be up-to-date, but since its height doesn't |
| 259 // change on window resize, and since most users don't use devtools, this is | 259 // change on window resize, and since most users don't use devtools, this is |
| 260 // good enough. | 260 // good enough. |
| 261 bottomOffset += | 261 bottomOffset += |
| 262 devToolsContents->web_contents()->GetRenderViewHost()->GetView()-> | 262 devToolsContents->web_contents()->GetRenderViewHost()->GetView()-> |
| 263 GetViewBounds().height(); | 263 GetViewBounds().height(); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 CGFloat title_font_size() const { return title_font_size_; } | 409 CGFloat title_font_size() const { return title_font_size_; } |
| 410 | 410 |
| 411 NSRect GetTitleStartRectRelativeTo(const Tile& tile) const; | 411 NSRect GetTitleStartRectRelativeTo(const Tile& tile) const; |
| 412 NSRect title_rect() const { return NSIntegralRect(title_rect_); } | 412 NSRect title_rect() const { return NSIntegralRect(title_rect_); } |
| 413 | 413 |
| 414 // Returns an unelided title. The view logic is responsible for eliding. | 414 // Returns an unelided title. The view logic is responsible for eliding. |
| 415 const string16& title() const { | 415 const string16& title() const { |
| 416 return contents_->web_contents()->GetTitle(); | 416 return contents_->web_contents()->GetTitle(); |
| 417 } | 417 } |
| 418 | 418 |
| 419 TabContentsWrapper* tab_contents() const { return contents_; } | 419 TabContents* tab_contents() const { return contents_; } |
| 420 void set_tab_contents(TabContentsWrapper* new_contents) { | 420 void set_tab_contents(TabContents* new_contents) { |
| 421 contents_ = new_contents; | 421 contents_ = new_contents; |
| 422 } | 422 } |
| 423 | 423 |
| 424 private: | 424 private: |
| 425 friend class TileSet; | 425 friend class TileSet; |
| 426 | 426 |
| 427 // The thumb rect includes infobars, detached thumbnail bar, web contents, | 427 // The thumb rect includes infobars, detached thumbnail bar, web contents, |
| 428 // and devtools. | 428 // and devtools. |
| 429 NSRect thumb_rect_; | 429 NSRect thumb_rect_; |
| 430 NSRect start_thumb_rect_; | 430 NSRect start_thumb_rect_; |
| 431 | 431 |
| 432 NSRect favicon_rect_; | 432 NSRect favicon_rect_; |
| 433 | 433 |
| 434 CGFloat title_font_size_; | 434 CGFloat title_font_size_; |
| 435 NSRect title_rect_; | 435 NSRect title_rect_; |
| 436 | 436 |
| 437 TabContentsWrapper* contents_; // weak | 437 TabContents* contents_; // weak |
| 438 | 438 |
| 439 DISALLOW_COPY_AND_ASSIGN(Tile); | 439 DISALLOW_COPY_AND_ASSIGN(Tile); |
| 440 }; | 440 }; |
| 441 | 441 |
| 442 NSRect Tile::GetStartRectRelativeTo(const Tile& tile) const { | 442 NSRect Tile::GetStartRectRelativeTo(const Tile& tile) const { |
| 443 NSRect rect = start_thumb_rect_; | 443 NSRect rect = start_thumb_rect_; |
| 444 rect.origin.x -= tile.start_thumb_rect_.origin.x; | 444 rect.origin.x -= tile.start_thumb_rect_.origin.x; |
| 445 rect.origin.y -= tile.start_thumb_rect_.origin.y; | 445 rect.origin.y -= tile.start_thumb_rect_.origin.y; |
| 446 return rect; | 446 return rect; |
| 447 } | 447 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 int down_index() const; | 520 int down_index() const; |
| 521 int left_index() const; | 521 int left_index() const; |
| 522 int right_index() const; | 522 int right_index() const; |
| 523 | 523 |
| 524 // These return which index needs to be selected on tab / shift-tab. | 524 // These return which index needs to be selected on tab / shift-tab. |
| 525 int next_index() const; | 525 int next_index() const; |
| 526 int previous_index() const; | 526 int previous_index() const; |
| 527 | 527 |
| 528 // Inserts a new Tile object containing |contents| at |index|. Does no | 528 // Inserts a new Tile object containing |contents| at |index|. Does no |
| 529 // relayout. | 529 // relayout. |
| 530 void InsertTileAt(int index, TabContentsWrapper* contents); | 530 void InsertTileAt(int index, TabContents* contents); |
| 531 | 531 |
| 532 // Removes the Tile object at |index|. Does no relayout. | 532 // Removes the Tile object at |index|. Does no relayout. |
| 533 void RemoveTileAt(int index); | 533 void RemoveTileAt(int index); |
| 534 | 534 |
| 535 // Moves the Tile object at |from_index| to |to_index|. Since this doesn't | 535 // Moves the Tile object at |from_index| to |to_index|. Since this doesn't |
| 536 // change the number of tiles, relayout can be done just by swapping the | 536 // change the number of tiles, relayout can be done just by swapping the |
| 537 // tile rectangles in the index interval [from_index, to_index], so this does | 537 // tile rectangles in the index interval [from_index, to_index], so this does |
| 538 // layout. | 538 // layout. |
| 539 void MoveTileFromTo(int from_index, int to_index); | 539 void MoveTileFromTo(int from_index, int to_index); |
| 540 | 540 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 return new_index; | 786 return new_index; |
| 787 } | 787 } |
| 788 | 788 |
| 789 int TileSet::previous_index() const { | 789 int TileSet::previous_index() const { |
| 790 int new_index = selected_index() - 1; | 790 int new_index = selected_index() - 1; |
| 791 if (new_index < 0) | 791 if (new_index < 0) |
| 792 new_index = tiles_.size() - 1; | 792 new_index = tiles_.size() - 1; |
| 793 return new_index; | 793 return new_index; |
| 794 } | 794 } |
| 795 | 795 |
| 796 void TileSet::InsertTileAt(int index, TabContentsWrapper* contents) { | 796 void TileSet::InsertTileAt(int index, TabContents* contents) { |
| 797 tiles_.insert(tiles_.begin() + index, new Tile); | 797 tiles_.insert(tiles_.begin() + index, new Tile); |
| 798 tiles_[index]->contents_ = contents; | 798 tiles_[index]->contents_ = contents; |
| 799 } | 799 } |
| 800 | 800 |
| 801 void TileSet::RemoveTileAt(int index) { | 801 void TileSet::RemoveTileAt(int index) { |
| 802 tiles_.erase(tiles_.begin() + index); | 802 tiles_.erase(tiles_.begin() + index); |
| 803 } | 803 } |
| 804 | 804 |
| 805 // Moves the Tile object at |from_index| to |to_index|. Also updates rectangles | 805 // Moves the Tile object at |from_index| to |to_index|. Also updates rectangles |
| 806 // so that the tiles stay in a left-to-right, top-to-bottom layout when walked | 806 // so that the tiles stay in a left-to-right, top-to-bottom layout when walked |
| (...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1515 | 1515 |
| 1516 CALayer* titleLayer = [allTitleLayers_ objectAtIndex:i]; | 1516 CALayer* titleLayer = [allTitleLayers_ objectAtIndex:i]; |
| 1517 AnimateCALayerFrameFromTo( | 1517 AnimateCALayerFrameFromTo( |
| 1518 titleLayer, | 1518 titleLayer, |
| 1519 NSRectFromCGRect(titleLayer.frame), | 1519 NSRectFromCGRect(titleLayer.frame), |
| 1520 tile.title_rect(), | 1520 tile.title_rect(), |
| 1521 kObserverChangeAnimationDuration, | 1521 kObserverChangeAnimationDuration, |
| 1522 nil); | 1522 nil); |
| 1523 } | 1523 } |
| 1524 | 1524 |
| 1525 - (void)insertTabWithContents:(TabContentsWrapper*)contents | 1525 - (void)insertTabWithContents:(TabContents*)contents |
| 1526 atIndex:(NSInteger)index | 1526 atIndex:(NSInteger)index |
| 1527 inForeground:(bool)inForeground { | 1527 inForeground:(bool)inForeground { |
| 1528 // This happens if you cmd-click a link and then immediately open tabpose | 1528 // This happens if you cmd-click a link and then immediately open tabpose |
| 1529 // on a slowish machine. | 1529 // on a slowish machine. |
| 1530 ScopedCAActionSetDuration durationSetter(kObserverChangeAnimationDuration); | 1530 ScopedCAActionSetDuration durationSetter(kObserverChangeAnimationDuration); |
| 1531 | 1531 |
| 1532 // Insert new layer and relayout. | 1532 // Insert new layer and relayout. |
| 1533 tileSet_->InsertTileAt(index, contents); | 1533 tileSet_->InsertTileAt(index, contents); |
| 1534 tileSet_->Layout(containingRect_); | 1534 tileSet_->Layout(containingRect_); |
| 1535 [self addLayersForTile:tileSet_->tile_at(index) | 1535 [self addLayersForTile:tileSet_->tile_at(index) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1552 [self selectTileAtIndexWithoutAnimation:selectedIndex]; | 1552 [self selectTileAtIndexWithoutAnimation:selectedIndex]; |
| 1553 | 1553 |
| 1554 // Animate everything into its new place. | 1554 // Animate everything into its new place. |
| 1555 for (int i = 0; i < tabStripModel_->count(); ++i) { | 1555 for (int i = 0; i < tabStripModel_->count(); ++i) { |
| 1556 if (i == index) // The new layer. | 1556 if (i == index) // The new layer. |
| 1557 continue; | 1557 continue; |
| 1558 [self refreshLayerFramesAtIndex:i]; | 1558 [self refreshLayerFramesAtIndex:i]; |
| 1559 } | 1559 } |
| 1560 } | 1560 } |
| 1561 | 1561 |
| 1562 - (void)tabClosingWithContents:(TabContentsWrapper*)contents | 1562 - (void)tabClosingWithContents:(TabContents*)contents |
| 1563 atIndex:(NSInteger)index { | 1563 atIndex:(NSInteger)index { |
| 1564 // We will also get a -tabDetachedWithContents:atIndex: notification for | 1564 // We will also get a -tabDetachedWithContents:atIndex: notification for |
| 1565 // closing tabs, so do nothing here. | 1565 // closing tabs, so do nothing here. |
| 1566 } | 1566 } |
| 1567 | 1567 |
| 1568 - (void)tabDetachedWithContents:(TabContentsWrapper*)contents | 1568 - (void)tabDetachedWithContents:(TabContents*)contents |
| 1569 atIndex:(NSInteger)index { | 1569 atIndex:(NSInteger)index { |
| 1570 ScopedCAActionSetDuration durationSetter(kObserverChangeAnimationDuration); | 1570 ScopedCAActionSetDuration durationSetter(kObserverChangeAnimationDuration); |
| 1571 | 1571 |
| 1572 // Remove layer and relayout. | 1572 // Remove layer and relayout. |
| 1573 tileSet_->RemoveTileAt(index); | 1573 tileSet_->RemoveTileAt(index); |
| 1574 tileSet_->Layout(containingRect_); | 1574 tileSet_->Layout(containingRect_); |
| 1575 | 1575 |
| 1576 { | 1576 { |
| 1577 ScopedCAActionDisabler disabler; | 1577 ScopedCAActionDisabler disabler; |
| 1578 [[allThumbnailLayers_ objectAtIndex:index] removeFromSuperlayer]; | 1578 [[allThumbnailLayers_ objectAtIndex:index] removeFromSuperlayer]; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1599 if (selectedIndex > index || selectedIndex >= tabStripModel_->count()) | 1599 if (selectedIndex > index || selectedIndex >= tabStripModel_->count()) |
| 1600 selectedIndex--; | 1600 selectedIndex--; |
| 1601 if (selectedIndex >= 0) | 1601 if (selectedIndex >= 0) |
| 1602 [self selectTileAtIndexWithoutAnimation:selectedIndex]; | 1602 [self selectTileAtIndexWithoutAnimation:selectedIndex]; |
| 1603 | 1603 |
| 1604 // Animate everything into its new place. | 1604 // Animate everything into its new place. |
| 1605 for (int i = 0; i < tabStripModel_->count(); ++i) | 1605 for (int i = 0; i < tabStripModel_->count(); ++i) |
| 1606 [self refreshLayerFramesAtIndex:i]; | 1606 [self refreshLayerFramesAtIndex:i]; |
| 1607 } | 1607 } |
| 1608 | 1608 |
| 1609 - (void)tabMovedWithContents:(TabContentsWrapper*)contents | 1609 - (void)tabMovedWithContents:(TabContents*)contents |
| 1610 fromIndex:(NSInteger)from | 1610 fromIndex:(NSInteger)from |
| 1611 toIndex:(NSInteger)to { | 1611 toIndex:(NSInteger)to { |
| 1612 ScopedCAActionSetDuration durationSetter(kObserverChangeAnimationDuration); | 1612 ScopedCAActionSetDuration durationSetter(kObserverChangeAnimationDuration); |
| 1613 | 1613 |
| 1614 // Move tile from |from| to |to|. | 1614 // Move tile from |from| to |to|. |
| 1615 tileSet_->MoveTileFromTo(from, to); | 1615 tileSet_->MoveTileFromTo(from, to); |
| 1616 | 1616 |
| 1617 // Move corresponding layers from |from| to |to|. | 1617 // Move corresponding layers from |from| to |to|. |
| 1618 scoped_nsobject<CALayer> thumbLayer( | 1618 scoped_nsobject<CALayer> thumbLayer( |
| 1619 [[allThumbnailLayers_ objectAtIndex:from] retain]); | 1619 [[allThumbnailLayers_ objectAtIndex:from] retain]); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1636 selectedIndex--; | 1636 selectedIndex--; |
| 1637 else if (to <= selectedIndex && selectedIndex < from) | 1637 else if (to <= selectedIndex && selectedIndex < from) |
| 1638 selectedIndex++; | 1638 selectedIndex++; |
| 1639 [self selectTileAtIndexWithoutAnimation:selectedIndex]; | 1639 [self selectTileAtIndexWithoutAnimation:selectedIndex]; |
| 1640 | 1640 |
| 1641 // Update frames of the layers. | 1641 // Update frames of the layers. |
| 1642 for (int i = std::min(from, to); i <= std::max(from, to); ++i) | 1642 for (int i = std::min(from, to); i <= std::max(from, to); ++i) |
| 1643 [self refreshLayerFramesAtIndex:i]; | 1643 [self refreshLayerFramesAtIndex:i]; |
| 1644 } | 1644 } |
| 1645 | 1645 |
| 1646 - (void)tabChangedWithContents:(TabContentsWrapper*)contents | 1646 - (void)tabChangedWithContents:(TabContents*)contents |
| 1647 atIndex:(NSInteger)index | 1647 atIndex:(NSInteger)index |
| 1648 changeType:(TabStripModelObserver::TabChangeType)change { | 1648 changeType:(TabStripModelObserver::TabChangeType)change { |
| 1649 // Tell the window to update text, title, and thumb layers at |index| to get | 1649 // Tell the window to update text, title, and thumb layers at |index| to get |
| 1650 // their data from |contents|. |contents| can be different from the old | 1650 // their data from |contents|. |contents| can be different from the old |
| 1651 // contents at that index! | 1651 // contents at that index! |
| 1652 // While a tab is loading, this is unfortunately called quite often for | 1652 // While a tab is loading, this is unfortunately called quite often for |
| 1653 // both the "loading" and the "all" change types, so we don't really want to | 1653 // both the "loading" and the "all" change types, so we don't really want to |
| 1654 // send thumb requests to the corresponding renderer when this is called. | 1654 // send thumb requests to the corresponding renderer when this is called. |
| 1655 // For now, just make sure that we don't hold on to an invalid WebContents | 1655 // For now, just make sure that we don't hold on to an invalid WebContents |
| 1656 // object. | 1656 // object. |
| 1657 tabpose::Tile& tile = tileSet_->tile_at(index); | 1657 tabpose::Tile& tile = tileSet_->tile_at(index); |
| 1658 if (contents == tile.tab_contents()) { | 1658 if (contents == tile.tab_contents()) { |
| 1659 // TODO(thakis): Install a timer to send a thumb request/update title/update | 1659 // TODO(thakis): Install a timer to send a thumb request/update title/update |
| 1660 // favicon after 20ms or so, and reset the timer every time this is called | 1660 // favicon after 20ms or so, and reset the timer every time this is called |
| 1661 // to make sure we get an updated thumb, without requesting them all over. | 1661 // to make sure we get an updated thumb, without requesting them all over. |
| 1662 return; | 1662 return; |
| 1663 } | 1663 } |
| 1664 | 1664 |
| 1665 tile.set_tab_contents(contents); | 1665 tile.set_tab_contents(contents); |
| 1666 ThumbnailLayer* thumbLayer = [allThumbnailLayers_ objectAtIndex:index]; | 1666 ThumbnailLayer* thumbLayer = [allThumbnailLayers_ objectAtIndex:index]; |
| 1667 [thumbLayer setTabContents:contents]; | 1667 [thumbLayer setTabContents:contents]; |
| 1668 } | 1668 } |
| 1669 | 1669 |
| 1670 - (void)tabStripModelDeleted { | 1670 - (void)tabStripModelDeleted { |
| 1671 [self close]; | 1671 [self close]; |
| 1672 } | 1672 } |
| 1673 | 1673 |
| 1674 @end | 1674 @end |
| OLD | NEW |