Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "AXObjectCache.h" | 7 #include "AXObjectCache.h" |
| 8 #include "Document.h" | 8 #include "Document.h" |
| 9 #include "Frame.h" | 9 #include "Frame.h" |
| 10 #include "RefPtr.h" | 10 #include "RefPtr.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 RefPtr<GlueAccessibilityObject> acc_obj_root_; | 27 RefPtr<GlueAccessibilityObject> acc_obj_root_; |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 /*static*/ | 30 /*static*/ |
| 31 WebAccessibilityManager* WebAccessibilityManager::Create() { | 31 WebAccessibilityManager* WebAccessibilityManager::Create() { |
| 32 return new WebAccessibilityManagerImpl(); | 32 return new WebAccessibilityManagerImpl(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 // class WebAccessibilityManagerImpl | 35 // class WebAccessibilityManagerImpl |
| 36 WebAccessibilityManagerImpl::WebAccessibilityManagerImpl() | 36 WebAccessibilityManagerImpl::WebAccessibilityManagerImpl() |
| 37 : root_(new GlueAccessibilityObjectRoot) { | 37 : root_(new GlueAccessibilityObjectRoot), |
| 38 acc_obj_id_(0) { | |
| 39 } | |
| 40 | |
| 41 WebAccessibilityManagerImpl::~WebAccessibilityManagerImpl() { | |
| 42 int_to_glue_acc_obj_map_.clear(); | |
| 43 acc_obj_to_int_map_.clear(); | |
| 38 } | 44 } |
| 39 | 45 |
| 40 bool WebAccessibilityManagerImpl::GetAccObjInfo(WebView* view, | 46 bool WebAccessibilityManagerImpl::GetAccObjInfo(WebView* view, |
| 41 const WebAccessibility::InParams& in_params, | 47 const WebAccessibility::InParams& in_params, |
| 42 WebAccessibility::OutParams* out_params) { | 48 WebAccessibility::OutParams* out_params) { |
| 43 if (!root_->acc_obj_root_ && !InitAccObjRoot(view)) { | 49 if (!root_->acc_obj_root_ && !InitAccObjRoot(view)) { |
| 44 // Failure in retrieving or initializing the root. | 50 // Failure in retrieving or initializing the root. |
| 45 return false; | 51 return false; |
| 46 } | 52 } |
| 47 | 53 |
| 48 // Find GlueAccessibilityObject requested by [in_params.object_id]. | 54 // Function input parameters. |
| 49 IntToAccObjMap::iterator it = | 55 int object_id = in_params.object_id; |
| 50 int_to_acc_obj_map_.find(in_params.object_id); | 56 int child_id = in_params.child_id; |
| 51 if (it == int_to_acc_obj_map_.end() || !it->second) { | 57 |
| 58 if (!in_params.direct_descendant) { | |
| 59 // Object is not a direct child, re-map the input parameters accordingly. | |
| 60 // The object to be retrived is referred to by the |in_params.child_id|, as | |
|
jcampan
2009/05/19 21:50:04
typo: retrived -> retrieved
| |
| 61 // a result of e.g. a focus event. The local |child_id| is set to 0, to | |
| 62 // indicate that any function call should refer to the object itself. | |
| 63 object_id = in_params.child_id; | |
| 64 child_id = 0; | |
| 65 } | |
| 66 | |
| 67 // Find GlueAccessibilityObject requested by |object_id|. | |
| 68 IntToGlueAccObjMap::iterator it = | |
| 69 int_to_glue_acc_obj_map_.find(object_id); | |
| 70 if (it == int_to_glue_acc_obj_map_.end() || !it->second) { | |
| 52 // Map did not contain a valid instance of the data requested. | 71 // Map did not contain a valid instance of the data requested. |
| 53 return false; | 72 return false; |
| 54 } | 73 } |
| 55 RefPtr<GlueAccessibilityObject> active_acc_obj = it->second; | 74 RefPtr<GlueAccessibilityObject> active_acc_obj = it->second; |
| 56 | 75 |
| 57 // Function input parameters. | |
| 58 int child_id = in_params.child_id; | |
| 59 | |
| 60 // Temp paramters for holding output information. | 76 // Temp paramters for holding output information. |
| 61 RefPtr<GlueAccessibilityObject> out_acc_obj = NULL; | 77 RefPtr<GlueAccessibilityObject> out_acc_obj = NULL; |
| 62 WebCore::String out_string; | 78 WebCore::String out_string; |
| 63 | 79 |
| 64 switch (in_params.function_id) { | 80 switch (in_params.function_id) { |
| 65 case WebAccessibility::FUNCTION_DODEFAULTACTION : | 81 case WebAccessibility::FUNCTION_DODEFAULTACTION : |
| 66 if (!active_acc_obj->DoDefaultAction(child_id)) | 82 if (!active_acc_obj->DoDefaultAction(child_id)) |
| 67 return false; | 83 return false; |
| 68 break; | 84 break; |
| 69 case WebAccessibility::FUNCTION_HITTEST : | 85 case WebAccessibility::FUNCTION_HITTEST : |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 default: | 165 default: |
| 150 // Non-supported function id. | 166 // Non-supported function id. |
| 151 return false; | 167 return false; |
| 152 } | 168 } |
| 153 | 169 |
| 154 // Output and hashmap assignments, as appropriate. | 170 // Output and hashmap assignments, as appropriate. |
| 155 if (!out_string.isEmpty()) | 171 if (!out_string.isEmpty()) |
| 156 out_params->output_string = StringToString16(out_string); | 172 out_params->output_string = StringToString16(out_string); |
| 157 | 173 |
| 158 if (out_acc_obj) { | 174 if (out_acc_obj) { |
| 159 AccObjToIntMap::iterator it = acc_obj_to_int_map_.find(out_acc_obj.get()); | 175 AccObjToIntMap::iterator it = |
| 176 acc_obj_to_int_map_.find(out_acc_obj->accessibilityObject()); | |
| 160 | 177 |
| 161 if (it != acc_obj_to_int_map_.end()) { | 178 if (it != acc_obj_to_int_map_.end()) { |
| 162 // Data already present in map, return previously assigned id. | 179 // Data already present in map, return previously assigned id. |
| 163 out_params->object_id = it->second; | 180 out_params->object_id = it->second; |
| 164 out_params->output_long1 = -1; | 181 out_params->output_long1 = -1; |
| 165 } else { | 182 } else { |
| 166 // Insert new GlueAccessibilityObject in hashmaps. | 183 // Insert new GlueAccessibilityObject in hashmaps. |
| 167 int_to_acc_obj_map_[acc_obj_id_] = out_acc_obj.get(); | 184 int_to_glue_acc_obj_map_[acc_obj_id_] = out_acc_obj.get(); |
| 168 acc_obj_to_int_map_[out_acc_obj.get()] = acc_obj_id_; | 185 acc_obj_to_int_map_[out_acc_obj->accessibilityObject()] = acc_obj_id_; |
| 169 out_params->object_id = acc_obj_id_++; | 186 out_params->object_id = acc_obj_id_++; |
| 170 out_params->output_long1 = -1; | 187 out_params->output_long1 = -1; |
| 171 } | 188 } |
| 172 } | 189 } |
| 173 // TODO(klink): Handle simple objects returned. | 190 // TODO(klink): Handle simple objects returned. |
| 174 return true; | 191 return true; |
| 175 } | 192 } |
| 176 | 193 |
| 177 bool WebAccessibilityManagerImpl::InitAccObjRoot(WebView* view) { | 194 bool WebAccessibilityManagerImpl::InitAccObjRoot(WebView* view) { |
| 178 // Root id is always 0. | |
| 179 acc_obj_id_ = 0; | |
| 180 | |
| 181 // Enable accessibility and retrieve Document. | 195 // Enable accessibility and retrieve Document. |
| 182 WebCore::AXObjectCache::enableAccessibility(); | 196 WebCore::AXObjectCache::enableAccessibility(); |
| 183 WebFrameImpl* main_frame_impl = | 197 WebFrameImpl* main_frame_impl = |
| 184 static_cast<WebFrameImpl*>(view->GetMainFrame()); | 198 static_cast<WebFrameImpl*>(view->GetMainFrame()); |
| 185 if (!main_frame_impl || !main_frame_impl->frame()) | 199 if (!main_frame_impl || !main_frame_impl->frame()) |
| 186 return false; | 200 return false; |
| 187 | 201 |
| 188 WebCore::Document* doc = main_frame_impl->frame()->document(); | 202 WebCore::Document* doc = main_frame_impl->frame()->document(); |
| 189 | 203 |
| 190 if (!doc || !doc->renderer()) | 204 if (!doc || !doc->renderer()) |
| 191 return false; | 205 return false; |
| 192 | 206 |
| 193 if (!root_->acc_obj_root_) { | 207 if (!root_->acc_obj_root_) { |
| 194 // Either we've never had a wrapper for this frame's top-level Document, | 208 // Either we've never had a wrapper for this frame's top-level Document, |
| 195 // the Document renderer was destroyed and its wrapper was detached, or | 209 // the Document renderer was destroyed and its wrapper was detached, or |
| 196 // the previous Document is in the page cache, and the current document | 210 // the previous Document is in the page cache, and the current document |
| 197 // needs to be wrapped. | 211 // needs to be wrapped. |
| 198 root_->acc_obj_root_ = GlueAccessibilityObject::CreateInstance(doc-> | 212 root_->acc_obj_root_ = GlueAccessibilityObject::CreateInstance(doc-> |
| 199 axObjectCache()->getOrCreate(doc->renderer())); | 213 axObjectCache()->getOrCreate(doc->renderer())); |
| 200 } | 214 } |
| 201 // Insert root in hashmaps. | 215 // Insert root in hashmaps. |
| 202 int_to_acc_obj_map_[acc_obj_id_] = root_->acc_obj_root_.get(); | 216 int_to_glue_acc_obj_map_[acc_obj_id_] = root_->acc_obj_root_.get(); |
| 203 acc_obj_to_int_map_[root_->acc_obj_root_.get()] = acc_obj_id_++; | 217 acc_obj_to_int_map_[root_->acc_obj_root_->accessibilityObject()] = |
| 218 acc_obj_id_++; | |
| 204 | 219 |
| 205 return true; | 220 return true; |
| 206 } | 221 } |
| 207 | 222 |
| 208 bool WebAccessibilityManagerImpl::ClearAccObjMap(int acc_obj_id, | 223 bool WebAccessibilityManagerImpl::ClearAccObjMap(int acc_obj_id, |
| 209 bool clear_all) { | 224 bool clear_all) { |
| 210 if (clear_all) { | 225 if (clear_all) { |
| 211 // Clear maps and invalidate root. | 226 // Clear maps and invalidate root. |
| 212 int_to_acc_obj_map_.clear(); | 227 int_to_glue_acc_obj_map_.clear(); |
| 213 acc_obj_to_int_map_.clear(); | 228 acc_obj_to_int_map_.clear(); |
| 214 root_->acc_obj_root_ = 0; | 229 root_->acc_obj_root_ = 0; |
| 215 return true; | 230 return true; |
| 216 } | 231 } |
| 217 | 232 |
| 218 IntToAccObjMap::iterator it = int_to_acc_obj_map_.find(acc_obj_id); | 233 IntToGlueAccObjMap::iterator it = int_to_glue_acc_obj_map_.find(acc_obj_id); |
| 219 | 234 |
| 220 if (it == int_to_acc_obj_map_.end()) { | 235 if (it == int_to_glue_acc_obj_map_.end()) { |
| 221 // Element not found. | 236 // Element not found. |
| 222 return false; | 237 return false; |
| 223 } | 238 } |
| 224 | 239 |
| 225 if (it->second) { | 240 if (it->second) { |
| 226 // Erase element from reverse hashmap. | 241 // Erase element from reverse hashmap. |
| 227 AccObjToIntMap::iterator it2 = acc_obj_to_int_map_.find(it->second); | 242 AccObjToIntMap::iterator it2 = |
| 243 acc_obj_to_int_map_.find(it->second->accessibilityObject()); | |
| 228 | 244 |
| 229 if (it2 != acc_obj_to_int_map_.end()) | 245 if (it2 != acc_obj_to_int_map_.end()) |
| 230 acc_obj_to_int_map_.erase(it2); | 246 acc_obj_to_int_map_.erase(it2); |
| 231 } | 247 } |
| 232 int_to_acc_obj_map_.erase(it); | 248 int_to_glue_acc_obj_map_.erase(it); |
| 233 | 249 |
| 234 if (acc_obj_id == 0) { | 250 if (acc_obj_id == 0) { |
| 235 // Invalidate root. | 251 // Invalidate root. |
| 236 root_->acc_obj_root_ = 0; | 252 root_->acc_obj_root_ = 0; |
| 237 } | 253 } |
| 238 return true; | 254 return true; |
| 239 } | 255 } |
| 240 | 256 |
| 257 int WebAccessibilityManagerImpl::FocusAccObj( | |
| 258 WebCore::AccessibilityObject* acc_obj) { | |
| 259 if (!acc_obj) { | |
| 260 // Return with failure. | |
| 261 return -1; | |
| 262 } | |
| 263 | |
| 264 AccObjToIntMap::iterator it = acc_obj_to_int_map_.find(acc_obj); | |
| 265 | |
| 266 if (it != acc_obj_to_int_map_.end()) { | |
| 267 return it->second; | |
| 268 } else { | |
|
darin (slow to review)
2009/05/18 22:43:21
nit: no need for else after return. would be nice
| |
| 269 // Insert new accessibility object in hashmaps and return its newly | |
| 270 // assigned accessibility object id. | |
| 271 int_to_glue_acc_obj_map_[acc_obj_id_] = | |
| 272 GlueAccessibilityObject::CreateInstance(acc_obj); | |
| 273 acc_obj_to_int_map_[acc_obj] = acc_obj_id_; | |
| 274 | |
| 275 return acc_obj_id_++; | |
| 276 } | |
| 277 } | |
| 278 | |
| 241 } // namespace webkit_glue | 279 } // namespace webkit_glue |
| OLD | NEW |