From 7ca51e26dc7316b50d5f96e4e1b4312584cb995f Mon Sep 17 00:00:00 2001 From: estade Date: Mon, 31 Aug 2015 12:03:33 -0700 Subject: [PATCH] Vectorize website settings icons in omnibox unlike other icon vectorization/MD work, this does respect the --top-chrome-md flag, because these icons live in the omnibox and look funky if you put them in the old omnibox. BUG=505953, 514718 Review URL: https://codereview.chromium.org/1313603003 Cr-Commit-Position: refs/heads/master@{#346432} --- .../location_bar/content_setting_decoration.mm | 11 +- .../content_setting_image_model.cc | 135 ++++++++++++++++++--- .../content_settings/content_setting_image_model.h | 18 ++- .../content_setting_image_model_unittest.cc | 8 +- .../location_bar/content_setting_image_view.cc | 4 +- ui/gfx/BUILD.gn | 4 + ui/gfx/paint_vector_icon.cc | 60 +++++++-- ui/gfx/paint_vector_icon.h | 7 ++ ui/gfx/vector_icon_types.h | 2 + ui/gfx/vector_icons/blocked_badge.icon | 45 +++++++ ui/gfx/vector_icons/code.icon | 21 ++++ ui/gfx/vector_icons/cookie.icon | 117 +++++++++--------- ui/gfx/vector_icons/mixed_content.icon | 20 +++ ui/gfx/vector_icons/web.icon | 33 +++++ 14 files changed, 381 insertions(+), 104 deletions(-) create mode 100644 ui/gfx/vector_icons/blocked_badge.icon create mode 100644 ui/gfx/vector_icons/code.icon rewrite ui/gfx/vector_icons/cookie.icon (88%) create mode 100644 ui/gfx/vector_icons/mixed_content.icon create mode 100644 ui/gfx/vector_icons/web.icon diff --git a/chrome/browser/ui/cocoa/location_bar/content_setting_decoration.mm b/chrome/browser/ui/cocoa/location_bar/content_setting_decoration.mm index f896a4b07633..f53be8829075 100644 --- a/chrome/browser/ui/cocoa/location_bar/content_setting_decoration.mm +++ b/chrome/browser/ui/cocoa/location_bar/content_setting_decoration.mm @@ -23,7 +23,6 @@ #include "net/base/net_util.h" #include "ui/base/cocoa/appkit_utils.h" #include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" #include "ui/gfx/image/image.h" #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" @@ -178,17 +177,13 @@ ContentSettingDecoration::~ContentSettingDecoration() { bool ContentSettingDecoration::UpdateFromWebContents( WebContents* web_contents) { bool was_visible = IsVisible(); - int old_icon = content_setting_image_model_->get_icon(); + int old_icon = content_setting_image_model_->icon_id(); content_setting_image_model_->UpdateFromWebContents(web_contents); SetVisible(content_setting_image_model_->is_visible()); bool decoration_changed = was_visible != IsVisible() || - old_icon != content_setting_image_model_->get_icon(); + old_icon != content_setting_image_model_->icon_id(); if (IsVisible()) { - // TODO(thakis): We should use pdfs for these icons on OSX. - // http://crbug.com/35847 - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - SetImage(rb.GetNativeImageNamed( - content_setting_image_model_->get_icon()).ToNSImage()); + SetImage(content_setting_image_model_->icon().ToNSImage()); SetToolTip(base::SysUTF8ToNSString( content_setting_image_model_->get_tooltip())); diff --git a/chrome/browser/ui/content_settings/content_setting_image_model.cc b/chrome/browser/ui/content_settings/content_setting_image_model.cc index 170545103338..6a9e0a817347 100644 --- a/chrome/browser/ui/content_settings/content_setting_image_model.cc +++ b/chrome/browser/ui/content_settings/content_setting_image_model.cc @@ -12,9 +12,30 @@ #include "content/public/browser/web_contents.h" #include "grit/theme_resources.h" #include "ui/base/l10n/l10n_util.h" +#include "ui/base/resource/material_design/material_design_controller.h" +#include "ui/base/resource/resource_bundle.h" + +#if !defined(OS_MACOSX) +#include "ui/gfx/paint_vector_icon.h" +#include "ui/gfx/vector_icons_public2.h" +#include "ui/native_theme/common_theme.h" +#include "ui/native_theme/native_theme.h" +#endif using content::WebContents; +namespace { + +bool UseVectorGraphics() { +#if defined(OS_MACOSX) + return false; +#else + return ui::MaterialDesignController::IsModeMaterial(); +#endif +} + +} // namespace + class ContentSettingBlockedImageModel : public ContentSettingImageModel { public: explicit ContentSettingBlockedImageModel( @@ -89,6 +110,7 @@ void ContentSettingBlockedImageModel::UpdateFromWebContents( if (!web_contents) return; + ContentSettingsType type = get_content_settings_type(); static const ContentSettingsTypeIdEntry kBlockedIconIDs[] = { {CONTENT_SETTINGS_TYPE_COOKIES, IDR_BLOCKED_COOKIES}, {CONTENT_SETTINGS_TYPE_IMAGES, IDR_BLOCKED_IMAGES}, @@ -99,6 +121,45 @@ void ContentSettingBlockedImageModel::UpdateFromWebContents( {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDR_BLOCKED_PPAPI_BROKER}, {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDR_BLOCKED_DOWNLOADS}, }; + int icon_id = + GetIdForContentType(kBlockedIconIDs, arraysize(kBlockedIconIDs), type); + +#if !defined(OS_MACOSX) + gfx::VectorIconId vector_icon_id = gfx::VectorIconId::VECTOR_ICON_NONE; + switch (type) { + case CONTENT_SETTINGS_TYPE_COOKIES: + vector_icon_id = gfx::VectorIconId::COOKIE; + break; + case CONTENT_SETTINGS_TYPE_IMAGES: + vector_icon_id = gfx::VectorIconId::IMAGE; + break; + case CONTENT_SETTINGS_TYPE_JAVASCRIPT: + vector_icon_id = gfx::VectorIconId::CODE; + break; + case CONTENT_SETTINGS_TYPE_PLUGINS: + vector_icon_id = gfx::VectorIconId::EXTENSION; + break; + case CONTENT_SETTINGS_TYPE_POPUPS: + vector_icon_id = gfx::VectorIconId::WEB; + break; + case CONTENT_SETTINGS_TYPE_MIXEDSCRIPT: + vector_icon_id = gfx::VectorIconId::MIXED_CONTENT; + break; + // TODO(estade): change this one? + case CONTENT_SETTINGS_TYPE_PPAPI_BROKER: + vector_icon_id = gfx::VectorIconId::EXTENSION; + break; + case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS: + vector_icon_id = gfx::VectorIconId::FILE_DOWNLOAD; + break; + default: + // If we didn't find a vector icon ID we shouldn't have found an + // asset ID either. + DCHECK_EQ(0, icon_id); + break; + } +#endif + static const ContentSettingsTypeIdEntry kBlockedTooltipIDs[] = { {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE}, {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE}, @@ -110,18 +171,15 @@ void ContentSettingBlockedImageModel::UpdateFromWebContents( {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_TITLE}, {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOAD_TITLE}, }; + int tooltip_id = GetIdForContentType(kBlockedTooltipIDs, + arraysize(kBlockedTooltipIDs), type); + static const ContentSettingsTypeIdEntry kBlockedExplanatoryTextIDs[] = { {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_EXPLANATORY_TEXT}, {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGIN_EXPLANATORY_TEXT}, {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOADS_EXPLANATION}, }; - - ContentSettingsType type = get_content_settings_type(); - int icon_id = GetIdForContentType( - kBlockedIconIDs, arraysize(kBlockedIconIDs), type); - int tooltip_id = GetIdForContentType( - kBlockedTooltipIDs, arraysize(kBlockedTooltipIDs), type); int explanation_id = GetIdForContentType( kBlockedExplanatoryTextIDs, arraysize(kBlockedExplanatoryTextIDs), type); @@ -159,20 +217,27 @@ void ContentSettingBlockedImageModel::UpdateFromWebContents( {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDR_BLOCKED_PPAPI_BROKER}, {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDR_ALLOWED_DOWNLOADS}, }; + icon_id = GetIdForContentType(kAccessedIconIDs, arraysize(kAccessedIconIDs), + type); static const ContentSettingsTypeIdEntry kAccessedTooltipIDs[] = { {CONTENT_SETTINGS_TYPE_COOKIES, IDS_ACCESSED_COOKIES_TITLE}, {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_TITLE}, {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_ALLOWED_DOWNLOAD_TITLE}, }; - icon_id = GetIdForContentType( - kAccessedIconIDs, arraysize(kAccessedIconIDs), type); tooltip_id = GetIdForContentType( kAccessedTooltipIDs, arraysize(kAccessedTooltipIDs), type); explanation_id = 0; } set_visible(true); - DCHECK(icon_id); - set_icon(icon_id); + if (!UseVectorGraphics()) { + DCHECK(icon_id); + SetIconByResourceId(icon_id); +#if !defined(OS_MACOSX) + } else { + DCHECK(gfx::VectorIconId::VECTOR_ICON_NONE != vector_icon_id); + SetIconByVectorId(vector_icon_id, content_settings->IsContentBlocked(type)); +#endif + } set_explanatory_string_id(explanation_id); DCHECK(tooltip_id); set_tooltip(l10n_util::GetStringUTF8(tooltip_id)); @@ -203,7 +268,12 @@ void ContentSettingGeolocationImageModel::UpdateFromWebContents( usages_state.GetDetailedInfo(NULL, &state_flags); bool allowed = !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED); - set_icon(allowed ? IDR_ALLOWED_LOCATION : IDR_BLOCKED_LOCATION); + if (!UseVectorGraphics()) + SetIconByResourceId(allowed ? IDR_ALLOWED_LOCATION : IDR_BLOCKED_LOCATION); +#if !defined(OS_MACOSX) + else + SetIconByVectorId(gfx::VectorIconId::MY_LOCATION, !allowed); +#endif set_tooltip(l10n_util::GetStringUTF8(allowed ? IDS_GEOLOCATION_ALLOWED_TOOLTIP : IDS_GEOLOCATION_BLOCKED_TOOLTIP)); } @@ -260,11 +330,21 @@ void ContentSettingMediaImageModel::UpdateFromWebContents( int id = IDS_CAMERA_BLOCKED; if (state & (TabSpecificContentSettings::MICROPHONE_BLOCKED | TabSpecificContentSettings::CAMERA_BLOCKED)) { - set_icon(IDR_BLOCKED_CAMERA); + if (!UseVectorGraphics()) + SetIconByResourceId(IDR_BLOCKED_CAMERA); +#if !defined(OS_MACOSX) + else + SetIconByVectorId(gfx::VectorIconId::VIDEOCAM, true); +#endif if (is_mic) id = is_cam ? IDS_MICROPHONE_CAMERA_BLOCKED : IDS_MICROPHONE_BLOCKED; } else { - set_icon(IDR_ALLOWED_CAMERA); + if (!UseVectorGraphics()) + SetIconByResourceId(IDR_ALLOWED_CAMERA); +#if !defined(OS_MACOSX) + else + SetIconByVectorId(gfx::VectorIconId::VIDEOCAM, false); +#endif id = IDS_CAMERA_ACCESSED; if (is_mic) id = is_cam ? IDS_MICROPHONE_CAMERA_ALLOWED : IDS_MICROPHONE_ACCESSED; @@ -276,7 +356,8 @@ void ContentSettingMediaImageModel::UpdateFromWebContents( ContentSettingRPHImageModel::ContentSettingRPHImageModel() : ContentSettingImageModel( CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { - set_icon(IDR_REGISTER_PROTOCOL_HANDLER); + // TODO(estade): get an MD icon for this one. + SetIconByResourceId(IDR_REGISTER_PROTOCOL_HANDLER); set_tooltip(l10n_util::GetStringUTF8(IDS_REGISTER_PROTOCOL_HANDLER_TOOLTIP)); } @@ -331,7 +412,12 @@ void ContentSettingMIDISysExImageModel::UpdateFromWebContents( usages_state.GetDetailedInfo(NULL, &state_flags); bool allowed = !!(state_flags & ContentSettingsUsagesState::TABSTATE_HAS_ANY_ALLOWED); - set_icon(allowed ? IDR_ALLOWED_MIDI_SYSEX : IDR_BLOCKED_MIDI_SYSEX); +#if defined(OS_MACOSX) + SetIconByResourceId(allowed ? IDR_ALLOWED_MIDI_SYSEX + : IDR_BLOCKED_MIDI_SYSEX); +#else + SetIconByVectorId(gfx::VectorIconId::MIDI, !allowed); +#endif set_tooltip(l10n_util::GetStringUTF8(allowed ? IDS_MIDI_SYSEX_ALLOWED_TOOLTIP : IDS_MIDI_SYSEX_BLOCKED_TOOLTIP)); } @@ -340,7 +426,7 @@ ContentSettingImageModel::ContentSettingImageModel( ContentSettingsType content_settings_type) : content_settings_type_(content_settings_type), is_visible_(false), - icon_(0), + icon_id_(0), explanatory_string_id_(0) { } @@ -365,3 +451,20 @@ ContentSettingImageModel* return new ContentSettingBlockedImageModel(content_settings_type); } } + +void ContentSettingImageModel::SetIconByResourceId(int id) { + icon_id_ = id; + icon_ = ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(id); +} + +#if !defined(OS_MACOSX) +void ContentSettingImageModel::SetIconByVectorId(gfx::VectorIconId id, + bool blocked) { + SkColor icon_color; + ui::CommonThemeGetSystemColor(ui::NativeTheme::kColorId_ChromeIconGrey, + &icon_color); + icon_ = gfx::Image(gfx::CreateVectorIconWithBadge( + id, 16, icon_color, blocked ? gfx::VectorIconId::BLOCKED_BADGE + : gfx::VectorIconId::VECTOR_ICON_NONE)); +} +#endif diff --git a/chrome/browser/ui/content_settings/content_setting_image_model.h b/chrome/browser/ui/content_settings/content_setting_image_model.h index b1c04af788b8..459e429929e0 100644 --- a/chrome/browser/ui/content_settings/content_setting_image_model.h +++ b/chrome/browser/ui/content_settings/content_setting_image_model.h @@ -9,11 +9,16 @@ #include "base/basictypes.h" #include "components/content_settings/core/common/content_settings_types.h" +#include "ui/gfx/image/image.h" namespace content { class WebContents; } +namespace gfx { +enum class VectorIconId; +} + // This model provides data (icon ids and tooltip) for the content setting icons // that are displayed in the location bar. class ContentSettingImageModel { @@ -32,7 +37,10 @@ class ContentSettingImageModel { return content_settings_type_; } bool is_visible() const { return is_visible_; } - int get_icon() const { return icon_; } + const gfx::Image& icon() const { return icon_; } +#if defined(OS_MACOSX) + int icon_id() const { return icon_id_; } +#endif // Returns the resource ID of a string to show when the icon appears, or 0 if // we don't wish to show anything. int explanatory_string_id() const { return explanatory_string_id_; } @@ -40,8 +48,11 @@ class ContentSettingImageModel { protected: explicit ContentSettingImageModel(ContentSettingsType content_settings_type); + void SetIconByResourceId(int id); +#if !defined(OS_MACOSX) + void SetIconByVectorId(gfx::VectorIconId id, bool blocked); +#endif void set_visible(bool visible) { is_visible_ = visible; } - void set_icon(int icon) { icon_ = icon; } void set_explanatory_string_id(int text_id) { explanatory_string_id_ = text_id; } @@ -50,7 +61,8 @@ class ContentSettingImageModel { private: const ContentSettingsType content_settings_type_; bool is_visible_; - int icon_; + int icon_id_; + gfx::Image icon_; int explanatory_string_id_; std::string tooltip_; diff --git a/chrome/browser/ui/content_settings/content_setting_image_model_unittest.cc b/chrome/browser/ui/content_settings/content_setting_image_model_unittest.cc index 5dac6b1c16c9..7b533ff58735 100644 --- a/chrome/browser/ui/content_settings/content_setting_image_model_unittest.cc +++ b/chrome/browser/ui/content_settings/content_setting_image_model_unittest.cc @@ -63,14 +63,14 @@ TEST_F(ContentSettingImageModelTest, UpdateFromWebContents) { ContentSettingImageModel::CreateContentSettingImageModel( CONTENT_SETTINGS_TYPE_IMAGES)); EXPECT_FALSE(content_setting_image_model->is_visible()); - EXPECT_EQ(0, content_setting_image_model->get_icon()); + EXPECT_TRUE(content_setting_image_model->icon().IsEmpty()); EXPECT_TRUE(content_setting_image_model->get_tooltip().empty()); content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES); content_setting_image_model->UpdateFromWebContents(web_contents()); EXPECT_TRUE(content_setting_image_model->is_visible()); - EXPECT_NE(0, content_setting_image_model->get_icon()); + EXPECT_FALSE(content_setting_image_model->icon().IsEmpty()); EXPECT_FALSE(content_setting_image_model->get_tooltip().empty()); } @@ -101,7 +101,7 @@ TEST_F(ContentSettingImageModelTest, CookieAccessed) { ContentSettingImageModel::CreateContentSettingImageModel( CONTENT_SETTINGS_TYPE_COOKIES)); EXPECT_FALSE(content_setting_image_model->is_visible()); - EXPECT_EQ(0, content_setting_image_model->get_icon()); + EXPECT_TRUE(content_setting_image_model->icon().IsEmpty()); EXPECT_TRUE(content_setting_image_model->get_tooltip().empty()); net::CookieOptions options; @@ -112,7 +112,7 @@ TEST_F(ContentSettingImageModelTest, CookieAccessed) { false); content_setting_image_model->UpdateFromWebContents(web_contents()); EXPECT_TRUE(content_setting_image_model->is_visible()); - EXPECT_NE(0, content_setting_image_model->get_icon()); + EXPECT_FALSE(content_setting_image_model->icon().IsEmpty()); EXPECT_FALSE(content_setting_image_model->get_tooltip().empty()); } diff --git a/chrome/browser/ui/views/location_bar/content_setting_image_view.cc b/chrome/browser/ui/views/location_bar/content_setting_image_view.cc index 7e041a20f023..1de65954169a 100644 --- a/chrome/browser/ui/views/location_bar/content_setting_image_view.cc +++ b/chrome/browser/ui/views/location_bar/content_setting_image_view.cc @@ -13,7 +13,6 @@ #include "chrome/browser/ui/views/location_bar/location_bar_view.h" #include "grit/theme_resources.h" #include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" #include "ui/base/theme_provider.h" #include "ui/gfx/color_utils.h" #include "ui/views/controls/image_view.h" @@ -76,8 +75,7 @@ void ContentSettingImageView::Update(content::WebContents* web_contents) { return; } - SetImage(*ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( - content_setting_image_model_->get_icon())); + SetImage(content_setting_image_model_->icon().AsImageSkia()); image()->SetTooltipText( base::UTF8ToUTF16(content_setting_image_model_->get_tooltip())); SetVisible(true); diff --git a/ui/gfx/BUILD.gn b/ui/gfx/BUILD.gn index f2aa36700cbf..d8994b877231 100644 --- a/ui/gfx/BUILD.gn +++ b/ui/gfx/BUILD.gn @@ -421,7 +421,9 @@ action("aggregate_vector_icons") { "vector_icon_types.h", "vector_icons/account_box.icon", "vector_icons/account_child_invert.icon", + "vector_icons/blocked_badge.icon", "vector_icons/check_circle.icon", + "vector_icons/code.icon", "vector_icons/cookie.icon", "vector_icons/extension.icon", "vector_icons/file_download.icon", @@ -438,6 +440,7 @@ action("aggregate_vector_icons") { "vector_icons/laptop.icon", "vector_icons/location_on.icon", "vector_icons/midi.icon", + "vector_icons/mixed_content.icon", "vector_icons/mode_edit.icon", "vector_icons/my_location.icon", "vector_icons/notifications.icon", @@ -453,6 +456,7 @@ action("aggregate_vector_icons") { "vector_icons/tablet.icon", "vector_icons/translate.icon", "vector_icons/warning.icon", + "vector_icons/web.icon", ] outputs = [ vector_icons_cc_file, diff --git a/ui/gfx/paint_vector_icon.cc b/ui/gfx/paint_vector_icon.cc index 304ed4c08fc1..8251817e42e7 100644 --- a/ui/gfx/paint_vector_icon.cc +++ b/ui/gfx/paint_vector_icon.cc @@ -9,7 +9,9 @@ #include "base/lazy_instance.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" +#include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/core/SkPath.h" +#include "third_party/skia/include/core/SkXfermode.h" #include "ui/gfx/canvas.h" #include "ui/gfx/image/canvas_image_source.h" #include "ui/gfx/vector_icon_types.h" @@ -27,6 +29,7 @@ CommandType CommandFromString(const std::string& source) { RETURN_IF_IS(NEW_PATH); RETURN_IF_IS(PATH_COLOR_ARGB); + RETURN_IF_IS(PATH_MODE_CLEAR); RETURN_IF_IS(STROKE); RETURN_IF_IS(MOVE_TO); RETURN_IF_IS(R_MOVE_TO); @@ -68,6 +71,7 @@ void PaintPath(Canvas* canvas, const PathElement* path_elements, size_t dip_size, SkColor color) { + canvas->Save(); SkPath path; path.setFillType(SkPath::kEvenOdd_FillType); @@ -103,6 +107,11 @@ void PaintPath(Canvas* canvas, break; } + case PATH_MODE_CLEAR: { + paint.setXfermodeMode(SkXfermode::kClear_Mode); + break; + }; + case STROKE: { paint.setStyle(SkPaint::kStroke_Style); SkScalar width = path_elements[++i].arg; @@ -238,16 +247,21 @@ void PaintPath(Canvas* canvas, DCHECK_EQ(paints.size(), paths.size()); for (size_t i = 0; i < paths.size(); ++i) canvas->DrawPath(paths[i], paints[i]); + canvas->Restore(); } class VectorIconSource : public CanvasImageSource { public: - VectorIconSource(VectorIconId id, size_t dip_size, SkColor color) + VectorIconSource(VectorIconId id, + size_t dip_size, + SkColor color, + VectorIconId badge_id) : CanvasImageSource( gfx::Size(static_cast(dip_size), static_cast(dip_size)), false), id_(id), - color_(color) {} + color_(color), + badge_id_(badge_id) {} VectorIconSource(const std::string& definition, size_t dip_size, @@ -257,22 +271,27 @@ class VectorIconSource : public CanvasImageSource { false), id_(VectorIconId::VECTOR_ICON_NONE), path_(PathFromSource(definition)), - color_(color) {} + color_(color), + badge_id_(VectorIconId::VECTOR_ICON_NONE) {} ~VectorIconSource() override {} // CanvasImageSource: void Draw(gfx::Canvas* canvas) override { - if (path_.empty()) + if (path_.empty()) { PaintVectorIcon(canvas, id_, size_.width(), color_); - else + if (badge_id_ != VectorIconId::VECTOR_ICON_NONE) + PaintVectorIcon(canvas, badge_id_, size_.width(), color_); + } else { PaintPath(canvas, path_.data(), size_.width(), color_); + } } private: const VectorIconId id_; const std::vector path_; const SkColor color_; + const VectorIconId badge_id_; DISALLOW_COPY_AND_ASSIGN(VectorIconSource); }; @@ -285,14 +304,17 @@ class VectorIconCache { VectorIconCache() {} ~VectorIconCache() {} - ImageSkia GetOrCreateIcon(VectorIconId id, size_t dip_size, SkColor color) { - IconDescription description(id, dip_size, color); + ImageSkia GetOrCreateIcon(VectorIconId id, + size_t dip_size, + SkColor color, + VectorIconId badge_id) { + IconDescription description(id, dip_size, color, badge_id); auto iter = images_.find(description); if (iter != images_.end()) return iter->second; ImageSkia icon( - new VectorIconSource(id, dip_size, color), + new VectorIconSource(id, dip_size, color, badge_id), gfx::Size(static_cast(dip_size), static_cast(dip_size))); images_.insert(std::make_pair(description, icon)); return icon; @@ -300,20 +322,26 @@ class VectorIconCache { private: struct IconDescription { - IconDescription(VectorIconId id, size_t dip_size, SkColor color) - : id(id), dip_size(dip_size), color(color) {} + IconDescription(VectorIconId id, + size_t dip_size, + SkColor color, + VectorIconId badge_id) + : id(id), dip_size(dip_size), color(color), badge_id(badge_id) {} bool operator<(const IconDescription& other) const { if (id != other.id) return id < other.id; if (dip_size != other.dip_size) return dip_size < other.dip_size; - return color < other.color; + if (color != other.color) + return color < other.color; + return badge_id < other.badge_id; } VectorIconId id; size_t dip_size; SkColor color; + VectorIconId badge_id; }; std::map images_; @@ -338,7 +366,15 @@ void PaintVectorIcon(Canvas* canvas, } ImageSkia CreateVectorIcon(VectorIconId id, size_t dip_size, SkColor color) { - return g_icon_cache.Get().GetOrCreateIcon(id, dip_size, color); + return CreateVectorIconWithBadge(id, dip_size, color, + VectorIconId::VECTOR_ICON_NONE); +} + +ImageSkia CreateVectorIconWithBadge(VectorIconId id, + size_t dip_size, + SkColor color, + VectorIconId badge_id) { + return g_icon_cache.Get().GetOrCreateIcon(id, dip_size, color, badge_id); } ImageSkia CreateVectorIconFromSource(const std::string& source, diff --git a/ui/gfx/paint_vector_icon.h b/ui/gfx/paint_vector_icon.h index 51b244029824..73650a5a2cb6 100644 --- a/ui/gfx/paint_vector_icon.h +++ b/ui/gfx/paint_vector_icon.h @@ -28,6 +28,13 @@ GFX_EXPORT ImageSkia CreateVectorIcon(VectorIconId id, size_t dip_size, SkColor color); +// As above, but also paints a badge defined by |badge_id| on top of the icon. +// The badge uses the same canvas size and default color as the icon. +GFX_EXPORT ImageSkia CreateVectorIconWithBadge(VectorIconId id, + size_t dip_size, + SkColor color, + VectorIconId badge_id); + #if defined(GFX_VECTOR_ICONS_UNSAFE) || defined(GFX_IMPLEMENTATION) // Takes a string of the format expected of .icon files and renders onto // a canvas. This should only be used as a debugging aid and should never be diff --git a/ui/gfx/vector_icon_types.h b/ui/gfx/vector_icon_types.h index d93518e694a4..23b58d039a2b 100644 --- a/ui/gfx/vector_icon_types.h +++ b/ui/gfx/vector_icon_types.h @@ -24,6 +24,8 @@ enum CommandType { NEW_PATH, // Sets the color for the current path. PATH_COLOR_ARGB, + // Sets the path to clear mode (Skia's kClear_Mode). + PATH_MODE_CLEAR, // By default, the path will be filled. This changes the paint action to // stroke at the given width. STROKE, diff --git a/ui/gfx/vector_icons/blocked_badge.icon b/ui/gfx/vector_icons/blocked_badge.icon new file mode 100644 index 000000000000..687be0dec0ff --- /dev/null +++ b/ui/gfx/vector_icons/blocked_badge.icon @@ -0,0 +1,45 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +CANVAS_DIMENSIONS, 32, +PATH_MODE_CLEAR, +MOVE_TO, 32, 32, +LINE_TO, 16, 32, +LINE_TO, 16, 18, +CUBIC_TO, 16, 16.9f, 16.9f, 16, 18, 16, +LINE_TO, 32, 16, +CLOSE, +NEW_PATH, +PATH_COLOR_ARGB, 0xFF, 0xDB, 0x44, 0x37, +MOVE_TO, 30, 32, +LINE_TO, 20, 32, +CUBIC_TO, 18.9f, 32, 18, 31.1f, 18, 30, +LINE_TO, 18, 20, +CUBIC_TO, 18, 18.9f, 18.9f, 18, 20, 18, +LINE_TO, 30, 18, +CUBIC_TO, 31.1f, 18, 32, 18.9f, 32, 20, +LINE_TO, 32, 30, +CUBIC_TO, 32, 31.1f, 31.1f, 32, 30, 32, +CLOSE, +NEW_PATH, +PATH_COLOR_ARGB, 0xFF, 0xFF, 0xFF, 0xFF, +MOVE_TO, 26.8f, 22, +LINE_TO, 25, 23.8f, +LINE_TO, 23.2f, 22, +CUBIC_TO, 22.87f, 21.66f, 22.33f, 21.66f, 22, 22, +CUBIC_TO, 21.66f, 22.33f, 21.66f, 22.87f, 22, 23.2f, +LINE_TO, 23.8f, 25, +LINE_TO, 22, 26.8f, +CUBIC_TO, 21.66f, 27.13f, 21.66f, 27.67f, 22, 28, +CUBIC_TO, 22.33f, 28.34f, 22.87f, 28.34f, 23.2f, 28, +LINE_TO, 25, 26.2f, +LINE_TO, 26.8f, 28, +CUBIC_TO, 27.13f, 28.34f, 27.67f, 28.34f, 28, 28, +CUBIC_TO, 28.34f, 27.67f, 28.34f, 27.13f, 28, 26.8f, +LINE_TO, 26.2f, 25, +LINE_TO, 28, 23.2f, +CUBIC_TO, 28.34f, 22.87f, 28.34f, 22.33f, 28, 22, +CUBIC_TO, 27.67f, 21.66f, 27.13f, 21.66f, 26.8f, 22, +CLOSE, +END diff --git a/ui/gfx/vector_icons/code.icon b/ui/gfx/vector_icons/code.icon new file mode 100644 index 000000000000..8492f13d2bad --- /dev/null +++ b/ui/gfx/vector_icons/code.icon @@ -0,0 +1,21 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +MOVE_TO, 18.8f, 33.2f, +LINE_TO, 9.7f, 24, +R_LINE_TO, 9.2f, -9.2f, +LINE_TO, 16, 12, +LINE_TO, 4, 24, +R_LINE_TO, 12, 12, +R_LINE_TO, 2.8f, -2.8f, +CLOSE, +R_MOVE_TO, 10.4f, 0, +R_LINE_TO, 9.2f, -9.2f, +R_LINE_TO, -9.2f, -9.2f, +LINE_TO, 32, 12, +R_LINE_TO, 12, 12, +R_LINE_TO, -12, 12, +R_LINE_TO, -2.8f, -2.8f, +CLOSE, +END diff --git a/ui/gfx/vector_icons/cookie.icon b/ui/gfx/vector_icons/cookie.icon dissimilarity index 88% index d325989e17f0..a4e6887ad100 100644 --- a/ui/gfx/vector_icons/cookie.icon +++ b/ui/gfx/vector_icons/cookie.icon @@ -1,58 +1,59 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -CANVAS_DIMENSIONS, 36, -MOVE_TO, 29, 15, -LINE_TO, 29, 13, -CUBIC_TO, 29, 12.02f, 27.48f, 11, 26.5f, 11, -LINE_TO, 24, 11, -LINE_TO, 24, 8.5f, -CUBIC_TO, 24, 7.52f, 23.48f, 7, 22.5f, 7, -LINE_TO, 20, 7, -LINE_TO, 20, 4, -CUBIC_TO, 20, 3.22f, 19.28f, 2.36f, 18.58f, 2.12f, -CUBIC_TO, 18.46f, 2.05f, 18.28f, 2, 18, 2, -CUBIC_TO, 9.16f, 2, 2, 9.16f, 2, 18, -CUBIC_TO, 2, 26.84f, 9.16f, 34, 18, 34, -CUBIC_TO, 26.84f, 34, 34, 26.84f, 34, 18, -LINE_TO, 34, 16.5f, -CUBIC_TO, 34, 15.52f, 33.48f, 15, 32.5f, 15, -LINE_TO, 29, 15, -CLOSE, -MOVE_TO, 7.5f, 19, -CUBIC_TO, 6.12f, 19, 5, 17.88f, 5, 16.5f, -CUBIC_TO, 5, 15.12f, 6.12f, 14, 7.5f, 14, -CUBIC_TO, 8.88f, 14, 10, 15.12f, 10, 16.5f, -CUBIC_TO, 10, 17.88f, 8.88f, 19, 7.5f, 19, -LINE_TO, 7.5f, 19, -CLOSE, -MOVE_TO, 11, 9.5f, -CUBIC_TO, 11, 8.12f, 12.12f, 7, 13.5f, 7, -CUBIC_TO, 14.88f, 7, 16, 8.12f, 16, 9.5f, -CUBIC_TO, 16, 10.88f, 14.88f, 12, 13.5f, 12, -CUBIC_TO, 12.12f, 12, 11, 10.88f, 11, 9.5f, -LINE_TO, 11, 9.5f, -CLOSE, -MOVE_TO, 15.5f, 29, -CUBIC_TO, 14.12f, 29, 13, 27.88f, 13, 26.5f, -CUBIC_TO, 13, 25.12f, 14.12f, 24, 15.5f, 24, -CUBIC_TO, 16.88f, 24, 18, 25.12f, 18, 26.5f, -CUBIC_TO, 18, 27.88f, 16.88f, 29, 15.5f, 29, -LINE_TO, 15.5f, 29, -CLOSE, -MOVE_TO, 16.5f, 21, -CUBIC_TO, 15.12f, 21, 14, 19.88f, 14, 18.5f, -CUBIC_TO, 14, 17.12f, 15.12f, 16, 16.5f, 16, -CUBIC_TO, 17.88f, 16, 19, 17.12f, 19, 18.5f, -CUBIC_TO, 19, 19.88f, 17.88f, 21, 16.5f, 21, -LINE_TO, 16.5f, 21, -CLOSE, -MOVE_TO, 25.5f, 24, -CUBIC_TO, 24.12f, 24, 23, 22.88f, 23, 21.5f, -CUBIC_TO, 23, 20.12f, 24.12f, 19, 25.5f, 19, -CUBIC_TO, 26.88f, 19, 28, 20.12f, 28, 21.5f, -CUBIC_TO, 28, 22.88f, 26.88f, 24, 25.5f, 24, -LINE_TO, 25.5f, 24, -CLOSE, -END +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +MOVE_TO, 31, 15, +LINE_TO, 31, 14, +CUBIC_TO, 31, 12.04f, 30, 11, 28, 11, +LINE_TO, 27, 11, +CUBIC_TO, 26.45f, 11, 26, 10.55f, 26, 10, +LINE_TO, 26, 6, +CUBIC_TO, 26, 4.04f, 24, 4, 24, 4, +CUBIC_TO, 12.6f, 4, 3.42f, 13.54f, 4.03f, 25.08f, +CUBIC_TO, 4.56f, 35.17f, 12.83f, 43.44f, 22.92f, 43.97f, +CUBIC_TO, 34.46f, 44.58f, 44, 35.4f, 44, 24, +LINE_TO, 44, 22, +CUBIC_TO, 44, 20.9f, 43.11f, 20, 42, 20, +LINE_TO, 38, 20, +CUBIC_TO, 37.45f, 20, 37, 19.55f, 37, 19, +LINE_TO, 37, 18, +CUBIC_TO, 37, 16.13f, 36.04f, 15.04f, 34, 15, +LINE_TO, 31, 15, +LINE_TO, 31, 15, +CLOSE, +MOVE_TO, 11.59f, 24.94f, +CUBIC_TO, 9.47f, 25.35f, 7.66f, 23.53f, 8.06f, 21.41f, +CUBIC_TO, 8.28f, 20.24f, 9.24f, 19.28f, 10.41f, 19.06f, +CUBIC_TO, 12.53f, 18.66f, 14.35f, 20.47f, 13.94f, 22.59f, +CUBIC_TO, 13.72f, 23.76f, 12.76f, 24.72f, 11.59f, 24.94f, +LINE_TO, 11.59f, 24.94f, +CLOSE, +MOVE_TO, 15.06f, 14.59f, +CUBIC_TO, 14.66f, 12.47f, 16.47f, 10.66f, 18.59f, 11.06f, +CUBIC_TO, 19.76f, 11.28f, 20.72f, 12.24f, 20.94f, 13.41f, +CUBIC_TO, 21.35f, 15.53f, 19.53f, 17.35f, 17.41f, 16.94f, +CUBIC_TO, 16.24f, 16.72f, 15.28f, 15.76f, 15.06f, 14.59f, +LINE_TO, 15.06f, 14.59f, +CLOSE, +MOVE_TO, 22.59f, 38.94f, +CUBIC_TO, 20.47f, 39.35f, 18.66f, 37.53f, 19.06f, 35.41f, +CUBIC_TO, 19.28f, 34.24f, 20.24f, 33.28f, 21.41f, 33.06f, +CUBIC_TO, 23.53f, 32.66f, 25.35f, 34.47f, 24.94f, 36.59f, +CUBIC_TO, 24.72f, 37.76f, 23.76f, 38.72f, 22.59f, 38.94f, +LINE_TO, 22.59f, 38.94f, +CLOSE, +MOVE_TO, 23, 28, +CUBIC_TO, 21.34f, 28, 20, 26.66f, 20, 25, +CUBIC_TO, 20, 23.34f, 21.34f, 22, 23, 22, +CUBIC_TO, 24.66f, 22, 26, 23.34f, 26, 25, +CUBIC_TO, 26, 26.66f, 24.66f, 28, 23, 28, +LINE_TO, 23, 28, +CLOSE, +MOVE_TO, 33, 32, +CUBIC_TO, 31.34f, 32, 30, 30.66f, 30, 29, +CUBIC_TO, 30, 27.34f, 31.34f, 26, 33, 26, +CUBIC_TO, 34.66f, 26, 36, 27.34f, 36, 29, +CUBIC_TO, 36, 30.66f, 34.66f, 32, 33, 32, +LINE_TO, 33, 32, +CLOSE, +END diff --git a/ui/gfx/vector_icons/mixed_content.icon b/ui/gfx/vector_icons/mixed_content.icon new file mode 100644 index 000000000000..a3303bbe4234 --- /dev/null +++ b/ui/gfx/vector_icons/mixed_content.icon @@ -0,0 +1,20 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +MOVE_TO, 26, 4, +LINE_TO, 10, 11.27f, +LINE_TO, 10, 22.18f, +CUBIC_TO, 10, 32.27f, 16.83f, 41.71f, 26, 44, +CUBIC_TO, 35.17f, 41.71f, 42, 32.27f, 42, 22.18f, +LINE_TO, 42, 11.27f, +LINE_TO, 26, 4, +LINE_TO, 26, 4, +CLOSE, +MOVE_TO, 26, 8, +LINE_TO, 39, 14, +LINE_TO, 39, 22.11f, +CUBIC_TO, 39, 29.93f, 33.34f, 38.22f, 26, 40, +LINE_TO, 26, 8, +CLOSE, +END diff --git a/ui/gfx/vector_icons/web.icon b/ui/gfx/vector_icons/web.icon new file mode 100644 index 000000000000..78d9b5f9a46e --- /dev/null +++ b/ui/gfx/vector_icons/web.icon @@ -0,0 +1,33 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +MOVE_TO, 40, 8, +H_LINE_TO, 8, +R_CUBIC_TO, -2.21f, 0, -3.98f, 1.79f, -3.98f, 4, +LINE_TO, 4, 36, +R_CUBIC_TO, 0, 2.21f, 1.79f, 4, 4, 4, +R_H_LINE_TO, 32, +R_CUBIC_TO, 2.21f, 0, 4, -1.79f, 4, -4, +V_LINE_TO, 12, +R_CUBIC_TO, 0, -2.21f, -1.79f, -4, -4, -4, +CLOSE, +MOVE_TO, 30, 36, +H_LINE_TO, 8, +R_V_LINE_TO, -8, +R_H_LINE_TO, 22, +R_V_LINE_TO, 8, +CLOSE, +R_MOVE_TO, 0, -10, +H_LINE_TO, 8, +R_V_LINE_TO, -8, +R_H_LINE_TO, 22, +R_V_LINE_TO, 8, +CLOSE, +R_MOVE_TO, 10, 10, +R_H_LINE_TO, -8, +V_LINE_TO, 18, +R_H_LINE_TO, 8, +R_V_LINE_TO, 18, +CLOSE, +END -- 2.11.4.GIT