| OLD | NEW |
| 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 #include "chrome/browser/ui/ash/accessibility/ax_root_obj_wrapper.h" | 5 #include "chrome/browser/ui/ash/accessibility/ax_root_obj_wrapper.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "ui/accessibility/ax_node_data.h" | 8 #include "ui/accessibility/ax_node_data.h" |
| 10 #include "ui/accessibility/ax_view_state.h" | 9 #include "ui/accessibility/ax_view_state.h" |
| 11 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
| 12 #include "ui/views/accessibility/ax_aura_obj_cache.h" | 11 #include "ui/views/accessibility/ax_aura_obj_cache.h" |
| 13 | 12 |
| 14 namespace { | 13 AXRootObjWrapper::AXRootObjWrapper(int32 id) : id_(id) { |
| 15 class AlertWindow : public aura::Window { | |
| 16 public: | |
| 17 AlertWindow() : aura::Window(NULL) {} | |
| 18 virtual ~AlertWindow() {} | |
| 19 }; | |
| 20 | |
| 21 } // namespace | |
| 22 | |
| 23 AXRootObjWrapper::AXRootObjWrapper(int32 id) | |
| 24 : id_(id), alert_window_(new AlertWindow()) { | |
| 25 } | 14 } |
| 26 | 15 |
| 27 AXRootObjWrapper::~AXRootObjWrapper() { | 16 AXRootObjWrapper::~AXRootObjWrapper() {} |
| 28 if (alert_window_) { | |
| 29 delete alert_window_; | |
| 30 alert_window_ = NULL; | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 views::AXAuraObjWrapper* AXRootObjWrapper::GetAlertForText( | |
| 35 const std::string& text) { | |
| 36 alert_window_->SetTitle(base::UTF8ToUTF16((text))); | |
| 37 return views::AXAuraObjCache::GetInstance()->GetOrCreate(alert_window_); | |
| 38 } | |
| 39 | 17 |
| 40 bool AXRootObjWrapper::HasChild(views::AXAuraObjWrapper* child) { | 18 bool AXRootObjWrapper::HasChild(views::AXAuraObjWrapper* child) { |
| 41 std::vector<views::AXAuraObjWrapper*> children; | 19 std::vector<views::AXAuraObjWrapper*> children; |
| 42 GetChildren(&children); | 20 GetChildren(&children); |
| 43 return std::find(children.begin(), children.end(), child) != children.end(); | 21 return std::find(children.begin(), children.end(), child) != children.end(); |
| 44 } | 22 } |
| 45 | 23 |
| 46 views::AXAuraObjWrapper* AXRootObjWrapper::GetParent() { | 24 views::AXAuraObjWrapper* AXRootObjWrapper::GetParent() { |
| 47 return NULL; | 25 return NULL; |
| 48 } | 26 } |
| 49 | 27 |
| 50 void AXRootObjWrapper::GetChildren( | 28 void AXRootObjWrapper::GetChildren( |
| 51 std::vector<views::AXAuraObjWrapper*>* out_children) { | 29 std::vector<views::AXAuraObjWrapper*>* out_children) { |
| 52 if (!ash::Shell::HasInstance()) | 30 if (!ash::Shell::HasInstance()) |
| 53 return; | 31 return; |
| 54 | 32 |
| 55 // Only on ash is there a notion of a root with children. | 33 // Only on ash is there a notion of a root with children. |
| 56 aura::Window::Windows children = | 34 aura::Window::Windows children = |
| 57 ash::Shell::GetInstance()->GetAllRootWindows(); | 35 ash::Shell::GetInstance()->GetAllRootWindows(); |
| 58 for (size_t i = 0; i < children.size(); ++i) { | 36 for (size_t i = 0; i < children.size(); ++i) { |
| 59 out_children->push_back( | 37 out_children->push_back( |
| 60 views::AXAuraObjCache::GetInstance()->GetOrCreate(children[i])); | 38 views::AXAuraObjCache::GetInstance()->GetOrCreate(children[i])); |
| 61 } | 39 } |
| 62 | |
| 63 out_children->push_back( | |
| 64 views::AXAuraObjCache::GetInstance()->GetOrCreate(alert_window_)); | |
| 65 } | 40 } |
| 66 | 41 |
| 67 void AXRootObjWrapper::Serialize(ui::AXNodeData* out_node_data) { | 42 void AXRootObjWrapper::Serialize(ui::AXNodeData* out_node_data) { |
| 68 out_node_data->id = id_; | 43 out_node_data->id = id_; |
| 69 out_node_data->role = ui::AX_ROLE_DESKTOP; | 44 out_node_data->role = ui::AX_ROLE_DESKTOP; |
| 70 // TODO(dtseng): Apply a richer set of states. | 45 // TODO(dtseng): Apply a richer set of states. |
| 71 out_node_data->state = 0; | 46 out_node_data->state = 0; |
| 72 } | 47 } |
| 73 | 48 |
| 74 int32 AXRootObjWrapper::GetID() { | 49 int32 AXRootObjWrapper::GetID() { |
| 75 return id_; | 50 return id_; |
| 76 } | 51 } |
| OLD | NEW |