| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/aura/mus/text_input_client_impl.h" | 5 #include "ui/aura/mus/text_input_client_impl.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" |
| 7 #include "ui/aura/mus/input_method_mus.h" | 8 #include "ui/aura/mus/input_method_mus.h" |
| 8 #include "ui/base/ime/text_input_client.h" | 9 #include "ui/base/ime/text_input_client.h" |
| 9 | 10 |
| 10 namespace aura { | 11 namespace aura { |
| 11 | 12 |
| 12 TextInputClientImpl::TextInputClientImpl(ui::TextInputClient* text_input_client) | 13 TextInputClientImpl::TextInputClientImpl(ui::TextInputClient* text_input_client) |
| 13 : text_input_client_(text_input_client), binding_(this) {} | 14 : text_input_client_(text_input_client), binding_(this) {} |
| 14 | 15 |
| 15 TextInputClientImpl::~TextInputClientImpl() {} | 16 TextInputClientImpl::~TextInputClientImpl() {} |
| 16 | 17 |
| 17 ui::mojom::TextInputClientPtr TextInputClientImpl::CreateInterfacePtrAndBind() { | 18 ui::mojom::TextInputClientPtr TextInputClientImpl::CreateInterfacePtrAndBind() { |
| 18 return binding_.CreateInterfacePtrAndBind(); | 19 return binding_.CreateInterfacePtrAndBind(); |
| 19 } | 20 } |
| 20 | 21 |
| 21 void TextInputClientImpl::OnCompositionEvent( | 22 void TextInputClientImpl::SetCompositionText( |
| 22 ui::mojom::CompositionEventPtr event) { | 23 const ui::CompositionText& composition) { |
| 23 switch (event->type) { | 24 text_input_client_->SetCompositionText(composition); |
| 24 case ui::mojom::CompositionEventType::INSERT_CHAR: { | 25 } |
| 25 DCHECK((*event->key_event)->IsKeyEvent()); | 26 |
| 26 ui::KeyEvent* key_event = (*event->key_event)->AsKeyEvent(); | 27 void TextInputClientImpl::ConfirmCompositionText() { |
| 27 DCHECK(key_event->is_char()); | 28 text_input_client_->ConfirmCompositionText(); |
| 28 text_input_client_->InsertChar(*key_event); | 29 } |
| 29 break; | 30 |
| 30 } | 31 void TextInputClientImpl::ClearCompositionText() { |
| 31 case ui::mojom::CompositionEventType::CONFIRM: | 32 text_input_client_->ClearCompositionText(); |
| 32 text_input_client_->ConfirmCompositionText(); | 33 } |
| 33 break; | 34 |
| 34 case ui::mojom::CompositionEventType::CLEAR: | 35 void TextInputClientImpl::InsertText(const std::string& text) { |
| 35 text_input_client_->ClearCompositionText(); | 36 text_input_client_->InsertText(base::UTF8ToUTF16(text)); |
| 36 break; | 37 } |
| 37 case ui::mojom::CompositionEventType::UPDATE: | 38 |
| 38 case ui::mojom::CompositionEventType::INSERT_TEXT: | 39 void TextInputClientImpl::InsertChar(std::unique_ptr<ui::Event> event) { |
| 39 // TODO(moshayedi): crbug.com/631524. Implement these types of composition | 40 DCHECK(event->IsKeyEvent()); |
| 40 // events once we have the necessary fields in ui.mojom.CompositionEvent. | 41 ui::KeyEvent* key_event = event->AsKeyEvent(); |
| 41 NOTIMPLEMENTED(); | 42 DCHECK(key_event->is_char()); |
| 42 break; | 43 text_input_client_->InsertChar(*key_event); |
| 43 } | |
| 44 } | 44 } |
| 45 | 45 |
| 46 } // namespace aura | 46 } // namespace aura |
| OLD | NEW |