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

Unified Diff: Source/modules/gamepad/NavigatorGamepad.cpp

Issue 336693004: Deduplicate DeviceEvent* classes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: oops - fix grammar in test expectation as well Created 6 years, 6 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 | « Source/modules/gamepad/NavigatorGamepad.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/gamepad/NavigatorGamepad.cpp
diff --git a/Source/modules/gamepad/NavigatorGamepad.cpp b/Source/modules/gamepad/NavigatorGamepad.cpp
index d1c006ef9a76fdb2b6725626b327a8a675a79c49..493494814c274de7767aa8f6f9b6f0bbcda1277c 100644
--- a/Source/modules/gamepad/NavigatorGamepad.cpp
+++ b/Source/modules/gamepad/NavigatorGamepad.cpp
@@ -129,11 +129,8 @@ void NavigatorGamepad::trace(Visitor* visitor)
WillBeHeapSupplement<Navigator>::trace(visitor);
}
-void NavigatorGamepad::didConnectOrDisconnectGamepad(unsigned index, const blink::WebGamepad& webGamepad, bool connected)
+void NavigatorGamepad::didUpdateData()
{
- ASSERT(index < blink::WebGamepads::itemsLengthCap);
- ASSERT(connected == webGamepad.connected);
-
// We should stop listening once we detached.
ASSERT(window());
@@ -144,23 +141,24 @@ void NavigatorGamepad::didConnectOrDisconnectGamepad(unsigned index, const blink
if (window()->document()->activeDOMObjectsAreStopped() || window()->document()->activeDOMObjectsAreSuspended())
return;
+ const GamepadDispatcher::ConnectionChange& change = GamepadDispatcher::instance().latestConnectionChange();
+
if (!m_gamepads)
m_gamepads = GamepadList::create();
- Gamepad* gamepad = m_gamepads->item(index);
+ Gamepad* gamepad = m_gamepads->item(change.index);
if (!gamepad)
gamepad = Gamepad::create();
- sampleGamepad(index, *gamepad, webGamepad);
- m_gamepads->set(index, gamepad);
+ sampleGamepad(change.index, *gamepad, change.pad);
+ m_gamepads->set(change.index, gamepad);
- const AtomicString& eventName = connected ? EventTypeNames::gamepadconnected : EventTypeNames::gamepaddisconnected;
- RefPtrWillBeRawPtr<GamepadEvent> event = GamepadEvent::create(eventName, false, true, gamepad);
- window()->dispatchEvent(event);
+ const AtomicString& eventName = change.pad.connected ? EventTypeNames::gamepadconnected : EventTypeNames::gamepaddisconnected;
+ window()->dispatchEvent(GamepadEvent::create(eventName, false, true, gamepad));
}
NavigatorGamepad::NavigatorGamepad(LocalFrame* frame)
: DOMWindowProperty(frame)
- , DeviceSensorEventController(frame ? frame->page() : 0)
+ , DeviceEventControllerBase(frame ? frame->page() : 0)
, DOMWindowLifecycleObserver(frame ? frame->domWindow() : 0)
{
}
@@ -188,12 +186,12 @@ void NavigatorGamepad::willDetachGlobalObjectFromFrame()
void NavigatorGamepad::registerWithDispatcher()
{
- GamepadDispatcher::instance().addClient(this);
+ GamepadDispatcher::instance().addController(this);
}
void NavigatorGamepad::unregisterWithDispatcher()
{
- GamepadDispatcher::instance().removeClient(this);
+ GamepadDispatcher::instance().removeController(this);
}
bool NavigatorGamepad::hasLastData()
@@ -202,25 +200,6 @@ bool NavigatorGamepad::hasLastData()
return false;
}
-PassRefPtrWillBeRawPtr<Event> NavigatorGamepad::getLastEvent()
-{
- // This is called only when hasLastData() is true.
- ASSERT_NOT_REACHED();
- return nullptr;
-}
-
-bool NavigatorGamepad::isNullEvent(Event*)
-{
- // This is called only when hasLastData() is true.
- ASSERT_NOT_REACHED();
- return false;
-}
-
-Document* NavigatorGamepad::document()
-{
- return window() ? window()->document() : 0;
-}
-
static bool isGamepadEvent(const AtomicString& eventType)
{
return eventType == EventTypeNames::gamepadconnected || eventType == EventTypeNames::gamepaddisconnected;
@@ -235,10 +214,13 @@ void NavigatorGamepad::didAddEventListener(DOMWindow*, const AtomicString& event
}
}
-void NavigatorGamepad::didRemoveEventListener(DOMWindow*, const AtomicString& eventType)
+void NavigatorGamepad::didRemoveEventListener(DOMWindow* window, const AtomicString& eventType)
{
- if (isGamepadEvent(eventType))
+ if (isGamepadEvent(eventType)
+ && !window->hasEventListeners(EventTypeNames::gamepadconnected)
+ && !window->hasEventListeners(EventTypeNames::gamepaddisconnected)) {
m_hasEventListener = false;
+ }
}
void NavigatorGamepad::didRemoveAllEventListeners(DOMWindow*)
« no previous file with comments | « Source/modules/gamepad/NavigatorGamepad.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698