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 // Must hide keyboard container here instead of when animation finished or |
212 // aborted. Otherwise, if we regain focus during hide animation, show | |
213 // animation wont be triggered because Chrome still thinks the keyboard | |
214 // container is visible and ignores show keyboard request. | |
215 container->Hide(); | |
216 container->layer()->SetOpacity(kAnimationStartOrAfterHideOpacity); | |
209 } | 217 } |
210 | 218 |
211 void AshKeyboardControllerProxy::OnLayerAnimationEnded( | 219 void AshKeyboardControllerProxy::OnLayerAnimationEnded( |
212 ui::LayerAnimationSequence* sequence) { | 220 ui::LayerAnimationSequence* sequence) { |
213 if (!animation_window_) | 221 if (!animation_window_) |
214 return; | 222 return; |
223 | |
215 ui::LayerAnimator* animator = animation_window_->layer()->GetAnimator(); | 224 ui::LayerAnimator* animator = animation_window_->layer()->GetAnimator(); |
216 if (animator && !animator->is_animating()) { | 225 if (animator && !animator->is_animating()) { |
217 KeyboardControllerProxy::HideKeyboardContainer(animation_window_); | 226 // Hides keyboard window after keyboard window container's animation |
227 // finished. Otherwise, keyboard window hides immediately and makes it looks | |
228 // like no animation at all. | |
229 GetKeyboardWindow()->Hide(); | |
James Cook
2014/01/15 20:49:57
I'm having a hard time following this and the Hide
bshe
2014/01/16 17:47:58
Looks like it is possible if I add a check conditi
| |
218 animator->RemoveObserver(this); | 230 animator->RemoveObserver(this); |
219 animation_window_ = NULL; | 231 animation_window_ = NULL; |
220 } | 232 } |
221 }; | 233 }; |
222 | 234 |
223 void AshKeyboardControllerProxy::OnLayerAnimationAborted( | 235 void AshKeyboardControllerProxy::OnLayerAnimationAborted( |
224 ui::LayerAnimationSequence* sequence) { | 236 ui::LayerAnimationSequence* sequence) { |
225 if (!animation_window_) | 237 if (!animation_window_) |
226 return; | 238 return; |
227 ui::LayerAnimator* animator = animation_window_->layer()->GetAnimator(); | 239 ui::LayerAnimator* animator = animation_window_->layer()->GetAnimator(); |
(...skipping 21 matching lines...) Expand all Loading... | |
249 input_context->SetString("type", | 261 input_context->SetString("type", |
250 Context::ToString(TextInputTypeToGeneratedInputTypeEnum(type))); | 262 Context::ToString(TextInputTypeToGeneratedInputTypeEnum(type))); |
251 event_args->Append(input_context.release()); | 263 event_args->Append(input_context.release()); |
252 | 264 |
253 scoped_ptr<extensions::Event> event(new extensions::Event( | 265 scoped_ptr<extensions::Event> event(new extensions::Event( |
254 virtual_keyboard_private::OnTextInputBoxFocused::kEventName, | 266 virtual_keyboard_private::OnTextInputBoxFocused::kEventName, |
255 event_args.Pass())); | 267 event_args.Pass())); |
256 event->restrict_to_browser_context = context; | 268 event->restrict_to_browser_context = context; |
257 router->DispatchEventToExtension(kVirtualKeyboardExtensionID, event.Pass()); | 269 router->DispatchEventToExtension(kVirtualKeyboardExtensionID, event.Pass()); |
258 } | 270 } |
OLD | NEW |