| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "chrome/browser/views/tabs/tab_overview_cell.h" | 5 #include "chrome/browser/views/tabs/tab_overview_cell.h" |
| 6 | 6 |
| 7 #include "app/gfx/favicon_size.h" | 7 #include "app/gfx/favicon_size.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "skia/ext/image_operations.h" |
| 9 #include "views/border.h" | 10 #include "views/border.h" |
| 10 #include "views/controls/image_view.h" | 11 #include "views/controls/image_view.h" |
| 11 #include "views/controls/label.h" | 12 #include "views/controls/label.h" |
| 12 #include "views/grid_layout.h" | 13 #include "views/grid_layout.h" |
| 13 | 14 |
| 14 using views::ColumnSet; | 15 using views::ColumnSet; |
| 15 using views::GridLayout; | 16 using views::GridLayout; |
| 16 | 17 |
| 17 // Padding between the favicon and label. | 18 // Padding between the favicon and label. |
| 18 static const int kFavIconPadding = 4; | 19 static const int kFavIconPadding = 4; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 layout->AddView(thumbnail_view_); | 58 layout->AddView(thumbnail_view_); |
| 58 | 59 |
| 59 thumbnail_view_->set_background( | 60 thumbnail_view_->set_background( |
| 60 views::Background::CreateSolidBackground(SK_ColorWHITE)); | 61 views::Background::CreateSolidBackground(SK_ColorWHITE)); |
| 61 | 62 |
| 62 thumbnail_view_->set_border( | 63 thumbnail_view_->set_border( |
| 63 views::Border::CreateSolidBorder(1, SkColorSetRGB(176, 176, 176))); | 64 views::Border::CreateSolidBorder(1, SkColorSetRGB(176, 176, 176))); |
| 64 } | 65 } |
| 65 | 66 |
| 66 void TabOverviewCell::SetThumbnail(const SkBitmap& thumbnail) { | 67 void TabOverviewCell::SetThumbnail(const SkBitmap& thumbnail) { |
| 67 thumbnail_view_->SetImage(thumbnail); | 68 // Do mipmapped-based resampling to get closer to the correct size. The |
| 69 // input bitmap isn't guaranteed to have any specific resolution. |
| 70 thumbnail_view_->SetImage(skia::ImageOperations::DownsampleByTwoUntilSize( |
| 71 thumbnail, kThumbnailWidth, kThumbnailHeight)); |
| 68 } | 72 } |
| 69 | 73 |
| 70 void TabOverviewCell::SetTitle(const string16& title) { | 74 void TabOverviewCell::SetTitle(const string16& title) { |
| 71 title_label_->SetText(UTF16ToWide(title)); | 75 title_label_->SetText(UTF16ToWide(title)); |
| 72 } | 76 } |
| 73 | 77 |
| 74 void TabOverviewCell::SetFavIcon(const SkBitmap& favicon) { | 78 void TabOverviewCell::SetFavIcon(const SkBitmap& favicon) { |
| 75 fav_icon_view_->SetImage(favicon); | 79 fav_icon_view_->SetImage(favicon); |
| 76 } | 80 } |
| 77 | 81 |
| 78 bool TabOverviewCell::IsPointInThumbnail(const gfx::Point& point) { | 82 bool TabOverviewCell::IsPointInThumbnail(const gfx::Point& point) { |
| 79 return thumbnail_view_->bounds().Contains(point); | 83 return thumbnail_view_->bounds().Contains(point); |
| 80 } | 84 } |
| 81 | 85 |
| 82 gfx::Size TabOverviewCell::GetPreferredSize() { | 86 gfx::Size TabOverviewCell::GetPreferredSize() { |
| 83 if (!preferred_size_.IsEmpty()) | 87 if (!preferred_size_.IsEmpty()) |
| 84 return preferred_size_; | 88 return preferred_size_; |
| 85 | 89 |
| 86 // Force the preferred width to that of the thumbnail. | 90 // Force the preferred width to that of the thumbnail. |
| 87 gfx::Size thumbnail_pref = thumbnail_view_->GetPreferredSize(); | 91 gfx::Size thumbnail_pref = thumbnail_view_->GetPreferredSize(); |
| 88 gfx::Size pref = View::GetPreferredSize(); | 92 gfx::Size pref = View::GetPreferredSize(); |
| 89 pref.set_width(thumbnail_pref.width()); | 93 pref.set_width(thumbnail_pref.width()); |
| 90 return pref; | 94 return pref; |
| 91 } | 95 } |
| OLD | NEW |