Skip to content

Commit

Permalink
2nd try
Browse files Browse the repository at this point in the history
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

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=188324

Review URL: https://codereview.chromium.org/12848004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188362 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
oshima@chromium.org committed Mar 15, 2013
1 parent b6fd2de commit af5ed95
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 48 deletions.
45 changes: 38 additions & 7 deletions ash/accelerators/accelerator_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
const float* location = std::find(kScales, kScales + kScaleTableSize, scale);
// Fallback to 1.0f if the |scale| wasn't in the list.
if (location == kScales + kScaleTableSize)
return 1.0f;
int index = std::distance(kScales, location) + next;
return kScales[std::min(kScaleTableSize - 1, std::max(0, index))];
}

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 scalacing 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(
Expand Down Expand Up @@ -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:
Expand All @@ -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);
Expand Down
17 changes: 16 additions & 1 deletion ash/accelerators/accelerator_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -294,6 +305,8 @@ const AcceleratorAction kNonrepeatableActions[] = {
CYCLE_FORWARD_MRU,
ROTATE_SCREEN,
ROTATE_WINDOW,
SCALE_UI_UP,
SCALE_UI_DOWN,
TOGGLE_MAXIMIZED,
WINDOW_MINIMIZE,
};
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions ash/accelerators/accelerator_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions ash/ash_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
2 changes: 2 additions & 0 deletions ash/ash_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 41 additions & 1 deletion ash/display/display_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void DisplayManager::CycleDisplay() {
}

// static
void DisplayManager::ToggleDisplayScale() {
void DisplayManager::ToggleDisplayScaleFactor() {
Shell::GetInstance()->display_manager()->ScaleDisplayImpl();
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion ash/display/display_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
18 changes: 0 additions & 18 deletions chrome/app/generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 0 additions & 17 deletions chrome/browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 5 additions & 3 deletions ui/aura/root_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
Expand All @@ -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) {
Expand Down

0 comments on commit af5ed95

Please sign in to comment.