| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/tab_icon_view.h" | 5 #include "chrome/browser/views/tab_icon_view.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <shellapi.h> | 8 #include <shellapi.h> |
| 9 | 9 |
| 10 #include "app/gfx/chrome_canvas.h" | 10 #include "app/gfx/canvas.h" |
| 11 #include "app/gfx/favicon_size.h" | 11 #include "app/gfx/favicon_size.h" |
| 12 #include "app/gfx/icon_util.h" | 12 #include "app/gfx/icon_util.h" |
| 13 #include "app/resource_bundle.h" | 13 #include "app/resource_bundle.h" |
| 14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "chrome/app/chrome_dll_resource.h" | 16 #include "chrome/app/chrome_dll_resource.h" |
| 17 #include "chrome/browser/tab_contents/tab_contents.h" | 17 #include "chrome/browser/tab_contents/tab_contents.h" |
| 18 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
| 19 | 19 |
| 20 static bool g_initialized = false; | 20 static bool g_initialized = false; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 76 } |
| 77 } else if (model_->ShouldTabIconViewAnimate()) { | 77 } else if (model_->ShouldTabIconViewAnimate()) { |
| 78 // We didn't think we were loading, but the tab is loading. Reset the | 78 // We didn't think we were loading, but the tab is loading. Reset the |
| 79 // frame and status and schedule a paint. | 79 // frame and status and schedule a paint. |
| 80 throbber_running_ = true; | 80 throbber_running_ = true; |
| 81 throbber_frame_ = 0; | 81 throbber_frame_ = 0; |
| 82 SchedulePaint(); | 82 SchedulePaint(); |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 void TabIconView::PaintThrobber(ChromeCanvas* canvas) { | 86 void TabIconView::PaintThrobber(gfx::Canvas* canvas) { |
| 87 int image_size = g_throbber_frames->height(); | 87 int image_size = g_throbber_frames->height(); |
| 88 PaintIcon(canvas, is_light_ ? *g_throbber_frames_light : *g_throbber_frames, | 88 PaintIcon(canvas, is_light_ ? *g_throbber_frames_light : *g_throbber_frames, |
| 89 throbber_frame_ * image_size, 0, image_size, image_size, false); | 89 throbber_frame_ * image_size, 0, image_size, image_size, false); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void TabIconView::PaintFavIcon(ChromeCanvas* canvas, const SkBitmap& bitmap) { | 92 void TabIconView::PaintFavIcon(gfx::Canvas* canvas, const SkBitmap& bitmap) { |
| 93 PaintIcon(canvas, bitmap, 0, 0, bitmap.width(), bitmap.height(), true); | 93 PaintIcon(canvas, bitmap, 0, 0, bitmap.width(), bitmap.height(), true); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void TabIconView::PaintIcon(ChromeCanvas* canvas, | 96 void TabIconView::PaintIcon(gfx::Canvas* canvas, |
| 97 const SkBitmap& bitmap, | 97 const SkBitmap& bitmap, |
| 98 int src_x, | 98 int src_x, |
| 99 int src_y, | 99 int src_y, |
| 100 int src_w, | 100 int src_w, |
| 101 int src_h, | 101 int src_h, |
| 102 bool filter) { | 102 bool filter) { |
| 103 // For source images smaller than the favicon square, scale them as if they | 103 // For source images smaller than the favicon square, scale them as if they |
| 104 // were padded to fit the favicon square, so we don't blow up tiny favicons | 104 // were padded to fit the favicon square, so we don't blow up tiny favicons |
| 105 // into larger or nonproportional results. | 105 // into larger or nonproportional results. |
| 106 float float_src_w = static_cast<float>(src_w); | 106 float float_src_w = static_cast<float>(src_w); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 118 static_cast<float>(height()) / scalable_h); | 118 static_cast<float>(height()) / scalable_h); |
| 119 int dest_w = static_cast<int>(float_src_w * scale); | 119 int dest_w = static_cast<int>(float_src_w * scale); |
| 120 int dest_h = static_cast<int>(float_src_h * scale); | 120 int dest_h = static_cast<int>(float_src_h * scale); |
| 121 | 121 |
| 122 // Center the scaled image. | 122 // Center the scaled image. |
| 123 canvas->DrawBitmapInt(bitmap, src_x, src_y, src_w, src_h, | 123 canvas->DrawBitmapInt(bitmap, src_x, src_y, src_w, src_h, |
| 124 (width() - dest_w) / 2, (height() - dest_h) / 2, dest_w, | 124 (width() - dest_w) / 2, (height() - dest_h) / 2, dest_w, |
| 125 dest_h, filter); | 125 dest_h, filter); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void TabIconView::Paint(ChromeCanvas* canvas) { | 128 void TabIconView::Paint(gfx::Canvas* canvas) { |
| 129 bool rendered = false; | 129 bool rendered = false; |
| 130 | 130 |
| 131 if (throbber_running_) { | 131 if (throbber_running_) { |
| 132 rendered = true; | 132 rendered = true; |
| 133 PaintThrobber(canvas); | 133 PaintThrobber(canvas); |
| 134 } else { | 134 } else { |
| 135 SkBitmap favicon = model_->GetFavIconForTabIconView(); | 135 SkBitmap favicon = model_->GetFavIconForTabIconView(); |
| 136 if (!favicon.isNull()) { | 136 if (!favicon.isNull()) { |
| 137 rendered = true; | 137 rendered = true; |
| 138 PaintFavIcon(canvas, favicon); | 138 PaintFavIcon(canvas, favicon); |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 if (!rendered) | 142 if (!rendered) |
| 143 PaintFavIcon(canvas, *g_default_fav_icon); | 143 PaintFavIcon(canvas, *g_default_fav_icon); |
| 144 } | 144 } |
| 145 | 145 |
| 146 gfx::Size TabIconView::GetPreferredSize() { | 146 gfx::Size TabIconView::GetPreferredSize() { |
| 147 return gfx::Size(kFavIconSize, kFavIconSize); | 147 return gfx::Size(kFavIconSize, kFavIconSize); |
| 148 } | 148 } |
| OLD | NEW |