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

Side by Side Diff: ui/android/java/src/org/chromium/ui/base/Clipboard.java

Issue 59023007: Enable pasting HTML content from the Android clipboard (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Upload *all* the files Created 7 years 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
OLDNEW
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.base; 5 package org.chromium.ui.base;
6 6
7 import org.chromium.base.ApiCompatibilityUtils;
7 import org.chromium.base.CalledByNative; 8 import org.chromium.base.CalledByNative;
8 import org.chromium.base.JNINamespace; 9 import org.chromium.base.JNINamespace;
9 10
10 import android.content.ClipData; 11 import android.content.ClipData;
11 import android.content.ClipboardManager; 12 import android.content.ClipboardManager;
12 import android.content.Context; 13 import android.content.Context;
13 import android.os.Build; 14 import android.os.Build;
14 import android.text.TextUtils; 15 import android.text.TextUtils;
15 16
16 /** 17 /**
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 if (clip != null && clip.getItemCount() > 0) { 71 if (clip != null && clip.getItemCount() > 0) {
71 final CharSequence sequence = clip.getItemAt(0).coerceToText(mContex t); 72 final CharSequence sequence = clip.getItemAt(0).coerceToText(mContex t);
72 if (sequence != null) { 73 if (sequence != null) {
73 return sequence.toString(); 74 return sequence.toString();
74 } 75 }
75 } 76 }
76 return null; 77 return null;
77 } 78 }
78 79
79 /** 80 /**
81 * Gets the HTML text of top item on the primary clip on the Android clipboa rd.
82 *
83 * @return a Java string with the html text if any, or null if there is no h tml
84 * text or no entries on the primary clip.
85 */
86 @CalledByNative
87 private String getHTMLText() {
88 if (isHTMLClipboardSupported()) {
89 final ClipData clip = mClipboardManager.getPrimaryClip();
90 if (clip != null && clip.getItemCount() > 0) {
91 return clip.getItemAt(0).getHtmlText();
92 }
93 }
94 return null;
95 }
96
97 /**
80 * Emulates the behavior of the now-deprecated 98 * Emulates the behavior of the now-deprecated
81 * {@link android.text.ClipboardManager#setText(CharSequence)}, setting the 99 * {@link android.text.ClipboardManager#setText(CharSequence)}, setting the
82 * clipboard's current primary clip to a plain-text clip that consists of 100 * clipboard's current primary clip to a plain-text clip that consists of
83 * the specified string. 101 * the specified string.
84 * 102 *
85 * @param text will become the content of the clipboard's primary clip 103 * @param text will become the content of the clipboard's primary clip
86 */ 104 */
87 @SuppressWarnings("javadoc") 105 @SuppressWarnings("javadoc")
88 @CalledByNative 106 @CalledByNative
89 private void setText(final String text) { 107 private void setText(final String text) {
90 mClipboardManager.setPrimaryClip(ClipData.newPlainText(null, text)); 108 mClipboardManager.setPrimaryClip(ClipData.newPlainText(null, text));
91 } 109 }
92 110
93 /** 111 /**
94 * Writes HTML to the clipboard, together with a plain-text representation 112 * 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 113 * of that very data. This API is only available in Android JellyBean+ and
96 * will be a no-operation in older versions. 114 * will be a no-operation in older versions.
97 * 115 *
98 * @param html The HTML content to be pasted to the clipboard. 116 * @param html The HTML content to be pasted to the clipboard.
99 * @param text Plain-text representation of the HTML content. 117 * @param text Plain-text representation of the HTML content.
100 */ 118 */
101 @CalledByNative 119 @CalledByNative
102 private void setHTMLText(final String html, final String text) { 120 private void setHTMLText(final String html, final String text) {
103 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 121 if (isHTMLClipboardSupported()) {
104 mClipboardManager.setPrimaryClip( 122 mClipboardManager.setPrimaryClip(
105 ClipData.newHtmlText(null, text, html)); 123 ClipData.newHtmlText(null, text, html));
106 } 124 }
107 } 125 }
108 126
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 127 @CalledByNative
120 private boolean hasPlainText() { 128 private static boolean isHTMLClipboardSupported() {
121 final ClipData clip = mClipboardManager.getPrimaryClip(); 129 return ApiCompatibilityUtils.isHTMLClipboardSupported();
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 } 130 }
128 } 131 }
OLDNEW
« no previous file with comments | « base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java ('k') | ui/base/clipboard/clipboard_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698