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