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 // This file declares the ScopedClipboardWriter class, a wrapper around | 5 // This file declares the ScopedClipboardWriter class, a wrapper around |
6 // the Clipboard class which simplifies writing data to the system clipboard. | 6 // the Clipboard class which simplifies writing data to the system clipboard. |
7 // Upon deletion the class atomically writes all data to the clipboard, | 7 // Upon deletion the class atomically writes all data to the clipboard, |
8 // avoiding any potential race condition with other processes that are also | 8 // avoiding any potential race condition with other processes that are also |
9 // writing to the system clipboard. | 9 // writing to the system clipboard. |
10 | 10 |
11 #ifndef UI_BASE_CLIPBOARD_SCOPED_CLIPBOARD_WRITER_H_ | 11 #ifndef UI_BASE_CLIPBOARD_SCOPED_CLIPBOARD_WRITER_H_ |
12 #define UI_BASE_CLIPBOARD_SCOPED_CLIPBOARD_WRITER_H_ | 12 #define UI_BASE_CLIPBOARD_SCOPED_CLIPBOARD_WRITER_H_ |
13 | 13 |
14 #include <string> | 14 #include <string> |
15 | 15 |
16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
17 #include "third_party/skia/include/core/SkBitmap.h" | |
18 #include "ui/base/clipboard/clipboard.h" | 17 #include "ui/base/clipboard/clipboard.h" |
19 #include "ui/base/ui_base_export.h" | 18 #include "ui/base/ui_base_export.h" |
20 | 19 |
21 class Pickle; | 20 class Pickle; |
22 | 21 |
23 namespace ui { | 22 namespace ui { |
24 | 23 |
25 // This class is a wrapper for |Clipboard| that handles packing data | 24 // This class is a wrapper for |Clipboard| that handles packing data |
26 // into a Clipboard::ObjectMap. | 25 // into a Clipboard::ObjectMap. |
27 class UI_BASE_EXPORT ScopedClipboardWriter { | 26 class UI_BASE_EXPORT ScopedClipboardWriter { |
(...skipping 27 matching lines...) Expand all Loading... |
55 void WriteHyperlink(const base::string16& anchor_text, | 54 void WriteHyperlink(const base::string16& anchor_text, |
56 const std::string& url); | 55 const std::string& url); |
57 | 56 |
58 // Used by WebKit to determine whether WebKit wrote the clipboard last | 57 // Used by WebKit to determine whether WebKit wrote the clipboard last |
59 void WriteWebSmartPaste(); | 58 void WriteWebSmartPaste(); |
60 | 59 |
61 // Adds arbitrary pickled data to clipboard. | 60 // Adds arbitrary pickled data to clipboard. |
62 void WritePickledData(const Pickle& pickle, | 61 void WritePickledData(const Pickle& pickle, |
63 const Clipboard::FormatType& format); | 62 const Clipboard::FormatType& format); |
64 | 63 |
65 void WriteImage(const SkBitmap& bitmap); | |
66 | |
67 // Removes all objects that would be written to the clipboard. | 64 // Removes all objects that would be written to the clipboard. |
68 void Reset(); | 65 void Reset(); |
69 | 66 |
70 private: | 67 protected: |
71 // Converts |text| to UTF-8 and adds it to the clipboard. If it's a URL, we | 68 // Converts |text| to UTF-8 and adds it to the clipboard. If it's a URL, we |
72 // also notify the clipboard of that fact. | 69 // also notify the clipboard of that fact. |
73 void WriteTextOrURL(const base::string16& text, bool is_url); | 70 void WriteTextOrURL(const base::string16& text, bool is_url); |
74 | 71 |
75 // We accumulate the data passed to the various targets in the |objects_| | 72 // We accumulate the data passed to the various targets in the |objects_| |
76 // vector, and pass it to Clipboard::WriteObjects() during object destruction. | 73 // vector, and pass it to Clipboard::WriteObjects() during object destruction. |
77 Clipboard::ObjectMap objects_; | 74 Clipboard::ObjectMap objects_; |
78 const ClipboardType type_; | 75 const ClipboardType type_; |
79 | 76 |
80 SkBitmap bitmap_; | |
81 | |
82 // We keep around the UTF-8 text of the URL in order to pass it to | 77 // We keep around the UTF-8 text of the URL in order to pass it to |
83 // Clipboard::DidWriteURL(). | 78 // Clipboard::DidWriteURL(). |
84 std::string url_text_; | 79 std::string url_text_; |
85 | 80 |
| 81 private: |
86 DISALLOW_COPY_AND_ASSIGN(ScopedClipboardWriter); | 82 DISALLOW_COPY_AND_ASSIGN(ScopedClipboardWriter); |
87 }; | 83 }; |
88 | 84 |
89 } // namespace ui | 85 } // namespace ui |
90 | 86 |
91 #endif // UI_BASE_CLIPBOARD_SCOPED_CLIPBOARD_WRITER_H_ | 87 #endif // UI_BASE_CLIPBOARD_SCOPED_CLIPBOARD_WRITER_H_ |
92 | 88 |
OLD | NEW |