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

Side by Side Diff: base/win/win_util.cc

Issue 1986153005: The on screen keyboard on Windows 8+ should not obscure the input field. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove include Created 4 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/win/win_util.h" 5 #include "base/win/win_util.h"
6 6
7 #include <aclapi.h> 7 #include <aclapi.h>
8 #include <cfgmgr32.h> 8 #include <cfgmgr32.h>
9 #include <lm.h> 9 #include <lm.h>
10 #include <powrprof.h> 10 #include <powrprof.h>
11 #include <shellapi.h>
12 #include <shlobj.h>
13 #include <shobjidl.h> // Must be before propkey. 11 #include <shobjidl.h> // Must be before propkey.
14 #include <initguid.h> 12 #include <initguid.h>
15 #include <inspectable.h> 13 #include <inspectable.h>
16 #include <propkey.h> 14 #include <propkey.h>
17 #include <propvarutil.h> 15 #include <propvarutil.h>
18 #include <psapi.h> 16 #include <psapi.h>
19 #include <roapi.h> 17 #include <roapi.h>
20 #include <sddl.h> 18 #include <sddl.h>
21 #include <setupapi.h> 19 #include <setupapi.h>
22 #include <signal.h> 20 #include <signal.h>
23 #include <stddef.h> 21 #include <stddef.h>
24 #include <stdlib.h> 22 #include <stdlib.h>
25 #include <tchar.h> // Must be before tpcshrd.h or for any use of _T macro 23 #include <tchar.h> // Must be before tpcshrd.h or for any use of _T macro
26 #include <tpcshrd.h> 24 #include <tpcshrd.h>
27 #include <uiviewsettingsinterop.h> 25 #include <uiviewsettingsinterop.h>
28 #include <windows.ui.viewmanagement.h> 26 #include <windows.ui.viewmanagement.h>
29 #include <winstring.h> 27 #include <winstring.h>
30 #include <wrl/wrappers/corewrappers.h> 28 #include <wrl/wrappers/corewrappers.h>
31 29
32 #include <memory> 30 #include <memory>
33 31
34 #include "base/base_switches.h" 32 #include "base/base_switches.h"
35 #include "base/command_line.h" 33 #include "base/command_line.h"
36 #include "base/lazy_instance.h" 34 #include "base/lazy_instance.h"
37 #include "base/logging.h" 35 #include "base/logging.h"
38 #include "base/macros.h" 36 #include "base/macros.h"
37 #include "base/memory/singleton.h"
39 #include "base/strings/string_util.h" 38 #include "base/strings/string_util.h"
40 #include "base/strings/stringprintf.h" 39 #include "base/strings/stringprintf.h"
41 #include "base/strings/utf_string_conversions.h" 40 #include "base/strings/utf_string_conversions.h"
42 #include "base/threading/thread_restrictions.h" 41 #include "base/threading/thread_restrictions.h"
42 #include "base/win/osk_display_manager.h"
43 #include "base/win/registry.h" 43 #include "base/win/registry.h"
44 #include "base/win/scoped_co_mem.h"
45 #include "base/win/scoped_comptr.h" 44 #include "base/win/scoped_comptr.h"
46 #include "base/win/scoped_handle.h" 45 #include "base/win/scoped_handle.h"
47 #include "base/win/scoped_propvariant.h" 46 #include "base/win/scoped_propvariant.h"
48 #include "base/win/windows_version.h" 47 #include "base/win/windows_version.h"
49 48
50 namespace base { 49 namespace base {
51 namespace win { 50 namespace win {
52 51
53 namespace { 52 namespace {
54 53
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 99 }
101 100
102 return false; 101 return false;
103 } 102 }
104 103
105 const bool value_; 104 const bool value_;
106 105
107 DISALLOW_COPY_AND_ASSIGN(LazyIsUser32AndGdi32Available); 106 DISALLOW_COPY_AND_ASSIGN(LazyIsUser32AndGdi32Available);
108 }; 107 };
109 108
110 const wchar_t kWindows8OSKRegPath[] =
111 L"Software\\Classes\\CLSID\\{054AAE20-4BEA-4347-8A35-64A533254A9D}"
112 L"\\LocalServer32";
113
114 // Returns the current platform role. We use the PowerDeterminePlatformRoleEx 109 // Returns the current platform role. We use the PowerDeterminePlatformRoleEx
115 // API for that. 110 // API for that.
116 POWER_PLATFORM_ROLE GetPlatformRole() { 111 POWER_PLATFORM_ROLE GetPlatformRole() {
117 return PowerDeterminePlatformRoleEx(POWER_PLATFORM_ROLE_V2); 112 return PowerDeterminePlatformRoleEx(POWER_PLATFORM_ROLE_V2);
118 } 113 }
119 114
120 } // namespace 115 } // namespace
121 116
122 // Uses the Windows 10 WRL API's to query the current system state. The API's 117 // Uses the Windows 10 WRL API's to query the current system state. The API's
123 // we are using in the function below are supported in Win32 apps as per msdn. 118 // we are using in the function below are supported in Win32 apps as per msdn.
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 } 514 }
520 } 515 }
521 } else { 516 } else {
522 if (reason) 517 if (reason)
523 *reason += "Device role is not mobile or slate.\n"; 518 *reason += "Device role is not mobile or slate.\n";
524 } 519 }
525 return is_tablet; 520 return is_tablet;
526 } 521 }
527 522
528 bool DisplayVirtualKeyboard() { 523 bool DisplayVirtualKeyboard() {
529 if (GetVersion() < VERSION_WIN8) 524 DCHECK(OnScreenKeyboardDisplayManager::GetInstance());
530 return false; 525 return OnScreenKeyboardDisplayManager::
531 526 GetInstance()->DisplayVirtualKeyboard(nullptr); // !keyboard_observer.
532 if (IsKeyboardPresentOnSlate(nullptr))
533 return false;
534
535 static LazyInstance<string16>::Leaky osk_path = LAZY_INSTANCE_INITIALIZER;
536
537 if (osk_path.Get().empty()) {
538 // We need to launch TabTip.exe from the location specified under the
539 // LocalServer32 key for the {{054AAE20-4BEA-4347-8A35-64A533254A9D}}
540 // CLSID.
541 // TabTip.exe is typically found at
542 // c:\program files\common files\microsoft shared\ink on English Windows.
543 // We don't want to launch TabTip.exe from
544 // c:\program files (x86)\common files\microsoft shared\ink. This path is
545 // normally found on 64 bit Windows.
546 RegKey key(HKEY_LOCAL_MACHINE, kWindows8OSKRegPath,
547 KEY_READ | KEY_WOW64_64KEY);
548 DWORD osk_path_length = 1024;
549 if (key.ReadValue(NULL,
550 WriteInto(&osk_path.Get(), osk_path_length),
551 &osk_path_length,
552 NULL) != ERROR_SUCCESS) {
553 DLOG(WARNING) << "Failed to read on screen keyboard path from registry";
554 return false;
555 }
556 size_t common_program_files_offset =
557 osk_path.Get().find(L"%CommonProgramFiles%");
558 // Typically the path to TabTip.exe read from the registry will start with
559 // %CommonProgramFiles% which needs to be replaced with the corrsponding
560 // expanded string.
561 // If the path does not begin with %CommonProgramFiles% we use it as is.
562 if (common_program_files_offset != string16::npos) {
563 // Preserve the beginning quote in the path.
564 osk_path.Get().erase(common_program_files_offset,
565 wcslen(L"%CommonProgramFiles%"));
566 // The path read from the registry contains the %CommonProgramFiles%
567 // environment variable prefix. On 64 bit Windows the SHGetKnownFolderPath
568 // function returns the common program files path with the X86 suffix for
569 // the FOLDERID_ProgramFilesCommon value.
570 // To get the correct path to TabTip.exe we first read the environment
571 // variable CommonProgramW6432 which points to the desired common
572 // files path. Failing that we fallback to the SHGetKnownFolderPath API.
573
574 // We then replace the %CommonProgramFiles% value with the actual common
575 // files path found in the process.
576 string16 common_program_files_path;
577 std::unique_ptr<wchar_t[]> common_program_files_wow6432;
578 DWORD buffer_size =
579 GetEnvironmentVariable(L"CommonProgramW6432", NULL, 0);
580 if (buffer_size) {
581 common_program_files_wow6432.reset(new wchar_t[buffer_size]);
582 GetEnvironmentVariable(L"CommonProgramW6432",
583 common_program_files_wow6432.get(),
584 buffer_size);
585 common_program_files_path = common_program_files_wow6432.get();
586 DCHECK(!common_program_files_path.empty());
587 } else {
588 ScopedCoMem<wchar_t> common_program_files;
589 if (FAILED(SHGetKnownFolderPath(FOLDERID_ProgramFilesCommon, 0, NULL,
590 &common_program_files))) {
591 return false;
592 }
593 common_program_files_path = common_program_files;
594 }
595
596 osk_path.Get().insert(1, common_program_files_path);
597 }
598 }
599
600 HINSTANCE ret = ::ShellExecuteW(NULL,
601 L"",
602 osk_path.Get().c_str(),
603 NULL,
604 NULL,
605 SW_SHOW);
606 return reinterpret_cast<intptr_t>(ret) > 32;
607 } 527 }
608 528
609 bool DismissVirtualKeyboard() { 529 bool DismissVirtualKeyboard() {
610 if (GetVersion() < VERSION_WIN8) 530 DCHECK(OnScreenKeyboardDisplayManager::GetInstance());
611 return false; 531 return OnScreenKeyboardDisplayManager::
612 532 GetInstance()->DismissVirtualKeyboard(nullptr); // !keyboard_observer.
613 // We dismiss the virtual keyboard by generating the ESC keystroke
614 // programmatically.
615 const wchar_t kOSKClassName[] = L"IPTip_Main_Window";
616 HWND osk = ::FindWindow(kOSKClassName, NULL);
617 if (::IsWindow(osk) && ::IsWindowEnabled(osk)) {
618 PostMessage(osk, WM_SYSCOMMAND, SC_CLOSE, 0);
619 return true;
620 }
621 return false;
622 } 533 }
623 534
624 enum DomainEnrollementState {UNKNOWN = -1, NOT_ENROLLED, ENROLLED}; 535 enum DomainEnrollementState {UNKNOWN = -1, NOT_ENROLLED, ENROLLED};
625 static volatile long int g_domain_state = UNKNOWN; 536 static volatile long int g_domain_state = UNKNOWN;
626 537
627 bool IsEnrolledToDomain() { 538 bool IsEnrolledToDomain() {
628 // Doesn't make any sense to retry inside a user session because joining a 539 // Doesn't make any sense to retry inside a user session because joining a
629 // domain will only kick in on a restart. 540 // domain will only kick in on a restart.
630 if (g_domain_state == UNKNOWN) { 541 if (g_domain_state == UNKNOWN) {
631 LPWSTR domain; 542 LPWSTR domain;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 } 611 }
701 612
702 void DisableFlicks(HWND hwnd) { 613 void DisableFlicks(HWND hwnd) {
703 ::SetProp(hwnd, MICROSOFT_TABLETPENSERVICE_PROPERTY, 614 ::SetProp(hwnd, MICROSOFT_TABLETPENSERVICE_PROPERTY,
704 reinterpret_cast<HANDLE>(TABLET_DISABLE_FLICKS | 615 reinterpret_cast<HANDLE>(TABLET_DISABLE_FLICKS |
705 TABLET_DISABLE_FLICKFALLBACKKEYS)); 616 TABLET_DISABLE_FLICKFALLBACKKEYS));
706 } 617 }
707 618
708 } // namespace win 619 } // namespace win
709 } // namespace base 620 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698