Commit cc1bf8ea authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Remove KitKat-only code from //content

Bug: 1041930
Change-Id: If407bc3418dbf0759d248baa7cdd7d4a3b6844a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2297704
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#788890}
parent 1442059a
...@@ -808,7 +808,7 @@ jboolean WebContentsAccessibilityAndroid::PopulateAccessibilityNodeInfo( ...@@ -808,7 +808,7 @@ jboolean WebContentsAccessibilityAndroid::PopulateAccessibilityNodeInfo(
UpdateAccessibilityNodeInfoBoundsRect(env, obj, info, unique_id, node); UpdateAccessibilityNodeInfoBoundsRect(env, obj, info, unique_id, node);
Java_WebContentsAccessibilityImpl_setAccessibilityNodeInfoLollipopAttributes( Java_WebContentsAccessibilityImpl_setAccessibilityNodeInfoAttributes(
env, obj, info, node->CanOpenPopup(), node->IsContentInvalid(), env, obj, info, node->CanOpenPopup(), node->IsContentInvalid(),
node->IsDismissable(), node->IsMultiLine(), node->AndroidInputType(), node->IsDismissable(), node->IsMultiLine(), node->AndroidInputType(),
node->AndroidLiveRegionType(), node->AndroidLiveRegionType(),
...@@ -894,30 +894,6 @@ jboolean WebContentsAccessibilityAndroid::PopulateAccessibilityEvent( ...@@ -894,30 +894,6 @@ jboolean WebContentsAccessibilityAndroid::PopulateAccessibilityEvent(
break; break;
} }
Java_WebContentsAccessibilityImpl_setAccessibilityEventLollipopAttributes(
env, obj, event, node->CanOpenPopup(), node->IsContentInvalid(),
node->IsDismissable(), node->IsMultiLine(), node->AndroidInputType(),
node->AndroidLiveRegionType());
if (node->IsCollection()) {
Java_WebContentsAccessibilityImpl_setAccessibilityEventCollectionInfo(
env, obj, event, node->RowCount(), node->ColumnCount(),
node->IsHierarchical());
}
if (node->IsHeading()) {
Java_WebContentsAccessibilityImpl_setAccessibilityEventHeadingFlag(
env, obj, event, true);
}
if (node->IsCollectionItem()) {
Java_WebContentsAccessibilityImpl_setAccessibilityEventCollectionItemInfo(
env, obj, event, node->RowIndex(), node->RowSpan(), node->ColumnIndex(),
node->ColumnSpan());
}
if (node->IsRangeType()) {
Java_WebContentsAccessibilityImpl_setAccessibilityEventRangeInfo(
env, obj, event, node->AndroidRangeType(), node->RangeMin(),
node->RangeMax(), node->RangeCurrentValue());
}
return true; return true;
} }
......
...@@ -166,7 +166,6 @@ android_library("content_java") { ...@@ -166,7 +166,6 @@ android_library("content_java") {
"java/src/org/chromium/content/browser/JavascriptInterface.java", "java/src/org/chromium/content/browser/JavascriptInterface.java",
"java/src/org/chromium/content/browser/JoystickHandler.java", "java/src/org/chromium/content/browser/JoystickHandler.java",
"java/src/org/chromium/content/browser/LauncherThread.java", "java/src/org/chromium/content/browser/LauncherThread.java",
"java/src/org/chromium/content/browser/LollipopTtsPlatformImpl.java",
"java/src/org/chromium/content/browser/MediaSessionImpl.java", "java/src/org/chromium/content/browser/MediaSessionImpl.java",
"java/src/org/chromium/content/browser/MotionEventSynthesizerImpl.java", "java/src/org/chromium/content/browser/MotionEventSynthesizerImpl.java",
"java/src/org/chromium/content/browser/NfcHost.java", "java/src/org/chromium/content/browser/NfcHost.java",
...@@ -186,16 +185,13 @@ android_library("content_java") { ...@@ -186,16 +185,13 @@ android_library("content_java") {
"java/src/org/chromium/content/browser/WindowEventObserverManager.java", "java/src/org/chromium/content/browser/WindowEventObserverManager.java",
"java/src/org/chromium/content/browser/accessibility/AccessibilityEventDispatcher.java", "java/src/org/chromium/content/browser/accessibility/AccessibilityEventDispatcher.java",
"java/src/org/chromium/content/browser/accessibility/BrowserAccessibilityState.java", "java/src/org/chromium/content/browser/accessibility/BrowserAccessibilityState.java",
"java/src/org/chromium/content/browser/accessibility/LollipopWebContentsAccessibility.java",
"java/src/org/chromium/content/browser/accessibility/OWebContentsAccessibility.java", "java/src/org/chromium/content/browser/accessibility/OWebContentsAccessibility.java",
"java/src/org/chromium/content/browser/accessibility/PieWebContentsAccessibility.java", "java/src/org/chromium/content/browser/accessibility/PieWebContentsAccessibility.java",
"java/src/org/chromium/content/browser/accessibility/WebContentsAccessibilityImpl.java", "java/src/org/chromium/content/browser/accessibility/WebContentsAccessibilityImpl.java",
"java/src/org/chromium/content/browser/accessibility/captioning/CaptioningBridgeFactory.java", "java/src/org/chromium/content/browser/accessibility/captioning/CaptioningBridge.java",
"java/src/org/chromium/content/browser/accessibility/captioning/CaptioningChangeDelegate.java", "java/src/org/chromium/content/browser/accessibility/captioning/CaptioningChangeDelegate.java",
"java/src/org/chromium/content/browser/accessibility/captioning/CaptioningController.java", "java/src/org/chromium/content/browser/accessibility/captioning/CaptioningController.java",
"java/src/org/chromium/content/browser/accessibility/captioning/CaptioningStyle.java", "java/src/org/chromium/content/browser/accessibility/captioning/CaptioningStyle.java",
"java/src/org/chromium/content/browser/accessibility/captioning/EmptyCaptioningBridge.java",
"java/src/org/chromium/content/browser/accessibility/captioning/KitKatCaptioningBridge.java",
"java/src/org/chromium/content/browser/accessibility/captioning/SystemCaptioningBridge.java", "java/src/org/chromium/content/browser/accessibility/captioning/SystemCaptioningBridge.java",
"java/src/org/chromium/content/browser/accessibility/captioning/TextTrackSettings.java", "java/src/org/chromium/content/browser/accessibility/captioning/TextTrackSettings.java",
"java/src/org/chromium/content/browser/androidoverlay/AndroidOverlayProviderImpl.java", "java/src/org/chromium/content/browser/androidoverlay/AndroidOverlayProviderImpl.java",
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.content.browser;
import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.UtteranceProgressListener;
import org.chromium.base.annotations.JNINamespace;
/**
* Subclass of TtsPlatformImpl for Lollipop to make use of newer APIs.
*/
@JNINamespace("content")
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
class LollipopTtsPlatformImpl extends TtsPlatformImpl {
protected LollipopTtsPlatformImpl(long nativeTtsPlatformImplAndroid) {
super(nativeTtsPlatformImplAndroid);
}
/**
* Overrides TtsPlatformImpl because the API changed in Lollipop.
*/
@Override
protected void addOnUtteranceProgressListener() {
mTextToSpeech.setOnUtteranceProgressListener(new UtteranceProgressListener() {
@Override
public void onDone(final String utteranceId) {
sendEndEventOnUiThread(utteranceId);
}
@Override
public void onError(final String utteranceId, int errorCode) {
sendErrorEventOnUiThread(utteranceId);
}
@Override
@Deprecated
public void onError(final String utteranceId) {}
@Override
public void onStart(final String utteranceId) {
sendStartEventOnUiThread(utteranceId);
}
});
}
/**
* Overrides TtsPlatformImpl because the API changed in Lollipop.
*/
@Override
protected int callSpeak(String text, float volume, int utteranceId) {
Bundle params = new Bundle();
if (volume != 1.0) {
params.putFloat(TextToSpeech.Engine.KEY_PARAM_VOLUME, volume);
}
return mTextToSpeech.speak(
text, TextToSpeech.QUEUE_FLUSH, params, Integer.toString(utteranceId));
}
}
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
package org.chromium.content.browser; package org.chromium.content.browser;
import android.os.Build; import android.os.Bundle;
import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech;
import android.speech.tts.UtteranceProgressListener; import android.speech.tts.UtteranceProgressListener;
...@@ -18,7 +18,6 @@ import org.chromium.base.task.PostTask; ...@@ -18,7 +18,6 @@ import org.chromium.base.task.PostTask;
import org.chromium.content_public.browser.UiThreadTaskTraits; import org.chromium.content_public.browser.UiThreadTaskTraits;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
...@@ -68,13 +67,13 @@ class TtsPlatformImpl { ...@@ -68,13 +67,13 @@ class TtsPlatformImpl {
} }
private long mNativeTtsPlatformImplAndroid; private long mNativeTtsPlatformImplAndroid;
protected final TextToSpeech mTextToSpeech; private final TextToSpeech mTextToSpeech;
private boolean mInitialized; private boolean mInitialized;
private List<TtsVoice> mVoices; private List<TtsVoice> mVoices;
private String mCurrentLanguage; private String mCurrentLanguage;
private PendingUtterance mPendingUtterance; private PendingUtterance mPendingUtterance;
protected TtsPlatformImpl(long nativeTtsPlatformImplAndroid) { private TtsPlatformImpl(long nativeTtsPlatformImplAndroid) {
mInitialized = false; mInitialized = false;
mNativeTtsPlatformImplAndroid = nativeTtsPlatformImplAndroid; mNativeTtsPlatformImplAndroid = nativeTtsPlatformImplAndroid;
mTextToSpeech = new TextToSpeech(ContextUtils.getApplicationContext(), status -> { mTextToSpeech = new TextToSpeech(ContextUtils.getApplicationContext(), status -> {
...@@ -93,11 +92,7 @@ class TtsPlatformImpl { ...@@ -93,11 +92,7 @@ class TtsPlatformImpl {
*/ */
@CalledByNative @CalledByNative
private static TtsPlatformImpl create(long nativeTtsPlatformImplAndroid) { private static TtsPlatformImpl create(long nativeTtsPlatformImplAndroid) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return new TtsPlatformImpl(nativeTtsPlatformImplAndroid);
return new LollipopTtsPlatformImpl(nativeTtsPlatformImplAndroid);
} else {
return new TtsPlatformImpl(nativeTtsPlatformImplAndroid);
}
} }
/** /**
...@@ -192,7 +187,7 @@ class TtsPlatformImpl { ...@@ -192,7 +187,7 @@ class TtsPlatformImpl {
/** /**
* Post a task to the UI thread to send the TTS "end" event. * Post a task to the UI thread to send the TTS "end" event.
*/ */
protected void sendEndEventOnUiThread(final String utteranceId) { private void sendEndEventOnUiThread(final String utteranceId) {
PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT, () -> { PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT, () -> {
if (mNativeTtsPlatformImplAndroid != 0) { if (mNativeTtsPlatformImplAndroid != 0) {
TtsPlatformImplJni.get().onEndEvent( TtsPlatformImplJni.get().onEndEvent(
...@@ -204,7 +199,7 @@ class TtsPlatformImpl { ...@@ -204,7 +199,7 @@ class TtsPlatformImpl {
/** /**
* Post a task to the UI thread to send the TTS "error" event. * Post a task to the UI thread to send the TTS "error" event.
*/ */
protected void sendErrorEventOnUiThread(final String utteranceId) { private void sendErrorEventOnUiThread(final String utteranceId) {
PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT, () -> { PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT, () -> {
if (mNativeTtsPlatformImplAndroid != 0) { if (mNativeTtsPlatformImplAndroid != 0) {
TtsPlatformImplJni.get().onErrorEvent( TtsPlatformImplJni.get().onErrorEvent(
...@@ -216,7 +211,7 @@ class TtsPlatformImpl { ...@@ -216,7 +211,7 @@ class TtsPlatformImpl {
/** /**
* Post a task to the UI thread to send the TTS "start" event. * Post a task to the UI thread to send the TTS "start" event.
*/ */
protected void sendStartEventOnUiThread(final String utteranceId) { private void sendStartEventOnUiThread(final String utteranceId) {
PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT, () -> { PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT, () -> {
if (mNativeTtsPlatformImplAndroid != 0) { if (mNativeTtsPlatformImplAndroid != 0) {
TtsPlatformImplJni.get().onStartEvent( TtsPlatformImplJni.get().onStartEvent(
...@@ -225,25 +220,23 @@ class TtsPlatformImpl { ...@@ -225,25 +220,23 @@ class TtsPlatformImpl {
}); });
} }
/**
* This is overridden by LollipopTtsPlatformImpl because the API changed.
*/
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
protected void addOnUtteranceProgressListener() { private void addOnUtteranceProgressListener() {
mTextToSpeech.setOnUtteranceProgressListener(new UtteranceProgressListener() { mTextToSpeech.setOnUtteranceProgressListener(new UtteranceProgressListener() {
@Override @Override
public void onDone(final String utteranceId) { public void onDone(final String utteranceId) {
sendEndEventOnUiThread(utteranceId); sendEndEventOnUiThread(utteranceId);
} }
// This is deprecated in Lollipop and higher but we still need to catch it
// on pre-Lollipop builds.
@Override @Override
@SuppressWarnings("deprecation") public void onError(final String utteranceId, int errorCode) {
public void onError(final String utteranceId) {
sendErrorEventOnUiThread(utteranceId); sendErrorEventOnUiThread(utteranceId);
} }
@Override
@Deprecated
public void onError(final String utteranceId) {}
@Override @Override
public void onStart(final String utteranceId) { public void onStart(final String utteranceId) {
sendStartEventOnUiThread(utteranceId); sendStartEventOnUiThread(utteranceId);
...@@ -251,17 +244,14 @@ class TtsPlatformImpl { ...@@ -251,17 +244,14 @@ class TtsPlatformImpl {
}); });
} }
/**
* This is overridden by LollipopTtsPlatformImpl because the API changed.
*/
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
protected int callSpeak(String text, float volume, int utteranceId) { private int callSpeak(String text, float volume, int utteranceId) {
HashMap<String, String> params = new HashMap<String, String>(); Bundle params = new Bundle();
if (volume != 1.0) { if (volume != 1.0) {
params.put(TextToSpeech.Engine.KEY_PARAM_VOLUME, Double.toString(volume)); params.putFloat(TextToSpeech.Engine.KEY_PARAM_VOLUME, volume);
} }
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, Integer.toString(utteranceId)); return mTextToSpeech.speak(
return mTextToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, params); text, TextToSpeech.QUEUE_FLUSH, params, Integer.toString(utteranceId));
} }
/** /**
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.content.browser.accessibility;
import android.annotation.TargetApi;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ReceiverCallNotAllowedException;
import android.os.Build;
import android.text.SpannableString;
import android.text.style.LocaleSpan;
import android.text.style.SuggestionSpan;
import android.util.SparseArray;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.content_public.browser.WebContents;
import java.util.Locale;
/**
* Subclass of WebContentsAccessibility for Lollipop.
*/
@JNINamespace("content")
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class LollipopWebContentsAccessibility extends WebContentsAccessibilityImpl {
private static SparseArray<AccessibilityAction> sAccessibilityActionMap =
new SparseArray<AccessibilityAction>();
private String mSystemLanguageTag;
private BroadcastReceiver mBroadcastReceiver;
LollipopWebContentsAccessibility(WebContents webContents) {
super(webContents);
}
@Override
protected void onNativeInit() {
super.onNativeInit();
mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
mSystemLanguageTag = Locale.getDefault().toLanguageTag();
}
};
// Register a broadcast receiver for locale change for Lollipop or higher version.
if (mView.isAttachedToWindow()) registerLocaleChangeReceiver();
}
@Override
protected void setAccessibilityNodeInfoLollipopAttributes(AccessibilityNodeInfo node,
boolean canOpenPopup, boolean contentInvalid, boolean dismissable, boolean multiLine,
int inputType, int liveRegion, String errorMessage) {
node.setCanOpenPopup(canOpenPopup);
node.setContentInvalid(contentInvalid);
node.setDismissable(contentInvalid);
node.setMultiLine(multiLine);
node.setInputType(inputType);
node.setLiveRegion(liveRegion);
node.setError(errorMessage);
}
@Override
protected void setAccessibilityNodeInfoCollectionInfo(
AccessibilityNodeInfo node, int rowCount, int columnCount, boolean hierarchical) {
node.setCollectionInfo(
AccessibilityNodeInfo.CollectionInfo.obtain(rowCount, columnCount, hierarchical));
}
@Override
protected void setAccessibilityNodeInfoCollectionItemInfo(AccessibilityNodeInfo node,
int rowIndex, int rowSpan, int columnIndex, int columnSpan, boolean heading) {
node.setCollectionItemInfo(AccessibilityNodeInfo.CollectionItemInfo.obtain(
rowIndex, rowSpan, columnIndex, columnSpan, heading));
}
@Override
protected void setAccessibilityNodeInfoRangeInfo(
AccessibilityNodeInfo node, int rangeType, float min, float max, float current) {
node.setRangeInfo(AccessibilityNodeInfo.RangeInfo.obtain(rangeType, min, max, current));
}
@Override
protected void setAccessibilityNodeInfoViewIdResourceName(
AccessibilityNodeInfo node, String viewIdResourceName) {
node.setViewIdResourceName(viewIdResourceName);
}
@Override
protected void setAccessibilityEventLollipopAttributes(AccessibilityEvent event,
boolean canOpenPopup, boolean contentInvalid, boolean dismissable, boolean multiLine,
int inputType, int liveRegion) {
// This is just a fallback for pre-Lollipop systems.
// Do nothing on Lollipop and higher.
}
@Override
protected void setAccessibilityEventCollectionInfo(
AccessibilityEvent event, int rowCount, int columnCount, boolean hierarchical) {
// This is just a fallback for pre-Lollipop systems.
// Do nothing on Lollipop and higher.
}
@Override
protected void setAccessibilityEventHeadingFlag(AccessibilityEvent event, boolean heading) {
// This is just a fallback for pre-Lollipop systems.
// Do nothing on Lollipop and higher.
}
@Override
protected void setAccessibilityEventCollectionItemInfo(
AccessibilityEvent event, int rowIndex, int rowSpan, int columnIndex, int columnSpan) {
// This is just a fallback for pre-Lollipop systems.
// Do nothing on Lollipop and higher.
}
@Override
protected void setAccessibilityEventRangeInfo(
AccessibilityEvent event, int rangeType, float min, float max, float current) {
// This is just a fallback for pre-Lollipop systems.
// Do nothing on Lollipop and higher.
}
@Override
protected void addAction(AccessibilityNodeInfo node, int actionId) {
// The Lollipop SDK requires us to call AccessibilityNodeInfo.addAction with an
// AccessibilityAction argument, but to simplify things and share more code with
// the pre-L SDK, we just cache a set of AccessibilityActions mapped by their ID.
AccessibilityAction action = sAccessibilityActionMap.get(actionId);
if (action == null) {
action = new AccessibilityAction(actionId, null);
sAccessibilityActionMap.put(actionId, action);
}
node.addAction(action);
}
@Override
protected CharSequence computeText(String text, boolean annotateAsLink, String language,
int[] suggestionStarts, int[] suggestionEnds, String[] suggestions) {
CharSequence charSequence = super.computeText(
text, annotateAsLink, language, suggestionStarts, suggestionEnds, suggestions);
if (!language.isEmpty() && !language.equals(mSystemLanguageTag)) {
SpannableString spannable;
if (charSequence instanceof SpannableString) {
spannable = (SpannableString) charSequence;
} else {
spannable = new SpannableString(charSequence);
}
Locale locale = Locale.forLanguageTag(language);
spannable.setSpan(new LocaleSpan(locale), 0, spannable.length(), 0);
charSequence = spannable;
}
if (suggestionStarts != null && suggestionStarts.length > 0) {
assert suggestionEnds != null;
assert suggestionEnds.length == suggestionStarts.length;
assert suggestions != null;
assert suggestions.length == suggestionStarts.length;
SpannableString spannable;
if (charSequence instanceof SpannableString) {
spannable = (SpannableString) charSequence;
} else {
spannable = new SpannableString(charSequence);
}
int spannableLen = spannable.length();
for (int i = 0; i < suggestionStarts.length; i++) {
int start = suggestionStarts[i];
int end = suggestionEnds[i];
// Ignore any spans outside the range of the spannable string.
if (start < 0 || start > spannableLen || end < 0 || end > spannableLen
|| start > end) {
continue;
}
String[] suggestionArray = new String[1];
suggestionArray[0] = suggestions[i];
int flags = SuggestionSpan.FLAG_MISSPELLED;
SuggestionSpan suggestionSpan =
new SuggestionSpan(mContext, suggestionArray, flags);
spannable.setSpan(suggestionSpan, start, end, 0);
}
charSequence = spannable;
}
return charSequence;
}
@Override
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
if (!isNativeInitialized()) return;
ContextUtils.getApplicationContext().unregisterReceiver(mBroadcastReceiver);
}
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
registerLocaleChangeReceiver();
}
private void registerLocaleChangeReceiver() {
if (!isNativeInitialized()) return;
try {
IntentFilter filter = new IntentFilter(Intent.ACTION_LOCALE_CHANGED);
ContextUtils.getApplicationContext().registerReceiver(mBroadcastReceiver, filter);
} catch (ReceiverCallNotAllowedException e) {
// WebView may be running inside a BroadcastReceiver, in which case registerReceiver is
// not allowed.
}
mSystemLanguageTag = Locale.getDefault().toLanguageTag();
}
}
...@@ -25,7 +25,7 @@ import java.util.Arrays; ...@@ -25,7 +25,7 @@ import java.util.Arrays;
*/ */
@JNINamespace("content") @JNINamespace("content")
@TargetApi(Build.VERSION_CODES.O) @TargetApi(Build.VERSION_CODES.O)
public class OWebContentsAccessibility extends LollipopWebContentsAccessibility { public class OWebContentsAccessibility extends WebContentsAccessibilityImpl {
OWebContentsAccessibility(WebContents webContents) { OWebContentsAccessibility(WebContents webContents) {
super(webContents); super(webContents);
} }
......
...@@ -4,9 +4,7 @@ ...@@ -4,9 +4,7 @@
package org.chromium.content.browser.accessibility.captioning; package org.chromium.content.browser.accessibility.captioning;
import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.os.Build;
import android.view.accessibility.CaptioningManager; import android.view.accessibility.CaptioningManager;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
...@@ -14,67 +12,47 @@ import org.chromium.base.ContextUtils; ...@@ -14,67 +12,47 @@ import org.chromium.base.ContextUtils;
import java.util.Locale; import java.util.Locale;
/** /**
* This is the implementation of SystemCaptioningBridge that uses CaptioningManager * Implementation of SystemCaptioningBridge that uses CaptioningManager.
* on KitKat+ systems.
*/ */
@TargetApi(Build.VERSION_CODES.KITKAT) public class CaptioningBridge
public class KitKatCaptioningBridge implements SystemCaptioningBridge { extends CaptioningManager.CaptioningChangeListener implements SystemCaptioningBridge {
private final CaptioningManager.CaptioningChangeListener mCaptioningChangeListener =
new KitKatCaptioningChangeListener();
private final CaptioningChangeDelegate mCaptioningChangeDelegate; private final CaptioningChangeDelegate mCaptioningChangeDelegate;
private final CaptioningManager mCaptioningManager; private final CaptioningManager mCaptioningManager;
private static KitKatCaptioningBridge sKitKatCaptioningBridge; private static CaptioningBridge sInstance;
/** public static CaptioningBridge getInstance() {
* Bridge listener to inform the mCaptioningChangeDelegate when the mCaptioningManager if (sInstance == null) {
* broadcasts any changes. sInstance = new CaptioningBridge();
*/
private class KitKatCaptioningChangeListener extends
CaptioningManager.CaptioningChangeListener {
@Override
public void onEnabledChanged(boolean enabled) {
mCaptioningChangeDelegate.onEnabledChanged(enabled);
} }
return sInstance;
}
@Override private CaptioningBridge() {
public void onFontScaleChanged(float fontScale) { mCaptioningChangeDelegate = new CaptioningChangeDelegate();
mCaptioningChangeDelegate.onFontScaleChanged(fontScale); mCaptioningManager =
} (CaptioningManager) ContextUtils.getApplicationContext().getSystemService(
Context.CAPTIONING_SERVICE);
}
@Override @Override
public void onLocaleChanged(Locale locale) { public void onEnabledChanged(boolean enabled) {
mCaptioningChangeDelegate.onLocaleChanged(locale); mCaptioningChangeDelegate.onEnabledChanged(enabled);
} }
@Override @Override
public void onUserStyleChanged(CaptioningManager.CaptionStyle userStyle) { public void onFontScaleChanged(float fontScale) {
final CaptioningStyle captioningStyle = getCaptioningStyleFrom(userStyle); mCaptioningChangeDelegate.onFontScaleChanged(fontScale);
mCaptioningChangeDelegate.onUserStyleChanged(captioningStyle);
}
} }
/** @Override
* Return the singleton instance of the captioning bridge for Kitkat+ public void onLocaleChanged(Locale locale) {
* mCaptioningChangeDelegate.onLocaleChanged(locale);
* @param context the Context to associate with this bridge.
* @return the singleton instance of KitKatCaptioningBridge.
*/
public static KitKatCaptioningBridge getInstance() {
if (sKitKatCaptioningBridge == null) {
sKitKatCaptioningBridge = new KitKatCaptioningBridge();
}
return sKitKatCaptioningBridge;
} }
/** @Override
* Construct a new KitKat+ captioning bridge public void onUserStyleChanged(CaptioningManager.CaptionStyle userStyle) {
*/ final CaptioningStyle captioningStyle = getCaptioningStyleFrom(userStyle);
private KitKatCaptioningBridge() { mCaptioningChangeDelegate.onUserStyleChanged(captioningStyle);
mCaptioningChangeDelegate = new CaptioningChangeDelegate();
mCaptioningManager =
(CaptioningManager) ContextUtils.getApplicationContext().getSystemService(
Context.CAPTIONING_SERVICE);
} }
/** /**
...@@ -99,7 +77,7 @@ public class KitKatCaptioningBridge implements SystemCaptioningBridge { ...@@ -99,7 +77,7 @@ public class KitKatCaptioningBridge implements SystemCaptioningBridge {
@Override @Override
public void addListener(SystemCaptioningBridge.SystemCaptioningBridgeListener listener) { public void addListener(SystemCaptioningBridge.SystemCaptioningBridgeListener listener) {
if (!mCaptioningChangeDelegate.hasActiveListener()) { if (!mCaptioningChangeDelegate.hasActiveListener()) {
mCaptioningManager.addCaptioningChangeListener(mCaptioningChangeListener); mCaptioningManager.addCaptioningChangeListener(this);
syncToDelegate(); syncToDelegate();
} }
mCaptioningChangeDelegate.addListener(listener); mCaptioningChangeDelegate.addListener(listener);
...@@ -110,7 +88,7 @@ public class KitKatCaptioningBridge implements SystemCaptioningBridge { ...@@ -110,7 +88,7 @@ public class KitKatCaptioningBridge implements SystemCaptioningBridge {
public void removeListener(SystemCaptioningBridge.SystemCaptioningBridgeListener listener) { public void removeListener(SystemCaptioningBridge.SystemCaptioningBridgeListener listener) {
mCaptioningChangeDelegate.removeListener(listener); mCaptioningChangeDelegate.removeListener(listener);
if (!mCaptioningChangeDelegate.hasActiveListener()) { if (!mCaptioningChangeDelegate.hasActiveListener()) {
mCaptioningManager.removeCaptioningChangeListener(mCaptioningChangeListener); mCaptioningManager.removeCaptioningChangeListener(this);
} }
} }
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.content.browser.accessibility.captioning;
import android.os.Build;
/**
* Returns the best captions bridge available. If the API level is lower than KitKat, a no-op
* bridge is returned since those systems didn't support this functionality.
*/
public class CaptioningBridgeFactory {
/**
* Create and return the best SystemCaptioningBridge available.
*
* @return the best SystemCaptioningBridge available.
*/
public static SystemCaptioningBridge getSystemCaptioningBridge() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
return KitKatCaptioningBridge.getInstance();
}
// On older systems, return a CaptioningBridge that does nothing.
return new EmptyCaptioningBridge();
}
}
...@@ -68,9 +68,6 @@ public class CaptioningChangeDelegate { ...@@ -68,9 +68,6 @@ public class CaptioningChangeDelegate {
public void onLocaleChanged(Locale locale) {} public void onLocaleChanged(Locale locale) {}
/** /**
* Unlike the original method, use Chromium's CaptioningStyle since CaptionStyle is only
* available on KitKat or higher. userStyle will never be null.
*
* @see android.view.accessibility.CaptioningManager.CaptioningChangeListener#onUserStyleChanged * @see android.view.accessibility.CaptioningManager.CaptioningChangeListener#onUserStyleChanged
*/ */
public void onUserStyleChanged(CaptioningStyle userStyle) { public void onUserStyleChanged(CaptioningStyle userStyle) {
...@@ -108,7 +105,6 @@ public class CaptioningChangeDelegate { ...@@ -108,7 +105,6 @@ public class CaptioningChangeDelegate {
public static String getShadowFromColorAndSystemEdge(String color, Integer type) { public static String getShadowFromColorAndSystemEdge(String color, Integer type) {
String edgeShadow = ""; String edgeShadow = "";
if (type != null) { if (type != null) {
// Lollipop adds support for EDGE_TYPE_DEPRESSED and EDGE_TYPE_RAISED.
switch (type) { switch (type) {
case CaptionStyle.EDGE_TYPE_OUTLINE: case CaptionStyle.EDGE_TYPE_OUTLINE:
edgeShadow = edgeShadow =
...@@ -149,9 +145,7 @@ public class CaptioningChangeDelegate { ...@@ -149,9 +145,7 @@ public class CaptioningChangeDelegate {
// in Android settings app. // in Android settings app.
String fonts[] = {// Fonts in Lollipop and above String fonts[] = {// Fonts in Lollipop and above
"", "sans-serif", "sans-serif-condensed", "sans-serif-monospace", "serif", "", "sans-serif", "sans-serif-condensed", "sans-serif-monospace", "serif",
"serif-monospace", "casual", "cursive", "sans-serif-smallcaps", "serif-monospace", "casual", "cursive", "sans-serif-smallcaps", "monospace"};
// Fonts in KitKat
"monospace"};
for (String font : fonts) { for (String font : fonts) {
if (Typeface.create(font, typeFace.getStyle()).equals(typeFace)) return font; if (Typeface.create(font, typeFace.getStyle()).equals(typeFace)) return font;
} }
......
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
package org.chromium.content.browser.accessibility.captioning; package org.chromium.content.browser.accessibility.captioning;
import android.annotation.TargetApi;
import android.os.Build;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods; import org.chromium.base.annotations.NativeMethods;
...@@ -21,7 +18,7 @@ public class CaptioningController implements SystemCaptioningBridge.SystemCaptio ...@@ -21,7 +18,7 @@ public class CaptioningController implements SystemCaptioningBridge.SystemCaptio
private long mNativeCaptioningController; private long mNativeCaptioningController;
public CaptioningController(WebContents webContents) { public CaptioningController(WebContents webContents) {
mSystemCaptioningBridge = CaptioningBridgeFactory.getSystemCaptioningBridge(); mSystemCaptioningBridge = CaptioningBridge.getInstance();
mNativeCaptioningController = mNativeCaptioningController =
CaptioningControllerJni.get().init(CaptioningController.this, webContents); CaptioningControllerJni.get().init(CaptioningController.this, webContents);
} }
...@@ -39,7 +36,6 @@ public class CaptioningController implements SystemCaptioningBridge.SystemCaptio ...@@ -39,7 +36,6 @@ public class CaptioningController implements SystemCaptioningBridge.SystemCaptio
mSystemCaptioningBridge.syncToListener(this); mSystemCaptioningBridge.syncToListener(this);
} }
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override @Override
public void onSystemCaptioningChanged(TextTrackSettings settings) { public void onSystemCaptioningChanged(TextTrackSettings settings) {
if (mNativeCaptioningController == 0) return; if (mNativeCaptioningController == 0) return;
......
...@@ -4,10 +4,7 @@ ...@@ -4,10 +4,7 @@
package org.chromium.content.browser.accessibility.captioning; package org.chromium.content.browser.accessibility.captioning;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.Build;
import android.view.accessibility.CaptioningManager.CaptionStyle; import android.view.accessibility.CaptioningManager.CaptionStyle;
/** /**
...@@ -18,7 +15,6 @@ import android.view.accessibility.CaptioningManager.CaptionStyle; ...@@ -18,7 +15,6 @@ import android.view.accessibility.CaptioningManager.CaptionStyle;
* For information on CaptionStyle, introduced in KitKat, see: * For information on CaptionStyle, introduced in KitKat, see:
* @link https://developer.android.com/reference/android/view/accessibility/CaptioningManager.CaptionStyle.html * @link https://developer.android.com/reference/android/view/accessibility/CaptioningManager.CaptionStyle.html
*/ */
@TargetApi(Build.VERSION_CODES.KITKAT)
public class CaptioningStyle { public class CaptioningStyle {
private Integer mBackgroundColor; private Integer mBackgroundColor;
private Integer mEdgeColor; private Integer mEdgeColor;
...@@ -105,7 +101,6 @@ public class CaptioningStyle { ...@@ -105,7 +101,6 @@ public class CaptioningStyle {
* @param captionStyle an Android platform CaptionStyle object * @param captionStyle an Android platform CaptionStyle object
* @return a Chromium CaptioningStyle object * @return a Chromium CaptioningStyle object
*/ */
@SuppressLint("NewApi")
public static CaptioningStyle createFrom(CaptionStyle captionStyle) { public static CaptioningStyle createFrom(CaptionStyle captionStyle) {
if (captionStyle == null) { if (captionStyle == null) {
return new CaptioningStyle(null, null, null, null, null, null); return new CaptioningStyle(null, null, null, null, null, null);
...@@ -116,28 +111,21 @@ public class CaptioningStyle { ...@@ -116,28 +111,21 @@ public class CaptioningStyle {
Integer edgeType = null; Integer edgeType = null;
Integer foregroundColor = null; Integer foregroundColor = null;
Integer windowColor = null; Integer windowColor = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (captionStyle.hasBackgroundColor()) {
if (captionStyle.hasBackgroundColor()) {
backgroundColor = Integer.valueOf(captionStyle.backgroundColor);
}
if (captionStyle.hasEdgeColor()) {
edgeColor = Integer.valueOf(captionStyle.edgeColor);
}
if (captionStyle.hasEdgeType()) {
edgeType = Integer.valueOf(captionStyle.edgeType);
}
if (captionStyle.hasForegroundColor()) {
foregroundColor = Integer.valueOf(captionStyle.foregroundColor);
}
if (captionStyle.hasWindowColor()) {
windowColor = Integer.valueOf(captionStyle.windowColor);
}
} else {
backgroundColor = Integer.valueOf(captionStyle.backgroundColor); backgroundColor = Integer.valueOf(captionStyle.backgroundColor);
}
if (captionStyle.hasEdgeColor()) {
edgeColor = Integer.valueOf(captionStyle.edgeColor); edgeColor = Integer.valueOf(captionStyle.edgeColor);
}
if (captionStyle.hasEdgeType()) {
edgeType = Integer.valueOf(captionStyle.edgeType); edgeType = Integer.valueOf(captionStyle.edgeType);
}
if (captionStyle.hasForegroundColor()) {
foregroundColor = Integer.valueOf(captionStyle.foregroundColor); foregroundColor = Integer.valueOf(captionStyle.foregroundColor);
} }
if (captionStyle.hasWindowColor()) {
windowColor = Integer.valueOf(captionStyle.windowColor);
}
return new CaptioningStyle(backgroundColor, edgeColor, edgeType, foregroundColor, return new CaptioningStyle(backgroundColor, edgeColor, edgeType, foregroundColor,
windowColor, captionStyle.getTypeface()); windowColor, captionStyle.getTypeface());
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.content.browser.accessibility.captioning;
/**
* This is the empty implementation of SystemCaptioningBridge that does nothing used
* on versions of Android that do not have support for system closed captioning settings.
*/
public class EmptyCaptioningBridge implements SystemCaptioningBridge {
/**
* A no-op implementation of the syncToListener function.
*/
@Override
public void syncToListener(SystemCaptioningBridge.SystemCaptioningBridgeListener listener) {}
/**
* No-op implementation of addListener.
*/
@Override
public void addListener(SystemCaptioningBridge.SystemCaptioningBridgeListener listener) {}
/**
* A no-op implementation of the removeListener function.
*/
@Override
public void removeListener(SystemCaptioningBridge.SystemCaptioningBridgeListener listener) {}
}
...@@ -4,16 +4,12 @@ ...@@ -4,16 +4,12 @@
package org.chromium.content.browser.accessibility.captioning; package org.chromium.content.browser.accessibility.captioning;
import android.annotation.TargetApi;
import android.os.Build;
import java.util.Objects; import java.util.Objects;
/** /**
* Bundles the Closed Caption Track Settings and ensures that non-null * Bundles the Closed Caption Track Settings and ensures that non-null
* strings are used used by the recipient of this bundle. * strings are used used by the recipient of this bundle.
*/ */
@TargetApi(Build.VERSION_CODES.KITKAT)
public final class TextTrackSettings { public final class TextTrackSettings {
private static final String DEFAULT_VALUE = ""; private static final String DEFAULT_VALUE = "";
private boolean mTextTracksEnabled; private boolean mTextTracksEnabled;
......
...@@ -4,9 +4,7 @@ ...@@ -4,9 +4,7 @@
package org.chromium.content.browser.input; package org.chromium.content.browser.input;
import android.annotation.TargetApi;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.os.Build;
import android.view.View; import android.view.View;
import android.view.inputmethod.CursorAnchorInfo; import android.view.inputmethod.CursorAnchorInfo;
...@@ -22,10 +20,8 @@ import javax.annotation.Nonnull; ...@@ -22,10 +20,8 @@ import javax.annotation.Nonnull;
/** /**
* A state machine interface which receives Chromium internal events to determines when to call * A state machine interface which receives Chromium internal events to determines when to call
* {@link InputMethodManager#updateCursorAnchorInfo(View, CursorAnchorInfo)}. This interface is * {@link InputMethodManager#updateCursorAnchorInfo(View, CursorAnchorInfo)}. This interface is
* also used in unit tests to mock out {@link CursorAnchorInfo}, which is available only in * also used in unit tests to mock out {@link CursorAnchorInfo}.
* Android 5.0 (Lollipop) and later.
*/ */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
final class CursorAnchorInfoController { final class CursorAnchorInfoController {
/** /**
* An interface to mock out {@link View#getLocationOnScreen(int[])} for testing. * An interface to mock out {@link View#getLocationOnScreen(int[])} for testing.
......
...@@ -8,7 +8,6 @@ import android.content.Context; ...@@ -8,7 +8,6 @@ import android.content.Context;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.ResultReceiver; import android.os.ResultReceiver;
...@@ -208,33 +207,29 @@ public class ImeAdapterImpl ...@@ -208,33 +207,29 @@ public class ImeAdapterImpl
mCurrentConfig = new Configuration(getContainerView().getResources().getConfiguration()); mCurrentConfig = new Configuration(getContainerView().getResources().getConfiguration());
// CursorAnchroInfo is supported only after L. // CursorAnchroInfo is supported only after L.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mCursorAnchorInfoController = CursorAnchorInfoController.create(
mCursorAnchorInfoController = CursorAnchorInfoController.create( wrapper, new CursorAnchorInfoController.ComposingTextDelegate() {
wrapper, new CursorAnchorInfoController.ComposingTextDelegate() { @Override
@Override public CharSequence getText() {
public CharSequence getText() { return mLastText;
return mLastText; }
} @Override
@Override public int getSelectionStart() {
public int getSelectionStart() { return mLastSelectionStart;
return mLastSelectionStart; }
} @Override
@Override public int getSelectionEnd() {
public int getSelectionEnd() { return mLastSelectionEnd;
return mLastSelectionEnd; }
} @Override
@Override public int getComposingTextStart() {
public int getComposingTextStart() { return mLastCompositionStart;
return mLastCompositionStart; }
} @Override
@Override public int getComposingTextEnd() {
public int getComposingTextEnd() { return mLastCompositionEnd;
return mLastCompositionEnd; }
} });
});
} else {
mCursorAnchorInfoController = null;
}
mInputMethodManagerWrapper = wrapper; mInputMethodManagerWrapper = wrapper;
mNativeImeAdapterAndroid = ImeAdapterImplJni.get().init(ImeAdapterImpl.this, mWebContents); mNativeImeAdapterAndroid = ImeAdapterImplJni.get().init(ImeAdapterImpl.this, mWebContents);
WindowEventObserverManager.from(mWebContents).addObserver(this); WindowEventObserverManager.from(mWebContents).addObserver(this);
......
...@@ -190,11 +190,9 @@ public class InputMethodManagerWrapperImpl implements InputMethodManagerWrapper ...@@ -190,11 +190,9 @@ public class InputMethodManagerWrapperImpl implements InputMethodManagerWrapper
@Override @Override
public void updateCursorAnchorInfo(View view, CursorAnchorInfo cursorAnchorInfo) { public void updateCursorAnchorInfo(View view, CursorAnchorInfo cursorAnchorInfo) {
if (DEBUG_LOGS) Log.i(TAG, "updateCursorAnchorInfo"); if (DEBUG_LOGS) Log.i(TAG, "updateCursorAnchorInfo");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { InputMethodManager manager = getInputMethodManager();
InputMethodManager manager = getInputMethodManager(); if (manager == null) return;
if (manager == null) return; manager.updateCursorAnchorInfo(view, cursorAnchorInfo);
manager.updateCursorAnchorInfo(view, cursorAnchorInfo);
}
} }
@Override @Override
......
...@@ -7,10 +7,7 @@ package org.chromium.content.browser.input; ...@@ -7,10 +7,7 @@ package org.chromium.content.browser.input;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.text.SpannableString; import android.text.SpannableString;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.Gravity; import android.view.Gravity;
...@@ -42,9 +39,6 @@ public abstract class SuggestionsPopupWindow ...@@ -42,9 +39,6 @@ public abstract class SuggestionsPopupWindow
"com.android.settings.USER_DICTIONARY_INSERT"; "com.android.settings.USER_DICTIONARY_INSERT";
private static final String USER_DICTIONARY_EXTRA_WORD = "word"; private static final String USER_DICTIONARY_EXTRA_WORD = "word";
// From Android Settings app's @integer/maximum_user_dictionary_word_length.
private static final int ADD_TO_DICTIONARY_MAX_LENGTH_ON_JELLY_BEAN = 48;
private final Context mContext; private final Context mContext;
protected final TextSuggestionHost mTextSuggestionHost; protected final TextSuggestionHost mTextSuggestionHost;
private final View mParentView; private final View mParentView;
...@@ -118,22 +112,13 @@ public abstract class SuggestionsPopupWindow ...@@ -118,22 +112,13 @@ public abstract class SuggestionsPopupWindow
mPopupWindow = new PopupWindow(); mPopupWindow = new PopupWindow();
mPopupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); mPopupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
mPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); mPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // Set the background on the PopupWindow instead of on mContentView (where we set it for
// Set the background on the PopupWindow instead of on mContentView (where we set it for // pre-Lollipop) since the popup will not properly dismiss on pre-Marshmallow unless it
// pre-Lollipop) since the popup will not properly dismiss on pre-Marshmallow unless it // has a background set.
// has a background set. mPopupWindow.setBackgroundDrawable(ApiCompatibilityUtils.getDrawable(
mPopupWindow.setBackgroundDrawable(ApiCompatibilityUtils.getDrawable( mContext.getResources(), R.drawable.floating_popup_background_light));
mContext.getResources(), R.drawable.floating_popup_background_light)); mPopupWindow.setElevation(mContext.getResources().getDimensionPixelSize(
// On Lollipop and later, we use elevation to create a drop shadow effect. R.dimen.text_suggestion_popup_elevation));
// On pre-Lollipop, we instead use a background image on mContentView (in
// initContentView).
mPopupWindow.setElevation(mContext.getResources().getDimensionPixelSize(
R.dimen.text_suggestion_popup_elevation));
} else {
// The PopupWindow does not properly dismiss pre-Marshmallow unless it has a background
// set.
mPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
mPopupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED); mPopupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
mPopupWindow.setFocusable(true); mPopupWindow.setFocusable(true);
...@@ -147,13 +132,6 @@ public abstract class SuggestionsPopupWindow ...@@ -147,13 +132,6 @@ public abstract class SuggestionsPopupWindow
mContentView = mContentView =
(LinearLayout) inflater.inflate(R.layout.text_edit_suggestion_container, null); (LinearLayout) inflater.inflate(R.layout.text_edit_suggestion_container, null);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
// Set this on the content view instead of on the PopupWindow so we can retrieve the
// padding later.
mContentView.setBackground(ApiCompatibilityUtils.getDrawable(
mContext.getResources(), R.drawable.popup_bg));
}
// mPopupVerticalMargin is the minimum amount of space we want to have between the popup // mPopupVerticalMargin is the minimum amount of space we want to have between the popup
// and the top or bottom of the window. // and the top or bottom of the window.
mPopupVerticalMargin = mContext.getResources().getDimensionPixelSize( mPopupVerticalMargin = mContext.getResources().getDimensionPixelSize(
...@@ -206,20 +184,6 @@ public abstract class SuggestionsPopupWindow ...@@ -206,20 +184,6 @@ public abstract class SuggestionsPopupWindow
final Intent intent = new Intent(ACTION_USER_DICTIONARY_INSERT); final Intent intent = new Intent(ACTION_USER_DICTIONARY_INSERT);
String wordToAdd = mHighlightedText; String wordToAdd = mHighlightedText;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
// There was a bug in Jelly Bean, fixed in the initial version of KitKat, that can cause
// a crash if the word we try to add is too long. The "add to dictionary" intent uses an
// EditText widget to show the word about to be added (and allow the user to edit it).
// It has a maximum length of 48 characters. If a word is longer than this, it will be
// truncated, but the intent will try to select the full length of the word, causing a
// crash.
// KitKit and later still truncate the word, but avoid the crash.
if (wordToAdd.length() > ADD_TO_DICTIONARY_MAX_LENGTH_ON_JELLY_BEAN) {
wordToAdd = wordToAdd.substring(0, ADD_TO_DICTIONARY_MAX_LENGTH_ON_JELLY_BEAN);
}
}
intent.putExtra(USER_DICTIONARY_EXTRA_WORD, wordToAdd); intent.putExtra(USER_DICTIONARY_EXTRA_WORD, wordToAdd);
intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent); mContext.startActivity(intent);
......
...@@ -7,7 +7,6 @@ package org.chromium.content.browser.picker; ...@@ -7,7 +7,6 @@ package org.chromium.content.browser.picker;
import android.app.DatePickerDialog; import android.app.DatePickerDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Build;
import android.widget.DatePicker; import android.widget.DatePicker;
/** /**
...@@ -48,9 +47,7 @@ class DatePickerDialogCompat extends DatePickerDialog { ...@@ -48,9 +47,7 @@ class DatePickerDialogCompat extends DatePickerDialog {
// On Android L+, the dialog shouldn't have a title. This works around a bug in // On Android L+, the dialog shouldn't have a title. This works around a bug in
// DatePickerDialog where calling updateDate() before the dialog has been shown causes // DatePickerDialog where calling updateDate() before the dialog has been shown causes
// a title to appear. http://crbug.com/541350 // a title to appear. http://crbug.com/541350
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { title = "";
title = "";
}
super.setTitle(title); super.setTitle(title);
} }
} }
...@@ -76,7 +76,6 @@ import java.util.List; ...@@ -76,7 +76,6 @@ import java.util.List;
* Implementation of the interface {@link SelectionPopupController}. * Implementation of the interface {@link SelectionPopupController}.
*/ */
@JNINamespace("content") @JNINamespace("content")
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class SelectionPopupControllerImpl extends ActionModeCallbackHelper public class SelectionPopupControllerImpl extends ActionModeCallbackHelper
implements ImeEventObserver, SelectionPopupController, WindowEventObserver, HideablePopup, implements ImeEventObserver, SelectionPopupController, WindowEventObserver, HideablePopup,
ContainerViewObserver, UserData { ContainerViewObserver, UserData {
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
package org.chromium.content_public.browser; package org.chromium.content_public.browser;
import android.annotation.TargetApi;
import android.os.Build;
import android.os.IBinder; import android.os.IBinder;
import android.os.ResultReceiver; import android.os.ResultReceiver;
import android.view.View; import android.view.View;
...@@ -54,7 +52,6 @@ public interface InputMethodManagerWrapper { ...@@ -54,7 +52,6 @@ public interface InputMethodManagerWrapper {
* @see android.view.inputmethod.InputMethodManager#updateCursorAnchorInfo(View, * @see android.view.inputmethod.InputMethodManager#updateCursorAnchorInfo(View,
* CursorAnchorInfo) * CursorAnchorInfo)
*/ */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void updateCursorAnchorInfo(View view, CursorAnchorInfo cursorAnchorInfo); void updateCursorAnchorInfo(View view, CursorAnchorInfo cursorAnchorInfo);
/** /**
......
...@@ -128,8 +128,7 @@ public class VideoFullscreenOrientationLockTest { ...@@ -128,8 +128,7 @@ public class VideoFullscreenOrientationLockTest {
@Test @Test
@MediumTest @MediumTest
@DisableIf.Build(message = "crbug.com/837423", sdk_is_greater_than = Build.VERSION_CODES.KITKAT, @DisableIf.Build(message = "crbug.com/837423", sdk_is_less_than = Build.VERSION_CODES.M)
sdk_is_less_than = Build.VERSION_CODES.M)
@Restriction({UiRestriction.RESTRICTION_TYPE_PHONE}) @Restriction({UiRestriction.RESTRICTION_TYPE_PHONE})
public void testEnterExitFullscreenWithControlsButton() throws Exception { public void testEnterExitFullscreenWithControlsButton() throws Exception {
// Start playback to guarantee it's properly loaded. // Start playback to guarantee it's properly loaded.
......
...@@ -356,8 +356,6 @@ public class WebContentsAccessibilityTest { ...@@ -356,8 +356,6 @@ public class WebContentsAccessibilityTest {
*/ */
@Test @Test
@MediumTest @MediumTest
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP)
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void testEventIndices_SelectionOFF_CharacterGranularity() throws Throwable { public void testEventIndices_SelectionOFF_CharacterGranularity() throws Throwable {
// Build a simple web page with an input and the text "Testing" // Build a simple web page with an input and the text "Testing"
int editTextVirtualViewId = buildWebPageWithEditText( int editTextVirtualViewId = buildWebPageWithEditText(
...@@ -403,8 +401,6 @@ public class WebContentsAccessibilityTest { ...@@ -403,8 +401,6 @@ public class WebContentsAccessibilityTest {
@Test @Test
@LargeTest @LargeTest
@Ignore("Skipping due to long run time") @Ignore("Skipping due to long run time")
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP)
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void testEventIndices_SelectionON_CharacterGranularity() throws Throwable { public void testEventIndices_SelectionON_CharacterGranularity() throws Throwable {
// Build a simple web page with an input and the text "Testing" // Build a simple web page with an input and the text "Testing"
int editTextVirtualViewId = buildWebPageWithEditText( int editTextVirtualViewId = buildWebPageWithEditText(
...@@ -505,8 +501,6 @@ public class WebContentsAccessibilityTest { ...@@ -505,8 +501,6 @@ public class WebContentsAccessibilityTest {
*/ */
@Test @Test
@MediumTest @MediumTest
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP)
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void testEventIndices_SelectionOFF_WordGranularity() throws Throwable { public void testEventIndices_SelectionOFF_WordGranularity() throws Throwable {
// Build a simple web page with an input and the text "Testing this output is correct" // Build a simple web page with an input and the text "Testing this output is correct"
int editTextVirtualViewId = buildWebPageWithEditText( int editTextVirtualViewId = buildWebPageWithEditText(
...@@ -556,8 +550,6 @@ public class WebContentsAccessibilityTest { ...@@ -556,8 +550,6 @@ public class WebContentsAccessibilityTest {
@Test @Test
@LargeTest @LargeTest
@Ignore("Skipping due to long run time") @Ignore("Skipping due to long run time")
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP)
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void testEventIndices_SelectionON_WordGranularity() throws Throwable { public void testEventIndices_SelectionON_WordGranularity() throws Throwable {
// Build a simple web page with an input and the text "Testing this output is correct" // Build a simple web page with an input and the text "Testing this output is correct"
int editTextVirtualViewId = buildWebPageWithEditText( int editTextVirtualViewId = buildWebPageWithEditText(
...@@ -663,8 +655,6 @@ public class WebContentsAccessibilityTest { ...@@ -663,8 +655,6 @@ public class WebContentsAccessibilityTest {
@Test @Test
@LargeTest @LargeTest
@Ignore("Skipping due to long run time") @Ignore("Skipping due to long run time")
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP)
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void testEventIndices_contenteditable_SelectionON_CharacterGranularity() public void testEventIndices_contenteditable_SelectionON_CharacterGranularity()
throws Throwable { throws Throwable {
int contentEditableVirtualViewId = int contentEditableVirtualViewId =
...@@ -773,8 +763,6 @@ public class WebContentsAccessibilityTest { ...@@ -773,8 +763,6 @@ public class WebContentsAccessibilityTest {
*/ */
@Test @Test
@MediumTest @MediumTest
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP)
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void testTextFieldExposesActionSetText() { public void testTextFieldExposesActionSetText() {
// Load a web page with a text field. // Load a web page with a text field.
final String data = "<h1>Simple test page</h1>" final String data = "<h1>Simple test page</h1>"
...@@ -797,8 +785,6 @@ public class WebContentsAccessibilityTest { ...@@ -797,8 +785,6 @@ public class WebContentsAccessibilityTest {
**/ **/
@Test @Test
@MediumTest @MediumTest
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP)
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void testContentEditableClassName() { public void testContentEditableClassName() {
final String data = "<div contenteditable>Edit This</div>"; final String data = "<div contenteditable>Edit This</div>";
...@@ -819,8 +805,6 @@ public class WebContentsAccessibilityTest { ...@@ -819,8 +805,6 @@ public class WebContentsAccessibilityTest {
**/ **/
@Test @Test
@MediumTest @MediumTest
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP)
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void testEditTextFieldAriaInvalidTrueErrorMessage() { public void testEditTextFieldAriaInvalidTrueErrorMessage() {
final String data = "<form>\n" final String data = "<form>\n"
+ " First name:<br>\n" + " First name:<br>\n"
...@@ -844,8 +828,6 @@ public class WebContentsAccessibilityTest { ...@@ -844,8 +828,6 @@ public class WebContentsAccessibilityTest {
**/ **/
@Test @Test
@MediumTest @MediumTest
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP)
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void testEditTextFieldAriaInvalidSpellingErrorMessage() { public void testEditTextFieldAriaInvalidSpellingErrorMessage() {
final String data = "<input type='text' aria-invalid='spelling'><br>\n"; final String data = "<input type='text' aria-invalid='spelling'><br>\n";
...@@ -866,8 +848,6 @@ public class WebContentsAccessibilityTest { ...@@ -866,8 +848,6 @@ public class WebContentsAccessibilityTest {
**/ **/
@Test @Test
@MediumTest @MediumTest
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP)
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void testEditTextFieldAriaInvalidGrammarErrorMessage() { public void testEditTextFieldAriaInvalidGrammarErrorMessage() {
final String data = "<input type='text' aria-invalid='grammar'><br>\n"; final String data = "<input type='text' aria-invalid='grammar'><br>\n";
...@@ -887,8 +867,6 @@ public class WebContentsAccessibilityTest { ...@@ -887,8 +867,6 @@ public class WebContentsAccessibilityTest {
**/ **/
@Test @Test
@MediumTest @MediumTest
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP)
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void testEditTextFieldValidNoErrorMessage() { public void testEditTextFieldValidNoErrorMessage() {
final String data = "<input type='text'><br>\n"; final String data = "<input type='text'><br>\n";
mActivityTestRule.launchContentShellWithUrl(UrlUtils.encodeHtmlDataUri(data)); mActivityTestRule.launchContentShellWithUrl(UrlUtils.encodeHtmlDataUri(data));
...@@ -908,8 +886,6 @@ public class WebContentsAccessibilityTest { ...@@ -908,8 +886,6 @@ public class WebContentsAccessibilityTest {
**/ **/
@Test @Test
@MediumTest @MediumTest
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP)
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void testSpellingError() { public void testSpellingError() {
// Load a web page containing a text field with one misspelling. // Load a web page containing a text field with one misspelling.
// Note that for content_shell, no spelling suggestions are enabled // Note that for content_shell, no spelling suggestions are enabled
......
...@@ -4,10 +4,8 @@ ...@@ -4,10 +4,8 @@
package org.chromium.content.browser.input; package org.chromium.content.browser.input;
import android.annotation.TargetApi;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.graphics.RectF; import android.graphics.RectF;
import android.os.Build;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.View; import android.view.View;
import android.view.inputmethod.CursorAnchorInfo; import android.view.inputmethod.CursorAnchorInfo;
...@@ -19,7 +17,6 @@ import org.junit.Test; ...@@ -19,7 +17,6 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.MinAndroidSdkLevel;
import org.chromium.content_public.browser.test.ContentJUnit4ClassRunner; import org.chromium.content_public.browser.test.ContentJUnit4ClassRunner;
import org.chromium.content_public.browser.test.util.TestInputMethodManagerWrapper; import org.chromium.content_public.browser.test.util.TestInputMethodManagerWrapper;
...@@ -27,8 +24,6 @@ import org.chromium.content_public.browser.test.util.TestInputMethodManagerWrapp ...@@ -27,8 +24,6 @@ import org.chromium.content_public.browser.test.util.TestInputMethodManagerWrapp
* Test for {@link CursorAnchorInfoController}. * Test for {@link CursorAnchorInfoController}.
*/ */
@RunWith(ContentJUnit4ClassRunner.class) @RunWith(ContentJUnit4ClassRunner.class)
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP)
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class CursorAnchorInfoControllerTest { public class CursorAnchorInfoControllerTest {
private static final class TestViewDelegate implements CursorAnchorInfoController.ViewDelegate { private static final class TestViewDelegate implements CursorAnchorInfoController.ViewDelegate {
public int locationX; public int locationX;
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
package org.chromium.content.browser.input; package org.chromium.content.browser.input;
import android.annotation.TargetApi;
import android.os.Build;
import android.view.inputmethod.CursorAnchorInfo; import android.view.inputmethod.CursorAnchorInfo;
import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputConnection;
...@@ -19,7 +17,6 @@ import org.junit.Test; ...@@ -19,7 +17,6 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.MinAndroidSdkLevel;
import org.chromium.content_public.browser.test.ContentJUnit4ClassRunner; import org.chromium.content_public.browser.test.ContentJUnit4ClassRunner;
import org.chromium.content_public.browser.test.util.Criteria; import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper; import org.chromium.content_public.browser.test.util.CriteriaHelper;
...@@ -31,8 +28,6 @@ import java.util.concurrent.Callable; ...@@ -31,8 +28,6 @@ import java.util.concurrent.Callable;
* Integration tests for text input for Android L (or above) features. * Integration tests for text input for Android L (or above) features.
*/ */
@RunWith(ContentJUnit4ClassRunner.class) @RunWith(ContentJUnit4ClassRunner.class)
@MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP)
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class ImeLollipopTest { public class ImeLollipopTest {
@Rule @Rule
public ImeActivityTestRule mRule = new ImeActivityTestRule(); public ImeActivityTestRule mRule = new ImeActivityTestRule();
......
...@@ -4,12 +4,10 @@ ...@@ -4,12 +4,10 @@
package org.chromium.content_shell_apk; package org.chromium.content_shell_apk;
import android.annotation.TargetApi;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.PowerManager; import android.os.PowerManager;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule; import android.support.test.rule.ActivityTestRule;
...@@ -72,17 +70,12 @@ public class ContentShellActivityTestRule extends ActivityTestRule<ContentShellA ...@@ -72,17 +70,12 @@ public class ContentShellActivityTestRule extends ActivityTestRule<ContentShellA
} }
@Override @Override
@TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
protected void beforeActivityLaunched() { protected void beforeActivityLaunched() {
PowerManager pm = (PowerManager) InstrumentationRegistry.getInstrumentation() PowerManager pm = (PowerManager) InstrumentationRegistry.getInstrumentation()
.getContext() .getContext()
.getSystemService(Context.POWER_SERVICE); .getSystemService(Context.POWER_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { Assert.assertTrue("Many tests will fail if the screen is not on.", pm.isInteractive());
Assert.assertTrue("Many tests will fail if the screen is not on.", pm.isInteractive());
} else {
Assert.assertTrue("Many tests will fail if the screen is not on.", pm.isScreenOn());
}
} }
/** /**
......
...@@ -4,9 +4,7 @@ ...@@ -4,9 +4,7 @@
package org.chromium.content_shell_apk; package org.chromium.content_shell_apk;
import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.os.Build;
import android.os.PowerManager; import android.os.PowerManager;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
...@@ -25,7 +23,6 @@ import org.chromium.base.test.util.Feature; ...@@ -25,7 +23,6 @@ import org.chromium.base.test.util.Feature;
@RunWith(BaseJUnit4ClassRunner.class) @RunWith(BaseJUnit4ClassRunner.class)
public class ContentShellPreconditionsTest { public class ContentShellPreconditionsTest {
@Test @Test
@TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@MediumTest @MediumTest
@Feature({"TestInfrastructure"}) @Feature({"TestInfrastructure"})
...@@ -33,10 +30,6 @@ public class ContentShellPreconditionsTest { ...@@ -33,10 +30,6 @@ public class ContentShellPreconditionsTest {
PowerManager pm = (PowerManager) InstrumentationRegistry.getContext().getSystemService( PowerManager pm = (PowerManager) InstrumentationRegistry.getContext().getSystemService(
Context.POWER_SERVICE); Context.POWER_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { Assert.assertTrue("Many tests will fail if the screen is not on.", pm.isInteractive());
Assert.assertTrue("Many tests will fail if the screen is not on.", pm.isInteractive());
} else {
Assert.assertTrue("Many tests will fail if the screen is not on.", pm.isScreenOn());
}
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment