Use the physical-pixel space for native IME on linux platform.

What's more, this cl makes a clear spec for the coordinates system in
ui::TextInputClient.

BUG=475718,360334

Review-Url: https://codereview.chromium.org/2593323002
Cr-Commit-Position: refs/heads/master@{#451980}
diff --git a/chrome/browser/ui/libgtkui/x11_input_method_context_impl_gtk.cc b/chrome/browser/ui/libgtkui/x11_input_method_context_impl_gtk.cc
index 65bbe05..cfd6ede 100644
--- a/chrome/browser/ui/libgtkui/x11_input_method_context_impl_gtk.cc
+++ b/chrome/browser/ui/libgtkui/x11_input_method_context_impl_gtk.cc
@@ -21,7 +21,9 @@
 #include "ui/base/ime/text_input_client.h"
 #include "ui/events/event.h"
 #include "ui/events/keycodes/keyboard_code_conversion_x.h"
+#include "ui/gfx/geometry/dip_util.h"
 #include "ui/gfx/x/x11_types.h"
+#include "ui/views/linux_ui/linux_ui.h"
 
 namespace libgtkui {
 
@@ -81,9 +83,11 @@
   gint x = 0;
   gint y = 0;
   gdk_window_get_origin(event->key.window, &x, &y);
-  GdkRectangle rect = {last_caret_bounds_.x() - x, last_caret_bounds_.y() - y,
-                       last_caret_bounds_.width(), last_caret_bounds_.height()};
-  gtk_im_context_set_cursor_location(gtk_context_, &rect);
+
+  GdkRectangle gdk_rect = {
+      last_caret_bounds_.x() - x, last_caret_bounds_.y() - y,
+      last_caret_bounds_.width(), last_caret_bounds_.height()};
+  gtk_im_context_set_cursor_location(gtk_context_, &gdk_rect);
 
   const bool handled =
       gtk_im_context_filter_keypress(gtk_context_, &event->key);
@@ -109,7 +113,12 @@
   // client window, which is unknown at this point.  So we'll call
   // gtk_im_context_set_cursor_location() later in ProcessKeyEvent() where
   // (and only where) we know the client window.
-  last_caret_bounds_ = rect;
+  if (views::LinuxUI::instance()) {
+    last_caret_bounds_ = gfx::ConvertRectToPixel(
+        views::LinuxUI::instance()->GetDeviceScaleFactor(), rect);
+  } else {
+    last_caret_bounds_ = rect;
+  }
 }
 
 // private:
diff --git a/ui/base/ime/text_input_client.h b/ui/base/ime/text_input_client.h
index d76c00a..57bbba4 100644
--- a/ui/base/ime/text_input_client.h
+++ b/ui/base/ime/text_input_client.h
@@ -82,23 +82,15 @@
   virtual bool CanComposeInline() const = 0;
 
   // Returns current caret (insertion point) bounds in the universal screen
-  // coordinates. If there is selection, then the selection bounds will be
-  // returned.
-  // Note: On Windows, the returned value is supposed to be DIP (Density
-  // Independent Pixel).
-  // TODO(ime): Have a clear spec whether the returned value is DIP or not.
-  // http://crbug.com/360334
+  // coordinates in DIP (Density Independent Pixel).
+  // If there is selection, then the selection bounds will be returned.
   virtual gfx::Rect GetCaretBounds() const = 0;
 
   // Retrieves the composition character boundary rectangle in the universal
-  // screen coordinates. The |index| is zero-based index of character position
-  // in composition text.
+  // screen coordinates in DIP (Density Independent Pixel).
+  // The |index| is zero-based index of character position in composition text.
   // Returns false if there is no composition text or |index| is out of range.
   // The |rect| is not touched in the case of failure.
-  // Note: On Windows, the returned value is supposed to be DIP
-  // (Density Independent Pixel).
-  // TODO(ime): Have a clear spec whether the returned value is DIP or not.
-  // http://crbug.com/360334
   virtual bool GetCompositionCharacterBounds(uint32_t index,
                                              gfx::Rect* rect) const = 0;
 
@@ -162,12 +154,9 @@
   // between browser and renderer.
   virtual void ExtendSelectionAndDelete(size_t before, size_t after) = 0;
 
-  // Ensure the caret is not in |rect|.  |rect| is in screen coordinates and
-  // may extend beyond the bounds of this TextInputClient.
-  // Note: On Windows, the returned value is supposed to be DIP (Density
-  // Independent Pixel).
-  // TODO(ime): Have a clear spec whether the returned value is DIP or not.
-  // http://crbug.com/360334
+  // Ensure the caret is not in |rect|.  |rect| is in screen coordinates in
+  // DIP (Density Independent Pixel) and may extend beyond the bounds of this
+  // TextInputClient.
   virtual void EnsureCaretNotInRect(const gfx::Rect& rect) = 0;
 
   // Returns true if |command| is currently allowed to be executed.