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 namespace metro_driver { | |
8 namespace { | |
9 | |
10 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.
| |
11 public: | |
12 explicit InputScopeImpl(const std::vector<InputScope>& input_scopes) | |
13 : ref_count_(0), | |
14 input_scopes_(input_scopes) {} | |
15 | |
16 // ITfInputScope overrides: | |
17 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.
| |
18 return InterlockedIncrement(&ref_count_); | |
19 } | |
20 STDMETHOD_(ULONG, Release)() OVERRIDE { | |
21 const LONG count = InterlockedDecrement(&ref_count_); | |
22 if (!count) { | |
23 delete this; | |
24 return 0; | |
25 } | |
26 return static_cast<ULONG>(count); | |
27 } | |
28 STDMETHOD(QueryInterface)(REFIID iid, void** result) OVERRIDE { | |
29 if (!result) | |
30 return E_INVALIDARG; | |
31 if (iid == IID_IUnknown || iid == IID_ITfInputScope) { | |
32 *result = static_cast<ITfInputScope*>(this); | |
33 } else { | |
34 *result = NULL; | |
35 return E_NOINTERFACE; | |
36 } | |
37 AddRef(); | |
38 return S_OK; | |
39 } | |
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 = 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 private: | |
67 // 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)
| |
68 volatile LONG ref_count_; | |
69 // Data which ITfInputScope::GetInputScopes should return. | |
70 const std::vector<InputScope> input_scopes_; | |
71 | |
72 DISALLOW_COPY_AND_ASSIGN(InputScopeImpl); | |
73 }; | |
74 | |
75 } // namespace | |
76 | |
77 base::win::ScopedComPtr<ITfInputScope> | |
78 CreteInputScope(const std::vector<InputScope>& input_scopes) { | |
79 return base::win::ScopedComPtr<ITfInputScope>( | |
80 new InputScopeImpl(input_scopes)); | |
81 } | |
82 | |
83 } // namespace metro_driver | |
OLD | NEW |