Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/accelerators/accelerator_controller.h" | 5 #include "ash/accelerators/accelerator_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 // rotation and position. Use replace so we only enqueue one at a time. | 147 // rotation and position. Use replace so we only enqueue one at a time. |
| 148 active_window->layer()->GetAnimator()-> | 148 active_window->layer()->GetAnimator()-> |
| 149 set_preemption_strategy(ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | 149 set_preemption_strategy(ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
| 150 active_window->layer()->GetAnimator()->StartAnimation( | 150 active_window->layer()->GetAnimator()->StartAnimation( |
| 151 new ui::LayerAnimationSequence( | 151 new ui::LayerAnimationSequence( |
| 152 new ash::ScreenRotation(360, active_window->layer()))); | 152 new ash::ScreenRotation(360, active_window->layer()))); |
| 153 } | 153 } |
| 154 return true; | 154 return true; |
| 155 } | 155 } |
| 156 | 156 |
| 157 const gfx::Display::Rotation GetNextRotation(gfx::Display::Rotation current) { | 157 gfx::Display::Rotation GetNextRotation(gfx::Display::Rotation current) { |
| 158 switch (current) { | 158 switch (current) { |
| 159 case gfx::Display::ROTATE_0: | 159 case gfx::Display::ROTATE_0: |
| 160 return gfx::Display::ROTATE_90; | 160 return gfx::Display::ROTATE_90; |
| 161 case gfx::Display::ROTATE_90: | 161 case gfx::Display::ROTATE_90: |
| 162 return gfx::Display::ROTATE_180; | 162 return gfx::Display::ROTATE_180; |
| 163 case gfx::Display::ROTATE_180: | 163 case gfx::Display::ROTATE_180: |
| 164 return gfx::Display::ROTATE_270; | 164 return gfx::Display::ROTATE_270; |
| 165 case gfx::Display::ROTATE_270: | 165 case gfx::Display::ROTATE_270: |
| 166 return gfx::Display::ROTATE_0; | 166 return gfx::Display::ROTATE_0; |
| 167 } | 167 } |
| 168 NOTREACHED() << "Unknown rotation:" << current; | 168 NOTREACHED() << "Unknown rotation:" << current; |
| 169 return gfx::Display::ROTATE_0; | 169 return gfx::Display::ROTATE_0; |
| 170 } | 170 } |
| 171 | 171 |
| 172 float GetNextScale(float scale, bool up) { | |
| 173 // These scales are equivalent to 1024, 1280, 1600 and 1920 pixel width | |
| 174 // respectively on 2560 pixel width 2x density display. | |
| 175 static const float kScales[] = {0.8f, 1.0f, 1.25f, 1.5f}; | |
| 176 static const size_t kScaleTableSize = arraysize(kScales); | |
| 177 for (size_t i = 0; i < kScaleTableSize; ++i) { | |
| 178 if (kScales[i] == scale) { | |
| 179 if (up && i != kScaleTableSize -1) | |
|
James Cook
2013/03/15 17:09:38
nit: "kScaleTableSize - 1"
| |
| 180 return kScales[i + 1]; | |
| 181 if (!up && i != 0) | |
| 182 return kScales[i - 1]; | |
| 183 return kScales[i]; | |
| 184 } | |
| 185 } | |
| 186 // Fallback to 1.0f if the |scale| wasn't in the list. | |
| 187 return 1.0f; | |
| 188 } | |
| 189 | |
| 190 bool HandleScaleUI(bool up) { | |
| 191 // UI Scaling is effective only on internal display. | |
| 192 int64 display_id = gfx::Display::InternalDisplayId(); | |
| 193 #if defined(OS_CHROMEOS) | |
| 194 // On linux desktop, allow ui scalacing on the first dislpay. | |
| 195 if (!base::chromeos::IsRunningOnChromeOS()) | |
| 196 display_id = Shell::GetInstance()->display_manager()->first_display_id(); | |
| 197 #endif | |
| 198 const gfx::Display& display = Shell::GetInstance()->display_manager()-> | |
| 199 GetDisplayForId(display_id); | |
| 200 const DisplayInfo& display_info = Shell::GetInstance()->display_manager()-> | |
| 201 GetDisplayInfo(display); | |
| 202 Shell::GetInstance()->display_manager()->SetDisplayUIScale( | |
| 203 display.id(), GetNextScale(display_info.ui_scale(), up)); | |
| 204 return true; | |
| 205 } | |
| 206 | |
| 172 // Rotates the screen. | 207 // Rotates the screen. |
| 173 bool HandleRotateScreen() { | 208 bool HandleRotateScreen() { |
| 174 aura::Window* active_window = wm::GetActiveWindow(); | 209 gfx::Point point = Shell::GetScreen()->GetCursorScreenPoint(); |
| 175 if (!active_window) | 210 gfx::Display display = Shell::GetScreen()->GetDisplayNearestPoint(point); |
| 176 return false; | |
| 177 const gfx::Display& display = | |
| 178 Shell::GetScreen()->GetDisplayNearestWindow(active_window); | |
| 179 const DisplayInfo& display_info = | 211 const DisplayInfo& display_info = |
| 180 Shell::GetInstance()->display_manager()->GetDisplayInfo(display); | 212 Shell::GetInstance()->display_manager()->GetDisplayInfo(display); |
| 181 Shell::GetInstance()->display_manager()->SetDisplayRotation( | 213 Shell::GetInstance()->display_manager()->SetDisplayRotation( |
| 182 display.id(), GetNextRotation(display_info.rotation())); | 214 display.id(), GetNextRotation(display_info.rotation())); |
| 183 return true; | 215 return true; |
| 184 } | 216 } |
| 185 | 217 |
| 186 bool HandleToggleDesktopBackgroundMode() { | 218 bool HandleToggleDesktopBackgroundMode() { |
| 187 DesktopBackgroundController* desktop_background_controller = | 219 DesktopBackgroundController* desktop_background_controller = |
| 188 Shell::GetInstance()->desktop_background_controller(); | 220 Shell::GetInstance()->desktop_background_controller(); |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 751 return true; | 783 return true; |
| 752 } | 784 } |
| 753 case WINDOW_POSITION_CENTER: { | 785 case WINDOW_POSITION_CENTER: { |
| 754 aura::Window* window = wm::GetActiveWindow(); | 786 aura::Window* window = wm::GetActiveWindow(); |
| 755 if (window) { | 787 if (window) { |
| 756 wm::CenterWindow(window); | 788 wm::CenterWindow(window); |
| 757 return true; | 789 return true; |
| 758 } | 790 } |
| 759 break; | 791 break; |
| 760 } | 792 } |
| 793 case SCALE_UI_UP: | |
| 794 return HandleScaleUI(true /* up */); | |
| 795 case SCALE_UI_DOWN: | |
| 796 return HandleScaleUI(false /* down */); | |
| 761 case ROTATE_WINDOW: | 797 case ROTATE_WINDOW: |
| 762 return HandleRotateActiveWindow(); | 798 return HandleRotateActiveWindow(); |
| 763 case ROTATE_SCREEN: | 799 case ROTATE_SCREEN: |
| 764 return HandleRotateScreen(); | 800 return HandleRotateScreen(); |
| 765 case TOGGLE_DESKTOP_BACKGROUND_MODE: | 801 case TOGGLE_DESKTOP_BACKGROUND_MODE: |
| 766 return HandleToggleDesktopBackgroundMode(); | 802 return HandleToggleDesktopBackgroundMode(); |
| 767 case TOGGLE_ROOT_WINDOW_FULL_SCREEN: | 803 case TOGGLE_ROOT_WINDOW_FULL_SCREEN: |
| 768 return HandleToggleRootWindowFullScreen(); | 804 return HandleToggleRootWindowFullScreen(); |
| 769 case DISPLAY_TOGGLE_SCALE: | 805 case DISPLAY_TOGGLE_SCALE: |
| 770 internal::DisplayManager::ToggleDisplayScale(); | 806 internal::DisplayManager::ToggleDisplayScaleFactor(); |
| 771 return true; | 807 return true; |
| 772 case MAGNIFY_SCREEN_ZOOM_IN: | 808 case MAGNIFY_SCREEN_ZOOM_IN: |
| 773 return HandleMagnifyScreen(1); | 809 return HandleMagnifyScreen(1); |
| 774 case MAGNIFY_SCREEN_ZOOM_OUT: | 810 case MAGNIFY_SCREEN_ZOOM_OUT: |
| 775 return HandleMagnifyScreen(-1); | 811 return HandleMagnifyScreen(-1); |
| 776 case MEDIA_NEXT_TRACK: | 812 case MEDIA_NEXT_TRACK: |
| 777 return HandleMediaNextTrack(); | 813 return HandleMediaNextTrack(); |
| 778 case MEDIA_PLAY_PAUSE: | 814 case MEDIA_PLAY_PAUSE: |
| 779 return HandleMediaPlayPause(); | 815 return HandleMediaPlayPause(); |
| 780 case MEDIA_PREV_TRACK: | 816 case MEDIA_PREV_TRACK: |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 864 keyboard_brightness_control_delegate) { | 900 keyboard_brightness_control_delegate) { |
| 865 keyboard_brightness_control_delegate_ = | 901 keyboard_brightness_control_delegate_ = |
| 866 keyboard_brightness_control_delegate.Pass(); | 902 keyboard_brightness_control_delegate.Pass(); |
| 867 } | 903 } |
| 868 | 904 |
| 869 bool AcceleratorController::CanHandleAccelerators() const { | 905 bool AcceleratorController::CanHandleAccelerators() const { |
| 870 return true; | 906 return true; |
| 871 } | 907 } |
| 872 | 908 |
| 873 } // namespace ash | 909 } // namespace ash |
| OLD | NEW |