Ignore whitespace input in fakebox when focused

This change fixes the bug from the omnibox side. When the fakebox is
focused, the omnibox will be in an "invisible focus" state. So these
changes prevent the focus state to change if whitespace is inputted or
pasted into the fakebox. The existing behaviour for dragging whitespace
text into the fakebox does not hide the fakebox. That was not changed.

A small change was made to the fakebox cursor, so when the fakebox is
hidden, hovering over that area shows the default cursor instead of the
text cursor.

R=ramyan@chromium.org, treib@chromium.org

Bug: 727302
Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: Id075e3e52113d5e8e27e2e1bab74926a6b8bc723
Reviewed-on: https://chromium-review.googlesource.com/1127488
Commit-Queue: Justin Donnelly <jdonnelly@chromium.org>
Reviewed-by: Justin Donnelly <jdonnelly@chromium.org>
Reviewed-by: Marc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575188}
diff --git a/chrome/browser/resources/local_ntp/local_ntp.css b/chrome/browser/resources/local_ntp/local_ntp.css
index cf01786..3b5ee1a 100644
--- a/chrome/browser/resources/local_ntp/local_ntp.css
+++ b/chrome/browser/resources/local_ntp/local_ntp.css
@@ -110,7 +110,7 @@
 }
 
 body.hide-fakebox #fakebox {
-  opacity: 0;
+  visibility: hidden;
 }
 
 #logo {
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
index 4f90b68..3b18428 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
@@ -437,16 +437,24 @@
 
 void OmniboxViewViews::OnPaste() {
   const base::string16 text(GetClipboardText());
-  if (!text.empty()) {
-    OnBeforePossibleChange();
-    // Record this paste, so we can do different behavior.
-    model()->OnPaste();
-    // Force a Paste operation to trigger the text_changed code in
-    // OnAfterPossibleChange(), even if identical contents are pasted.
-    state_before_change_.text.clear();
-    InsertOrReplaceText(text);
-    OnAfterPossibleChange(true);
+
+  if (text.empty() ||
+      // When the fakebox is focused, ignore pasted whitespace because if the
+      // fakebox is hidden and there's only whitespace in the omnibox, it's
+      // difficult for the user to see that the focus moved to the omnibox.
+      (model()->focus_state() == OMNIBOX_FOCUS_INVISIBLE &&
+       std::all_of(text.begin(), text.end(), base::IsUnicodeWhitespace))) {
+    return;
   }
+
+  OnBeforePossibleChange();
+  // Record this paste, so we can do different behavior.
+  model()->OnPaste();
+  // Force a Paste operation to trigger the text_changed code in
+  // OnAfterPossibleChange(), even if identical contents are pasted.
+  state_before_change_.text.clear();
+  InsertOrReplaceText(text);
+  OnAfterPossibleChange(true);
 }
 
 bool OmniboxViewViews::HandleEarlyTabActions(const ui::KeyEvent& event) {
@@ -1095,6 +1103,14 @@
 }
 
 void OmniboxViewViews::DoInsertChar(base::char16 ch) {
+  // When the fakebox is focused, ignore whitespace input because if the
+  // fakebox is hidden and there's only whitespace in the omnibox, it's
+  // difficult for the user to see that the focus moved to the omnibox.
+  if ((model()->focus_state() == OMNIBOX_FOCUS_INVISIBLE) &&
+      base::IsUnicodeWhitespace(ch)) {
+    return;
+  }
+
   // If |insert_char_time_| is not null, there's a pending insert char operation
   // that hasn't been painted yet. Keep the earlier time.
   if (insert_char_time_.is_null()) {