OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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 "ui/base/win/atl_module.h" |
| 11 |
| 12 namespace metro_driver { |
| 13 namespace { |
| 14 |
| 15 // An implementation of ITfInputScope interface. |
| 16 // This implementation only covers ITfInputScope::GetInputScopes since built-in |
| 17 // on-screen keyboard on Windows 8+ changes its layout depending on the returned |
| 18 // value of this method. |
| 19 // Although other advanced features of ITfInputScope such as phase list or |
| 20 // regex support might be useful for IMEs or on-screen keyboards in future, |
| 21 // no IME seems to be utilizing such features as of Windows 8.1. |
| 22 class ATL_NO_VTABLE InputScopeImpl |
| 23 : public CComObjectRootEx<CComMultiThreadModel>, |
| 24 public ITfInputScope { |
| 25 public: |
| 26 InputScopeImpl() {} |
| 27 |
| 28 BEGIN_COM_MAP(InputScopeImpl) |
| 29 COM_INTERFACE_ENTRY(ITfInputScope) |
| 30 END_COM_MAP() |
| 31 |
| 32 void Initialize(const std::vector<InputScope>& input_scopes) { |
| 33 input_scopes_ = input_scopes; |
| 34 } |
| 35 |
| 36 private: |
| 37 // ITfInputScope overrides: |
| 38 STDMETHOD(GetInputScopes)(InputScope** input_scopes, UINT* count) OVERRIDE { |
| 39 if (!count || !input_scopes) |
| 40 return E_INVALIDARG; |
| 41 *input_scopes = static_cast<InputScope*>( |
| 42 CoTaskMemAlloc(sizeof(InputScope) * input_scopes_.size())); |
| 43 if (!input_scopes) { |
| 44 *count = 0; |
| 45 return E_OUTOFMEMORY; |
| 46 } |
| 47 std::copy(input_scopes_.begin(), input_scopes_.end(), *input_scopes); |
| 48 *count = input_scopes_.size(); |
| 49 return S_OK; |
| 50 } |
| 51 STDMETHOD(GetPhrase)(BSTR** phrases, UINT* count) OVERRIDE { |
| 52 return E_NOTIMPL; |
| 53 } |
| 54 STDMETHOD(GetRegularExpression)(BSTR* regexp) OVERRIDE { |
| 55 return E_NOTIMPL; |
| 56 } |
| 57 STDMETHOD(GetSRGS)(BSTR* srgs) OVERRIDE { |
| 58 return E_NOTIMPL; |
| 59 } |
| 60 STDMETHOD(GetXML)(BSTR* xml) OVERRIDE { |
| 61 return E_NOTIMPL; |
| 62 } |
| 63 |
| 64 // Data which ITfInputScope::GetInputScopes should return. |
| 65 std::vector<InputScope> input_scopes_; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(InputScopeImpl); |
| 68 }; |
| 69 |
| 70 } // namespace |
| 71 |
| 72 base::win::ScopedComPtr<ITfInputScope> |
| 73 CreteInputScope(const std::vector<InputScope>& input_scopes) { |
| 74 ui::win::CreateATLModuleIfNeeded(); |
| 75 CComObject<InputScopeImpl>* object = NULL; |
| 76 if (FAILED(CComObject<InputScopeImpl>::CreateInstance(&object))) |
| 77 return base::win::ScopedComPtr<ITfInputScope>(); |
| 78 object->Initialize(input_scopes); |
| 79 return base::win::ScopedComPtr<ITfInputScope>(object); |
| 80 } |
| 81 |
| 82 } // namespace metro_driver |
OLD | NEW |