0

Add viewport scroll information to PDFAccessibilityTree

This CL adds following information to PDFAccessibilityTree
- ax::mojom::IntAttribute::kScrollXMin
- ax::mojom::IntAttribute::kScrollXMax
- ax::mojom::IntAttribute::kScrollX
- ax::mojom::IntAttribute::kScrollYMin
- ax::mojom::IntAttribute::kScrollYMax
- ax::mojom::IntAttribute::kScrollY

It enables partial implementation of IScrollProvider, following methods
will work with this change
- IScrollProvider::get_HorizontallyScrollable
- IScrollProvider::get_VerticallyScrollable
- IScrollProvider::get_HorizontalScrollPercent
- IScrollProvider::get_VerticalScrollPercent

This information is required by Screen readers to announce the current
scroll position and extent of scroll to the user.

Tests: The best way to test this change will be through browser tests.
However, it requires the second part of the change, detailed in the
associated bug, to be completed.

Bug: 1034521
Change-Id: I11067b2af4d5bd73e62d89c8ce86fb00b5f3f7ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1969412
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Kevin Babbitt <kbabbitt@microsoft.com>
Commit-Queue: Virender Singh <virens@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#727858}
This commit is contained in:
Virender Singh
2019-12-31 08:36:47 +00:00
committed by Commit Bot
parent 6f92ba5be3
commit a351b484e7
10 changed files with 54 additions and 7 deletions

