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 "ui/keyboard/keyboard_controller.h" | 5 #include "ui/keyboard/keyboard_controller.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 command.AppendArg("1"); | 138 command.AppendArg("1"); |
139 else | 139 else |
140 command.AppendArg("0"); | 140 command.AppendArg("0"); |
141 VLOG(1) << "Running " << command.GetCommandLineString(); | 141 VLOG(1) << "Running " << command.GetCommandLineString(); |
142 base::LaunchOptions options; | 142 base::LaunchOptions options; |
143 options.wait = true; | 143 options.wait = true; |
144 base::LaunchProcess(command, options, NULL); | 144 base::LaunchProcess(command, options, NULL); |
145 #endif | 145 #endif |
146 } | 146 } |
147 | 147 |
148 aura::Window *GetFrameWindow(aura::Window *window) { | |
149 // Each container window has a non-negative id. Stop traversing at the child | |
150 // of a container window. | |
151 if (!window) | |
152 return NULL; | |
153 while (window->parent() && window->parent()->id() < 0) { | |
154 window = window->parent(); | |
155 } | |
156 return window; | |
157 } | |
158 | |
159 } // namespace | 148 } // namespace |
160 | 149 |
161 namespace keyboard { | 150 namespace keyboard { |
162 | 151 |
163 // Observer for both keyboard show and hide animations. It should be owned by | 152 // Observer for both keyboard show and hide animations. It should be owned by |
164 // KeyboardController. | 153 // KeyboardController. |
165 class CallbackAnimationObserver : public ui::LayerAnimationObserver { | 154 class CallbackAnimationObserver : public ui::LayerAnimationObserver { |
166 public: | 155 public: |
167 CallbackAnimationObserver(ui::LayerAnimator* animator, | 156 CallbackAnimationObserver(ui::LayerAnimator* animator, |
168 base::Callback<void(void)> callback); | 157 base::Callback<void(void)> callback); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 FOR_EACH_OBSERVER(KeyboardControllerObserver, | 291 FOR_EACH_OBSERVER(KeyboardControllerObserver, |
303 observer_list_, | 292 observer_list_, |
304 OnKeyboardBoundsChanging(new_bounds)); | 293 OnKeyboardBoundsChanging(new_bounds)); |
305 if (keyboard::IsKeyboardOverscrollEnabled()) { | 294 if (keyboard::IsKeyboardOverscrollEnabled()) { |
306 // Adjust the height of the viewport for visible windows on the primary | 295 // Adjust the height of the viewport for visible windows on the primary |
307 // display. | 296 // display. |
308 // TODO(kevers): Add EnvObserver to properly initialize insets if a | 297 // TODO(kevers): Add EnvObserver to properly initialize insets if a |
309 // window is created while the keyboard is visible. | 298 // window is created while the keyboard is visible. |
310 scoped_ptr<content::RenderWidgetHostIterator> widgets( | 299 scoped_ptr<content::RenderWidgetHostIterator> widgets( |
311 content::RenderWidgetHost::GetRenderWidgetHosts()); | 300 content::RenderWidgetHost::GetRenderWidgetHosts()); |
312 aura::Window *keyboard_window = proxy_->GetKeyboardWindow(); | 301 aura::Window* keyboard_window = proxy_->GetKeyboardWindow(); |
313 aura::Window *root_window = keyboard_window->GetRootWindow(); | 302 aura::Window* root_window = keyboard_window->GetRootWindow(); |
314 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { | 303 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { |
315 content::RenderWidgetHostView* view = widget->GetView(); | 304 content::RenderWidgetHostView* view = widget->GetView(); |
316 // Can be NULL, e.g. if the RenderWidget is being destroyed or | 305 // Can be NULL, e.g. if the RenderWidget is being destroyed or |
317 // the render process crashed. | 306 // the render process crashed. |
318 if (view) { | 307 if (view) { |
319 aura::Window *window = view->GetNativeView(); | 308 aura::Window* window = view->GetNativeView(); |
320 // If virtual keyboard failed to load, a widget that displays error | 309 // If virtual keyboard failed to load, a widget that displays error |
321 // message will be created and adds as a child of the virtual keyboard | 310 // message will be created and adds as a child of the virtual keyboard |
322 // window. We want to avoid add BoundsChangedObserver to that window. | 311 // window. We want to avoid add BoundsChangedObserver to that window. |
323 if (GetFrameWindow(window) != keyboard_window && | 312 if (!keyboard_window->Contains(window) && |
324 window->GetRootWindow() == root_window) { | 313 window->GetRootWindow() == root_window) { |
325 gfx::Rect window_bounds = window->GetBoundsInScreen(); | 314 gfx::Rect window_bounds = window->GetBoundsInScreen(); |
326 gfx::Rect intersect = gfx::IntersectRects(window_bounds, | 315 gfx::Rect intersect = gfx::IntersectRects(window_bounds, |
327 new_bounds); | 316 new_bounds); |
328 int overlap = intersect.height(); | 317 int overlap = intersect.height(); |
329 if (overlap > 0 && overlap < window_bounds.height()) | 318 if (overlap > 0 && overlap < window_bounds.height()) |
330 view->SetInsets(gfx::Insets(0, 0, overlap, 0)); | 319 view->SetInsets(gfx::Insets(0, 0, overlap, 0)); |
331 else | 320 else |
332 view->SetInsets(gfx::Insets()); | 321 view->SetInsets(gfx::Insets()); |
333 AddBoundsChangedObserver(window); | 322 AddBoundsChangedObserver(window); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 // background during animation. | 558 // background during animation. |
570 NotifyKeyboardBoundsChanging(proxy_->GetKeyboardWindow()->bounds()); | 559 NotifyKeyboardBoundsChanging(proxy_->GetKeyboardWindow()->bounds()); |
571 proxy_->EnsureCaretInWorkArea(); | 560 proxy_->EnsureCaretInWorkArea(); |
572 } | 561 } |
573 | 562 |
574 void KeyboardController::HideAnimationFinished() { | 563 void KeyboardController::HideAnimationFinished() { |
575 proxy_->HideKeyboardContainer(container_.get()); | 564 proxy_->HideKeyboardContainer(container_.get()); |
576 } | 565 } |
577 | 566 |
578 void KeyboardController::AddBoundsChangedObserver(aura::Window* window) { | 567 void KeyboardController::AddBoundsChangedObserver(aura::Window* window) { |
579 aura::Window* target_window = GetFrameWindow(window); | 568 aura::Window* target_window = window ? window->GetToplevelWindow() : nullptr; |
580 if (target_window) | 569 if (target_window) |
581 window_bounds_observer_->AddObservedWindow(target_window); | 570 window_bounds_observer_->AddObservedWindow(target_window); |
582 } | 571 } |
583 | 572 |
584 } // namespace keyboard | 573 } // namespace keyboard |
OLD | NEW |