Commit ddfa7205 authored by Daichi Hirono's avatar Daichi Hirono Committed by Commit Bot

Load accessibility style from prefs.

Previously ArcAccessibilityHelperBridges has used
GetCaptionStyleFromPrefs. But it started adding "important!" token to
override existing style, which Android side does not recognize.

The CL stop using GetCaptionStyleFromPrefs and loads caption style
directly from prefs.

BUG=b:141660231
TEST=GetCaptionStyleFromPrefsTests.*

Change-Id: Iee017eb3c5afd28205067df842f112cc553406a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1837437Reviewed-by: default avatarSara Kato <sarakato@chromium.org>
Commit-Queue: Daichi Hirono <hirono@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705008}
parent db72457e
...@@ -127,15 +127,6 @@ class ArcAccessibilityHelperBridgeFactory ...@@ -127,15 +127,6 @@ class ArcAccessibilityHelperBridgeFactory
~ArcAccessibilityHelperBridgeFactory() override = default; ~ArcAccessibilityHelperBridgeFactory() override = default;
}; };
} // namespace
// static
ArcAccessibilityHelperBridge*
ArcAccessibilityHelperBridge::GetForBrowserContext(
content::BrowserContext* context) {
return ArcAccessibilityHelperBridgeFactory::GetForBrowserContext(context);
}
static constexpr const char* kTextShadowRaised = static constexpr const char* kTextShadowRaised =
"-2px -2px 4px rgba(0, 0, 0, 0.5)"; "-2px -2px 4px rgba(0, 0, 0, 0.5)";
static constexpr const char* kTextShadowDepressed = static constexpr const char* kTextShadowDepressed =
...@@ -146,11 +137,63 @@ static constexpr const char* kTextShadowUniform = ...@@ -146,11 +137,63 @@ static constexpr const char* kTextShadowUniform =
static constexpr const char* kTextShadowDropShadow = static constexpr const char* kTextShadowDropShadow =
"0px 0px 2px rgba(0, 0, 0, 0.5), 2px 2px 2px black"; "0px 0px 2px rgba(0, 0, 0, 0.5), 2px 2px 2px black";
std::string GetARGBFromPrefs(PrefService* prefs,
const char* color_pref_name,
const char* opacity_pref_name) {
const std::string color = prefs->GetString(color_pref_name);
if (color.empty()) {
return "";
}
const int opacity = prefs->GetInteger(opacity_pref_name);
return base::StringPrintf("rgba(%s,%s)", color.c_str(),
base::NumberToString(opacity / 100.0).c_str());
}
} // namespace
arc::mojom::CaptionStylePtr GetCaptionStyleFromPrefs(PrefService* prefs) {
DCHECK(prefs);
arc::mojom::CaptionStylePtr style = arc::mojom::CaptionStyle::New();
style->text_size = prefs->GetString(prefs::kAccessibilityCaptionsTextSize);
style->text_color =
GetARGBFromPrefs(prefs, prefs::kAccessibilityCaptionsTextColor,
prefs::kAccessibilityCaptionsTextOpacity);
style->background_color =
GetARGBFromPrefs(prefs, prefs::kAccessibilityCaptionsBackgroundColor,
prefs::kAccessibilityCaptionsBackgroundOpacity);
style->user_locale = prefs->GetString(language::prefs::kApplicationLocale);
const std::string test_shadow =
prefs->GetString(prefs::kAccessibilityCaptionsTextShadow);
if (test_shadow == kTextShadowRaised) {
style->text_shadow_type = arc::mojom::CaptionTextShadowType::RAISED;
} else if (test_shadow == kTextShadowDepressed) {
style->text_shadow_type = arc::mojom::CaptionTextShadowType::DEPRESSED;
} else if (test_shadow == kTextShadowUniform) {
style->text_shadow_type = arc::mojom::CaptionTextShadowType::UNIFORM;
} else if (test_shadow == kTextShadowDropShadow) {
style->text_shadow_type = arc::mojom::CaptionTextShadowType::DROP_SHADOW;
} else {
style->text_shadow_type = arc::mojom::CaptionTextShadowType::NONE;
}
return style;
}
// static
ArcAccessibilityHelperBridge*
ArcAccessibilityHelperBridge::GetForBrowserContext(
content::BrowserContext* context) {
return ArcAccessibilityHelperBridgeFactory::GetForBrowserContext(context);
}
void ArcAccessibilityHelperBridge::UpdateCaptionSettings() const { void ArcAccessibilityHelperBridge::UpdateCaptionSettings() const {
base::Optional<ui::CaptionStyle> prefs_caption_style = arc::mojom::CaptionStylePtr caption_style =
pref_names_util::GetCaptionStyleFromPrefs(profile_->GetPrefs()); GetCaptionStyleFromPrefs(profile_->GetPrefs());
if (!prefs_caption_style) if (!caption_style)
return; return;
auto* instance = ARC_GET_INSTANCE_FOR_METHOD( auto* instance = ARC_GET_INSTANCE_FOR_METHOD(
...@@ -159,29 +202,6 @@ void ArcAccessibilityHelperBridge::UpdateCaptionSettings() const { ...@@ -159,29 +202,6 @@ void ArcAccessibilityHelperBridge::UpdateCaptionSettings() const {
if (!instance) if (!instance)
return; return;
arc::mojom::CaptionStylePtr caption_style = arc::mojom::CaptionStyle::New();
caption_style->text_size = prefs_caption_style->text_size.c_str();
caption_style->background_color = prefs_caption_style->background_color;
caption_style->text_color = prefs_caption_style->text_color;
caption_style->user_locale =
profile_->GetPrefs()->GetString(language::prefs::kApplicationLocale);
// Convert the text shadow CSS string to a mojom::CaptionTextShadowType enum.
if (prefs_caption_style->text_shadow == kTextShadowRaised) {
caption_style->text_shadow_type = arc::mojom::CaptionTextShadowType::RAISED;
} else if (prefs_caption_style->text_shadow == kTextShadowDepressed) {
caption_style->text_shadow_type =
arc::mojom::CaptionTextShadowType::DEPRESSED;
} else if (prefs_caption_style->text_shadow == kTextShadowUniform) {
caption_style->text_shadow_type =
arc::mojom::CaptionTextShadowType::UNIFORM;
} else if (prefs_caption_style->text_shadow == kTextShadowDropShadow) {
caption_style->text_shadow_type =
arc::mojom::CaptionTextShadowType::DROP_SHADOW;
} else {
caption_style->text_shadow_type = arc::mojom::CaptionTextShadowType::NONE;
}
instance->SetCaptionStyle(std::move(caption_style)); instance->SetCaptionStyle(std::move(caption_style));
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "ui/aura/window_tracker.h" #include "ui/aura/window_tracker.h"
#include "ui/wm/public/activation_change_observer.h" #include "ui/wm/public/activation_change_observer.h"
class PrefService;
class Profile; class Profile;
namespace content { namespace content {
...@@ -37,6 +38,8 @@ namespace arc { ...@@ -37,6 +38,8 @@ namespace arc {
class AXTreeSourceArc; class AXTreeSourceArc;
class ArcBridgeService; class ArcBridgeService;
arc::mojom::CaptionStylePtr GetCaptionStyleFromPrefs(PrefService* prefs);
// ArcAccessibilityHelperBridge is an instance to receive converted Android // ArcAccessibilityHelperBridge is an instance to receive converted Android
// accessibility events and info via mojo interface and dispatch them to chrome // accessibility events and info via mojo interface and dispatch them to chrome
// os components. // os components.
......
...@@ -18,7 +18,9 @@ ...@@ -18,7 +18,9 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/common/extensions/api/accessibility_private.h" #include "chrome/common/extensions/api/accessibility_private.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "chrome/test/views/chrome_views_test_base.h" #include "chrome/test/views/chrome_views_test_base.h"
#include "chromeos/constants/chromeos_switches.h" #include "chromeos/constants/chromeos_switches.h"
...@@ -26,6 +28,9 @@ ...@@ -26,6 +28,9 @@
#include "components/arc/session/arc_bridge_service.h" #include "components/arc/session/arc_bridge_service.h"
#include "components/exo/shell_surface.h" #include "components/exo/shell_surface.h"
#include "components/exo/shell_surface_util.h" #include "components/exo/shell_surface_util.h"
#include "components/language/core/browser/pref_names.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "extensions/browser/test_event_router.h" #include "extensions/browser/test_event_router.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
...@@ -546,4 +551,65 @@ TEST_F(ArcAccessibilityHelperBridgeTest, TextSelectionChangedFocusContentView) { ...@@ -546,4 +551,65 @@ TEST_F(ArcAccessibilityHelperBridgeTest, TextSelectionChangedFocusContentView) {
arc_notification_surface_manager_->RemoveSurface(surface.get()); arc_notification_surface_manager_->RemoveSurface(surface.get());
} }
class GetCaptionStyleFromPrefsTests : public ::testing::Test {
public:
void SetUp() override {
prefs_.registry()->RegisterStringPref(prefs::kAccessibilityCaptionsTextSize,
"");
prefs_.registry()->RegisterStringPref(
prefs::kAccessibilityCaptionsTextColor, "");
prefs_.registry()->RegisterIntegerPref(
prefs::kAccessibilityCaptionsTextOpacity, 100);
prefs_.registry()->RegisterStringPref(
prefs::kAccessibilityCaptionsBackgroundColor, "");
prefs_.registry()->RegisterIntegerPref(
prefs::kAccessibilityCaptionsBackgroundOpacity, 100);
prefs_.registry()->RegisterStringPref(
prefs::kAccessibilityCaptionsTextShadow, "");
prefs_.registry()->RegisterStringPref(language::prefs::kApplicationLocale,
"");
}
protected:
TestingPrefServiceSimple prefs_;
};
TEST_F(GetCaptionStyleFromPrefsTests, ValidValues) {
prefs_.SetUserPref(prefs::kAccessibilityCaptionsTextSize,
std::make_unique<base::Value>("200%"));
prefs_.SetUserPref(prefs::kAccessibilityCaptionsTextColor,
std::make_unique<base::Value>("10,20,30"));
prefs_.SetUserPref(prefs::kAccessibilityCaptionsTextOpacity,
std::make_unique<base::Value>(90));
prefs_.SetUserPref(prefs::kAccessibilityCaptionsBackgroundColor,
std::make_unique<base::Value>("40,50,60"));
prefs_.SetUserPref(prefs::kAccessibilityCaptionsBackgroundOpacity,
std::make_unique<base::Value>(80));
prefs_.SetUserPref(
prefs::kAccessibilityCaptionsTextShadow,
std::make_unique<base::Value>("-2px -2px 4px rgba(0, 0, 0, 0.5)"));
prefs_.SetUserPref(language::prefs::kApplicationLocale,
std::make_unique<base::Value>("my_locale"));
auto style = GetCaptionStyleFromPrefs(&prefs_);
ASSERT_TRUE(style);
EXPECT_EQ("200%", style->text_size);
EXPECT_EQ("rgba(10,20,30,0.9)", style->text_color);
EXPECT_EQ("rgba(40,50,60,0.8)", style->background_color);
EXPECT_EQ("my_locale", style->user_locale);
EXPECT_EQ(arc::mojom::CaptionTextShadowType::RAISED, style->text_shadow_type);
}
TEST_F(GetCaptionStyleFromPrefsTests, EmptyValues) {
auto style = GetCaptionStyleFromPrefs(&prefs_);
ASSERT_TRUE(style);
EXPECT_EQ("", style->text_size);
EXPECT_EQ("", style->text_color);
EXPECT_EQ("", style->background_color);
EXPECT_EQ("", style->user_locale);
EXPECT_EQ(arc::mojom::CaptionTextShadowType::NONE, style->text_shadow_type);
}
} // namespace arc } // namespace arc
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