Added SkColorToHexString function.
Added function to convert SkColor to a formatted hexadecimal string, and replaced repetitious logic with this function. Bug: 1286561 Change-Id: I6bde8689494637b59ca6acd68c60bc1c5e56facf Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3382021 Reviewed-by: Mark Schillaci <mschillaci@google.com> Reviewed-by: Eric Willigers <ericwilligers@chromium.org> Reviewed-by: Alexander Bolodurin <alexbn@chromium.org> Reviewed-by: Nico Weber <thakis@chromium.org> Commit-Queue: Catherine Cheng <catherinecheng@google.com> Cr-Commit-Position: refs/heads/main@{#959012}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
94849f73cb
commit
37ca5a4911
chrome/browser
content/browser/accessibility
skia/ext
ui/views/color_chooser
@ -7,9 +7,9 @@
|
||||
#include "base/logging.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "chrome/browser/new_tab_page/chrome_colors/selected_colors_info.h"
|
||||
#include "chrome/common/themes/autogenerated_theme_util.h"
|
||||
#include "skia/ext/skia_utils_base.h"
|
||||
|
||||
// Template for color info line.
|
||||
// $1 - color id
|
||||
@ -49,12 +49,6 @@ const char kFileContentTemplate[] =
|
||||
"\n"
|
||||
"#endif // CHROME_COMMON_SEARCH_GENERATED_COLORS_INFO_H_\n";
|
||||
|
||||
// Returns hex string representation for the |color| in "#FFFFFF" format.
|
||||
std::string SkColorToHexString(SkColor color) {
|
||||
return base::StringPrintf("#%02X%02X%02X", SkColorGetR(color),
|
||||
SkColorGetG(color), SkColorGetB(color));
|
||||
}
|
||||
|
||||
// Generates color info line in the following format:
|
||||
// ColorInfo(ID, SkColorSetRGB(R, G, B), LABEL, ICON_DATA)
|
||||
std::string GenerateColorLine(chrome_colors::ColorInfo color_info) {
|
||||
|
@ -59,6 +59,7 @@
|
||||
#include "google_apis/gaia/core_account_id.h"
|
||||
#include "media/base/media_switches.h"
|
||||
#include "services/network/public/mojom/content_security_policy.mojom.h"
|
||||
#include "skia/ext/skia_utils_base.h"
|
||||
#include "ui/base/accelerators/accelerator.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
@ -596,11 +597,8 @@ void NewTabPageUI::OnThemeChanged() {
|
||||
auto background_color =
|
||||
ThemeService::GetThemeProviderForProfile(profile_).GetColor(
|
||||
ThemeProperties::COLOR_NTP_BACKGROUND);
|
||||
update->SetString(
|
||||
"backgroundColor",
|
||||
base::StringPrintf("#%02X%02X%02X", SkColorGetR(background_color),
|
||||
SkColorGetG(background_color),
|
||||
SkColorGetB(background_color)));
|
||||
update->SetString("backgroundColor",
|
||||
skia::SkColorToHexString(background_color));
|
||||
content::WebUIDataSource::Update(profile_, chrome::kChromeUINewTabPageHost,
|
||||
std::move(update));
|
||||
}
|
||||
|
@ -12,10 +12,10 @@
|
||||
#include "base/lazy_instance.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "content/browser/accessibility/browser_accessibility_manager_android.h"
|
||||
#include "content/public/common/content_client.h"
|
||||
#include "skia/ext/skia_utils_base.h"
|
||||
#include "third_party/blink/public/strings/grit/blink_accessibility_strings.h"
|
||||
#include "third_party/blink/public/strings/grit/blink_strings.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
@ -646,11 +646,7 @@ std::u16string BrowserAccessibilityAndroid::GetTextContentUTF16() const {
|
||||
if (GetRole() == ax::mojom::Role::kColorWell) {
|
||||
unsigned int color = static_cast<unsigned int>(
|
||||
GetIntAttribute(ax::mojom::IntAttribute::kColorValue));
|
||||
unsigned int red = SkColorGetR(color);
|
||||
unsigned int green = SkColorGetG(color);
|
||||
unsigned int blue = SkColorGetB(color);
|
||||
return base::UTF8ToUTF16(
|
||||
base::StringPrintf("#%02X%02X%02X", red, green, blue));
|
||||
return base::UTF8ToUTF16(skia::SkColorToHexString(color));
|
||||
}
|
||||
|
||||
std::u16string text = GetNameAsString16();
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "base/pickle.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "third_party/skia/include/core/SkData.h"
|
||||
#include "third_party/skia/include/core/SkEncodedImageFormat.h"
|
||||
@ -115,4 +116,8 @@ bool SkBitmapToN32OpaqueOrPremul(const SkBitmap& in, SkBitmap* out) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string SkColorToHexString(SkColor color) {
|
||||
return base::StringPrintf("#%02X%02X%02X", SkColorGetR(color),
|
||||
SkColorGetG(color), SkColorGetB(color));
|
||||
}
|
||||
} // namespace skia
|
||||
|
@ -5,6 +5,7 @@
|
||||
#ifndef SKIA_EXT_SKIA_UTILS_BASE_H_
|
||||
#define SKIA_EXT_SKIA_UTILS_BASE_H_
|
||||
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
#include "third_party/skia/include/core/SkFlattenable.h"
|
||||
#include "third_party/skia/include/ports/SkFontConfigInterface.h"
|
||||
|
||||
@ -55,6 +56,9 @@ SK_API void WriteSkFontStyle(base::Pickle* pickle, SkFontStyle style);
|
||||
// delaying this conversion until a later time.
|
||||
SK_API bool SkBitmapToN32OpaqueOrPremul(const SkBitmap& in, SkBitmap* out);
|
||||
|
||||
// Returns hex string representation for the |color| in "#FFFFFF" format.
|
||||
SK_API std::string SkColorToHexString(SkColor color);
|
||||
|
||||
} // namespace skia
|
||||
|
||||
#endif // SKIA_EXT_SKIA_UTILS_BASE_H_
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
#include "third_party/skia/include/core/SkImageInfo.h"
|
||||
|
||||
namespace skia {
|
||||
@ -85,5 +86,12 @@ TEST(SkiaUtilsBase, ConvertWeirdFormatToN32) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(SkiaUtilsBase, ConvertSkColorToHexString) {
|
||||
EXPECT_EQ(SkColorToHexString(SK_ColorBLUE), "#0000FF");
|
||||
EXPECT_EQ(SkColorToHexString(SK_ColorRED), "#FF0000");
|
||||
EXPECT_EQ(SkColorToHexString(SK_ColorGREEN), "#00FF00");
|
||||
EXPECT_EQ(SkColorToHexString(SK_ColorWHITE), "#FFFFFF");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace skia
|
||||
|
@ -14,10 +14,10 @@
|
||||
#include "base/check.h"
|
||||
#include "base/cxx17_backports.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "cc/paint/paint_flags.h"
|
||||
#include "cc/paint/paint_shader.h"
|
||||
#include "skia/ext/skia_utils_base.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
#include "third_party/skia/include/core/SkPath.h"
|
||||
#include "third_party/skia/include/effects/SkGradientShader.h"
|
||||
@ -53,9 +53,7 @@ constexpr int kBorderWidth = 1;
|
||||
constexpr int kTextfieldLengthInChars = 14;
|
||||
|
||||
std::u16string GetColorText(SkColor color) {
|
||||
return base::ASCIIToUTF16(
|
||||
base::StringPrintf("#%02x%02x%02x", SkColorGetR(color),
|
||||
SkColorGetG(color), SkColorGetB(color)));
|
||||
return base::ASCIIToUTF16(skia::SkColorToHexString(color));
|
||||
}
|
||||
|
||||
bool GetColorFromText(const std::u16string& text, SkColor* result) {
|
||||
|
Reference in New Issue
Block a user