| 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 "ash/shell.h" | 5 #include "ash/shell.h" |
| 6 #include "chrome/browser/chromeos/accessibility/accessibility_highlight_manager.
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" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 OffscreenPoint()); | 61 OffscreenPoint()); |
| 62 | 62 |
| 63 aura::Window* root_window = shell->GetPrimaryRootWindow(); | 63 aura::Window* root_window = shell->GetPrimaryRootWindow(); |
| 64 ui::InputMethod* input_method = GetInputMethod(root_window); | 64 ui::InputMethod* input_method = GetInputMethod(root_window); |
| 65 input_method->RemoveObserver(this); | 65 input_method->RemoveObserver(this); |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 void AccessibilityHighlightManager::HighlightFocus(bool focus) { | 69 void AccessibilityHighlightManager::HighlightFocus(bool focus) { |
| 70 focus_ = focus; | 70 focus_ = focus; |
| 71 | 71 UpdateFocusAndCaretHighlights(); |
| 72 std::vector<gfx::Rect> rects; | |
| 73 rects.push_back(focus_ ? focus_rect_ : OffscreenRect()); | |
| 74 AccessibilityFocusRingController::GetInstance()->SetFocusRing(rects); | |
| 75 } | 72 } |
| 76 | 73 |
| 77 void AccessibilityHighlightManager::HighlightCursor(bool cursor) { | 74 void AccessibilityHighlightManager::HighlightCursor(bool cursor) { |
| 78 cursor_ = cursor; | 75 cursor_ = cursor; |
| 79 | 76 |
| 80 AccessibilityFocusRingController::GetInstance()->SetCursorRing( | 77 AccessibilityFocusRingController::GetInstance()->SetCursorRing( |
| 81 cursor_ ? cursor_point_ : OffscreenPoint()); | 78 cursor_ ? cursor_point_ : OffscreenPoint()); |
| 82 } | 79 } |
| 83 | 80 |
| 84 void AccessibilityHighlightManager::HighlightCaret(bool caret) { | 81 void AccessibilityHighlightManager::HighlightCaret(bool caret) { |
| 85 caret_ = caret; | 82 caret_ = caret; |
| 86 | 83 UpdateFocusAndCaretHighlights(); |
| 87 AccessibilityFocusRingController::GetInstance()->SetCaretRing( | |
| 88 caret_ ? caret_point_ : OffscreenPoint()); | |
| 89 } | 84 } |
| 90 | 85 |
| 91 void AccessibilityHighlightManager::OnMouseEvent(ui::MouseEvent* event) { | 86 void AccessibilityHighlightManager::OnMouseEvent(ui::MouseEvent* event) { |
| 92 if (event->type() == ui::ET_MOUSE_MOVED) { | 87 if (event->type() == ui::ET_MOUSE_MOVED) { |
| 93 cursor_point_ = event->root_location(); | 88 cursor_point_ = event->root_location(); |
| 94 AccessibilityFocusRingController::GetInstance()->SetCursorRing( | 89 AccessibilityFocusRingController::GetInstance()->SetCursorRing( |
| 95 cursor_ ? cursor_point_ : OffscreenPoint()); | 90 cursor_ ? cursor_point_ : OffscreenPoint()); |
| 96 } | 91 } |
| 97 } | 92 } |
| 98 | 93 |
| 99 void AccessibilityHighlightManager::Observe( | 94 void AccessibilityHighlightManager::Observe( |
| 100 int type, | 95 int type, |
| 101 const content::NotificationSource& source, | 96 const content::NotificationSource& source, |
| 102 const content::NotificationDetails& details) { | 97 const content::NotificationDetails& details) { |
| 103 DCHECK_EQ(type, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE); | 98 DCHECK_EQ(type, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE); |
| 104 content::FocusedNodeDetails* node_details = | 99 content::FocusedNodeDetails* node_details = |
| 105 content::Details<content::FocusedNodeDetails>(details).ptr(); | 100 content::Details<content::FocusedNodeDetails>(details).ptr(); |
| 106 focus_rect_ = node_details->node_bounds_in_screen; | 101 focus_rect_ = node_details->node_bounds_in_screen; |
| 107 | 102 UpdateFocusAndCaretHighlights(); |
| 108 if (focus_) { | |
| 109 std::vector<gfx::Rect> rects; | |
| 110 rects.push_back(focus_rect_); | |
| 111 AccessibilityFocusRingController::GetInstance()->SetFocusRing(rects); | |
| 112 } | |
| 113 } | 103 } |
| 114 | 104 |
| 115 void AccessibilityHighlightManager::OnTextInputStateChanged( | 105 void AccessibilityHighlightManager::OnTextInputStateChanged( |
| 116 const ui::TextInputClient* client) { | 106 const ui::TextInputClient* client) { |
| 117 if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) { | 107 if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) { |
| 118 caret_point_ = OffscreenPoint(); | 108 caret_visible_ = false; |
| 119 if (caret_) { | 109 UpdateFocusAndCaretHighlights(); |
| 120 AccessibilityFocusRingController::GetInstance()->SetCaretRing( | |
| 121 caret_point_); | |
| 122 } | |
| 123 } | 110 } |
| 124 } | 111 } |
| 125 | 112 |
| 126 void AccessibilityHighlightManager::OnCaretBoundsChanged( | 113 void AccessibilityHighlightManager::OnCaretBoundsChanged( |
| 127 const ui::TextInputClient* client) { | 114 const ui::TextInputClient* client) { |
| 128 gfx::Rect caret_bounds = client->GetCaretBounds(); | 115 gfx::Rect caret_bounds = client->GetCaretBounds(); |
| 129 if (caret_bounds.width() == 0 && caret_bounds.height() == 0) | |
| 130 caret_bounds = OffscreenRect(); | |
| 131 caret_point_ = caret_bounds.CenterPoint(); | 116 caret_point_ = caret_bounds.CenterPoint(); |
| 117 caret_visible_ = client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE && |
| 118 (caret_bounds.width() || caret_bounds.height()); |
| 119 UpdateFocusAndCaretHighlights(); |
| 120 } |
| 132 | 121 |
| 133 if (caret_) | 122 void AccessibilityHighlightManager::UpdateFocusAndCaretHighlights() { |
| 134 AccessibilityFocusRingController::GetInstance()->SetCaretRing(caret_point_); | 123 auto controller = AccessibilityFocusRingController::GetInstance(); |
| 124 |
| 125 // The caret highlight takes precedence over the focus highlight if |
| 126 // both are visible. |
| 127 if (caret_ && caret_visible_) { |
| 128 controller->SetCaretRing(caret_point_); |
| 129 controller->SetFocusRing(std::vector<gfx::Rect>()); |
| 130 } else if (focus_) { |
| 131 controller->SetCaretRing(OffscreenPoint()); |
| 132 std::vector<gfx::Rect> rects; |
| 133 if (!focus_rect_.IsEmpty()) |
| 134 rects.push_back(focus_rect_); |
| 135 controller->SetFocusRing(rects); |
| 136 } else { |
| 137 controller->SetCaretRing(OffscreenPoint()); |
| 138 controller->SetFocusRing(std::vector<gfx::Rect>()); |
| 139 } |
| 135 } | 140 } |
| 136 | 141 |
| 137 } // namespace chromeos | 142 } // namespace chromeos |
| OLD | NEW |