Home | History | Annotate | Download | only in display
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef ASH_DISPLAY_MOUSE_CURSOR_EVENT_FILTER_H
      6 #define ASH_DISPLAY_MOUSE_CURSOR_EVENT_FILTER_H
      7 
      8 #include "ash/ash_export.h"
      9 #include "base/compiler_specific.h"
     10 #include "base/gtest_prod_util.h"
     11 #include "base/memory/scoped_ptr.h"
     12 #include "ui/base/events/event_handler.h"
     13 #include "ui/gfx/rect.h"
     14 
     15 namespace aura {
     16 class RootWindow;
     17 }
     18 
     19 namespace ash {
     20 class DisplayController;
     21 
     22 namespace internal {
     23 class SharedDisplayEdgeIndicator;
     24 
     25 // An event filter that controls mouse location in extended desktop
     26 // environment.
     27 class ASH_EXPORT MouseCursorEventFilter : public ui::EventHandler {
     28  public:
     29   enum MouseWarpMode {
     30     WARP_ALWAYS,   // Always warp the mouse when possible.
     31     WARP_DRAG,     // Used when dragging a window. Top and bottom
     32                    // corner of the shared edge is reserved for window
     33                    // snapping.
     34     WARP_NONE,     // No mouse warping. Used when resizing the window.
     35   };
     36 
     37   MouseCursorEventFilter();
     38   virtual ~MouseCursorEventFilter();
     39 
     40   void set_mouse_warp_mode(MouseWarpMode mouse_warp_mode) {
     41     mouse_warp_mode_ = mouse_warp_mode;
     42   }
     43 
     44   // Shows/Hide the indicator for window dragging. The |from|
     45   // is the window where the dragging started.
     46   void ShowSharedEdgeIndicator(const aura::RootWindow* from);
     47   void HideSharedEdgeIndicator();
     48 
     49   // Overridden from ui::EventHandler:
     50   virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
     51 
     52  private:
     53   FRIEND_TEST_ALL_PREFIXES(MouseCursorEventFilterTest, SetMouseWarpModeFlag);
     54   FRIEND_TEST_ALL_PREFIXES(MouseCursorEventFilterTest, WarpMouse);
     55   FRIEND_TEST_ALL_PREFIXES(MouseCursorEventFilterTest,
     56                            WarpMouseDifferentSizeDisplays);
     57   FRIEND_TEST_ALL_PREFIXES(MouseCursorEventFilterTest,
     58                            WarpMouseDifferentScaleDisplays);
     59   FRIEND_TEST_ALL_PREFIXES(MouseCursorEventFilterTest,
     60                            IndicatorBoundsTestOnRight);
     61   FRIEND_TEST_ALL_PREFIXES(MouseCursorEventFilterTest,
     62                            IndicatorBoundsTestOnLeft);
     63   FRIEND_TEST_ALL_PREFIXES(MouseCursorEventFilterTest,
     64                            IndicatorBoundsTestOnTopBottom);
     65   FRIEND_TEST_ALL_PREFIXES(MouseCursorEventFilterTest, CursorDeviceScaleFactor);
     66   FRIEND_TEST_ALL_PREFIXES(DragWindowResizerTest, WarpMousePointer);
     67   FRIEND_TEST_ALL_PREFIXES(DragWindowResizerTest, CursorDeviceScaleFactor);
     68   FRIEND_TEST_ALL_PREFIXES(DragWindowResizerTest, MoveWindowAcrossDisplays);
     69 
     70   // Warps the mouse cursor to an alternate root window when the
     71   // |point_in_screen|, which is the location of the mouse cursor,
     72   // hits or exceeds the edge of the |target_root| and the mouse cursor
     73   // is considered to be in an alternate display. Returns true if
     74   // the cursor was moved.
     75   bool WarpMouseCursorIfNecessary(aura::RootWindow* target_root,
     76                                   const gfx::Point& point_in_screen);
     77 
     78   void UpdateHorizontalIndicatorWindowBounds();
     79   void UpdateVerticalIndicatorWindowBounds();
     80 
     81   MouseWarpMode mouse_warp_mode_;
     82 
     83   // The bounds for warp hole windows. |dst_indicator_bounds_| is kept
     84   // in the instance for testing.
     85   gfx::Rect src_indicator_bounds_;
     86   gfx::Rect dst_indicator_bounds_;
     87 
     88   // The root window in which the dragging started.
     89   const aura::RootWindow* drag_source_root_;
     90 
     91   // Shows the area where a window can be dragged in to/out from
     92   // another display.
     93   scoped_ptr<SharedDisplayEdgeIndicator> shared_display_edge_indicator_;
     94 
     95   DISALLOW_COPY_AND_ASSIGN(MouseCursorEventFilter);
     96 };
     97 
     98 }  // namespace internal
     99 }  // namespace ash
    100 
    101 #endif  // ASH_DISPLAY_MOUSE_CURSOR_EVENT_FILTER_H
    102