Changes launcher auto-hide not to appear if mouse is down.

BUG=120894
TEST=see bug
[email protected]

Review URL: https://chromiumcodereview.appspot.com/10065022

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132066 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/ash/wm/shelf_layout_manager.cc b/ash/wm/shelf_layout_manager.cc
index 1708f37c..c2fd695 100644
--- a/ash/wm/shelf_layout_manager.cc
+++ b/ash/wm/shelf_layout_manager.cc
@@ -49,6 +49,9 @@
   explicit AutoHideEventFilter(ShelfLayoutManager* shelf);
   virtual ~AutoHideEventFilter();
 
+  // Returns true if the last mouse event was a mouse drag.
+  bool in_mouse_drag() const { return in_mouse_drag_; }
+
   // Overridden from aura::EventFilter:
   virtual bool PreHandleKeyEvent(aura::Window* target,
                                  aura::KeyEvent* event) OVERRIDE;
@@ -62,13 +65,15 @@
 
  private:
   ShelfLayoutManager* shelf_;
+  bool in_mouse_drag_;
 
   DISALLOW_COPY_AND_ASSIGN(AutoHideEventFilter);
 };
 
 ShelfLayoutManager::AutoHideEventFilter::AutoHideEventFilter(
     ShelfLayoutManager* shelf)
-    : shelf_(shelf) {
+    : shelf_(shelf),
+      in_mouse_drag_(false) {
   Shell::GetInstance()->AddRootWindowEventFilter(this);
 }
 
@@ -85,6 +90,12 @@
 bool ShelfLayoutManager::AutoHideEventFilter::PreHandleMouseEvent(
     aura::Window* target,
     aura::MouseEvent* event) {
+  // This also checks IsShelfWindow() to make sure we don't attempt to hide the
+  // shelf if the mouse down occurs on the shelf.
+  in_mouse_drag_ = (event->type() == ui::ET_MOUSE_DRAGGED ||
+                    (in_mouse_drag_ && event->type() != ui::ET_MOUSE_RELEASED &&
+                     event->type() != ui::ET_MOUSE_CAPTURE_CHANGED)) &&
+      !shelf_->IsShelfWindow(target);
   if (event->type() == ui::ET_MOUSE_MOVED)
     shelf_->UpdateAutoHideState();
   return false;  // Not handled.
@@ -417,6 +428,10 @@
   if (launcher_widget()->IsActive() || status_->IsActive())
     return AUTO_HIDE_SHOWN;
 
+  // Don't show if the user is dragging the mouse.
+  if (event_filter_.get() && event_filter_->in_mouse_drag())
+    return AUTO_HIDE_HIDDEN;
+
   aura::RootWindow* root = launcher_widget()->GetNativeView()->GetRootWindow();
   bool mouse_over_launcher =
       launcher_widget()->GetWindowScreenBounds().Contains(
@@ -439,5 +454,13 @@
   status_->GetNativeWindow()->set_hit_test_bounds_override_outer(insets);
 }
 
+bool ShelfLayoutManager::IsShelfWindow(aura::Window* window) {
+  if (!window)
+    return false;
+  return (launcher_widget() &&
+          launcher_widget()->GetNativeWindow()->Contains(window)) ||
+      (status_ && status_->GetNativeWindow()->Contains(window));
+}
+
 }  // namespace internal
 }  // namespace ash