Commit d4e25911 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Implement PDFiumEngine::GetFocusInfo().

Add a method to query the focus state of the PDF plugin. This
information will be used to implement focus changes in the
PdfAccessibilityTree.

This CL is partially based on code borrowed from
https://crrev.com/c/2230804/21.

Bug: 1015350
Change-Id: I3475010b8aec146f258d5f481ec2d60133d1acda
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2351721
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Ankit Kumar 🌪️ <ankk@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#798789}
parent 0b24720b
...@@ -483,6 +483,9 @@ class PDFEngine { ...@@ -483,6 +483,9 @@ class PDFEngine {
// Notify whether the PDF currently has the focus or not. // Notify whether the PDF currently has the focus or not.
virtual void UpdateFocus(bool has_focus) = 0; virtual void UpdateFocus(bool has_focus) = 0;
// Returns the focus info of current focus item.
virtual PP_PrivateAccessibilityFocusInfo GetFocusInfo() = 0;
virtual uint32_t GetLoadedByteSize() = 0; virtual uint32_t GetLoadedByteSize() = 0;
virtual bool ReadLoadedBytes(uint32_t length, void* buffer) = 0; virtual bool ReadLoadedBytes(uint32_t length, void* buffer) = 0;
}; };
......
...@@ -362,6 +362,20 @@ void SetLinkUnderCursor(pp::Instance* instance, ...@@ -362,6 +362,20 @@ void SetLinkUnderCursor(pp::Instance* instance,
pp::PDF::SetLinkUnderCursor(instance, link_under_cursor.c_str()); pp::PDF::SetLinkUnderCursor(instance, link_under_cursor.c_str());
} }
PP_PrivateFocusObjectType GetAnnotationFocusType(
FPDF_ANNOTATION_SUBTYPE annot_type) {
switch (annot_type) {
case FPDF_ANNOT_LINK:
return PP_PrivateFocusObjectType::PP_PRIVATEFOCUSOBJECT_LINK;
case FPDF_ANNOT_HIGHLIGHT:
return PP_PrivateFocusObjectType::PP_PRIVATEFOCUSOBJECT_HIGHLIGHT;
case FPDF_ANNOT_WIDGET:
return PP_PrivateFocusObjectType::PP_PRIVATEFOCUSOBJECT_TEXT_FIELD;
default:
return PP_PrivateFocusObjectType::PP_PRIVATEFOCUSOBJECT_NONE;
}
}
base::string16 GetAttachmentAttribute(FPDF_ATTACHMENT attachment, base::string16 GetAttachmentAttribute(FPDF_ATTACHMENT attachment,
FPDF_BYTESTRING field) { FPDF_BYTESTRING field) {
return CallPDFiumWideStringBufferApi( return CallPDFiumWideStringBufferApi(
...@@ -1008,6 +1022,44 @@ void PDFiumEngine::UpdateFocus(bool has_focus) { ...@@ -1008,6 +1022,44 @@ void PDFiumEngine::UpdateFocus(bool has_focus) {
} }
} }
PP_PrivateAccessibilityFocusInfo PDFiumEngine::GetFocusInfo() {
PP_PrivateAccessibilityFocusInfo focus_info = {
PP_PrivateFocusObjectType::PP_PRIVATEFOCUSOBJECT_NONE, 0, 0};
switch (focus_item_type_) {
case FocusElementType::kNone: {
break;
}
case FocusElementType::kPage: {
int page_index;
FPDF_ANNOTATION focused_annot;
FPDF_BOOL ret = FORM_GetFocusedAnnot(form(), &page_index, &focused_annot);
DCHECK(ret);
if (PageIndexInBounds(page_index) && focused_annot) {
PP_PrivateFocusObjectType type =
GetAnnotationFocusType(FPDFAnnot_GetSubtype(focused_annot));
int annot_index = FPDFPage_GetAnnotIndex(pages_[page_index]->GetPage(),
focused_annot);
if (type != PP_PrivateFocusObjectType::PP_PRIVATEFOCUSOBJECT_NONE &&
annot_index >= 0) {
focus_info.focused_object_type = type;
focus_info.focused_object_page_index = page_index;
focus_info.focused_annotation_index_in_page = annot_index;
}
}
FPDFPage_CloseAnnot(focused_annot);
break;
}
case FocusElementType::kDocument: {
focus_info.focused_object_type =
PP_PrivateFocusObjectType::PP_PRIVATEFOCUSOBJECT_DOCUMENT;
break;
}
}
return focus_info;
}
uint32_t PDFiumEngine::GetLoadedByteSize() { uint32_t PDFiumEngine::GetLoadedByteSize() {
return doc_loader_->GetDocumentSize(); return doc_loader_->GetDocumentSize();
} }
......
...@@ -174,6 +174,7 @@ class PDFiumEngine : public PDFEngine, ...@@ -174,6 +174,7 @@ class PDFiumEngine : public PDFEngine,
void OnDocumentCanceled() override; void OnDocumentCanceled() override;
void KillFormFocus() override; void KillFormFocus() override;
void UpdateFocus(bool has_focus) override; void UpdateFocus(bool has_focus) override;
PP_PrivateAccessibilityFocusInfo GetFocusInfo() override;
uint32_t GetLoadedByteSize() override; uint32_t GetLoadedByteSize() override;
bool ReadLoadedBytes(uint32_t length, void* buffer) override; bool ReadLoadedBytes(uint32_t length, void* buffer) override;
#if defined(PDF_ENABLE_XFA) #if defined(PDF_ENABLE_XFA)
......
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