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