Home | History | Annotate | Download | only in wm
      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_WM_PARTIAL_SCREENSHOT_VIEW_H_
      6 #define ASH_WM_PARTIAL_SCREENSHOT_VIEW_H_
      7 
      8 #include <vector>
      9 
     10 #include "ash/ash_export.h"
     11 #include "base/compiler_specific.h"
     12 #include "base/gtest_prod_util.h"
     13 #include "ui/gfx/point.h"
     14 #include "ui/views/widget/widget_delegate.h"
     15 
     16 namespace aura {
     17 class RootWindow;
     18 }
     19 
     20 namespace ash {
     21 class ScreenshotDelegate;
     22 
     23 // The view of taking partial screenshot, i.e.: drawing region
     24 // rectangles during drag, and changing the mouse cursor to indicate
     25 // the current mode.
     26 class ASH_EXPORT PartialScreenshotView : public views::WidgetDelegateView {
     27  public:
     28   // Starts the UI for taking partial screenshot; dragging to select a region.
     29   // PartialScreenshotViews manage their own lifetime so caller must not delete
     30   // the returned PartialScreenshotViews.
     31   static std::vector<PartialScreenshotView*>
     32       StartPartialScreenshot(ScreenshotDelegate* screenshot_delegate);
     33 
     34  private:
     35   FRIEND_TEST_ALL_PREFIXES(PartialScreenshotViewTest, BasicMouse);
     36   FRIEND_TEST_ALL_PREFIXES(PartialScreenshotViewTest, BasicTouch);
     37 
     38   class OverlayDelegate;
     39 
     40   PartialScreenshotView(OverlayDelegate* overlay_delegate,
     41                         ScreenshotDelegate* screenshot_delegate);
     42   virtual ~PartialScreenshotView();
     43 
     44   // Initializes partial screenshot UI widget for |root_window|.
     45   void Init(aura::RootWindow* root_window);
     46 
     47   // Returns the currently selected region.
     48   gfx::Rect GetScreenshotRect() const;
     49 
     50   void OnSelectionStarted(const gfx::Point& position);
     51   void OnSelectionChanged(const gfx::Point& position);
     52   void OnSelectionFinished();
     53 
     54   // Overridden from views::View:
     55   virtual gfx::NativeCursor GetCursor(const ui::MouseEvent& event) OVERRIDE;
     56   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
     57   virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
     58   virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE;
     59   virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE;
     60   virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
     61   virtual void OnMouseCaptureLost() OVERRIDE;
     62   virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
     63 
     64   bool is_dragging_;
     65   gfx::Point start_position_;
     66   gfx::Point current_position_;
     67 
     68   // The delegate to receive Cancel. No ownership.
     69   OverlayDelegate* overlay_delegate_;
     70 
     71   // ScreenshotDelegate to take the actual screenshot. No ownership.
     72   ScreenshotDelegate* screenshot_delegate_;
     73 
     74   DISALLOW_COPY_AND_ASSIGN(PartialScreenshotView);
     75 };
     76 
     77 }  // namespace ash
     78 
     79 #endif  // #ifndef ASH_WM_PARTIAL_SCREENSHOT_VIEW_H_
     80