OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_BROWSER_UI_ASH_SCREENSHOT_TAKER_H_ | 5 #ifndef CHROME_BROWSER_UI_ASH_SCREENSHOT_TAKER_H_ |
6 #define CHROME_BROWSER_UI_ASH_SCREENSHOT_TAKER_H_ | 6 #define CHROME_BROWSER_UI_ASH_SCREENSHOT_TAKER_H_ |
7 | 7 |
8 #include "ash/screenshot_delegate.h" | 8 #include "ash/screenshot_delegate.h" |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/files/file_path.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/memory/weak_ptr.h" | |
14 #include "base/observer_list.h" | |
11 #include "base/time.h" | 15 #include "base/time.h" |
12 #include "ui/compositor/layer.h" | |
13 | 16 |
17 class Profile; | |
18 | |
19 namespace ash { | |
20 namespace test { | |
21 class ScreenshotTakerTest; | |
22 } | |
23 } | |
14 namespace aura { | 24 namespace aura { |
15 class Window; | 25 class Window; |
16 } // namespace aura | 26 } |
27 | |
28 class ScreenshotTakerObserver { | |
29 public: | |
30 enum Result { | |
31 SCREENSHOT_SUCCESS = 0, | |
32 SCREENSHOT_GRABWINDOW_PARTIAL_FAILED, | |
33 SCREENSHOT_GRABWINDOW_FULL_FAILED, | |
34 SCREENSHOT_CREATE_DIR_FAILED, | |
35 SCREENSHOT_GET_DIR_FAILED, | |
36 SCREENSHOT_CHECK_DIR_FAILED, | |
37 SCREENSHOT_CREATE_FILE_FAILED, | |
38 SCREENSHOT_WRITE_FILE_FAILED, | |
39 SCREENSHOT_RESULT_COUNT | |
40 }; | |
41 | |
42 virtual void OnScreenshotCompleted( | |
43 Result screenshot_result, const base::FilePath& screenshot_path) = 0; | |
sky
2013/04/03 23:16:09
nit: when you wrap put each param on its own line.
sschmitz
2013/04/04 01:06:08
Done.
| |
44 | |
45 protected: | |
46 virtual ~ScreenshotTakerObserver() {} | |
47 }; | |
17 | 48 |
18 class ScreenshotTaker : public ash::ScreenshotDelegate { | 49 class ScreenshotTaker : public ash::ScreenshotDelegate { |
19 public: | 50 public: |
20 ScreenshotTaker(); | 51 explicit ScreenshotTaker(Profile* profile); |
52 | |
21 virtual ~ScreenshotTaker(); | 53 virtual ~ScreenshotTaker(); |
22 | 54 |
23 // Overridden from ash::ScreenshotDelegate: | 55 // Overridden from ash::ScreenshotDelegate: |
24 virtual void HandleTakeScreenshotForAllRootWindows() OVERRIDE; | 56 virtual void HandleTakeScreenshotForAllRootWindows() OVERRIDE; |
25 virtual void HandleTakePartialScreenshot(aura::Window* window, | 57 virtual void HandleTakePartialScreenshot(aura::Window* window, |
26 const gfx::Rect& rect) OVERRIDE; | 58 const gfx::Rect& rect) OVERRIDE; |
27 virtual bool CanTakeScreenshot() OVERRIDE; | 59 virtual bool CanTakeScreenshot() OVERRIDE; |
28 | 60 |
61 void ShowNotification( | |
62 ScreenshotTakerObserver::Result screenshot_result, | |
63 const base::FilePath& screenshot_path); | |
64 | |
65 void AddObserver(ScreenshotTakerObserver* observer); | |
66 void RemoveObserver(ScreenshotTakerObserver* observer); | |
67 bool HasObserver(ScreenshotTakerObserver* observer) const; | |
68 | |
29 private: | 69 private: |
30 // Flashes the screen to provide visual feedback that a screenshot has | 70 friend class ash::test::ScreenshotTakerTest; |
31 // been taken. | |
32 void DisplayVisualFeedback(const gfx::Rect& rect); | |
33 | 71 |
34 // Closes the visual feedback layer. | 72 void SetScreenshotDirectoryForTest(const base::FilePath& directory); |
35 void CloseVisualFeedbackLayer(); | 73 void SetScreenshotBasenameForTest(const std::string& basename); |
74 | |
75 Profile* profile_; | |
76 | |
77 base::WeakPtrFactory<ScreenshotTaker> factory_; | |
36 | 78 |
37 // The timestamp when the screenshot task was issued last time. | 79 // The timestamp when the screenshot task was issued last time. |
38 base::Time last_screenshot_timestamp_; | 80 base::Time last_screenshot_timestamp_; |
39 | 81 |
40 // The flashing effect of the screen for the visual feedback when taking a | 82 ObserverList<ScreenshotTakerObserver> observers_; |
41 // screenshot. | 83 base::FilePath screenshot_directory_for_test_; |
42 scoped_ptr<ui::Layer> visual_feedback_layer_; | 84 std::string screenshot_basename_for_test_; |
43 | 85 |
44 DISALLOW_COPY_AND_ASSIGN(ScreenshotTaker); | 86 DISALLOW_COPY_AND_ASSIGN(ScreenshotTaker); |
45 }; | 87 }; |
46 | 88 |
47 #endif // CHROME_BROWSER_UI_ASH_SCREENSHOT_TAKER_H_ | 89 #endif // CHROME_BROWSER_UI_ASH_SCREENSHOT_TAKER_H_ |
OLD | NEW |