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