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/browser_accessibility_manager_win.h" | 5 #include "chrome/browser/browser_accessibility_manager_win.h" |
6 | 6 |
7 #include "chrome/browser/browser_accessibility_win.h" | 7 #include "chrome/browser/browser_accessibility_win.h" |
8 #include "chrome/browser/renderer_host/render_process_host.h" | 8 #include "chrome/browser/renderer_host/render_process_host.h" |
9 #include "chrome/browser/renderer_host/render_view_host.h" | 9 #include "chrome/browser/renderer_host/render_view_host.h" |
10 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 OnAccessibilityObjectFocusChange(param.acc_obj); | 119 OnAccessibilityObjectFocusChange(param.acc_obj); |
120 break; | 120 break; |
121 case ViewHostMsg_AccessibilityNotification_Params:: | 121 case ViewHostMsg_AccessibilityNotification_Params:: |
122 NOTIFICATION_TYPE_LOAD_COMPLETE: | 122 NOTIFICATION_TYPE_LOAD_COMPLETE: |
123 OnAccessibilityObjectLoadComplete(param.acc_obj); | 123 OnAccessibilityObjectLoadComplete(param.acc_obj); |
124 break; | 124 break; |
125 case ViewHostMsg_AccessibilityNotification_Params:: | 125 case ViewHostMsg_AccessibilityNotification_Params:: |
126 NOTIFICATION_TYPE_VALUE_CHANGED: | 126 NOTIFICATION_TYPE_VALUE_CHANGED: |
127 OnAccessibilityObjectValueChange(param.acc_obj); | 127 OnAccessibilityObjectValueChange(param.acc_obj); |
128 break; | 128 break; |
| 129 case ViewHostMsg_AccessibilityNotification_Params:: |
| 130 NOTIFICATION_TYPE_SELECTED_TEXT_CHANGED: |
| 131 OnAccessibilityObjectTextChange(param.acc_obj); |
| 132 break; |
129 default: | 133 default: |
130 DCHECK(0); | 134 DCHECK(0); |
131 break; | 135 break; |
132 } | 136 } |
133 } | 137 } |
134 } | 138 } |
135 | 139 |
| 140 bool BrowserAccessibilityManager::CanModifyTreeInPlace( |
| 141 BrowserAccessibility* current_root, |
| 142 const webkit_glue::WebAccessibility& new_root) { |
| 143 if (current_root->renderer_id() != new_root.id) |
| 144 return false; |
| 145 if (current_root->GetChildCount() != new_root.children.size()) |
| 146 return false; |
| 147 for (unsigned int i = 0; i < current_root->GetChildCount(); i++) { |
| 148 if (!CanModifyTreeInPlace(current_root->GetChild(i), |
| 149 new_root.children[i])) { |
| 150 return false; |
| 151 } |
| 152 } |
| 153 return true; |
| 154 } |
| 155 |
| 156 void BrowserAccessibilityManager::ModifyTreeInPlace( |
| 157 BrowserAccessibility* current_root, |
| 158 const webkit_glue::WebAccessibility& new_root) { |
| 159 DCHECK_EQ(current_root->renderer_id(), new_root.id); |
| 160 DCHECK_EQ(current_root->GetChildCount(), new_root.children.size()); |
| 161 for (unsigned int i = 0; i < current_root->GetChildCount(); i++) |
| 162 ModifyTreeInPlace(current_root->GetChild(i), new_root.children[i]); |
| 163 current_root->Initialize( |
| 164 this, |
| 165 current_root->GetParent(), |
| 166 current_root->child_id(), |
| 167 current_root->index_in_parent(), |
| 168 new_root); |
| 169 } |
| 170 |
136 BrowserAccessibility* BrowserAccessibilityManager::UpdateTree( | 171 BrowserAccessibility* BrowserAccessibilityManager::UpdateTree( |
137 const webkit_glue::WebAccessibility& acc_obj) { | 172 const webkit_glue::WebAccessibility& acc_obj) { |
138 base::hash_map<int, LONG>::iterator iter = | 173 base::hash_map<int, LONG>::iterator iter = |
139 renderer_id_to_child_id_map_.find(acc_obj.id); | 174 renderer_id_to_child_id_map_.find(acc_obj.id); |
140 if (iter == renderer_id_to_child_id_map_.end()) | 175 if (iter == renderer_id_to_child_id_map_.end()) |
141 return NULL; | 176 return NULL; |
142 | 177 |
143 LONG child_id = iter->second; | 178 LONG child_id = iter->second; |
144 BrowserAccessibility* old_browser_acc = GetFromChildID(child_id); | 179 BrowserAccessibility* old_browser_acc = GetFromChildID(child_id); |
145 if (!old_browser_acc) | 180 if (!old_browser_acc) |
146 return NULL; | 181 return NULL; |
147 | 182 |
148 if (old_browser_acc->GetChildCount() == 0 && acc_obj.children.size() == 0) { | 183 if (CanModifyTreeInPlace(old_browser_acc, acc_obj)) { |
149 // Reinitialize the BrowserAccessibility if there are no children to update. | 184 ModifyTreeInPlace(old_browser_acc, acc_obj); |
150 old_browser_acc->Initialize( | 185 return old_browser_acc; |
151 this, | 186 } |
152 old_browser_acc->GetParent(), | |
153 child_id, | |
154 old_browser_acc->index_in_parent(), | |
155 acc_obj); | |
156 | 187 |
157 return old_browser_acc; | 188 BrowserAccessibility* new_browser_acc = CreateAccessibilityTree( |
| 189 old_browser_acc->GetParent(), |
| 190 child_id, |
| 191 acc_obj, |
| 192 old_browser_acc->index_in_parent()); |
| 193 |
| 194 if (old_browser_acc->GetParent()) { |
| 195 old_browser_acc->GetParent()->ReplaceChild( |
| 196 old_browser_acc, |
| 197 new_browser_acc); |
158 } else { | 198 } else { |
159 BrowserAccessibility* new_browser_acc = CreateAccessibilityTree( | 199 DCHECK_EQ(old_browser_acc, root_); |
160 old_browser_acc->GetParent(), | 200 root_ = new_browser_acc; |
161 child_id, | 201 } |
162 acc_obj, | 202 old_browser_acc->InactivateTree(); |
163 old_browser_acc->index_in_parent()); | 203 old_browser_acc->Release(); |
| 204 child_id_map_[child_id] = new_browser_acc; |
164 | 205 |
165 if (old_browser_acc->GetParent()) { | 206 return new_browser_acc; |
166 old_browser_acc->GetParent()->ReplaceChild( | |
167 old_browser_acc, | |
168 new_browser_acc); | |
169 } else { | |
170 DCHECK_EQ(old_browser_acc, root_); | |
171 root_ = new_browser_acc; | |
172 } | |
173 old_browser_acc->InactivateTree(); | |
174 old_browser_acc->Release(); | |
175 child_id_map_[child_id] = new_browser_acc; | |
176 | |
177 return new_browser_acc; | |
178 } | |
179 } | 207 } |
180 | 208 |
181 void BrowserAccessibilityManager::OnAccessibilityObjectStateChange( | 209 void BrowserAccessibilityManager::OnAccessibilityObjectStateChange( |
182 const webkit_glue::WebAccessibility& acc_obj) { | 210 const webkit_glue::WebAccessibility& acc_obj) { |
183 BrowserAccessibility* new_browser_acc = UpdateTree(acc_obj); | 211 BrowserAccessibility* new_browser_acc = UpdateTree(acc_obj); |
184 if (!new_browser_acc) | 212 if (!new_browser_acc) |
185 return; | 213 return; |
186 | 214 |
187 LONG child_id = new_browser_acc->child_id(); | 215 LONG child_id = new_browser_acc->child_id(); |
188 NotifyWinEvent( | 216 NotifyWinEvent( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 const webkit_glue::WebAccessibility& acc_obj) { | 264 const webkit_glue::WebAccessibility& acc_obj) { |
237 BrowserAccessibility* new_browser_acc = UpdateTree(acc_obj); | 265 BrowserAccessibility* new_browser_acc = UpdateTree(acc_obj); |
238 if (!new_browser_acc) | 266 if (!new_browser_acc) |
239 return; | 267 return; |
240 | 268 |
241 LONG child_id = new_browser_acc->child_id(); | 269 LONG child_id = new_browser_acc->child_id(); |
242 NotifyWinEvent( | 270 NotifyWinEvent( |
243 EVENT_OBJECT_VALUECHANGE, parent_hwnd_, OBJID_CLIENT, child_id); | 271 EVENT_OBJECT_VALUECHANGE, parent_hwnd_, OBJID_CLIENT, child_id); |
244 } | 272 } |
245 | 273 |
| 274 void BrowserAccessibilityManager::OnAccessibilityObjectTextChange( |
| 275 const webkit_glue::WebAccessibility& acc_obj) { |
| 276 BrowserAccessibility* new_browser_acc = UpdateTree(acc_obj); |
| 277 if (!new_browser_acc) |
| 278 return; |
| 279 |
| 280 LONG child_id = new_browser_acc->child_id(); |
| 281 NotifyWinEvent( |
| 282 IA2_EVENT_TEXT_CARET_MOVED, parent_hwnd_, OBJID_CLIENT, child_id); |
| 283 } |
| 284 |
246 LONG BrowserAccessibilityManager::GetNextChildID() { | 285 LONG BrowserAccessibilityManager::GetNextChildID() { |
247 // Get the next child ID, and wrap around when we get near the end | 286 // Get the next child ID, and wrap around when we get near the end |
248 // of a 32-bit integer range. It's okay to wrap around; we just want | 287 // of a 32-bit integer range. It's okay to wrap around; we just want |
249 // to avoid it as long as possible because clients may cache the ID of | 288 // to avoid it as long as possible because clients may cache the ID of |
250 // an object for a while to determine if they've seen it before. | 289 // an object for a while to determine if they've seen it before. |
251 next_child_id_--; | 290 next_child_id_--; |
252 if (next_child_id_ == -2000000000) | 291 if (next_child_id_ == -2000000000) |
253 next_child_id_ = -1; | 292 next_child_id_ = -1; |
254 | 293 |
255 return next_child_id_; | 294 return next_child_id_; |
(...skipping 12 matching lines...) Expand all Loading... |
268 if ((src.state >> WebAccessibility::STATE_FOCUSED) & 1) | 307 if ((src.state >> WebAccessibility::STATE_FOCUSED) & 1) |
269 focus_ = instance; | 308 focus_ = instance; |
270 for (int i = 0; i < static_cast<int>(src.children.size()); ++i) { | 309 for (int i = 0; i < static_cast<int>(src.children.size()); ++i) { |
271 BrowserAccessibility* child = CreateAccessibilityTree( | 310 BrowserAccessibility* child = CreateAccessibilityTree( |
272 instance, GetNextChildID(), src.children[i], i); | 311 instance, GetNextChildID(), src.children[i], i); |
273 instance->AddChild(child); | 312 instance->AddChild(child); |
274 } | 313 } |
275 | 314 |
276 return instance; | 315 return instance; |
277 } | 316 } |
OLD | NEW |