From abbc36920278d751c1361ddb24fbe4697949bbc9 Mon Sep 17 00:00:00 2001 From: Kamil Klimek Date: Tue, 25 Nov 2014 09:39:57 +0100 Subject: [PATCH] [Tizen][M34-Merge] Fix screen size reporting. The current EFL implementation of gfx::Screen interface is not entirely correct. The main differences compared to Android and Aura ports are: 1. The screen size is reported in px, not in DIP. 2. Screen size is always reported in portrait mode. As a direct result of the differences most mobile pages relying on CSS3 media queries will render incorrectly. They'll use style sheet version designed for devices with larger screen devices that the device has. One example of such page is http://slideshare.net. This patch changes current gfx::Screen implementation to report proper screen size values in DIP for both portrait and landscape orientations. Original patch: http://165.213.202.130:8080/#/c/70582/ Original author: Piotr Tworek Original bug: http://107.108.218.239/bugzilla/show_bug.cgi?id=6308 Bug: http://107.108.218.239/bugzilla/show_bug.cgi?id=5594 Reviewed by: Antonio Gomes, Viatcheslav Ostapenko Change-Id: I21a7baeaf0a9b05dab7d00d255cc611589e784bf Signed-off-by: Kamil Klimek --- .../renderer_host/render_widget_host_view_efl.cc | 36 +++++----------- tizen_src/impl/ewk_global_data.cc | 2 +- tizen_src/impl/screen_efl.cc | 49 +++++++++++++++------- tizen_src/impl/screen_efl.h | 2 +- 4 files changed, 48 insertions(+), 41 deletions(-) diff --git a/tizen_src/impl/browser/renderer_host/render_widget_host_view_efl.cc b/tizen_src/impl/browser/renderer_host/render_widget_host_view_efl.cc index 401e994..a3276c1 100755 --- a/tizen_src/impl/browser/renderer_host/render_widget_host_view_efl.cc +++ b/tizen_src/impl/browser/renderer_host/render_widget_host_view_efl.cc @@ -69,12 +69,10 @@ namespace content { -void RenderWidgetHostViewBase::GetDefaultScreenInfo(blink::WebScreenInfo* results) { - gfx::Screen* screen = gfx::Screen::GetNativeScreen(); - if (!screen) - return; +void RenderWidgetHostViewBase::GetDefaultScreenInfo( + blink::WebScreenInfo* results) { + const gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); - const gfx::Display display = screen->GetPrimaryDisplay(); results->rect = display.bounds(); results->availableRect = display.work_area(); results->deviceScaleFactor = display.device_scale_factor(); @@ -119,6 +117,9 @@ RenderWidgetHostViewEfl::RenderWidgetHostViewEfl(RenderWidgetHost* widget, EWebV #endif #endif + device_scale_factor_ = gfx::Screen::GetNativeScreen()-> + GetPrimaryDisplay().device_scale_factor(); + set_eweb_view(eweb_view); host_->SetView(this); @@ -1006,32 +1007,17 @@ bool RenderWidgetHostViewEfl::HasAcceleratedSurface(const gfx::Size&) { void RenderWidgetHostViewEfl::GetScreenInfo( blink::WebScreenInfo* results) { - gfx::Screen* screen = gfx::Screen::GetNativeScreen(); - if (!screen) - return; - - const gfx::Display display = screen->GetPrimaryDisplay(); -#if defined(OS_TIZEN_MOBILE) - results->rect = GetBoundsInRootWindow(); -#else - results->rect = display.bounds(); -#endif - results->availableRect = display.work_area(); - - device_scale_factor_ = display.device_scale_factor(); - results->deviceScaleFactor = device_scale_factor_; - results->orientationAngle = display.rotation(); - - // TODO(derat|oshima): Don't hardcode this. Get this from display object. - results->depth = 24; - results->depthPerComponent = 8; + RenderWidgetHostViewBase::GetDefaultScreenInfo(results); } gfx::Rect RenderWidgetHostViewEfl::GetBoundsInRootWindow() { Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_); int x, y, w, h; ecore_evas_geometry_get(ee, &x, &y, &w, &h); - return gfx::Rect(x, y, w, h); + if (current_orientation_ == 90 || current_orientation_ == 270) + return ConvertRectToDIP(device_scale_factor_, gfx::Rect(x, y, h, w)); + + return ConvertRectToDIP(device_scale_factor_, gfx::Rect(x, y, w, h)); } gfx::GLSurfaceHandle RenderWidgetHostViewEfl::GetCompositingSurface() { diff --git a/tizen_src/impl/ewk_global_data.cc b/tizen_src/impl/ewk_global_data.cc index 9fd7da9..1973c52 100644 --- a/tizen_src/impl/ewk_global_data.cc +++ b/tizen_src/impl/ewk_global_data.cc @@ -87,7 +87,7 @@ void EwkGlobalData::Ensure() { base::MessageLoop::InitMessagePumpForUIFactory(&MessagePumpFactory); DCHECK(message_pump_overridden); - content::InstallScreenInstance(); + ui::InstallScreenInstance(); content::ContentMainParams params(new ContentMainDelegateEfl()); params.argc = CommandLineEfl::GetArgc(); diff --git a/tizen_src/impl/screen_efl.cc b/tizen_src/impl/screen_efl.cc index cf9d20c..06fe709 100644 --- a/tizen_src/impl/screen_efl.cc +++ b/tizen_src/impl/screen_efl.cc @@ -14,9 +14,20 @@ #include "ui/gfx/screen.h" #include "ui/gfx/x/x11_types.h" #include "ui/views/view.h" +#include "content/browser/renderer_host/dip_util.h" namespace ui { +namespace { +// TODO: Get default values from platform +// http://107.108.218.239/bugzilla/show_bug.cgi?id=9662 +#if defined(OS_TIZEN_MOBILE) +const float kDefaultDeviceScaleFactor = 2.0f; +#else +const float kDefaultDeviceScaleFactor = 1.0f; +#endif +} // namespace + class EflScreen : public gfx::Screen { public: EflScreen() { @@ -75,22 +86,35 @@ class EflScreen : public gfx::Screen { } virtual gfx::Display GetPrimaryDisplay() const override { - static ::Screen* screen = DefaultScreenOfDisplay(gfx::GetXDisplay()); + ::Screen* screen = DefaultScreenOfDisplay(gfx::GetXDisplay()); - static gfx::Display display(0, - gfx::Rect(0, 0, WidthOfScreen(screen), HeightOfScreen(screen))); + const float device_scale_factor = + gfx::Display::HasForceDeviceScaleFactor() ? + gfx::Display::GetForcedDeviceScaleFactor() : kDefaultDeviceScaleFactor; + + gfx::Display display(0); - //TODO:remove hardcoding - if (!gfx::Display::HasForceDeviceScaleFactor()) -#if defined(OS_TIZEN_MOBILE) - display.set_device_scale_factor(2.0f); -#else - display.set_device_scale_factor(1.0f); -#endif // TODO(Youngsoo Choi): If there's a way to get orientation // from platform not using saved value, it would be better. display.SetRotationAsDegree(EWebView::GetOrientation()); + int width, height; + if (display.rotation() == gfx::Display::ROTATE_90 || + display.rotation() == gfx::Display::ROTATE_270) { + width = HeightOfScreen(screen); + height = WidthOfScreen(screen); + } else { + width = WidthOfScreen(screen); + height = HeightOfScreen(screen); + } + + const gfx::Rect bounds_in_pixels = gfx::Rect(width, height); + const gfx::Rect bounds_in_dip = + content::ConvertRectToDIP(device_scale_factor, bounds_in_pixels); + + display.set_device_scale_factor(device_scale_factor); + display.set_bounds(bounds_in_dip); + return display; } @@ -104,9 +128,6 @@ class EflScreen : public gfx::Screen { DISALLOW_COPY_AND_ASSIGN(EflScreen); }; -} - -namespace content { void InstallScreenInstance() { static bool installed = false; @@ -116,4 +137,4 @@ void InstallScreenInstance() } } -} +} // namespace ui diff --git a/tizen_src/impl/screen_efl.h b/tizen_src/impl/screen_efl.h index b5677ac..c2c7529 100644 --- a/tizen_src/impl/screen_efl.h +++ b/tizen_src/impl/screen_efl.h @@ -7,7 +7,7 @@ #include "ui/gfx/screen.h" -namespace content { +namespace ui { void InstallScreenInstance(); -- 2.7.4