OLD | NEW |
| (Empty) |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "win8/metro_driver/ime/input_scope.h" | |
6 | |
7 #include <atlbase.h> | |
8 #include <atlcom.h> | |
9 | |
10 #include "base/logging.h" | |
11 #include "base/macros.h" | |
12 #include "ui/base/win/atl_module.h" | |
13 | |
14 namespace metro_driver { | |
15 namespace { | |
16 | |
17 // An implementation of ITfInputScope interface. | |
18 // This implementation only covers ITfInputScope::GetInputScopes since built-in | |
19 // on-screen keyboard on Windows 8+ changes its layout depending on the returned | |
20 // value of this method. | |
21 // Although other advanced features of ITfInputScope such as phase list or | |
22 // regex support might be useful for IMEs or on-screen keyboards in future, | |
23 // no IME seems to be utilizing such features as of Windows 8.1. | |
24 class ATL_NO_VTABLE InputScopeImpl | |
25 : public CComObjectRootEx<CComMultiThreadModel>, | |
26 public ITfInputScope { | |
27 public: | |
28 InputScopeImpl() {} | |
29 | |
30 BEGIN_COM_MAP(InputScopeImpl) | |
31 COM_INTERFACE_ENTRY(ITfInputScope) | |
32 END_COM_MAP() | |
33 | |
34 void Initialize(const std::vector<InputScope>& input_scopes) { | |
35 input_scopes_ = input_scopes; | |
36 } | |
37 | |
38 private: | |
39 // ITfInputScope overrides: | |
40 STDMETHOD(GetInputScopes)(InputScope** input_scopes, UINT* count) override { | |
41 if (!count || !input_scopes) | |
42 return E_INVALIDARG; | |
43 *input_scopes = static_cast<InputScope*>( | |
44 CoTaskMemAlloc(sizeof(InputScope) * input_scopes_.size())); | |
45 if (!input_scopes) { | |
46 *count = 0; | |
47 return E_OUTOFMEMORY; | |
48 } | |
49 std::copy(input_scopes_.begin(), input_scopes_.end(), *input_scopes); | |
50 *count = static_cast<UINT>(input_scopes_.size()); | |
51 return S_OK; | |
52 } | |
53 STDMETHOD(GetPhrase)(BSTR** phrases, UINT* count) override { | |
54 return E_NOTIMPL; | |
55 } | |
56 STDMETHOD(GetRegularExpression)(BSTR* regexp) override { | |
57 return E_NOTIMPL; | |
58 } | |
59 STDMETHOD(GetSRGS)(BSTR* srgs) override { | |
60 return E_NOTIMPL; | |
61 } | |
62 STDMETHOD(GetXML)(BSTR* xml) override { | |
63 return E_NOTIMPL; | |
64 } | |
65 | |
66 // Data which ITfInputScope::GetInputScopes should return. | |
67 std::vector<InputScope> input_scopes_; | |
68 | |
69 DISALLOW_COPY_AND_ASSIGN(InputScopeImpl); | |
70 }; | |
71 | |
72 } // namespace | |
73 | |
74 base::win::ScopedComPtr<ITfInputScope> | |
75 CreteInputScope(const std::vector<InputScope>& input_scopes) { | |
76 ui::win::CreateATLModuleIfNeeded(); | |
77 CComObject<InputScopeImpl>* object = NULL; | |
78 HRESULT hr = CComObject<InputScopeImpl>::CreateInstance(&object); | |
79 if (FAILED(hr)) { | |
80 LOG(ERROR) << "CComObject<InputScopeImpl>::CreateInstance failed. hr = " | |
81 << hr; | |
82 return base::win::ScopedComPtr<ITfInputScope>(); | |
83 } | |
84 object->Initialize(input_scopes); | |
85 return base::win::ScopedComPtr<ITfInputScope>(object); | |
86 } | |
87 | |
88 } // namespace metro_driver | |
OLD | NEW |