| 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..bbe9cd3d06035a438f4e9736cccc58f851eae6dc
|
| --- /dev/null
|
| +++ b/win8/metro_driver/ime/input_scope.cc
|
| @@ -0,0 +1,82 @@
|
| +// 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 {
|
| + public:
|
| + explicit InputScopeImpl(const std::vector<InputScope>& input_scopes)
|
| + : ref_count_(0),
|
| + input_scopes_(input_scopes) {}
|
| +
|
| + // ITfInputScope overrides:
|
| + STDMETHOD_(ULONG, AddRef)() OVERRIDE {
|
| + 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.
|
| + volatile LONG ref_count_;
|
| + // The corresponding text input types.
|
| + const std::vector<InputScope> input_scopes_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(InputScopeImpl);
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +base::win::ScopedComPtr<IUnknown>
|
| +CreteInputScope(const std::vector<InputScope>& input_scopes) {
|
| + return base::win::ScopedComPtr<IUnknown>(new InputScopeImpl(input_scopes));
|
| +}
|
| +
|
| +} // namespace metro_driver
|
|
|