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

Unified Diff: Source/modules/device_orientation/DeviceOrientationController.cpp

Issue 315023006: Revert of Generalize and refactor DeviceSensorEvent* architecture to support multi-event type targets. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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
Index: Source/modules/device_orientation/DeviceOrientationController.cpp
diff --git a/Source/modules/device_orientation/DeviceOrientationController.cpp b/Source/modules/device_orientation/DeviceOrientationController.cpp
index 98e04dd6e5529f445bfa90d4b23121ef8383d21b..23b943df73f3280fc2a91e5793c9d8a2f5935896 100644
--- a/Source/modules/device_orientation/DeviceOrientationController.cpp
+++ b/Source/modules/device_orientation/DeviceOrientationController.cpp
@@ -1,12 +1,35 @@
-// 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.
+/*
+ * Copyright 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2012 Samsung Electronics. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
#include "config.h"
#include "modules/device_orientation/DeviceOrientationController.h"
#include "core/dom/Document.h"
-#include "modules/EventModules.h"
+#include "core/frame/DOMWindow.h"
+#include "core/page/Page.h"
#include "modules/device_orientation/DeviceOrientationData.h"
#include "modules/device_orientation/DeviceOrientationDispatcher.h"
#include "modules/device_orientation/DeviceOrientationEvent.h"
@@ -14,7 +37,9 @@
namespace WebCore {
DeviceOrientationController::DeviceOrientationController(Document& document)
- : DeviceSingleWindowEventController(document)
+ : DeviceSensorEventController(document.page())
+ , DOMWindowLifecycleObserver(document.domWindow())
+ , m_document(document)
{
}
@@ -23,11 +48,11 @@
stopUpdating();
}
-void DeviceOrientationController::didUpdateData()
+void DeviceOrientationController::didChangeDeviceOrientation(DeviceOrientationData* deviceOrientationData)
{
if (m_overrideOrientationData)
return;
- dispatchDeviceEvent(lastEvent());
+ dispatchDeviceEvent(DeviceOrientationEvent::create(EventTypeNames::deviceorientation, deviceOrientationData));
}
const char* DeviceOrientationController::supplementName()
@@ -45,7 +70,7 @@
return *controller;
}
-DeviceOrientationData* DeviceOrientationController::lastData() const
+DeviceOrientationData* DeviceOrientationController::lastData()
{
return m_overrideOrientationData ? m_overrideOrientationData.get() : DeviceOrientationDispatcher::instance().latestDeviceOrientationData();
}
@@ -55,37 +80,63 @@
return lastData();
}
+PassRefPtrWillBeRawPtr<Event> DeviceOrientationController::getLastEvent()
+{
+ return DeviceOrientationEvent::create(EventTypeNames::deviceorientation, lastData());
+}
+
void DeviceOrientationController::registerWithDispatcher()
{
- DeviceOrientationDispatcher::instance().addController(this);
+ DeviceOrientationDispatcher::instance().addDeviceOrientationController(this);
}
void DeviceOrientationController::unregisterWithDispatcher()
{
- DeviceOrientationDispatcher::instance().removeController(this);
+ DeviceOrientationDispatcher::instance().removeDeviceOrientationController(this);
}
-PassRefPtrWillBeRawPtr<Event> DeviceOrientationController::lastEvent() const
-{
- return DeviceOrientationEvent::create(eventTypeName(), lastData());
-}
-
-bool DeviceOrientationController::isNullEvent(Event* event) const
+bool DeviceOrientationController::isNullEvent(Event* event)
{
DeviceOrientationEvent* orientationEvent = toDeviceOrientationEvent(event);
return !orientationEvent->orientation()->canProvideEventData();
}
-const AtomicString& DeviceOrientationController::eventTypeName() const
+Document* DeviceOrientationController::document()
{
- return EventTypeNames::deviceorientation;
+ return &m_document;
+}
+
+void DeviceOrientationController::didAddEventListener(DOMWindow* window, const AtomicString& eventType)
+{
+ if (eventType != EventTypeNames::deviceorientation)
+ return;
+
+ if (page() && page()->visibilityState() == PageVisibilityStateVisible)
+ startUpdating();
+
+ m_hasEventListener = true;
+}
+
+void DeviceOrientationController::didRemoveEventListener(DOMWindow* window, const AtomicString& eventType)
+{
+ if (eventType != EventTypeNames::deviceorientation || window->hasEventListeners(EventTypeNames::deviceorientation))
+ return;
+
+ stopUpdating();
+ m_hasEventListener = false;
+}
+
+void DeviceOrientationController::didRemoveAllEventListeners(DOMWindow* window)
+{
+ stopUpdating();
+ m_hasEventListener = false;
}
void DeviceOrientationController::setOverride(DeviceOrientationData* deviceOrientationData)
{
- ASSERT(deviceOrientationData);
+ m_overrideOrientationData.clear();
+ didChangeDeviceOrientation(deviceOrientationData);
m_overrideOrientationData = deviceOrientationData;
- dispatchDeviceEvent(lastEvent());
}
void DeviceOrientationController::clearOverride()
@@ -93,8 +144,9 @@
if (!m_overrideOrientationData)
return;
m_overrideOrientationData.clear();
- if (lastData())
- didUpdateData();
+ DeviceOrientationData* orientation = lastData();
+ if (orientation)
+ didChangeDeviceOrientation(orientation);
}
void DeviceOrientationController::trace(Visitor* visitor)

Powered by Google App Engine
This is Rietveld 408576698