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

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: Created 4 years, 4 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 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 14 matching lines...) Expand all
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:
60 RenderFrameImpl* render_frame_; 82 RenderFrameImpl* render_frame_;
83
84 // An explicit root to use, otherwise it's taken from the WebDocument.
85 blink::WebAXObject explicit_root_;
86
87 // The id of the object with accessibility focus.
88 int accessibility_focus_id_;
David Tseng 2016/09/07 18:59:27 Can you remove this now that you keep around |focu
dmazzoni 2016/09/08 05:26:43 No, because on Android we still use accessibility
89
90 // These are updated when calling |Freeze|.
91 bool frozen_;
92 blink::WebDocument document_;
61 blink::WebAXObject root_; 93 blink::WebAXObject root_;
62 94 blink::WebAXObject focus_;
David Tseng 2016/09/07 18:59:27 Suggestion: can we get a property accesser for thi
dmazzoni 2016/09/08 05:26:43 Sure, good idea
63 int accessibility_focus_id_;
64 }; 95 };
65 96
66 } // namespace content 97 } // namespace content
67 98
68 #endif // CONTENT_RENDERER_ACCESSIBILITY_BLINK_AX_TREE_SOURCE_H_ 99 #endif // CONTENT_RENDERER_ACCESSIBILITY_BLINK_AX_TREE_SOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698