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