Chromium Code Reviews| Index: win8/metro_driver/ime/input_scope.cc |
| diff --git a/win8/metro_driver/ime/input_scope.cc b/win8/metro_driver/ime/input_scope.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..24772fdd961874bc16fe8d30568d1d11fbda5d71 |
| --- /dev/null |
| +++ b/win8/metro_driver/ime/input_scope.cc |
| @@ -0,0 +1,83 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "win8/metro_driver/ime/input_scope.h" |
| + |
| +namespace metro_driver { |
| +namespace { |
| + |
| +class InputScopeImpl : public ITfInputScope { |
|
ananta
2013/11/27 02:27:44
Please add some comments about the functionality p
yukawa
2013/11/27 11:30:04
Done.
|
| + public: |
| + explicit InputScopeImpl(const std::vector<InputScope>& input_scopes) |
| + : ref_count_(0), |
| + input_scopes_(input_scopes) {} |
| + |
| + // ITfInputScope overrides: |
| + STDMETHOD_(ULONG, AddRef)() OVERRIDE { |
|
ananta
2013/11/27 02:27:44
Can we use ATL here instead of implementing IUnkno
yukawa
2013/11/27 11:30:04
Done.
|
| + return InterlockedIncrement(&ref_count_); |
| + } |
| + STDMETHOD_(ULONG, Release)() OVERRIDE { |
| + const LONG count = InterlockedDecrement(&ref_count_); |
| + if (!count) { |
| + delete this; |
| + return 0; |
| + } |
| + return static_cast<ULONG>(count); |
| + } |
| + STDMETHOD(QueryInterface)(REFIID iid, void** result) OVERRIDE { |
| + if (!result) |
| + return E_INVALIDARG; |
| + if (iid == IID_IUnknown || iid == IID_ITfInputScope) { |
| + *result = static_cast<ITfInputScope*>(this); |
| + } else { |
| + *result = NULL; |
| + return E_NOINTERFACE; |
| + } |
| + AddRef(); |
| + return S_OK; |
| + } |
| + STDMETHOD(GetInputScopes)(InputScope** input_scopes, UINT* count) OVERRIDE { |
| + if (!count || !input_scopes) |
| + return E_INVALIDARG; |
| + *input_scopes = static_cast<InputScope*>( |
| + CoTaskMemAlloc(sizeof(InputScope) * input_scopes_.size())); |
| + if (!input_scopes) { |
| + *count = 0; |
| + return E_OUTOFMEMORY; |
| + } |
| + std::copy(input_scopes_.begin(), input_scopes_.end(), *input_scopes); |
| + *count = input_scopes_.size(); |
| + return S_OK; |
| + } |
| + STDMETHOD(GetPhrase)(BSTR** phrases, UINT* count) OVERRIDE { |
| + return E_NOTIMPL; |
| + } |
| + STDMETHOD(GetRegularExpression)(BSTR* regexp) OVERRIDE { |
| + return E_NOTIMPL; |
| + } |
| + STDMETHOD(GetSRGS)(BSTR* srgs) OVERRIDE { |
| + return E_NOTIMPL; |
| + } |
| + STDMETHOD(GetXML)(BSTR* xml) OVERRIDE { |
| + return E_NOTIMPL; |
| + } |
| + |
| + private: |
| + // The refrence count of this instance. |
|
ananta
2013/11/27 02:27:44
reference
yukawa
2013/11/27 11:30:04
Done. (Removed thanks to ATL)
|
| + volatile LONG ref_count_; |
| + // Data which ITfInputScope::GetInputScopes should return. |
| + const std::vector<InputScope> input_scopes_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(InputScopeImpl); |
| +}; |
| + |
| +} // namespace |
| + |
| +base::win::ScopedComPtr<ITfInputScope> |
| +CreteInputScope(const std::vector<InputScope>& input_scopes) { |
| + return base::win::ScopedComPtr<ITfInputScope>( |
| + new InputScopeImpl(input_scopes)); |
| +} |
| + |
| +} // namespace metro_driver |