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/content/keyboard_ui_content.h" | 5 #include "ui/keyboard/content/keyboard_ui_content.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "content/public/browser/render_widget_host.h" | 9 #include "content/public/browser/render_widget_host.h" |
10 #include "content/public/browser/render_widget_host_iterator.h" | 10 #include "content/public/browser/render_widget_host_iterator.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 DCHECK(keyboard_contents_); | 153 DCHECK(keyboard_contents_); |
154 if (keyboard_contents_->GetURL() != default_url_) { | 154 if (keyboard_contents_->GetURL() != default_url_) { |
155 // TODO(bshe): The height of system virtual keyboard and IME virtual | 155 // TODO(bshe): The height of system virtual keyboard and IME virtual |
156 // keyboard may different. The height needs to be restored too. | 156 // keyboard may different. The height needs to be restored too. |
157 LoadContents(default_url_); | 157 LoadContents(default_url_); |
158 } | 158 } |
159 } | 159 } |
160 | 160 |
161 void KeyboardUIContent::UpdateInsetsForWindow(aura::Window* window) { | 161 void KeyboardUIContent::UpdateInsetsForWindow(aura::Window* window) { |
162 aura::Window* keyboard_window = GetKeyboardWindow(); | 162 aura::Window* keyboard_window = GetKeyboardWindow(); |
| 163 if (!ShouldWindowOverscroll(window)) |
| 164 return; |
| 165 |
163 scoped_ptr<content::RenderWidgetHostIterator> widgets( | 166 scoped_ptr<content::RenderWidgetHostIterator> widgets( |
164 content::RenderWidgetHost::GetRenderWidgetHosts()); | 167 content::RenderWidgetHost::GetRenderWidgetHosts()); |
165 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { | 168 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { |
166 content::RenderWidgetHostView* view = widget->GetView(); | 169 content::RenderWidgetHostView* view = widget->GetView(); |
167 if (view && window->Contains(view->GetNativeView())) { | 170 if (view && window->Contains(view->GetNativeView())) { |
168 gfx::Rect window_bounds = view->GetNativeView()->GetBoundsInScreen(); | 171 gfx::Rect window_bounds = view->GetNativeView()->GetBoundsInScreen(); |
169 gfx::Rect intersect = | 172 gfx::Rect intersect = |
170 gfx::IntersectRects(window_bounds, keyboard_window->bounds()); | 173 gfx::IntersectRects(window_bounds, keyboard_window->bounds()); |
171 int overlap = ShouldEnableInsets(window) ? intersect.height() : 0; | 174 int overlap = ShouldEnableInsets(window) ? intersect.height() : 0; |
172 if (overlap > 0 && overlap < window_bounds.height()) | 175 if (overlap > 0 && overlap < window_bounds.height()) |
(...skipping 18 matching lines...) Expand all Loading... |
191 keyboard_contents_->GetNativeView()->AddObserver(this); | 194 keyboard_contents_->GetNativeView()->AddObserver(this); |
192 } | 195 } |
193 | 196 |
194 return keyboard_contents_->GetNativeView(); | 197 return keyboard_contents_->GetNativeView(); |
195 } | 198 } |
196 | 199 |
197 bool KeyboardUIContent::HasKeyboardWindow() const { | 200 bool KeyboardUIContent::HasKeyboardWindow() const { |
198 return keyboard_contents_; | 201 return keyboard_contents_; |
199 } | 202 } |
200 | 203 |
| 204 bool KeyboardUIContent::ShouldWindowOverscroll(aura::Window* window) const { |
| 205 return true; |
| 206 } |
| 207 |
201 void KeyboardUIContent::ReloadKeyboardIfNeeded() { | 208 void KeyboardUIContent::ReloadKeyboardIfNeeded() { |
202 DCHECK(keyboard_contents_); | 209 DCHECK(keyboard_contents_); |
203 if (keyboard_contents_->GetURL() != GetVirtualKeyboardUrl()) { | 210 if (keyboard_contents_->GetURL() != GetVirtualKeyboardUrl()) { |
204 if (keyboard_contents_->GetURL().GetOrigin() != | 211 if (keyboard_contents_->GetURL().GetOrigin() != |
205 GetVirtualKeyboardUrl().GetOrigin()) { | 212 GetVirtualKeyboardUrl().GetOrigin()) { |
206 // Sets keyboard window rectangle to 0 and close current page before | 213 // Sets keyboard window rectangle to 0 and close current page before |
207 // navigate to a keyboard in a different extension. This keeps the UX the | 214 // navigate to a keyboard in a different extension. This keeps the UX the |
208 // same as Android. Note we need to explicitly close current page as it | 215 // same as Android. Note we need to explicitly close current page as it |
209 // might try to resize keyboard window in javascript on a resize event. | 216 // might try to resize keyboard window in javascript on a resize event. |
210 GetKeyboardWindow()->SetBounds(gfx::Rect()); | 217 GetKeyboardWindow()->SetBounds(gfx::Rect()); |
211 keyboard_contents_->ClosePage(); | 218 keyboard_contents_->ClosePage(); |
212 keyboard_controller()->SetKeyboardMode(FULL_WIDTH); | 219 keyboard_controller()->SetKeyboardMode(FULL_WIDTH); |
213 } | 220 } |
214 LoadContents(GetVirtualKeyboardUrl()); | 221 LoadContents(GetVirtualKeyboardUrl()); |
215 } | 222 } |
216 } | 223 } |
217 | 224 |
218 void KeyboardUIContent::InitInsets(const gfx::Rect& new_bounds) { | 225 void KeyboardUIContent::InitInsets(const gfx::Rect& new_bounds) { |
219 // Adjust the height of the viewport for visible windows on the primary | 226 // Adjust the height of the viewport for visible windows on the primary |
220 // display. | 227 // display. |
221 // TODO(kevers): Add EnvObserver to properly initialize insets if a | 228 // TODO(kevers): Add EnvObserver to properly initialize insets if a |
222 // window is created while the keyboard is visible. | 229 // window is created while the keyboard is visible. |
223 scoped_ptr<content::RenderWidgetHostIterator> widgets( | 230 scoped_ptr<content::RenderWidgetHostIterator> widgets( |
224 content::RenderWidgetHost::GetRenderWidgetHosts()); | 231 content::RenderWidgetHost::GetRenderWidgetHosts()); |
225 aura::Window* keyboard_window = GetKeyboardWindow(); | |
226 aura::Window* root_window = keyboard_window->GetRootWindow(); | |
227 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { | 232 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { |
228 content::RenderWidgetHostView* view = widget->GetView(); | 233 content::RenderWidgetHostView* view = widget->GetView(); |
229 // Can be NULL, e.g. if the RenderWidget is being destroyed or | 234 // Can be NULL, e.g. if the RenderWidget is being destroyed or |
230 // the render process crashed. | 235 // the render process crashed. |
231 if (view) { | 236 if (view) { |
232 aura::Window* window = view->GetNativeView(); | 237 aura::Window* window = view->GetNativeView(); |
233 // If virtual keyboard failed to load, a widget that displays error | 238 if (ShouldWindowOverscroll(window)) { |
234 // message will be created and adds as a child of the virtual keyboard | |
235 // window. We want to avoid add BoundsChangedObserver to that window. | |
236 if (!keyboard_window->Contains(window) && | |
237 window->GetRootWindow() == root_window) { | |
238 gfx::Rect window_bounds = window->GetBoundsInScreen(); | 239 gfx::Rect window_bounds = window->GetBoundsInScreen(); |
239 gfx::Rect intersect = gfx::IntersectRects(window_bounds, | 240 gfx::Rect intersect = gfx::IntersectRects(window_bounds, |
240 new_bounds); | 241 new_bounds); |
241 int overlap = intersect.height(); | 242 int overlap = intersect.height(); |
242 if (overlap > 0 && overlap < window_bounds.height()) | 243 if (overlap > 0 && overlap < window_bounds.height()) |
243 view->SetInsets(gfx::Insets(0, 0, overlap, 0)); | 244 view->SetInsets(gfx::Insets(0, 0, overlap, 0)); |
244 else | 245 else |
245 view->SetInsets(gfx::Insets()); | 246 view->SetInsets(gfx::Insets()); |
246 AddBoundsChangedObserver(window); | 247 AddBoundsChangedObserver(window); |
247 } | 248 } |
(...skipping 28 matching lines...) Expand all Loading... |
276 shadow_->layer()); | 277 shadow_->layer()); |
277 } | 278 } |
278 | 279 |
279 shadow_->SetContentBounds(new_bounds); | 280 shadow_->SetContentBounds(new_bounds); |
280 } | 281 } |
281 | 282 |
282 void KeyboardUIContent::OnWindowDestroyed(aura::Window* window) { | 283 void KeyboardUIContent::OnWindowDestroyed(aura::Window* window) { |
283 window->RemoveObserver(this); | 284 window->RemoveObserver(this); |
284 } | 285 } |
285 | 286 |
| 287 const aura::Window* KeyboardUIContent::GetKeyboardRootWindow() const { |
| 288 if (!keyboard_contents_) { |
| 289 return nullptr; |
| 290 } |
| 291 return keyboard_contents_->GetNativeView()->GetRootWindow(); |
| 292 } |
| 293 |
286 void KeyboardUIContent::LoadContents(const GURL& url) { | 294 void KeyboardUIContent::LoadContents(const GURL& url) { |
287 if (keyboard_contents_) { | 295 if (keyboard_contents_) { |
288 content::OpenURLParams params( | 296 content::OpenURLParams params( |
289 url, | 297 url, |
290 content::Referrer(), | 298 content::Referrer(), |
291 SINGLETON_TAB, | 299 SINGLETON_TAB, |
292 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 300 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
293 false); | 301 false); |
294 keyboard_contents_->OpenURL(params); | 302 keyboard_contents_->OpenURL(params); |
295 } | 303 } |
(...skipping 16 matching lines...) Expand all Loading... |
312 keyboard_controller()->keyboard_visible()); | 320 keyboard_controller()->keyboard_visible()); |
313 } | 321 } |
314 | 322 |
315 void KeyboardUIContent::AddBoundsChangedObserver(aura::Window* window) { | 323 void KeyboardUIContent::AddBoundsChangedObserver(aura::Window* window) { |
316 aura::Window* target_window = window ? window->GetToplevelWindow() : nullptr; | 324 aura::Window* target_window = window ? window->GetToplevelWindow() : nullptr; |
317 if (target_window) | 325 if (target_window) |
318 window_bounds_observer_->AddObservedWindow(target_window); | 326 window_bounds_observer_->AddObservedWindow(target_window); |
319 } | 327 } |
320 | 328 |
321 } // namespace keyboard | 329 } // namespace keyboard |
OLD | NEW |