Commit 79f8dc4c authored by Thomas Lukaszewicz's avatar Thomas Lukaszewicz Committed by Commit Bot

Removed TabGroupIconImageSource

Removed the need for TabGroupIconImageSource from the
ExistingTabGroupSubMenuModel and instead switched to using vector
icons for the group image.

When the ThemedVectorIcon change gets merged in this change will
enable the group icon to be rendered using colors obtained through
the ThemeProvider supplied from the rendered menu's Widget.

Bug: 1056916
Change-Id: Ibc8bb5df41cd2b8e9e5baea97822d97e28c2e246
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2116492Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Commit-Queue: Thomas Lukaszewicz <tluk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753399}
parent c939527d
......@@ -115,6 +115,7 @@ aggregate_vector_icons("chrome_vector_icons") {
"tab_audio_rounded.icon",
"tab_bluetooth_connected.icon",
"tab_close_normal.icon",
"tab_group.icon",
"tab_media_capturing.icon",
"tab_media_capturing_with_arrow.icon",
"tab_media_recording.icon",
......
// 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.
CIRCLE, 24, 24, 24
\ No newline at end of file
......@@ -6,6 +6,7 @@
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/ui/tabs/tab_group.h"
......@@ -18,59 +19,9 @@
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/canvas_image_source.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/native_theme/native_theme.h"
namespace {
// The tab group icon is a circle that reflects the color of the group in the
// tab strip. Because it's a simple, colored shape, we use a CanvasImageSource
// to draw the icon directly into the menu, rather than passing in a vector.
class TabGroupIconImageSource : public gfx::CanvasImageSource {
public:
// Note: This currently matches the size of the empty tab group header, but
// it doesn't share the same variable because this icon should remain
// constrained to a menu icon size.
static constexpr int kIconSize = 14;
TabGroupIconImageSource(Profile* profile,
const tab_groups::TabGroupVisualData* visual_data);
~TabGroupIconImageSource() override;
private:
// gfx::CanvasImageSource overrides:
void Draw(gfx::Canvas* canvas) override;
Profile* profile_;
const tab_groups::TabGroupVisualData* visual_data_;
DISALLOW_COPY_AND_ASSIGN(TabGroupIconImageSource);
};
TabGroupIconImageSource::TabGroupIconImageSource(
Profile* profile,
const tab_groups::TabGroupVisualData* visual_data)
: CanvasImageSource(gfx::Size(kIconSize, kIconSize)),
profile_(profile),
visual_data_(visual_data) {}
TabGroupIconImageSource::~TabGroupIconImageSource() = default;
void TabGroupIconImageSource::Draw(gfx::Canvas* canvas) {
const ui::ThemeProvider& tp =
ThemeService::GetThemeProviderForProfile(profile_);
const SkColor color =
tp.GetColor(GetTabGroupContextMenuColorId(visual_data_->color()));
cc::PaintFlags flags;
flags.setStyle(cc::PaintFlags::kFill_Style);
flags.setAntiAlias(true);
flags.setColor(color);
canvas->DrawCircle(gfx::PointF(kIconSize / 2, kIconSize / 2), kIconSize / 2,
flags);
}
} // namespace
constexpr int kFirstCommandIndex =
TabStripModel::ContextMenuCommand::CommandLast + 1;
......@@ -85,18 +36,19 @@ ExistingTabGroupSubMenuModel::ExistingTabGroupSubMenuModel(TabStripModel* model,
void ExistingTabGroupSubMenuModel::Build() {
// Start command ids after the parent menu's ids to avoid collisions.
int group_index = kFirstCommandIndex;
const auto& tp = ThemeService::GetThemeProviderForProfile(model_->profile());
for (tab_groups::TabGroupId group : GetOrderedTabGroups()) {
if (ShouldShowGroup(model_, context_index_, group)) {
const TabGroup* tab_group = model_->group_model()->GetTabGroup(group);
const base::string16 group_title = tab_group->visual_data()->title();
const base::string16 displayed_title =
group_title.empty() ? tab_group->GetContentString() : group_title;
AddItemWithIcon(
group_index, displayed_title,
gfx::ImageSkia(std::make_unique<TabGroupIconImageSource>(
model_->profile(), tab_group->visual_data()),
gfx::Size(TabGroupIconImageSource::kIconSize,
TabGroupIconImageSource::kIconSize)));
constexpr int kIconSize = 14;
const int color_id =
GetTabGroupContextMenuColorId(tab_group->visual_data()->color());
AddItemWithIcon(group_index, displayed_title,
gfx::CreateVectorIcon(kTabGroupIcon, kIconSize,
tp.GetColor(color_id)));
}
group_index++;
}
......
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