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

Side by Side Diff: services/keyboard_native/view_observer_delegate.cc

Issue 1247903003: Add spellcheck and word suggestion to the prediction service (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: format README and CHROMIUM.diff Created 5 years, 4 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
« no previous file with comments | « services/keyboard_native/view_observer_delegate.h ('k') | services/prediction/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <math.h> 5 #include <math.h>
6 6
7 #include "services/keyboard_native/view_observer_delegate.h" 7 #include "services/keyboard_native/view_observer_delegate.h"
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/sys_info.h" 10 #include "base/sys_info.h"
11 #include "mojo/gpu/gl_texture.h" 11 #include "mojo/gpu/gl_texture.h"
12 #include "mojo/public/cpp/application/application_impl.h" 12 #include "mojo/public/cpp/application/application_impl.h"
13 #include "mojo/public/cpp/application/connect.h" 13 #include "mojo/public/cpp/application/connect.h"
14 #include "mojo/services/prediction/public/interfaces/prediction.mojom.h"
14 #include "mojo/skia/ganesh_surface.h" 15 #include "mojo/skia/ganesh_surface.h"
15 #include "services/keyboard_native/clip_animation.h" 16 #include "services/keyboard_native/clip_animation.h"
16 #include "services/keyboard_native/keyboard_service_impl.h" 17 #include "services/keyboard_native/keyboard_service_impl.h"
18 #include "services/keyboard_native/predictor.h"
17 #include "skia/ext/refptr.h" 19 #include "skia/ext/refptr.h"
18 #include "third_party/skia/include/core/SkCanvas.h" 20 #include "third_party/skia/include/core/SkCanvas.h"
19 #include "third_party/skia/include/core/SkTypeface.h" 21 #include "third_party/skia/include/core/SkTypeface.h"
20 #include "ui/gfx/geometry/rect_f.h" 22 #include "ui/gfx/geometry/rect_f.h"
21 #include "ui/gfx/shadow_value.h" 23 #include "ui/gfx/shadow_value.h"
22 #include "ui/gfx/skia_util.h" 24 #include "ui/gfx/skia_util.h"
23 #include "ui/gfx/vector2d.h" 25 #include "ui/gfx/vector2d.h"
24 26
25 namespace keyboard { 27 namespace keyboard {
26 28
27 static const base::TimeDelta kAnimationDurationMs = 29 static const base::TimeDelta kAnimationDurationMs =
28 base::TimeDelta::FromMilliseconds(1000); 30 base::TimeDelta::FromMilliseconds(1000);
29 31
30 mojo::Size ToSize(const mojo::Rect& rect) { 32 mojo::Size ToSize(const mojo::Rect& rect) {
31 mojo::Size size; 33 mojo::Size size;
32 size.width = rect.width; 34 size.width = rect.width;
33 size.height = rect.height; 35 size.height = rect.height;
34 return size; 36 return size;
35 } 37 }
36 38
37 ViewObserverDelegate::ViewObserverDelegate() 39 ViewObserverDelegate::ViewObserverDelegate()
38 : keyboard_service_impl_(nullptr), 40 : keyboard_service_impl_(nullptr),
41 predictor_(nullptr),
39 view_(nullptr), 42 view_(nullptr),
40 id_namespace_(0u), 43 id_namespace_(0u),
41 surface_id_(1u), 44 surface_id_(1u),
42 key_layout_(), 45 key_layout_(),
43 needs_draw_(false), 46 needs_draw_(false),
44 frame_pending_(false), 47 frame_pending_(false),
45 floating_key_height_(0.0f), 48 floating_key_height_(0.0f),
46 floating_key_width_(0.0f), 49 floating_key_width_(0.0f),
47 weak_factory_(this) { 50 weak_factory_(this) {
48 key_layout_.SetTextCallback( 51 key_layout_.SetTextCallback(
49 base::Bind(&ViewObserverDelegate::OnText, weak_factory_.GetWeakPtr())); 52 base::Bind(&ViewObserverDelegate::OnText, weak_factory_.GetWeakPtr()));
50 key_layout_.SetDeleteCallback( 53 key_layout_.SetDeleteCallback(
51 base::Bind(&ViewObserverDelegate::OnDelete, weak_factory_.GetWeakPtr())); 54 base::Bind(&ViewObserverDelegate::OnDelete, weak_factory_.GetWeakPtr()));
55 key_layout_.SetSuggestTextCallback(base::Bind(
56 &ViewObserverDelegate::OnSuggestText, weak_factory_.GetWeakPtr()));
52 submit_frame_callback_ = base::Bind(&ViewObserverDelegate::OnFrameComplete, 57 submit_frame_callback_ = base::Bind(&ViewObserverDelegate::OnFrameComplete,
53 weak_factory_.GetWeakPtr()); 58 weak_factory_.GetWeakPtr());
54 } 59 }
55 60
56 ViewObserverDelegate::~ViewObserverDelegate() { 61 ViewObserverDelegate::~ViewObserverDelegate() {
57 } 62 }
58 63
59 void ViewObserverDelegate::SetKeyboardServiceImpl( 64 void ViewObserverDelegate::SetKeyboardServiceImpl(
60 KeyboardServiceImpl* keyboard_service_impl) { 65 KeyboardServiceImpl* keyboard_service_impl) {
61 keyboard_service_impl_ = keyboard_service_impl; 66 keyboard_service_impl_ = keyboard_service_impl;
(...skipping 23 matching lines...) Expand all
85 gr_context_.reset(new mojo::GaneshContext(gl_context_)); 90 gr_context_.reset(new mojo::GaneshContext(gl_context_));
86 mojo::ServiceProviderPtr surfaces_service_provider; 91 mojo::ServiceProviderPtr surfaces_service_provider;
87 shell->ConnectToApplication("mojo:surfaces_service", 92 shell->ConnectToApplication("mojo:surfaces_service",
88 mojo::GetProxy(&surfaces_service_provider), 93 mojo::GetProxy(&surfaces_service_provider),
89 nullptr); 94 nullptr);
90 mojo::ConnectToService(surfaces_service_provider.get(), &surface_); 95 mojo::ConnectToService(surfaces_service_provider.get(), &surface_);
91 surface_->SetResourceReturner(resource_returner.Pass()); 96 surface_->SetResourceReturner(resource_returner.Pass());
92 surface_->CreateSurface(surface_id_); 97 surface_->CreateSurface(surface_id_);
93 surface_->GetIdNamespace(base::Bind(&ViewObserverDelegate::SetIdNamespace, 98 surface_->GetIdNamespace(base::Bind(&ViewObserverDelegate::SetIdNamespace,
94 base::Unretained(this))); 99 base::Unretained(this)));
100 predictor_ = new Predictor(shell);
101 predictor_->SetUpdateCallback(base::Bind(
102 &ViewObserverDelegate::OnUpdateSuggestion, weak_factory_.GetWeakPtr()));
103 key_layout_.SetPredictor(predictor_);
95 IssueDraw(); 104 IssueDraw();
96 } 105 }
97 106
98 void ViewObserverDelegate::OnText(const std::string& text) { 107 void ViewObserverDelegate::OnText(const std::string& text) {
99 keyboard_service_impl_->OnKey(text.c_str()); 108 keyboard_service_impl_->OnKey(text.c_str());
100 } 109 }
101 110
102 void ViewObserverDelegate::OnDelete() { 111 void ViewObserverDelegate::OnDelete() {
103 keyboard_service_impl_->OnDelete(); 112 keyboard_service_impl_->OnDelete();
104 } 113 }
105 114
115 void ViewObserverDelegate::OnSuggestText(const std::string& text) {
116 std::string text_with_space = text + " ";
117 keyboard_service_impl_->OnKey(text_with_space.c_str());
118 }
119
120 void ViewObserverDelegate::OnUpdateSuggestion() {
121 IssueDraw();
122 }
123
106 void ViewObserverDelegate::UpdateState(int32 pointer_id, 124 void ViewObserverDelegate::UpdateState(int32 pointer_id,
107 int action, 125 int action,
108 const gfx::PointF& touch_point) { 126 const gfx::PointF& touch_point) {
109 // Ignore touches outside of key area. 127 // Ignore touches outside of key area.
110 if (!key_area_.Contains(touch_point)) { 128 if (!key_area_.Contains(touch_point)) {
111 return; 129 return;
112 } 130 }
113 131
114 base::TimeTicks current_ticks = base::TimeTicks::Now(); 132 base::TimeTicks current_ticks = base::TimeTicks::Now();
115 133
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 377
360 void ViewObserverDelegate::OnViewDestroyed(mojo::View* view) { 378 void ViewObserverDelegate::OnViewDestroyed(mojo::View* view) {
361 if (view_ == view) { 379 if (view_ == view) {
362 view_->RemoveObserver(this); 380 view_->RemoveObserver(this);
363 view_ = nullptr; 381 view_ = nullptr;
364 gl_context_->Destroy(); 382 gl_context_->Destroy();
365 } 383 }
366 } 384 }
367 385
368 } // namespace keyboard 386 } // namespace keyboard
OLDNEW
« no previous file with comments | « services/keyboard_native/view_observer_delegate.h ('k') | services/prediction/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698