Skip to content

Commit

Permalink
Create vector icon resource directory specific to Chrome.
Browse files Browse the repository at this point in the history
BUG=626786

Review-Url: https://codereview.chromium.org/2610163003
Cr-Commit-Position: refs/heads/master@{#442183}
  • Loading branch information
estade authored and Commit bot committed Jan 8, 2017
1 parent 197af4a commit 8283cad
Show file tree
Hide file tree
Showing 31 changed files with 178 additions and 74 deletions.
58 changes: 58 additions & 0 deletions chrome/app/vector_icons/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright 2017 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.

action("aggregate_vector_icons") {
visibility = [ ":*" ]

script = "//ui/gfx/vector_icons/aggregate_vector_icons.py"

icons = [
"browser_tools.icon",
"browser_tools_error.icon",
"browser_tools_update.icon",
"navigate_back.1x.icon",
"navigate_back.icon",
"navigate_forward.1x.icon",
"navigate_forward.icon",
"navigate_home.1x.icon",
"navigate_home.icon",
"navigate_reload.1x.icon",
"navigate_reload.icon",
"navigate_stop.1x.icon",
"navigate_stop.icon",
]

output_cc = "$target_gen_dir/vector_icons.cc"
output_h = "$target_gen_dir/vector_icons.h"

inputs = icons
inputs += [
"vector_icons.cc.template",
"vector_icons.h.template",
]
outputs = [
output_cc,
output_h,
]

response_file_contents = rebase_path(icons, root_build_dir)

args = [
"--working_directory=" + rebase_path("./"),
"--file_list={{response_file_name}}",
"--output_cc=" + rebase_path(output_cc, root_build_dir),
"--output_h=" + rebase_path(output_h, root_build_dir),
]
}

source_set("vector_icons") {
sources = get_target_outputs(":aggregate_vector_icons")
sources += [ "//ui/gfx/vector_icon_types.h" ]

deps = [
":aggregate_vector_icons",
"//base",
"//skia",
]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions chrome/app/vector_icons/vector_icons.cc.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2017 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.

// vector_icons.cc.template is used to generate vector_icons.cc. Edit the former
// rather than the latter.

#include "chrome/app/vector_icons/vector_icons.h"

#include "base/logging.h"
#include "ui/gfx/vector_icon_types.h"

#define PATH_ELEMENT_TEMPLATE(path_name, ...) \
static gfx::PathElement path_name[] = {__VA_ARGS__};

#define VECTOR_ICON_TEMPLATE(icon_name, path_name, path_name_1x) \
const gfx::VectorIcon icon_name = { path_name , path_name_1x };

using namespace gfx;

TEMPLATE_PLACEHOLDER
20 changes: 20 additions & 0 deletions chrome/app/vector_icons/vector_icons.h.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2017 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.

// vector_icons.h.template is used to generate vector_icons.h. Edit the former
// rather than the latter.

#ifndef CHROME_APP_VECTOR_ICONS_VECTOR_ICONS_H_
#define CHROME_APP_VECTOR_ICONS_VECTOR_ICONS_H_

namespace gfx {
struct VectorIcon;
}

#define VECTOR_ICON_TEMPLATE_H(icon_name) \
extern const gfx::VectorIcon icon_name;

TEMPLATE_PLACEHOLDER

#endif // CHROME_APP_VECTOR_ICONS_VECTOR_ICONS_H_
4 changes: 2 additions & 2 deletions chrome/browser/recovery/recovery_install_global_error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "chrome/browser/recovery/recovery_install_global_error.h"

#include "chrome/app/chrome_command_ids.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/component_updater/recovery_component_installer.h"
#include "chrome/browser/profiles/profile.h"
Expand All @@ -17,7 +18,6 @@
#include "components/prefs/pref_service.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icons_public.h"
#include "ui/native_theme/native_theme.h"

RecoveryInstallGlobalError::RecoveryInstallGlobalError(Profile* profile)
Expand Down Expand Up @@ -69,7 +69,7 @@ base::string16 RecoveryInstallGlobalError::MenuItemLabel() {

gfx::Image RecoveryInstallGlobalError::MenuItemIcon() {
return gfx::Image(gfx::CreateVectorIcon(
gfx::VectorIconId::BROWSER_TOOLS_UPDATE,
kBrowserToolsUpdateIcon,
ui::NativeTheme::GetInstanceForNativeUi()->GetSystemColor(
ui::NativeTheme::kColorId_AlertSeverityHigh)));
}
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,7 @@ split_static_library("ui") {
]
deps += [
"//apps",
"//chrome/app/vector_icons",
"//chrome/browser/profile_resetter:profile_reset_report_proto",
"//chrome/common:features",
"//components/feedback/proto",
Expand Down
11 changes: 6 additions & 5 deletions chrome/browser/ui/cocoa/toolbar/app_toolbar_button.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#import "chrome/browser/ui/cocoa/toolbar/app_toolbar_button.h"

#include "base/macros.h"
#include "chrome/app/vector_icons/vector_icons.h"
#import "chrome/browser/ui/cocoa/themed_window.h"
#import "chrome/browser/ui/cocoa/view_id_util.h"
#include "ui/base/material_design/material_design_controller.h"
Expand Down Expand Up @@ -33,19 +34,19 @@ - (void)commonInit {
type_ = AppMenuIconController::IconType::NONE;
}

- (gfx::VectorIconId)vectorIconId {
- (const gfx::VectorIcon*)vectorIcon {
switch (type_) {
case AppMenuIconController::IconType::NONE:
DCHECK_EQ(severity_, AppMenuIconController::Severity::NONE);
return gfx::VectorIconId::BROWSER_TOOLS;
return &kBrowserToolsIcon;
case AppMenuIconController::IconType::UPGRADE_NOTIFICATION:
return gfx::VectorIconId::BROWSER_TOOLS_UPDATE;
return &kBrowserToolsUpdateIcon;
case AppMenuIconController::IconType::GLOBAL_ERROR:
case AppMenuIconController::IconType::INCOMPATIBILITY_WARNING:
return gfx::VectorIconId::BROWSER_TOOLS_ERROR;
return &kBrowserToolsErrorIcon;
}

return gfx::VectorIconId::VECTOR_ICON_NONE;
return nullptr;
}

- (SkColor)vectorIconColor:(BOOL)themeIsDark {
Expand Down
9 changes: 5 additions & 4 deletions chrome/browser/ui/cocoa/toolbar/reload_button_cocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "base/macros.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/command_updater.h"
#import "chrome/browser/ui/cocoa/accelerators_cocoa.h"
#import "chrome/browser/ui/cocoa/themed_window.h"
Expand Down Expand Up @@ -193,16 +194,16 @@ - (ViewID)viewID {
return VIEW_ID_RELOAD_BUTTON;
}

- (gfx::VectorIconId)vectorIconId {
- (const gfx::VectorIcon*)vectorIcon {
if ([self tag] == IDC_RELOAD) {
return gfx::VectorIconId::NAVIGATE_RELOAD;
return &kNavigateReloadIcon;
} else if ([self tag] == IDC_STOP) {
return gfx::VectorIconId::NAVIGATE_STOP;
return &kNavigateStopIcon;
} else {
NOTREACHED();
}

return gfx::VectorIconId::VECTOR_ICON_NONE;
return nullptr;
}

- (void)mouseInsideStateDidChange:(BOOL)isInside {
Expand Down
9 changes: 6 additions & 3 deletions chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
#import "base/mac/scoped_nsobject.h"
#import "chrome/browser/ui/cocoa/themed_window.h"
#import "ui/gfx/color_utils.h"
#include "ui/gfx/vector_icons_public.h"

namespace gfx {
struct VectorIcon;
}

enum class ToolbarButtonImageBackgroundStyle {
DEFAULT,
Expand All @@ -34,8 +37,8 @@ enum class ToolbarButtonImageBackgroundStyle {
+ (NSSize)toolbarButtonSize;
// Whether or not to handle the mouse middle click events.
@property(assign, nonatomic) BOOL handleMiddleClick;
// Override point for subclasses to return their vector icon id.
- (gfx::VectorIconId)vectorIconId;
// Override point for subclasses to return their vector icon.
- (const gfx::VectorIcon*)vectorIcon;
// Override point for subclasses to return their vector icon color.
- (SkColor)vectorIconColor:(BOOL)themeIsDark;
// When in Material Design mode, sets the images for each of the ToolbarButton's
Expand Down
29 changes: 14 additions & 15 deletions chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "base/mac/foundation_util.h"
#include "base/mac/sdk_forward_declarations.h"
#include "chrome/app/vector_icons/vector_icons.h"
#import "chrome/browser/ui/cocoa/image_button_cell.h"
#import "chrome/browser/ui/cocoa/l10n_util.h"
#import "chrome/browser/ui/cocoa/view_id_util.h"
Expand Down Expand Up @@ -204,24 +205,22 @@ - (void)drawFocusRingMask {
yRadius:2] fill];
}

- (gfx::VectorIconId)vectorIconId {
- (const gfx::VectorIcon*)vectorIcon {
BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout();
switch ([self viewID]) {
case VIEW_ID_BACK_BUTTON:
return isRTL ? gfx::VectorIconId::NAVIGATE_FORWARD
: gfx::VectorIconId::NAVIGATE_BACK;
return isRTL ? &kNavigateForwardIcon : &kNavigateBackIcon;
case VIEW_ID_FORWARD_BUTTON:
return isRTL ? gfx::VectorIconId::NAVIGATE_BACK
: gfx::VectorIconId::NAVIGATE_FORWARD;
return isRTL ? &kNavigateBackIcon : &kNavigateForwardIcon;
case VIEW_ID_HOME_BUTTON:
return gfx::VectorIconId::NAVIGATE_HOME;
return &kNavigateHomeIcon;
case VIEW_ID_APP_MENU:
return gfx::VectorIconId::BROWSER_TOOLS;
return &kBrowserToolsIcon;
default:
break;
}

return gfx::VectorIconId::VECTOR_ICON_NONE;
return nullptr;
}

- (SkColor)vectorIconColor:(BOOL)themeIsDark {
Expand Down Expand Up @@ -286,9 +285,9 @@ - (void)resetButtonStateImages {
NSImage* disabledIcon = nil;
BOOL isDarkTheme = NO;

gfx::VectorIconId iconId = [self vectorIconId];
if (iconId == gfx::VectorIconId::VECTOR_ICON_NONE) {
// If the button does not have a vector icon id (e.g. it's an extension
const gfx::VectorIcon* icon = [self vectorIcon];
if (!icon) {
// If the button does not have a vector icon (e.g. it's an extension
// button), use its image. The hover, etc. images will be created using
// imageForIcon:withBackgroundStyle: so do the same for the default image.
// If we don't do this, the icon may not appear in the same place as in the
Expand All @@ -308,19 +307,19 @@ - (void)resetButtonStateImages {

// Create the normal and disabled state icons. These icons are always the
// same shape but use a different color.
if (iconId == gfx::VectorIconId::BROWSER_TOOLS) {
if (icon == &kBrowserToolsIcon) {
normalIcon = [self browserToolsIconForFillColor:normalColor];
disabledIcon = [self browserToolsIconForFillColor:disabledColor];
} else {
normalIcon = NSImageFromImageSkia(
gfx::CreateVectorIcon(iconId,
gfx::CreateVectorIcon(*icon,
kMDButtonIconSize.width,
normalColor));

// The home button has no icon for its disabled state.
if (iconId != gfx::VectorIconId::NAVIGATE_RELOAD) {
if (icon != &kNavigateReloadIcon) {
disabledIcon = NSImageFromImageSkia(
gfx::CreateVectorIcon(iconId,
gfx::CreateVectorIcon(*icon,
kMDButtonIconSize.width,
disabledColor));
}
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/ui/global_error/global_error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#include "ui/gfx/image/image.h"

#if !defined(OS_ANDROID)
#include "chrome/app/vector_icons/vector_icons.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icons_public.h"
#endif

// GlobalError ---------------------------------------------------------------
Expand All @@ -30,8 +30,8 @@ gfx::Image GlobalError::MenuItemIcon() {
return ResourceBundle::GetSharedInstance().GetNativeImageNamed(
IDR_INPUT_ALERT_MENU);
#else
return gfx::Image(gfx::CreateVectorIcon(
gfx::VectorIconId::BROWSER_TOOLS_ERROR, gfx::kGoogleYellow700));
return gfx::Image(
gfx::CreateVectorIcon(kBrowserToolsErrorIcon, gfx::kGoogleYellow700));
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include "chrome/browser/ui/views/payments/payment_request_views_util.h"

#include "base/memory/ptr_util.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/vector_icons_public.h"
#include "ui/views/background.h"
#include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/controls/button/button.h"
Expand Down Expand Up @@ -42,7 +42,7 @@ std::unique_ptr<views::View> CreateSheetHeaderView(
layout->SkipColumns(1);
} else {
views::VectorIconButton* back_arrow = new views::VectorIconButton(delegate);
back_arrow->SetIcon(gfx::VectorIconId::NAVIGATE_BACK);
back_arrow->SetIcon(kNavigateBackIcon);
back_arrow->SetSize(back_arrow->GetPreferredSize());
back_arrow->set_tag(static_cast<int>(
PaymentRequestCommonTags::BACK_BUTTON_TAG));
Expand Down
12 changes: 6 additions & 6 deletions chrome/browser/ui/views/toolbar/app_menu_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_otr_state.h"
Expand All @@ -24,7 +25,6 @@
#include "ui/base/theme_provider.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icons_public.h"
#include "ui/keyboard/keyboard_controller.h"
#include "ui/views/controls/button/label_button_border.h"
#include "ui/views/controls/menu/menu_listener.h"
Expand Down Expand Up @@ -136,22 +136,22 @@ void AppMenuButton::UpdateIcon() {
break;
}

gfx::VectorIconId icon_id = gfx::VectorIconId::VECTOR_ICON_NONE;
const gfx::VectorIcon* icon_id = nullptr;
switch (type_) {
case AppMenuIconController::IconType::NONE:
icon_id = gfx::VectorIconId::BROWSER_TOOLS;
icon_id = &kBrowserToolsIcon;
DCHECK_EQ(AppMenuIconController::Severity::NONE, severity_);
break;
case AppMenuIconController::IconType::UPGRADE_NOTIFICATION:
icon_id = gfx::VectorIconId::BROWSER_TOOLS_UPDATE;
icon_id = &kBrowserToolsUpdateIcon;
break;
case AppMenuIconController::IconType::GLOBAL_ERROR:
case AppMenuIconController::IconType::INCOMPATIBILITY_WARNING:
icon_id = gfx::VectorIconId::BROWSER_TOOLS_ERROR;
icon_id = &kBrowserToolsErrorIcon;
break;
}

SetImage(views::Button::STATE_NORMAL, gfx::CreateVectorIcon(icon_id, color));
SetImage(views::Button::STATE_NORMAL, gfx::CreateVectorIcon(*icon_id, color));
}

void AppMenuButton::SetTrailingMargin(int margin) {
Expand Down
Loading

0 comments on commit 8283cad

Please sign in to comment.