summaryrefslogtreecommitdiffstats
path: root/win8/metro_driver
diff options
context:
space:
mode:
authoryukawa@chromium.org <yukawa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-11 02:37:45 +0000
committeryukawa@chromium.org <yukawa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-11 02:37:45 +0000
commitf180513858d93f060593d0fb50de5b59b6dc3487 (patch)
tree8f10d991bbbc4c4cc129dd7e24302876b84e68ff /win8/metro_driver
parent8be5344d42caeff97ff8eaadf9220fa9383852d1 (diff)
downloadchromium_src-f180513858d93f060593d0fb50de5b59b6dc3487.zip
chromium_src-f180513858d93f060593d0fb50de5b59b6dc3487.tar.gz
chromium_src-f180513858d93f060593d0fb50de5b59b6dc3487.tar.bz2
Ash: Use ATL to implement TsfTextStore.
This is just a cleanup CL that never changes current behavior. This CL uses CComObjectRootEx to avoid boilerplate COM implementation code BUG=326912 TEST=manually done on Windows 8.1 Review URL: https://codereview.chromium.org/109723002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239972 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'win8/metro_driver')
-rw-r--r--win8/metro_driver/ime/text_store.cc95
-rw-r--r--win8/metro_driver/ime/text_store.h42
2 files changed, 64 insertions, 73 deletions
diff --git a/win8/metro_driver/ime/text_store.cc b/win8/metro_driver/ime/text_store.cc
index 960af56..4652a7f 100644
--- a/win8/metro_driver/ime/text_store.cc
+++ b/win8/metro_driver/ime/text_store.cc
@@ -2,15 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#define INITGUID // required for GUID_PROP_INPUTSCOPE
#include "win8/metro_driver/ime/text_store.h"
-#include <InputScope.h>
-#include <OleCtl.h>
-
#include <algorithm>
#include "base/win/scoped_variant.h"
+#include "ui/base/win/atl_module.h"
#include "win8/metro_driver/ime/input_scope.h"
#include "win8/metro_driver/ime/text_store_delegate.h"
@@ -22,23 +19,21 @@ const TsViewCookie kViewCookie = 1;
} // namespace
-TSFTextStore::TSFTextStore(HWND window_handle,
- ITfCategoryMgr* category_manager,
- ITfDisplayAttributeMgr* display_attribute_manager,
- ITfInputScope* input_scope,
- TextStoreDelegate* delegate)
- : ref_count_(0),
- text_store_acp_sink_mask_(0),
- window_handle_(window_handle),
- delegate_(delegate),
+TSFTextStore::TSFTextStore()
+ : text_store_acp_sink_mask_(0),
+ window_handle_(NULL),
+ delegate_(NULL),
committed_size_(0),
selection_start_(0),
selection_end_(0),
edit_flag_(false),
current_lock_type_(0),
- category_manager_(category_manager),
- display_attribute_manager_(display_attribute_manager),
- input_scope_(input_scope) {
+ category_manager_(NULL),
+ display_attribute_manager_(NULL),
+ input_scope_(NULL) {
+}
+
+TSFTextStore::~TSFTextStore() {
}
// static
@@ -68,45 +63,36 @@ scoped_refptr<TSFTextStore> TSFTextStore::Create(
LOG(ERROR) << "Failed to initialize InputScope.";
return scoped_refptr<TSFTextStore>();
}
- return scoped_refptr<TSFTextStore>(
- new TSFTextStore(window_handle,
- category_manager,
- display_attribute_manager,
- input_scope,
- delegate));
-}
-
-TSFTextStore::~TSFTextStore() {
-}
-
-ULONG STDMETHODCALLTYPE TSFTextStore::AddRef() {
- return InterlockedIncrement(&ref_count_);
-}
-ULONG STDMETHODCALLTYPE TSFTextStore::Release() {
- const LONG count = InterlockedDecrement(&ref_count_);
- if (!count) {
- delete this;
- return 0;
+ ui::win::CreateATLModuleIfNeeded();
+ CComObject<TSFTextStore>* object = NULL;
+ hr = CComObject<TSFTextStore>::CreateInstance(&object);
+ if (FAILED(hr)) {
+ LOG(ERROR) << "CComObject<TSFTextStore>::CreateInstance failed. hr = "
+ << hr;
+ return scoped_refptr<TSFTextStore>();
}
- return static_cast<ULONG>(count);
+ object->Initialize(window_handle,
+ category_manager,
+ display_attribute_manager,
+ input_scope,
+ delegate);
+ return scoped_refptr<TSFTextStore>(object);
}
-STDMETHODIMP TSFTextStore::QueryInterface(REFIID iid, void** result) {
- if (iid == IID_IUnknown || iid == IID_ITextStoreACP) {
- *result = static_cast<ITextStoreACP*>(this);
- } else if (iid == IID_ITfContextOwnerCompositionSink) {
- *result = static_cast<ITfContextOwnerCompositionSink*>(this);
- } else if (iid == IID_ITfTextEditSink) {
- *result = static_cast<ITfTextEditSink*>(this);
- } else {
- *result = NULL;
- return E_NOINTERFACE;
- }
- AddRef();
- return S_OK;
+void TSFTextStore::Initialize(HWND window_handle,
+ ITfCategoryMgr* category_manager,
+ ITfDisplayAttributeMgr* display_attribute_manager,
+ ITfInputScope* input_scope,
+ TextStoreDelegate* delegate) {
+ window_handle_ = window_handle;
+ category_manager_ = category_manager;
+ display_attribute_manager_ = display_attribute_manager;
+ input_scope_ = input_scope;
+ delegate_ = delegate;
}
+
STDMETHODIMP TSFTextStore::AdviseSink(REFIID iid,
IUnknown* unknown,
DWORD mask) {
@@ -282,9 +268,8 @@ STDMETHODIMP TSFTextStore::GetText(LONG acp_start,
const string16& result =
string_buffer_.substr(acp_start, *text_buffer_copied);
- for (size_t i = 0; i < result.size(); ++i) {
+ for (size_t i = 0; i < result.size(); ++i)
text_buffer[i] = result[i];
- }
if (run_info_buffer_size) {
run_info_buffer[0].uCount = *text_buffer_copied;
@@ -359,11 +344,10 @@ STDMETHODIMP TSFTextStore::GetTextExt(TsViewCookie view_cookie,
// Hack for PPAPI flash. PPAPI flash does not support GetCaretBounds, so
// it's better to return previous caret rectangle instead.
// TODO(nona, kinaba): Remove this hack.
- if (start_pos == 0) {
+ if (start_pos == 0)
result = delegate_->GetCaretBounds();
- } else {
+ else
return TS_E_NOLAYOUT;
- }
}
}
@@ -417,9 +401,8 @@ STDMETHODIMP TSFTextStore::InsertTextAtSelection(DWORD flags,
return TS_E_NOLOCK;
if (acp_start)
*acp_start = start_pos;
- if (acp_end) {
+ if (acp_end)
*acp_end = end_pos;
- }
return S_OK;
}
diff --git a/win8/metro_driver/ime/text_store.h b/win8/metro_driver/ime/text_store.h
index 3a308cf..1986095 100644
--- a/win8/metro_driver/ime/text_store.h
+++ b/win8/metro_driver/ime/text_store.h
@@ -5,6 +5,9 @@
#ifndef WIN8_METRO_DRIVER_IME_TEXT_STORE_H_
#define WIN8_METRO_DRIVER_IME_TEXT_STORE_H_
+#include <atlbase.h>
+#include <atlcom.h>
+#include <initguid.h>
#include <inputscope.h>
#include <msctf.h>
@@ -85,16 +88,21 @@ class TextStoreDelegate;
// More information about TSF can be found here:
// http://msdn.microsoft.com/en-us/library/ms629032
// TODO(yukawa): Rename TSFTextStore to TextStore.
-class TSFTextStore : public ITextStoreACP,
- public ITfContextOwnerCompositionSink,
- public ITfTextEditSink {
+class ATL_NO_VTABLE TSFTextStore
+ : public CComObjectRootEx<CComMultiThreadModel>,
+ public ITextStoreACP,
+ public ITfContextOwnerCompositionSink,
+ public ITfTextEditSink {
public:
virtual ~TSFTextStore();
+ BEGIN_COM_MAP(TSFTextStore)
+ COM_INTERFACE_ENTRY(ITextStoreACP)
+ COM_INTERFACE_ENTRY(ITfContextOwnerCompositionSink)
+ COM_INTERFACE_ENTRY(ITfTextEditSink)
+ END_COM_MAP()
+
// ITextStoreACP:
- STDMETHOD_(ULONG, AddRef)() OVERRIDE;
- STDMETHOD_(ULONG, Release)() OVERRIDE;
- STDMETHOD(QueryInterface)(REFIID iid, void** ppv) OVERRIDE;
STDMETHOD(AdviseSink)(REFIID iid, IUnknown* unknown, DWORD mask) OVERRIDE;
STDMETHOD(FindNextAttrTransition)(LONG acp_start,
LONG acp_halt,
@@ -215,11 +223,14 @@ class TSFTextStore : public ITextStoreACP,
TextStoreDelegate* delegate);
private:
- TSFTextStore(HWND window_handle,
- ITfCategoryMgr* category_manager,
- ITfDisplayAttributeMgr* display_attribute_manager,
- ITfInputScope* input_scope,
- TextStoreDelegate* delegate);
+ friend CComObject<TSFTextStore>;
+ TSFTextStore();
+
+ void Initialize(HWND window_handle,
+ ITfCategoryMgr* category_manager,
+ ITfDisplayAttributeMgr* display_attribute_manager,
+ ITfInputScope* input_scope,
+ TextStoreDelegate* delegate);
// Checks if the document has a read-only lock.
bool HasReadLock() const;
@@ -238,9 +249,6 @@ class TSFTextStore : public ITextStoreACP,
uint32* committed_size,
std::vector<metro_viewer::UnderlineInfo>* undelines);
- // The refrence count of this instance.
- volatile LONG ref_count_;
-
// A pointer of ITextStoreACPSink, this instance is given in AdviseSink.
base::win::ScopedComPtr<ITextStoreACPSink> text_store_acp_sink_;
@@ -250,9 +258,6 @@ class TSFTextStore : public ITextStoreACP,
// HWND of the attached window.
HWND window_handle_;
- // The delegate attached to this text store.
- TextStoreDelegate* delegate_;
-
// |string_buffer_| contains committed string and composition string.
// Example: "aoi" is committed, and "umi" is under composition.
// |string_buffer_|: "aoiumi"
@@ -300,6 +305,9 @@ class TSFTextStore : public ITextStoreACP,
// Represents the context information of this text.
base::win::ScopedComPtr<ITfInputScope> input_scope_;
+ // The delegate attached to this text store.
+ TextStoreDelegate* delegate_;
+
DISALLOW_COPY_AND_ASSIGN(TSFTextStore);
};