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

Unified Diff: content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java

Issue 385963002: [Android] Support SPen events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: renamed eventAction as eventActionMasked Created 6 years, 5 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
index 45f6f8719ee76dd9984c0f4e0de72f83d035b204..67cc7a46813ab11ab90b49bf9243727998ce8010 100644
--- a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
+++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
@@ -10,6 +10,7 @@ import android.app.SearchManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.FeatureInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.database.ContentObserver;
@@ -111,6 +112,13 @@ public class ContentViewCore
// Length of the delay (in ms) before fading in handles after the last page movement.
private static final int TEXT_HANDLE_FADE_IN_DELAY = 300;
+ // These values are empirically obtained.
+ private static final int SPEN_ACTION_DOWN = 11;
+ private static final int SPEN_ACTION_UP = 12;
+ private static final int SPEN_ACTION_MOVE = 13;
+ private static final int SPEN_ACTION_CANCEL = 14;
+ private static Boolean sIsSPenSupported;
+
// If the embedder adds a JavaScript interface object that contains an indirect reference to
// the ContentViewCore, then storing a strong ref to the interface object on the native
// side would prevent garbage collection of the ContentViewCore (as that strong ref would
@@ -1122,6 +1130,41 @@ public class ContentViewCore
// End FrameLayout overrides.
+ private static boolean isSPenSupported(Context context) {
+ if (sIsSPenSupported == null)
+ sIsSPenSupported = detectSPenSupport(context);
+ return sIsSPenSupported.booleanValue();
+ }
+
+ private static boolean detectSPenSupport(Context context) {
+ if (!"SAMSUNG".equalsIgnoreCase(Build.MANUFACTURER))
+ return false;
+
+ final FeatureInfo[] infos = context.getPackageManager().getSystemAvailableFeatures();
+ for (FeatureInfo info : infos) {
+ if ("com.sec.feature.spen_usp".equalsIgnoreCase(info.name)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static int convertSPenEventAction(int eventActionMasked) {
+ // S-Pen support: convert to normal stylus event handling
+ switch (eventActionMasked) {
+ case SPEN_ACTION_DOWN:
+ return MotionEvent.ACTION_DOWN;
+ case SPEN_ACTION_UP:
+ return MotionEvent.ACTION_UP;
+ case SPEN_ACTION_MOVE:
+ return MotionEvent.ACTION_MOVE;
+ case SPEN_ACTION_CANCEL:
+ return MotionEvent.ACTION_CANCEL;
+ default:
+ return eventActionMasked;
+ }
+ }
+
/**
* @see View#onTouchEvent(MotionEvent)
*/
@@ -1130,7 +1173,10 @@ public class ContentViewCore
try {
cancelRequestToScrollFocusedEditableNodeIntoView();
- final int eventAction = event.getActionMasked();
+ int eventAction = event.getActionMasked();
+
+ if (isSPenSupported(mContext))
+ eventAction = convertSPenEventAction(eventAction);
// Only these actions have any effect on gesture detection. Other
// actions have no corresponding WebTouchEvent type and may confuse the
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698