1 // Copyright 2014 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.
5 #ifndef ASH_UTILITY_PARTIAL_SCREENSHOT_CONTROLLER_H_
6 #define ASH_UTILITY_PARTIAL_SCREENSHOT_CONTROLLER_H_
10 #include "ash/ash_export.h"
11 #include "ash/shell_observer.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "ui/events/event_handler.h"
14 #include "ui/gfx/display_observer.h"
15 #include "ui/gfx/geometry/point.h"
26 class ScreenshotDelegate
;
28 // This class controls a session of taking partial screenshot, i.e.: drawing
29 // region rectangles during drag, and changing the mouse cursor to indicate
31 // This class does not use aura::Window / views::Widget intentionally to avoid
32 // the conflicts of window manager features like mouse captures or window focus.
33 class ASH_EXPORT PartialScreenshotController
: public ui::EventHandler
,
34 public gfx::DisplayObserver
{
36 PartialScreenshotController();
37 ~PartialScreenshotController() override
;
39 // Starts the UI for taking partial screenshot; dragging to select a region.
40 // PartialScreenshotController manage their own lifetime so caller must not
41 // delete the returned values.
42 void StartPartialScreenshotSession(ScreenshotDelegate
* screenshot_delegate
);
45 friend class PartialScreenshotControllerTest
;
47 class ScopedCursorSetter
;
48 class PartialScreenshotLayer
;
50 // Starts, ends, cancels, or updates the region selection.
51 void MaybeStart(const ui::LocatedEvent
& event
);
54 void Update(const ui::LocatedEvent
& event
);
57 void OnKeyEvent(ui::KeyEvent
* event
) override
;
58 void OnMouseEvent(ui::MouseEvent
* event
) override
;
59 void OnTouchEvent(ui::TouchEvent
* event
) override
;
61 // gfx::DisplayObserver:
62 void OnDisplayAdded(const gfx::Display
& new_display
) override
;
63 void OnDisplayRemoved(const gfx::Display
& old_display
) override
;
64 void OnDisplayMetricsChanged(const gfx::Display
& display
,
65 uint32_t changed_metrics
) override
;
67 // The data to build the screenshot region.
68 gfx::Point start_position_
;
69 aura::Window
* root_window_
;
71 // Layers to create the visual effect of region selection.
72 std::map
<aura::Window
*, PartialScreenshotLayer
*> layers_
;
74 // The object to specify the crosshair cursor.
75 scoped_ptr
<ScopedCursorSetter
> cursor_setter_
;
77 // ScreenshotDelegate to take the actual screenshot. No ownership.
78 ScreenshotDelegate
* screenshot_delegate_
;
80 DISALLOW_COPY_AND_ASSIGN(PartialScreenshotController
);
85 #endif // #ifndef ASH_WM_PARTIAL_SCREENSHOT_VIEW_H_