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,
// For testing.
static void SetNoFadeForTesting();
static void SkipActivationCheckForTesting();
static SkColor GetHighlightColorForTesting();
static void UseDefaultColorForTesting();
// Create the layer if needed, and update its bounds to match |bounds_|.
void CreateOrUpdateLayer();
// Create the layer if needed, and set node_bounds_
void CreateOrUpdateLayer(gfx::Rect node_bounds);
// Get rid of the layer and stop animation.
void RemoveLayer();
......@@ -70,15 +70,17 @@ class AccessibilityFocusHighlight : public ui::LayerDelegate,
void OnAnimationStep(base::TimeTicks timestamp) override;
void OnCompositingShuttingDown(ui::Compositor* compositor) override;
// Compute the highlight color based on theme colors and defaults.
SkColor GetHighlightColor();
// The layer, if visible.
std::unique_ptr<ui::Layer> layer_;
// The compositor associated with this layer.
ui::Compositor* compositor_ = nullptr;
// The bounding rectangle of the focused object, in the coordinate system
// of our owner BrowserView's layer.
gfx::Rect bounds_;
// The bounding rectangle of the focused object, relative to the layer.
gfx::Rect node_bounds_;
// Owns this.
BrowserView* browser_view_;
......@@ -92,18 +94,25 @@ class AccessibilityFocusHighlight : public ui::LayerDelegate,
// The current scale factor between DIPs and pixels.
float device_scale_factor_;
// The color used for the highlight.
static SkColor color_;
// The default color used for the highlight.
static SkColor default_color_;
// The amount of time it should take for the highlight to fade in.
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.
static base::TimeDelta fade_out_time_;
// If set, draws the highlight even if the widget is not active.
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.
PrefChangeRegistrar profile_pref_registrar_;
......
......@@ -127,11 +127,12 @@ IN_PROC_BROWSER_TEST_F(AccessibilityFocusHighlightBrowserTest,
MAYBE_DrawsHighlight) {
ui_test_utils::NavigateToURL(
browser(), GURL("data:text/html,"
"<body style='background-color: rgb(204, 255, 255)'>"
"<input id='textfield' style='width: 100%'>"));
"<body style='background-color: rgb(204, 255, 255);'>"
"<div tabindex=0 id='div'>Focusable div</div>"));
AccessibilityFocusHighlight::SetNoFadeForTesting();
AccessibilityFocusHighlight::SkipActivationCheckForTesting();
AccessibilityFocusHighlight::UseDefaultColorForTesting();
browser()->profile()->GetPrefs()->SetBoolean(
prefs::kAccessibilityFocusHighlightEnabled, true);
......@@ -145,16 +146,16 @@ IN_PROC_BROWSER_TEST_F(AccessibilityFocusHighlightBrowserTest,
} while (CountPercentPixelsWithColor(image, SkColorSetRGB(204, 255, 255)) <
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.
SkColor highlight_color =
AccessibilityFocusHighlight::GetHighlightColorForTesting();
ASSERT_LT(CountPercentPixelsWithColor(image, highlight_color), 0.01f);
ASSERT_LT(CountPercentPixelsWithColor(image, highlight_color), 0.05f);
// Focus something.
content::WebContents* web_contents =
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));
// 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