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 DisplayInfo::Rotation GetNextRotation(DisplayInfo::Rotation current) { | 157 DisplayInfo::Rotation GetNextRotation(DisplayInfo::Rotation current) { |
158 switch (current) { | 158 switch (current) { |
159 case DisplayInfo::ROTATE_0: | 159 case DisplayInfo::ROTATE_0: |
160 return DisplayInfo::ROTATE_90; | 160 return DisplayInfo::ROTATE_90; |
161 case DisplayInfo::ROTATE_90: | 161 case DisplayInfo::ROTATE_90: |
162 return DisplayInfo::ROTATE_180; | 162 return DisplayInfo::ROTATE_180; |
163 case DisplayInfo::ROTATE_180: | 163 case DisplayInfo::ROTATE_180: |
164 return DisplayInfo::ROTATE_270; | 164 return DisplayInfo::ROTATE_270; |
165 case DisplayInfo::ROTATE_270: | 165 case DisplayInfo::ROTATE_270: |
166 return DisplayInfo::ROTATE_0; | 166 return DisplayInfo::ROTATE_0; |
167 } | 167 } |
168 NOTREACHED() << "Unknown rotation:" << current; | 168 NOTREACHED() << "Unknown rotation:" << current; |
169 return DisplayInfo::ROTATE_0; | 169 return DisplayInfo::ROTATE_0; |
170 } | 170 } |
171 | 171 |
172 float GetNextScale(float scale, int next) { | |
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 int size = arraysize(kScales); | |
James Cook
2013/03/14 17:50:43
size -> kScalesSize, or inline the use of arraysiz
oshima
2013/03/14 19:56:15
Done.
| |
177 int index = std::distance(kScales, std::find(kScales, kScales + size, scale)); | |
178 // Fallback to 1.0f if the |scale| wasn't in the list. | |
179 index = index == size ? 1 : index + next; | |
180 return kScales[std::max(std::min(3, index), 0)]; | |
James Cook
2013/03/14 17:50:43
Use size-1 instead of 3.
oshima
2013/03/14 19:56:15
Done.
| |
181 } | |
182 | |
183 bool HandleScaleUI(bool up) { | |
184 // UI Scaling is effective only on internal display. | |
185 int64 display_id = gfx::Display::InternalDisplayId(); | |
186 #if defined(OS_CHROMEOS) | |
187 // On linux desktop, allow ui scaling on the first dislpay. | |
188 if (!base::chromeos::IsRunningOnChromeOS()) | |
189 display_id = Shell::GetInstance()->display_manager()->first_display_id(); | |
190 #endif | |
191 const gfx::Display& display = Shell::GetInstance()->display_manager()-> | |
192 GetDisplayForId(display_id); | |
193 const DisplayInfo& display_info = Shell::GetInstance()->display_manager()-> | |
194 GetDisplayInfo(display); | |
195 Shell::GetInstance()->display_manager()->SetDisplayUIScale( | |
196 display.id(), GetNextScale(display_info.ui_scale(), up ? 1 : -1)); | |
197 return true; | |
198 } | |
199 | |
172 // Rotates the screen. | 200 // Rotates the screen. |
173 bool HandleRotateScreen() { | 201 bool HandleRotateScreen() { |
174 aura::Window* active_window = wm::GetActiveWindow(); | 202 gfx::Point point = Shell::GetScreen()->GetCursorScreenPoint(); |
175 if (!active_window) | 203 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 = | 204 const DisplayInfo& display_info = |
180 Shell::GetInstance()->display_manager()->GetDisplayInfo(display); | 205 Shell::GetInstance()->display_manager()->GetDisplayInfo(display); |
181 Shell::GetInstance()->display_manager()->SetDisplayRotation( | 206 Shell::GetInstance()->display_manager()->SetDisplayRotation( |
182 display.id(), GetNextRotation(display_info.rotation())); | 207 display.id(), GetNextRotation(display_info.rotation())); |
183 return true; | 208 return true; |
184 } | 209 } |
185 | 210 |
186 bool HandleToggleDesktopBackgroundMode() { | 211 bool HandleToggleDesktopBackgroundMode() { |
187 DesktopBackgroundController* desktop_background_controller = | 212 DesktopBackgroundController* desktop_background_controller = |
188 Shell::GetInstance()->desktop_background_controller(); | 213 Shell::GetInstance()->desktop_background_controller(); |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
749 return true; | 774 return true; |
750 } | 775 } |
751 case WINDOW_POSITION_CENTER: { | 776 case WINDOW_POSITION_CENTER: { |
752 aura::Window* window = wm::GetActiveWindow(); | 777 aura::Window* window = wm::GetActiveWindow(); |
753 if (window) { | 778 if (window) { |
754 wm::CenterWindow(window); | 779 wm::CenterWindow(window); |
755 return true; | 780 return true; |
756 } | 781 } |
757 break; | 782 break; |
758 } | 783 } |
784 case SCALE_UI_UP: | |
785 return HandleScaleUI(true /* up */); | |
786 case SCALE_UI_DOWN: | |
787 return HandleScaleUI(false /* down */); | |
759 case ROTATE_WINDOW: | 788 case ROTATE_WINDOW: |
760 return HandleRotateActiveWindow(); | 789 return HandleRotateActiveWindow(); |
761 case ROTATE_SCREEN: | 790 case ROTATE_SCREEN: |
762 return HandleRotateScreen(); | 791 return HandleRotateScreen(); |
763 case TOGGLE_DESKTOP_BACKGROUND_MODE: | 792 case TOGGLE_DESKTOP_BACKGROUND_MODE: |
764 return HandleToggleDesktopBackgroundMode(); | 793 return HandleToggleDesktopBackgroundMode(); |
765 case TOGGLE_ROOT_WINDOW_FULL_SCREEN: | 794 case TOGGLE_ROOT_WINDOW_FULL_SCREEN: |
766 return HandleToggleRootWindowFullScreen(); | 795 return HandleToggleRootWindowFullScreen(); |
767 case DISPLAY_TOGGLE_SCALE: | 796 case DISPLAY_TOGGLE_SCALE: |
768 internal::DisplayManager::ToggleDisplayScale(); | 797 internal::DisplayManager::ToggleDisplayScaleFactor(); |
769 return true; | 798 return true; |
770 case MAGNIFY_SCREEN_ZOOM_IN: | 799 case MAGNIFY_SCREEN_ZOOM_IN: |
771 return HandleMagnifyScreen(1); | 800 return HandleMagnifyScreen(1); |
772 case MAGNIFY_SCREEN_ZOOM_OUT: | 801 case MAGNIFY_SCREEN_ZOOM_OUT: |
773 return HandleMagnifyScreen(-1); | 802 return HandleMagnifyScreen(-1); |
774 case MEDIA_NEXT_TRACK: | 803 case MEDIA_NEXT_TRACK: |
775 return HandleMediaNextTrack(); | 804 return HandleMediaNextTrack(); |
776 case MEDIA_PLAY_PAUSE: | 805 case MEDIA_PLAY_PAUSE: |
777 return HandleMediaPlayPause(); | 806 return HandleMediaPlayPause(); |
778 case MEDIA_PREV_TRACK: | 807 case MEDIA_PREV_TRACK: |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
862 keyboard_brightness_control_delegate) { | 891 keyboard_brightness_control_delegate) { |
863 keyboard_brightness_control_delegate_ = | 892 keyboard_brightness_control_delegate_ = |
864 keyboard_brightness_control_delegate.Pass(); | 893 keyboard_brightness_control_delegate.Pass(); |
865 } | 894 } |
866 | 895 |
867 bool AcceleratorController::CanHandleAccelerators() const { | 896 bool AcceleratorController::CanHandleAccelerators() const { |
868 return true; | 897 return true; |
869 } | 898 } |
870 | 899 |
871 } // namespace ash | 900 } // namespace ash |
OLD | NEW |