Commit 7f683b76 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Move Android color_helpers to //ui/android

This is a pretty generic file with no ties to //chrome, and is needed
by code in components.

Bug: 1147291
Change-Id: I9259a472354661e45bac8af6c56205a227a1978e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2543125
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828525}
parent 733d058c
...@@ -2507,8 +2507,6 @@ static_library("browser") { ...@@ -2507,8 +2507,6 @@ static_library("browser") {
"android/chrome_session_state.h", "android/chrome_session_state.h",
"android/chrome_startup_flags.cc", "android/chrome_startup_flags.cc",
"android/chrome_startup_flags.h", "android/chrome_startup_flags.h",
"android/color_helpers.cc",
"android/color_helpers.h",
"android/component_updater/background_task_update_scheduler.cc", "android/component_updater/background_task_update_scheduler.cc",
"android/component_updater/background_task_update_scheduler.h", "android/component_updater/background_task_update_scheduler.h",
"android/compose_bitmaps_helper.cc", "android/compose_bitmaps_helper.cc",
......
...@@ -19,13 +19,13 @@ ...@@ -19,13 +19,13 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "chrome/android/chrome_jni_headers/ShortcutHelper_jni.h" #include "chrome/android/chrome_jni_headers/ShortcutHelper_jni.h"
#include "chrome/browser/android/color_helpers.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/manifest_icon_downloader.h" #include "content/public/browser/manifest_icon_downloader.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "third_party/blink/public/common/manifest/manifest.h" #include "third_party/blink/public/common/manifest/manifest.h"
#include "third_party/blink/public/common/manifest/manifest_icon_selector.h" #include "third_party/blink/public/common/manifest/manifest_icon_selector.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/android/color_helpers.h"
#include "ui/gfx/android/java_bitmap.h" #include "ui/gfx/android/java_bitmap.h"
#include "ui/gfx/color_analysis.h" #include "ui/gfx/color_analysis.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -103,8 +103,8 @@ void AddWebappWithSkBitmap(content::WebContents* web_contents, ...@@ -103,8 +103,8 @@ void AddWebappWithSkBitmap(content::WebContents* web_contents,
java_short_name, java_best_primary_icon_url, java_bitmap, java_short_name, java_best_primary_icon_url, java_bitmap,
is_icon_maskable, static_cast<int>(info.display), is_icon_maskable, static_cast<int>(info.display),
static_cast<int>(info.orientation), info.source, static_cast<int>(info.orientation), info.source,
OptionalSkColorToJavaColor(info.theme_color), ui::OptionalSkColorToJavaColor(info.theme_color),
OptionalSkColorToJavaColor(info.background_color)); ui::OptionalSkColorToJavaColor(info.background_color));
// Start downloading the splash image in parallel with the app install. // Start downloading the splash image in parallel with the app install.
content::ManifestIconDownloader::Download( content::ManifestIconDownloader::Download(
......
...@@ -8,10 +8,10 @@ ...@@ -8,10 +8,10 @@
#include "base/android/jni_string.h" #include "base/android/jni_string.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/android/chrome_jni_headers/WebApkHandlerDelegate_jni.h" #include "chrome/android/chrome_jni_headers/WebApkHandlerDelegate_jni.h"
#include "chrome/browser/android/color_helpers.h"
#include "third_party/blink/public/common/manifest/manifest.h" #include "third_party/blink/public/common/manifest/manifest.h"
#include "third_party/blink/public/common/manifest/manifest_icon_selector.h" #include "third_party/blink/public/common/manifest/manifest_icon_selector.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/android/color_helpers.h"
using base::android::JavaParamRef; using base::android::JavaParamRef;
...@@ -73,8 +73,8 @@ void WebApkHandlerDelegate::OnWebApkInfoRetrieved( ...@@ -73,8 +73,8 @@ void WebApkHandlerDelegate::OnWebApkInfoRetrieved(
base::android::ConvertJavaStringToUTF8(env, jmanifest_start_url), base::android::ConvertJavaStringToUTF8(env, jmanifest_start_url),
static_cast<blink::mojom::DisplayMode>(jdisplay_mode), static_cast<blink::mojom::DisplayMode>(jdisplay_mode),
static_cast<device::mojom::ScreenOrientationLockType>(jorientation), static_cast<device::mojom::ScreenOrientationLockType>(jorientation),
JavaColorToOptionalSkColor(jtheme_color), ui::JavaColorToOptionalSkColor(jtheme_color),
JavaColorToOptionalSkColor(jbackground_color), ui::JavaColorToOptionalSkColor(jbackground_color),
base::Time::FromJavaTime(jlast_update_check_time_ms), base::Time::FromJavaTime(jlast_update_check_time_ms),
base::Time::FromJavaTime(jlast_update_completion_time_ms), base::Time::FromJavaTime(jlast_update_completion_time_ms),
static_cast<bool>(jrelax_updates), backing_browser_package_name, static_cast<bool>(jrelax_updates), backing_browser_package_name,
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include "base/threading/scoped_blocking_call.h" #include "base/threading/scoped_blocking_call.h"
#include "base/timer/elapsed_timer.h" #include "base/timer/elapsed_timer.h"
#include "chrome/android/chrome_jni_headers/WebApkInstaller_jni.h" #include "chrome/android/chrome_jni_headers/WebApkInstaller_jni.h"
#include "chrome/browser/android/color_helpers.h"
#include "chrome/browser/android/shortcut_helper.h" #include "chrome/browser/android/shortcut_helper.h"
#include "chrome/browser/android/webapk/webapk.pb.h" #include "chrome/browser/android/webapk/webapk.pb.h"
#include "chrome/browser/android/webapk/webapk_install_service.h" #include "chrome/browser/android/webapk/webapk_install_service.h"
...@@ -51,6 +50,7 @@ ...@@ -51,6 +50,7 @@
#include "services/network/public/cpp/simple_url_loader.h" #include "services/network/public/cpp/simple_url_loader.h"
#include "third_party/blink/public/common/manifest/manifest.h" #include "third_party/blink/public/common/manifest/manifest.h"
#include "third_party/blink/public/common/manifest/manifest_util.h" #include "third_party/blink/public/common/manifest/manifest_util.h"
#include "ui/android/color_helpers.h"
#include "ui/gfx/android/java_bitmap.h" #include "ui/gfx/android/java_bitmap.h"
#include "ui/gfx/codec/png_codec.h" #include "ui/gfx/codec/png_codec.h"
#include "url/origin.h" #include "url/origin.h"
...@@ -200,9 +200,9 @@ std::unique_ptr<std::string> BuildProtoInBackground( ...@@ -200,9 +200,9 @@ std::unique_ptr<std::string> BuildProtoInBackground(
web_app_manifest->set_display_mode( web_app_manifest->set_display_mode(
blink::DisplayModeToString(shortcut_info.display)); blink::DisplayModeToString(shortcut_info.display));
web_app_manifest->set_background_color( web_app_manifest->set_background_color(
OptionalSkColorToString(shortcut_info.background_color)); ui::OptionalSkColorToString(shortcut_info.background_color));
web_app_manifest->set_theme_color( web_app_manifest->set_theme_color(
OptionalSkColorToString(shortcut_info.theme_color)); ui::OptionalSkColorToString(shortcut_info.theme_color));
std::string* scope = web_app_manifest->add_scopes(); std::string* scope = web_app_manifest->add_scopes();
scope->assign(shortcut_info.scope.spec()); scope->assign(shortcut_info.scope.spec());
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/android/chrome_jni_headers/WebApkUpdateDataFetcher_jni.h" #include "chrome/android/chrome_jni_headers/WebApkUpdateDataFetcher_jni.h"
#include "chrome/browser/android/color_helpers.h"
#include "chrome/browser/android/shortcut_helper.h" #include "chrome/browser/android/shortcut_helper.h"
#include "chrome/browser/android/webapk/webapk_web_manifest_checker.h" #include "chrome/browser/android/webapk/webapk_web_manifest_checker.h"
#include "chrome/browser/installable/installable_manager.h" #include "chrome/browser/installable/installable_manager.h"
...@@ -27,6 +26,7 @@ ...@@ -27,6 +26,7 @@
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "third_party/blink/public/common/manifest/manifest.h" #include "third_party/blink/public/common/manifest/manifest.h"
#include "third_party/smhasher/src/MurmurHash2.h" #include "third_party/smhasher/src/MurmurHash2.h"
#include "ui/android/color_helpers.h"
#include "ui/gfx/android/java_bitmap.h" #include "ui/gfx/android/java_bitmap.h"
#include "ui/gfx/codec/png_codec.h" #include "ui/gfx/codec/png_codec.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -284,8 +284,8 @@ void WebApkUpdateDataFetcher::OnGotIconMurmur2Hashes( ...@@ -284,8 +284,8 @@ void WebApkUpdateDataFetcher::OnGotIconMurmur2Hashes(
java_is_primary_icon_maskable, java_splash_icon_url, java_is_primary_icon_maskable, java_splash_icon_url,
java_splash_icon_murmur2_hash, java_splash_icon, java_icon_urls, java_splash_icon_murmur2_hash, java_splash_icon, java_icon_urls,
static_cast<int>(info_.display), static_cast<int>(info_.orientation), static_cast<int>(info_.display), static_cast<int>(info_.orientation),
OptionalSkColorToJavaColor(info_.theme_color), ui::OptionalSkColorToJavaColor(info_.theme_color),
OptionalSkColorToJavaColor(info_.background_color), java_share_action, ui::OptionalSkColorToJavaColor(info_.background_color), java_share_action,
java_share_params_title, java_share_params_text, java_share_params_title, java_share_params_text,
java_share_params_is_method_post, java_share_params_is_enctype_multipart, java_share_params_is_method_post, java_share_params_is_enctype_multipart,
java_share_params_file_names, java_share_params_accepts, java_share_params_file_names, java_share_params_accepts,
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "chrome/android/chrome_jni_headers/WebApkUpdateManager_jni.h" #include "chrome/android/chrome_jni_headers/WebApkUpdateManager_jni.h"
#include "chrome/browser/android/color_helpers.h"
#include "chrome/browser/android/shortcut_info.h" #include "chrome/browser/android/shortcut_info.h"
#include "chrome/browser/android/webapk/webapk_install_service.h" #include "chrome/browser/android/webapk/webapk_install_service.h"
#include "chrome/browser/android/webapk/webapk_installer.h" #include "chrome/browser/android/webapk/webapk_installer.h"
...@@ -27,6 +26,7 @@ ...@@ -27,6 +26,7 @@
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "third_party/blink/public/mojom/manifest/manifest.mojom.h" #include "third_party/blink/public/mojom/manifest/manifest.mojom.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "ui/android/color_helpers.h"
#include "ui/gfx/android/java_bitmap.h" #include "ui/gfx/android/java_bitmap.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -94,8 +94,8 @@ static void JNI_WebApkUpdateManager_StoreWebApkUpdateRequestToFile( ...@@ -94,8 +94,8 @@ static void JNI_WebApkUpdateManager_StoreWebApkUpdateRequestToFile(
info.display = static_cast<blink::mojom::DisplayMode>(java_display_mode); info.display = static_cast<blink::mojom::DisplayMode>(java_display_mode);
info.orientation = info.orientation =
static_cast<device::mojom::ScreenOrientationLockType>(java_orientation); static_cast<device::mojom::ScreenOrientationLockType>(java_orientation);
info.theme_color = JavaColorToOptionalSkColor(java_theme_color); info.theme_color = ui::JavaColorToOptionalSkColor(java_theme_color);
info.background_color = JavaColorToOptionalSkColor(java_background_color); info.background_color = ui::JavaColorToOptionalSkColor(java_background_color);
info.best_primary_icon_url = info.best_primary_icon_url =
GURL(ConvertJavaStringToUTF8(env, java_primary_icon_url)); GURL(ConvertJavaStringToUTF8(env, java_primary_icon_url));
info.splash_image_url = info.splash_image_url =
......
...@@ -9,10 +9,10 @@ ...@@ -9,10 +9,10 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/android/color_helpers.h"
#include "chrome/browser/android/shortcut_helper.h" #include "chrome/browser/android/shortcut_helper.h"
#include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui.h"
#include "third_party/blink/public/common/manifest/manifest_util.h" #include "third_party/blink/public/common/manifest/manifest_util.h"
#include "ui/android/color_helpers.h"
#include "ui/gfx/color_utils.h" #include "ui/gfx/color_utils.h"
WebApksHandler::WebApksHandler() WebApksHandler::WebApksHandler()
...@@ -64,9 +64,9 @@ void WebApksHandler::OnWebApkInfoRetrieved(const WebApkInfo& webapk_info) { ...@@ -64,9 +64,9 @@ void WebApksHandler::OnWebApkInfoRetrieved(const WebApkInfo& webapk_info) {
result.SetString("orientation", blink::WebScreenOrientationLockTypeToString( result.SetString("orientation", blink::WebScreenOrientationLockTypeToString(
webapk_info.orientation)); webapk_info.orientation));
result.SetString("themeColor", result.SetString("themeColor",
OptionalSkColorToString(webapk_info.theme_color)); ui::OptionalSkColorToString(webapk_info.theme_color));
result.SetString("backgroundColor", result.SetString("backgroundColor",
OptionalSkColorToString(webapk_info.background_color)); ui::OptionalSkColorToString(webapk_info.background_color));
result.SetDouble("lastUpdateCheckTimeMs", result.SetDouble("lastUpdateCheckTimeMs",
webapk_info.last_update_check_time.ToJsTime()); webapk_info.last_update_check_time.ToJsTime());
result.SetDouble("lastUpdateCompletionTimeMs", result.SetDouble("lastUpdateCompletionTimeMs",
......
...@@ -3806,7 +3806,6 @@ test("unit_tests") { ...@@ -3806,7 +3806,6 @@ test("unit_tests") {
sources += [ sources += [
"../browser/android/bookmarks/partner_bookmarks_shim_unittest.cc", "../browser/android/bookmarks/partner_bookmarks_shim_unittest.cc",
"../browser/android/chrome_backup_agent_unittest.cc", "../browser/android/chrome_backup_agent_unittest.cc",
"../browser/android/color_helpers_unittest.cc",
"../browser/android/compositor/layer/tab_layer_unittest.cc", "../browser/android/compositor/layer/tab_layer_unittest.cc",
"../browser/android/contextualsearch/contextual_search_delegate_unittest.cc", "../browser/android/contextualsearch/contextual_search_delegate_unittest.cc",
"../browser/android/contextualsearch/contextual_search_field_trial_unittest.cc", "../browser/android/contextualsearch/contextual_search_field_trial_unittest.cc",
......
...@@ -13,6 +13,8 @@ component("android") { ...@@ -13,6 +13,8 @@ component("android") {
output_name = "ui_android" output_name = "ui_android"
sources = [ sources = [
"animation_utils.h", "animation_utils.h",
"color_helpers.cc",
"color_helpers.h",
"delegated_frame_host_android.cc", "delegated_frame_host_android.cc",
"delegated_frame_host_android.h", "delegated_frame_host_android.h",
"display_android_manager.cc", "display_android_manager.cc",
...@@ -487,6 +489,7 @@ test("ui_android_unittests") { ...@@ -487,6 +489,7 @@ test("ui_android_unittests") {
# Clipboard unittests are run here for Android as gtests on Android are not # Clipboard unittests are run here for Android as gtests on Android are not
# sharded. On other OSs these are run as part of interactive_ui_tests. # sharded. On other OSs these are run as part of interactive_ui_tests.
"//ui/base/clipboard/clipboard_unittest.cc", "//ui/base/clipboard/clipboard_unittest.cc",
"color_helpers_unittest.cc",
"overscroll_refresh_unittest.cc", "overscroll_refresh_unittest.cc",
"resources/resource_manager_impl_unittest.cc", "resources/resource_manager_impl_unittest.cc",
"run_all_unittests.cc", "run_all_unittests.cc",
......
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/android/color_helpers.h" #include "ui/android/color_helpers.h"
#include "base/check.h" #include "base/check.h"
#include "base/numerics/safe_math.h" #include "base/numerics/safe_math.h"
#include "ui/gfx/color_utils.h" #include "ui/gfx/color_utils.h"
namespace ui {
std::string OptionalSkColorToString(const base::Optional<SkColor>& color) { std::string OptionalSkColorToString(const base::Optional<SkColor>& color) {
if (!color) if (!color)
return std::string(); return std::string();
...@@ -26,3 +28,5 @@ base::Optional<SkColor> JavaColorToOptionalSkColor(int64_t java_color) { ...@@ -26,3 +28,5 @@ base::Optional<SkColor> JavaColorToOptionalSkColor(int64_t java_color) {
DCHECK(base::IsValueInRangeForNumericType<int32_t>(java_color)); DCHECK(base::IsValueInRangeForNumericType<int32_t>(java_color));
return static_cast<SkColor>(java_color); return static_cast<SkColor>(java_color);
} }
} // namespace ui
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_ANDROID_COLOR_HELPERS_H_ #ifndef UI_ANDROID_COLOR_HELPERS_H_
#define CHROME_BROWSER_ANDROID_COLOR_HELPERS_H_ #define UI_ANDROID_COLOR_HELPERS_H_
#include <stdint.h> #include <stdint.h>
...@@ -12,19 +12,27 @@ ...@@ -12,19 +12,27 @@
#include "base/optional.h" #include "base/optional.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/android/ui_android_export.h"
constexpr int64_t kInvalidJavaColor = namespace ui {
UI_ANDROID_EXPORT constexpr int64_t kInvalidJavaColor =
static_cast<int64_t>(std::numeric_limits<int32_t>::max()) + 1; static_cast<int64_t>(std::numeric_limits<int32_t>::max()) + 1;
// Converts |color| to a CSS color string. If |color| is null, the empty string // Converts |color| to a CSS color string. If |color| is null, the empty string
// is returned. // is returned.
std::string OptionalSkColorToString(const base::Optional<SkColor>& color); UI_ANDROID_EXPORT std::string OptionalSkColorToString(
const base::Optional<SkColor>& color);
// Conversions between a Java color and an Optional<SkColor>. Java colors are // Conversions between a Java color and an Optional<SkColor>. Java colors are
// represented as 64-bit signed integers. Valid colors are in the range // represented as 64-bit signed integers. Valid colors are in the range
// [std::numeric_limits<int32_t>::min(), std::numeric_limits<int32_t>::max()]. // [std::numeric_limits<int32_t>::min(), std::numeric_limits<int32_t>::max()].
// while |kInvalidJavaColor| is reserved for representing a null/unset color. // while |kInvalidJavaColor| is reserved for representing a null/unset color.
int64_t OptionalSkColorToJavaColor(const base::Optional<SkColor>& skcolor); UI_ANDROID_EXPORT int64_t
base::Optional<SkColor> JavaColorToOptionalSkColor(int64_t java_color); OptionalSkColorToJavaColor(const base::Optional<SkColor>& skcolor);
UI_ANDROID_EXPORT base::Optional<SkColor> JavaColorToOptionalSkColor(
int64_t java_color);
} // namespace ui
#endif // CHROME_BROWSER_ANDROID_COLOR_HELPERS_H_ #endif // UI_ANDROID_COLOR_HELPERS_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/android/color_helpers.h" #include "ui/android/color_helpers.h"
#include <stdint.h> #include <stdint.h>
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
namespace ui {
namespace { namespace {
// Intentionally avoids reusing the constant defined in color_helpers.h to catch // Intentionally avoids reusing the constant defined in color_helpers.h to catch
...@@ -52,3 +54,5 @@ TEST(ColorHelpersTest, Roundtrip) { ...@@ -52,3 +54,5 @@ TEST(ColorHelpersTest, Roundtrip) {
EXPECT_EQ(SK_ColorTRANSPARENT, EXPECT_EQ(SK_ColorTRANSPARENT,
JavaColorToOptionalSkColor(kAndroidTransparent)); JavaColorToOptionalSkColor(kAndroidTransparent));
} }
} // namespace ui
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