Index: content/browser/renderer_host/render_view_host_impl.cc |
diff --git a/content/browser/renderer_host/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc |
index c457e2c339f50a4ca165710470be9a12f0d3b7df..78f5730da7f73ac475fe845d7300640bcb817b14 100644 |
--- a/content/browser/renderer_host/render_view_host_impl.cc |
+++ b/content/browser/renderer_host/render_view_host_impl.cc |
@@ -90,7 +90,10 @@ |
#include "url/url_constants.h" |
#if defined(OS_WIN) |
+#include "base/memory/singleton.h" |
+#include "base/win/osk_display_manager.h" |
#include "base/win/win_util.h" |
+#include "ui/aura/window.h" |
#include "ui/display/win/dpi.h" |
#include "ui/gfx/platform_font_win.h" |
#endif |
@@ -166,6 +169,57 @@ void GetWindowsSpecificPrefs(RendererPreferences* prefs) { |
} // namespace |
+#if defined(OS_WIN) |
ncarter (slow)
2016/05/18 20:09:11
This is getting to be more OS_WIN code in this fil
ananta
2016/05/19 01:57:12
Moved this RenderWidgetHostViewAura.
This involve
|
+// This class implements the base::win::OnScreenKeyboardObserver interface |
+// which provides notifications about the on screen keyboard on Windows getting |
+// displayed or hidden in response to taps on editable fields. |
+class OnScreenKeyboardObserver : public base::win::OnScreenKeyboardObserver { |
+ public: |
+ OnScreenKeyboardObserver(RenderViewHostImpl* host) |
ncarter (slow)
2016/05/18 20:09:11
explicit
ananta
2016/05/19 01:57:13
Done.
|
+ : host_(host) { |
+ } |
+ |
+ // base::win::OnScreenKeyboardObserver overrides. |
+ void OnKeyboardVisible(const RECT& keyboard_rect) override { |
+ DCHECK(host_); |
+ RenderWidgetHostImpl* widget_host = host_->GetWidget(); |
+ if (widget_host && widget_host->GetView()) { |
+ // We use the cursor position to determine whether the tap occurred |
+ // inside the bounds of the on screen keyboard. |
+ POINT cursor_pos = {}; |
+ ::GetCursorPos(&cursor_pos); |
sky
2016/05/18 19:54:51
Is the cursor position always updated for touch? N
ananta
2016/05/19 02:18:47
It is updated for touch. I pass the cursor positio
|
+ if (::PtInRect(&keyboard_rect, cursor_pos)) { |
+ DVLOG(1) << "OSK covering focus point."; |
+ // We set the viewport to the bounds of the keyboard with an offset of |
+ // 10 to ensure that the editable field gets scrolled into view |
+ // correctly. |
+ gfx::Rect display_rect(keyboard_rect); |
+ display_rect.set_y(display_rect.y() - 10); |
+ display_rect.set_height(display_rect.height() - 10); |
+ widget_host->GetView()->SetInsets( |
+ gfx::Insets(0, 0, display_rect.height(), 0)); |
sky
2016/05/18 19:54:52
Shouldn't this depend upon the region of the rende
ananta
2016/05/19 02:18:47
Yeah. Updated. PTAL
|
+ widget_host->ScrollFocusedEditableNodeIntoRect(display_rect); |
+ } else { |
+ // Restore the viewport. |
+ widget_host->GetView()->SetInsets(gfx::Insets()); |
+ } |
+ } |
+ } |
+ |
+ void OnKeyboardHidden(const RECT& keyboard_rect) override { |
+ DCHECK(host_); |
+ RenderWidgetHost* widget_host = host_->GetWidget(); |
+ // Restore the viewport. |
+ if (widget_host && widget_host->GetView()) { |
+ widget_host->GetView()->SetInsets(gfx::Insets()); |
sky
2016/05/18 19:54:52
Should this be done in the constructor too?
ananta
2016/05/19 01:57:12
Done.
|
+ } |
+ } |
+ |
+ private: |
+ RenderViewHostImpl* host_; |
+}; |
sky
2016/05/18 19:54:51
DISALLOW...
ananta
2016/05/19 01:57:13
Done.
|
+#endif |
+ |
// static |
const int64_t RenderViewHostImpl::kUnloadTimeoutMS = 1000; |
@@ -1299,13 +1353,18 @@ void RenderViewHostImpl::OnRunFileChooser(const FileChooserParams& params) { |
void RenderViewHostImpl::OnFocusedNodeTouched(bool editable) { |
#if defined(OS_WIN) |
+ base::win::OnScreenKeyboardDisplayManager* osk_display_manager = |
+ base::win::OnScreenKeyboardDisplayManager::GetInstance(); |
+ DCHECK(osk_display_manager); |
if (editable) { |
- virtual_keyboard_requested_ = base::win::DisplayVirtualKeyboard(); |
+ keyboard_observer_.reset(new OnScreenKeyboardObserver(this)); |
sky
2016/05/18 19:54:51
Is it possible the keyboard is already visible at
ananta
2016/05/19 01:57:13
I don't think that would be needed. The DisplayVir
|
+ virtual_keyboard_requested_ = osk_display_manager->DisplayVirtualKeyboard( |
+ keyboard_observer_.get()); |
delegate_->SetIsVirtualKeyboardRequested(true); |
} else { |
virtual_keyboard_requested_ = false; |
delegate_->SetIsVirtualKeyboardRequested(false); |
- base::win::DismissVirtualKeyboard(); |
+ osk_display_manager->DismissVirtualKeyboard(keyboard_observer_.get()); |
ncarter (slow)
2016/05/18 20:09:11
It's not clear to me why this DismissVirtualKeyboa
ananta
2016/05/19 01:57:12
Yes. Removed the observer parameter.
|
} |
#endif |
} |