| 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 UI_BASE_CLIPBOARD_CLIPBOARD_H_ | 5 #ifndef UI_BASE_CLIPBOARD_CLIPBOARD_H_ |
| 6 #define UI_BASE_CLIPBOARD_CLIPBOARD_H_ | 6 #define UI_BASE_CLIPBOARD_CLIPBOARD_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 // object containing the bitmap data. | 142 // object containing the bitmap data. |
| 143 // size gfx::Size struct | 143 // size gfx::Size struct |
| 144 // CBF_DATA format char array | 144 // CBF_DATA format char array |
| 145 // data byte array | 145 // data byte array |
| 146 typedef std::vector<char> ObjectMapParam; | 146 typedef std::vector<char> ObjectMapParam; |
| 147 typedef std::vector<ObjectMapParam> ObjectMapParams; | 147 typedef std::vector<ObjectMapParam> ObjectMapParams; |
| 148 typedef std::map<int /* ObjectType */, ObjectMapParams> ObjectMap; | 148 typedef std::map<int /* ObjectType */, ObjectMapParams> ObjectMap; |
| 149 | 149 |
| 150 // Buffer designates which clipboard the action should be applied to. | 150 // Buffer designates which clipboard the action should be applied to. |
| 151 // Only platforms that use the X Window System support the selection | 151 // Only platforms that use the X Window System support the selection |
| 152 // buffer. Furthermore we currently only use a buffer other than the | 152 // buffer. |
| 153 // standard buffer when reading from the clipboard so only those | |
| 154 // functions accept a buffer parameter. | |
| 155 enum Buffer { | 153 enum Buffer { |
| 156 BUFFER_STANDARD, | 154 BUFFER_STANDARD, |
| 157 BUFFER_SELECTION, | 155 BUFFER_SELECTION, |
| 158 }; | 156 }; |
| 159 | 157 |
| 160 static bool IsValidBuffer(int32 buffer) { | 158 static bool IsValidBuffer(int32 buffer) { |
| 161 switch (buffer) { | 159 switch (buffer) { |
| 162 case BUFFER_STANDARD: | 160 case BUFFER_STANDARD: |
| 163 return true; | 161 return true; |
| 164 #if defined(USE_X11) && !defined(USE_AURA) | 162 #if defined(USE_X11) && !defined(USE_AURA) |
| 165 case BUFFER_SELECTION: | 163 case BUFFER_SELECTION: |
| 166 return true; | 164 return true; |
| 167 #endif | 165 #endif |
| 168 } | 166 } |
| 169 return false; | 167 return false; |
| 170 } | 168 } |
| 171 | 169 |
| 172 static Buffer FromInt(int32 buffer) { | 170 static Buffer FromInt(int32 buffer) { |
| 173 return static_cast<Buffer>(buffer); | 171 return static_cast<Buffer>(buffer); |
| 174 } | 172 } |
| 175 | 173 |
| 176 Clipboard(); | 174 Clipboard(); |
| 177 ~Clipboard(); | 175 ~Clipboard(); |
| 178 | 176 |
| 179 // Write a bunch of objects to the system clipboard. Copies are made of the | 177 // Write a bunch of objects to the system clipboard. Copies are made of the |
| 180 // contents of |objects|. On Windows they are copied to the system clipboard. | 178 // contents of |objects|. On Windows they are copied to the system clipboard. |
| 181 // On linux they are copied into a structure owned by the Clipboard object and | 179 // On linux they are copied into a structure owned by the Clipboard object and |
| 182 // kept until the system clipboard is set again. | 180 // kept until the system clipboard is set again. |
| 183 void WriteObjects(const ObjectMap& objects); | 181 void WriteObjects(Buffer buffer, const ObjectMap& objects); |
| 184 | 182 |
| 185 // On Linux/BSD, we need to know when the clipboard is set to a URL. Most | 183 // On Linux/BSD, we need to know when the clipboard is set to a URL. Most |
| 186 // platforms don't care. | 184 // platforms don't care. |
| 187 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(USE_AURA) \ | 185 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(USE_AURA) \ |
| 188 || defined(OS_ANDROID) | 186 || defined(OS_ANDROID) |
| 189 void DidWriteURL(const std::string& utf8_text) {} | 187 void DidWriteURL(const std::string& utf8_text) {} |
| 190 #else // !defined(OS_WIN) && !defined(OS_MACOSX) | 188 #else // !defined(OS_WIN) && !defined(OS_MACOSX) |
| 191 void DidWriteURL(const std::string& utf8_text); | 189 void DidWriteURL(const std::string& utf8_text); |
| 192 #endif | 190 #endif |
| 193 | 191 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 // of data we intend to put on the clipboard on clipboard_data_ as | 317 // of data we intend to put on the clipboard on clipboard_data_ as |
| 320 // WriteObjects is running, and then at the end call SetGtkClipboard | 318 // WriteObjects is running, and then at the end call SetGtkClipboard |
| 321 // which replaces whatever is on the system clipboard with the | 319 // which replaces whatever is on the system clipboard with the |
| 322 // contents of clipboard_data_. | 320 // contents of clipboard_data_. |
| 323 | 321 |
| 324 public: | 322 public: |
| 325 typedef std::map<std::string, std::pair<char*, size_t> > TargetMap; | 323 typedef std::map<std::string, std::pair<char*, size_t> > TargetMap; |
| 326 | 324 |
| 327 private: | 325 private: |
| 328 // Write changes to gtk clipboard. | 326 // Write changes to gtk clipboard. |
| 329 void SetGtkClipboard(); | 327 void SetGtkClipboard(Buffer buffer); |
| 330 // Insert a mapping into clipboard_data_. | 328 // Insert a mapping into clipboard_data_. |
| 331 void InsertMapping(const char* key, char* data, size_t data_len); | 329 void InsertMapping(const char* key, char* data, size_t data_len); |
| 332 | 330 |
| 333 // Find the gtk clipboard for the passed buffer enum. | 331 // Find the gtk clipboard for the passed buffer enum. |
| 334 GtkClipboard* LookupBackingClipboard(Buffer clipboard) const; | 332 GtkClipboard* LookupBackingClipboard(Buffer clipboard) const; |
| 335 | 333 |
| 336 TargetMap* clipboard_data_; | 334 TargetMap* clipboard_data_; |
| 337 GtkClipboard* clipboard_; | 335 GtkClipboard* clipboard_; |
| 338 GtkClipboard* primary_selection_; | 336 GtkClipboard* primary_selection_; |
| 339 #elif defined(OS_ANDROID) | 337 #elif defined(OS_ANDROID) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 361 jmethodID get_text_; | 359 jmethodID get_text_; |
| 362 jmethodID to_string_; | 360 jmethodID to_string_; |
| 363 #endif | 361 #endif |
| 364 | 362 |
| 365 DISALLOW_COPY_AND_ASSIGN(Clipboard); | 363 DISALLOW_COPY_AND_ASSIGN(Clipboard); |
| 366 }; | 364 }; |
| 367 | 365 |
| 368 } // namespace ui | 366 } // namespace ui |
| 369 | 367 |
| 370 #endif // UI_BASE_CLIPBOARD_CLIPBOARD_H_ | 368 #endif // UI_BASE_CLIPBOARD_CLIPBOARD_H_ |
| OLD | NEW |