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/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
,
35 public gfx::DisplayObserver
{
37 // Starts the UI for taking partial screenshot; dragging to select a region.
38 // PartialScreenshotController manage their own lifetime so caller must not
39 // delete the returned values.
40 static void StartPartialScreenshotSession(
41 ScreenshotDelegate
* screenshot_delegate
);
43 ~PartialScreenshotController() override
;
46 friend class PartialScreenshotControllerTest
;
48 class ScopedCursorSetter
;
49 class PartialScreenshotLayer
;
51 static PartialScreenshotController
* GetInstanceForTest();
53 PartialScreenshotController(ScreenshotDelegate
* screenshot_delegate
);
55 // Starts, ends, cancels, or updates the region selection.
56 void MaybeStart(const ui::LocatedEvent
& event
);
59 void Update(const ui::LocatedEvent
& event
);
62 void OnKeyEvent(ui::KeyEvent
* event
) override
;
63 void OnMouseEvent(ui::MouseEvent
* event
) override
;
64 void OnTouchEvent(ui::TouchEvent
* event
) override
;
67 void OnAppTerminating() override
;
69 // gfx::DisplayObserver:
70 void OnDisplayAdded(const gfx::Display
& new_display
) override
;
71 void OnDisplayRemoved(const gfx::Display
& old_display
) override
;
72 void OnDisplayMetricsChanged(const gfx::Display
& display
,
73 uint32_t changed_metrics
) override
;
75 // The data to build the screenshot region.
76 gfx::Point start_position_
;
77 aura::Window
* root_window_
;
79 // Layers to create the visual effect of region selection.
80 std::map
<aura::Window
*, PartialScreenshotLayer
*> layers_
;
82 // The object to specify the crosshair cursor.
83 scoped_ptr
<ScopedCursorSetter
> cursor_setter_
;
85 // ScreenshotDelegate to take the actual screenshot. No ownership.
86 ScreenshotDelegate
* screenshot_delegate_
;
88 DISALLOW_COPY_AND_ASSIGN(PartialScreenshotController
);
93 #endif // #ifndef ASH_WM_PARTIAL_SCREENSHOT_VIEW_H_