Commit b3d9099d authored by Katie D's avatar Katie D Committed by Commit Bot

Fix accessibility node bounds after pinch zoom.

Also refactors a common helper class into test_utils.

Bug: 840576
Change-Id: Ia6ca2d6af641864ef1a508f6121f9aa1cd523117
Reviewed-on: https://chromium-review.googlesource.com/1106999
Commit-Queue: Katie Dektar <katie@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571606}
parent 3867c4f4
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h" #include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h" #include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h" #include "content/shell/browser/shell.h"
namespace { namespace {
...@@ -79,44 +80,12 @@ class TouchpadPinchBrowserTest : public ContentBrowserTest { ...@@ -79,44 +80,12 @@ class TouchpadPinchBrowserTest : public ContentBrowserTest {
} }
}; };
namespace {
class TestPageScaleObserver : public WebContentsObserver {
public:
explicit TestPageScaleObserver(WebContents* web_contents)
: WebContentsObserver(web_contents) {}
void OnPageScaleFactorChanged(float page_scale_factor) override {
last_scale_ = page_scale_factor;
seen_page_scale_change_ = true;
if (done_callback_)
std::move(done_callback_).Run();
}
float WaitForPageScaleUpdate() {
if (!seen_page_scale_change_) {
base::RunLoop run_loop;
done_callback_ = run_loop.QuitClosure();
run_loop.Run();
}
seen_page_scale_change_ = false;
return last_scale_;
}
private:
base::OnceClosure done_callback_;
bool seen_page_scale_change_ = false;
float last_scale_ = 0.f;
};
} // namespace
// Performing a touchpad pinch gesture should change the page scale. // Performing a touchpad pinch gesture should change the page scale.
IN_PROC_BROWSER_TEST_F(TouchpadPinchBrowserTest, IN_PROC_BROWSER_TEST_F(TouchpadPinchBrowserTest,
TouchpadPinchChangesPageScale) { TouchpadPinchChangesPageScale) {
LoadURL(); LoadURL();
TestPageScaleObserver scale_observer(shell()->web_contents()); content::TestPageScaleObserver scale_observer(shell()->web_contents());
const gfx::Rect contents_rect = shell()->web_contents()->GetContainerBounds(); const gfx::Rect contents_rect = shell()->web_contents()->GetContainerBounds();
const gfx::Point pinch_position(contents_rect.width() / 2, const gfx::Point pinch_position(contents_rect.width() / 2,
...@@ -135,7 +104,7 @@ IN_PROC_BROWSER_TEST_F(TouchpadPinchBrowserTest, WheelListenerAllowingPinch) { ...@@ -135,7 +104,7 @@ IN_PROC_BROWSER_TEST_F(TouchpadPinchBrowserTest, WheelListenerAllowingPinch) {
content::ExecuteScript(shell()->web_contents(), "setListener(false);")); content::ExecuteScript(shell()->web_contents(), "setListener(false);"));
SynchronizeThreads(); SynchronizeThreads();
TestPageScaleObserver scale_observer(shell()->web_contents()); content::TestPageScaleObserver scale_observer(shell()->web_contents());
const gfx::Rect contents_rect = shell()->web_contents()->GetContainerBounds(); const gfx::Rect contents_rect = shell()->web_contents()->GetContainerBounds();
const gfx::Point pinch_position(contents_rect.width() / 2, const gfx::Point pinch_position(contents_rect.width() / 2,
...@@ -165,7 +134,8 @@ IN_PROC_BROWSER_TEST_F(TouchpadPinchBrowserTest, WheelListenerPreventingPinch) { ...@@ -165,7 +134,8 @@ IN_PROC_BROWSER_TEST_F(TouchpadPinchBrowserTest, WheelListenerPreventingPinch) {
// Perform an initial pinch so we can figure out the page scale we're // Perform an initial pinch so we can figure out the page scale we're
// starting with for the test proper. // starting with for the test proper.
TestPageScaleObserver starting_scale_observer(shell()->web_contents()); content::TestPageScaleObserver starting_scale_observer(
shell()->web_contents());
const gfx::Rect contents_rect = shell()->web_contents()->GetContainerBounds(); const gfx::Rect contents_rect = shell()->web_contents()->GetContainerBounds();
const gfx::Point pinch_position(contents_rect.width() / 2, const gfx::Point pinch_position(contents_rect.width() / 2,
contents_rect.height() / 2); contents_rect.height() / 2);
...@@ -199,7 +169,7 @@ IN_PROC_BROWSER_TEST_F(TouchpadPinchBrowserTest, WheelListenerPreventingPinch) { ...@@ -199,7 +169,7 @@ IN_PROC_BROWSER_TEST_F(TouchpadPinchBrowserTest, WheelListenerPreventingPinch) {
"setListener(false);")); "setListener(false);"));
SynchronizeThreads(); SynchronizeThreads();
TestPageScaleObserver scale_observer(shell()->web_contents()); content::TestPageScaleObserver scale_observer(shell()->web_contents());
SimulateGesturePinchSequence(shell()->web_contents(), pinch_position, 2.0, SimulateGesturePinchSequence(shell()->web_contents(), pinch_position, 2.0,
blink::kWebGestureDeviceTouchpad); blink::kWebGestureDeviceTouchpad);
ASSERT_TRUE(content::ExecuteScriptAndExtractBool( ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
......
...@@ -3513,35 +3513,6 @@ IN_PROC_BROWSER_TEST_P(SitePerProcessHitTestBrowserTest, ...@@ -3513,35 +3513,6 @@ IN_PROC_BROWSER_TEST_P(SitePerProcessHitTestBrowserTest,
#endif #endif
} }
namespace {
class TestPageScaleObserver : public WebContentsObserver {
public:
explicit TestPageScaleObserver(WebContents* web_contents)
: WebContentsObserver(web_contents) {}
void OnPageScaleFactorChanged(float page_scale_factor) override {
seen_page_scale_change_ = true;
if (done_callback_)
std::move(done_callback_).Run();
}
void WaitForPageScaleUpdate() {
if (!seen_page_scale_change_) {
base::RunLoop run_loop;
done_callback_ = run_loop.QuitClosure();
run_loop.Run();
}
seen_page_scale_change_ = false;
}
private:
base::OnceClosure done_callback_;
bool seen_page_scale_change_ = false;
};
} // namespace
// Test that performing a touchpad pinch over an OOPIF offers the synthetic // Test that performing a touchpad pinch over an OOPIF offers the synthetic
// wheel events to the child and causes the page scale factor to change for // wheel events to the child and causes the page scale factor to change for
// the main frame (given that the child did not consume the wheel). // the main frame (given that the child did not consume the wheel).
...@@ -3580,7 +3551,7 @@ IN_PROC_BROWSER_TEST_P(SitePerProcessHitTestBrowserTest, ...@@ -3580,7 +3551,7 @@ IN_PROC_BROWSER_TEST_P(SitePerProcessHitTestBrowserTest,
const gfx::Point point_in_child(gfx::ToCeiledInt(100 * scale_factor), const gfx::Point point_in_child(gfx::ToCeiledInt(100 * scale_factor),
gfx::ToCeiledInt(100 * scale_factor)); gfx::ToCeiledInt(100 * scale_factor));
TestPageScaleObserver scale_observer(shell()->web_contents()); content::TestPageScaleObserver scale_observer(shell()->web_contents());
SendTouchpadPinchSequenceWithExpectedTarget( SendTouchpadPinchSequenceWithExpectedTarget(
rwhv_parent, point_in_child, router->touchpad_gesture_target_.target, rwhv_parent, point_in_child, router->touchpad_gesture_target_.target,
rwhv_child); rwhv_child);
......
...@@ -460,6 +460,28 @@ void WebContentsDestroyedWatcher::WebContentsDestroyed() { ...@@ -460,6 +460,28 @@ void WebContentsDestroyedWatcher::WebContentsDestroyed() {
run_loop_.Quit(); run_loop_.Quit();
} }
TestPageScaleObserver::TestPageScaleObserver(WebContents* web_contents)
: WebContentsObserver(web_contents) {}
TestPageScaleObserver::~TestPageScaleObserver() {}
void TestPageScaleObserver::OnPageScaleFactorChanged(float page_scale_factor) {
last_scale_ = page_scale_factor;
seen_page_scale_change_ = true;
if (done_callback_)
std::move(done_callback_).Run();
}
float TestPageScaleObserver::WaitForPageScaleUpdate() {
if (!seen_page_scale_change_) {
base::RunLoop run_loop;
done_callback_ = run_loop.QuitClosure();
run_loop.Run();
}
seen_page_scale_change_ = false;
return last_scale_;
}
GURL EffectiveURLContentBrowserClient::GetEffectiveURL( GURL EffectiveURLContentBrowserClient::GetEffectiveURL(
BrowserContext* browser_context, BrowserContext* browser_context,
const GURL& url) { const GURL& url) {
......
...@@ -332,6 +332,23 @@ class WebContentsDestroyedWatcher : public WebContentsObserver { ...@@ -332,6 +332,23 @@ class WebContentsDestroyedWatcher : public WebContentsObserver {
DISALLOW_COPY_AND_ASSIGN(WebContentsDestroyedWatcher); DISALLOW_COPY_AND_ASSIGN(WebContentsDestroyedWatcher);
}; };
// Watches a web contents for page scales.
class TestPageScaleObserver : public WebContentsObserver {
public:
explicit TestPageScaleObserver(WebContents* web_contents);
~TestPageScaleObserver() override;
float WaitForPageScaleUpdate();
private:
void OnPageScaleFactorChanged(float page_scale_factor) override;
base::OnceClosure done_callback_;
bool seen_page_scale_change_ = false;
float last_scale_ = 0.f;
DISALLOW_COPY_AND_ASSIGN(TestPageScaleObserver);
};
// A custom ContentBrowserClient that simulates GetEffectiveURL() translation // A custom ContentBrowserClient that simulates GetEffectiveURL() translation
// for a single URL. // for a single URL.
class EffectiveURLContentBrowserClient : public ContentBrowserClient { class EffectiveURLContentBrowserClient : public ContentBrowserClient {
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "third_party/blink/public/web/web_view.h" #include "third_party/blink/public/web/web_view.h"
#include "ui/accessibility/ax_enum_util.h" #include "ui/accessibility/ax_enum_util.h"
#include "ui/accessibility/ax_role_properties.h" #include "ui/accessibility/ax_role_properties.h"
#include "ui/gfx/geometry/vector2d_f.h"
using base::ASCIIToUTF16; using base::ASCIIToUTF16;
using base::UTF16ToUTF8; using base::UTF16ToUTF8;
...@@ -469,8 +470,24 @@ void BlinkAXTreeSource::SerializeNode(WebAXObject src, ...@@ -469,8 +470,24 @@ void BlinkAXTreeSource::SerializeNode(WebAXObject src,
src.GetRelativeBounds(offset_container, bounds_in_container, src.GetRelativeBounds(offset_container, bounds_in_container,
container_transform, &clips_children); container_transform, &clips_children);
dst->location = bounds_in_container; dst->location = bounds_in_container;
#if !defined(OS_ANDROID) && !defined(OS_MACOSX)
if (src.Equals(root())) {
WebView* web_view = render_frame_->GetRenderView()->GetWebView();
std::unique_ptr<gfx::Transform> container_transform_gfx =
std::make_unique<gfx::Transform>(container_transform);
container_transform_gfx->Scale(web_view->PageScaleFactor(),
web_view->PageScaleFactor());
container_transform_gfx->Translate(
gfx::Vector2dF(-web_view->VisualViewportOffset().x,
-web_view->VisualViewportOffset().y));
if (!container_transform_gfx->IsIdentity())
dst->transform = std::move(container_transform_gfx);
} else if (!container_transform.isIdentity())
dst->transform = base::WrapUnique(new gfx::Transform(container_transform));
#else
if (!container_transform.isIdentity()) if (!container_transform.isIdentity())
dst->transform = base::WrapUnique(new gfx::Transform(container_transform)); dst->transform = base::WrapUnique(new gfx::Transform(container_transform));
#endif // !defined(OS_ANDROID) && !defined(OS_MACOSX)
if (!offset_container.IsDetached()) if (!offset_container.IsDetached())
dst->offset_container_id = offset_container.AxID(); dst->offset_container_id = offset_container.AxID();
if (clips_children) if (clips_children)
......
...@@ -91,6 +91,7 @@ class CORE_EXPORT AXObjectCache ...@@ -91,6 +91,7 @@ class CORE_EXPORT AXObjectCache
Node* new_focused_node) = 0; Node* new_focused_node) = 0;
virtual void HandleInitialFocus() = 0; virtual void HandleInitialFocus() = 0;
virtual void HandleEditableTextContentChanged(Node*) = 0; virtual void HandleEditableTextContentChanged(Node*) = 0;
virtual void HandleScaleAndLocationChanged(Document*) = 0;
virtual void HandleTextMarkerDataAdded(Node* start, Node* end) = 0; virtual void HandleTextMarkerDataAdded(Node* start, Node* end) = 0;
virtual void HandleTextFormControlChanged(Node*) = 0; virtual void HandleTextFormControlChanged(Node*) = 0;
virtual void HandleValueChanged(Node*) = 0; virtual void HandleValueChanged(Node*) = 0;
......
...@@ -325,8 +325,13 @@ double VisualViewport::ScaleForVisualViewport() const { ...@@ -325,8 +325,13 @@ double VisualViewport::ScaleForVisualViewport() const {
void VisualViewport::SetScaleAndLocation(float scale, void VisualViewport::SetScaleAndLocation(float scale,
const FloatPoint& location) { const FloatPoint& location) {
if (DidSetScaleOrLocation(scale, location)) if (DidSetScaleOrLocation(scale, location)) {
NotifyRootFrameViewport(); NotifyRootFrameViewport();
Document* document = MainFrame()->GetDocument();
if (AXObjectCache* cache = document->ExistingAXObjectCache()) {
cache->HandleScaleAndLocationChanged(document);
}
}
} }
double VisualViewport::VisibleWidthCSSPx() const { double VisualViewport::VisibleWidthCSSPx() const {
......
...@@ -1147,6 +1147,12 @@ void AXObjectCacheImpl::HandleEditableTextContentChanged(Node* node) { ...@@ -1147,6 +1147,12 @@ void AXObjectCacheImpl::HandleEditableTextContentChanged(Node* node) {
PostNotification(obj, kAXValueChanged); PostNotification(obj, kAXValueChanged);
} }
void AXObjectCacheImpl::HandleScaleAndLocationChanged(Document* document) {
if (!document)
return;
PostNotification(document, kAXLocationChanged);
}
void AXObjectCacheImpl::HandleTextFormControlChanged(Node* node) { void AXObjectCacheImpl::HandleTextFormControlChanged(Node* node) {
HandleEditableTextContentChanged(node); HandleEditableTextContentChanged(node);
} }
......
...@@ -141,6 +141,7 @@ class MODULES_EXPORT AXObjectCacheImpl ...@@ -141,6 +141,7 @@ class MODULES_EXPORT AXObjectCacheImpl
void HandleInitialFocus() override; void HandleInitialFocus() override;
void HandleTextFormControlChanged(Node*) override; void HandleTextFormControlChanged(Node*) override;
void HandleEditableTextContentChanged(Node*) override; void HandleEditableTextContentChanged(Node*) override;
void HandleScaleAndLocationChanged(Document*) override;
void HandleTextMarkerDataAdded(Node* start, Node* end) override; void HandleTextMarkerDataAdded(Node* start, Node* end) override;
void HandleValueChanged(Node*) override; void HandleValueChanged(Node*) override;
void HandleUpdateActiveMenuOption(LayoutMenuList*, int option_index) override; void HandleUpdateActiveMenuOption(LayoutMenuList*, int option_index) override;
......
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