Add shortcut keys to ui scaling
- Round root window size because it can be fractional size when root_window_scale_ is specified. - Remove scaling option from about:flags. - Rotate display where the mouse is in. BUG=179997,119268 Review URL: https://chromiumcodereview.appspot.com/12848004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188324 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
@ -154,7 +154,7 @@ bool HandleRotateActiveWindow() {
|
||||
return true;
|
||||
}
|
||||
|
||||
const gfx::Display::Rotation GetNextRotation(gfx::Display::Rotation current) {
|
||||
gfx::Display::Rotation GetNextRotation(gfx::Display::Rotation current) {
|
||||
switch (current) {
|
||||
case gfx::Display::ROTATE_0:
|
||||
return gfx::Display::ROTATE_90;
|
||||
@ -169,13 +169,40 @@ const gfx::Display::Rotation GetNextRotation(gfx::Display::Rotation current) {
|
||||
return gfx::Display::ROTATE_0;
|
||||
}
|
||||
|
||||
float GetNextScale(float scale, int next) {
|
||||
// These scales are equivalent to 1024, 1280, 1600 and 1920 pixel width
|
||||
// respectively on 2560 pixel width 2x density display.
|
||||
static const float kScales[] = {0.8f, 1.0f, 1.25f, 1.5f};
|
||||
static const int kScaleTableSize = arraysize(kScales);
|
||||
int index = std::distance(kScales, std::find(kScales,
|
||||
kScales + kScaleTableSize,
|
||||
scale));
|
||||
// Fallback to 1.0f if the |scale| wasn't in the list.
|
||||
index = index == kScaleTableSize ? 1 : index + next;
|
||||
return kScales[std::max(std::min(kScaleTableSize - 1, index), 0)];
|
||||
}
|
||||
|
||||
bool HandleScaleUI(bool up) {
|
||||
// UI Scaling is effective only on internal display.
|
||||
int64 display_id = gfx::Display::InternalDisplayId();
|
||||
#if defined(OS_CHROMEOS)
|
||||
// On linux desktop, allow ui scaling on the first dislpay.
|
||||
if (!base::chromeos::IsRunningOnChromeOS())
|
||||
display_id = Shell::GetInstance()->display_manager()->first_display_id();
|
||||
#endif
|
||||
const gfx::Display& display = Shell::GetInstance()->display_manager()->
|
||||
GetDisplayForId(display_id);
|
||||
const DisplayInfo& display_info = Shell::GetInstance()->display_manager()->
|
||||
GetDisplayInfo(display);
|
||||
Shell::GetInstance()->display_manager()->SetDisplayUIScale(
|
||||
display.id(), GetNextScale(display_info.ui_scale(), up ? 1 : -1));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Rotates the screen.
|
||||
bool HandleRotateScreen() {
|
||||
aura::Window* active_window = wm::GetActiveWindow();
|
||||
if (!active_window)
|
||||
return false;
|
||||
const gfx::Display& display =
|
||||
Shell::GetScreen()->GetDisplayNearestWindow(active_window);
|
||||
gfx::Point point = Shell::GetScreen()->GetCursorScreenPoint();
|
||||
gfx::Display display = Shell::GetScreen()->GetDisplayNearestPoint(point);
|
||||
const DisplayInfo& display_info =
|
||||
Shell::GetInstance()->display_manager()->GetDisplayInfo(display);
|
||||
Shell::GetInstance()->display_manager()->SetDisplayRotation(
|
||||
@ -758,6 +785,10 @@ bool AcceleratorController::PerformAction(int action,
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SCALE_UI_UP:
|
||||
return HandleScaleUI(true /* up */);
|
||||
case SCALE_UI_DOWN:
|
||||
return HandleScaleUI(false /* down */);
|
||||
case ROTATE_WINDOW:
|
||||
return HandleRotateActiveWindow();
|
||||
case ROTATE_SCREEN:
|
||||
@ -767,7 +798,7 @@ bool AcceleratorController::PerformAction(int action,
|
||||
case TOGGLE_ROOT_WINDOW_FULL_SCREEN:
|
||||
return HandleToggleRootWindowFullScreen();
|
||||
case DISPLAY_TOGGLE_SCALE:
|
||||
internal::DisplayManager::ToggleDisplayScale();
|
||||
internal::DisplayManager::ToggleDisplayScaleFactor();
|
||||
return true;
|
||||
case MAGNIFY_SCREEN_ZOOM_IN:
|
||||
return HandleMagnifyScreen(1);
|
||||
|
@ -77,7 +77,11 @@ const AcceleratorData kAcceleratorData[] = {
|
||||
// Extra shortcut to lock the screen on linux desktop.
|
||||
{ true, ui::VKEY_POWER, ui::EF_SHIFT_DOWN, LOCK_PRESSED },
|
||||
{ false, ui::VKEY_POWER, ui::EF_SHIFT_DOWN, LOCK_RELEASED },
|
||||
// Extra shortcut to rotate/scale up/down the screen on linux desktop.
|
||||
{ true, ui::VKEY_F3, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, ROTATE_SCREEN },
|
||||
{ true, ui::VKEY_F2, ui::EF_CONTROL_DOWN , SCALE_UI_UP },
|
||||
{ true, ui::VKEY_F2,
|
||||
ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN, SCALE_UI_DOWN },
|
||||
#endif // !defined(NDEBUG)
|
||||
{ true, ui::VKEY_O, ui::EF_CONTROL_DOWN, OPEN_FILE_DIALOG },
|
||||
{ true, ui::VKEY_M, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN,
|
||||
@ -101,6 +105,10 @@ const AcceleratorData kAcceleratorData[] = {
|
||||
NEW_INCOGNITO_WINDOW },
|
||||
{ true, ui::VKEY_N, ui::EF_CONTROL_DOWN, NEW_WINDOW },
|
||||
{ true, ui::VKEY_T, ui::EF_CONTROL_DOWN, NEW_TAB },
|
||||
{ true, ui::VKEY_BROWSER_BACK,
|
||||
ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN, SCALE_UI_UP },
|
||||
{ true, ui::VKEY_BROWSER_FORWARD,
|
||||
ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN, SCALE_UI_DOWN },
|
||||
{ true, ui::VKEY_BROWSER_REFRESH,
|
||||
ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN, ROTATE_SCREEN },
|
||||
{ true, ui::VKEY_BROWSER_REFRESH,
|
||||
@ -129,7 +137,8 @@ const AcceleratorData kAcceleratorData[] = {
|
||||
{ true, ui::VKEY_F14, ui::EF_NONE, SHOW_KEYBOARD_OVERLAY },
|
||||
{ true, ui::VKEY_N, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN,
|
||||
SHOW_MESSAGE_CENTER_BUBBLE },
|
||||
{ true, ui::VKEY_BROWSER_BACK, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN,
|
||||
{ true, ui::VKEY_BROWSER_BACK,
|
||||
ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN,
|
||||
SHOW_OAK },
|
||||
{ true, ui::VKEY_S, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN,
|
||||
SHOW_SYSTEM_TRAY_BUBBLE },
|
||||
@ -228,6 +237,8 @@ const AcceleratorAction kActionsAllowedAtLoginOrLockScreen[] = {
|
||||
VOLUME_UP,
|
||||
ROTATE_SCREEN,
|
||||
ROTATE_WINDOW,
|
||||
SCALE_UI_UP,
|
||||
SCALE_UI_DOWN,
|
||||
#if !defined(NDEBUG)
|
||||
PRINT_LAYER_HIERARCHY,
|
||||
PRINT_VIEW_HIERARCHY,
|
||||
@ -294,6 +305,8 @@ const AcceleratorAction kNonrepeatableActions[] = {
|
||||
CYCLE_FORWARD_MRU,
|
||||
ROTATE_SCREEN,
|
||||
ROTATE_WINDOW,
|
||||
SCALE_UI_UP,
|
||||
SCALE_UI_DOWN,
|
||||
TOGGLE_MAXIMIZED,
|
||||
WINDOW_MINIMIZE,
|
||||
};
|
||||
@ -321,6 +334,8 @@ const AcceleratorAction kActionsAllowedInAppMode[] = {
|
||||
POWER_RELEASED,
|
||||
PREVIOUS_IME,
|
||||
ROTATE_SCREEN,
|
||||
SCALE_UI_UP,
|
||||
SCALE_UI_DOWN,
|
||||
SWAP_PRIMARY_DISPLAY,
|
||||
SWITCH_IME, // Switch to another IME depending on the accelerator.
|
||||
TOGGLE_CAPS_LOCK,
|
||||
|
@ -47,6 +47,8 @@ enum AcceleratorAction {
|
||||
RESTORE_TAB,
|
||||
ROTATE_SCREEN,
|
||||
ROTATE_WINDOW,
|
||||
SCALE_UI_DOWN,
|
||||
SCALE_UI_UP,
|
||||
SELECT_LAST_WIN,
|
||||
SELECT_WIN_0,
|
||||
SELECT_WIN_1,
|
||||
|
@ -61,6 +61,12 @@ const char kAshDisablePerAppLauncher[] = "ash-disable-per-app-launcher";
|
||||
// Disables immersive fullscreen mode.
|
||||
const char kAshDisableImmersiveMode[] = "ash-disable-immersive-mode";
|
||||
|
||||
// Disables display rotation.
|
||||
const char kAshDisableDisplayRotation[] = "ash-disable-display-rotation";
|
||||
|
||||
// Disables ui scaling.
|
||||
const char kAshDisableUIScaling[] = "ash-disable-ui-scaling";
|
||||
|
||||
// Enable advanced gestures (e.g. for window management).
|
||||
const char kAshEnableAdvancedGestures[] = "ash-enable-advanced-gestures";
|
||||
|
||||
|
@ -31,6 +31,8 @@ ASH_EXPORT extern const char kAshDisableLauncherPerDisplay[];
|
||||
ASH_EXPORT extern const char kAshDisableNewLockAnimations[];
|
||||
ASH_EXPORT extern const char kAshDisableNewNetworkStatusArea[];
|
||||
ASH_EXPORT extern const char kAshDisablePerAppLauncher[];
|
||||
ASH_EXPORT extern const char kAshDisableUIScaling[];
|
||||
ASH_EXPORT extern const char kAshDisableDisplayRotation[];
|
||||
ASH_EXPORT extern const char kAshEnableAdvancedGestures[];
|
||||
ASH_EXPORT extern const char kAshEnableBrightnessControl[];
|
||||
#if defined(OS_LINUX)
|
||||
|
@ -102,7 +102,7 @@ void DisplayManager::CycleDisplay() {
|
||||
}
|
||||
|
||||
// static
|
||||
void DisplayManager::ToggleDisplayScale() {
|
||||
void DisplayManager::ToggleDisplayScaleFactor() {
|
||||
Shell::GetInstance()->display_manager()->ScaleDisplayImpl();
|
||||
}
|
||||
|
||||
@ -173,6 +173,8 @@ void DisplayManager::ClearCustomOverscanInsets(int64 display_id) {
|
||||
|
||||
void DisplayManager::SetDisplayRotation(int64 display_id,
|
||||
gfx::Display::Rotation rotation) {
|
||||
if (!IsDisplayRotationEnabled())
|
||||
return;
|
||||
DisplayInfoList display_info_list;
|
||||
for (DisplayList::const_iterator iter = displays_.begin();
|
||||
iter != displays_.end(); ++iter) {
|
||||
@ -184,6 +186,44 @@ void DisplayManager::SetDisplayRotation(int64 display_id,
|
||||
UpdateDisplays(display_info_list);
|
||||
}
|
||||
|
||||
void DisplayManager::SetDisplayUIScale(int64 display_id,
|
||||
float ui_scale) {
|
||||
if (!IsDisplayUIScalingEnabled())
|
||||
return;
|
||||
DisplayInfoList display_info_list;
|
||||
for (DisplayList::const_iterator iter = displays_.begin();
|
||||
iter != displays_.end(); ++iter) {
|
||||
DisplayInfo info = GetDisplayInfo(*iter);
|
||||
if (info.id() == display_id)
|
||||
info.set_ui_scale(ui_scale);
|
||||
display_info_list.push_back(info);
|
||||
}
|
||||
UpdateDisplays(display_info_list);
|
||||
}
|
||||
|
||||
|
||||
bool DisplayManager::IsDisplayRotationEnabled() const {
|
||||
static bool enabled = !CommandLine::ForCurrentProcess()->
|
||||
HasSwitch(switches::kAshDisableDisplayRotation);
|
||||
return enabled;
|
||||
}
|
||||
|
||||
bool DisplayManager::IsDisplayUIScalingEnabled() const {
|
||||
static bool enabled = !CommandLine::ForCurrentProcess()->
|
||||
HasSwitch(switches::kAshDisableUIScaling);
|
||||
if (!enabled)
|
||||
return false;
|
||||
// UI Scaling is effective only when the internal display has
|
||||
// 2x density (currently Pixel).
|
||||
int64 display_id = gfx::Display::InternalDisplayId();
|
||||
#if defined(OS_CHROMEOS)
|
||||
// On linux desktop, allow ui scaling on the first dislpay.
|
||||
if (!base::chromeos::IsRunningOnChromeOS())
|
||||
display_id = Shell::GetInstance()->display_manager()->first_display_id();
|
||||
#endif
|
||||
return GetDisplayForId(display_id).device_scale_factor() == 2.0f;
|
||||
}
|
||||
|
||||
gfx::Insets DisplayManager::GetOverscanInsets(int64 display_id) const {
|
||||
std::map<int64, DisplayInfo>::const_iterator it =
|
||||
display_info_.find(display_id);
|
||||
|
@ -43,7 +43,7 @@ class ASH_EXPORT DisplayManager : public aura::RootWindowObserver {
|
||||
// Used to emulate display change when run in a desktop environment instead
|
||||
// of on a device.
|
||||
static void CycleDisplay();
|
||||
static void ToggleDisplayScale();
|
||||
static void ToggleDisplayScaleFactor();
|
||||
|
||||
// When set to true, the MonitorManager calls OnDisplayBoundsChanged
|
||||
// even if the display's bounds didn't change. Used to swap primary
|
||||
@ -86,6 +86,13 @@ class ASH_EXPORT DisplayManager : public aura::RootWindowObserver {
|
||||
// Sets the display's rotation.
|
||||
void SetDisplayRotation(int64 display_id, gfx::Display::Rotation rotation);
|
||||
|
||||
// Sets the display's ui scale.
|
||||
void SetDisplayUIScale(int64 display_id, float ui_scale);
|
||||
|
||||
// Tells if display rotation/ui scaling features are enabled.
|
||||
bool IsDisplayRotationEnabled() const;
|
||||
bool IsDisplayUIScalingEnabled() const;
|
||||
|
||||
// Returns the current overscan insets for the specified |display_id|.
|
||||
// Returns an empty insets (0, 0, 0, 0) if no insets are specified for
|
||||
// the display.
|
||||
|
@ -6877,24 +6877,6 @@ Keep your key file in a safe place. You will need it to create new versions of y
|
||||
<message name="IDS_FLAGS_ENABLE_EXPERIMENTAL_BLUETOOTH_DESCRIPTION" desc="Description for the flag to enable experimental Bluetooth features.">
|
||||
Enable experimental Bluetooth features.
|
||||
</message>
|
||||
<message name="IDS_FLAGS_ASH_INTERNAL_DISPLAY_SCALE_DESCRIPTION" desc="Description for the flag to specify the UI scale of the internal display.">
|
||||
Specify the UI scale of the intenral display.
|
||||
</message>
|
||||
<message name="IDS_FLAGS_ASH_INTERNAL_DISPLAY_SCALE_NAME" desc="Name for the flag to specify the UI scale of the internal display.">
|
||||
UI scale of the internal display.
|
||||
</message>
|
||||
<message name="IDS_FLAGS_ASH_INTERNAL_DISPLAY_SCALE_DEFAULT" desc="">
|
||||
Default (1.0x)
|
||||
</message>
|
||||
<message name="IDS_FLAGS_ASH_INTERNAL_DISPLAY_SCALE_125" desc="">
|
||||
1.25x
|
||||
</message>
|
||||
<message name="IDS_FLAGS_ASH_INTERNAL_DISPLAY_SCALE_150" desc="">
|
||||
1.5x
|
||||
</message>
|
||||
<message name="IDS_FLAGS_ASH_INTERNAL_DISPLAY_SCALE_80" desc="">
|
||||
0.8x
|
||||
</message>
|
||||
</if>
|
||||
<message name="IDS_FLAGS_FULL_HISTORY_SYNC_NAME" desc="Name of the flag to enable full history sync.">
|
||||
Enable full history sync.
|
||||
|
@ -187,16 +187,6 @@ const Experiment::Choice kChromeCaptivePortalDetectionChoices[] = {
|
||||
switches::kDisableChromeCaptivePortalDetector, ""}
|
||||
};
|
||||
|
||||
const Experiment::Choice kAshInternalDisplayUIScaleChoices[] = {
|
||||
{ IDS_FLAGS_ASH_INTERNAL_DISPLAY_SCALE_DEFAULT, "", "" },
|
||||
{ IDS_FLAGS_ASH_INTERNAL_DISPLAY_SCALE_80,
|
||||
ash::switches::kAshInternalDisplayUIScale, "0.8"},
|
||||
{ IDS_FLAGS_ASH_INTERNAL_DISPLAY_SCALE_125,
|
||||
ash::switches::kAshInternalDisplayUIScale, "1.25"},
|
||||
{ IDS_FLAGS_ASH_INTERNAL_DISPLAY_SCALE_150,
|
||||
ash::switches::kAshInternalDisplayUIScale, "1.5"},
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
const Experiment::Choice kImplSidePaintingChoices[] = {
|
||||
@ -1009,13 +999,6 @@ const Experiment kExperiments[] = {
|
||||
kOsCrOS,
|
||||
SINGLE_VALUE_TYPE(switches::kForceFullscreenApp),
|
||||
},
|
||||
{
|
||||
"ash-internal-display-ui-scale",
|
||||
IDS_FLAGS_ASH_INTERNAL_DISPLAY_SCALE_NAME,
|
||||
IDS_FLAGS_ASH_INTERNAL_DISPLAY_SCALE_DESCRIPTION,
|
||||
kOsCrOS,
|
||||
MULTI_VALUE_TYPE(kAshInternalDisplayUIScaleChoices)
|
||||
},
|
||||
#endif // defined(OS_CHROMEOS)
|
||||
{
|
||||
"views-textfield",
|
||||
|
@ -36,8 +36,8 @@
|
||||
#include "ui/gfx/display.h"
|
||||
#include "ui/gfx/point3_f.h"
|
||||
#include "ui/gfx/point_conversions.h"
|
||||
#include "ui/gfx/rect_conversions.h"
|
||||
#include "ui/gfx/screen.h"
|
||||
#include "ui/gfx/size_conversions.h"
|
||||
|
||||
using std::vector;
|
||||
|
||||
@ -771,7 +771,6 @@ void RootWindow::UpdateWindowSize(const gfx::Size& host_size) {
|
||||
bounds = ui::ConvertRectToDIP(layer(), bounds);
|
||||
gfx::RectF new_bounds(bounds);
|
||||
layer()->transform().TransformRect(&new_bounds);
|
||||
|
||||
// It makes little sense to scale beyond the original
|
||||
// resolution.
|
||||
DCHECK_LE(root_window_scale_, GetDeviceScaleFactor());
|
||||
@ -782,7 +781,10 @@ void RootWindow::UpdateWindowSize(const gfx::Size& host_size) {
|
||||
new_bounds.Scale(root_window_scale_ * root_window_scale_);
|
||||
// Ignore the origin because RootWindow's insets are handled by
|
||||
// the transform.
|
||||
SetBounds(gfx::Rect(gfx::ToNearestRect(new_bounds).size()));
|
||||
// Round the size because the bounds is no longer aligned to
|
||||
// backing pixel when |root_window_scale_| is specified
|
||||
// (850 height at 1.25 scale becomes 1062.5 for example.)
|
||||
SetBounds(gfx::Rect(gfx::ToRoundedSize(new_bounds.size())));
|
||||
}
|
||||
|
||||
void RootWindow::OnWindowAddedToRootWindow(Window* attached) {
|
||||
|
Reference in New Issue
Block a user