| 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/ui/extensions/icon_with_badge_image_source.h" | 5 #include "chrome/browser/ui/extensions/icon_with_badge_image_source.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "chrome/browser/extensions/extension_action.h" | 13 #include "chrome/browser/extensions/extension_action.h" |
| 14 #include "chrome/grit/theme_resources.h" | 14 #include "chrome/grit/theme_resources.h" |
| 15 #include "skia/ext/cdl_paint.h" |
| 15 #include "third_party/skia/include/core/SkPaint.h" | 16 #include "third_party/skia/include/core/SkPaint.h" |
| 16 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 17 #include "ui/gfx/canvas.h" | 18 #include "ui/gfx/canvas.h" |
| 18 #include "ui/gfx/color_palette.h" | 19 #include "ui/gfx/color_palette.h" |
| 19 #include "ui/gfx/font.h" | 20 #include "ui/gfx/font.h" |
| 20 #include "ui/gfx/geometry/rect.h" | 21 #include "ui/gfx/geometry/rect.h" |
| 21 #include "ui/gfx/geometry/size.h" | 22 #include "ui/gfx/geometry/size.h" |
| 22 #include "ui/gfx/image/image_skia_operations.h" | 23 #include "ui/gfx/image/image_skia_operations.h" |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 if (size().width() != 0 && (badge_width % 2 != size().width() % 2)) | 141 if (size().width() != 0 && (badge_width % 2 != size().width() % 2)) |
| 141 badge_width += 1; | 142 badge_width += 1; |
| 142 badge_width = std::max(kBadgeHeight, badge_width); | 143 badge_width = std::max(kBadgeHeight, badge_width); |
| 143 | 144 |
| 144 // Calculate the badge background rect. It is usually right-aligned, but it | 145 // Calculate the badge background rect. It is usually right-aligned, but it |
| 145 // can also be center-aligned if it is large. | 146 // can also be center-aligned if it is large. |
| 146 gfx::Rect rect(badge_width >= kCenterAlignThreshold | 147 gfx::Rect rect(badge_width >= kCenterAlignThreshold |
| 147 ? (size().width() - badge_width) / 2 | 148 ? (size().width() - badge_width) / 2 |
| 148 : size().width() - badge_width, | 149 : size().width() - badge_width, |
| 149 size().height() - kBadgeHeight, badge_width, kBadgeHeight); | 150 size().height() - kBadgeHeight, badge_width, kBadgeHeight); |
| 150 SkPaint rect_paint; | 151 CdlPaint rect_paint; |
| 151 rect_paint.setStyle(SkPaint::kFill_Style); | 152 rect_paint.setStyle(CdlPaint::kFill_Style); |
| 152 rect_paint.setAntiAlias(true); | 153 rect_paint.setAntiAlias(true); |
| 153 rect_paint.setColor(background_color); | 154 rect_paint.setColor(background_color); |
| 154 | 155 |
| 155 // Clear part of the background icon. | 156 // Clear part of the background icon. |
| 156 gfx::Rect cutout_rect(rect); | 157 gfx::Rect cutout_rect(rect); |
| 157 cutout_rect.Inset(-1, -1); | 158 cutout_rect.Inset(-1, -1); |
| 158 SkPaint cutout_paint = rect_paint; | 159 CdlPaint cutout_paint = rect_paint; |
| 159 cutout_paint.setBlendMode(SkBlendMode::kClear); | 160 cutout_paint.setBlendMode(SkBlendMode::kClear); |
| 160 canvas->DrawRoundRect(cutout_rect, 2, cutout_paint); | 161 canvas->DrawRoundRect(cutout_rect, 2, cutout_paint); |
| 161 | 162 |
| 162 // Paint the backdrop. | 163 // Paint the backdrop. |
| 163 canvas->DrawRoundRect(rect, 1, rect_paint); | 164 canvas->DrawRoundRect(rect, 1, rect_paint); |
| 164 | 165 |
| 165 // Paint the text. | 166 // Paint the text. |
| 166 rect.Inset(std::max(kPadding, (rect.width() - text_width) / 2), | 167 rect.Inset(std::max(kPadding, (rect.width() - text_width) / 2), |
| 167 kBadgeHeight - base_font.GetHeight(), kPadding, 0); | 168 kBadgeHeight - base_font.GetHeight(), kPadding, 0); |
| 168 canvas->DrawStringRect(utf16_text, base_font, text_color, rect); | 169 canvas->DrawStringRect(utf16_text, base_font, text_color, rect); |
| 169 } | 170 } |
| 170 | 171 |
| 171 void IconWithBadgeImageSource::PaintPageActionDecoration(gfx::Canvas* canvas) { | 172 void IconWithBadgeImageSource::PaintPageActionDecoration(gfx::Canvas* canvas) { |
| 172 static const SkColor decoration_color = SkColorSetARGB(255, 70, 142, 226); | 173 static const SkColor decoration_color = SkColorSetARGB(255, 70, 142, 226); |
| 173 | 174 |
| 174 int major_radius = std::ceil(size().width() / 5.0); | 175 int major_radius = std::ceil(size().width() / 5.0); |
| 175 int minor_radius = std::ceil(major_radius / 2.0); | 176 int minor_radius = std::ceil(major_radius / 2.0); |
| 176 gfx::Point center_point(major_radius + 1, size().height() - (major_radius)-1); | 177 gfx::Point center_point(major_radius + 1, size().height() - (major_radius)-1); |
| 177 SkPaint paint; | 178 CdlPaint paint; |
| 178 paint.setAntiAlias(true); | 179 paint.setAntiAlias(true); |
| 179 paint.setStyle(SkPaint::kFill_Style); | 180 paint.setStyle(CdlPaint::kFill_Style); |
| 180 paint.setColor(SK_ColorTRANSPARENT); | 181 paint.setColor(SK_ColorTRANSPARENT); |
| 181 paint.setBlendMode(SkBlendMode::kSrc); | 182 paint.setBlendMode(SkBlendMode::kSrc); |
| 182 canvas->DrawCircle(center_point, major_radius, paint); | 183 canvas->DrawCircle(center_point, major_radius, paint); |
| 183 paint.setColor(decoration_color); | 184 paint.setColor(decoration_color); |
| 184 canvas->DrawCircle(center_point, minor_radius, paint); | 185 canvas->DrawCircle(center_point, minor_radius, paint); |
| 185 } | 186 } |
| 186 | 187 |
| 187 void IconWithBadgeImageSource::PaintBlockedActionDecoration( | 188 void IconWithBadgeImageSource::PaintBlockedActionDecoration( |
| 188 gfx::Canvas* canvas) { | 189 gfx::Canvas* canvas) { |
| 189 canvas->Save(); | 190 canvas->Save(); |
| 190 gfx::ImageSkia img = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 191 gfx::ImageSkia img = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 191 IDR_BLOCKED_EXTENSION_SCRIPT); | 192 IDR_BLOCKED_EXTENSION_SCRIPT); |
| 192 canvas->DrawImageInt(img, size().width() - img.width(), 0); | 193 canvas->DrawImageInt(img, size().width() - img.width(), 0); |
| 193 canvas->Restore(); | 194 canvas->Restore(); |
| 194 } | 195 } |
| OLD | NEW |