| 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 #include "chrome/browser/extensions/tab_helper.h" | 5 #include "chrome/browser/extensions/tab_helper.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 std::map<int, SkBitmap>::const_iterator it = | 131 std::map<int, SkBitmap>::const_iterator it = |
| 132 bitmaps->lower_bound(output_size); | 132 bitmaps->lower_bound(output_size); |
| 133 // Do nothing if there is no icon smaller than the desired size or there is | 133 // Do nothing if there is no icon smaller than the desired size or there is |
| 134 // already an icon of |output_size|. | 134 // already an icon of |output_size|. |
| 135 if (it == bitmaps->begin() || bitmaps->count(output_size)) | 135 if (it == bitmaps->begin() || bitmaps->count(output_size)) |
| 136 return; | 136 return; |
| 137 | 137 |
| 138 --it; | 138 --it; |
| 139 // This is the biggest icon smaller than |output_size|. | 139 // This is the biggest icon smaller than |output_size|. |
| 140 const SkBitmap& base_icon = it->second; | 140 const SkBitmap& base_icon = it->second; |
| 141 scoped_ptr<SkCanvas> canvas( | |
| 142 skia::CreateBitmapCanvas(output_size, output_size, false)); | |
| 143 DCHECK(canvas); | |
| 144 | 141 |
| 145 const size_t kBorderRadius = 5; | 142 const size_t kBorderRadius = 5; |
| 146 const size_t kColorStripHeight = 3; | 143 const size_t kColorStripHeight = 3; |
| 147 const size_t kColorStripRadius = 2; | |
| 148 const SkColor kBorderColor = 0xFFD5D5D5; | 144 const SkColor kBorderColor = 0xFFD5D5D5; |
| 145 const SkColor kBackgroundColor = 0xFFFFFFFF; |
| 146 |
| 147 // Create a separate canvas for the color strip. |
| 148 scoped_ptr<SkCanvas> color_strip_canvas( |
| 149 skia::CreateBitmapCanvas(output_size, output_size, false)); |
| 150 DCHECK(color_strip_canvas); |
| 149 | 151 |
| 150 // Draw a rounded rect of the |base_icon|'s dominant color. | 152 // Draw a rounded rect of the |base_icon|'s dominant color. |
| 151 SkPaint color_strip_paint; | 153 SkPaint color_strip_paint; |
| 152 color_utils::GridSampler sampler; | 154 color_utils::GridSampler sampler; |
| 153 color_strip_paint.setFlags(SkPaint::kAntiAlias_Flag); | 155 color_strip_paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 154 color_strip_paint.setColor( | 156 color_strip_paint.setColor( |
| 155 color_utils::CalculateKMeanColorOfPNG( | 157 color_utils::CalculateKMeanColorOfPNG( |
| 156 gfx::Image::CreateFrom1xBitmap(base_icon).As1xPNGBytes(), | 158 gfx::Image::CreateFrom1xBitmap(base_icon).As1xPNGBytes(), |
| 157 100, 665, &sampler)); | 159 100, 665, &sampler)); |
| 158 canvas->drawRoundRect( | 160 color_strip_canvas->drawRoundRect( |
| 159 SkRect::MakeXYWH(1, 0, output_size - 2, output_size - 1), | 161 SkRect::MakeWH(output_size, output_size), |
| 160 kColorStripRadius, kColorStripRadius, color_strip_paint); | 162 kBorderRadius, kBorderRadius, color_strip_paint); |
| 161 | 163 |
| 162 // Erase the top of the rounded rect to leave a color strip. | 164 // Erase the top of the rounded rect to leave a color strip. |
| 163 SkPaint clear_paint; | 165 SkPaint clear_paint; |
| 164 clear_paint.setColor(SK_ColorTRANSPARENT); | 166 clear_paint.setColor(SK_ColorTRANSPARENT); |
| 165 clear_paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 167 clear_paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 166 canvas->drawRect( | 168 color_strip_canvas->drawRect( |
| 167 SkRect::MakeWH(output_size, output_size - kColorStripHeight - 1), | 169 SkRect::MakeWH(output_size, output_size - kColorStripHeight), |
| 168 clear_paint); | 170 clear_paint); |
| 169 | 171 |
| 172 // Draw each element to an output canvas. |
| 173 scoped_ptr<SkCanvas> canvas( |
| 174 skia::CreateBitmapCanvas(output_size, output_size, false)); |
| 175 DCHECK(canvas); |
| 176 |
| 177 // Draw the background. |
| 178 SkPaint background_paint; |
| 179 background_paint.setColor(kBackgroundColor); |
| 180 background_paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 181 canvas->drawRoundRect( |
| 182 SkRect::MakeWH(output_size, output_size), |
| 183 kBorderRadius, kBorderRadius, background_paint); |
| 184 |
| 185 // Draw the color strip. |
| 186 canvas->drawBitmap(color_strip_canvas->getDevice()->accessBitmap(false), |
| 187 0, 0); |
| 188 |
| 170 // Draw the border. | 189 // Draw the border. |
| 171 SkPaint border_paint; | 190 SkPaint border_paint; |
| 172 border_paint.setColor(kBorderColor); | 191 border_paint.setColor(kBorderColor); |
| 173 border_paint.setStyle(SkPaint::kStroke_Style); | 192 border_paint.setStyle(SkPaint::kStroke_Style); |
| 174 border_paint.setFlags(SkPaint::kAntiAlias_Flag); | 193 border_paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 175 canvas->drawRoundRect( | 194 canvas->drawRoundRect( |
| 176 SkRect::MakeWH(output_size, output_size), | 195 SkRect::MakeWH(output_size, output_size), |
| 177 kBorderRadius, kBorderRadius, border_paint); | 196 kBorderRadius, kBorderRadius, border_paint); |
| 178 | 197 |
| 179 // Draw the centered base icon. | 198 // Draw the centered base icon to the output canvas. |
| 180 canvas->drawBitmap(base_icon, | 199 canvas->drawBitmap(base_icon, |
| 181 (output_size - base_icon.width()) / 2, | 200 (output_size - base_icon.width()) / 2, |
| 182 (output_size - base_icon.height()) / 2); | 201 (output_size - base_icon.height()) / 2); |
| 183 | 202 |
| 184 const SkBitmap& generated_icon = | 203 const SkBitmap& generated_icon = |
| 185 canvas->getDevice()->accessBitmap(false); | 204 canvas->getDevice()->accessBitmap(false); |
| 186 generated_icon.deepCopyTo(&(*bitmaps)[output_size], | 205 generated_icon.deepCopyTo(&(*bitmaps)[output_size], |
| 187 generated_icon.getConfig()); | 206 generated_icon.getConfig()); |
| 188 } | 207 } |
| 189 | 208 |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 } | 801 } |
| 783 } | 802 } |
| 784 | 803 |
| 785 void TabHelper::SetTabId(RenderViewHost* render_view_host) { | 804 void TabHelper::SetTabId(RenderViewHost* render_view_host) { |
| 786 render_view_host->Send( | 805 render_view_host->Send( |
| 787 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(), | 806 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(), |
| 788 SessionID::IdForTab(web_contents()))); | 807 SessionID::IdForTab(web_contents()))); |
| 789 } | 808 } |
| 790 | 809 |
| 791 } // namespace extensions | 810 } // namespace extensions |
| OLD | NEW |