Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Side by Side Diff: ui/base/clipboard/clipboard.h

Issue 9264014: Upstream the clipboard implementation for Android (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/base/clipboard/clipboard_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/process.h" 14 #include "base/process.h"
15 #include "base/shared_memory.h" 15 #include "base/shared_memory.h"
16 #include "base/string16.h" 16 #include "base/string16.h"
17 #include "ui/base/ui_export.h" 17 #include "ui/base/ui_export.h"
18 18
19 #if defined(TOOLKIT_USES_GTK) 19 #if defined(TOOLKIT_USES_GTK)
20 #include <gdk/gdk.h> 20 #include <gdk/gdk.h>
21 #endif 21 #endif
22 22
23 #if defined(OS_ANDROID)
24 #include <jni.h>
25
26 #include "base/android/jni_android.h"
27 #include "base/android/scoped_java_ref.h"
28 #endif
29
23 namespace gfx { 30 namespace gfx {
24 class Size; 31 class Size;
25 } 32 }
26 33
27 class FilePath; 34 class FilePath;
28 class SkBitmap; 35 class SkBitmap;
29 36
30 #if defined(TOOLKIT_USES_GTK) 37 #if defined(TOOLKIT_USES_GTK)
31 typedef struct _GtkClipboard GtkClipboard; 38 typedef struct _GtkClipboard GtkClipboard;
32 #endif 39 #endif
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 NSString* data_; 75 NSString* data_;
69 #elif defined(USE_AURA) 76 #elif defined(USE_AURA)
70 explicit FormatType(const std::string& native_format); 77 explicit FormatType(const std::string& native_format);
71 const std::string& ToString() const { return data_; } 78 const std::string& ToString() const { return data_; }
72 std::string data_; 79 std::string data_;
73 #elif defined(TOOLKIT_USES_GTK) 80 #elif defined(TOOLKIT_USES_GTK)
74 explicit FormatType(const std::string& native_format); 81 explicit FormatType(const std::string& native_format);
75 explicit FormatType(const GdkAtom& native_format); 82 explicit FormatType(const GdkAtom& native_format);
76 const GdkAtom& ToGdkAtom() const { return data_; } 83 const GdkAtom& ToGdkAtom() const { return data_; }
77 GdkAtom data_; 84 GdkAtom data_;
85 #elif defined(OS_ANDROID)
86 explicit FormatType(const std::string& native_format);
87 const std::string& ToString() const { return data_; }
88 int compare(const std::string& str) const { return data_.compare(str); }
89 std::string data_;
78 #else 90 #else
79 #error No FormatType definition. 91 #error No FormatType definition.
80 #endif 92 #endif
81 }; 93 };
82 94
83 // ObjectType designates the type of data to be stored in the clipboard. This 95 // ObjectType designates the type of data to be stored in the clipboard. This
84 // designation is shared across all OSes. The system-specific designation 96 // designation is shared across all OSes. The system-specific designation
85 // is defined by FormatType. A single ObjectType might be represented by 97 // is defined by FormatType. A single ObjectType might be represented by
86 // several system-specific FormatTypes. For example, on Linux the CBF_TEXT 98 // several system-specific FormatTypes. For example, on Linux the CBF_TEXT
87 // ObjectType maps to "text/plain", "STRING", and several other formats. On 99 // ObjectType maps to "text/plain", "STRING", and several other formats. On
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 ~Clipboard(); 170 ~Clipboard();
159 171
160 // Write a bunch of objects to the system clipboard. Copies are made of the 172 // Write a bunch of objects to the system clipboard. Copies are made of the
161 // contents of |objects|. On Windows they are copied to the system clipboard. 173 // contents of |objects|. On Windows they are copied to the system clipboard.
162 // On linux they are copied into a structure owned by the Clipboard object and 174 // On linux they are copied into a structure owned by the Clipboard object and
163 // kept until the system clipboard is set again. 175 // kept until the system clipboard is set again.
164 void WriteObjects(const ObjectMap& objects); 176 void WriteObjects(const ObjectMap& objects);
165 177
166 // On Linux/BSD, we need to know when the clipboard is set to a URL. Most 178 // On Linux/BSD, we need to know when the clipboard is set to a URL. Most
167 // platforms don't care. 179 // platforms don't care.
168 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(USE_AURA) 180 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(USE_AURA) \
181 || defined(OS_ANDROID)
169 void DidWriteURL(const std::string& utf8_text) {} 182 void DidWriteURL(const std::string& utf8_text) {}
170 #else // !defined(OS_WIN) && !defined(OS_MACOSX) 183 #else // !defined(OS_WIN) && !defined(OS_MACOSX)
171 void DidWriteURL(const std::string& utf8_text); 184 void DidWriteURL(const std::string& utf8_text);
172 #endif 185 #endif
173 186
174 // Returns a sequence number which uniquely identifies clipboard state. 187 // Returns a sequence number which uniquely identifies clipboard state.
175 // This can be used to version the data on the clipboard and determine 188 // This can be used to version the data on the clipboard and determine
176 // whether it has changed. 189 // whether it has changed.
177 uint64 GetSequenceNumber(Buffer buffer); 190 uint64 GetSequenceNumber(Buffer buffer);
178 191
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 void SetGtkClipboard(); 327 void SetGtkClipboard();
315 // Insert a mapping into clipboard_data_. 328 // Insert a mapping into clipboard_data_.
316 void InsertMapping(const char* key, char* data, size_t data_len); 329 void InsertMapping(const char* key, char* data, size_t data_len);
317 330
318 // Find the gtk clipboard for the passed buffer enum. 331 // Find the gtk clipboard for the passed buffer enum.
319 GtkClipboard* LookupBackingClipboard(Buffer clipboard) const; 332 GtkClipboard* LookupBackingClipboard(Buffer clipboard) const;
320 333
321 TargetMap* clipboard_data_; 334 TargetMap* clipboard_data_;
322 GtkClipboard* clipboard_; 335 GtkClipboard* clipboard_;
323 GtkClipboard* primary_selection_; 336 GtkClipboard* primary_selection_;
337 #elif defined(OS_ANDROID)
338 // Returns whether some text is available from the Android Clipboard.
339 bool IsTextAvailableFromAndroid() const;
340
341 // Make sure that the Android Clipboard contents matches what we think it
342 // should contain. If it changed, a copy occured from another application and
343 // all internal data is dropped.
344 void ValidateInternalClipboard() const;
345
346 // Clear the Clipboard for all types. Both for Android and internal.
347 void Clear();
348
349 // Clear the internal clipboard.
350 void ClearInternalClipboard() const;
351
352 // This private method is used to set non text key/value.
353 void Set(const std::string& key, const std::string& value);
354
355 // Java class and methods for the Android ClipboardManager.
356 base::android::ScopedJavaGlobalRef<jobject> clipboard_manager_;
357 jmethodID set_text_;
358 jmethodID has_text_;
359 jmethodID get_text_;
360 jmethodID to_string_;
324 #endif 361 #endif
325 362
326 // MIME type constants. 363 // MIME type constants.
327 static const char kMimeTypeText[]; 364 static const char kMimeTypeText[];
328 static const char kMimeTypeHTML[]; 365 static const char kMimeTypeHTML[];
329 static const char kMimeTypePNG[]; 366 static const char kMimeTypePNG[];
330 367
331 DISALLOW_COPY_AND_ASSIGN(Clipboard); 368 DISALLOW_COPY_AND_ASSIGN(Clipboard);
332 }; 369 };
333 370
334 } // namespace ui 371 } // namespace ui
335 372
336 #endif // UI_BASE_CLIPBOARD_CLIPBOARD_H_ 373 #endif // UI_BASE_CLIPBOARD_CLIPBOARD_H_
OLDNEW
« no previous file with comments | « no previous file | ui/base/clipboard/clipboard_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698