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

Unified Diff: Source/modules/screen_orientation/ScreenOrientationController.cpp

Issue 1195793008: [DevTools] Implement screen orientation override. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Restore test Created 5 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/screen_orientation/ScreenOrientationController.cpp
diff --git a/Source/modules/screen_orientation/ScreenOrientationController.cpp b/Source/modules/screen_orientation/ScreenOrientationController.cpp
index 0820474f073e7db10f66ec4a4058887cf10b4a33..abaec2ce42197dc283aecc164518e0843b99b098 100644
--- a/Source/modules/screen_orientation/ScreenOrientationController.cpp
+++ b/Source/modules/screen_orientation/ScreenOrientationController.cpp
@@ -41,6 +41,9 @@ ScreenOrientationController::ScreenOrientationController(LocalFrame& frame, WebS
, PlatformEventController(frame.page())
, m_client(client)
, m_dispatchEventTimer(this, &ScreenOrientationController::dispatchEventTimerFired)
+ , m_override(false)
+ , m_overrideType(WebScreenOrientationUndefined)
+ , m_overrideAngle(0)
{
}
@@ -50,7 +53,7 @@ const char* ScreenOrientationController::supplementName()
}
// Compute the screen orientation using the orientation angle and the screen width / height.
-WebScreenOrientationType ScreenOrientationController::computeOrientation(ChromeClient& chromeClient)
+WebScreenOrientationType ScreenOrientationController::computeOrientation(const IntRect& rect, uint16_t rotation)
{
// Bypass orientation detection in layout tests to get consistent results.
// FIXME: The screen dimension should be fixed when running the layout tests to avoid such
@@ -58,8 +61,6 @@ WebScreenOrientationType ScreenOrientationController::computeOrientation(ChromeC
if (LayoutTestSupport::isRunningLayoutTest())
return WebScreenOrientationPortraitPrimary;
- IntRect rect = chromeClient.screenInfo().rect;
- uint16_t rotation = chromeClient.screenInfo().orientationAngle;
bool isTallDisplay = rotation % 180 ? rect.height() < rect.width() : rect.height() > rect.width();
switch (rotation) {
case 0:
@@ -76,6 +77,16 @@ WebScreenOrientationType ScreenOrientationController::computeOrientation(ChromeC
}
}
+unsigned short ScreenOrientationController::effectiveAngle(ChromeClient& chromeClient)
+{
+ return m_override ? m_overrideAngle : chromeClient.screenInfo().orientationAngle;
+}
+
+WebScreenOrientationType ScreenOrientationController::effectiveType(ChromeClient& chromeClient)
+{
+ return m_override ? m_overrideType : chromeClient.screenInfo().orientationType;
+}
+
void ScreenOrientationController::updateOrientation()
{
ASSERT(m_orientation);
@@ -83,15 +94,15 @@ void ScreenOrientationController::updateOrientation()
ASSERT(frame()->host());
ChromeClient& chromeClient = frame()->host()->chromeClient();
- WebScreenOrientationType orientationType = chromeClient.screenInfo().orientationType;
+ WebScreenOrientationType orientationType = effectiveType(chromeClient);
if (orientationType == WebScreenOrientationUndefined) {
// The embedder could not provide us with an orientation, deduce it ourselves.
- orientationType = computeOrientation(chromeClient);
+ orientationType = computeOrientation(chromeClient.screenInfo().rect, effectiveAngle(chromeClient));
}
ASSERT(orientationType != WebScreenOrientationUndefined);
m_orientation->setType(orientationType);
- m_orientation->setAngle(chromeClient.screenInfo().orientationAngle);
+ m_orientation->setAngle(effectiveAngle(chromeClient));
}
bool ScreenOrientationController::isActiveAndVisible() const
@@ -108,7 +119,7 @@ void ScreenOrientationController::pageVisibilityChanged()
// The orientation type and angle are tied in a way that if the angle has
// changed, the type must have changed.
- unsigned short currentAngle = frame()->host()->chromeClient().screenInfo().orientationAngle;
+ unsigned short currentAngle = effectiveAngle(frame()->host()->chromeClient());
// FIXME: sendOrientationChangeEvent() currently send an event all the
// children of the frame, so it should only be called on the frame on
@@ -172,6 +183,20 @@ void ScreenOrientationController::unlock()
m_client->unlockOrientation();
}
+void ScreenOrientationController::setOverride(WebScreenOrientationType type, unsigned short angle)
+{
+ m_override = true;
+ m_overrideType = type;
+ m_overrideAngle = angle;
+ notifyOrientationChanged();
+}
+
+void ScreenOrientationController::clearOverride()
+{
+ m_override = false;
+ notifyOrientationChanged();
+}
+
void ScreenOrientationController::dispatchEventTimerFired(Timer<ScreenOrientationController>*)
{
if (!m_orientation)

Powered by Google App Engine
This is Rietveld 408576698