Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 package org.chromium.ui; | 5 package org.chromium.ui; |
| 6 | 6 |
| 7 import org.chromium.base.CalledByNative; | 7 import org.chromium.base.CalledByNative; |
| 8 import org.chromium.base.JNINamespace; | 8 import org.chromium.base.JNINamespace; |
| 9 | 9 |
| 10 import android.content.ClipData; | 10 import android.content.ClipData; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 if (clip != null && clip.getItemCount() > 0) { | 70 if (clip != null && clip.getItemCount() > 0) { |
| 71 final CharSequence sequence = clip.getItemAt(0).coerceToText(mContex t); | 71 final CharSequence sequence = clip.getItemAt(0).coerceToText(mContex t); |
| 72 if (sequence != null) { | 72 if (sequence != null) { |
| 73 return sequence.toString(); | 73 return sequence.toString(); |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 return null; | 76 return null; |
| 77 } | 77 } |
| 78 | 78 |
| 79 /** | 79 /** |
| 80 * Gets the HTML text of top item on the primary clip on the Android clipboa rd. | |
| 81 * | |
| 82 * @return a Java string with the html text if any, or null if there is no h tml | |
| 83 * text or no entries on the primary clip. | |
| 84 */ | |
| 85 @CalledByNative | |
| 86 private String getHtmlText() { | |
| 87 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { | |
| 88 final ClipData clip = mClipboardManager.getPrimaryClip(); | |
| 89 if (clip != null && clip.getItemCount() > 0) { | |
| 90 return clip.getItemAt(0).getHtmlText(); | |
|
joth
2013/11/12 01:45:39
It looks like coerceToHtmlText handles a few addit
Kristian Monsen
2013/11/12 04:27:23
Done.
| |
| 91 } | |
| 92 } | |
| 93 return null; | |
| 94 } | |
| 95 | |
| 96 /** | |
| 80 * Emulates the behavior of the now-deprecated | 97 * Emulates the behavior of the now-deprecated |
| 81 * {@link android.text.ClipboardManager#setText(CharSequence)}, setting the | 98 * {@link android.text.ClipboardManager#setText(CharSequence)}, setting the |
| 82 * clipboard's current primary clip to a plain-text clip that consists of | 99 * clipboard's current primary clip to a plain-text clip that consists of |
| 83 * the specified string. | 100 * the specified string. |
| 84 * | 101 * |
| 85 * @param text will become the content of the clipboard's primary clip | 102 * @param text will become the content of the clipboard's primary clip |
| 86 */ | 103 */ |
| 87 @SuppressWarnings("javadoc") | 104 @SuppressWarnings("javadoc") |
| 88 @CalledByNative | 105 @CalledByNative |
| 89 private void setText(final String text) { | 106 private void setText(final String text) { |
| 90 mClipboardManager.setPrimaryClip(ClipData.newPlainText(null, text)); | 107 mClipboardManager.setPrimaryClip(ClipData.newPlainText(null, text)); |
| 91 } | 108 } |
| 92 | 109 |
| 93 /** | 110 /** |
| 94 * Writes HTML to the clipboard, together with a plain-text representation | 111 * Writes HTML to the clipboard, together with a plain-text representation |
| 95 * of that very data. This API is only available in Android JellyBean+ and | 112 * of that very data. This API is only available in Android JellyBean+ and |
| 96 * will be a no-operation in older versions. | 113 * will be a no-operation in older versions. |
| 97 * | 114 * |
| 98 * @param html The HTML content to be pasted to the clipboard. | 115 * @param html The HTML content to be pasted to the clipboard. |
| 99 * @param text Plain-text representation of the HTML content. | 116 * @param text Plain-text representation of the HTML content. |
| 100 */ | 117 */ |
| 101 @CalledByNative | 118 @CalledByNative |
| 102 private void setHTMLText(final String html, final String text) { | 119 private void setHTMLText(final String html, final String text) { |
| 103 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { | 120 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { |
| 104 mClipboardManager.setPrimaryClip( | 121 mClipboardManager.setPrimaryClip( |
| 105 ClipData.newHtmlText(null, text, html)); | 122 ClipData.newHtmlText(null, text, html)); |
| 106 } | 123 } |
| 107 } | 124 } |
| 108 | |
| 109 /** | |
| 110 * Approximates the behavior of the now-deprecated | |
| 111 * {@link android.text.ClipboardManager#hasText()}, returning true if and | |
| 112 * only if the clipboard has a primary clip and that clip contains a plain | |
| 113 * non-empty text entry (without attempting coercion - URLs and intents | |
| 114 * will cause this method to return false). | |
| 115 * | |
| 116 * @return as described above | |
| 117 */ | |
| 118 @SuppressWarnings("javadoc") | |
| 119 @CalledByNative | |
| 120 private boolean hasPlainText() { | |
| 121 final ClipData clip = mClipboardManager.getPrimaryClip(); | |
| 122 if (clip != null && clip.getItemCount() > 0) { | |
| 123 final CharSequence text = clip.getItemAt(0).getText(); | |
| 124 return !TextUtils.isEmpty(text); | |
| 125 } | |
| 126 return false; | |
| 127 } | |
| 128 } | 125 } |
| OLD | NEW |