Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: content/renderer/accessibility/render_accessibility_impl.cc

Issue 2365263003: Implement NSAccessibilityScrollToVisibleAction on Mac (Closed)
Patch Set: Fix endless loop in AXObject::scrollToMakeVisibleWithSubFocus Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/accessibility/render_accessibility_impl.h" 5 #include "content/renderer/accessibility/render_accessibility_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <queue> 10 #include <queue>
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 // Tree-only mode gets used by the automation extension API which requires a 526 // Tree-only mode gets used by the automation extension API which requires a
527 // load complete event to invoke listener callbacks. 527 // load complete event to invoke listener callbacks.
528 ui::AXEvent evt = document.accessibilityObject().isLoaded() 528 ui::AXEvent evt = document.accessibilityObject().isLoaded()
529 ? ui::AX_EVENT_LOAD_COMPLETE : ui::AX_EVENT_LAYOUT_COMPLETE; 529 ? ui::AX_EVENT_LOAD_COMPLETE : ui::AX_EVENT_LAYOUT_COMPLETE;
530 HandleAXEvent(document.accessibilityObject(), evt); 530 HandleAXEvent(document.accessibilityObject(), evt);
531 } 531 }
532 } 532 }
533 533
534 void RenderAccessibilityImpl::OnScrollToMakeVisible( 534 void RenderAccessibilityImpl::OnScrollToMakeVisible(
535 int acc_obj_id, gfx::Rect subfocus) { 535 int acc_obj_id, gfx::Rect subfocus) {
536 if (pdf_tree_source_ && pdf_tree_source_->GetFromId(acc_obj_id)) {
537 ScrollPdf(acc_obj_id);
538 return;
539 }
540
536 const WebDocument& document = GetMainDocument(); 541 const WebDocument& document = GetMainDocument();
537 if (document.isNull()) 542 if (document.isNull())
538 return; 543 return;
539 544
540 WebAXObject obj = document.accessibilityObjectFromID(acc_obj_id); 545 WebAXObject obj = document.accessibilityObjectFromID(acc_obj_id);
541 if (obj.isDetached()) { 546 if (obj.isDetached()) {
542 #ifndef NDEBUG 547 #ifndef NDEBUG
543 LOG(WARNING) << "ScrollToMakeVisible on invalid object id " << acc_obj_id; 548 LOG(WARNING) << "ScrollToMakeVisible on invalid object id " << acc_obj_id;
544 #endif 549 #endif
545 return; 550 return;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 size_t old_count = update->nodes.size(); 718 size_t old_count = update->nodes.size();
714 size_t new_count = pdf_update.nodes.size(); 719 size_t new_count = pdf_update.nodes.size();
715 update->nodes.resize(old_count + new_count); 720 update->nodes.resize(old_count + new_count);
716 for (size_t i = 0; i < new_count; ++i) 721 for (size_t i = 0; i < new_count; ++i)
717 update->nodes[old_count + i] = pdf_update.nodes[i]; 722 update->nodes[old_count + i] = pdf_update.nodes[i];
718 break; 723 break;
719 } 724 }
720 } 725 }
721 } 726 }
722 727
728 void RenderAccessibilityImpl::ScrollPdf(int id_to_make_visible) {
729 // The PDF content doesn't scroll itself, rather it's just one big document
730 // and the embedding page scrolls. So, when we're requested to scroll to make
731 // a particular PDF node visible, get the coordinates of the target PDF node
732 // and then tell the document node to scroll to those coordinates.
733 //
734 // Note that calling scrollToMakeVisibleWithSubFocus() is preferable to
735 // telling the document to scroll to a specific coordinate because it will
736 // first compute whether that rectangle is visible and do nothing if it is.
737 // If it's not visible, it will automatically center it.
738
739 DCHECK(pdf_tree_source_);
740 ui::AXNodeData root_data = pdf_tree_source_->GetRoot()->data();
741 ui::AXNodeData target_data =
742 pdf_tree_source_->GetFromId(id_to_make_visible)->data();
743
744 gfx::RectF bounds = target_data.location;
745 if (root_data.transform)
746 root_data.transform->TransformRect(&bounds);
747
748 const WebDocument& document = GetMainDocument();
749 if (document.isNull())
750 return;
751
752 document.accessibilityObject().scrollToMakeVisibleWithSubFocus(
753 WebRect(bounds.x(), bounds.y(), bounds.width(), bounds.height()));
754 }
755
723 } // namespace content 756 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698