Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: blimp/client/core/contents/ime_feature.cc

Issue 2292343002: Hooking up Blimp IME with BlimpContents (Closed)
Patch Set: Using Callback Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "blimp/client/core/contents/ime_feature.h" 5 #include "blimp/client/core/contents/ime_feature.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "blimp/common/create_blimp_message.h" 9 #include "blimp/common/create_blimp_message.h"
10 #include "blimp/common/proto/blimp_message.pb.h" 10 #include "blimp/common/proto/blimp_message.pb.h"
11 #include "blimp/net/input_message_converter.h" 11 #include "blimp/net/input_message_converter.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 13
14 namespace blimp { 14 namespace blimp {
15 namespace client { 15 namespace client {
16 16
17 ImeFeature::ImeFeature() {} 17 ImeFeature::ImeFeature() {}
18 18
19 ImeFeature::~ImeFeature() {} 19 ImeFeature::~ImeFeature() {}
20 20
21 void ImeFeature::OnImeTextEntered(const std::string& text) { 21 void ImeFeature::OnImeTextEntered(int tab_id,
22 DCHECK_LE(0, tab_id_); 22 int render_widget_id,
23 DCHECK_LT(0, render_widget_id_); 23 const std::string& text) {
24 DCHECK_LE(0, tab_id);
25 DCHECK_LT(0, render_widget_id);
24 26
25 ImeMessage* ime_message; 27 ImeMessage* ime_message;
26 std::unique_ptr<BlimpMessage> blimp_message = 28 std::unique_ptr<BlimpMessage> blimp_message =
27 CreateBlimpMessage(&ime_message, tab_id_); 29 CreateBlimpMessage(&ime_message, tab_id);
28 ime_message->set_render_widget_id(render_widget_id_); 30 ime_message->set_render_widget_id(render_widget_id);
29 ime_message->set_type(ImeMessage::SET_TEXT); 31 ime_message->set_type(ImeMessage::SET_TEXT);
30 ime_message->set_ime_text(text); 32 ime_message->set_ime_text(text);
31 33
32 outgoing_message_processor_->ProcessMessage(std::move(blimp_message), 34 outgoing_message_processor_->ProcessMessage(std::move(blimp_message),
33 net::CompletionCallback()); 35 net::CompletionCallback());
34 } 36 }
35 37
36 void ImeFeature::ProcessMessage(std::unique_ptr<BlimpMessage> message, 38 void ImeFeature::ProcessMessage(std::unique_ptr<BlimpMessage> message,
37 const net::CompletionCallback& callback) { 39 const net::CompletionCallback& callback) {
38 DCHECK(!callback.is_null()); 40 DCHECK(!callback.is_null());
39 DCHECK_EQ(BlimpMessage::kIme, message->feature_case()); 41 DCHECK_EQ(BlimpMessage::kIme, message->feature_case());
40 42
41 DCHECK(delegate_); 43 DCHECK(delegate_);
42 44
43 const ImeMessage& ime_message = message->ime(); 45 const ImeMessage& ime_message = message->ime();
44 46
45 switch (ime_message.type()) { 47 switch (ime_message.type()) {
46 case ImeMessage::SHOW_IME: 48 case ImeMessage::SHOW_IME:
47 if (!message->has_target_tab_id() || message->target_tab_id() < 0 || 49 if (!message->has_target_tab_id() || message->target_tab_id() < 0 ||
48 ime_message.render_widget_id() <= 0) { 50 ime_message.render_widget_id() <= 0) {
49 callback.Run(net::ERR_INVALID_ARGUMENT); 51 callback.Run(net::ERR_INVALID_ARGUMENT);
50 return; 52 return;
51 } 53 }
52 54 {
53 tab_id_ = message->target_tab_id(); 55 ShowImeCallback showImeCallback = base::Bind(
David Trainor- moved to gerrit 2016/08/31 05:59:10 show_ime_callback
shaktisahu 2016/08/31 17:28:21 Done.
54 render_widget_id_ = ime_message.render_widget_id(); 56 &ImeFeature::OnImeTextEntered, base::Unretained(this),
55 57 message->target_tab_id(), ime_message.render_widget_id());
56 delegate_->OnShowImeRequested( 58 delegate_->OnShowImeRequested(
57 InputMessageConverter::TextInputTypeFromProto( 59 InputMessageConverter::TextInputTypeFromProto(
58 ime_message.text_input_type()), 60 ime_message.text_input_type()),
59 ime_message.ime_text()); 61 ime_message.ime_text(), showImeCallback);
62 }
60 break; 63 break;
61 case ImeMessage::HIDE_IME: 64 case ImeMessage::HIDE_IME:
62 tab_id_ = -1;
63 render_widget_id_ = 0;
64 delegate_->OnHideImeRequested(); 65 delegate_->OnHideImeRequested();
65 break; 66 break;
66 case ImeMessage::SET_TEXT: 67 case ImeMessage::SET_TEXT:
67 case ImeMessage::UNKNOWN: 68 case ImeMessage::UNKNOWN:
68 NOTREACHED(); 69 NOTREACHED();
69 callback.Run(net::ERR_UNEXPECTED); 70 callback.Run(net::ERR_UNEXPECTED);
70 return; 71 return;
71 } 72 }
72 73
73 callback.Run(net::OK); 74 callback.Run(net::OK);
74 } 75 }
75 76
76 } // namespace client 77 } // namespace client
77 } // namespace blimp 78 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698