| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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/chromeos/accessibility/accessibility_highlight_manager.
h" |
| 6 |
| 5 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 6 #include "chrome/browser/chromeos/accessibility/accessibility_highlight_manager.
h" | |
| 7 #include "chrome/browser/chromeos/ui/accessibility_focus_ring_controller.h" | 8 #include "chrome/browser/chromeos/ui/accessibility_focus_ring_controller.h" |
| 8 #include "content/public/browser/focused_node_details.h" | 9 #include "content/public/browser/focused_node_details.h" |
| 9 #include "content/public/browser/notification_service.h" | 10 #include "content/public/browser/notification_service.h" |
| 10 #include "content/public/browser/notification_types.h" | 11 #include "content/public/browser/notification_types.h" |
| 11 #include "ui/aura/window_tree_host.h" | 12 #include "ui/aura/window_tree_host.h" |
| 12 #include "ui/wm/core/coordinate_conversion.h" | 13 #include "ui/wm/core/coordinate_conversion.h" |
| 13 #include "ui/wm/core/cursor_manager.h" | 14 #include "ui/wm/core/cursor_manager.h" |
| 15 #include "ui/wm/public/activation_client.h" |
| 14 | 16 |
| 15 namespace chromeos { | 17 namespace chromeos { |
| 16 | 18 |
| 17 namespace { | 19 namespace { |
| 18 | 20 |
| 19 ui::InputMethod* GetInputMethod(aura::Window* root_window) { | 21 ui::InputMethod* GetInputMethod(aura::Window* root_window) { |
| 20 if (root_window->GetHost()) | 22 if (root_window->GetHost()) |
| 21 return root_window->GetHost()->GetInputMethod(); | 23 return root_window->GetHost()->GetInputMethod(); |
| 22 return nullptr; | 24 return nullptr; |
| 23 } | 25 } |
| 24 | 26 |
| 25 } // namespace | 27 } // namespace |
| 26 | 28 |
| 27 AccessibilityHighlightManager::AccessibilityHighlightManager() { | 29 AccessibilityHighlightManager::AccessibilityHighlightManager() {} |
| 28 } | |
| 29 | 30 |
| 30 AccessibilityHighlightManager::~AccessibilityHighlightManager() { | 31 AccessibilityHighlightManager::~AccessibilityHighlightManager() { |
| 31 // No need to do anything during shutdown | 32 // No need to do anything during shutdown |
| 32 if (!ash::Shell::HasInstance()) | 33 if (!ash::Shell::HasInstance()) |
| 33 return; | 34 return; |
| 34 | 35 |
| 35 AccessibilityFocusRingController::GetInstance()->SetFocusRing( | 36 AccessibilityFocusRingController::GetInstance()->SetFocusRing( |
| 36 std::vector<gfx::Rect>(), | 37 std::vector<gfx::Rect>(), |
| 37 AccessibilityFocusRingController::FADE_OUT_FOCUS_RING); | 38 AccessibilityFocusRingController::FADE_OUT_FOCUS_RING); |
| 38 AccessibilityFocusRingController::GetInstance()->HideCaretRing(); | 39 AccessibilityFocusRingController::GetInstance()->HideCaretRing(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 void AccessibilityHighlightManager::OnTextInputStateChanged( | 113 void AccessibilityHighlightManager::OnTextInputStateChanged( |
| 113 const ui::TextInputClient* client) { | 114 const ui::TextInputClient* client) { |
| 114 if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) { | 115 if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) { |
| 115 caret_visible_ = false; | 116 caret_visible_ = false; |
| 116 UpdateFocusAndCaretHighlights(); | 117 UpdateFocusAndCaretHighlights(); |
| 117 } | 118 } |
| 118 } | 119 } |
| 119 | 120 |
| 120 void AccessibilityHighlightManager::OnCaretBoundsChanged( | 121 void AccessibilityHighlightManager::OnCaretBoundsChanged( |
| 121 const ui::TextInputClient* client) { | 122 const ui::TextInputClient* client) { |
| 123 if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) { |
| 124 caret_visible_ = false; |
| 125 return; |
| 126 } |
| 122 gfx::Rect caret_bounds = client->GetCaretBounds(); | 127 gfx::Rect caret_bounds = client->GetCaretBounds(); |
| 123 caret_point_ = caret_bounds.CenterPoint(); | 128 gfx::Point new_caret_point = caret_bounds.CenterPoint(); |
| 124 caret_visible_ = client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE && | 129 ::wm::ConvertPointFromScreen(ash::Shell::GetPrimaryRootWindow(), |
| 125 (caret_bounds.width() || caret_bounds.height()); | 130 &new_caret_point); |
| 131 if (new_caret_point == caret_point_) |
| 132 return; |
| 133 caret_point_ = new_caret_point; |
| 134 caret_visible_ = IsCaretVisible(caret_bounds); |
| 126 UpdateFocusAndCaretHighlights(); | 135 UpdateFocusAndCaretHighlights(); |
| 127 } | 136 } |
| 128 | 137 |
| 129 void AccessibilityHighlightManager::OnCursorVisibilityChanged(bool is_visible) { | 138 void AccessibilityHighlightManager::OnCursorVisibilityChanged(bool is_visible) { |
| 130 UpdateCursorHighlight(); | 139 UpdateCursorHighlight(); |
| 131 } | 140 } |
| 132 | 141 |
| 133 bool AccessibilityHighlightManager::IsCursorVisible() { | 142 bool AccessibilityHighlightManager::IsCursorVisible() { |
| 134 return ash::Shell::Get()->cursor_manager()->IsCursorVisible(); | 143 return ash::Shell::Get()->cursor_manager()->IsCursorVisible(); |
| 135 } | 144 } |
| 136 | 145 |
| 146 bool AccessibilityHighlightManager::IsCaretVisible( |
| 147 const gfx::Rect& caret_bounds) { |
| 148 aura::Window* root_window = ash::Shell::GetPrimaryRootWindow(); |
| 149 aura::Window* active_window = |
| 150 ::wm::GetActivationClient(root_window)->GetActiveWindow(); |
| 151 if (!active_window) |
| 152 active_window = root_window; |
| 153 return (caret_bounds.width() || caret_bounds.height()) && |
| 154 active_window->GetBoundsInScreen().Contains(caret_point_); |
| 155 } |
| 156 |
| 137 void AccessibilityHighlightManager::UpdateFocusAndCaretHighlights() { | 157 void AccessibilityHighlightManager::UpdateFocusAndCaretHighlights() { |
| 138 auto* controller = AccessibilityFocusRingController::GetInstance(); | 158 auto* controller = AccessibilityFocusRingController::GetInstance(); |
| 139 | 159 |
| 140 // The caret highlight takes precedence over the focus highlight if | 160 // The caret highlight takes precedence over the focus highlight if |
| 141 // both are visible. | 161 // both are visible. |
| 142 if (caret_ && caret_visible_) { | 162 if (caret_ && caret_visible_) { |
| 143 controller->SetCaretRing(caret_point_); | 163 controller->SetCaretRing(caret_point_); |
| 144 controller->SetFocusRing( | 164 controller->SetFocusRing( |
| 145 std::vector<gfx::Rect>(), | 165 std::vector<gfx::Rect>(), |
| 146 AccessibilityFocusRingController::FADE_OUT_FOCUS_RING); | 166 AccessibilityFocusRingController::FADE_OUT_FOCUS_RING); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 162 void AccessibilityHighlightManager::UpdateCursorHighlight() { | 182 void AccessibilityHighlightManager::UpdateCursorHighlight() { |
| 163 if (cursor_ && IsCursorVisible()) { | 183 if (cursor_ && IsCursorVisible()) { |
| 164 AccessibilityFocusRingController::GetInstance()->SetCursorRing( | 184 AccessibilityFocusRingController::GetInstance()->SetCursorRing( |
| 165 cursor_point_); | 185 cursor_point_); |
| 166 } else { | 186 } else { |
| 167 AccessibilityFocusRingController::GetInstance()->HideCursorRing(); | 187 AccessibilityFocusRingController::GetInstance()->HideCursorRing(); |
| 168 } | 188 } |
| 169 } | 189 } |
| 170 | 190 |
| 171 } // namespace chromeos | 191 } // namespace chromeos |
| OLD | NEW |