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 #include "ui/base/clipboard/clipboard_android.h" | 5 #include "ui/base/clipboard/clipboard_android.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/android/context_utils.h" | 9 #include "base/android/context_utils.h" |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 void ClipboardAndroid::WriteWebSmartPaste() { | 491 void ClipboardAndroid::WriteWebSmartPaste() { |
492 g_map.Get().Set(kWebKitSmartPasteFormat, std::string()); | 492 g_map.Get().Set(kWebKitSmartPasteFormat, std::string()); |
493 } | 493 } |
494 | 494 |
495 // Note: we implement this to pass all unit tests but it is currently unclear | 495 // Note: we implement this to pass all unit tests but it is currently unclear |
496 // how some code would consume this. | 496 // how some code would consume this. |
497 void ClipboardAndroid::WriteBitmap(const SkBitmap& bitmap) { | 497 void ClipboardAndroid::WriteBitmap(const SkBitmap& bitmap) { |
498 gfx::Size size(bitmap.width(), bitmap.height()); | 498 gfx::Size size(bitmap.width(), bitmap.height()); |
499 | 499 |
500 std::string packed(reinterpret_cast<const char*>(&size), sizeof(size)); | 500 std::string packed(reinterpret_cast<const char*>(&size), sizeof(size)); |
501 { | 501 packed += std::string(static_cast<const char*>(bitmap.getPixels()), |
502 SkAutoLockPixels bitmap_lock(bitmap); | 502 bitmap.getSize()); |
503 packed += std::string(static_cast<const char*>(bitmap.getPixels()), | |
504 bitmap.getSize()); | |
505 } | |
506 g_map.Get().Set(kBitmapFormat, packed); | 503 g_map.Get().Set(kBitmapFormat, packed); |
507 } | 504 } |
508 | 505 |
509 void ClipboardAndroid::WriteData(const Clipboard::FormatType& format, | 506 void ClipboardAndroid::WriteData(const Clipboard::FormatType& format, |
510 const char* data_data, | 507 const char* data_data, |
511 size_t data_len) { | 508 size_t data_len) { |
512 g_map.Get().Set(format.ToString(), std::string(data_data, data_len)); | 509 g_map.Get().Set(format.ToString(), std::string(data_data, data_len)); |
513 } | 510 } |
514 | 511 |
515 bool RegisterClipboardAndroid(JNIEnv* env) { | 512 bool RegisterClipboardAndroid(JNIEnv* env) { |
516 return RegisterNativesImpl(env); | 513 return RegisterNativesImpl(env); |
517 } | 514 } |
518 | 515 |
519 // Returns a pointer to the current ClipboardAndroid object. | 516 // Returns a pointer to the current ClipboardAndroid object. |
520 static jlong Init(JNIEnv* env, | 517 static jlong Init(JNIEnv* env, |
521 const base::android::JavaParamRef<jobject>& obj) { | 518 const base::android::JavaParamRef<jobject>& obj) { |
522 return reinterpret_cast<intptr_t>(Clipboard::GetForCurrentThread()); | 519 return reinterpret_cast<intptr_t>(Clipboard::GetForCurrentThread()); |
523 } | 520 } |
524 | 521 |
525 } // namespace ui | 522 } // namespace ui |
OLD | NEW |