OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/accessibility/browser_accessibility.h" | 5 #include "chrome/browser/accessibility/browser_accessibility.h" |
6 | 6 |
7 #include "base/logging.h" | |
8 #include "chrome/browser/accessibility/browser_accessibility_manager.h" | |
9 | |
10 BrowserAccessibility::BrowserAccessibility() { | 7 BrowserAccessibility::BrowserAccessibility() { |
11 } | 8 } |
12 | 9 |
13 BrowserAccessibility::~BrowserAccessibility() { | 10 BrowserAccessibility::~BrowserAccessibility() { |
14 } | 11 } |
15 | |
16 void BrowserAccessibility::Initialize( | |
17 BrowserAccessibilityManager* manager, | |
18 BrowserAccessibility* parent, | |
19 int32 child_id, | |
20 int32 index_in_parent, | |
21 const webkit_glue::WebAccessibility& src) { | |
22 manager_ = manager; | |
23 parent_ = parent; | |
24 child_id_ = child_id; | |
25 index_in_parent_ = index_in_parent; | |
26 | |
27 renderer_id_ = src.id; | |
28 name_ = src.name; | |
29 value_ = src.value; | |
30 attributes_ = src.attributes; | |
31 html_attributes_ = src.html_attributes; | |
32 location_ = src.location; | |
33 role_ = src.role; | |
34 state_ = src.state; | |
35 | |
36 Initialize(); | |
37 } | |
38 | |
39 void BrowserAccessibility::ReleaseTree() { | |
40 // Now we can safely call InactivateTree on our children and remove | |
41 // references to them, so that as much of the tree as possible will be | |
42 // destroyed now - however, nodes that still have references to them | |
43 // might stick around a while until all clients have released them. | |
44 for (std::vector<BrowserAccessibility*>::iterator iter = | |
45 children_.begin(); | |
46 iter != children_.end(); ++iter) { | |
47 (*iter)->ReleaseTree(); | |
48 (*iter)->ReleaseReference(); | |
49 } | |
50 children_.clear(); | |
51 manager_->Remove(child_id_); | |
52 } | |
53 | |
54 void BrowserAccessibility::AddChild(BrowserAccessibility* child) { | |
55 children_.push_back(child); | |
56 } | |
57 | |
58 bool BrowserAccessibility::IsDescendantOf( | |
59 BrowserAccessibility* ancestor) { | |
60 if (this == ancestor) { | |
61 return true; | |
62 } else if (parent_) { | |
63 return parent_->IsDescendantOf(ancestor); | |
64 } | |
65 | |
66 return false; | |
67 } | |
68 | |
69 BrowserAccessibility* BrowserAccessibility::GetParent() { | |
70 return parent_; | |
71 } | |
72 | |
73 uint32 BrowserAccessibility::GetChildCount() { | |
74 return children_.size(); | |
75 } | |
76 | |
77 BrowserAccessibility* BrowserAccessibility::GetChild(uint32 child_index) { | |
78 DCHECK(child_index < children_.size()); | |
79 return children_[child_index]; | |
80 } | |
81 | |
82 BrowserAccessibility* BrowserAccessibility::GetPreviousSibling() { | |
83 if (parent_ && index_in_parent_ > 0) | |
84 return parent_->children_[index_in_parent_ - 1]; | |
85 | |
86 return NULL; | |
87 } | |
88 | |
89 BrowserAccessibility* BrowserAccessibility::GetNextSibling() { | |
90 if (parent_ && | |
91 index_in_parent_ >= 0 && | |
92 index_in_parent_ < static_cast<int>(parent_->children_.size() - 1)) { | |
93 return parent_->children_[index_in_parent_ + 1]; | |
94 } | |
95 | |
96 return NULL; | |
97 } | |
98 | |
99 void BrowserAccessibility::ReplaceChild( | |
100 const BrowserAccessibility* old_acc, BrowserAccessibility* new_acc) { | |
101 DCHECK_EQ(children_[old_acc->index_in_parent_], old_acc); | |
102 | |
103 old_acc = children_[old_acc->index_in_parent_]; | |
104 children_[old_acc->index_in_parent_] = new_acc; | |
105 } | |
OLD | NEW |