| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "ui/base/win/osk_display_manager.h" | 5 #include "ui/base/win/osk_display_manager.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <shellapi.h> | 8 #include <shellapi.h> |
| 9 #include <shlobj.h> | 9 #include <shlobj.h> |
| 10 #include <shobjidl.h> // Must be before propkey. | 10 #include <shobjidl.h> // Must be before propkey. |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/debug/leak_annotations.h" | 13 #include "base/debug/leak_annotations.h" |
| 14 #include "base/location.h" |
| 14 #include "base/logging.h" | 15 #include "base/logging.h" |
| 15 #include "base/message_loop/message_loop.h" | 16 #include "base/single_thread_task_runner.h" |
| 16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "base/win/registry.h" | 19 #include "base/win/registry.h" |
| 18 #include "base/win/scoped_co_mem.h" | 20 #include "base/win/scoped_co_mem.h" |
| 19 #include "base/win/win_util.h" | 21 #include "base/win/win_util.h" |
| 20 #include "base/win/windows_version.h" | 22 #include "base/win/windows_version.h" |
| 21 #include "ui/base/win/osk_display_observer.h" | 23 #include "ui/base/win/osk_display_observer.h" |
| 22 #include "ui/display/win/dpi.h" | 24 #include "ui/display/win/dpi.h" |
| 23 #include "ui/gfx/geometry/dip_util.h" | 25 #include "ui/gfx/geometry/dip_util.h" |
| 24 | 26 |
| 25 namespace { | 27 namespace { |
| 26 | 28 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 OnScreenKeyboardDetector::~OnScreenKeyboardDetector() {} | 117 OnScreenKeyboardDetector::~OnScreenKeyboardDetector() {} |
| 116 | 118 |
| 117 void OnScreenKeyboardDetector::DetectKeyboard(HWND main_window) { | 119 void OnScreenKeyboardDetector::DetectKeyboard(HWND main_window) { |
| 118 main_window_ = main_window; | 120 main_window_ = main_window; |
| 119 keyboard_detect_requested_ = true; | 121 keyboard_detect_requested_ = true; |
| 120 // The keyboard is displayed by TabTip.exe which is launched via a | 122 // The keyboard is displayed by TabTip.exe which is launched via a |
| 121 // ShellExecute call in the | 123 // ShellExecute call in the |
| 122 // OnScreenKeyboardDisplayManager::DisplayVirtualKeyboard() function. We use | 124 // OnScreenKeyboardDisplayManager::DisplayVirtualKeyboard() function. We use |
| 123 // a delayed task to check if the keyboard is visible because of the possible | 125 // a delayed task to check if the keyboard is visible because of the possible |
| 124 // delay between the ShellExecute call and the keyboard becoming visible. | 126 // delay between the ShellExecute call and the keyboard becoming visible. |
| 125 base::MessageLoop::current()->PostDelayedTask( | 127 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 126 FROM_HERE, base::Bind(&OnScreenKeyboardDetector::CheckIfKeyboardVisible, | 128 FROM_HERE, base::Bind(&OnScreenKeyboardDetector::CheckIfKeyboardVisible, |
| 127 keyboard_detector_factory_.GetWeakPtr()), | 129 keyboard_detector_factory_.GetWeakPtr()), |
| 128 base::TimeDelta::FromMilliseconds(kCheckOSKDelayMs)); | 130 base::TimeDelta::FromMilliseconds(kCheckOSKDelayMs)); |
| 129 } | 131 } |
| 130 | 132 |
| 131 bool OnScreenKeyboardDetector::DismissKeyboard() { | 133 bool OnScreenKeyboardDetector::DismissKeyboard() { |
| 132 // We dismiss the virtual keyboard by generating the ESC keystroke | 134 // We dismiss the virtual keyboard by generating the ESC keystroke |
| 133 // programmatically. | 135 // programmatically. |
| 134 HWND osk = ::FindWindow(kOSKClassName, nullptr); | 136 HWND osk = ::FindWindow(kOSKClassName, nullptr); |
| 135 if (::IsWindow(osk) && ::IsWindowEnabled(osk)) { | 137 if (::IsWindow(osk) && ::IsWindowEnabled(osk)) { |
| 136 keyboard_detect_requested_ = false; | 138 keyboard_detect_requested_ = false; |
| 137 keyboard_dismiss_retry_count_ = 0; | 139 keyboard_dismiss_retry_count_ = 0; |
| 138 HandleKeyboardHidden(); | 140 HandleKeyboardHidden(); |
| 139 PostMessage(osk, WM_SYSCOMMAND, SC_CLOSE, 0); | 141 PostMessage(osk, WM_SYSCOMMAND, SC_CLOSE, 0); |
| 140 return true; | 142 return true; |
| 141 } else if (keyboard_detect_requested_) { | 143 } else if (keyboard_detect_requested_) { |
| 142 if (keyboard_dismiss_retry_count_ < kDismissKeyboardMaxRetries) { | 144 if (keyboard_dismiss_retry_count_ < kDismissKeyboardMaxRetries) { |
| 143 keyboard_dismiss_retry_count_++; | 145 keyboard_dismiss_retry_count_++; |
| 144 // Please refer to the comments in the DetectKeyboard() function for more | 146 // Please refer to the comments in the DetectKeyboard() function for more |
| 145 // information as to why we need a delayed task here. | 147 // information as to why we need a delayed task here. |
| 146 base::MessageLoop::current()->PostDelayedTask( | 148 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 147 FROM_HERE, base::Bind(base::IgnoreResult( | 149 FROM_HERE, base::Bind(base::IgnoreResult( |
| 148 &OnScreenKeyboardDetector::DismissKeyboard), | 150 &OnScreenKeyboardDetector::DismissKeyboard), |
| 149 keyboard_detector_factory_.GetWeakPtr()), | 151 keyboard_detector_factory_.GetWeakPtr()), |
| 150 base::TimeDelta::FromMilliseconds(kDismissKeyboardRetryTimeoutMs)); | 152 base::TimeDelta::FromMilliseconds(kDismissKeyboardRetryTimeoutMs)); |
| 151 } else { | 153 } else { |
| 152 keyboard_dismiss_retry_count_ = 0; | 154 keyboard_dismiss_retry_count_ = 0; |
| 153 } | 155 } |
| 154 } | 156 } |
| 155 return false; | 157 return false; |
| 156 } | 158 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 DVLOG(1) << "OSK window hidden while we are in the foreground."; | 201 DVLOG(1) << "OSK window hidden while we are in the foreground."; |
| 200 HandleKeyboardHidden(); | 202 HandleKeyboardHidden(); |
| 201 } | 203 } |
| 202 } | 204 } |
| 203 } else if (main_window_ != ::GetForegroundWindow()) { | 205 } else if (main_window_ != ::GetForegroundWindow()) { |
| 204 if (osk_visible_notification_received_) { | 206 if (osk_visible_notification_received_) { |
| 205 DVLOG(1) << "We are no longer in the foreground. Dismising OSK."; | 207 DVLOG(1) << "We are no longer in the foreground. Dismising OSK."; |
| 206 DismissKeyboard(); | 208 DismissKeyboard(); |
| 207 } | 209 } |
| 208 } else { | 210 } else { |
| 209 base::MessageLoop::current()->PostDelayedTask( | 211 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 210 FROM_HERE, base::Bind(&OnScreenKeyboardDetector::HideIfNecessary, | 212 FROM_HERE, base::Bind(&OnScreenKeyboardDetector::HideIfNecessary, |
| 211 keyboard_detector_factory_.GetWeakPtr()), | 213 keyboard_detector_factory_.GetWeakPtr()), |
| 212 base::TimeDelta::FromMilliseconds(kCheckOSKDelayMs)); | 214 base::TimeDelta::FromMilliseconds(kCheckOSKDelayMs)); |
| 213 } | 215 } |
| 214 } | 216 } |
| 215 | 217 |
| 216 void OnScreenKeyboardDetector::HandleKeyboardVisible() { | 218 void OnScreenKeyboardDetector::HandleKeyboardVisible() { |
| 217 DCHECK(!osk_visible_notification_received_); | 219 DCHECK(!osk_visible_notification_received_); |
| 218 osk_visible_notification_received_ = true; | 220 osk_visible_notification_received_ = true; |
| 219 | 221 |
| 220 FOR_EACH_OBSERVER(OnScreenKeyboardObserver, observers_, | 222 FOR_EACH_OBSERVER(OnScreenKeyboardObserver, observers_, |
| 221 OnKeyboardVisible(osk_rect_pixels_)); | 223 OnKeyboardVisible(osk_rect_pixels_)); |
| 222 | 224 |
| 223 // Now that the keyboard is visible, run the task to detect if it was hidden. | 225 // Now that the keyboard is visible, run the task to detect if it was hidden. |
| 224 base::MessageLoop::current()->PostDelayedTask( | 226 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 225 FROM_HERE, base::Bind(&OnScreenKeyboardDetector::HideIfNecessary, | 227 FROM_HERE, base::Bind(&OnScreenKeyboardDetector::HideIfNecessary, |
| 226 keyboard_detector_factory_.GetWeakPtr()), | 228 keyboard_detector_factory_.GetWeakPtr()), |
| 227 base::TimeDelta::FromMilliseconds(kCheckOSKDelayMs)); | 229 base::TimeDelta::FromMilliseconds(kCheckOSKDelayMs)); |
| 228 } | 230 } |
| 229 | 231 |
| 230 void OnScreenKeyboardDetector::HandleKeyboardHidden() { | 232 void OnScreenKeyboardDetector::HandleKeyboardHidden() { |
| 231 osk_visible_notification_received_ = false; | 233 osk_visible_notification_received_ = false; |
| 232 FOR_EACH_OBSERVER(OnScreenKeyboardObserver, observers_, | 234 FOR_EACH_OBSERVER(OnScreenKeyboardObserver, observers_, |
| 233 OnKeyboardHidden(osk_rect_pixels_)); | 235 OnKeyboardHidden(osk_rect_pixels_)); |
| 234 ClearObservers(); | 236 ClearObservers(); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 return false; | 357 return false; |
| 356 } | 358 } |
| 357 common_program_files_path = common_program_files; | 359 common_program_files_path = common_program_files; |
| 358 } | 360 } |
| 359 osk_path->insert(common_program_files_offset, common_program_files_path); | 361 osk_path->insert(common_program_files_offset, common_program_files_path); |
| 360 } | 362 } |
| 361 return !osk_path->empty(); | 363 return !osk_path->empty(); |
| 362 } | 364 } |
| 363 | 365 |
| 364 } // namespace ui | 366 } // namespace ui |
| OLD | NEW |