OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef WEBKIT_TOOLS_TEST_SHELL_FOREGROUND_HELPER_H_ | 5 #ifndef WEBKIT_TOOLS_TEST_SHELL_FOREGROUND_HELPER_H_ |
6 #define WEBKIT_TOOLS_TEST_SHELL_FOREGROUND_HELPER_H_ | 6 #define WEBKIT_TOOLS_TEST_SHELL_FOREGROUND_HELPER_H_ |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/window_impl.h" | 9 #include "base/window_impl.h" |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 return S_OK; | 31 return S_OK; |
32 } | 32 } |
33 | 33 |
34 private: | 34 private: |
35 HRESULT ForegroundHotKey(HWND window) { | 35 HRESULT ForegroundHotKey(HWND window) { |
36 // This implementation registers a hot key (F22) and then | 36 // This implementation registers a hot key (F22) and then |
37 // triggers the hot key. When receiving the hot key, we'll | 37 // triggers the hot key. When receiving the hot key, we'll |
38 // be in the foreground and allowed to move the target window | 38 // be in the foreground and allowed to move the target window |
39 // into the foreground too. | 39 // into the foreground too. |
40 | 40 |
41 set_window_ex_style(WS_POPUP); | 41 set_window_style(WS_POPUP); |
42 Init(NULL, gfx::Rect()); | 42 Init(NULL, gfx::Rect()); |
43 | 43 |
44 static const int hotkey_id = 0x0000baba; | 44 static const int hotkey_id = 0x0000baba; |
45 | 45 |
46 // Store the target window into our USERDATA for use in our | 46 // Store the target window into our USERDATA for use in our |
47 // HotKey handler. | 47 // HotKey handler. |
48 SetWindowLongPtr(GetNativeView(), GWLP_USERDATA, | 48 SetWindowLongPtr(hwnd(), GWLP_USERDATA, |
49 reinterpret_cast<ULONG_PTR>(window)); | 49 reinterpret_cast<ULONG_PTR>(window)); |
50 RegisterHotKey(GetNativeView(), hotkey_id, 0, VK_F22); | 50 RegisterHotKey(hwnd(), hotkey_id, 0, VK_F22); |
51 | 51 |
52 // If the calling thread is not yet a UI thread, call PeekMessage | 52 // If the calling thread is not yet a UI thread, call PeekMessage |
53 // to ensure creation of its message queue. | 53 // to ensure creation of its message queue. |
54 MSG msg = {0}; | 54 MSG msg = {0}; |
55 PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE); | 55 PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE); |
56 | 56 |
57 // Send the Hotkey. | 57 // Send the Hotkey. |
58 INPUT hotkey = {0}; | 58 INPUT hotkey = {0}; |
59 hotkey.type = INPUT_KEYBOARD; | 59 hotkey.type = INPUT_KEYBOARD; |
60 hotkey.ki.wVk = VK_F22; | 60 hotkey.ki.wVk = VK_F22; |
61 if (1 != SendInput(1, &hotkey, sizeof(hotkey))) | 61 if (1 != SendInput(1, &hotkey, sizeof(hotkey))) |
62 return E_FAIL; | 62 return E_FAIL; |
63 | 63 |
64 // Loop until we get the key. | 64 // Loop until we get the key. |
65 // TODO: It may be possible to get stuck here if the | 65 // TODO: It may be possible to get stuck here if the |
66 // message gets lost? | 66 // message gets lost? |
67 while (GetMessage(&msg, NULL, 0, 0)) { | 67 while (GetMessage(&msg, NULL, 0, 0)) { |
68 TranslateMessage(&msg); | 68 TranslateMessage(&msg); |
69 DispatchMessage(&msg); | 69 DispatchMessage(&msg); |
70 | 70 |
71 if (WM_HOTKEY == msg.message) | 71 if (WM_HOTKEY == msg.message) |
72 break; | 72 break; |
73 } | 73 } |
74 | 74 |
75 UnregisterHotKey(GetNativeView(), hotkey_id); | 75 UnregisterHotKey(hwnd(), hotkey_id); |
76 DestroyWindow(); | 76 DestroyWindow(hwnd()); |
77 | 77 |
78 return S_OK; | 78 return S_OK; |
79 } | 79 } |
80 | 80 |
81 // Handle the registered Hotkey being pressed. | 81 // Handle the registered Hotkey being pressed. |
82 LRESULT OnHotKey(UINT message, | 82 LRESULT OnHotKey(UINT message, |
83 WPARAM wparam, | 83 WPARAM wparam, |
84 LPARAM lparam, | 84 LPARAM lparam, |
85 BOOL& handled) { | 85 BOOL& handled) { |
86 HWND window = reinterpret_cast<HWND>(GetWindowLongPtr(GetNativeView(), | 86 HWND window = reinterpret_cast<HWND>(GetWindowLongPtr(hwnd(), |
87 GWLP_USERDATA)); | 87 GWLP_USERDATA)); |
88 SetForegroundWindow(window); | 88 SetForegroundWindow(window); |
89 return 1; | 89 return 1; |
90 } | 90 } |
91 }; | 91 }; |
92 | 92 |
93 #endif // WEBKIT_TOOLS_TEST_SHELL_FOREGROUND_HELPER_H_ | 93 #endif // WEBKIT_TOOLS_TEST_SHELL_FOREGROUND_HELPER_H_ |
OLD | NEW |