1 // Copyright 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.
5 #include "win8/metro_driver/ime/text_store.h"
9 #include "base/win/scoped_variant.h"
10 #include "ui/base/win/atl_module.h"
11 #include "win8/metro_driver/ime/input_scope.h"
12 #include "win8/metro_driver/ime/text_store_delegate.h"
14 namespace metro_driver {
17 // We support only one view.
18 const TsViewCookie kViewCookie = 1;
22 TextStore::TextStore()
23 : text_store_acp_sink_mask_(0),
30 current_lock_type_(0),
31 category_manager_(NULL),
32 display_attribute_manager_(NULL),
36 TextStore::~TextStore() {
40 scoped_refptr<TextStore> TextStore::Create(
42 const std::vector<InputScope>& input_scopes,
43 TextStoreDelegate* delegate) {
45 LOG(ERROR) << "|delegate| must be non-NULL.";
46 return scoped_refptr<TextStore>();
48 base::win::ScopedComPtr<ITfCategoryMgr> category_manager;
49 HRESULT hr = category_manager.CreateInstance(CLSID_TF_CategoryMgr);
51 LOG(ERROR) << "Failed to initialize CategoryMgr. hr = " << hr;
52 return scoped_refptr<TextStore>();
54 base::win::ScopedComPtr<ITfDisplayAttributeMgr> display_attribute_manager;
55 hr = display_attribute_manager.CreateInstance(CLSID_TF_DisplayAttributeMgr);
57 LOG(ERROR) << "Failed to initialize DisplayAttributeMgr. hr = " << hr;
58 return scoped_refptr<TextStore>();
60 base::win::ScopedComPtr<ITfInputScope> input_scope =
61 CreteInputScope(input_scopes);
63 LOG(ERROR) << "Failed to initialize InputScope.";
64 return scoped_refptr<TextStore>();
67 ui::win::CreateATLModuleIfNeeded();
68 CComObject<TextStore>* object = NULL;
69 hr = CComObject<TextStore>::CreateInstance(&object);
71 LOG(ERROR) << "CComObject<TextStore>::CreateInstance failed. hr = "
73 return scoped_refptr<TextStore>();
75 object->Initialize(window_handle,
77 display_attribute_manager,
80 return scoped_refptr<TextStore>(object);
83 void TextStore::Initialize(HWND window_handle,
84 ITfCategoryMgr* category_manager,
85 ITfDisplayAttributeMgr* display_attribute_manager,
86 ITfInputScope* input_scope,
87 TextStoreDelegate* delegate) {
88 window_handle_ = window_handle;
89 category_manager_ = category_manager;
90 display_attribute_manager_ = display_attribute_manager;
91 input_scope_ = input_scope;
96 STDMETHODIMP TextStore::AdviseSink(REFIID iid,
99 if (!IsEqualGUID(iid, IID_ITextStoreACPSink))
101 if (text_store_acp_sink_) {
102 if (text_store_acp_sink_.IsSameObject(unknown)) {
103 text_store_acp_sink_mask_ = mask;
106 return CONNECT_E_ADVISELIMIT;
109 if (FAILED(text_store_acp_sink_.QueryFrom(unknown)))
111 text_store_acp_sink_mask_ = mask;
116 STDMETHODIMP TextStore::FindNextAttrTransition(
119 ULONG num_filter_attributes,
120 const TS_ATTRID* filter_attributes,
124 LONG* found_offset) {
125 if (!acp_next || !found || !found_offset)
127 // We don't support any attributes.
128 // So we always return "not found".
135 STDMETHODIMP TextStore::GetACPFromPoint(TsViewCookie view_cookie,
140 if (view_cookie != kViewCookie)
145 STDMETHODIMP TextStore::GetActiveView(TsViewCookie* view_cookie) {
148 // We support only one view.
149 *view_cookie = kViewCookie;
153 STDMETHODIMP TextStore::GetEmbedded(LONG acp_pos,
156 IUnknown** unknown) {
157 // We don't support any embedded objects.
165 STDMETHODIMP TextStore::GetEndACP(LONG* acp) {
170 *acp = static_cast<LONG>(string_buffer_.size());
174 STDMETHODIMP TextStore::GetFormattedText(LONG acp_start,
176 IDataObject** data_object) {
181 STDMETHODIMP TextStore::GetScreenExt(TsViewCookie view_cookie, RECT* rect) {
182 if (view_cookie != kViewCookie)
187 // {0, 0, 0, 0} means that the document rect is not currently displayed.
188 SetRect(rect, 0, 0, 0, 0);
190 RECT client_rect = {};
191 if (!GetClientRect(window_handle_, &client_rect))
193 POINT left_top = {client_rect.left, client_rect.top};
194 POINT right_bottom = {client_rect.right, client_rect.bottom};
195 if (!ClientToScreen(window_handle_, &left_top))
197 if (!ClientToScreen(window_handle_, &right_bottom))
200 rect->left = left_top.x;
201 rect->top = left_top.y;
202 rect->right = right_bottom.x;
203 rect->bottom = right_bottom.y;
207 STDMETHODIMP TextStore::GetSelection(ULONG selection_index,
208 ULONG selection_buffer_size,
209 TS_SELECTION_ACP* selection_buffer,
210 ULONG* fetched_count) {
211 if (!selection_buffer)
218 if ((selection_buffer_size > 0) &&
219 ((selection_index == 0) || (selection_index == TS_DEFAULT_SELECTION))) {
220 selection_buffer[0].acpStart = selection_start_;
221 selection_buffer[0].acpEnd = selection_end_;
222 selection_buffer[0].style.ase = TS_AE_END;
223 selection_buffer[0].style.fInterimChar = FALSE;
229 STDMETHODIMP TextStore::GetStatus(TS_STATUS* status) {
233 status->dwDynamicFlags = 0;
234 // We use transitory contexts and we don't support hidden text.
235 status->dwStaticFlags = TS_SS_TRANSITORY | TS_SS_NOHIDDENTEXT;
240 STDMETHODIMP TextStore::GetText(LONG acp_start,
242 wchar_t* text_buffer,
243 ULONG text_buffer_size,
244 ULONG* text_buffer_copied,
245 TS_RUNINFO* run_info_buffer,
246 ULONG run_info_buffer_size,
247 ULONG* run_info_buffer_copied,
249 if (!text_buffer_copied || !run_info_buffer_copied)
251 if (!text_buffer && text_buffer_size != 0)
253 if (!run_info_buffer && run_info_buffer_size != 0)
259 const LONG string_buffer_size = static_cast<LONG>(string_buffer_.size());
261 acp_end = string_buffer_size;
262 if (!((0 <= acp_start) &&
263 (acp_start <= acp_end) &&
264 (acp_end <= string_buffer_size))) {
265 return TF_E_INVALIDPOS;
267 acp_end = std::min(acp_end, acp_start + static_cast<LONG>(text_buffer_size));
268 *text_buffer_copied = acp_end - acp_start;
270 const base::string16& result =
271 string_buffer_.substr(acp_start, *text_buffer_copied);
272 for (size_t i = 0; i < result.size(); ++i)
273 text_buffer[i] = result[i];
275 if (run_info_buffer_size) {
276 run_info_buffer[0].uCount = *text_buffer_copied;
277 run_info_buffer[0].type = TS_RT_PLAIN;
278 *run_info_buffer_copied = 1;
285 STDMETHODIMP TextStore::GetTextExt(TsViewCookie view_cookie,
290 if (!rect || !clipped)
292 if (view_cookie != kViewCookie)
296 if (!((static_cast<LONG>(committed_size_) <= acp_start) &&
297 (acp_start <= acp_end) &&
298 (acp_end <= static_cast<LONG>(string_buffer_.size())))) {
299 return TS_E_INVALIDPOS;
302 // According to a behavior of notepad.exe and wordpad.exe, top left corner of
303 // rect indicates a first character's one, and bottom right corner of rect
304 // indicates a last character's one.
305 // We use RECT instead of gfx::Rect since left position may be bigger than
306 // right position when composition has multiple lines.
309 const uint32 start_pos = acp_start - committed_size_;
310 const uint32 end_pos = acp_end - committed_size_;
312 if (start_pos == end_pos) {
313 // According to MSDN document, if |acp_start| and |acp_end| are equal it is
314 // OK to just return E_INVALIDARG.
315 // http://msdn.microsoft.com/en-us/library/ms538435
316 // But when using Pinin IME of Windows 8, this method is called with the
317 // equal values of |acp_start| and |acp_end|. So we handle this condition.
318 if (start_pos == 0) {
319 if (delegate_->GetCompositionCharacterBounds(0, &tmp_rect)) {
320 tmp_rect.right = tmp_rect.right;
322 } else if (string_buffer_.size() == committed_size_) {
323 result = delegate_->GetCaretBounds();
325 return TS_E_NOLAYOUT;
327 } else if (delegate_->GetCompositionCharacterBounds(start_pos - 1,
329 tmp_rect.left = tmp_rect.right;
332 return TS_E_NOLAYOUT;
335 if (delegate_->GetCompositionCharacterBounds(start_pos, &tmp_rect)) {
337 if (delegate_->GetCompositionCharacterBounds(end_pos - 1, &tmp_rect)) {
338 result.right = tmp_rect.right;
339 result.bottom = tmp_rect.bottom;
341 // We may not be able to get the last character bounds, so we use the
342 // first character bounds instead of returning TS_E_NOLAYOUT.
345 // Hack for PPAPI flash. PPAPI flash does not support GetCaretBounds, so
346 // it's better to return previous caret rectangle instead.
347 // TODO(nona, kinaba): Remove this hack.
349 result = delegate_->GetCaretBounds();
351 return TS_E_NOLAYOUT;
360 STDMETHODIMP TextStore::GetWnd(TsViewCookie view_cookie,
361 HWND* window_handle) {
364 if (view_cookie != kViewCookie)
366 *window_handle = window_handle_;
370 STDMETHODIMP TextStore::InsertEmbedded(DWORD flags,
373 IDataObject* data_object,
374 TS_TEXTCHANGE* change) {
375 // We don't support any embedded objects.
380 STDMETHODIMP TextStore::InsertEmbeddedAtSelection(DWORD flags,
381 IDataObject* data_object,
384 TS_TEXTCHANGE* change) {
385 // We don't support any embedded objects.
390 STDMETHODIMP TextStore::InsertTextAtSelection(DWORD flags,
391 const wchar_t* text_buffer,
392 ULONG text_buffer_size,
395 TS_TEXTCHANGE* text_change) {
396 const LONG start_pos = selection_start_;
397 const LONG end_pos = selection_end_;
398 const LONG new_end_pos = start_pos + text_buffer_size;
400 if (flags & TS_IAS_QUERYONLY) {
404 *acp_start = start_pos;
410 if (!HasReadWriteLock())
415 DCHECK_LE(start_pos, end_pos);
416 string_buffer_ = string_buffer_.substr(0, start_pos) +
417 base::string16(text_buffer, text_buffer + text_buffer_size) +
418 string_buffer_.substr(end_pos);
420 *acp_start = start_pos;
422 *acp_end = new_end_pos;
424 text_change->acpStart = start_pos;
425 text_change->acpOldEnd = end_pos;
426 text_change->acpNewEnd = new_end_pos;
428 selection_start_ = start_pos;
429 selection_end_ = new_end_pos;
433 STDMETHODIMP TextStore::QueryInsert(
437 LONG* acp_result_start,
438 LONG* acp_result_end) {
439 if (!acp_result_start || !acp_result_end || acp_test_start > acp_test_end)
441 const LONG committed_size = static_cast<LONG>(committed_size_);
442 const LONG buffer_size = static_cast<LONG>(string_buffer_.size());
443 *acp_result_start = std::min(std::max(committed_size, acp_test_start),
445 *acp_result_end = std::min(std::max(committed_size, acp_test_end),
450 STDMETHODIMP TextStore::QueryInsertEmbedded(const GUID* service,
451 const FORMATETC* format,
455 // We don't support any embedded objects.
461 STDMETHODIMP TextStore::RequestAttrsAtPosition(
463 ULONG attribute_buffer_size,
464 const TS_ATTRID* attribute_buffer,
466 // We don't support any document attributes.
467 // This method just returns S_OK, and the subsequently called
468 // RetrieveRequestedAttrs() returns 0 as the number of supported attributes.
472 STDMETHODIMP TextStore::RequestAttrsTransitioningAtPosition(
474 ULONG attribute_buffer_size,
475 const TS_ATTRID* attribute_buffer,
477 // We don't support any document attributes.
478 // This method just returns S_OK, and the subsequently called
479 // RetrieveRequestedAttrs() returns 0 as the number of supported attributes.
483 STDMETHODIMP TextStore::RequestLock(DWORD lock_flags, HRESULT* result) {
484 if (!text_store_acp_sink_.get())
489 if (current_lock_type_ != 0) {
490 if (lock_flags & TS_LF_SYNC) {
491 // Can't lock synchronously.
492 *result = TS_E_SYNCHRONOUS;
495 // Queue the lock request.
496 lock_queue_.push_back(lock_flags & TS_LF_READWRITE);
497 *result = TS_S_ASYNC;
502 current_lock_type_ = (lock_flags & TS_LF_READWRITE);
505 const uint32 last_committed_size = committed_size_;
508 *result = text_store_acp_sink_->OnLockGranted(current_lock_type_);
511 current_lock_type_ = 0;
513 // Handles the pending lock requests.
514 while (!lock_queue_.empty()) {
515 current_lock_type_ = lock_queue_.front();
516 lock_queue_.pop_front();
517 text_store_acp_sink_->OnLockGranted(current_lock_type_);
518 current_lock_type_ = 0;
524 // If the text store is edited in OnLockGranted(), we may need to call
525 // TextStoreDelegate::ConfirmComposition() or
526 // TextStoreDelegate::SetComposition().
527 const uint32 new_committed_size = committed_size_;
528 const base::string16& new_committed_string =
529 string_buffer_.substr(last_committed_size,
530 new_committed_size - last_committed_size);
531 const base::string16& composition_string =
532 string_buffer_.substr(new_committed_size);
534 // If there is new committed string, calls
535 // TextStoreDelegate::ConfirmComposition().
536 if ((!new_committed_string.empty()))
537 delegate_->OnTextCommitted(new_committed_string);
539 // Calls TextInputClient::SetCompositionText().
540 std::vector<metro_viewer::UnderlineInfo> underlines = underlines_;
541 // Adjusts the offset.
542 for (size_t i = 0; i < underlines_.size(); ++i) {
543 underlines[i].start_offset -= new_committed_size;
544 underlines[i].end_offset -= new_committed_size;
546 int32 selection_start = 0;
547 int32 selection_end = 0;
548 if (selection_start_ >= new_committed_size)
549 selection_start = selection_start_ - new_committed_size;
550 if (selection_end_ >= new_committed_size)
551 selection_end = selection_end_ - new_committed_size;
552 delegate_->OnCompositionChanged(
553 composition_string, selection_start, selection_end, underlines);
555 // If there is no composition string, clear the text store status.
556 // And call OnSelectionChange(), OnLayoutChange(), and OnTextChange().
557 if ((composition_string.empty()) && (new_committed_size != 0)) {
558 string_buffer_.clear();
560 selection_start_ = 0;
562 if (text_store_acp_sink_mask_ & TS_AS_SEL_CHANGE)
563 text_store_acp_sink_->OnSelectionChange();
564 if (text_store_acp_sink_mask_ & TS_AS_LAYOUT_CHANGE)
565 text_store_acp_sink_->OnLayoutChange(TS_LC_CHANGE, 0);
566 if (text_store_acp_sink_mask_ & TS_AS_TEXT_CHANGE) {
567 TS_TEXTCHANGE textChange;
568 textChange.acpStart = 0;
569 textChange.acpOldEnd = new_committed_size;
570 textChange.acpNewEnd = 0;
571 text_store_acp_sink_->OnTextChange(0, &textChange);
578 STDMETHODIMP TextStore::RequestSupportedAttrs(
579 DWORD /* flags */, // Seems that we should ignore this.
580 ULONG attribute_buffer_size,
581 const TS_ATTRID* attribute_buffer) {
582 if (!attribute_buffer)
586 // We support only input scope attribute.
587 for (size_t i = 0; i < attribute_buffer_size; ++i) {
588 if (IsEqualGUID(GUID_PROP_INPUTSCOPE, attribute_buffer[i]))
594 STDMETHODIMP TextStore::RetrieveRequestedAttrs(
595 ULONG attribute_buffer_size,
596 TS_ATTRVAL* attribute_buffer,
597 ULONG* attribute_buffer_copied) {
598 if (!attribute_buffer_copied)
600 *attribute_buffer_copied = 0;
601 if (!attribute_buffer)
605 // We support only input scope attribute.
606 *attribute_buffer_copied = 0;
607 if (attribute_buffer_size == 0)
610 attribute_buffer[0].dwOverlapId = 0;
611 attribute_buffer[0].idAttr = GUID_PROP_INPUTSCOPE;
612 attribute_buffer[0].varValue.vt = VT_UNKNOWN;
613 attribute_buffer[0].varValue.punkVal = input_scope_.get();
614 attribute_buffer[0].varValue.punkVal->AddRef();
615 *attribute_buffer_copied = 1;
619 STDMETHODIMP TextStore::SetSelection(
620 ULONG selection_buffer_size,
621 const TS_SELECTION_ACP* selection_buffer) {
622 if (!HasReadWriteLock())
624 if (selection_buffer_size > 0) {
625 const LONG start_pos = selection_buffer[0].acpStart;
626 const LONG end_pos = selection_buffer[0].acpEnd;
627 if (!((static_cast<LONG>(committed_size_) <= start_pos) &&
628 (start_pos <= end_pos) &&
629 (end_pos <= static_cast<LONG>(string_buffer_.size())))) {
630 return TF_E_INVALIDPOS;
632 selection_start_ = start_pos;
633 selection_end_ = end_pos;
638 STDMETHODIMP TextStore::SetText(DWORD flags,
641 const wchar_t* text_buffer,
642 ULONG text_buffer_size,
643 TS_TEXTCHANGE* text_change) {
644 if (!HasReadWriteLock())
646 if (!((static_cast<LONG>(committed_size_) <= acp_start) &&
647 (acp_start <= acp_end) &&
648 (acp_end <= static_cast<LONG>(string_buffer_.size())))) {
649 return TS_E_INVALIDPOS;
652 TS_SELECTION_ACP selection;
653 selection.acpStart = acp_start;
654 selection.acpEnd = acp_end;
655 selection.style.ase = TS_AE_NONE;
656 selection.style.fInterimChar = 0;
659 ret = SetSelection(1, &selection);
663 TS_TEXTCHANGE change;
664 ret = InsertTextAtSelection(0, text_buffer, text_buffer_size,
665 &acp_start, &acp_end, &change);
670 *text_change = change;
675 STDMETHODIMP TextStore::UnadviseSink(IUnknown* unknown) {
676 if (!text_store_acp_sink_.IsSameObject(unknown))
677 return CONNECT_E_NOCONNECTION;
678 text_store_acp_sink_.Release();
679 text_store_acp_sink_mask_ = 0;
683 STDMETHODIMP TextStore::OnStartComposition(
684 ITfCompositionView* composition_view,
691 STDMETHODIMP TextStore::OnUpdateComposition(
692 ITfCompositionView* composition_view,
697 STDMETHODIMP TextStore::OnEndComposition(
698 ITfCompositionView* composition_view) {
702 STDMETHODIMP TextStore::OnEndEdit(ITfContext* context,
703 TfEditCookie read_only_edit_cookie,
704 ITfEditRecord* edit_record) {
705 if (!context || !edit_record)
707 if (!GetCompositionStatus(context, read_only_edit_cookie, &committed_size_,
715 bool TextStore::GetDisplayAttribute(TfGuidAtom guid_atom,
716 TF_DISPLAYATTRIBUTE* attribute) {
718 if (FAILED(category_manager_->GetGUID(guid_atom, &guid)))
721 base::win::ScopedComPtr<ITfDisplayAttributeInfo> display_attribute_info;
722 if (FAILED(display_attribute_manager_->GetDisplayAttributeInfo(
723 guid, display_attribute_info.Receive(), NULL))) {
726 return SUCCEEDED(display_attribute_info->GetAttributeInfo(attribute));
729 bool TextStore::GetCompositionStatus(
731 const TfEditCookie read_only_edit_cookie,
732 uint32* committed_size,
733 std::vector<metro_viewer::UnderlineInfo>* undelines) {
735 DCHECK(committed_size);
737 const GUID* rgGuids[2] = {&GUID_PROP_COMPOSING, &GUID_PROP_ATTRIBUTE};
738 base::win::ScopedComPtr<ITfReadOnlyProperty> track_property;
739 if (FAILED(context->TrackProperties(rgGuids, 2, NULL, 0,
740 track_property.Receive()))) {
746 base::win::ScopedComPtr<ITfRange> start_to_end_range;
747 base::win::ScopedComPtr<ITfRange> end_range;
748 if (FAILED(context->GetStart(read_only_edit_cookie,
749 start_to_end_range.Receive()))) {
752 if (FAILED(context->GetEnd(read_only_edit_cookie, end_range.Receive())))
754 if (FAILED(start_to_end_range->ShiftEndToRange(read_only_edit_cookie,
755 end_range, TF_ANCHOR_END))) {
759 base::win::ScopedComPtr<IEnumTfRanges> ranges;
760 if (FAILED(track_property->EnumRanges(read_only_edit_cookie, ranges.Receive(),
761 start_to_end_range))) {
766 base::win::ScopedComPtr<ITfRange> range;
767 if (ranges->Next(1, range.Receive(), NULL) != S_OK)
769 base::win::ScopedVariant value;
770 base::win::ScopedComPtr<IEnumTfPropertyValue> enum_prop_value;
771 if (FAILED(track_property->GetValue(read_only_edit_cookie, range,
775 if (FAILED(enum_prop_value.QueryFrom(value.AsInput()->punkVal)))
778 TF_PROPERTYVAL property_value;
779 bool is_composition = false;
780 metro_viewer::UnderlineInfo underline;
781 while (enum_prop_value->Next(1, &property_value, NULL) == S_OK) {
782 if (IsEqualGUID(property_value.guidId, GUID_PROP_COMPOSING)) {
783 is_composition = (property_value.varValue.lVal == TRUE);
784 } else if (IsEqualGUID(property_value.guidId, GUID_PROP_ATTRIBUTE)) {
785 TfGuidAtom guid_atom =
786 static_cast<TfGuidAtom>(property_value.varValue.lVal);
787 TF_DISPLAYATTRIBUTE display_attribute;
788 if (GetDisplayAttribute(guid_atom, &display_attribute))
789 underline.thick = !!display_attribute.fBoldLine;
791 VariantClear(&property_value.varValue);
794 base::win::ScopedComPtr<ITfRangeACP> range_acp;
795 range_acp.QueryFrom(range);
796 LONG start_pos, length;
797 range_acp->GetExtent(&start_pos, &length);
798 if (is_composition) {
799 underline.start_offset = start_pos;
800 underline.end_offset = start_pos + length;
801 undelines->push_back(underline);
802 } else if (*committed_size < static_cast<size_t>(start_pos + length)) {
803 *committed_size = start_pos + length;
808 bool TextStore::CancelComposition() {
809 // If there is an on-going document lock, we must not edit the text.
813 if (string_buffer_.empty())
816 // Unlike ImmNotifyIME(NI_COMPOSITIONSTR, CPS_CANCEL, 0) in IMM32, TSF does
817 // not have a dedicated method to cancel composition. However, CUAS actually
818 // has a protocol conversion from CPS_CANCEL into TSF operations. According
819 // to the observations on Windows 7, TIPs are expected to cancel composition
820 // when an on-going composition text is replaced with an empty string. So
821 // we use the same operation to cancel composition here to minimize the risk
822 // of potential compatibility issues.
824 const uint32 previous_buffer_size =
825 static_cast<uint32>(string_buffer_.size());
826 string_buffer_.clear();
828 selection_start_ = 0;
830 if (text_store_acp_sink_mask_ & TS_AS_SEL_CHANGE)
831 text_store_acp_sink_->OnSelectionChange();
832 if (text_store_acp_sink_mask_ & TS_AS_LAYOUT_CHANGE)
833 text_store_acp_sink_->OnLayoutChange(TS_LC_CHANGE, 0);
834 if (text_store_acp_sink_mask_ & TS_AS_TEXT_CHANGE) {
835 TS_TEXTCHANGE textChange = {};
836 textChange.acpStart = 0;
837 textChange.acpOldEnd = previous_buffer_size;
838 textChange.acpNewEnd = 0;
839 text_store_acp_sink_->OnTextChange(0, &textChange);
844 bool TextStore::ConfirmComposition() {
845 // If there is an on-going document lock, we must not edit the text.
849 if (string_buffer_.empty())
852 // See the comment in TextStore::CancelComposition.
853 // This logic is based on the observation about how to emulate
854 // ImmNotifyIME(NI_COMPOSITIONSTR, CPS_COMPLETE, 0) by CUAS.
856 const base::string16& composition_text =
857 string_buffer_.substr(committed_size_);
858 if (!composition_text.empty())
859 delegate_->OnTextCommitted(composition_text);
861 const uint32 previous_buffer_size =
862 static_cast<uint32>(string_buffer_.size());
863 string_buffer_.clear();
865 selection_start_ = 0;
867 if (text_store_acp_sink_mask_ & TS_AS_SEL_CHANGE)
868 text_store_acp_sink_->OnSelectionChange();
869 if (text_store_acp_sink_mask_ & TS_AS_LAYOUT_CHANGE)
870 text_store_acp_sink_->OnLayoutChange(TS_LC_CHANGE, 0);
871 if (text_store_acp_sink_mask_ & TS_AS_TEXT_CHANGE) {
872 TS_TEXTCHANGE textChange = {};
873 textChange.acpStart = 0;
874 textChange.acpOldEnd = previous_buffer_size;
875 textChange.acpNewEnd = 0;
876 text_store_acp_sink_->OnTextChange(0, &textChange);
881 void TextStore::SendOnLayoutChange() {
882 if (text_store_acp_sink_ && (text_store_acp_sink_mask_ & TS_AS_LAYOUT_CHANGE))
883 text_store_acp_sink_->OnLayoutChange(TS_LC_CHANGE, 0);
886 bool TextStore::HasReadLock() const {
887 return (current_lock_type_ & TS_LF_READ) == TS_LF_READ;
890 bool TextStore::HasReadWriteLock() const {
891 return (current_lock_type_ & TS_LF_READWRITE) == TS_LF_READWRITE;
894 } // namespace metro_driver