Ensure that the OSK pops up when we touch on an input field in chrome desktop mode on windows 8. The
pen input panel API does not work anymore on the later windows 8 builds. The ITextInputPanel API appears
to be working correctly.

R=cpu
BUG=none
TEST=OSK should popup on windows 8 chrome in desktop mode.
Review URL: https://chromiumcodereview.appspot.com/10384193

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137322 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/content/browser/renderer_host/render_widget_host_view_win.cc b/content/browser/renderer_host/render_widget_host_view_win.cc
index c4f776ab..5b844e2 100644
--- a/content/browser/renderer_host/render_widget_host_view_win.cc
+++ b/content/browser/renderer_host/render_widget_host_view_win.cc
@@ -14,6 +14,7 @@
 #include "base/metrics/histogram.h"
 #include "base/process_util.h"
 #include "base/threading/thread.h"
+#include "base/win/metro.h"
 #include "base/win/scoped_comptr.h"
 #include "base/win/scoped_gdi_object.h"
 #include "base/win/win_util.h"
@@ -350,20 +351,12 @@
 void RenderWidgetHostViewWin::CreateWnd(HWND parent) {
   // ATL function to create the window.
   Create(parent);
-  if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
-    // MSDN recommends using the ITextInputPanel interface to display the on
-    // screen keyboard. This interface does not work predictably due to focus
-    // and activation bugs. We use the deprecated IPenInputPanel interface for
-    // now which works reliably with the caveat being that the keyboard cannot
-    // be closed via the system close menu. Esc or clicking elsewhere works.
-    // TODO(ananta): Revisit this.
-    virtual_keyboard_.CreateInstance(CLSID_PenInputPanel, NULL, CLSCTX_INPROC);
+  if (base::win::GetVersion() >= base::win::VERSION_WIN8 &&
+      !base::win::GetMetroModule()) {
+    virtual_keyboard_.CreateInstance(CLSID_TextInputPanel, NULL, CLSCTX_INPROC);
     if (virtual_keyboard_) {
-      virtual_keyboard_->put_AttachedEditWindow(
-          reinterpret_cast<int>(m_hWnd));
-      virtual_keyboard_->put_DefaultPanel(PT_Keyboard);
-      virtual_keyboard_->put_Visible(VARIANT_FALSE);
-      virtual_keyboard_->put_AutoShow(VARIANT_FALSE);
+      virtual_keyboard_->put_AttachedEditWindow(m_hWnd);
+      virtual_keyboard_->SetInPlaceVisibility(FALSE);
     } else {
       NOTREACHED() << "Failed to create instance of pen input panel";
     }
@@ -2337,13 +2330,15 @@
   lparam = MAKELPARAM(point.x, point.y);
 
   if (message == WM_POINTERDOWN) {
-    SetFocus();
-    pointer_down_context_ = true;
-    received_focus_change_after_pointer_down_ = false;
-    MessageLoop::current()->PostDelayedTask(FROM_HERE,
-        base::Bind(&RenderWidgetHostViewWin::ResetPointerDownContext,
-                   weak_factory_.GetWeakPtr()),
-        base::TimeDelta::FromMilliseconds(kPointerDownContextResetDelay));
+    if (!base::win::GetMetroModule()) {
+      SetFocus();
+      pointer_down_context_ = true;
+      received_focus_change_after_pointer_down_ = false;
+      MessageLoop::current()->PostDelayedTask(FROM_HERE,
+          base::Bind(&RenderWidgetHostViewWin::ResetPointerDownContext,
+                     weak_factory_.GetWeakPtr()),
+          base::TimeDelta::FromMilliseconds(kPointerDownContextResetDelay));
+    }
   }
   handled = FALSE;
   return 0;
@@ -2669,10 +2664,10 @@
 void RenderWidgetHostViewWin::DisplayOnScreenKeyboardIfNeeded() {
   if (focus_on_editable_field_) {
     if (pointer_down_context_) {
-      virtual_keyboard_->put_Visible(VARIANT_TRUE);
+      virtual_keyboard_->SetInPlaceVisibility(TRUE);
     }
   } else {
-    virtual_keyboard_->put_Visible(VARIANT_FALSE);
+    virtual_keyboard_->SetInPlaceVisibility(FALSE);
   }
 }
 
diff --git a/content/browser/renderer_host/render_widget_host_view_win.h b/content/browser/renderer_host/render_widget_host_view_win.h
index d6bac76..555683d 100644
--- a/content/browser/renderer_host/render_widget_host_view_win.h
+++ b/content/browser/renderer_host/render_widget_host_view_win.h
@@ -548,9 +548,9 @@
   // members starting from virtual_keyboard_ to
   // received_focus_change_after_pointer_down_.
 
-  // IPenInputPanel to allow us to show the Windows virtual keyboard when a
+  // ITextInputPanel to allow us to show the Windows virtual keyboard when a
   // user touches an editable field on the page.
-  base::win::ScopedComPtr<IPenInputPanel> virtual_keyboard_;
+  base::win::ScopedComPtr<ITextInputPanel> virtual_keyboard_;
 
   // Set to true if we are in the context of a WM_POINTERDOWN message
   bool pointer_down_context_;