Commit 60969ece authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

views: use MD folder icon for treeviews in Harmony mode on Mac

This change:
1) Moves the MD folder icon into //components
2) Makes the Views TreeView use it in Harmony mode

Note that there is no separate "open folder" icon in MD,
so the open and close icons are identical.

This change was previously reviewed as
<https://chromium-review.googlesource.com/c/chromium/src/+/663405>.

Bug: 610428
Change-Id: Ife816d911bef2a92497bb687c5aa59345359aa74
Reviewed-on: https://chromium-review.googlesource.com/692817
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#506822}
parent c74acf25
......@@ -40,8 +40,6 @@ aggregate_vector_icons("chrome_vector_icons") {
"file_download_incognito.1x.icon",
"file_download_incognito.icon",
"file_download_shelf.icon",
"folder.1x.icon",
"folder.icon",
"folder_managed.1x.icon",
"folder_managed.icon",
"folder_supervised.1x.icon",
......
......@@ -1221,8 +1221,6 @@ split_static_library("browser") {
"resource_coordinator/resource_coordinator_render_process_probe.h",
"resource_coordinator/resource_coordinator_web_contents_observer.cc",
"resource_coordinator/resource_coordinator_web_contents_observer.h",
"resource_delegate_mac.h",
"resource_delegate_mac.mm",
"resources_util.cc",
"resources_util.h",
"safe_search_api/safe_search_url_checker.cc",
......
......@@ -7,7 +7,6 @@
#include "base/macros.h"
#include "chrome/browser/chrome_browser_main_posix.h"
#include "chrome/browser/resource_delegate_mac.h"
class ChromeBrowserMainPartsMac : public ChromeBrowserMainPartsPosix {
public:
......@@ -27,8 +26,6 @@ class ChromeBrowserMainPartsMac : public ChromeBrowserMainPartsPosix {
static void DidEndMainMessageLoop();
private:
MacResourceDelegate resource_delegate_;
DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainPartsMac);
};
......
......@@ -117,8 +117,7 @@ void ChromeBrowserMainPartsMac::PreMainMessageLoopStart() {
// to enforce the application locale.
const std::string loaded_locale =
ui::ResourceBundle::InitSharedInstanceWithLocale(
std::string(), &resource_delegate_,
ui::ResourceBundle::LOAD_COMMON_RESOURCES);
std::string(), nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
CHECK(!loaded_locale.empty()) << "Default locale could not be found";
base::FilePath resources_pack_path;
......
// Copyright 2016 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.
#ifndef CHROME_BROWSER_RESOURCE_DELEGATE_MAC_H_
#define CHROME_BROWSER_RESOURCE_DELEGATE_MAC_H_
#include "base/macros.h"
#include "ui/base/resource/resource_bundle.h"
// A resource bundle delegate for Mac. Primary purpose is to intercept certain
// resource ids, and to provide assets from system APIs for them at runtime.
class MacResourceDelegate : public ui::ResourceBundle::Delegate {
public:
MacResourceDelegate();
~MacResourceDelegate() override;
// ui:ResourceBundle::Delegate implementation:
base::FilePath GetPathForResourcePack(const base::FilePath& pack_path,
ui::ScaleFactor scale_factor) override;
base::FilePath GetPathForLocalePack(const base::FilePath& pack_path,
const std::string& locale) override;
gfx::Image GetImageNamed(int resource_id) override;
gfx::Image GetNativeImageNamed(int resource_id) override;
base::RefCountedStaticMemory* LoadDataResourceBytes(
int resource_id,
ui::ScaleFactor scale_factor) override;
bool GetRawDataResource(int resource_id,
ui::ScaleFactor scale_factor,
base::StringPiece* value) override;
bool GetLocalizedString(int message_id, base::string16* value) override;
private:
DISALLOW_COPY_AND_ASSIGN(MacResourceDelegate);
};
#endif // CHROME_BROWSER_RESOURCE_DELEGATE_MAC_H_
// Copyright 2016 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.
#include "chrome/browser/resource_delegate_mac.h"
#import <Cocoa/Cocoa.h>
#include "ui/resources/grit/ui_resources.h"
#include "ui/views/resources/grit/views_resources.h"
namespace {
const int kFolderIconReportedSizeDIP = 16;
// Returns the icon for the given |hfs_type| defined in Cocoa's IconsCore.h, as
// a gfx::Image of dimensions |width| X |height|.
gfx::Image ImageForHFSType(int hfs_type, int width, int height) {
NSImage* icon = [[NSWorkspace sharedWorkspace]
iconForFileType:NSFileTypeForHFSTypeCode(hfs_type)];
DCHECK(icon);
[icon setSize:NSMakeSize(width, height)];
return gfx::Image([icon retain]);
}
} // namespace
MacResourceDelegate::MacResourceDelegate() {}
MacResourceDelegate::~MacResourceDelegate() {}
base::FilePath MacResourceDelegate::GetPathForResourcePack(
const base::FilePath& pack_path,
ui::ScaleFactor scale_factor) {
return pack_path;
}
base::FilePath MacResourceDelegate::GetPathForLocalePack(
const base::FilePath& pack_path,
const std::string& locale) {
return pack_path;
}
gfx::Image MacResourceDelegate::GetImageNamed(int resource_id) {
return GetNativeImageNamed(resource_id);
}
gfx::Image MacResourceDelegate::GetNativeImageNamed(int resource_id) {
switch (resource_id) {
// On Mac, return the same assets for the _RTL resources. Consistent with,
// e.g., Safari.
case IDR_FOLDER_OPEN:
case IDR_FOLDER_OPEN_RTL:
return ImageForHFSType(kOpenFolderIcon, kFolderIconReportedSizeDIP,
kFolderIconReportedSizeDIP);
case IDR_FOLDER_CLOSED:
case IDR_FOLDER_CLOSED_RTL:
return ImageForHFSType(kGenericFolderIcon, kFolderIconReportedSizeDIP,
kFolderIconReportedSizeDIP);
}
return gfx::Image();
}
base::RefCountedStaticMemory* MacResourceDelegate::LoadDataResourceBytes(
int resource_id,
ui::ScaleFactor scale_factor) {
return nullptr;
}
bool MacResourceDelegate::GetRawDataResource(int resource_id,
ui::ScaleFactor scale_factor,
base::StringPiece* value) {
return false;
}
bool MacResourceDelegate::GetLocalizedString(int message_id,
base::string16* value) {
return false;
}
......@@ -467,6 +467,7 @@ split_static_library("ui") {
"//components/user_prefs",
"//components/variations",
"//components/variations/service",
"//components/vector_icons",
"//components/version_ui",
"//components/web_cache/browser",
"//components/web_resource",
......
......@@ -20,6 +20,7 @@
#include "components/search/search.h"
#include "components/url_formatter/url_formatter.h"
#include "components/user_prefs/user_prefs.h"
#include "components/vector_icons/vector_icons.h"
#include "content/public/browser/web_contents.h"
#include "extensions/features/features.h"
#include "ui/base/dragdrop/drag_drop_types.h"
......@@ -298,7 +299,7 @@ gfx::ImageSkia GetBookmarkFolderIcon(SkColor text_color) {
return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
IDR_BOOKMARK_BAR_FOLDER);
#else
return GetFolderIcon(kFolderIcon, text_color);
return GetFolderIcon(vector_icons::kFolderIcon, text_color);
#endif
}
......
......@@ -19,6 +19,8 @@ aggregate_vector_icons("components_vector_icons") {
"close_16.icon",
"edit.icon",
"error_circle.icon",
"folder.1x.icon",
"folder.icon",
"forward_arrow.1x.icon",
"forward_arrow.icon",
"help_outline.icon",
......
......@@ -9,6 +9,8 @@
#include "base/i18n/rtl.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "build/build_config.h"
#include "components/vector_icons/vector_icons.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/ime/input_method.h"
#include "ui/base/material_design/material_design_controller.h"
......@@ -16,6 +18,7 @@
#include "ui/events/event.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_conversions.h"
......@@ -77,12 +80,27 @@ TreeView::TreeView()
drawing_provider_(base::MakeUnique<TreeViewDrawingProvider>()) {
// Always focusable, even on Mac (consistent with NSOutlineView).
SetFocusBehavior(FocusBehavior::ALWAYS);
closed_icon_ = *ui::ResourceBundle::GetSharedInstance().GetImageNamed(
(base::i18n::IsRTL() ? IDR_FOLDER_CLOSED_RTL
: IDR_FOLDER_CLOSED)).ToImageSkia();
open_icon_ = *ui::ResourceBundle::GetSharedInstance().GetImageNamed(
(base::i18n::IsRTL() ? IDR_FOLDER_OPEN_RTL
: IDR_FOLDER_OPEN)).ToImageSkia();
#if defined(OS_MACOSX)
constexpr bool kUseMdIcons = true;
#else
constexpr bool kUseMdIcons = false;
#endif
if (kUseMdIcons) {
closed_icon_ = open_icon_ =
gfx::CreateVectorIcon(vector_icons::kFolderIcon, gfx::kChromeIconGrey);
} else {
// TODO(ellyjones): if the pre-Harmony codepath goes away, merge
// closed_icon_ and open_icon_.
closed_icon_ =
*ui::ResourceBundle::GetSharedInstance()
.GetImageNamed((base::i18n::IsRTL() ? IDR_FOLDER_CLOSED_RTL
: IDR_FOLDER_CLOSED))
.ToImageSkia();
open_icon_ = *ui::ResourceBundle::GetSharedInstance()
.GetImageNamed((base::i18n::IsRTL() ? IDR_FOLDER_OPEN_RTL
: IDR_FOLDER_OPEN))
.ToImageSkia();
}
text_offset_ = closed_icon_.width() + kImagePadding + kImagePadding +
kArrowRegionSize;
}
......@@ -767,7 +785,7 @@ void TreeView::PaintRow(gfx::Canvas* canvas,
int icon_index = model_->GetIconIndex(node->model_node());
if (icon_index != -1)
icon = icons_[icon_index];
else if (node == selected_node_ && PlatformStyle::kTreeViewUsesOpenIcon)
else if (node == selected_node_)
icon = open_icon_;
else
icon = closed_icon_;
......
......@@ -47,7 +47,6 @@ const Button::KeyClickAction PlatformStyle::kKeyClickActionOnSpace =
Button::CLICK_ON_KEY_RELEASE;
const bool PlatformStyle::kReturnClicksFocusedControl = true;
const bool PlatformStyle::kTreeViewSelectionPaintsEntireRow = false;
const bool PlatformStyle::kTreeViewUsesOpenIcon = true;
const bool PlatformStyle::kUseRipples = true;
const bool PlatformStyle::kMirrorBubbleArrowInRTLByDefault = true;
const bool PlatformStyle::kTextfieldScrollsToStartOnFocusChange = false;
......
......@@ -54,10 +54,6 @@ class VIEWS_EXPORT PlatformStyle {
// label for that row.
static const bool kTreeViewSelectionPaintsEntireRow;
// Whether TreeViews use a separate icon for the currently selected node's
// ancestors.
static const bool kTreeViewUsesOpenIcon;
// Whether ripples should be used for visual feedback on control activation.
static const bool kUseRipples;
......
......@@ -22,7 +22,6 @@ const bool PlatformStyle::kSelectWordOnRightClick = true;
const bool PlatformStyle::kSelectAllOnRightClickWhenUnfocused = true;
const bool PlatformStyle::kTextfieldScrollsToStartOnFocusChange = true;
const bool PlatformStyle::kTreeViewSelectionPaintsEntireRow = true;
const bool PlatformStyle::kTreeViewUsesOpenIcon = false;
const bool PlatformStyle::kUseRipples = false;
// On Mac, the Cocoa browser window does not flip its UI in RTL (e.g. bookmark
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment