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

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

Issue 61923005: Make NativeTextfieldViews update the win system caret. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix typo and style issue Created 7 years, 1 month 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 #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 "ui/base/win/atl_module.h" 7 #include "ui/base/win/atl_module.h"
8 8
9 namespace base { 9 namespace base {
10 namespace win { 10 namespace win {
11 11
12 void SetInvisibleSystemCaretRect(HWND hwnd, gfx::Rect caret_rect) {
13 // Create an invisible bitmap.
14 HBITMAP caret_bitmap = CreateBitmap(1, caret_rect.height(), 1, 1, NULL);
15
16 // This destroys the previous caret (no matter what window it belonged to)
17 // and creates a new one owned by this window.
18 if (!CreateCaret(hwnd, caret_bitmap, 1, caret_rect.height()))
19 return;
20
21 ShowCaret(hwnd);
22 RECT window_rect;
23 GetWindowRect(hwnd, &window_rect);
24 SetCaretPos(caret_rect.x() - window_rect.left + 2,
25 caret_rect.y() - window_rect.top + 2);
26 DeleteObject(caret_bitmap);
sky 2013/11/07 01:34:42 Does caret_bitmap leak if CreateCaret returns fals
dmazzoni 2013/11/07 20:07:14 Good catch, done.
27 }
28
12 // UIA TextProvider implementation. 29 // UIA TextProvider implementation.
13 UIATextProvider::UIATextProvider() 30 UIATextProvider::UIATextProvider()
14 : editable_(false) {} 31 : editable_(false) {}
15 32
16 // static 33 // static
17 bool UIATextProvider::CreateTextProvider(bool editable, IUnknown** provider) { 34 bool UIATextProvider::CreateTextProvider(bool editable, IUnknown** provider) {
18 // Make sure ATL is initialized in this module. 35 // Make sure ATL is initialized in this module.
19 ui::win::CreateATLModuleIfNeeded(); 36 ui::win::CreateATLModuleIfNeeded();
20 37
21 CComObject<UIATextProvider>* text_provider = NULL; 38 CComObject<UIATextProvider>* text_provider = NULL;
22 HRESULT hr = CComObject<UIATextProvider>::CreateInstance(&text_provider); 39 HRESULT hr = CComObject<UIATextProvider>::CreateInstance(&text_provider);
23 if (SUCCEEDED(hr)) { 40 if (SUCCEEDED(hr)) {
24 DCHECK(text_provider); 41 DCHECK(text_provider);
25 text_provider->set_editable(editable); 42 text_provider->set_editable(editable);
26 text_provider->AddRef(); 43 text_provider->AddRef();
27 *provider = static_cast<ITextProvider*>(text_provider); 44 *provider = static_cast<ITextProvider*>(text_provider);
28 return true; 45 return true;
29 } 46 }
30 return false; 47 return false;
31 } 48 }
32 49
33 STDMETHODIMP UIATextProvider::get_IsReadOnly(BOOL* read_only) { 50 STDMETHODIMP UIATextProvider::get_IsReadOnly(BOOL* read_only) {
34 *read_only = !editable_; 51 *read_only = !editable_;
35 return S_OK; 52 return S_OK;
36 } 53 }
37 54
38 } // namespace win 55 } // namespace win
39 } // namespace base 56 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698