Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Screen Orientation API] Change natural orientation on iPad and TV to be landscape-primary #10803

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/WebCore/page/ScreenOrientation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ uint16_t ScreenOrientation::angle() const
auto orientation = manager ? manager->currentOrientation() : naturalScreenOrientationType();

// https://w3c.github.io/screen-orientation/#dfn-screen-orientation-values-table
if constexpr (isPortait(naturalScreenOrientationType())) {
if (isPortrait(naturalScreenOrientationType())) {
switch (orientation) {
case Type::PortraitPrimary:
return 0;
Expand Down
16 changes: 12 additions & 4 deletions Source/WebCore/page/ScreenOrientationType.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@

#include <wtf/EnumTraits.h>

#if PLATFORM(IOS)
#include "Device.h"
#endif

namespace WebCore {

enum class ScreenOrientationType : uint8_t {
Expand All @@ -36,7 +40,7 @@ enum class ScreenOrientationType : uint8_t {
LandscapeSecondary
};

constexpr bool isPortait(ScreenOrientationType type)
constexpr bool isPortrait(ScreenOrientationType type)
{
return type == ScreenOrientationType::PortraitPrimary || type == ScreenOrientationType::PortraitSecondary;
}
Expand All @@ -46,12 +50,16 @@ constexpr bool isLandscape(ScreenOrientationType type)
return type == ScreenOrientationType::LandscapePrimary || type == ScreenOrientationType::LandscapeSecondary;
}

constexpr ScreenOrientationType naturalScreenOrientationType()
inline ScreenOrientationType naturalScreenOrientationType()
{
#if PLATFORM(IOS_FAMILY)
#if PLATFORM(IOS)
if (deviceHasIPadCapability())
return ScreenOrientationType::LandscapePrimary;
return ScreenOrientationType::PortraitPrimary;
#elif PLATFORM(WATCHOS)
return ScreenOrientationType::PortraitPrimary;
#else
// On Desktop, the natural orientation must be landscape-primary.
// On Desktop and TV, the natural orientation must be landscape-primary.
return ScreenOrientationType::LandscapePrimary;
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/platform/ios/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ String deviceName(); // Thread-safe.
WEBCORE_EXPORT bool deviceClassIsSmallScreen();

// FIXME: How does this differ from !deviceClassIsSmallScreen()?
bool deviceHasIPadCapability();
WEBCORE_EXPORT bool deviceHasIPadCapability();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,16 @@ static WebCore::ScreenOrientationType resolveScreenOrientationLockType(WebCore::
return WebCore::ScreenOrientationType::LandscapePrimary;
case WebCore::ScreenOrientationLockType::LandscapeSecondary:
return WebCore::ScreenOrientationType::LandscapeSecondary;
case WebCore::ScreenOrientationLockType::Natural:
case WebCore::ScreenOrientationLockType::Natural: {
auto naturalOrientation = naturalScreenOrientationType();
if (WebCore::isPortrait(naturalOrientation) == WebCore::isPortrait(currentOrientation))
return currentOrientation;
return naturalOrientation;
}
case WebCore::ScreenOrientationLockType::Portrait:
break;
}
if (WebCore::isPortait(currentOrientation))
if (WebCore::isPortrait(currentOrientation))
return currentOrientation;
return WebCore::ScreenOrientationType::PortraitPrimary;
}
Expand Down