Commit a423be33 authored by David Black's avatar David Black Committed by Commit Bot

Add HoldingSpaceColorProvider.

The purpose of this class is workaround dependency restrictions that
prevent direct access to AshColorProvider from outside //ash:ash.

Moving forward, all color lookups for holding space will go through our
provider for consistency.

Bug: 1133913
Change-Id: Iea7caa2eda7d60ba88cb95ce7efe5fcfa259a075
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2446207Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: David Black <dmblack@google.com>
Cr-Commit-Position: refs/heads/master@{#813827}
parent 8943a9a4
......@@ -935,6 +935,8 @@ component("ash") {
"system/enterprise/enterprise_domain_observer.h",
"system/gesture_education/gesture_education_notification_controller.cc",
"system/gesture_education/gesture_education_notification_controller.h",
"system/holding_space/holding_space_color_provider_impl.cc",
"system/holding_space/holding_space_color_provider_impl.h",
"system/holding_space/holding_space_item_chip_view.cc",
"system/holding_space/holding_space_item_chip_view.h",
"system/holding_space/holding_space_item_chips_container.cc",
......
......@@ -140,6 +140,8 @@ component("cpp") {
"frame_utils.h",
"gesture_action_type.h",
"holding_space/holding_space_client.h",
"holding_space/holding_space_color_provider.cc",
"holding_space/holding_space_color_provider.h",
"holding_space/holding_space_constants.h",
"holding_space/holding_space_controller.cc",
"holding_space/holding_space_controller.h",
......
// Copyright 2020 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 "ash/public/cpp/holding_space/holding_space_color_provider.h"
#include "base/check_op.h"
namespace ash {
namespace {
// The singleton instance.
HoldingSpaceColorProvider* g_instance = nullptr;
} // namespace
HoldingSpaceColorProvider::~HoldingSpaceColorProvider() {
DCHECK_EQ(g_instance, this);
g_instance = nullptr;
}
// static
HoldingSpaceColorProvider* HoldingSpaceColorProvider::Get() {
return g_instance;
}
HoldingSpaceColorProvider::HoldingSpaceColorProvider() {
DCHECK_EQ(g_instance, nullptr);
g_instance = this;
}
} // namespace ash
// Copyright 2020 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 ASH_PUBLIC_CPP_HOLDING_SPACE_HOLDING_SPACE_COLOR_PROVIDER_H_
#define ASH_PUBLIC_CPP_HOLDING_SPACE_HOLDING_SPACE_COLOR_PROVIDER_H_
#include "ash/public/cpp/ash_public_export.h"
#include "third_party/skia/include/core/SkColor.h"
namespace ash {
// The interface for the singleton which provides colors to holding space.
class ASH_PUBLIC_EXPORT HoldingSpaceColorProvider {
public:
virtual ~HoldingSpaceColorProvider();
// Returns the singleton instance.
static HoldingSpaceColorProvider* Get();
// Returns the color to be used for file icons.
virtual SkColor GetFileIconColor() const = 0;
protected:
HoldingSpaceColorProvider();
};
} // namespace ash
#endif // ASH_PUBLIC_CPP_HOLDING_SPACE_HOLDING_SPACE_COLOR_PROVIDER_H_
......@@ -4,6 +4,7 @@
#include "ash/public/cpp/holding_space/holding_space_controller.h"
#include "ash/public/cpp/holding_space/holding_space_color_provider.h"
#include "ash/public/cpp/holding_space/holding_space_controller_observer.h"
#include "ash/public/cpp/session/session_controller.h"
#include "base/check.h"
......@@ -16,7 +17,9 @@ HoldingSpaceController* g_instance = nullptr;
} // namespace
HoldingSpaceController::HoldingSpaceController() {
HoldingSpaceController::HoldingSpaceController(
std::unique_ptr<HoldingSpaceColorProvider> color_provider)
: color_provider_(std::move(color_provider)) {
CHECK(!g_instance);
g_instance = this;
......
......@@ -5,6 +5,8 @@
#ifndef ASH_PUBLIC_CPP_HOLDING_SPACE_HOLDING_SPACE_CONTROLLER_H_
#define ASH_PUBLIC_CPP_HOLDING_SPACE_HOLDING_SPACE_CONTROLLER_H_
#include <memory>
#include "ash/public/cpp/ash_public_export.h"
#include "ash/public/cpp/session/session_observer.h"
#include "base/observer_list.h"
......@@ -13,6 +15,7 @@
namespace ash {
class HoldingSpaceClient;
class HoldingSpaceColorProvider;
class HoldingSpaceControllerObserver;
class HoldingSpaceModel;
......@@ -23,7 +26,7 @@ class HoldingSpaceModel;
// using HoldingSpaceController::Get().
class ASH_PUBLIC_EXPORT HoldingSpaceController : public SessionObserver {
public:
HoldingSpaceController();
explicit HoldingSpaceController(std::unique_ptr<HoldingSpaceColorProvider>);
HoldingSpaceController(const HoldingSpaceController& other) = delete;
HoldingSpaceController& operator=(const HoldingSpaceController& other) =
delete;
......@@ -53,6 +56,9 @@ class ASH_PUBLIC_EXPORT HoldingSpaceController : public SessionObserver {
void SetClient(HoldingSpaceClient* client);
void SetModel(HoldingSpaceModel* model);
// The singleton provider for colors used by holding space.
std::unique_ptr<HoldingSpaceColorProvider> color_provider_;
// The currently active holding space client, set by `SetClient()`.
HoldingSpaceClient* client_ = nullptr;
......
......@@ -109,6 +109,7 @@
#include "ash/system/brightness/brightness_controller_chromeos.h"
#include "ash/system/brightness_control_delegate.h"
#include "ash/system/caps_lock_notification_controller.h"
#include "ash/system/holding_space/holding_space_color_provider_impl.h"
#include "ash/system/keyboard_brightness/keyboard_brightness_controller.h"
#include "ash/system/keyboard_brightness_control_delegate.h"
#include "ash/system/locale/locale_update_controller_impl.h"
......@@ -1250,8 +1251,10 @@ void Shell::Init(
std::make_unique<DisplayAlignmentController>();
}
if (features::IsTemporaryHoldingSpaceEnabled())
holding_space_controller_ = std::make_unique<HoldingSpaceController>();
if (features::IsTemporaryHoldingSpaceEnabled()) {
holding_space_controller_ = std::make_unique<HoldingSpaceController>(
std::make_unique<HoldingSpaceColorProviderImpl>());
}
for (auto& observer : shell_observers_)
observer.OnShellInitialized();
......
// Copyright 2020 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 "ash/system/holding_space/holding_space_color_provider_impl.h"
#include "ash/style/ash_color_provider.h"
namespace ash {
HoldingSpaceColorProviderImpl::HoldingSpaceColorProviderImpl() = default;
HoldingSpaceColorProviderImpl::~HoldingSpaceColorProviderImpl() = default;
SkColor HoldingSpaceColorProviderImpl::GetFileIconColor() const {
return AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kIconColorPrimary);
}
} // namespace ash
// Copyright 2020 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 ASH_SYSTEM_HOLDING_SPACE_HOLDING_SPACE_COLOR_PROVIDER_IMPL_H_
#define ASH_SYSTEM_HOLDING_SPACE_HOLDING_SPACE_COLOR_PROVIDER_IMPL_H_
#include "ash/public/cpp/holding_space/holding_space_color_provider.h"
namespace ash {
// The implementation of the singleton which provides colors to holding space.
class HoldingSpaceColorProviderImpl : public HoldingSpaceColorProvider {
public:
HoldingSpaceColorProviderImpl();
HoldingSpaceColorProviderImpl(const HoldingSpaceColorProviderImpl&) = delete;
HoldingSpaceColorProviderImpl& operator=(
const HoldingSpaceColorProviderImpl&) = delete;
~HoldingSpaceColorProviderImpl() override;
private:
// HoldingSpaceColorProvider:
SkColor GetFileIconColor() const override;
};
} // namespace ash
#endif // ASH_PUBLIC_CPP_HOLDING_SPACE_HOLDING_SPACE_COLOR_PROVIDER_H_
......@@ -5,6 +5,7 @@
#include "chrome/browser/ui/ash/holding_space/holding_space_util.h"
#include "ash/public/cpp/file_icon_util.h"
#include "ash/public/cpp/holding_space/holding_space_color_provider.h"
#include "ash/public/cpp/holding_space/holding_space_constants.h"
#include "ash/public/cpp/holding_space/holding_space_image.h"
#include "base/barrier_closure.h"
......@@ -39,12 +40,15 @@ gfx::ImageSkia GetPlaceholderImage(HoldingSpaceItem::Type type,
break;
}
const SkColor color = HoldingSpaceColorProvider::Get()->GetFileIconColor();
// NOTE: We superimpose the file type icon for `file_path` over a transparent
// bitmap in order to center it within the placeholder image at a fixed size.
SkBitmap bitmap;
bitmap.allocN32Pixels(size.width(), size.height());
return gfx::ImageSkiaOperations::CreateSuperimposedImage(
gfx::ImageSkia::CreateFrom1xBitmap(bitmap), GetIconForPath(file_path));
gfx::ImageSkia::CreateFrom1xBitmap(bitmap),
GetIconForPath(file_path, color));
}
} // namespace
......
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