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

Side by Side Diff: content/renderer/accessibility/blink_ax_tree_source.h

Issue 2205083002: Optimize BlinkAXTreeSource by adding freeze/thaw for things like root, focus. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix pdf accessibility Created 4 years, 3 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
« no previous file with comments | « no previous file | content/renderer/accessibility/blink_ax_tree_source.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef CONTENT_RENDERER_ACCESSIBILITY_BLINK_AX_TREE_SOURCE_H_ 5 #ifndef CONTENT_RENDERER_ACCESSIBILITY_BLINK_AX_TREE_SOURCE_H_
6 #define CONTENT_RENDERER_ACCESSIBILITY_BLINK_AX_TREE_SOURCE_H_ 6 #define CONTENT_RENDERER_ACCESSIBILITY_BLINK_AX_TREE_SOURCE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "content/common/ax_content_node_data.h" 10 #include "content/common/ax_content_node_data.h"
11 #include "third_party/WebKit/public/web/WebAXObject.h" 11 #include "third_party/WebKit/public/web/WebAXObject.h"
12 #include "third_party/WebKit/public/web/WebDocument.h"
12 #include "ui/accessibility/ax_node_data.h" 13 #include "ui/accessibility/ax_node_data.h"
13 #include "ui/accessibility/ax_tree_source.h" 14 #include "ui/accessibility/ax_tree_source.h"
14 15
15 namespace content { 16 namespace content {
16 17
18 class BlinkAXTreeSource;
17 class RenderFrameImpl; 19 class RenderFrameImpl;
18 20
21 // Create this on the stack to freeze BlinkAXTreeSource and automatically
22 // un-freeze it when it goes out of scope.
23 class ScopedFreezeBlinkAXTreeSource {
24 public:
25 explicit ScopedFreezeBlinkAXTreeSource(BlinkAXTreeSource* tree_source);
26 ~ScopedFreezeBlinkAXTreeSource();
27
28 private:
29 BlinkAXTreeSource* tree_source_;
30
31 DISALLOW_COPY_AND_ASSIGN(ScopedFreezeBlinkAXTreeSource);
32 };
33
19 class BlinkAXTreeSource 34 class BlinkAXTreeSource
20 : public ui::AXTreeSource<blink::WebAXObject, 35 : public ui::AXTreeSource<blink::WebAXObject,
21 AXContentNodeData, 36 AXContentNodeData,
22 AXContentTreeData> { 37 AXContentTreeData> {
23 public: 38 public:
24 BlinkAXTreeSource(RenderFrameImpl* render_frame); 39 BlinkAXTreeSource(RenderFrameImpl* render_frame);
25 ~BlinkAXTreeSource() override; 40 ~BlinkAXTreeSource() override;
26 41
42 // Freeze caches the document, accessibility root, and current focused
43 // object for fast retrieval during a batch of operations. Use
44 // ScopedFreezeBlinkAXTreeSource on the stack rather than calling
45 // these directly.
46 void Freeze();
47 void Thaw();
48
27 // It may be necessary to call SetRoot if you're using a WebScopedAXContext, 49 // It may be necessary to call SetRoot if you're using a WebScopedAXContext,
28 // because BlinkAXTreeSource can't get the root of the tree from the 50 // because BlinkAXTreeSource can't get the root of the tree from the
29 // WebDocument if accessibility isn't enabled globally. 51 // WebDocument if accessibility isn't enabled globally.
30 void SetRoot(blink::WebAXObject root); 52 void SetRoot(blink::WebAXObject root);
31 53
32 // Walks up the ancestor chain to see if this is a descendant of the root. 54 // Walks up the ancestor chain to see if this is a descendant of the root.
33 bool IsInTree(blink::WebAXObject node) const; 55 bool IsInTree(blink::WebAXObject node) const;
34 56
35 // Set the id of the node with accessibility focus. The node with 57 // Set the id of the node with accessibility focus. The node with
36 // accessibility focus will force loading inline text box children, 58 // accessibility focus will force loading inline text box children,
(...skipping 13 matching lines...) Expand all
50 void SerializeNode(blink::WebAXObject node, 72 void SerializeNode(blink::WebAXObject node,
51 AXContentNodeData* out_data) const override; 73 AXContentNodeData* out_data) const override;
52 bool IsValid(blink::WebAXObject node) const override; 74 bool IsValid(blink::WebAXObject node) const override;
53 bool IsEqual(blink::WebAXObject node1, 75 bool IsEqual(blink::WebAXObject node1,
54 blink::WebAXObject node2) const override; 76 blink::WebAXObject node2) const override;
55 blink::WebAXObject GetNull() const override; 77 blink::WebAXObject GetNull() const override;
56 78
57 blink::WebDocument GetMainDocument() const; 79 blink::WebDocument GetMainDocument() const;
58 80
59 private: 81 private:
82 const blink::WebDocument& document() const {
83 DCHECK(frozen_);
84 return document_;
85 }
86 const blink::WebAXObject& root() const {
87 DCHECK(frozen_);
88 return root_;
89 }
90 const blink::WebAXObject& focus() const {
91 DCHECK(frozen_);
92 return focus_;
93 }
94
95 blink::WebAXObject ComputeRoot() const;
96
60 RenderFrameImpl* render_frame_; 97 RenderFrameImpl* render_frame_;
98
99 // An explicit root to use, otherwise it's taken from the WebDocument.
100 blink::WebAXObject explicit_root_;
101
102 // The id of the object with accessibility focus.
103 int accessibility_focus_id_;
104
105 // These are updated when calling |Freeze|.
106 bool frozen_;
107 blink::WebDocument document_;
61 blink::WebAXObject root_; 108 blink::WebAXObject root_;
62 109 blink::WebAXObject focus_;
63 int accessibility_focus_id_;
64 }; 110 };
65 111
66 } // namespace content 112 } // namespace content
67 113
68 #endif // CONTENT_RENDERER_ACCESSIBILITY_BLINK_AX_TREE_SOURCE_H_ 114 #endif // CONTENT_RENDERER_ACCESSIBILITY_BLINK_AX_TREE_SOURCE_H_
OLDNEW
« no previous file with comments | « no previous file | content/renderer/accessibility/blink_ax_tree_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698