[unseasoned-pdf] Send enable accessibility to PDF plugin
Forward an enable accessibility message to PDF plugin when accessibility is enabled during the PDF session or if accessibility was already enabled during the launch of PDF plugin. PdfViewWebPlugin receives the EnableAccessibility call from PdfAccessibilityTree and starts loading the accessibility information. Bug: 1144444 Change-Id: I25af4bfc8d682c2110f8cac7ebac3a8b6bbe62d9 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3102633 Reviewed-by: Daniel Hosseinian <dhoss@chromium.org> Commit-Queue: Daniel Hosseinian <dhoss@chromium.org> Cr-Commit-Position: refs/heads/main@{#918444}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
74c7f6f770
commit
882600e197
@ -1135,6 +1135,7 @@ PdfAccessibilityTree::PdfAccessibilityTree(
|
||||
: content::RenderFrameObserver(render_frame),
|
||||
action_handler_(action_handler) {
|
||||
DCHECK(action_handler_);
|
||||
MaybeHandleAccessibilityChange();
|
||||
}
|
||||
|
||||
PdfAccessibilityTree::~PdfAccessibilityTree() {
|
||||
@ -1601,6 +1602,11 @@ std::unique_ptr<ui::AXActionTarget> PdfAccessibilityTree::CreateActionTarget(
|
||||
return std::make_unique<PdfAXActionTarget>(target_node, this);
|
||||
}
|
||||
|
||||
void PdfAccessibilityTree::AccessibilityModeChanged(
|
||||
const ui::AXMode& /*mode*/) {
|
||||
MaybeHandleAccessibilityChange();
|
||||
}
|
||||
|
||||
void PdfAccessibilityTree::OnDestruct() {}
|
||||
|
||||
bool PdfAccessibilityTree::ShowContextMenu() {
|
||||
@ -1627,4 +1633,9 @@ PdfAccessibilityTree::GetPdfAnnotationInfoFromAXNode(int32_t ax_node_id) const {
|
||||
return AnnotationInfo(iter->second.page_index, iter->second.annotation_index);
|
||||
}
|
||||
|
||||
void PdfAccessibilityTree::MaybeHandleAccessibilityChange() {
|
||||
if (GetRenderAccessibility())
|
||||
action_handler_->EnableAccessibility();
|
||||
}
|
||||
|
||||
} // namespace pdf
|
||||
|
@ -108,6 +108,7 @@ class PdfAccessibilityTree : public content::PluginAXTreeSource,
|
||||
const ui::AXNode& target_node) override;
|
||||
|
||||
// content::RenderFrameObserver:
|
||||
void AccessibilityModeChanged(const ui::AXMode& /*mode*/) override;
|
||||
void OnDestruct() override;
|
||||
|
||||
bool ShowContextMenu();
|
||||
@ -146,6 +147,10 @@ class PdfAccessibilityTree : public content::PluginAXTreeSource,
|
||||
content::RenderAccessibility* GetRenderAccessibilityIfEnabled();
|
||||
std::unique_ptr<gfx::Transform> MakeTransformFromViewInfo() const;
|
||||
|
||||
// Handles an accessibility change only if there is a valid
|
||||
// `RenderAccessibility` for the frame.
|
||||
void MaybeHandleAccessibilityChange();
|
||||
|
||||
ui::AXTreeData tree_data_;
|
||||
ui::AXTree tree_;
|
||||
|
||||
|
@ -89,6 +89,7 @@ class TestPdfAccessibilityActionHandler
|
||||
~TestPdfAccessibilityActionHandler() override = default;
|
||||
|
||||
// chrome_pdf::PdfAccessibilityActionHandler:
|
||||
void EnableAccessibility() override {}
|
||||
void HandleAccessibilityAction(
|
||||
const chrome_pdf::AccessibilityActionData& action_data) override {
|
||||
received_action_data_ = action_data;
|
||||
|
@ -498,6 +498,10 @@ void PepperPDFHost::SetSelectionBounds(const gfx::PointF& base,
|
||||
instance->SetSelectionBounds(base, extent);
|
||||
}
|
||||
|
||||
void PepperPDFHost::EnableAccessibility() {
|
||||
// `PepperPluginInstanceImpl` notifies the PDF plugin of accessibility change.
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
PP_PdfPageCharacterIndex ToPdfPageCharacterIndex(
|
||||
|
@ -92,6 +92,7 @@ class PepperPDFHost : public ppapi::host::ResourceHost,
|
||||
const gfx::PointF& extent) override;
|
||||
|
||||
// chrome_pdf::PdfAccessibilityActionHandler:
|
||||
void EnableAccessibility() override;
|
||||
void HandleAccessibilityAction(
|
||||
const chrome_pdf::AccessibilityActionData& action_data) override;
|
||||
|
||||
|
@ -13,6 +13,7 @@ class PdfAccessibilityActionHandler {
|
||||
public:
|
||||
virtual ~PdfAccessibilityActionHandler() = default;
|
||||
|
||||
virtual void EnableAccessibility() = 0;
|
||||
virtual void HandleAccessibilityAction(
|
||||
const AccessibilityActionData& action_data) = 0;
|
||||
};
|
||||
|
@ -716,6 +716,10 @@ void PdfViewWebPlugin::UpdateSnapshot(sk_sp<SkImage> snapshot) {
|
||||
InvalidatePluginContainer();
|
||||
}
|
||||
|
||||
void PdfViewWebPlugin::EnableAccessibility() {
|
||||
PdfViewPluginBase::EnableAccessibility();
|
||||
}
|
||||
|
||||
void PdfViewWebPlugin::HandleAccessibilityAction(
|
||||
const AccessibilityActionData& action_data) {
|
||||
PdfViewPluginBase::HandleAccessibilityAction(action_data);
|
||||
@ -785,9 +789,12 @@ void PdfViewWebPlugin::SetAccessibilityPageInfo(
|
||||
|
||||
void PdfViewWebPlugin::SetAccessibilityViewportInfo(
|
||||
const AccessibilityViewportInfo& viewport_info) {
|
||||
if (!pdf_accessibility_data_handler_)
|
||||
return;
|
||||
pdf_accessibility_data_handler_->SetAccessibilityViewportInfo(viewport_info);
|
||||
// The accessibility tree cannot be updated within the scope of
|
||||
// `UpdateGeometry`.
|
||||
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(&PdfViewWebPlugin::OnSetAccessibilityViewportInfo,
|
||||
weak_factory_.GetWeakPtr(), viewport_info));
|
||||
}
|
||||
|
||||
void PdfViewWebPlugin::NotifyFindResultsChanged(int total, bool final_result) {
|
||||
@ -932,6 +939,13 @@ void PdfViewWebPlugin::OnInvokePrintDialog(int32_t /*result*/) {
|
||||
client_->Print(Container()->GetElement());
|
||||
}
|
||||
|
||||
void PdfViewWebPlugin::OnSetAccessibilityViewportInfo(
|
||||
const AccessibilityViewportInfo& viewport_info) {
|
||||
if (!pdf_accessibility_data_handler_)
|
||||
return;
|
||||
pdf_accessibility_data_handler_->SetAccessibilityViewportInfo(viewport_info);
|
||||
}
|
||||
|
||||
pdf::mojom::PdfService* PdfViewWebPlugin::GetPdfService() {
|
||||
return pdf_service_remote_.is_bound() ? pdf_service_remote_.get() : nullptr;
|
||||
}
|
||||
|
@ -234,6 +234,7 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
|
||||
void UpdateSnapshot(sk_sp<SkImage> snapshot) override;
|
||||
|
||||
// PdfAccessibilityActionHandler:
|
||||
void EnableAccessibility() override;
|
||||
void HandleAccessibilityAction(
|
||||
const AccessibilityActionData& action_data) override;
|
||||
|
||||
@ -301,6 +302,11 @@ class PdfViewWebPlugin final : public PdfViewPluginBase,
|
||||
// the plugin are moved off the main thread.
|
||||
void OnInvokePrintDialog(int32_t /*result*/);
|
||||
|
||||
// Callback to set the viewport information in accessibility tree
|
||||
// asynchronously.
|
||||
void OnSetAccessibilityViewportInfo(
|
||||
const AccessibilityViewportInfo& viewport_info);
|
||||
|
||||
// May be null in unit tests.
|
||||
pdf::mojom::PdfService* GetPdfService();
|
||||
|
||||
|
Reference in New Issue
Block a user