Chromium Code Reviews| Index: ui/base/scale.cc |
| diff --git a/ui/base/scale.cc b/ui/base/scale.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ab27386a3e33289dbe78aae39544cfe5f4b1e307 |
| --- /dev/null |
| +++ b/ui/base/scale.cc |
| @@ -0,0 +1,79 @@ |
| +// 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/base/scale.h" |
| + |
| +#include "base/basictypes.h" |
| + |
| +#if defined(OS_WIN) |
| +#include "ui/base/win/dpi.h" |
| +#include <Windows.h> |
| +#endif // defined(OS_WIN) |
| + |
| +namespace { |
| + |
| +#if defined(OS_WIN) |
| + |
| +// TODO(joi): Pick this function up from somewhere central. |
| +bool IsInMetroMode() { |
|
sail
2012/04/18 16:44:14
I've added a new metro.h file in this CL:
http://c
Jói
2012/04/18 17:06:31
Updated my patch of your change and switched to us
|
| + const char* kMetroModeEnvVar = "CHROME_METRO_DLL"; |
| + char buffer[2]; |
| + if (!::GetEnvironmentVariableA(kMetroModeEnvVar, buffer, arraysize(buffer))) |
| + return false; |
| + return buffer == std::string("1"); |
| +} |
| + |
| +void GetScaleImplWin(bool* use_metro, bool* use_hidpi) { |
| +#if defined(ENABLE_METRO) |
| + *use_metro = IsInMetroMode(); |
| +#endif // defined(ENABLE_METRO) |
| +#if defined(ENABLE_HIDPI) |
| + *use_hidpi = ui::GetDPIScale() > 1.5; |
| +#endif // defined(ENABLE_HIDPI) |
| +} |
| + |
| +#endif // defined(OS_WIN) |
| + |
| +} // namespace |
| + |
| +namespace ui { |
| + |
| +const DisplayScale GetThemeScale() { |
| +#if defined(USE_ASH) |
| + return DS_ASH; |
| +#elif !defined(OS_WIN) |
| + return DS_DESKTOP_100; |
| +#else // On Windows. |
| + bool use_metro = false; |
| + bool use_hidpi = false; |
| + GetScaleImplWin(&use_metro, &use_hidpi); |
| + if (use_metro) { |
| + // TODO(joi): Other Metro scales. |
| + return DS_METRO_100; |
| + } else if (use_hidpi) { |
| + return DS_DESKTOP_200; |
| + } else { |
| + return DS_DESKTOP_100; |
| + } |
| +#endif // On Windows. |
| +} |
| + |
| +const DisplayScale GetUIScale() { |
| +#if defined(USE_ASH) |
| + return DS_ASH; |
| +#elif !defined(OS_WIN) |
| + return DS_DESKTOP_100; |
| +#else // On Windows. |
| + bool use_metro = false; |
| + bool use_hidpi = false; |
| + GetScaleImplWin(&use_metro, &use_hidpi); |
| + if (use_hidpi) { |
| + return DS_DESKTOP_200; |
| + } else { |
| + return DS_DESKTOP_100; |
| + } |
| +#endif // On Windows. |
| +} |
| + |
| +} // namespace ui |