diff options
author | aruslan@chromium.org <aruslan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-24 01:50:11 +0000 |
---|---|---|
committer | aruslan@chromium.org <aruslan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-24 01:50:11 +0000 |
commit | 276e8a328ac79317d8202b1ff31018c94af01c73 (patch) | |
tree | bcd6a0553fccf51cbe2d770dcddc5dc9f7ce7c95 | |
parent | 0be98f3d8cbe8996b50ec3be7160d4de1f200f0b (diff) | |
download | chromium_src-276e8a328ac79317d8202b1ff31018c94af01c73.zip chromium_src-276e8a328ac79317d8202b1ff31018c94af01c73.tar.gz chromium_src-276e8a328ac79317d8202b1ff31018c94af01c73.tar.bz2 |
Use correct favicon scale factor on Android.
- Splits and moves Android's display DeviceInfo from content to gfx;
- Uses DeviceInfo for Android's Screen implementation;
- Uses PrimaryDisplay's scale to figure out favicon scale factor.
BUG=168319
BUG=117839
TEST=manual as in 168319; AwSettingsTest#testUseWideViewportLayoutWidth
Review URL: https://chromiumcodereview.appspot.com/11886074
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@178472 0039d316-1c4b-4281-b951-d872f2087c98
31 files changed, 387 insertions, 211 deletions
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java index 117e07d..7e08b28 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java @@ -26,8 +26,8 @@ import org.chromium.content.browser.test.util.CallbackHelper; import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.browser.test.util.HistoryUtils; -import org.chromium.content.common.DeviceInfo; import org.chromium.net.test.util.TestWebServer; +import org.chromium.ui.gfx.DeviceDisplayInfo; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -2098,8 +2098,9 @@ public class AwSettingsTest extends AndroidWebViewTestBase { pageTemplate, "<meta name='viewport' content='width=" + viewportTagSpecifiedWidth + "' />"); - DeviceInfo deviceInfo = DeviceInfo.create(getInstrumentation().getTargetContext()); - int displayWidth = (int) (deviceInfo.getWidth() / deviceInfo.getDPIScale()); + DeviceDisplayInfo deviceInfo = + DeviceDisplayInfo.create(getInstrumentation().getTargetContext()); + int displayWidth = (int) (deviceInfo.getDisplayWidth() / deviceInfo.getDIPScale()); settings.setJavaScriptEnabled(true); assertFalse(settings.getUseWideViewPort()); diff --git a/chrome/test/base/chrome_test_suite.cc b/chrome/test/base/chrome_test_suite.cc index 1181169..872a200 100644 --- a/chrome/test/base/chrome_test_suite.cc +++ b/chrome/test/base/chrome_test_suite.cc @@ -35,6 +35,7 @@ #include "base/android/jni_android.h" #include "chrome/browser/android/chrome_jni_registrar.h" #include "net/android/net_jni_registrar.h" +#include "ui/android/ui_jni_registrar.h" #endif #if defined(OS_MACOSX) @@ -202,6 +203,7 @@ void ChromeTestSuite::Initialize() { #if defined(OS_ANDROID) // Register JNI bindings for android. net::android::RegisterJni(base::android::AttachCurrentThread()); + ui::android::RegisterJni(base::android::AttachCurrentThread()); chrome::android::RegisterJni(base::android::AttachCurrentThread()); #endif diff --git a/content/app/android/library_loader_hooks.cc b/content/app/android/library_loader_hooks.cc index 80026b8..ac6ef27 100644 --- a/content/app/android/library_loader_hooks.cc +++ b/content/app/android/library_loader_hooks.cc @@ -28,7 +28,6 @@ #include "net/android/net_jni_registrar.h" #include "ui/android/ui_jni_registrar.h" #include "jni/LibraryLoader_jni.h" -#include "ui/gfx/android/gfx_jni_registrar.h" namespace { base::AtExitManager* g_at_exit_manager = NULL; @@ -76,7 +75,7 @@ static jint LibraryLoadedOnMainThread(JNIEnv* env, jclass clazz, if (!net::android::RegisterJni(env)) return RESULT_CODE_FAILED_TO_REGISTER_JNI; - if (!ui::RegisterJni(env)) + if (!ui::android::RegisterJni(env)) return RESULT_CODE_FAILED_TO_REGISTER_JNI; if (!content::android::RegisterCommonJni(env)) @@ -91,9 +90,6 @@ static jint LibraryLoadedOnMainThread(JNIEnv* env, jclass clazz, if (!media::RegisterJni(env)) return RESULT_CODE_FAILED_TO_REGISTER_JNI; - if (!gfx::RegisterJni(env)) - return RESULT_CODE_FAILED_TO_REGISTER_JNI; - return 0; } diff --git a/content/browser/android/content_view_core_impl.cc b/content/browser/android/content_view_core_impl.cc index 5942bc7..ae6cd47 100644 --- a/content/browser/android/content_view_core_impl.cc +++ b/content/browser/android/content_view_core_impl.cc @@ -28,7 +28,6 @@ #include "content/browser/web_contents/navigation_controller_impl.h" #include "content/browser/web_contents/navigation_entry_impl.h" #include "content/browser/web_contents/web_contents_view_android.h" -#include "content/common/android/device_info.h" #include "content/common/view_messages.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/favicon_status.h" @@ -176,8 +175,9 @@ ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj, switches::kEnableCssTransformPinch)) { dpi_scale_ = 1; } else { - scoped_ptr<content::DeviceInfo> device_info(new content::DeviceInfo()); - dpi_scale_ = device_info->GetDPIScale(); + const gfx::Display& display = + gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); + dpi_scale_ = display.device_scale_factor(); } // Currently, the only use case we have for overriding a user agent involves 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 fc65287..c278493 100644 --- a/content/browser/renderer_host/render_widget_host_view_android.cc +++ b/content/browser/renderer_host/render_widget_host_view_android.cc @@ -18,7 +18,6 @@ #include "content/browser/renderer_host/image_transport_factory_android.h" #include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/browser/renderer_host/surface_texture_transport_client_android.h" -#include "content/common/android/device_info.h" #include "content/common/gpu/client/gl_helper.h" #include "content/common/gpu/gpu_messages.h" #include "content/common/view_messages.h" @@ -27,6 +26,7 @@ #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebExternalTextureLayer.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" +#include "ui/gfx/android/device_display_info.h" #include "ui/gfx/android/java_bitmap.h" #include "ui/gfx/size_conversions.h" #include "webkit/compositor_bindings/web_compositor_support_impl.h" @@ -630,10 +630,10 @@ void RenderWidgetHostViewAndroid::HasTouchEventHandlers( // static void RenderWidgetHostViewPort::GetDefaultScreenInfo( WebKit::WebScreenInfo* results) { - DeviceInfo info; - const int width = info.GetWidth(); - const int height = info.GetHeight(); - results->deviceScaleFactor = info.GetDPIScale(); + gfx::DeviceDisplayInfo info; + const int width = info.GetDisplayWidth(); + const int height = info.GetDisplayHeight(); + results->deviceScaleFactor = info.GetDIPScale(); results->depth = info.GetBitsPerPixel(); results->depthPerComponent = info.GetBitsPerComponent(); results->isMonochrome = (results->depthPerComponent == 0); diff --git a/content/common/android/common_jni_registrar.cc b/content/common/android/common_jni_registrar.cc index d60e9dc..3169f44 100644 --- a/content/common/android/common_jni_registrar.cc +++ b/content/common/android/common_jni_registrar.cc @@ -7,7 +7,7 @@ #include "base/android/jni_android.h" #include "base/android/jni_registrar.h" #include "content/common/android/command_line.h" -#include "content/common/android/device_info.h" +#include "content/common/android/device_telephony_info.h" #include "content/common/android/hash_set.h" #include "content/common/android/surface_callback.h" #include "content/common/android/surface_texture_listener.h" @@ -16,7 +16,8 @@ namespace { base::android::RegistrationMethod kContentRegisteredMethods[] = { { "CommandLine", RegisterCommandLine }, - { "DeviceInfo", content::RegisterDeviceInfo }, + { "DeviceTelephonyInfo", + content::DeviceTelephonyInfo::RegisterDeviceTelephonyInfo }, { "HashSet", content::RegisterHashSet }, { "SurfaceCallback", content::RegisterSurfaceCallback }, { "SurfaceTextureListener", diff --git a/content/common/android/device_info.cc b/content/common/android/device_info.cc deleted file mode 100644 index 2522cae..0000000 --- a/content/common/android/device_info.cc +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) 2012 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. - -#include "content/common/android/device_info.h" - -#include "base/android/jni_android.h" -#include "base/android/jni_string.h" -#include "base/logging.h" -#include "jni/DeviceInfo_jni.h" - -using base::android::AttachCurrentThread; -using base::android::ConvertJavaStringToUTF8; -using base::android::ScopedJavaLocalRef; - -namespace content { - -DeviceInfo::DeviceInfo() { - JNIEnv* env = AttachCurrentThread(); - j_device_info_.Reset(Java_DeviceInfo_create(env, - base::android::GetApplicationContext())); -} - -DeviceInfo::~DeviceInfo() { -} - -int DeviceInfo::GetHeight() { - JNIEnv* env = AttachCurrentThread(); - jint result = - Java_DeviceInfo_getHeight(env, j_device_info_.obj()); - return static_cast<int>(result); -} - -int DeviceInfo::GetWidth() { - JNIEnv* env = AttachCurrentThread(); - jint result = - Java_DeviceInfo_getWidth(env, j_device_info_.obj()); - return static_cast<int>(result); -} - -int DeviceInfo::GetBitsPerPixel() { - JNIEnv* env = AttachCurrentThread(); - jint result = - Java_DeviceInfo_getBitsPerPixel(env, j_device_info_.obj()); - return static_cast<int>(result); -} - -int DeviceInfo::GetBitsPerComponent() { - JNIEnv* env = AttachCurrentThread(); - jint result = - Java_DeviceInfo_getBitsPerComponent(env, j_device_info_.obj()); - return static_cast<int>(result); -} - -double DeviceInfo::GetDPIScale() { - JNIEnv* env = AttachCurrentThread(); - jdouble result = - Java_DeviceInfo_getDPIScale(env, j_device_info_.obj()); - return static_cast<double>(result); -} - -double DeviceInfo::GetRefreshRate() { - JNIEnv* env = AttachCurrentThread(); - jdouble result = - Java_DeviceInfo_getRefreshRate(env, j_device_info_.obj()); - return static_cast<double>(result); -} - -std::string DeviceInfo::GetNetworkCountryIso() { - JNIEnv* env = AttachCurrentThread(); - ScopedJavaLocalRef<jstring> result = - Java_DeviceInfo_getNetworkCountryIso(env, j_device_info_.obj()); - return ConvertJavaStringToUTF8(result); -} - -bool RegisterDeviceInfo(JNIEnv* env) { - return RegisterNativesImpl(env); -} - -} // namespace content diff --git a/content/common/android/device_info.h b/content/common/android/device_info.h deleted file mode 100644 index 017961f..0000000 --- a/content/common/android/device_info.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2012 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. - -#ifndef CONTENT_COMMON_ANDROID_DEVICE_INFO_H_ -#define CONTENT_COMMON_ANDROID_DEVICE_INFO_H_ - -#include <jni.h> -#include <string> - -#include "base/android/scoped_java_ref.h" -#include "base/basictypes.h" - -namespace content { - -// Facilitates access to device information typically only -// available using the Android SDK, including Display properties. -class DeviceInfo { - public: - DeviceInfo(); - ~DeviceInfo(); - - int GetHeight(); - int GetWidth(); - int GetBitsPerPixel(); - int GetBitsPerComponent(); - double GetDPIScale(); - double GetRefreshRate(); - std::string GetNetworkCountryIso(); - - private: - base::android::ScopedJavaGlobalRef<jobject> j_device_info_; - - DISALLOW_COPY_AND_ASSIGN(DeviceInfo); -}; - -bool RegisterDeviceInfo(JNIEnv* env); - -} // namespace content - -#endif // CONTENT_COMMON_ANDROID_DEVICE_INFO_H_ diff --git a/content/common/android/device_telephony_info.cc b/content/common/android/device_telephony_info.cc new file mode 100644 index 0000000..1fc10ac --- /dev/null +++ b/content/common/android/device_telephony_info.cc @@ -0,0 +1,39 @@ +// Copyright (c) 2012 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. + +#include "content/common/android/device_telephony_info.h" + +#include "base/android/jni_android.h" +#include "base/android/jni_string.h" +#include "base/logging.h" +#include "jni/DeviceTelephonyInfo_jni.h" + +using base::android::AttachCurrentThread; +using base::android::ConvertJavaStringToUTF8; +using base::android::ScopedJavaLocalRef; + +namespace content { + +DeviceTelephonyInfo::DeviceTelephonyInfo() { + JNIEnv* env = AttachCurrentThread(); + j_device_info_.Reset(Java_DeviceTelephonyInfo_create(env, + base::android::GetApplicationContext())); +} + +DeviceTelephonyInfo::~DeviceTelephonyInfo() { +} + +std::string DeviceTelephonyInfo::GetNetworkCountryIso() { + JNIEnv* env = AttachCurrentThread(); + ScopedJavaLocalRef<jstring> result = + Java_DeviceTelephonyInfo_getNetworkCountryIso(env, j_device_info_.obj()); + return ConvertJavaStringToUTF8(result); +} + +// static +bool DeviceTelephonyInfo::RegisterDeviceTelephonyInfo(JNIEnv* env) { + return RegisterNativesImpl(env); +} + +} // namespace content diff --git a/content/common/android/device_telephony_info.h b/content/common/android/device_telephony_info.h new file mode 100644 index 0000000..84922d0 --- /dev/null +++ b/content/common/android/device_telephony_info.h @@ -0,0 +1,37 @@ +// Copyright (c) 2012 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. + +#ifndef CONTENT_COMMON_ANDROID_DEVICE_TELEPHONY_INFO_H_ +#define CONTENT_COMMON_ANDROID_DEVICE_TELEPHONY_INFO_H_ + +#include <jni.h> +#include <string> + +#include "base/android/scoped_java_ref.h" +#include "base/basictypes.h" + +namespace content { + +// Facilitates access to device information typically only +// available using the Android SDK, including Telephony properties. +class DeviceTelephonyInfo { + public: + DeviceTelephonyInfo(); + ~DeviceTelephonyInfo(); + + // Returns the ISO country code equivalent of the current MCC. + std::string GetNetworkCountryIso(); + + // Registers methods with JNI and returns true if succeeded. + static bool RegisterDeviceTelephonyInfo(JNIEnv* env); + + private: + base::android::ScopedJavaGlobalRef<jobject> j_device_info_; + + DISALLOW_COPY_AND_ASSIGN(DeviceTelephonyInfo); +}; + +} // namespace content + +#endif // CONTENT_COMMON_ANDROID_DEVICE_TELEPHONY_INFO_H_ diff --git a/content/content_common.gypi b/content/content_common.gypi index 4945c41..4629460 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -111,8 +111,8 @@ 'common/android/command_line.h', 'common/android/common_jni_registrar.cc', 'common/android/common_jni_registrar.h', - 'common/android/device_info.cc', - 'common/android/device_info.h', + 'common/android/device_telephony_info.cc', + 'common/android/device_telephony_info.h', 'common/android/hash_set.cc', 'common/android/hash_set.h', 'common/android/surface_callback.cc', diff --git a/content/content_jni.gypi b/content/content_jni.gypi index 607735b..7077e1f 100644 --- a/content/content_jni.gypi +++ b/content/content_jni.gypi @@ -30,7 +30,7 @@ 'public/android/java/src/org/chromium/content/browser/TracingIntentHandler.java', 'public/android/java/src/org/chromium/content/browser/WebContentsObserverAndroid.java', 'public/android/java/src/org/chromium/content/common/CommandLine.java', - 'public/android/java/src/org/chromium/content/common/DeviceInfo.java', + 'public/android/java/src/org/chromium/content/common/DeviceTelephonyInfo.java', 'public/android/java/src/org/chromium/content/common/SurfaceCallback.java', 'public/android/java/src/org/chromium/content/common/SurfaceTextureListener.java', 'public/android/java/src/org/chromium/content/common/TraceEvent.java', diff --git a/content/public/android/java/src/org/chromium/content/common/DeviceTelephonyInfo.java b/content/public/android/java/src/org/chromium/content/common/DeviceTelephonyInfo.java new file mode 100644 index 0000000..2c59e60 --- /dev/null +++ b/content/public/android/java/src/org/chromium/content/common/DeviceTelephonyInfo.java @@ -0,0 +1,42 @@ +// Copyright (c) 2012 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. + +package org.chromium.content.common; + +import android.content.Context; +import android.telephony.TelephonyManager; + +import org.chromium.base.CalledByNative; + +/** + * This class facilitates access to the current telephony region, + * typically only available using the Java SDK. + */ +public class DeviceTelephonyInfo { + + private TelephonyManager mTelManager; + + private DeviceTelephonyInfo(Context context) { + Context appContext = context.getApplicationContext(); + mTelManager = (TelephonyManager) appContext.getSystemService(Context.TELEPHONY_SERVICE); + } + + /** + * @return The ISO country code equivalent of the current MCC. + */ + @CalledByNative + public String getNetworkCountryIso() { + return mTelManager.getNetworkCountryIso(); + } + + /** + * Creates DeviceTelephonyInfo for a given Context. + * @param context A context to use. + * @return DeviceTelephonyInfo associated with a given Context. + */ + @CalledByNative + public static DeviceTelephonyInfo create(Context context) { + return new DeviceTelephonyInfo(context); + } +} diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ViewportTest.java b/content/public/android/javatests/src/org/chromium/content/browser/ViewportTest.java index f6361d7..9a6b3e3 100644 --- a/content/public/android/javatests/src/org/chromium/content/browser/ViewportTest.java +++ b/content/public/android/javatests/src/org/chromium/content/browser/ViewportTest.java @@ -13,7 +13,6 @@ import android.view.WindowManager; import org.chromium.base.test.util.Feature; import org.chromium.content.browser.test.util.JavaScriptUtils; import org.chromium.content.browser.test.util.TestCallbackHelperContainer; -import org.chromium.content.common.DeviceInfo; /** * Test suite for viewport-related properties. diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index 9d0a0b7..1656907 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -214,7 +214,7 @@ #include "webkit/plugins/npapi/webplugin_impl.h" #if defined(OS_ANDROID) -#include "content/common/android/device_info.h" +#include "content/common/android/device_telephony_info.h" #include "content/renderer/android/address_detector.h" #include "content/renderer/android/content_detector.h" #include "content/renderer/android/email_detector.h" @@ -665,12 +665,12 @@ RenderViewImpl::RenderViewImpl(RenderViewImplParams* params) const CommandLine& command_line = *CommandLine::ForCurrentProcess(); #if defined(OS_ANDROID) - scoped_ptr<DeviceInfo> device_info(new DeviceInfo()); + content::DeviceTelephonyInfo device_info; const std::string region_code = command_line.HasSwitch(switches::kNetworkCountryIso) ? command_line.GetSwitchValueASCII(switches::kNetworkCountryIso) - : device_info->GetNetworkCountryIso(); + : device_info.GetNetworkCountryIso(); content_detectors_.push_back(linked_ptr<ContentDetector>( new AddressDetector())); content_detectors_.push_back(linked_ptr<ContentDetector>( diff --git a/content/test/run_all_unittests.cc b/content/test/run_all_unittests.cc index 142192f..58de889 100644 --- a/content/test/run_all_unittests.cc +++ b/content/test/run_all_unittests.cc @@ -10,6 +10,7 @@ #include "content/browser/android/browser_jni_registrar.h" #include "content/common/android/common_jni_registrar.h" #include "net/android/net_jni_registrar.h" +#include "ui/android/ui_jni_registrar.h" #endif int main(int argc, char** argv) { @@ -20,6 +21,7 @@ int main(int argc, char** argv) { content::android::RegisterCommonJni(env); content::android::RegisterBrowserJni(env); net::android::RegisterJni(env); + ui::android::RegisterJni(env); #endif return content::UnitTestTestSuite( diff --git a/content/public/android/java/src/org/chromium/content/common/DeviceInfo.java b/ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java index ff7b2a6..61fc018 100644 --- a/content/public/android/java/src/org/chromium/content/common/DeviceInfo.java +++ b/ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -package org.chromium.content.common; +package org.chromium.ui.gfx; import android.content.Context; import android.graphics.PixelFormat; @@ -12,35 +12,44 @@ import android.view.Display; import android.view.WindowManager; import org.chromium.base.CalledByNative; +import org.chromium.base.JNINamespace; /** * This class facilitates access to android information typically only * available using the Java SDK, including {@link Display} properties. * * Currently the information consists of very raw display information (height, width, DPI scale) - * regarding the main display, and also the current telephony region. + * regarding the main display. */ -public class DeviceInfo { +@JNINamespace("gfx") +public class DeviceDisplayInfo { private WindowManager mWinManager; - private TelephonyManager mTelManager; - private DeviceInfo(Context context) { + private DeviceDisplayInfo(Context context) { Context appContext = context.getApplicationContext(); mWinManager = (WindowManager) appContext.getSystemService(Context.WINDOW_SERVICE); - mTelManager = (TelephonyManager) appContext.getSystemService(Context.TELEPHONY_SERVICE); } + /** + * @return Display height in physical pixels. + */ @CalledByNative - public int getHeight() { + public int getDisplayHeight() { return getMetrics().heightPixels; } + /** + * @return Display width in physical pixels. + */ @CalledByNative - public int getWidth() { + public int getDisplayWidth() { return getMetrics().widthPixels; } + /** + * @return Bits per pixel. + */ @CalledByNative public int getBitsPerPixel() { PixelFormat info = new PixelFormat(); @@ -48,6 +57,9 @@ public class DeviceInfo { return info.bitsPerPixel; } + /** + * @return Bits per component. + */ @CalledByNative public int getBitsPerComponent() { int format = getDisplay().getPixelFormat(); @@ -81,11 +93,18 @@ public class DeviceInfo { } } + /** + * @return A scaling factor for the Density Independent Pixel unit. + * 1.0 is 160dpi, 0.75 is 120dpi, 2.0 is 320dpi. + */ @CalledByNative - public double getDPIScale() { + public double getDIPScale() { return getMetrics().density; } + /** + * @return Display refresh rate in frames per second. + */ @CalledByNative public double getRefreshRate() { double result = getDisplay().getRefreshRate(); @@ -93,11 +112,6 @@ public class DeviceInfo { return (result >= 61 || result < 30) ? 0 : result; } - @CalledByNative - public String getNetworkCountryIso() { - return mTelManager.getNetworkCountryIso(); - } - private Display getDisplay() { return mWinManager.getDefaultDisplay(); } @@ -108,8 +122,13 @@ public class DeviceInfo { return metrics; } + /** + * Creates DeviceDisplayInfo for a given Context. + * @param context A context to use. + * @return DeviceDisplayInfo associated with a given Context. + */ @CalledByNative - public static DeviceInfo create(Context context) { - return new DeviceInfo(context); + public static DeviceDisplayInfo create(Context context) { + return new DeviceDisplayInfo(context); } } diff --git a/ui/android/ui_jni_registrar.cc b/ui/android/ui_jni_registrar.cc index 9ea0ef4..11daf36 100644 --- a/ui/android/ui_jni_registrar.cc +++ b/ui/android/ui_jni_registrar.cc @@ -6,14 +6,19 @@ #include "base/android/jni_android.h" #include "base/android/jni_registrar.h" +#include "ui/gfx/android/device_display_info.h" +#include "ui/gfx/android/java_bitmap.h" #include "ui/gfx/android/window_android.h" #include "ui/shell_dialogs/select_file_dialog_android.h" namespace ui { +namespace android { static base::android::RegistrationMethod kUiRegisteredMethods[] = { - { "NativeWindow", WindowAndroid::RegisterWindowAndroid }, - { "SelectFileDialog", SelectFileDialogImpl::RegisterSelectFileDialog }, + { "DeviceDisplayInfo", gfx::DeviceDisplayInfo::RegisterDeviceDisplayInfo }, + { "JavaBitmap", gfx::JavaBitmap::RegisterJavaBitmap }, + { "NativeWindow", ui::WindowAndroid::RegisterWindowAndroid }, + { "SelectFileDialog", ui::SelectFileDialogImpl::RegisterSelectFileDialog }, }; bool RegisterJni(JNIEnv* env) { @@ -21,4 +26,5 @@ bool RegisterJni(JNIEnv* env) { arraysize(kUiRegisteredMethods)); } -} // namespace ui +} // namespace android +} // namespace ui diff --git a/ui/android/ui_jni_registrar.h b/ui/android/ui_jni_registrar.h index d0778c4..f40ed40 100644 --- a/ui/android/ui_jni_registrar.h +++ b/ui/android/ui_jni_registrar.h @@ -10,10 +10,12 @@ #include "ui/base/ui_export.h" namespace ui { +namespace android { // Register all JNI bindings necessary for chrome. UI_EXPORT bool RegisterJni(JNIEnv* env); -} // namespace ui +} // namespace android +} // namespace ui #endif // UI_ANDROID_UI_JNI_REGISTRAR_H_ diff --git a/ui/base/layout.cc b/ui/base/layout.cc index 367dde3..23e70a9 100644 --- a/ui/base/layout.cc +++ b/ui/base/layout.cc @@ -64,11 +64,32 @@ bool UseTouchOptimizedUI() { } #endif // defined(OS_WIN) -const float kScaleFactorScales[] = {1.0f, 1.0f, 1.4f, 1.8f, 2.0f}; +const float kScaleFactorScales[] = {1.0f, 1.0f, 1.4f, 1.5f, 1.8f, 2.0f}; COMPILE_ASSERT(NUM_SCALE_FACTORS == arraysize(kScaleFactorScales), kScaleFactorScales_incorrect_size); const size_t kScaleFactorScalesLength = arraysize(kScaleFactorScales); +namespace { + +// Returns the scale factor closest to |scale| from the full list of factors. +// Note that it does NOT rely on the list of supported scale factors. +// Finding the closest match is inefficient and shouldn't be done frequently. +ScaleFactor FindClosestScaleFactorUnsafe(float scale) { + float smallest_diff = std::numeric_limits<float>::max(); + ScaleFactor closest_match = SCALE_FACTOR_100P; + for (int i = SCALE_FACTOR_100P; i < NUM_SCALE_FACTORS; ++i) { + const ScaleFactor scale_factor = static_cast<ScaleFactor>(i); + float diff = std::abs(kScaleFactorScales[scale_factor] - scale); + if (diff < smallest_diff) { + closest_match = scale_factor; + smallest_diff = diff; + } + } + return closest_match; +} + +} // namespace + std::vector<ScaleFactor>& GetSupportedScaleFactorsInternal() { static std::vector<ScaleFactor>* supported_scale_factors = new std::vector<ScaleFactor>(); @@ -78,7 +99,14 @@ std::vector<ScaleFactor>& GetSupportedScaleFactorsInternal() { supported_scale_factors->push_back(SCALE_FACTOR_100P); #endif -#if defined(OS_IOS) +#if defined(OS_ANDROID) + const gfx::Display display = + gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); + const float display_density = display.device_scale_factor(); + const ScaleFactor closest = FindClosestScaleFactorUnsafe(display_density); + if (closest != SCALE_FACTOR_100P) + supported_scale_factors->push_back(closest); +#elif defined(OS_IOS) gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); if (display.device_scale_factor() > 1.0) { DCHECK_EQ(2.0, display.device_scale_factor()); diff --git a/ui/base/layout.h b/ui/base/layout.h index 24663b7..eb150ff 100644 --- a/ui/base/layout.h +++ b/ui/base/layout.h @@ -39,6 +39,7 @@ enum ScaleFactor { SCALE_FACTOR_NONE = 0, SCALE_FACTOR_100P, SCALE_FACTOR_140P, + SCALE_FACTOR_150P, SCALE_FACTOR_180P, SCALE_FACTOR_200P, diff --git a/ui/base/layout_unittest.cc b/ui/base/layout_unittest.cc index 9cda5d5..8d135a2 100644 --- a/ui/base/layout_unittest.cc +++ b/ui/base/layout_unittest.cc @@ -17,6 +17,7 @@ namespace ui { TEST(LayoutTest, GetScaleFactorScale) { EXPECT_FLOAT_EQ(1.0f, GetScaleFactorScale(SCALE_FACTOR_100P)); EXPECT_FLOAT_EQ(1.4f, GetScaleFactorScale(SCALE_FACTOR_140P)); + EXPECT_FLOAT_EQ(1.5f, GetScaleFactorScale(SCALE_FACTOR_150P)); EXPECT_FLOAT_EQ(1.8f, GetScaleFactorScale(SCALE_FACTOR_180P)); EXPECT_FLOAT_EQ(2.0f, GetScaleFactorScale(SCALE_FACTOR_200P)); } @@ -58,8 +59,8 @@ TEST(LayoutTest, GetScaleFactorFromScaleAllSupported) { EXPECT_EQ(SCALE_FACTOR_140P, GetScaleFactorFromScale(1.21f)); EXPECT_EQ(SCALE_FACTOR_140P, GetScaleFactorFromScale(1.3f)); EXPECT_EQ(SCALE_FACTOR_140P, GetScaleFactorFromScale(1.4f)); - EXPECT_EQ(SCALE_FACTOR_140P, GetScaleFactorFromScale(1.59f)); - EXPECT_EQ(SCALE_FACTOR_180P, GetScaleFactorFromScale(1.61f)); + EXPECT_EQ(SCALE_FACTOR_150P, GetScaleFactorFromScale(1.59f)); + EXPECT_EQ(SCALE_FACTOR_150P, GetScaleFactorFromScale(1.61f)); EXPECT_EQ(SCALE_FACTOR_180P, GetScaleFactorFromScale(1.7f)); EXPECT_EQ(SCALE_FACTOR_180P, GetScaleFactorFromScale(1.89f)); EXPECT_EQ(SCALE_FACTOR_200P, GetScaleFactorFromScale(1.91f)); diff --git a/ui/gfx/android/device_display_info.cc b/ui/gfx/android/device_display_info.cc new file mode 100644 index 0000000..b6866a9 --- /dev/null +++ b/ui/gfx/android/device_display_info.cc @@ -0,0 +1,73 @@ +// Copyright (c) 2012 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. + +#include "ui/gfx/android/device_display_info.h" + +#include "base/android/jni_android.h" +#include "base/android/jni_string.h" +#include "base/logging.h" +#include "jni/DeviceDisplayInfo_jni.h" + +using base::android::AttachCurrentThread; +using base::android::ScopedJavaLocalRef; + +namespace gfx { + +DeviceDisplayInfo::DeviceDisplayInfo() { + JNIEnv* env = AttachCurrentThread(); + j_device_info_.Reset(Java_DeviceDisplayInfo_create(env, + base::android::GetApplicationContext())); +} + +DeviceDisplayInfo::~DeviceDisplayInfo() { +} + +int DeviceDisplayInfo::GetDisplayHeight() { + JNIEnv* env = AttachCurrentThread(); + jint result = + Java_DeviceDisplayInfo_getDisplayHeight(env, j_device_info_.obj()); + return static_cast<int>(result); +} + +int DeviceDisplayInfo::GetDisplayWidth() { + JNIEnv* env = AttachCurrentThread(); + jint result = + Java_DeviceDisplayInfo_getDisplayWidth(env, j_device_info_.obj()); + return static_cast<int>(result); +} + +int DeviceDisplayInfo::GetBitsPerPixel() { + JNIEnv* env = AttachCurrentThread(); + jint result = + Java_DeviceDisplayInfo_getBitsPerPixel(env, j_device_info_.obj()); + return static_cast<int>(result); +} + +int DeviceDisplayInfo::GetBitsPerComponent() { + JNIEnv* env = AttachCurrentThread(); + jint result = + Java_DeviceDisplayInfo_getBitsPerComponent(env, j_device_info_.obj()); + return static_cast<int>(result); +} + +double DeviceDisplayInfo::GetDIPScale() { + JNIEnv* env = AttachCurrentThread(); + jdouble result = + Java_DeviceDisplayInfo_getDIPScale(env, j_device_info_.obj()); + return static_cast<double>(result); +} + +double DeviceDisplayInfo::GetRefreshRate() { + JNIEnv* env = AttachCurrentThread(); + jdouble result = + Java_DeviceDisplayInfo_getRefreshRate(env, j_device_info_.obj()); + return static_cast<double>(result); +} + +// static +bool DeviceDisplayInfo::RegisterDeviceDisplayInfo(JNIEnv* env) { + return RegisterNativesImpl(env); +} + +} // namespace gfx diff --git a/ui/gfx/android/device_display_info.h b/ui/gfx/android/device_display_info.h new file mode 100644 index 0000000..f24b643 --- /dev/null +++ b/ui/gfx/android/device_display_info.h @@ -0,0 +1,54 @@ +// Copyright (c) 2012 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. + +#ifndef UI_GFX_ANDROID_DEVICE_DISPLAY_INFO_H_ +#define UI_GFX_ANDROID_DEVICE_DISPLAY_INFO_H_ + +#include <jni.h> +#include <string> + +#include "base/android/scoped_java_ref.h" +#include "base/basictypes.h" +#include "ui/base/ui_export.h" + +namespace gfx { + +// Facilitates access to device information typically only +// available using the Android SDK, including Display properties. +class UI_EXPORT DeviceDisplayInfo { + public: + DeviceDisplayInfo(); + ~DeviceDisplayInfo(); + + // Returns display height in physical pixels. + int GetDisplayHeight(); + + // Returns display width in physical pixels. + int GetDisplayWidth(); + + // Returns number of bits per pixel. + int GetBitsPerPixel(); + + // Returns number of bits per component. + int GetBitsPerComponent(); + + // Returns a scaling factor for Density Independent Pixel unit + // (1.0 is 160dpi, 0.75 is 120dpi, 2.0 is 320dpi). + double GetDIPScale(); + + // Returns display refresh rate in number of frames per second. + double GetRefreshRate(); + + // Registers methods with JNI and returns true if succeeded. + static bool RegisterDeviceDisplayInfo(JNIEnv* env); + + private: + base::android::ScopedJavaGlobalRef<jobject> j_device_info_; + + DISALLOW_COPY_AND_ASSIGN(DeviceDisplayInfo); +}; + +} // namespace gfx + +#endif // UI_GFX_ANDROID_DEVICE_DISPLAY_INFO_H_ diff --git a/ui/gfx/android/gfx_jni_registrar.cc b/ui/gfx/android/gfx_jni_registrar.cc deleted file mode 100644 index d4406c8..0000000 --- a/ui/gfx/android/gfx_jni_registrar.cc +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2012 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. - -#include "ui/gfx/android/gfx_jni_registrar.h" - -namespace gfx { - -void RegisterBitmapAndroid(JNIEnv* env); - -bool RegisterJni(JNIEnv* env) { - RegisterBitmapAndroid(env); - return true; -} - -} // namespace gfx diff --git a/ui/gfx/android/gfx_jni_registrar.h b/ui/gfx/android/gfx_jni_registrar.h deleted file mode 100644 index dc6f284..0000000 --- a/ui/gfx/android/gfx_jni_registrar.h +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) 2012 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. - -#ifndef UI_GFX_ANDROID_GFX_JNI_REGISTRAR_H_ -#define UI_GFX_ANDROID_GFX_JNI_REGISTRAR_H_ - -#include <jni.h> - -#include "ui/base/ui_export.h" - -namespace gfx { - -// Register all JNI bindings necessary for gfx. -UI_EXPORT bool RegisterJni(JNIEnv* env); - -} // namespace gfx - -#endif // UI_GFX_ANDROID_GFX_JNI_REGISTRAR_H_ diff --git a/ui/gfx/android/java_bitmap.cc b/ui/gfx/android/java_bitmap.cc index a0aff14..a19a000 100644 --- a/ui/gfx/android/java_bitmap.cc +++ b/ui/gfx/android/java_bitmap.cc @@ -35,8 +35,9 @@ JavaBitmap::~JavaBitmap() { DCHECK(!err); } -void RegisterBitmapAndroid(JNIEnv* env) { - ui::RegisterNativesImpl(env); +// static +bool JavaBitmap::RegisterJavaBitmap(JNIEnv* env) { + return ui::RegisterNativesImpl(env); } ScopedJavaLocalRef<jobject> CreateJavaBitmap(const gfx::Size& size) { diff --git a/ui/gfx/android/java_bitmap.h b/ui/gfx/android/java_bitmap.h index 061bb76..ac01653 100644 --- a/ui/gfx/android/java_bitmap.h +++ b/ui/gfx/android/java_bitmap.h @@ -5,6 +5,8 @@ #ifndef UI_GFX_ANDROID_JAVA_BITMAP_H_ #define UI_GFX_ANDROID_JAVA_BITMAP_H_ +#include <jni.h> + #include "base/android/scoped_java_ref.h" #include "ui/gfx/size.h" @@ -26,6 +28,9 @@ class UI_EXPORT JavaBitmap { inline int format() const { return format_; } inline uint32_t stride() const { return stride_; } + // Registers methods with JNI and returns true if succeeded. + static bool RegisterJavaBitmap(JNIEnv* env); + private: jobject bitmap_; void* pixels_; diff --git a/ui/gfx/screen_android.cc b/ui/gfx/screen_android.cc index bb8f01d..81d3bcf 100644 --- a/ui/gfx/screen_android.cc +++ b/ui/gfx/screen_android.cc @@ -5,7 +5,9 @@ #include "ui/gfx/screen.h" #include "base/logging.h" +#include "ui/gfx/android/device_display_info.h" #include "ui/gfx/display.h" +#include "ui/gfx/size_conversions.h" namespace gfx { @@ -27,8 +29,18 @@ class ScreenAndroid : public Screen { } gfx::Display GetPrimaryDisplay() const OVERRIDE { - NOTIMPLEMENTED() << "crbug.com/117839 tracks implementation"; - return gfx::Display(0, gfx::Rect(0, 0, 1, 1)); + gfx::DeviceDisplayInfo device_info; + const float device_scale_factor = device_info.GetDIPScale(); + const gfx::Rect bounds_in_pixels = + gfx::Rect( + device_info.GetDisplayWidth(), + device_info.GetDisplayHeight()); + const gfx::Rect bounds_in_dip = + gfx::Rect(gfx::ToCeiledSize(gfx::ScaleSize( + bounds_in_pixels.size(), 1.0f / device_scale_factor))); + gfx::Display display(0, bounds_in_dip); + display.set_device_scale_factor(device_scale_factor); + return display; } gfx::Display GetDisplayNearestWindow(gfx::NativeView view) const OVERRIDE { diff --git a/ui/test/test_suite.cc b/ui/test/test_suite.cc index 832a1ea..4d37214 100644 --- a/ui/test/test_suite.cc +++ b/ui/test/test_suite.cc @@ -12,6 +12,11 @@ #include "ui/base/ui_base_paths.h" #include "ui/gfx/gfx_paths.h" +#if defined(OS_ANDROID) +#include "base/android/jni_android.h" +#include "ui/android/ui_jni_registrar.h" +#endif + #if defined(OS_MACOSX) && !defined(OS_IOS) #include "base/mac/bundle_locations.h" #endif @@ -24,6 +29,11 @@ UITestSuite::UITestSuite(int argc, char** argv) : base::TestSuite(argc, argv) {} void UITestSuite::Initialize() { base::TestSuite::Initialize(); +#if defined(OS_ANDROID) + // Register JNI bindings for android. + ui::android::RegisterJni(base::android::AttachCurrentThread()); +#endif + ui::RegisterPathProvider(); gfx::RegisterPathProvider(); @@ -324,8 +324,8 @@ 'base/x/x11_util.cc', 'base/x/x11_util.h', 'base/x/x11_util_internal.h', - 'gfx/android/gfx_jni_registrar.cc', - 'gfx/android/gfx_jni_registrar.h', + 'gfx/android/device_display_info.cc', + 'gfx/android/device_display_info.h', 'gfx/android/java_bitmap.cc', 'gfx/android/java_bitmap.h', 'gfx/android/window_android.cc', @@ -853,6 +853,7 @@ 'type': 'none', 'sources': [ 'android/java/src/org/chromium/ui/gfx/BitmapHelper.java', + 'android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java', 'android/java/src/org/chromium/ui/gfx/NativeWindow.java', 'android/java/src/org/chromium/ui/SelectFileDialog.java', ], |