Commit 0ec59742 authored by Alice Boxhall's avatar Alice Boxhall Committed by Commit Bot

Making the temporary focus highlight match UX mocks. See bug for screenshots.

AX-Relnotes: N/A
Bug: 1021939
Change-Id: I051ee8ff4deb08977a5319783bae5aced602d54e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2256942
Commit-Queue: Alice Boxhall <aboxhall@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarChris Hall <chrishall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781731}
parent 50c45a82
...@@ -45,10 +45,10 @@ class AccessibilityFocusHighlight : public ui::LayerDelegate, ...@@ -45,10 +45,10 @@ class AccessibilityFocusHighlight : public ui::LayerDelegate,
// For testing. // For testing.
static void SetNoFadeForTesting(); static void SetNoFadeForTesting();
static void SkipActivationCheckForTesting(); static void SkipActivationCheckForTesting();
static SkColor GetHighlightColorForTesting(); static void UseDefaultColorForTesting();
// Create the layer if needed, and update its bounds to match |bounds_|. // Create the layer if needed, and set node_bounds_
void CreateOrUpdateLayer(); void CreateOrUpdateLayer(gfx::Rect node_bounds);
// Get rid of the layer and stop animation. // Get rid of the layer and stop animation.
void RemoveLayer(); void RemoveLayer();
...@@ -70,15 +70,17 @@ class AccessibilityFocusHighlight : public ui::LayerDelegate, ...@@ -70,15 +70,17 @@ class AccessibilityFocusHighlight : public ui::LayerDelegate,
void OnAnimationStep(base::TimeTicks timestamp) override; void OnAnimationStep(base::TimeTicks timestamp) override;
void OnCompositingShuttingDown(ui::Compositor* compositor) override; void OnCompositingShuttingDown(ui::Compositor* compositor) override;
// Compute the highlight color based on theme colors and defaults.
SkColor GetHighlightColor();
// The layer, if visible. // The layer, if visible.
std::unique_ptr<ui::Layer> layer_; std::unique_ptr<ui::Layer> layer_;
// The compositor associated with this layer. // The compositor associated with this layer.
ui::Compositor* compositor_ = nullptr; ui::Compositor* compositor_ = nullptr;
// The bounding rectangle of the focused object, in the coordinate system // The bounding rectangle of the focused object, relative to the layer.
// of our owner BrowserView's layer. gfx::Rect node_bounds_;
gfx::Rect bounds_;
// Owns this. // Owns this.
BrowserView* browser_view_; BrowserView* browser_view_;
...@@ -92,18 +94,25 @@ class AccessibilityFocusHighlight : public ui::LayerDelegate, ...@@ -92,18 +94,25 @@ class AccessibilityFocusHighlight : public ui::LayerDelegate,
// The current scale factor between DIPs and pixels. // The current scale factor between DIPs and pixels.
float device_scale_factor_; float device_scale_factor_;
// The color used for the highlight. // The default color used for the highlight.
static SkColor color_; static SkColor default_color_;
// The amount of time it should take for the highlight to fade in. // The amount of time it should take for the highlight to fade in.
static base::TimeDelta fade_in_time_; static base::TimeDelta fade_in_time_;
// The amount of time the highlight should persist between fading in and
// fading out.
static base::TimeDelta persist_time_;
// The amount of time it should take for the highlight to fade out. // The amount of time it should take for the highlight to fade out.
static base::TimeDelta fade_out_time_; static base::TimeDelta fade_out_time_;
// If set, draws the highlight even if the widget is not active. // If set, draws the highlight even if the widget is not active.
static bool skip_activation_check_for_testing_; static bool skip_activation_check_for_testing_;
// If set, don't check the system theme color.
static bool use_default_color_for_testing_;
// For observing browser preference notifications. // For observing browser preference notifications.
PrefChangeRegistrar profile_pref_registrar_; PrefChangeRegistrar profile_pref_registrar_;
......
...@@ -127,11 +127,12 @@ IN_PROC_BROWSER_TEST_F(AccessibilityFocusHighlightBrowserTest, ...@@ -127,11 +127,12 @@ IN_PROC_BROWSER_TEST_F(AccessibilityFocusHighlightBrowserTest,
MAYBE_DrawsHighlight) { MAYBE_DrawsHighlight) {
ui_test_utils::NavigateToURL( ui_test_utils::NavigateToURL(
browser(), GURL("data:text/html," browser(), GURL("data:text/html,"
"<body style='background-color: rgb(204, 255, 255)'>" "<body style='background-color: rgb(204, 255, 255);'>"
"<input id='textfield' style='width: 100%'>")); "<div tabindex=0 id='div'>Focusable div</div>"));
AccessibilityFocusHighlight::SetNoFadeForTesting(); AccessibilityFocusHighlight::SetNoFadeForTesting();
AccessibilityFocusHighlight::SkipActivationCheckForTesting(); AccessibilityFocusHighlight::SkipActivationCheckForTesting();
AccessibilityFocusHighlight::UseDefaultColorForTesting();
browser()->profile()->GetPrefs()->SetBoolean( browser()->profile()->GetPrefs()->SetBoolean(
prefs::kAccessibilityFocusHighlightEnabled, true); prefs::kAccessibilityFocusHighlightEnabled, true);
...@@ -145,16 +146,16 @@ IN_PROC_BROWSER_TEST_F(AccessibilityFocusHighlightBrowserTest, ...@@ -145,16 +146,16 @@ IN_PROC_BROWSER_TEST_F(AccessibilityFocusHighlightBrowserTest,
} while (CountPercentPixelsWithColor(image, SkColorSetRGB(204, 255, 255)) < } while (CountPercentPixelsWithColor(image, SkColorSetRGB(204, 255, 255)) <
90.0f); 90.0f);
// Initially less than 0.01% of the image should be the focus ring's highlight SkColor highlight_color = AccessibilityFocusHighlight::default_color_;
// Initially less than 0.05% of the image should be the focus ring's highlight
// color. // color.
SkColor highlight_color = ASSERT_LT(CountPercentPixelsWithColor(image, highlight_color), 0.05f);
AccessibilityFocusHighlight::GetHighlightColorForTesting();
ASSERT_LT(CountPercentPixelsWithColor(image, highlight_color), 0.01f);
// Focus something. // Focus something.
content::WebContents* web_contents = content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents(); browser()->tab_strip_model()->GetActiveWebContents();
std::string script("document.getElementById('textfield').focus();"); std::string script("document.getElementById('div').focus();");
EXPECT_TRUE(content::ExecuteScript(web_contents, script)); EXPECT_TRUE(content::ExecuteScript(web_contents, script));
// Now wait until at least 0.1% of the image has the focus ring's highlight // Now wait until at least 0.1% of the image has the focus ring's highlight
......
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