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

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

Issue 2824593002: Add ClipboardTest.java back (Closed)
Patch Set: add info Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/android/BUILD.gn ('k') | ui/android/junit/src/org/chromium/ui/base/ClipboardTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/android/java/src/org/chromium/ui/base/Clipboard.java
diff --git a/ui/android/java/src/org/chromium/ui/base/Clipboard.java b/ui/android/java/src/org/chromium/ui/base/Clipboard.java
index 0f3eb2578eaaf20da1f02001dba2a3884034b261..fddad5a451279f0fe215d359fe93e3745c8909f3 100644
--- a/ui/android/java/src/org/chromium/ui/base/Clipboard.java
+++ b/ui/android/java/src/org/chromium/ui/base/Clipboard.java
@@ -14,6 +14,7 @@ import android.text.style.CharacterStyle;
import android.text.style.ParagraphStyle;
import android.text.style.UpdateAppearance;
+import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
@@ -72,7 +73,7 @@ public class Clipboard implements ClipboardManager.OnPrimaryClipChangedListener
*/
@SuppressWarnings("javadoc")
@CalledByNative
- public String getCoercedText() {
+ private String getCoercedText() {
// getPrimaryClip() has been observed to throw unexpected exceptions for some devices (see
// crbug.com/654802 and b/31501780)
try {
@@ -97,6 +98,24 @@ public class Clipboard implements ClipboardManager.OnPrimaryClipChangedListener
return false;
}
+ public String clipDataToHtmlText(ClipData clipData) {
+ ClipDescription description = clipData.getDescription();
+ if (description.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML)) {
+ return clipData.getItemAt(0).getHtmlText();
+ }
+
+ if (description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
+ CharSequence text = clipData.getItemAt(0).getText();
+ if (!(text instanceof Spanned)) return null;
+ Spanned spanned = (Spanned) text;
+ if (hasStyleSpan(spanned)) {
+ return ApiCompatibilityUtils.toHtml(
+ spanned, Html.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE);
+ }
+ }
+ return null;
+ }
+
/**
* Gets the HTML text of top item on the primary clip on the Android clipboard.
*
@@ -104,26 +123,15 @@ public class Clipboard implements ClipboardManager.OnPrimaryClipChangedListener
* text or no entries on the primary clip.
*/
@CalledByNative
- public String getHTMLText() {
+ private String getHTMLText() {
// getPrimaryClip() has been observed to throw unexpected exceptions for some devices (see
// crbug/654802 and b/31501780)
try {
ClipData clipData = mClipboardManager.getPrimaryClip();
- ClipDescription description = clipData.getDescription();
- if (description.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML)) {
- return clipData.getItemAt(0).getHtmlText();
- }
-
- if (description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
- Spanned spanned = (Spanned) clipData.getItemAt(0).getText();
- if (hasStyleSpan(spanned)) {
- return Html.toHtml(spanned);
- }
- }
+ return clipDataToHtmlText(clipData);
} catch (Exception e) {
return null;
}
- return null;
}
/**
« no previous file with comments | « ui/android/BUILD.gn ('k') | ui/android/junit/src/org/chromium/ui/base/ClipboardTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698