OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/browser/ui/ash/ash_keyboard_controller_proxy.h" | 5 #include "chrome/browser/ui/ash/ash_keyboard_controller_proxy.h" |
6 | 6 |
7 #include "ash/display/display_controller.h" | 7 #include "ash/display/display_controller.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "chrome/browser/extensions/event_names.h" | 9 #include "chrome/browser/extensions/event_names.h" |
10 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 10 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
34 namespace virtual_keyboard_private = extensions::api::virtual_keyboard_private; | 34 namespace virtual_keyboard_private = extensions::api::virtual_keyboard_private; |
35 typedef virtual_keyboard_private::OnTextInputBoxFocused::Context Context; | 35 typedef virtual_keyboard_private::OnTextInputBoxFocused::Context Context; |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 const char* kVirtualKeyboardExtensionID = "mppnpdlheglhdfmldimlhpnegondlapf"; | 39 const char* kVirtualKeyboardExtensionID = "mppnpdlheglhdfmldimlhpnegondlapf"; |
40 | 40 |
41 // The virtual keyboard show/hide animation duration. | 41 // The virtual keyboard show/hide animation duration. |
42 const int kAnimationDurationMs = 200; | 42 const int kAnimationDurationMs = 200; |
43 | 43 |
44 // The opacity of virtual keyboard container when show animation starts or | |
45 // hide animation finishes. | |
46 const float kAnimationStartOrAfterHideOpacity = 0.2f; | |
47 | |
44 Context::Type TextInputTypeToGeneratedInputTypeEnum(ui::TextInputType type) { | 48 Context::Type TextInputTypeToGeneratedInputTypeEnum(ui::TextInputType type) { |
45 switch (type) { | 49 switch (type) { |
46 case ui::TEXT_INPUT_TYPE_NONE: | 50 case ui::TEXT_INPUT_TYPE_NONE: |
47 return Context::TYPE_NONE; | 51 return Context::TYPE_NONE; |
48 case ui::TEXT_INPUT_TYPE_PASSWORD: | 52 case ui::TEXT_INPUT_TYPE_PASSWORD: |
49 return Context::TYPE_PASSWORD; | 53 return Context::TYPE_PASSWORD; |
50 case ui::TEXT_INPUT_TYPE_EMAIL: | 54 case ui::TEXT_INPUT_TYPE_EMAIL: |
51 return Context::TYPE_EMAIL; | 55 return Context::TYPE_EMAIL; |
52 case ui::TEXT_INPUT_TYPE_NUMBER: | 56 case ui::TEXT_INPUT_TYPE_NUMBER: |
53 return Context::TYPE_NUMBER; | 57 return Context::TYPE_NUMBER; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 if (container->GetRootWindow() != ash::Shell::GetPrimaryRootWindow()) | 155 if (container->GetRootWindow() != ash::Shell::GetPrimaryRootWindow()) |
152 NOTIMPLEMENTED(); | 156 NOTIMPLEMENTED(); |
153 | 157 |
154 ui::LayerAnimator* container_animator = container->layer()->GetAnimator(); | 158 ui::LayerAnimator* container_animator = container->layer()->GetAnimator(); |
155 // If the container is not animating, makes sure the position and opacity | 159 // If the container is not animating, makes sure the position and opacity |
156 // are at begin states for animation. | 160 // are at begin states for animation. |
157 if (!container_animator->is_animating()) { | 161 if (!container_animator->is_animating()) { |
158 gfx::Transform transform; | 162 gfx::Transform transform; |
159 transform.Translate(0, GetKeyboardWindow()->bounds().height()); | 163 transform.Translate(0, GetKeyboardWindow()->bounds().height()); |
160 container->SetTransform(transform); | 164 container->SetTransform(transform); |
161 container->layer()->SetOpacity(0.0); | 165 container->layer()->SetOpacity(kAnimationStartOrAfterHideOpacity); |
162 } | 166 } |
163 | 167 |
168 container_animator->set_preemption_strategy( | |
169 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
170 | |
164 { | 171 { |
165 // Scope the following animation settings as we don't want to animate | 172 // Scope the following animation settings as we don't want to animate |
166 // visibility change that triggered by a call to the base class function | 173 // visibility change that triggered by a call to the base class function |
167 // ShowKeyboardContainer with these settings. The container should become | 174 // ShowKeyboardContainer with these settings. The container should become |
168 // visible immediately. | 175 // visible immediately. |
169 ui::ScopedLayerAnimationSettings settings(container_animator); | 176 ui::ScopedLayerAnimationSettings settings(container_animator); |
170 settings.SetPreemptionStrategy( | |
171 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
172 settings.SetTweenType(gfx::Tween::EASE_IN); | 177 settings.SetTweenType(gfx::Tween::EASE_IN); |
173 settings.SetTransitionDuration( | 178 settings.SetTransitionDuration( |
174 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); | 179 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); |
175 container->SetTransform(gfx::Transform()); | 180 container->SetTransform(gfx::Transform()); |
176 container->layer()->SetOpacity(1.0); | 181 container->layer()->SetOpacity(1.0); |
177 } | 182 } |
178 | 183 |
179 // TODO(bshe): Add animation observer and do the workspace resizing after | 184 // TODO(bshe): Add animation observer and do the workspace resizing after |
180 // animation finished. | 185 // animation finished. |
181 KeyboardControllerProxy::ShowKeyboardContainer(container); | 186 KeyboardControllerProxy::ShowKeyboardContainer(container); |
182 // GetTextInputClient may return NULL when keyboard-usability-experiment flag | 187 // GetTextInputClient may return NULL when keyboard-usability-experiment flag |
183 // is set. | 188 // is set. |
184 if (GetInputMethod()->GetTextInputClient()) { | 189 if (GetInputMethod()->GetTextInputClient()) { |
185 gfx::Rect showing_area = | 190 gfx::Rect showing_area = |
186 ash::DisplayController::GetPrimaryDisplay().work_area(); | 191 ash::DisplayController::GetPrimaryDisplay().work_area(); |
187 GetInputMethod()->GetTextInputClient()->EnsureCaretInRect(showing_area); | 192 GetInputMethod()->GetTextInputClient()->EnsureCaretInRect(showing_area); |
188 } | 193 } |
189 } | 194 } |
190 | 195 |
191 void AshKeyboardControllerProxy::HideKeyboardContainer( | 196 void AshKeyboardControllerProxy::HideKeyboardContainer( |
192 aura::Window* container) { | 197 aura::Window* container) { |
193 // The following animation settings should persist within this function scope. | 198 // The following animation settings should persist within this function scope. |
194 // Otherwise, a call to base class function HideKeyboardContainer will hide | 199 // Otherwise, a call to base class function HideKeyboardContainer will hide |
195 // the container immediately. | 200 // the container immediately. |
196 ui::LayerAnimator* container_animator = container->layer()->GetAnimator(); | 201 ui::LayerAnimator* container_animator = container->layer()->GetAnimator(); |
197 container_animator->AddObserver(this); | 202 container_animator->AddObserver(this); |
198 animation_window_ = container; | 203 animation_window_ = container; |
199 ui::ScopedLayerAnimationSettings settings(container_animator); | 204 ui::ScopedLayerAnimationSettings settings(container_animator); |
200 settings.SetPreemptionStrategy( | |
201 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
202 settings.SetTweenType(gfx::Tween::EASE_OUT); | 205 settings.SetTweenType(gfx::Tween::EASE_OUT); |
203 settings.SetTransitionDuration( | 206 settings.SetTransitionDuration( |
204 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); | 207 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); |
205 gfx::Transform transform; | 208 gfx::Transform transform; |
206 transform.Translate(0, GetKeyboardWindow()->bounds().height()); | 209 transform.Translate(0, GetKeyboardWindow()->bounds().height()); |
207 container->SetTransform(transform); | 210 container->SetTransform(transform); |
208 container->layer()->SetOpacity(0.0); | 211 container->layer()->SetOpacity(kAnimationStartOrAfterHideOpacity); |
209 } | 212 } |
210 | 213 |
211 void AshKeyboardControllerProxy::OnLayerAnimationEnded( | 214 void AshKeyboardControllerProxy::OnLayerAnimationEnded( |
212 ui::LayerAnimationSequence* sequence) { | 215 ui::LayerAnimationSequence* sequence) { |
213 if (!animation_window_) | 216 if (!animation_window_) |
214 return; | 217 return; |
215 ui::LayerAnimator* animator = animation_window_->layer()->GetAnimator(); | 218 ui::LayerAnimator* animator = animation_window_->layer()->GetAnimator(); |
216 if (animator && !animator->is_animating()) { | 219 if (!animator->is_animating()) { |
217 KeyboardControllerProxy::HideKeyboardContainer(animation_window_); | 220 KeyboardControllerProxy::HideKeyboardContainer(animation_window_); |
218 animator->RemoveObserver(this); | 221 animator->RemoveObserver(this); |
James Cook
2014/01/16 17:55:03
Is it possible to leak this observer? I'm not cle
bshe
2014/01/16 20:09:04
We have a few animations at the same time. So OnLa
| |
219 animation_window_ = NULL; | 222 animation_window_ = NULL; |
220 } | 223 } |
221 }; | 224 }; |
222 | 225 |
223 void AshKeyboardControllerProxy::OnLayerAnimationAborted( | 226 void AshKeyboardControllerProxy::OnLayerAnimationAborted( |
224 ui::LayerAnimationSequence* sequence) { | 227 ui::LayerAnimationSequence* sequence) { |
225 if (!animation_window_) | 228 if (!animation_window_) |
226 return; | 229 return; |
227 ui::LayerAnimator* animator = animation_window_->layer()->GetAnimator(); | 230 animation_window_->layer()->GetAnimator()->RemoveObserver(this); |
228 if (animator) { | |
229 animator->RemoveObserver(this); | |
230 } | |
231 animation_window_ = NULL; | 231 animation_window_ = NULL; |
232 }; | 232 }; |
233 | 233 |
234 void AshKeyboardControllerProxy::SetUpdateInputType(ui::TextInputType type) { | 234 void AshKeyboardControllerProxy::SetUpdateInputType(ui::TextInputType type) { |
235 // TODO(bshe): Need to check the affected window's profile once multi-profile | 235 // TODO(bshe): Need to check the affected window's profile once multi-profile |
236 // is supported. | 236 // is supported. |
237 content::BrowserContext* context = GetBrowserContext(); | 237 content::BrowserContext* context = GetBrowserContext(); |
238 extensions::EventRouter* router = | 238 extensions::EventRouter* router = |
239 extensions::ExtensionSystem::GetForBrowserContext(context)-> | 239 extensions::ExtensionSystem::GetForBrowserContext(context)-> |
240 event_router(); | 240 event_router(); |
241 | 241 |
242 if (!router->HasEventListener( | 242 if (!router->HasEventListener( |
243 virtual_keyboard_private::OnTextInputBoxFocused::kEventName)) { | 243 virtual_keyboard_private::OnTextInputBoxFocused::kEventName)) { |
244 return; | 244 return; |
245 } | 245 } |
246 | 246 |
247 scoped_ptr<base::ListValue> event_args(new base::ListValue()); | 247 scoped_ptr<base::ListValue> event_args(new base::ListValue()); |
248 scoped_ptr<base::DictionaryValue> input_context(new base::DictionaryValue()); | 248 scoped_ptr<base::DictionaryValue> input_context(new base::DictionaryValue()); |
249 input_context->SetString("type", | 249 input_context->SetString("type", |
250 Context::ToString(TextInputTypeToGeneratedInputTypeEnum(type))); | 250 Context::ToString(TextInputTypeToGeneratedInputTypeEnum(type))); |
251 event_args->Append(input_context.release()); | 251 event_args->Append(input_context.release()); |
252 | 252 |
253 scoped_ptr<extensions::Event> event(new extensions::Event( | 253 scoped_ptr<extensions::Event> event(new extensions::Event( |
254 virtual_keyboard_private::OnTextInputBoxFocused::kEventName, | 254 virtual_keyboard_private::OnTextInputBoxFocused::kEventName, |
255 event_args.Pass())); | 255 event_args.Pass())); |
256 event->restrict_to_browser_context = context; | 256 event->restrict_to_browser_context = context; |
257 router->DispatchEventToExtension(kVirtualKeyboardExtensionID, event.Pass()); | 257 router->DispatchEventToExtension(kVirtualKeyboardExtensionID, event.Pass()); |
258 } | 258 } |
OLD | NEW |