Commit 8b3b3615 authored by oshima@chromium.org's avatar oshima@chromium.org

Get the default device scale factor from monitor

BUG=none
TEST=none


Review URL: http://codereview.chromium.org/10255020

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134677 0039d316-1c4b-4281-b951-d872f2087c98
parent 73843519
......@@ -6,7 +6,6 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/memory/weak_ptr.h"
#include "base/string_number_conversions.h"
......@@ -18,7 +17,6 @@
#include "content/common/gpu/gpu_messages.h"
#include "content/port/browser/render_widget_host_view_port.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/content_switches.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderline.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
......@@ -126,19 +124,10 @@ void GetScreenInfoForWindow(WebKit::WebScreenInfo* results,
const gfx::Size size = monitor.size();
results->rect = WebKit::WebRect(0, 0, size.width(), size.height());
results->availableRect = results->rect;
// TODO(derat): Don't hardcode this?
// TODO(derat|oshima): Don't hardcode this. Get this from monitor object.
results->depth = 24;
results->depthPerComponent = 8;
int default_dpi = monitor.device_scale_factor() * 160;
// TODO(fsamuel): This is a temporary hack until Monitor code is complete.
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kDefaultDeviceScaleFactor)) {
int default_device_scale_factor;
base::StringToInt(command_line.GetSwitchValueASCII(
switches::kDefaultDeviceScaleFactor),
&default_device_scale_factor);
default_dpi = default_device_scale_factor * 160;
}
results->verticalDPI = default_dpi;
results->horizontalDPI = default_dpi;
}
......
......@@ -58,6 +58,8 @@
#include "content/public/common/content_restriction.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "ui/gfx/monitor.h"
#include "ui/gfx/screen.h"
#include "net/base/mime_util.h"
#include "net/base/net_util.h"
#include "net/base/network_change_notifier.h"
......@@ -74,6 +76,7 @@
#include "content/browser/web_contents/web_contents_view_gtk.h"
#elif defined(OS_MACOSX)
#include "content/browser/web_contents/web_contents_view_mac.h"
#include "ui/base/ui_base_switches.h"
#include "ui/gfx/surface/io_surface_support_mac.h"
#elif defined(OS_ANDROID)
#include "content/browser/web_contents/web_contents_view_android.h"
......@@ -504,13 +507,24 @@ WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
prefs.accelerated_compositing_enabled = false;
prefs.accelerated_2d_canvas_enabled = false;
}
#if defined(OS_MACOSX)
// Mac doesn't have gfx::Screen::GetMonitorNearestWindow impl.
// crbug.com/125690.
int default_device_scale_factor;
base::StringToInt(command_line.GetSwitchValueASCII(
switches::kDefaultDeviceScaleFactor),
&default_device_scale_factor);
prefs.default_device_scale_factor = default_device_scale_factor;
#else
if (rvh->GetView()) {
gfx::Monitor monitor = gfx::Screen::GetMonitorNearestWindow(
rvh->GetView()->GetNativeView());
prefs.default_device_scale_factor =
static_cast<int>(monitor.device_scale_factor());
} else {
prefs.default_device_scale_factor = 1;
}
#endif
content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
......
......@@ -36,10 +36,6 @@ const char kBrowserSubprocessPath[] = "browser-subprocess-path";
// as a dependent process of the Chrome Frame plugin.
const char kChromeFrame[] = "chrome-frame";
// The default device scale factor to apply to contents in the absence of
// a viewport meta tag.
const char kDefaultDeviceScaleFactor[] = "default-device-scale-factor";
// Disables client-visible 3D APIs, in particular WebGL and Pepper 3D.
// This is controlled by policy and is kept separate from the other
// enable/disable switches to avoid accidentally regressing the policy
......
......@@ -23,7 +23,6 @@ CONTENT_EXPORT extern const char kBrowserCrashTest[];
CONTENT_EXPORT extern const char kBrowserSubprocessPath[];
// TODO(jam): this doesn't belong in content.
CONTENT_EXPORT extern const char kChromeFrame[];
CONTENT_EXPORT extern const char kDefaultDeviceScaleFactor[];
CONTENT_EXPORT extern const char kDisable3DAPIs[];
CONTENT_EXPORT extern const char kDisableAccelerated2dCanvas[];
CONTENT_EXPORT extern const char kDisableAcceleratedCompositing[];
......
......@@ -32,7 +32,7 @@ gfx::Monitor MonitorManager::CreateMonitorFromSpec(const std::string& spec) {
gfx::Rect bounds(kDefaultHostWindowX, kDefaultHostWindowY,
kDefaultHostWindowWidth, kDefaultHostWindowHeight);
int x = 0, y = 0, width, height;
float scale = 1.0f;
float scale = gfx::Monitor::GetDefaultDeviceScaleFactor();
if (sscanf(spec.c_str(), "%dx%d*%f", &width, &height, &scale) >= 2) {
bounds.set_size(gfx::Size(width, height));
} else if (sscanf(spec.c_str(), "%d+%d-%dx%d*%f", &x, &y, &width, &height,
......
......@@ -42,6 +42,8 @@ class AURA_EXPORT MonitorManager {
// The location can be omitted and be just "1440x800", which creates
// monitor at the origin of the screen. An empty string creates
// the monitor with default size.
// The device scale factor can be specified by "*", like "1280x780*2",
// or |gfx::Monitor::GetDefaultDeviceScaleFactor()| will be used if omitted.
static gfx::Monitor CreateMonitorFromSpec(const std::string& spec);
// A utility function to create a root window for primary monitor.
......
......@@ -6,6 +6,10 @@
namespace switches {
// The default device scale factor to apply to the browser UI and
// the contents in the absence of a viewport meta tag.
const char kDefaultDeviceScaleFactor[] = "default-device-scale-factor";
// Enable support for touch events.
const char kEnableTouchEvents[] = "enable-touch-events";
......
......@@ -13,6 +13,7 @@
namespace switches {
UI_EXPORT extern const char kDefaultDeviceScaleFactor[];
UI_EXPORT extern const char kEnableTouchEvents[];
UI_EXPORT extern const char kLang[];
UI_EXPORT extern const char kLocalePak[];
......
......@@ -4,22 +4,52 @@
#include "ui/gfx/monitor.h"
#include "ui/gfx/insets.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/string_number_conversions.h"
#include "base/stringprintf.h"
#include "ui/base/ui_base_switches.h"
#include "ui/gfx/insets.h"
namespace gfx {
namespace {
float GetDefaultDeviceScaleFactorImpl() {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
double scale_in_double = 1.0;
if (command_line.HasSwitch(switches::kDefaultDeviceScaleFactor)) {
std::string value =
command_line.GetSwitchValueASCII(switches::kDefaultDeviceScaleFactor);
if (!base::StringToDouble(value, &scale_in_double))
LOG(ERROR) << "Failed to parse the deafult device scale factor:" << value;
}
return static_cast<float>(scale_in_double);
}
Monitor::Monitor() : id_(-1), device_scale_factor_(1.0) {
} // namespace
// static
float Monitor::GetDefaultDeviceScaleFactor() {
static const float kDefaultDeviceScaleFactor =
GetDefaultDeviceScaleFactorImpl();
return kDefaultDeviceScaleFactor;
}
Monitor::Monitor()
: id_(-1),
device_scale_factor_(GetDefaultDeviceScaleFactor()) {
}
Monitor::Monitor(int id) : id_(id), device_scale_factor_(1.0) {
Monitor::Monitor(int id)
: id_(id),
device_scale_factor_(GetDefaultDeviceScaleFactor()) {
}
Monitor::Monitor(int id, const gfx::Rect& bounds)
: id_(id),
bounds_(bounds),
work_area_(bounds),
device_scale_factor_(1.0) {
device_scale_factor_(GetDefaultDeviceScaleFactor()) {
#if defined(USE_ASH)
SetScaleAndBounds(device_scale_factor_, bounds);
#endif
......
......@@ -20,6 +20,10 @@ namespace gfx {
// TODO(oshima): Update the comment when ENABLE_DIP macro is removed.
class UI_EXPORT Monitor {
public:
// Returns the default value for the device scale factor, which is
// given by "--default-device-scale-factor".
static float GetDefaultDeviceScaleFactor();
// Creates a monitor with invalid id(-1) as default.
Monitor();
explicit Monitor(int id);
......
......@@ -6,6 +6,7 @@
#define UI_GFX_SCREEN_H_
#pragma once
#include "ui/base/ui_export.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/monitor.h"
#include "ui/gfx/point.h"
......
......@@ -15,6 +15,11 @@ gfx::Monitor Screen::GetPrimaryMonitor() {
return gfx::Monitor(0, gfx::Rect(0, 0, 1, 1));
}
// static
gfx::Monitor Screen::GetMonitorNearestWindow(gfx::NativeView view) {
return GetPrimaryMonitor();
}
// static
int Screen::GetNumMonitors() {
return 1;
......
......@@ -57,7 +57,7 @@ gfx::Rect NativePrimaryMonitorBounds() {
gfx::Rect GetMonitorAreaNearestWindow(gfx::NativeView view) {
GdkScreen* screen = gdk_screen_get_default();
gint monitor_num = 0;
if (view) {
if (view && GTK_IS_WINDOW(view)) {
GtkWidget* top_level = gtk_widget_get_toplevel(view);
DCHECK(GTK_IS_WINDOW(top_level));
GtkWindow* window = GTK_WINDOW(top_level);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment