diff options
20 files changed, 5 insertions, 897 deletions
diff --git a/android_webview/Android.mk b/android_webview/Android.mk index 525fb84..dd9e13b 100644 --- a/android_webview/Android.mk +++ b/android_webview/Android.mk @@ -61,8 +61,6 @@ $(call intermediates-dir-for,GYP,shared,,,$(TARGET_2ND_ARCH))/templates/org/chro $(call intermediates-dir-for,GYP,shared,,,$(TARGET_2ND_ARCH))/templates/org/chromium/content/browser/GestureEventType.java \ $(call intermediates-dir-for,GYP,shared,,,$(TARGET_2ND_ARCH))/templates/org/chromium/content/browser/PageTransitionTypes.java \ $(call intermediates-dir-for,GYP,shared,,,$(TARGET_2ND_ARCH))/templates/org/chromium/content/browser/SpeechRecognitionError.java \ -$(call intermediates-dir-for,GYP,shared,,,$(TARGET_2ND_ARCH))/templates/org/chromium/content/browser/input/CanonicalAxisIndex.java \ -$(call intermediates-dir-for,GYP,shared,,,$(TARGET_2ND_ARCH))/templates/org/chromium/content/browser/input/CanonicalButtonIndex.java \ $(call intermediates-dir-for,GYP,shared,,,$(TARGET_2ND_ARCH))/templates/org/chromium/content/browser/input/PopupItemType.java \ $(call intermediates-dir-for,GYP,shared,,,$(TARGET_2ND_ARCH))/templates/org/chromium/content/common/ResultCodes.java \ $(call intermediates-dir-for,GYP,shared,,,$(TARGET_2ND_ARCH))/templates/org/chromium/content/common/ScreenOrientationValues.java \ diff --git a/android_webview/android_webview.gyp b/android_webview/android_webview.gyp index e2455f3..420cd76 100644 --- a/android_webview/android_webview.gyp +++ b/android_webview/android_webview.gyp @@ -26,7 +26,6 @@ 'dependencies': [ '../base/base.gyp:base_java_application_state', '../base/base.gyp:base_java_memory_pressure_level_list', - '../content/content.gyp:content_gamepad_mapping', '../content/content.gyp:gesture_event_type_java', '../content/content.gyp:page_transition_types_java', '../content/content.gyp:popup_item_type_java', diff --git a/base/android/jni_generator/jni_generator.py b/base/android/jni_generator/jni_generator.py index 81bcfbb..7a6a163 100755 --- a/base/android/jni_generator/jni_generator.py +++ b/base/android/jni_generator/jni_generator.py @@ -402,7 +402,6 @@ def GetStaticCastForReturnType(return_type): 'short[]': 'jshortArray', 'int[]': 'jintArray', 'long[]': 'jlongArray', - 'float[]': 'jfloatArray', 'double[]': 'jdoubleArray' } ret = type_map.get(return_type, None) if ret: diff --git a/content/browser/android/browser_jni_registrar.cc b/content/browser/android/browser_jni_registrar.cc index 47ff5d1..3431479 100644 --- a/content/browser/android/browser_jni_registrar.cc +++ b/content/browser/android/browser_jni_registrar.cc @@ -26,7 +26,6 @@ #include "content/browser/battery_status/battery_status_manager.h" #include "content/browser/device_sensors/sensor_manager_android.h" #include "content/browser/frame_host/navigation_controller_android.h" -#include "content/browser/gamepad/gamepad_platform_data_fetcher_android.h" #include "content/browser/geolocation/location_api_adapter_android.h" #include "content/browser/media/android/media_drm_credential_manager.h" #include "content/browser/media/android/media_resource_getter_impl.h" @@ -63,8 +62,6 @@ base::android::RegistrationMethod kContentRegisteredMethods[] = { {"DateTimePickerAndroid", content::RegisterDateTimeChooserAndroid}, {"DownloadControllerAndroidImpl", content::DownloadControllerAndroidImpl::RegisterDownloadController}, - {"GamepadList", content::GamepadPlatformDataFetcherAndroid:: - RegisterGamepadPlatformDataFetcherAndroid}, {"InterstitialPageDelegateAndroid", content::InterstitialPageDelegateAndroid:: RegisterInterstitialPageDelegateAndroid}, diff --git a/content/browser/gamepad/canonical_axis_index_list.h b/content/browser/gamepad/canonical_axis_index_list.h deleted file mode 100644 index 58b85a6..0000000 --- a/content/browser/gamepad/canonical_axis_index_list.h +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2014 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. - -// This file intentionally does not have header guards, it's included -// inside a macro to generate enum values. - -// This file defines the canonical axes mapping order for gamepad-like devices. - -// TODO(SaurabhK): Consolidate with CanonicalAxisIndex enum in -// gamepad_standard_mappings.h, crbug.com/351558. -CANONICAL_AXIS_INDEX(AXIS_LEFT_STICK_X, 0) -CANONICAL_AXIS_INDEX(AXIS_LEFT_STICK_Y, 1) -CANONICAL_AXIS_INDEX(AXIS_RIGHT_STICK_X, 2) -CANONICAL_AXIS_INDEX(AXIS_RIGHT_STICK_Y, 3) -CANONICAL_AXIS_INDEX(NUM_CANONICAL_AXES, 4) diff --git a/content/browser/gamepad/canonical_button_index_list.h b/content/browser/gamepad/canonical_button_index_list.h deleted file mode 100644 index 153ce0e..0000000 --- a/content/browser/gamepad/canonical_button_index_list.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2014 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. - -// This file intentionally does not have header guards, it's included -// inside a macro to generate enum values. -// This defines the canonical button mapping order for gamepad-like devices. - -// TODO(SaurabhK): Consolidate with CanonicalButtonIndex enum in -// gamepad_standard_mappings.h, crbug.com/351558. -CANONICAL_BUTTON_INDEX(BUTTON_PRIMARY, 0) -CANONICAL_BUTTON_INDEX(BUTTON_SECONDARY, 1) -CANONICAL_BUTTON_INDEX(BUTTON_TERTIARY, 2) -CANONICAL_BUTTON_INDEX(BUTTON_QUATERNARY, 3) -CANONICAL_BUTTON_INDEX(BUTTON_LEFT_SHOULDER, 4) -CANONICAL_BUTTON_INDEX(BUTTON_RIGHT_SHOULDER, 5) -CANONICAL_BUTTON_INDEX(BUTTON_LEFT_TRIGGER, 6) -CANONICAL_BUTTON_INDEX(BUTTON_RIGHT_TRIGGER, 7) -CANONICAL_BUTTON_INDEX(BUTTON_BACK_SELECT, 8) -CANONICAL_BUTTON_INDEX(BUTTON_START, 9) -CANONICAL_BUTTON_INDEX(BUTTON_LEFT_THUMBSTICK, 10) -CANONICAL_BUTTON_INDEX(BUTTON_RIGHT_THUMBSTICK, 11) -CANONICAL_BUTTON_INDEX(BUTTON_DPAD_UP, 12) -CANONICAL_BUTTON_INDEX(BUTTON_DPAD_DOWN, 13) -CANONICAL_BUTTON_INDEX(BUTTON_DPAD_LEFT, 14) -CANONICAL_BUTTON_INDEX(BUTTON_DPAD_RIGHT, 15) -CANONICAL_BUTTON_INDEX(BUTTON_META, 16) -CANONICAL_BUTTON_INDEX(NUM_CANONICAL_BUTTONS, 17)
\ No newline at end of file diff --git a/content/browser/gamepad/gamepad_platform_data_fetcher.h b/content/browser/gamepad/gamepad_platform_data_fetcher.h index f3cf7cc..24730629 100644 --- a/content/browser/gamepad/gamepad_platform_data_fetcher.h +++ b/content/browser/gamepad/gamepad_platform_data_fetcher.h @@ -12,9 +12,7 @@ #include "base/compiler_specific.h" #include "content/browser/gamepad/gamepad_data_fetcher.h" -#if defined(OS_ANDROID) -#include "content/browser/gamepad/gamepad_platform_data_fetcher_android.h" -#elif defined(OS_WIN) +#if defined(OS_WIN) #include "content/browser/gamepad/gamepad_platform_data_fetcher_win.h" #elif defined(OS_MACOSX) #include "content/browser/gamepad/gamepad_platform_data_fetcher_mac.h" @@ -24,11 +22,7 @@ namespace content { -#if defined(OS_ANDROID) - -typedef GamepadPlatformDataFetcherAndroid GamepadPlatformDataFetcher; - -#elif defined(OS_WIN) +#if defined(OS_WIN) typedef GamepadPlatformDataFetcherWin GamepadPlatformDataFetcher; diff --git a/content/browser/gamepad/gamepad_platform_data_fetcher_android.cc b/content/browser/gamepad/gamepad_platform_data_fetcher_android.cc deleted file mode 100644 index 703b12e..0000000 --- a/content/browser/gamepad/gamepad_platform_data_fetcher_android.cc +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright 2014 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. - -#include "content/browser/gamepad/gamepad_platform_data_fetcher_android.h" - -#include "base/android/jni_android.h" -#include "base/android/jni_array.h" -#include "base/android/jni_string.h" -#include "base/debug/trace_event.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" - -#include "jni/GamepadList_jni.h" - -#include "third_party/WebKit/public/platform/WebGamepads.h" - -using base::android::AttachCurrentThread; -using base::android::CheckException; -using base::android::ClearException; -using base::android::ConvertJavaStringToUTF8; -using base::android::ScopedJavaLocalRef; -using blink::WebGamepad; -using blink::WebGamepads; - -namespace content { - -bool -GamepadPlatformDataFetcherAndroid::RegisterGamepadPlatformDataFetcherAndroid( - JNIEnv* env) { - return RegisterNativesImpl(env); -} - -GamepadPlatformDataFetcherAndroid::GamepadPlatformDataFetcherAndroid() { - PauseHint(false); -} - -GamepadPlatformDataFetcherAndroid::~GamepadPlatformDataFetcherAndroid() { - PauseHint(true); -} - -void GamepadPlatformDataFetcherAndroid::GetGamepadData( - blink::WebGamepads* pads, - bool devices_changed_hint) { - TRACE_EVENT0("GAMEPAD", "GetGamepadData"); - - pads->length = 0; - - JNIEnv* env = AttachCurrentThread(); - if (!env) - return; - - Java_GamepadList_updateGamepadData(env, reinterpret_cast<intptr_t>(pads)); -} - -void GamepadPlatformDataFetcherAndroid::PauseHint(bool paused) { - JNIEnv* env = AttachCurrentThread(); - if (!env) - return; - - Java_GamepadList_notifyForGamepadsAccess(env, paused); -} - -static void SetGamepadData(JNIEnv* env, - jobject obj, - jlong gamepads, - jint index, - jboolean mapping, - jboolean connected, - jstring devicename, - jlong timestamp, - jfloatArray jaxes, - jfloatArray jbuttons) { - DCHECK(gamepads); - blink::WebGamepads* pads = reinterpret_cast<WebGamepads*>(gamepads); - DCHECK_EQ(pads->length, unsigned(index)); - DCHECK_LT(index, static_cast<int>(blink::WebGamepads::itemsLengthCap)); - - ++pads->length; - - blink::WebGamepad& pad = pads->items[index]; - - pad.connected = connected; - - pad.timestamp = timestamp; - - // Do not set gamepad parameters for all the gamepad devices that are not - // attached. - if (!connected) - return; - - // Map the Gamepad DeviceName String to the WebGamepad Id. Ideally it should - // be mapped to vendor and product information but it is only available at - // kernel level and it can not be queried using class - // android.hardware.input.InputManager. - // TODO(SaurabhK): Store a cached WebGamePad object in - // GamepadPlatformDataFetcherAndroid and only update constant WebGamepad - // values when a device has changed. - base::string16 device_name; - base::android::ConvertJavaStringToUTF16(env, devicename, &device_name); - const size_t name_to_copy = - std::min(device_name.size(), WebGamepad::idLengthCap - 1); - memcpy(pad.id, - device_name.data(), - name_to_copy * sizeof(base::string16::value_type)); - pad.id[name_to_copy] = 0; - - base::string16 mapping_name = base::UTF8ToUTF16(mapping ? "standard" : ""); - const size_t mapping_to_copy = - std::min(mapping_name.size(), WebGamepad::mappingLengthCap - 1); - memcpy(pad.mapping, - mapping_name.data(), - mapping_to_copy * sizeof(base::string16::value_type)); - pad.mapping[mapping_to_copy] = 0; - - pad.timestamp = timestamp; - - std::vector<float> axes; - base::android::JavaFloatArrayToFloatVector(env, jaxes, &axes); - - // Set WebGamepad axeslength to total number of axes on the gamepad device. - // Only return the first axesLengthCap if axeslength captured by GamepadList - // is larger than axesLengthCap. - pad.axesLength = std::min(static_cast<int>(axes.size()), - static_cast<int>(WebGamepad::axesLengthCap)); - - memcpy(pad.axes, axes.begin(), pad.axesLength * sizeof(float)); - - std::vector<float> buttons; - base::android::JavaFloatArrayToFloatVector(env, jbuttons, &buttons); - - // Set WebGamepad buttonslength to total number of axes on the gamepad - // device. Only return the first buttonsLengthCap if axeslength captured by - // GamepadList is larger than buttonsLengthCap. - pad.buttonsLength = std::min(static_cast<int>(buttons.size()), - static_cast<int>(WebGamepad::buttonsLengthCap)); - - // Copy buttons state to the WebGamepad buttons[]. - for (unsigned int j = 0; j < pad.buttonsLength; j++) { - pad.buttons[j].pressed = buttons[j]; - pad.buttons[j].value = buttons[j]; - } -} - -} // namespace content diff --git a/content/browser/gamepad/gamepad_platform_data_fetcher_android.h b/content/browser/gamepad/gamepad_platform_data_fetcher_android.h deleted file mode 100644 index bbbdc1f..0000000 --- a/content/browser/gamepad/gamepad_platform_data_fetcher_android.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2014 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. - -// Define the data fetcher that GamepadProvider will use for android port. -// (GamepadPlatformDataFetcher). - -#ifndef CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_ANDROID_H_ -#define CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_ANDROID_H_ - -#include <jni.h> - -#include "base/android/jni_android.h" -#include "content/browser/gamepad/gamepad_data_fetcher.h" -#include "content/browser/gamepad/gamepad_provider.h" -#include "content/browser/gamepad/gamepad_standard_mappings.h" -#include "third_party/WebKit/public/platform/WebGamepads.h" - -namespace content { - -class GamepadPlatformDataFetcherAndroid : public GamepadDataFetcher { - public: - GamepadPlatformDataFetcherAndroid(); - virtual ~GamepadPlatformDataFetcherAndroid(); - - virtual void PauseHint(bool paused) OVERRIDE; - - virtual void GetGamepadData(blink::WebGamepads* pads, - bool devices_changed_hint) OVERRIDE; - - // Registers the JNI methods for GamepadsReader. - static bool RegisterGamepadPlatformDataFetcherAndroid(JNIEnv* env); - - private: - DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherAndroid); -}; - -} // namespace content - -#endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_ANDROID_H_ diff --git a/content/browser/gamepad/gamepad_provider.cc b/content/browser/gamepad/gamepad_provider.cc index 16976d9..8e7644e 100644 --- a/content/browser/gamepad/gamepad_provider.cc +++ b/content/browser/gamepad/gamepad_provider.cc @@ -131,10 +131,6 @@ void GamepadProvider::Initialize(scoped_ptr<GamepadDataFetcher> fetcher) { // On Linux, the data fetcher needs to watch file descriptors, so the message // loop needs to be a libevent loop. const base::MessageLoop::Type kMessageLoopType = base::MessageLoop::TYPE_IO; -#elif defined(OS_ANDROID) - // On Android, keeping a message loop of default type. - const base::MessageLoop::Type kMessageLoopType = - base::MessageLoop::TYPE_DEFAULT; #else // On Mac, the data fetcher uses IOKit which depends on CFRunLoop, so the // message loop needs to be a UI-type loop. On Windows it must be a UI loop diff --git a/content/child/runtime_features.cc b/content/child/runtime_features.cc index 7a2d8fda..e39345c9 100644 --- a/content/child/runtime_features.cc +++ b/content/child/runtime_features.cc @@ -33,6 +33,8 @@ static void SetRuntimeFeatureDefaultsForPlatform() { media::MediaCodecBridge::IsAvailable() && ((android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM) || (android_getCpuFamily() == ANDROID_CPU_FAMILY_X86))); + // Android does not support the Gamepad API. + WebRuntimeFeatures::enableGamepad(false); // Android does not have support for PagePopup WebRuntimeFeatures::enablePagePopup(false); // Android does not yet support the Web Notification API. crbug.com/115320 diff --git a/content/content.gyp b/content/content.gyp index 96daa44..d7b3324 100644 --- a/content/content.gyp +++ b/content/content.gyp @@ -384,7 +384,6 @@ 'common_aidl', 'content_common', 'content_strings_grd', - 'content_gamepad_mapping', 'gesture_event_type_java', 'page_transition_types_java', 'popup_item_type_java', @@ -546,22 +545,6 @@ }], ], }, - { - 'target_name': 'content_gamepad_mapping', - 'type': 'none', - 'sources': [ - 'public/android/java/src/org/chromium/content/browser/input/CanonicalButtonIndex.template', - 'public/android/java/src/org/chromium/content/browser/input/CanonicalAxisIndex.template', - ], - 'variables': { - 'package_name': 'org/chromium/content/browser/input', - 'template_deps': [ - 'browser/gamepad/canonical_axis_index_list.h', - 'browser/gamepad/canonical_button_index_list.h', - ], - }, - 'includes': [ '../build/android/java_cpp_template.gypi' ], - }, ], }], # OS == "android" ], diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 1b1357c..ad1a5e3 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -583,8 +583,6 @@ 'browser/gamepad/gamepad_consumer.h', 'browser/gamepad/gamepad_data_fetcher.h', 'browser/gamepad/gamepad_platform_data_fetcher.h', - 'browser/gamepad/gamepad_platform_data_fetcher_android.cc', - 'browser/gamepad/gamepad_platform_data_fetcher_android.h', 'browser/gamepad/gamepad_platform_data_fetcher_linux.cc', 'browser/gamepad/gamepad_platform_data_fetcher_linux.h', 'browser/gamepad/gamepad_platform_data_fetcher_mac.h', @@ -1406,7 +1404,7 @@ 'browser/power_profiler/power_data_provider_dummy.cc' ] }], - ['OS!="win" and OS!="mac" and OS!="android" and (OS!="linux" or use_udev==0)', { + ['OS!="win" and OS!="mac" and (OS!="linux" or use_udev==0)', { 'sources': [ 'browser/gamepad/gamepad_platform_data_fetcher.cc', ] diff --git a/content/content_jni.gypi b/content/content_jni.gypi index 42699aa..fb1f776 100644 --- a/content/content_jni.gypi +++ b/content/content_jni.gypi @@ -22,7 +22,6 @@ 'public/android/java/src/org/chromium/content/browser/ContentViewStatics.java', 'public/android/java/src/org/chromium/content/browser/DeviceSensors.java', 'public/android/java/src/org/chromium/content/browser/DownloadController.java', - 'public/android/java/src/org/chromium/content/browser/input/GamepadList.java', 'public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java', 'public/android/java/src/org/chromium/content/browser/input/DateTimeChooserAndroid.java', 'public/android/java/src/org/chromium/content/browser/InterstitialPageDelegateAndroid.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 1324222..272c8cf 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 @@ -59,7 +59,6 @@ import org.chromium.content.browser.ScreenOrientationListener.ScreenOrientationO import org.chromium.content.browser.accessibility.AccessibilityInjector; import org.chromium.content.browser.accessibility.BrowserAccessibilityManager; import org.chromium.content.browser.input.AdapterInputConnection; -import org.chromium.content.browser.input.GamepadList; import org.chromium.content.browser.input.HandleView; import org.chromium.content.browser.input.ImeAdapter; import org.chromium.content.browser.input.ImeAdapter.AdapterInputConnectionFactory; @@ -1386,7 +1385,6 @@ public class ContentViewCore setAccessibilityState(mAccessibilityManager.isEnabled()); ScreenOrientationListener.getInstance().addObserver(this, mContext); - GamepadList.onAttachedToWindow(mContext); } /** @@ -1401,7 +1399,6 @@ public class ContentViewCore unregisterAccessibilityContentObserver(); ScreenOrientationListener.getInstance().removeObserver(this); - GamepadList.onDetachedFromWindow(); } /** @@ -1594,7 +1591,6 @@ public class ContentViewCore * @see View#dispatchKeyEvent(KeyEvent) */ public boolean dispatchKeyEvent(KeyEvent event) { - if (GamepadList.dispatchKeyEvent(event)) return true; if (getContentViewClient().shouldOverrideKeyEvent(event)) { return mContainerViewInternals.super_dispatchKeyEvent(event); } @@ -1640,7 +1636,6 @@ public class ContentViewCore * @see View#onGenericMotionEvent(MotionEvent) */ public boolean onGenericMotionEvent(MotionEvent event) { - if (GamepadList.onGenericMotionEvent(event)) return true; if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { switch (event.getAction()) { case MotionEvent.ACTION_SCROLL: diff --git a/content/public/android/java/src/org/chromium/content/browser/input/CanonicalAxisIndex.template b/content/public/android/java/src/org/chromium/content/browser/input/CanonicalAxisIndex.template deleted file mode 100644 index 8152056..0000000 --- a/content/public/android/java/src/org/chromium/content/browser/input/CanonicalAxisIndex.template +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2014 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.input; - -public class CanonicalAxisIndex { -#define CANONICAL_AXIS_INDEX(name, value) public static final int name = value; -#include "content/browser/gamepad/canonical_axis_index_list.h" -}
\ No newline at end of file diff --git a/content/public/android/java/src/org/chromium/content/browser/input/CanonicalButtonIndex.template b/content/public/android/java/src/org/chromium/content/browser/input/CanonicalButtonIndex.template deleted file mode 100644 index fc28f9c..0000000 --- a/content/public/android/java/src/org/chromium/content/browser/input/CanonicalButtonIndex.template +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2014 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.input; - -public class CanonicalButtonIndex { -#define CANONICAL_BUTTON_INDEX(name, value) public static final int name = value; -#include "content/browser/gamepad/canonical_button_index_list.h" -}
\ No newline at end of file diff --git a/content/public/android/java/src/org/chromium/content/browser/input/GamepadDevice.java b/content/public/android/java/src/org/chromium/content/browser/input/GamepadDevice.java deleted file mode 100644 index 3e9ab5e..0000000 --- a/content/public/android/java/src/org/chromium/content/browser/input/GamepadDevice.java +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright 2014 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.input; - -import android.os.SystemClock; -import android.view.InputDevice; -import android.view.InputDevice.MotionRange; -import android.view.KeyEvent; -import android.view.MotionEvent; - -import java.util.Arrays; - -/** - * Manages information related to each connected gamepad device. - */ -class GamepadDevice { - // An id for the gamepad. - private int mDeviceId; - // The index of the gamepad in the Navigator. - private int mDeviceIndex; - // Last time the data for this gamepad was updated. - private long mTimestamp; - // If this gamepad is mapped to standard gamepad? - private boolean mIsStandardGamepad; - - // Array of values for all axes of the gamepad. - // All axis values must be linearly normalized to the range [-1.0 .. 1.0]. - // As appropriate, -1.0 should correspond to "up" or "left", and 1.0 - // should correspond to "down" or "right". - private float[] mAxisValues; - - private float[] mButtonsValues; - - // When the user agent recognizes the attached inputDevice, it is recommended - // that it be remapped to a canonical ordering when possible. Devices that are - // not recognized should still be exposed in their raw form. Therefore we must - // pass the raw Button and raw Axis values. - private float[] mRawButtons; - private float[] mRawAxes; - - // An identification string for the gamepad. - private String mDeviceName; - - // Array of axes ids. - private int[] mAxes; - - GamepadDevice(int index, InputDevice inputDevice) { - mDeviceIndex = index; - mDeviceId = inputDevice.getId(); - mDeviceName = inputDevice.getName(); - mTimestamp = SystemClock.uptimeMillis(); - mButtonsValues = new float[CanonicalButtonIndex.NUM_CANONICAL_BUTTONS]; - mAxisValues = new float[CanonicalAxisIndex.NUM_CANONICAL_AXES]; - mRawButtons = new float[256]; - // Get the total number of axes supported by gamepad. - int totalAxes = 0; - for (MotionRange range : inputDevice.getMotionRanges()) { - if ((range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { - totalAxes++; - } - } - // Get axis ids and initialize axes values. - mAxes = new int[totalAxes]; - mRawAxes = new float[totalAxes]; - int i = 0; - for (MotionRange range : inputDevice.getMotionRanges()) { - if ((range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { - mAxes[i] = range.getAxis(); - mRawAxes[i] = 0.0f; - i++; - } - } - } - - /** - * Updates the axes and buttons maping of a gamepad device to a standard gamepad format. - */ - public void updateButtonsAndAxesMapping() { - mIsStandardGamepad = GamepadMappings.mapToStandardGamepad( - mAxisValues, mButtonsValues, mRawAxes, mRawButtons, mDeviceName); - } - - /** - * @return Device Id of the gamepad device. - */ - public int getId() { return mDeviceId; } - - /** - * @return Mapping status of the gamepad device. - */ - public boolean isStandardGamepad() { return mIsStandardGamepad; } - - /** - * @return Device name of the gamepad device. - */ - public String getName() { return mDeviceName; } - - /** - * @return Device index of the gamepad device. - */ - public int getIndex() { return mDeviceIndex; } - - /** - * @return The timestamp when the gamepad device was last interacted. - */ - public long getTimestamp() { return mTimestamp; } - - /** - * @return The axes state of the gamepad device. - */ - public float[] getAxes() { return mAxisValues; } - - /** - * @return The buttons state of the gamepad device. - */ - public float[] getButtons() { return mButtonsValues; } - - /** - * Reset the axes and buttons data of the gamepad device everytime gamepad data access is - * paused. - */ - public void clearData() { - Arrays.fill(mAxisValues, 0); - Arrays.fill(mRawAxes, 0); - Arrays.fill(mButtonsValues, 0); - Arrays.fill(mRawButtons, 0); - } - - /** - * Handles key event from the gamepad device. - * @return True if the key event from the gamepad device has been consumed. - */ - public boolean handleKeyEvent(KeyEvent event) { - // Ignore event if it is not for standard gamepad key. - if (!GamepadList.isGamepadEvent(event)) return false; - int keyCode = event.getKeyCode(); - assert keyCode < 256; - // Button value 0.0 must mean fully unpressed, and 1.0 must mean fully pressed. - if (event.getAction() == KeyEvent.ACTION_DOWN) { - mRawButtons[keyCode] = 1.0f; - } else if (event.getAction() == KeyEvent.ACTION_UP) { - mRawButtons[keyCode] = 0.0f; - } - mTimestamp = event.getEventTime(); - - return true; - } - - /** - * Handles motion event from the gamepad device. - * @return True if the motion event from the gamepad device has been consumed. - */ - public boolean handleMotionEvent(MotionEvent event) { - // Ignore event if it is not a standard gamepad motion event. - if (!GamepadList.isGamepadEvent(event)) return false; - // Update axes values. - for (int i = 0; i < mAxes.length; i++) { - mRawAxes[i] = event.getAxisValue(mAxes[i]); - } - mTimestamp = event.getEventTime(); - return true; - } - -} diff --git a/content/public/android/java/src/org/chromium/content/browser/input/GamepadList.java b/content/public/android/java/src/org/chromium/content/browser/input/GamepadList.java deleted file mode 100644 index cad2b55..0000000 --- a/content/public/android/java/src/org/chromium/content/browser/input/GamepadList.java +++ /dev/null @@ -1,302 +0,0 @@ -// Copyright 2014 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.input; - -import android.content.Context; -import android.hardware.input.InputManager; -import android.hardware.input.InputManager.InputDeviceListener; -import android.view.InputDevice; -import android.view.InputEvent; -import android.view.KeyEvent; -import android.view.MotionEvent; - -import org.chromium.base.CalledByNative; -import org.chromium.base.JNINamespace; -import org.chromium.base.ThreadUtils; - -/** - * Class to manage connected gamepad devices list. - * - * It is a Java counterpart of GamepadPlatformDataFetcherAndroid and feeds Gamepad API with input - * data. - */ -@JNINamespace("content") -public class GamepadList implements InputDeviceListener { - private static final int MAX_GAMEPADS = 4; - - private final Object mLock = new Object(); - - private final GamepadDevice[] mGamepadDevices = new GamepadDevice[MAX_GAMEPADS]; - private InputManager mInputManager; - private int mAttachedToWindowCounter; - private boolean mIsGamepadAccessed; - - private GamepadList() {} - - private void initializeDevices() { - // Get list of all the attached input devices. - int[] deviceIds = mInputManager.getInputDeviceIds(); - for (int i = 0; i < deviceIds.length; i++) { - InputDevice inputDevice = InputDevice.getDevice(deviceIds[i]); - // Check for gamepad device - if (isGamepadDevice(inputDevice)) { - // Register a new gamepad device. - registerGamepad(inputDevice); - } - } - } - - /** - * Notifies the GamepadList that a {@link ContentView} is attached to a window and it should - * prepare itself for gamepad input. It must be called before {@link onGenericMotionEvent} and - * {@link dispatchKeyEvent}. - */ - public static void onAttachedToWindow(Context context) { - assert ThreadUtils.runningOnUiThread(); - getInstance().attachedToWindow(context); - } - - private void attachedToWindow(Context context) { - if (mAttachedToWindowCounter++ == 0) { - mInputManager = (InputManager) context.getSystemService(Context.INPUT_SERVICE); - synchronized (mLock) { - initializeDevices(); - } - // Register an input device listener. - mInputManager.registerInputDeviceListener(this, null); - } - } - - /** - * Notifies the GamepadList that a {@link ContentView} is detached from it's window. - */ - public static void onDetachedFromWindow() { - assert ThreadUtils.runningOnUiThread(); - getInstance().detachedFromWindow(); - } - - private void detachedFromWindow() { - if (--mAttachedToWindowCounter == 0) { - synchronized (mLock) { - for (int i = 0; i < MAX_GAMEPADS; ++i) { - mGamepadDevices[i] = null; - } - } - mInputManager.unregisterInputDeviceListener(this); - mInputManager = null; - } - } - - // ------------------------------------------------------------ - - // Override InputDeviceListener methods - @Override - public void onInputDeviceChanged(int deviceId) { - } - - @Override - public void onInputDeviceRemoved(int deviceId) { - synchronized (mLock) { - unregisterGamepad(deviceId); - } - } - - @Override - public void onInputDeviceAdded(int deviceId) { - InputDevice inputDevice = InputDevice.getDevice(deviceId); - if (!isGamepadDevice(inputDevice)) return; - synchronized (mLock) { - registerGamepad(inputDevice); - } - } - - // ------------------------------------------------------------ - - private static GamepadList getInstance() { - return LazyHolder.INSTANCE; - } - - private int getDeviceCount() { - int count = 0; - for (int i = 0; i < MAX_GAMEPADS; i++) { - if (getDevice(i) != null) { - count++; - } - } - return count; - } - - private boolean isDeviceConnected(int index) { - if (index < MAX_GAMEPADS && getDevice(index) != null) { - return true; - } - return false; - } - - private GamepadDevice getDeviceById(int deviceId) { - for (int i = 0; i < MAX_GAMEPADS; i++) { - GamepadDevice gamepad = mGamepadDevices[i]; - if (gamepad != null && gamepad.getId() == deviceId) { - return gamepad; - } - } - return null; - } - - private GamepadDevice getDevice(int index) { - // Maximum 4 Gamepads can be connected at a time starting at index zero. - assert index >= 0 && index < MAX_GAMEPADS; - return mGamepadDevices[index]; - } - - /** - * Handles key events from the gamepad devices. - * @return True if the event has been consumed. - */ - public static boolean dispatchKeyEvent(KeyEvent event) { - if (!isGamepadEvent(event)) return false; - return getInstance().handleKeyEvent(event); - } - - private boolean handleKeyEvent(KeyEvent event) { - synchronized (mLock) { - if (!mIsGamepadAccessed) return false; - GamepadDevice gamepad = getGamepadForEvent(event); - if (gamepad == null) return false; - return gamepad.handleKeyEvent(event); - } - } - - /** - * Handles motion events from the gamepad devices. - * @return True if the event has been consumed. - */ - public static boolean onGenericMotionEvent(MotionEvent event) { - if (!isGamepadEvent(event)) return false; - return getInstance().handleMotionEvent(event); - } - - private boolean handleMotionEvent(MotionEvent event) { - synchronized (mLock) { - if (!mIsGamepadAccessed) return false; - GamepadDevice gamepad = getGamepadForEvent(event); - if (gamepad == null) return false; - return gamepad.handleMotionEvent(event); - } - } - - private int getNextAvailableIndex() { - // When multiple gamepads are connected to a user agent, indices must be assigned on a - // first-come first-serve basis, starting at zero. If a gamepad is disconnected, previously - // assigned indices must not be reassigned to gamepads that continue to be connected. - // However, if a gamepad is disconnected, and subsequently the same or a different - // gamepad is then connected, index entries must be reused. - - for (int i = 0; i < MAX_GAMEPADS; ++i) { - if (getDevice(i) == null) { - return i; - } - } - // Reached maximum gamepads limit. - return -1; - } - - private boolean registerGamepad(InputDevice inputDevice) { - int index = getNextAvailableIndex(); - if (index == -1) return false; // invalid index - - GamepadDevice gamepad = new GamepadDevice(index, inputDevice); - mGamepadDevices[index] = gamepad; - return true; - } - - private void unregisterGamepad(int deviceId) { - GamepadDevice gamepadDevice = getDeviceById(deviceId); - if (gamepadDevice == null) return; // Not a registered device. - int index = gamepadDevice.getIndex(); - mGamepadDevices[index] = null; - } - - private static boolean isGamepadDevice(InputDevice inputDevice) { - return ((inputDevice.getSources() & InputDevice.SOURCE_JOYSTICK) == - InputDevice.SOURCE_JOYSTICK); - } - - private GamepadDevice getGamepadForEvent(InputEvent event) { - return getDeviceById(event.getDeviceId()); - } - - /** - * @return True if the motion event corresponds to a gamepad event. - */ - public static boolean isGamepadEvent(MotionEvent event) { - return ((event.getSource() & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK); - } - - /** - * @return True if event's keycode corresponds to a gamepad key. - */ - public static boolean isGamepadEvent(KeyEvent event) { - int keyCode = event.getKeyCode(); - switch (keyCode) { - // Specific handling for dpad keys is required because - // KeyEvent.isGamepadButton doesn't consider dpad keys. - case KeyEvent.KEYCODE_DPAD_UP: - case KeyEvent.KEYCODE_DPAD_DOWN: - case KeyEvent.KEYCODE_DPAD_LEFT: - case KeyEvent.KEYCODE_DPAD_RIGHT: - return true; - default: - return KeyEvent.isGamepadButton(keyCode); - } - } - - @CalledByNative - static void updateGamepadData(long webGamepadsPtr) { - getInstance().grabGamepadData(webGamepadsPtr); - } - - private void grabGamepadData(long webGamepadsPtr) { - synchronized (mLock) { - for (int i = 0; i < MAX_GAMEPADS; i++) { - final GamepadDevice device = getDevice(i); - if (device != null) { - device.updateButtonsAndAxesMapping(); - nativeSetGamepadData(webGamepadsPtr, i, device.isStandardGamepad(), true, - device.getName(), device.getTimestamp(), device.getAxes(), - device.getButtons()); - } else { - nativeSetGamepadData(webGamepadsPtr, i, false, false, null, 0, null, null); - } - } - } - } - - @CalledByNative - static void notifyForGamepadsAccess(boolean isAccessPaused) { - getInstance().setIsGamepadAccessed(!isAccessPaused); - } - - private void setIsGamepadAccessed(boolean isGamepadAccessed) { - synchronized (mLock) { - mIsGamepadAccessed = isGamepadAccessed; - if (isGamepadAccessed) { - for (int i = 0; i < MAX_GAMEPADS; i++) { - GamepadDevice gamepadDevice = getDevice(i); - if (gamepadDevice == null) continue; - gamepadDevice.clearData(); - } - } - } - } - - private native void nativeSetGamepadData(long webGamepadsPtr, int index, boolean mapping, - boolean connected, String devicename, long timestamp, float[] axes, float[] buttons); - - private static class LazyHolder { - private static final GamepadList INSTANCE = new GamepadList(); - } - -} diff --git a/content/public/android/java/src/org/chromium/content/browser/input/GamepadMappings.java b/content/public/android/java/src/org/chromium/content/browser/input/GamepadMappings.java deleted file mode 100644 index 7c171eb..0000000 --- a/content/public/android/java/src/org/chromium/content/browser/input/GamepadMappings.java +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright 2014 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.input; - -import android.view.KeyEvent; - -/** - * Class to manage mapping information related to each supported gamepad controller device. - */ -class GamepadMappings { - public static boolean mapToStandardGamepad(float[] mappedAxis, float[] mappedButtons, - float[] rawAxes, float[] rawButtons, String deviceName) { - if (deviceName.contains("NVIDIA Corporation NVIDIA Controller")) { - mapShieldGamepad(mappedButtons, rawButtons, mappedAxis, rawAxes); - return true; - } else if (deviceName.contains("Microsoft X-Box 360 pad")) { - mapXBox360Gamepad(mappedButtons, rawButtons, mappedAxis, rawAxes); - return true; - } - - mapUnknownGamepad(mappedButtons, rawButtons, mappedAxis, rawAxes); - return false; - } - - private static void mapCommonButtons(float[] mappedButtons, float[] rawButtons) { - mappedButtons[CanonicalButtonIndex.BUTTON_PRIMARY] = rawButtons[KeyEvent.KEYCODE_BUTTON_A]; - mappedButtons[CanonicalButtonIndex.BUTTON_SECONDARY] = - rawButtons[KeyEvent.KEYCODE_BUTTON_B]; - mappedButtons[CanonicalButtonIndex.BUTTON_TERTIARY] = - rawButtons[KeyEvent.KEYCODE_BUTTON_X]; - mappedButtons[CanonicalButtonIndex.BUTTON_QUATERNARY] = - rawButtons[KeyEvent.KEYCODE_BUTTON_Y]; - mappedButtons[CanonicalButtonIndex.BUTTON_LEFT_SHOULDER] = - rawButtons[KeyEvent.KEYCODE_BUTTON_L1]; - mappedButtons[CanonicalButtonIndex.BUTTON_RIGHT_SHOULDER] = - rawButtons[KeyEvent.KEYCODE_BUTTON_R1]; - mappedButtons[CanonicalButtonIndex.BUTTON_BACK_SELECT] = - rawButtons[KeyEvent.KEYCODE_BUTTON_SELECT]; - mappedButtons[CanonicalButtonIndex.BUTTON_START] = - rawButtons[KeyEvent.KEYCODE_BUTTON_START]; - mappedButtons[CanonicalButtonIndex.BUTTON_LEFT_THUMBSTICK] = - rawButtons[KeyEvent.KEYCODE_BUTTON_THUMBL]; - mappedButtons[CanonicalButtonIndex.BUTTON_RIGHT_THUMBSTICK] = - rawButtons[KeyEvent.KEYCODE_BUTTON_THUMBR]; - mappedButtons[CanonicalButtonIndex.BUTTON_META] = rawButtons[KeyEvent.KEYCODE_BUTTON_MODE]; - } - - private static void mapDpadButtonsToAxes(float[] mappedButtons, float[] rawAxes) { - // Negative value indicates dpad up. - mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_UP] = negativeAxisValueAsButton(rawAxes[9]); - // Positive axis value indicates dpad down. - mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_DOWN] = - positiveAxisValueAsButton(rawAxes[9]); - // Positive axis value indicates dpad right. - mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_RIGHT] = - positiveAxisValueAsButton(rawAxes[8]); - // Negative value indicates dpad left. - mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_LEFT] = - negativeAxisValueAsButton(rawAxes[8]); - } - - private static void mapAxes(float[] mappedAxis, float[] rawAxes) { - // Standard gamepad can have only four axes. - mappedAxis[CanonicalAxisIndex.AXIS_LEFT_STICK_X] = rawAxes[0]; - mappedAxis[CanonicalAxisIndex.AXIS_LEFT_STICK_Y] = rawAxes[1]; - mappedAxis[CanonicalAxisIndex.AXIS_RIGHT_STICK_X] = rawAxes[4]; - mappedAxis[CanonicalAxisIndex.AXIS_RIGHT_STICK_Y] = rawAxes[5]; - } - - private static float negativeAxisValueAsButton(float input) { - return (input < -0.5f) ? 1.f : 0.f; - } - - private static float positiveAxisValueAsButton(float input) { - return (input > 0.5f) ? 1.f : 0.f; - } - - /** - * Method for mapping Nvidia gamepad axis and button values - * to standard gamepad button and axes values. - */ - private static void mapShieldGamepad(float[] mappedButtons, float[] rawButtons, - float[] mappedAxis, float[] rawAxes) { - mapCommonButtons(mappedButtons, rawButtons); - - mappedButtons[CanonicalButtonIndex.BUTTON_LEFT_TRIGGER] = rawAxes[2]; - mappedButtons[CanonicalButtonIndex.BUTTON_RIGHT_TRIGGER] = rawAxes[6]; - - mapDpadButtonsToAxes(mappedButtons, rawAxes); - mapAxes(mappedAxis, rawAxes); - } - - /** - * Method for mapping Microsoft XBox 360 gamepad axis and button values - * to standard gamepad button and axes values. - */ - private static void mapXBox360Gamepad(float[] mappedButtons, float[] rawButtons, - float[] mappedAxis, float[] rawAxes) { - mapCommonButtons(mappedButtons, rawButtons); - - mappedButtons[CanonicalButtonIndex.BUTTON_LEFT_TRIGGER] = rawAxes[2]; - mappedButtons[CanonicalButtonIndex.BUTTON_RIGHT_TRIGGER] = rawAxes[6]; - - mapDpadButtonsToAxes(mappedButtons, rawAxes); - mapAxes(mappedAxis, rawAxes); - } - - /** - * Method for mapping Unkown gamepad axis and button values - * to standard gamepad button and axes values. - */ - private static void mapUnknownGamepad(float[] mappedButtons, float[] rawButtons, - float[] mappedAxis, float[] rawAxes) { - mapCommonButtons(mappedButtons, rawButtons); - - mappedButtons[CanonicalButtonIndex.BUTTON_LEFT_TRIGGER] = - rawButtons[KeyEvent.KEYCODE_BUTTON_L2]; - mappedButtons[CanonicalButtonIndex.BUTTON_RIGHT_TRIGGER] = - rawButtons[KeyEvent.KEYCODE_BUTTON_R2]; - - mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_UP] = rawButtons[KeyEvent.KEYCODE_DPAD_UP]; - mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_DOWN] = - rawButtons[KeyEvent.KEYCODE_DPAD_DOWN]; - mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_RIGHT] = - rawButtons[KeyEvent.KEYCODE_DPAD_RIGHT]; - mappedButtons[CanonicalButtonIndex.BUTTON_DPAD_LEFT] = - rawButtons[KeyEvent.KEYCODE_DPAD_LEFT]; - - mapAxes(mappedAxis, rawAxes); - } - -}
\ No newline at end of file |