Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: ui/base/win/osk_display_manager.cc

Issue 2971363002: Detect if osk is visible on windows (Closed)
Patch Set: Refactoring base function Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/base/win/osk_display_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // upto a maximum of kDismissKeyboardMaxRetries. 56 // upto a maximum of kDismissKeyboardMaxRetries.
57 bool DismissKeyboard(); 57 bool DismissKeyboard();
58 58
59 // Add/Remove keyboard observers. 59 // Add/Remove keyboard observers.
60 // Please note that this class does not track the |observer| destruction. It 60 // Please note that this class does not track the |observer| destruction. It
61 // is upto the classes which set up these observers to remove them when they 61 // is upto the classes which set up these observers to remove them when they
62 // are destroyed. 62 // are destroyed.
63 void AddObserver(OnScreenKeyboardObserver* observer); 63 void AddObserver(OnScreenKeyboardObserver* observer);
64 void RemoveObserver(OnScreenKeyboardObserver* observer); 64 void RemoveObserver(OnScreenKeyboardObserver* observer);
65 65
66 // Returns true if the osk is visible. Sets osk bounding rect if non-null
67 static bool IsKeyboardVisible(gfx::Rect* osk_bounding_rect);
68
66 private: 69 private:
67 // Executes as a task and detects if the on screen keyboard is displayed. 70 // Executes as a task and detects if the on screen keyboard is displayed.
68 // Once the keyboard is displayed it schedules the HideIfNecessary() task to 71 // Once the keyboard is displayed it schedules the HideIfNecessary() task to
69 // detect when the keyboard is or should be hidden. 72 // detect when the keyboard is or should be hidden.
70 void CheckIfKeyboardVisible(); 73 void CheckIfKeyboardVisible();
71 74
72 // Executes as a task and detects if the keyboard was hidden or should be 75 // Executes as a task and detects if the keyboard was hidden or should be
73 // hidden. 76 // hidden.
74 void HideIfNecessary(); 77 void HideIfNecessary();
75 78
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 162
160 void OnScreenKeyboardDetector::AddObserver(OnScreenKeyboardObserver* observer) { 163 void OnScreenKeyboardDetector::AddObserver(OnScreenKeyboardObserver* observer) {
161 observers_.AddObserver(observer); 164 observers_.AddObserver(observer);
162 } 165 }
163 166
164 void OnScreenKeyboardDetector::RemoveObserver( 167 void OnScreenKeyboardDetector::RemoveObserver(
165 OnScreenKeyboardObserver* observer) { 168 OnScreenKeyboardObserver* observer) {
166 observers_.RemoveObserver(observer); 169 observers_.RemoveObserver(observer);
167 } 170 }
168 171
169 void OnScreenKeyboardDetector::CheckIfKeyboardVisible() { 172 // static
173 bool OnScreenKeyboardDetector::IsKeyboardVisible(gfx::Rect* osk_bounding_rect) {
170 HWND osk = ::FindWindow(kOSKClassName, nullptr); 174 HWND osk = ::FindWindow(kOSKClassName, nullptr);
171 if (!::IsWindow(osk)) 175 if (!::IsWindow(osk))
172 return; 176 return false;
177 if (osk_bounding_rect) {
178 RECT osk_rect = {};
179 ::GetWindowRect(osk, &osk_rect);
180 *osk_bounding_rect = gfx::Rect(osk_rect);
181 }
182 return ::IsWindowVisible(osk) && ::IsWindowEnabled(osk);
183 }
173 184
174 RECT osk_rect = {}; 185 void OnScreenKeyboardDetector::CheckIfKeyboardVisible() {
175 ::GetWindowRect(osk, &osk_rect); 186 if (IsKeyboardVisible(&osk_rect_pixels_)) {
176 osk_rect_pixels_ = gfx::Rect(osk_rect);
177 if (::IsWindowVisible(osk) && ::IsWindowEnabled(osk)) {
178 if (!osk_visible_notification_received_) 187 if (!osk_visible_notification_received_)
179 HandleKeyboardVisible(); 188 HandleKeyboardVisible();
180 } else { 189 } else {
181 DVLOG(1) << "OSK did not come up in 1 second. Something wrong."; 190 DVLOG(1) << "OSK did not come up in 1 second. Something wrong.";
182 } 191 }
183 } 192 }
184 193
185 void OnScreenKeyboardDetector::HideIfNecessary() { 194 void OnScreenKeyboardDetector::HideIfNecessary() {
186 HWND osk = ::FindWindow(kOSKClassName, nullptr); 195 HWND osk = ::FindWindow(kOSKClassName, nullptr);
187 if (!::IsWindow(osk)) 196 if (!::IsWindow(osk))
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 &common_program_files))) { 362 &common_program_files))) {
354 return false; 363 return false;
355 } 364 }
356 common_program_files_path = common_program_files; 365 common_program_files_path = common_program_files;
357 } 366 }
358 osk_path->insert(common_program_files_offset, common_program_files_path); 367 osk_path->insert(common_program_files_offset, common_program_files_path);
359 } 368 }
360 return !osk_path->empty(); 369 return !osk_path->empty();
361 } 370 }
362 371
372 bool OnScreenKeyboardDisplayManager::IsKeyboardVisible() const {
373 return OnScreenKeyboardDetector::IsKeyboardVisible(nullptr);
374 }
375
363 } // namespace ui 376 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/win/osk_display_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698