OLD | NEW |
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 #include "ui/base/win/accessibility_misc_utils.h" | 4 #include "ui/base/win/accessibility_misc_utils.h" |
5 | 5 |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/win/scoped_gdi_object.h" |
7 #include "ui/base/win/atl_module.h" | 8 #include "ui/base/win/atl_module.h" |
8 | 9 |
9 namespace base { | 10 namespace base { |
10 namespace win { | 11 namespace win { |
11 | 12 |
| 13 void SetInvisibleSystemCaretRect(HWND hwnd, const gfx::Rect& caret_rect) { |
| 14 // Create an invisible bitmap. |
| 15 base::win::ScopedGDIObject<HBITMAP> caret_bitmap( |
| 16 CreateBitmap(1, caret_rect.height(), 1, 1, NULL)); |
| 17 |
| 18 // This destroys the previous caret (no matter what window it belonged to) |
| 19 // and creates a new one owned by this window. |
| 20 if (!CreateCaret(hwnd, caret_bitmap, 1, caret_rect.height())) |
| 21 return; |
| 22 |
| 23 ShowCaret(hwnd); |
| 24 RECT window_rect; |
| 25 GetWindowRect(hwnd, &window_rect); |
| 26 SetCaretPos(caret_rect.x() - window_rect.left + 2, |
| 27 caret_rect.y() - window_rect.top + 2); |
| 28 } |
| 29 |
12 // UIA TextProvider implementation. | 30 // UIA TextProvider implementation. |
13 UIATextProvider::UIATextProvider() | 31 UIATextProvider::UIATextProvider() |
14 : editable_(false) {} | 32 : editable_(false) {} |
15 | 33 |
16 // static | 34 // static |
17 bool UIATextProvider::CreateTextProvider(bool editable, IUnknown** provider) { | 35 bool UIATextProvider::CreateTextProvider(bool editable, IUnknown** provider) { |
18 // Make sure ATL is initialized in this module. | 36 // Make sure ATL is initialized in this module. |
19 ui::win::CreateATLModuleIfNeeded(); | 37 ui::win::CreateATLModuleIfNeeded(); |
20 | 38 |
21 CComObject<UIATextProvider>* text_provider = NULL; | 39 CComObject<UIATextProvider>* text_provider = NULL; |
22 HRESULT hr = CComObject<UIATextProvider>::CreateInstance(&text_provider); | 40 HRESULT hr = CComObject<UIATextProvider>::CreateInstance(&text_provider); |
23 if (SUCCEEDED(hr)) { | 41 if (SUCCEEDED(hr)) { |
24 DCHECK(text_provider); | 42 DCHECK(text_provider); |
25 text_provider->set_editable(editable); | 43 text_provider->set_editable(editable); |
26 text_provider->AddRef(); | 44 text_provider->AddRef(); |
27 *provider = static_cast<ITextProvider*>(text_provider); | 45 *provider = static_cast<ITextProvider*>(text_provider); |
28 return true; | 46 return true; |
29 } | 47 } |
30 return false; | 48 return false; |
31 } | 49 } |
32 | 50 |
33 STDMETHODIMP UIATextProvider::get_IsReadOnly(BOOL* read_only) { | 51 STDMETHODIMP UIATextProvider::get_IsReadOnly(BOOL* read_only) { |
34 *read_only = !editable_; | 52 *read_only = !editable_; |
35 return S_OK; | 53 return S_OK; |
36 } | 54 } |
37 | 55 |
38 } // namespace win | 56 } // namespace win |
39 } // namespace base | 57 } // namespace base |
OLD | NEW |