From 6131fe6d36d160340926091f4daf7d64bffdd5c5 Mon Sep 17 00:00:00 2001 From: "mlamouri@chromium.org" Date: Wed, 25 Jun 2014 13:52:30 +0000 Subject: Android: compute screen orientation type in the RWHV. BUG=162827 Review URL: https://codereview.chromium.org/336313011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@279709 0039d316-1c4b-4281-b951-d872f2087c98 --- .../render_widget_host_view_android.cc | 2 ++ .../renderer_host/render_widget_host_view_aura.cc | 3 ++ .../renderer_host/render_widget_host_view_base.cc | 34 +++++++++++++++++++++- .../renderer_host/render_widget_host_view_base.h | 5 ++++ .../renderer_host/render_widget_host_view_mac.mm | 2 ++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/content/browser/renderer_host/render_widget_host_view_android.cc b/content/browser/renderer_host/render_widget_host_view_android.cc index 51ac5fc..e830e65 100644 --- a/content/browser/renderer_host/render_widget_host_view_android.cc +++ b/content/browser/renderer_host/render_widget_host_view_android.cc @@ -1444,6 +1444,8 @@ void RenderWidgetHostViewBase::GetDefaultScreenInfo( results->availableRect = display.work_area(); results->deviceScaleFactor = display.device_scale_factor(); results->orientationAngle = display.RotationAsDegree(); + results->orientationType = + RenderWidgetHostViewBase::GetOrientationTypeFromDisplay(display); gfx::DeviceDisplayInfo info; results->depth = info.GetBitsPerPixel(); results->depthPerComponent = info.GetBitsPerComponent(); diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc index 16a4e76..77d0800 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.cc +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc @@ -316,6 +316,9 @@ void GetScreenInfoForWindow(WebScreenInfo* results, aura::Window* window) { results->orientationAngle = 270; else if (results->orientationAngle == 270) results->orientationAngle = 90; + + results->orientationType = + RenderWidgetHostViewBase::GetOrientationTypeFromDisplay(display); } bool PointerEventActivates(const ui::Event& event) { diff --git a/content/browser/renderer_host/render_widget_host_view_base.cc b/content/browser/renderer_host/render_widget_host_view_base.cc index d5f58e0..fda35284 100644 --- a/content/browser/renderer_host/render_widget_host_view_base.cc +++ b/content/browser/renderer_host/render_widget_host_view_base.cc @@ -12,7 +12,6 @@ #include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/common/content_switches_internal.h" #include "content/public/browser/render_widget_host_view_frame_subscriber.h" -#include "third_party/WebKit/public/platform/WebScreenInfo.h" #include "ui/gfx/display.h" #include "ui/gfx/screen.h" #include "ui/gfx/size_conversions.h" @@ -608,4 +607,37 @@ void RenderWidgetHostViewBase::SetInsets(const gfx::Insets& insets) { NOTIMPLEMENTED(); } +// static +blink::WebScreenOrientationType +RenderWidgetHostViewBase::GetOrientationTypeFromDisplay( + const gfx::Display& display) { + int angle = display.RotationAsDegree(); + const gfx::Rect& bounds = display.bounds(); + + // Whether the device's natural orientation is portrait. + bool naturalPortrait = false; + if (angle == 0 || angle == 180) // The device is in its natural orientation. + naturalPortrait = bounds.height() > bounds.width(); + else + naturalPortrait = bounds.height() < bounds.width(); + + switch (angle) { + case 0: + return naturalPortrait ? blink::WebScreenOrientationPortraitPrimary + : blink::WebScreenOrientationLandscapePrimary; + case 90: + return naturalPortrait ? blink::WebScreenOrientationLandscapePrimary + : blink::WebScreenOrientationPortraitSecondary; + case 180: + return naturalPortrait ? blink::WebScreenOrientationPortraitSecondary + : blink::WebScreenOrientationLandscapeSecondary; + case 270: + return naturalPortrait ? blink::WebScreenOrientationLandscapeSecondary + : blink::WebScreenOrientationPortraitPrimary; + default: + NOTREACHED(); + return blink::WebScreenOrientationPortraitPrimary; + } +} + } // namespace content diff --git a/content/browser/renderer_host/render_widget_host_view_base.h b/content/browser/renderer_host/render_widget_host_view_base.h index 9bf2e60..8ff1c75 100644 --- a/content/browser/renderer_host/render_widget_host_view_base.h +++ b/content/browser/renderer_host/render_widget_host_view_base.h @@ -22,6 +22,7 @@ #include "content/common/input/input_event_ack_state.h" #include "content/public/browser/render_widget_host_view.h" #include "ipc/ipc_listener.h" +#include "third_party/WebKit/public/platform/WebScreenOrientationType.h" #include "third_party/WebKit/public/web/WebPopupType.h" #include "third_party/WebKit/public/web/WebTextDirection.h" #include "ui/base/ime/text_input_mode.h" @@ -308,6 +309,10 @@ class CONTENT_EXPORT RenderWidgetHostViewBase : public RenderWidgetHostView, // returned only if the accelerated surface size matches. virtual bool HasAcceleratedSurface(const gfx::Size& desired_size) = 0; + // Returns the orientation type based on the current display state. + static blink::WebScreenOrientationType GetOrientationTypeFromDisplay( + const gfx::Display& display); + virtual void GetScreenInfo(blink::WebScreenInfo* results) = 0; // Gets the bounds of the window, in screen coordinates. diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm index bb24a63..34ff9bf 100644 --- a/content/browser/renderer_host/render_widget_host_view_mac.mm +++ b/content/browser/renderer_host/render_widget_host_view_mac.mm @@ -376,6 +376,8 @@ blink::WebScreenInfo GetWebScreenInfo(NSView* view) { results.rect = display.bounds(); results.availableRect = display.work_area(); results.orientationAngle = display.RotationAsDegree(); + results.orientationType = + content::RenderWidgetHostViewBase::GetOrientationTypeFromDisplay(display); return results; } -- cgit v1.1