| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ASH_UTILITY_PARTIAL_SCREENSHOT_CONTROLLER_H_ | 5 #ifndef ASH_UTILITY_SCREENSHOT_CONTROLLER_H_ |
| 6 #define ASH_UTILITY_PARTIAL_SCREENSHOT_CONTROLLER_H_ | 6 #define ASH_UTILITY_SCREENSHOT_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #include "ash/ash_export.h" | 13 #include "ash/ash_export.h" |
| 14 #include "ash/shell_observer.h" | 14 #include "ash/shell_observer.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "ui/aura/window_observer.h" |
| 16 #include "ui/display/display_observer.h" | 17 #include "ui/display/display_observer.h" |
| 17 #include "ui/events/event_handler.h" | 18 #include "ui/events/event_handler.h" |
| 18 #include "ui/gfx/geometry/point.h" | 19 #include "ui/gfx/geometry/point.h" |
| 19 | 20 |
| 20 namespace aura { | 21 namespace aura { |
| 21 class Window; | 22 class Window; |
| 22 } | 23 } |
| 23 | 24 |
| 24 namespace ui { | 25 namespace ui { |
| 25 class LocatedEvent; | 26 class LocatedEvent; |
| 26 } | 27 } |
| 27 | 28 |
| 28 namespace ash { | 29 namespace ash { |
| 29 class ScreenshotDelegate; | 30 class ScreenshotDelegate; |
| 30 | 31 |
| 31 // This class controls a session of taking partial screenshot, i.e.: drawing | 32 // This class controls a session of taking partial/window screenshot, i.e.: |
| 32 // region rectangles during drag, and changing the mouse cursor to indicate | 33 // drawing |
| 34 // region rectangles during selection, and changing the mouse cursor to indicate |
| 33 // the current mode. | 35 // the current mode. |
| 34 // This class does not use aura::Window / views::Widget intentionally to avoid | 36 // This class does not use aura::Window / views::Widget intentionally to avoid |
| 35 // the conflicts of window manager features like mouse captures or window focus. | 37 class ASH_EXPORT ScreenshotController : public ui::EventHandler, |
| 36 class ASH_EXPORT PartialScreenshotController : public ui::EventHandler, | 38 public display::DisplayObserver, |
| 37 public display::DisplayObserver { | 39 public aura::WindowObserver { |
| 38 public: | 40 public: |
| 39 PartialScreenshotController(); | 41 ScreenshotController(); |
| 40 ~PartialScreenshotController() override; | 42 ~ScreenshotController() override; |
| 41 | 43 |
| 42 // Starts the UI for taking partial screenshot; dragging to select a region. | 44 // Starts the UI for taking partial screenshot; dragging to select a region. |
| 43 // PartialScreenshotController manage their own lifetime so caller must not | 45 // ScreenshotController manage their own lifetime so caller must not |
| 44 // delete the returned values. | 46 // delete the returned values. |
| 45 void StartPartialScreenshotSession(ScreenshotDelegate* screenshot_delegate); | 47 void StartPartialScreenshotSession(ScreenshotDelegate* screenshot_delegate); |
| 46 | 48 |
| 49 // Starts the UI for taking a window screenshot; |
| 50 void StartWindowScreenshotSession(ScreenshotDelegate* screenshot_delegate); |
| 51 |
| 47 private: | 52 private: |
| 48 friend class PartialScreenshotControllerTest; | 53 enum Mode { |
| 54 NONE, |
| 55 PARTIAL, |
| 56 WINDOW, |
| 57 }; |
| 58 |
| 59 friend class ScreenshotControllerTest; |
| 49 | 60 |
| 50 class ScopedCursorSetter; | 61 class ScopedCursorSetter; |
| 51 class PartialScreenshotLayer; | 62 class ScreenshotLayer; |
| 52 | 63 |
| 53 // Starts, ends, cancels, or updates the region selection. | 64 // Starts, ends, cancels, or updates the region selection. |
| 54 void MaybeStart(const ui::LocatedEvent& event); | 65 void MaybeStart(const ui::LocatedEvent& event); |
| 55 void Complete(); | 66 void CompleteWindowScreenshot(); |
| 67 void CompletePartialScreenshot(); |
| 56 void Cancel(); | 68 void Cancel(); |
| 57 void Update(const ui::LocatedEvent& event); | 69 void Update(const ui::LocatedEvent& event); |
| 70 void UpdateSelectedWindow(ui::LocatedEvent* event); |
| 71 void SetSelectedWindow(aura::Window* window); |
| 58 | 72 |
| 59 // ui::EventHandler: | 73 // ui::EventHandler: |
| 60 void OnKeyEvent(ui::KeyEvent* event) override; | 74 void OnKeyEvent(ui::KeyEvent* event) override; |
| 61 void OnMouseEvent(ui::MouseEvent* event) override; | 75 void OnMouseEvent(ui::MouseEvent* event) override; |
| 62 void OnTouchEvent(ui::TouchEvent* event) override; | 76 void OnTouchEvent(ui::TouchEvent* event) override; |
| 63 | 77 |
| 64 // display::DisplayObserver: | 78 // display::DisplayObserver: |
| 65 void OnDisplayAdded(const display::Display& new_display) override; | 79 void OnDisplayAdded(const display::Display& new_display) override; |
| 66 void OnDisplayRemoved(const display::Display& old_display) override; | 80 void OnDisplayRemoved(const display::Display& old_display) override; |
| 67 void OnDisplayMetricsChanged(const display::Display& display, | 81 void OnDisplayMetricsChanged(const display::Display& display, |
| 68 uint32_t changed_metrics) override; | 82 uint32_t changed_metrics) override; |
| 69 | 83 |
| 84 // aura::WindowObserver: |
| 85 void OnWindowDestroying(aura::Window* window) override; |
| 86 |
| 87 Mode mode_; |
| 88 |
| 70 // The data to build the screenshot region. | 89 // The data to build the screenshot region. |
| 71 gfx::Point start_position_; | 90 gfx::Point start_position_; |
| 72 aura::Window* root_window_; | 91 aura::Window* root_window_; |
| 73 | 92 |
| 74 // Layers to create the visual effect of region selection. | 93 // Currently selected window in WINDOW mode. |
| 75 std::map<aura::Window*, PartialScreenshotLayer*> layers_; | 94 aura::Window* selected_; |
| 95 |
| 96 // Layers to create the visual effect of region selection or selected window. |
| 97 std::map<aura::Window*, ScreenshotLayer*> layers_; |
| 76 | 98 |
| 77 // The object to specify the crosshair cursor. | 99 // The object to specify the crosshair cursor. |
| 78 std::unique_ptr<ScopedCursorSetter> cursor_setter_; | 100 std::unique_ptr<ScopedCursorSetter> cursor_setter_; |
| 79 | 101 |
| 80 // ScreenshotDelegate to take the actual screenshot. No ownership. | 102 // ScreenshotDelegate to take the actual screenshot. No ownership. |
| 81 ScreenshotDelegate* screenshot_delegate_; | 103 ScreenshotDelegate* screenshot_delegate_; |
| 82 | 104 |
| 83 DISALLOW_COPY_AND_ASSIGN(PartialScreenshotController); | 105 DISALLOW_COPY_AND_ASSIGN(ScreenshotController); |
| 84 }; | 106 }; |
| 85 | 107 |
| 86 } // namespace ash | 108 } // namespace ash |
| 87 | 109 |
| 88 #endif // #ifndef ASH_WM_PARTIAL_SCREENSHOT_VIEW_H_ | 110 #endif // ASH_UTILITY_SCREENSHOT_CONTROLLER_H_ |
| OLD | NEW |