@ -362,6 +362,16 @@ void PdfAccessibilityTree::SetAccessibilityViewportInfo(
if (render_accessibility && tree_.size() > 1) {
ui::AXNode* root = tree_.root();
ui::AXNodeData root_data = root->data();
root_data.AddIntAttribute(ax::mojom::IntAttribute::kScrollXMin, 0);
root_data.AddIntAttribute(ax::mojom::IntAttribute::kScrollXMax,
viewport_info.total_scrollable_size.width);
root_data.AddIntAttribute(ax::mojom::IntAttribute::kScrollX,
viewport_info.current_scroll_position.x);
root_data.AddIntAttribute(ax::mojom::IntAttribute::kScrollYMin, 0);
root_data.AddIntAttribute(ax::mojom::IntAttribute::kScrollYMax,
viewport_info.total_scrollable_size.height);
root_data.AddIntAttribute(ax::mojom::IntAttribute::kScrollY,
viewport_info.current_scroll_position.y);
root_data.relative_bounds.transform =
base::WrapUnique(MakeTransformFromViewInfo());
root->SetData(root_data);

@ -1009,6 +1009,10 @@ void OutOfProcessInstance::SendAccessibilityViewportInfo() {
viewport_info.zoom = zoom_;
viewport_info.scale = device_scale_;
viewport_info.total_scrollable_size = {GetTotalScrollableWidth(),
GetTotalScrollableHeight()};
viewport_info.current_scroll_position = {GetHorizontalScrollPosition(),
GetVerticalScrollPosition()};
engine_->GetSelection(&viewport_info.selection_start_page_index,
&viewport_info.selection_start_char_index,
@ -1291,6 +1295,25 @@ int OutOfProcessInstance::GetDocumentPixelHeight() const {
ceil(document_size_.height() * zoom_ * device_scale_));
}
int OutOfProcessInstance::GetTotalScrollableWidth() const {
return std::max(GetDocumentPixelWidth() - plugin_size_.width(), 0);
}
int OutOfProcessInstance::GetTotalScrollableHeight() const {
return std::max(static_cast<int>(GetDocumentPixelHeight() +
GetToolbarHeightInScreenCoords() -
plugin_size_.height()),
0);
}
int OutOfProcessInstance::GetHorizontalScrollPosition() const {
return static_cast<int>(scroll_offset_.x() * device_scale_);
}
int OutOfProcessInstance::GetVerticalScrollPosition() const {
return static_cast<int>(scroll_offset_.y() * device_scale_);
}
void OutOfProcessInstance::FillRect(const pp::Rect& rect, uint32_t color) {
DCHECK(!image_data_.is_null() || rect.IsEmpty());
uint32_t* buffer_start = static_cast<uint32_t*>(image_data_.data());
@ -1982,7 +2005,7 @@ void OutOfProcessInstance::IsEditModeChanged(bool is_edit_mode) {
pp::PDF::SetPluginCanSave(this, ShouldSaveEdits());
}
float OutOfProcessInstance::GetToolbarHeightInScreenCoords() {
float OutOfProcessInstance::GetToolbarHeightInScreenCoords() const {
return top_toolbar_height_in_viewport_coords_ * device_scale_;
}

@ -149,7 +149,7 @@ class OutOfProcessInstance : public pp::Instance,
void IsSelectingChanged(bool is_selecting) override;
void SelectionChanged(const pp::Rect& left, const pp::Rect& right) override;
void IsEditModeChanged(bool is_edit_mode) override;
float GetToolbarHeightInScreenCoords() override;
float GetToolbarHeightInScreenCoords() const override;
// PreviewModeClient::Client implementation.
void PreviewDocumentLoadComplete() override;
@ -179,6 +179,14 @@ class OutOfProcessInstance : public pp::Instance,
int GetDocumentPixelWidth() const;
int GetDocumentPixelHeight() const;
// Computes total scrollable Width and Height of the document.
int GetTotalScrollableWidth() const;
int GetTotalScrollableHeight() const;
// Computes current horizontal and scroll position of the document.
int GetHorizontalScrollPosition() const;
int GetVerticalScrollPosition() const;
// Draws a rectangle with the specified dimensions and color in our buffer.
void FillRect(const pp::Rect& rect, uint32_t color);

@ -281,7 +281,7 @@ class PDFEngine {
// Gets the height of the top toolbar in screen coordinates. This is
// independent of whether it is hidden or not at the moment.
virtual float GetToolbarHeightInScreenCoords() = 0;
virtual float GetToolbarHeightInScreenCoords() const = 0;
};
struct AccessibilityLinkInfo {

@ -150,7 +150,7 @@ bool PreviewModeClient::IsPrintPreview() {
return false;
}
float PreviewModeClient::GetToolbarHeightInScreenCoords() {
float PreviewModeClient::GetToolbarHeightInScreenCoords() const {
return 0.0f;
}

@ -67,7 +67,7 @@ class PreviewModeClient : public PDFEngine::Client {
void DocumentHasUnsupportedFeature(const std::string& feature) override;
void FormTextFieldFocusChange(bool in_focus) override;
bool IsPrintPreview() override;
float GetToolbarHeightInScreenCoords() override;
float GetToolbarHeightInScreenCoords() const override;
uint32_t GetBackgroundColor() override;
private:

@ -56,7 +56,7 @@ uint32_t TestClient::GetBackgroundColor() {
return 0;
}
float TestClient::GetToolbarHeightInScreenCoords() {
float TestClient::GetToolbarHeightInScreenCoords() const {
return 0;
}

@ -37,7 +37,7 @@ class TestClient : public PDFEngine::Client {
pp::Instance* GetPluginInstance() override;
bool IsPrintPreview() override;
uint32_t GetBackgroundColor() override;
float GetToolbarHeightInScreenCoords() override;
float GetToolbarHeightInScreenCoords() const override;
private:
// Not owned. Expected to dangle briefly, as the engine usually is destroyed

@ -36,6 +36,10 @@ struct PP_PrivateFindResult {
struct PP_PrivateAccessibilityViewportInfo {
double zoom;
double scale;
// |total_scrollable_size| and |current_scroll_position| are relative
// to plugin embed and in screen coordinates.
struct PP_Size total_scrollable_size;
struct PP_Point current_scroll_position;
struct PP_Point scroll;
struct PP_Point offset;
uint32_t selection_start_page_index;

@ -268,6 +268,8 @@ IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(PP_PrivateAccessibilityViewportInfo)
IPC_STRUCT_TRAITS_MEMBER(zoom)
IPC_STRUCT_TRAITS_MEMBER(scale)
IPC_STRUCT_TRAITS_MEMBER(total_scrollable_size)
IPC_STRUCT_TRAITS_MEMBER(current_scroll_position)
IPC_STRUCT_TRAITS_MEMBER(scroll)
IPC_STRUCT_TRAITS_MEMBER(offset)
IPC_STRUCT_TRAITS_MEMBER(selection_start_page_index)