OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_delegate_aura.h" | 5 #include "ash/accelerators/accelerator_controller_delegate_aura.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "ash/accelerators/accelerator_commands_aura.h" | 12 #include "ash/accelerators/accelerator_commands_aura.h" |
13 #include "ash/common/accelerators/debug_commands.h" | 13 #include "ash/common/accelerators/debug_commands.h" |
14 #include "ash/common/accessibility_types.h" | 14 #include "ash/common/accessibility_types.h" |
15 #include "ash/common/ash_switches.h" | 15 #include "ash/common/ash_switches.h" |
16 #include "ash/common/gpu_support.h" | 16 #include "ash/common/gpu_support.h" |
17 #include "ash/common/session/session_state_delegate.h" | 17 #include "ash/common/session/session_state_delegate.h" |
18 #include "ash/common/shelf/wm_shelf.h" | 18 #include "ash/common/shelf/wm_shelf.h" |
19 #include "ash/common/shell_delegate.h" | 19 #include "ash/common/shell_delegate.h" |
20 #include "ash/common/shell_window_ids.h" | 20 #include "ash/common/shell_window_ids.h" |
21 #include "ash/common/system/system_notifier.h" | 21 #include "ash/common/system/system_notifier.h" |
22 #include "ash/common/system/tray/system_tray.h" | 22 #include "ash/common/system/tray/system_tray.h" |
23 #include "ash/common/wallpaper/wallpaper_delegate.h" | |
24 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 23 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
25 #include "ash/common/wm/window_state.h" | 24 #include "ash/common/wm/window_state.h" |
26 #include "ash/common/wm/wm_event.h" | 25 #include "ash/common/wm/wm_event.h" |
27 #include "ash/common/wm_shell.h" | 26 #include "ash/common/wm_shell.h" |
28 #include "ash/debug.h" | 27 #include "ash/debug.h" |
29 #include "ash/display/display_manager.h" | 28 #include "ash/display/display_manager.h" |
30 #include "ash/display/window_tree_host_manager.h" | 29 #include "ash/display/window_tree_host_manager.h" |
31 #include "ash/host/ash_window_tree_host.h" | 30 #include "ash/host/ash_window_tree_host.h" |
32 #include "ash/magnifier/magnification_controller.h" | 31 #include "ash/magnifier/magnification_controller.h" |
33 #include "ash/root_window_controller.h" | 32 #include "ash/root_window_controller.h" |
34 #include "ash/rotator/screen_rotation_animator.h" | 33 #include "ash/rotator/screen_rotation_animator.h" |
35 #include "ash/rotator/window_rotation.h" | 34 #include "ash/rotator/window_rotation.h" |
36 #include "ash/screen_util.h" | 35 #include "ash/screen_util.h" |
37 #include "ash/screenshot_delegate.h" | 36 #include "ash/screenshot_delegate.h" |
38 #include "ash/shell.h" | 37 #include "ash/shell.h" |
39 #include "ash/touch/touch_hud_debug.h" | 38 #include "ash/touch/touch_hud_debug.h" |
40 #include "ash/utility/screenshot_controller.h" | 39 #include "ash/utility/screenshot_controller.h" |
41 #include "ash/wallpaper/wallpaper_controller.h" | |
42 #include "ash/wm/power_button_controller.h" | 40 #include "ash/wm/power_button_controller.h" |
43 #include "ash/wm/window_state_aura.h" | 41 #include "ash/wm/window_state_aura.h" |
44 #include "ash/wm/window_util.h" | 42 #include "ash/wm/window_util.h" |
45 #include "base/metrics/histogram_macros.h" | 43 #include "base/metrics/histogram_macros.h" |
46 #include "base/metrics/user_metrics.h" | 44 #include "base/metrics/user_metrics.h" |
47 #include "base/strings/string_split.h" | 45 #include "base/strings/string_split.h" |
48 #include "base/strings/utf_string_conversions.h" | 46 #include "base/strings/utf_string_conversions.h" |
49 #include "third_party/skia/include/core/SkColor.h" | 47 #include "third_party/skia/include/core/SkColor.h" |
50 #include "third_party/skia/include/core/SkPaint.h" | 48 #include "third_party/skia/include/core/SkPaint.h" |
51 #include "ui/base/accelerators/accelerator.h" | 49 #include "ui/base/accelerators/accelerator.h" |
52 #include "ui/base/l10n/l10n_util.h" | 50 #include "ui/base/l10n/l10n_util.h" |
53 #include "ui/compositor/layer.h" | 51 #include "ui/compositor/layer.h" |
54 #include "ui/compositor/layer_animation_sequence.h" | 52 #include "ui/compositor/layer_animation_sequence.h" |
55 #include "ui/compositor/layer_animator.h" | 53 #include "ui/compositor/layer_animator.h" |
56 #include "ui/display/screen.h" | 54 #include "ui/display/screen.h" |
57 #include "ui/events/event.h" | 55 #include "ui/events/event.h" |
58 #include "ui/events/keycodes/keyboard_codes.h" | 56 #include "ui/events/keycodes/keyboard_codes.h" |
59 #include "ui/gfx/canvas.h" | |
60 #include "ui/gfx/image/image_skia.h" | |
61 #include "ui/message_center/message_center.h" | 57 #include "ui/message_center/message_center.h" |
62 #include "ui/message_center/notification.h" | 58 #include "ui/message_center/notification.h" |
63 #include "ui/message_center/notifier_settings.h" | 59 #include "ui/message_center/notifier_settings.h" |
64 | 60 |
65 #if defined(OS_CHROMEOS) | 61 #if defined(OS_CHROMEOS) |
66 #include "ash/display/display_configuration_controller.h" | 62 #include "ash/display/display_configuration_controller.h" |
67 #include "base/sys_info.h" | 63 #include "base/sys_info.h" |
68 #endif // defined(OS_CHROMEOS) | 64 #endif // defined(OS_CHROMEOS) |
69 | 65 |
70 namespace ash { | 66 namespace ash { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 screenshot_delegate, true /* draw_overlay_immediately */); | 216 screenshot_delegate, true /* draw_overlay_immediately */); |
221 } | 217 } |
222 | 218 |
223 void HandleTakeScreenshot(ScreenshotDelegate* screenshot_delegate) { | 219 void HandleTakeScreenshot(ScreenshotDelegate* screenshot_delegate) { |
224 base::RecordAction(UserMetricsAction("Accel_Take_Screenshot")); | 220 base::RecordAction(UserMetricsAction("Accel_Take_Screenshot")); |
225 DCHECK(screenshot_delegate); | 221 DCHECK(screenshot_delegate); |
226 if (screenshot_delegate->CanTakeScreenshot()) | 222 if (screenshot_delegate->CanTakeScreenshot()) |
227 screenshot_delegate->HandleTakeScreenshotForAllRootWindows(); | 223 screenshot_delegate->HandleTakeScreenshotForAllRootWindows(); |
228 } | 224 } |
229 | 225 |
230 gfx::ImageSkia CreateWallpaperImage(SkColor fill, SkColor rect) { | |
231 // TODO(oshima): Consider adding a command line option to control | |
232 // wallpaper images for testing. | |
233 // The size is randomly picked. | |
234 gfx::Size image_size(1366, 768); | |
235 gfx::Canvas canvas(image_size, 1.0f, true); | |
236 canvas.DrawColor(fill); | |
237 SkPaint paint; | |
238 paint.setColor(rect); | |
239 paint.setStrokeWidth(10); | |
240 paint.setStyle(SkPaint::kStroke_Style); | |
241 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); | |
242 canvas.DrawRoundRect(gfx::Rect(image_size), 100, paint); | |
243 return gfx::ImageSkia(canvas.ExtractImageRep()); | |
244 } | |
245 | |
246 void HandleToggleWallpaperMode() { | |
247 static int index = 0; | |
248 WallpaperController* wallpaper_controller = | |
249 Shell::GetInstance()->wallpaper_controller(); | |
250 switch (++index % 4) { | |
251 case 0: | |
252 ash::WmShell::Get()->wallpaper_delegate()->InitializeWallpaper(); | |
253 break; | |
254 case 1: | |
255 wallpaper_controller->SetWallpaperImage( | |
256 CreateWallpaperImage(SK_ColorRED, SK_ColorBLUE), | |
257 wallpaper::WALLPAPER_LAYOUT_STRETCH); | |
258 break; | |
259 case 2: | |
260 wallpaper_controller->SetWallpaperImage( | |
261 CreateWallpaperImage(SK_ColorBLUE, SK_ColorGREEN), | |
262 wallpaper::WALLPAPER_LAYOUT_CENTER); | |
263 break; | |
264 case 3: | |
265 wallpaper_controller->SetWallpaperImage( | |
266 CreateWallpaperImage(SK_ColorGREEN, SK_ColorRED), | |
267 wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED); | |
268 break; | |
269 } | |
270 } | |
271 | |
272 bool CanHandleUnpin() { | 226 bool CanHandleUnpin() { |
273 wm::WindowState* window_state = wm::GetActiveWindowState(); | 227 wm::WindowState* window_state = wm::GetActiveWindowState(); |
274 return window_state && window_state->IsPinned(); | 228 return window_state && window_state->IsPinned(); |
275 } | 229 } |
276 | 230 |
277 #if defined(OS_CHROMEOS) | 231 #if defined(OS_CHROMEOS) |
278 void HandleSwapPrimaryDisplay() { | 232 void HandleSwapPrimaryDisplay() { |
279 base::RecordAction(UserMetricsAction("Accel_Swap_Primary_Display")); | 233 base::RecordAction(UserMetricsAction("Accel_Swap_Primary_Display")); |
280 Shell::GetInstance()->display_configuration_controller()->SetPrimaryDisplayId( | 234 Shell::GetInstance()->display_configuration_controller()->SetPrimaryDisplayId( |
281 ScreenUtil::GetSecondaryDisplay().id(), true /* user_action */); | 235 ScreenUtil::GetSecondaryDisplay().id(), true /* user_action */); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 bool AcceleratorControllerDelegateAura::HandlesAction( | 272 bool AcceleratorControllerDelegateAura::HandlesAction( |
319 AcceleratorAction action) { | 273 AcceleratorAction action) { |
320 // NOTE: When adding a new accelerator that only depends on //ash/common code, | 274 // NOTE: When adding a new accelerator that only depends on //ash/common code, |
321 // add it to accelerator_controller.cc instead. See class comment. | 275 // add it to accelerator_controller.cc instead. See class comment. |
322 switch (action) { | 276 switch (action) { |
323 case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR: | 277 case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR: |
324 case DEBUG_TOGGLE_ROOT_WINDOW_FULL_SCREEN: | 278 case DEBUG_TOGGLE_ROOT_WINDOW_FULL_SCREEN: |
325 case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS: | 279 case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS: |
326 case DEBUG_TOGGLE_SHOW_FPS_COUNTER: | 280 case DEBUG_TOGGLE_SHOW_FPS_COUNTER: |
327 case DEBUG_TOGGLE_SHOW_PAINT_RECTS: | 281 case DEBUG_TOGGLE_SHOW_PAINT_RECTS: |
328 case DEBUG_TOGGLE_WALLPAPER_MODE: | |
329 case MAGNIFY_SCREEN_ZOOM_IN: | 282 case MAGNIFY_SCREEN_ZOOM_IN: |
330 case MAGNIFY_SCREEN_ZOOM_OUT: | 283 case MAGNIFY_SCREEN_ZOOM_OUT: |
331 case ROTATE_SCREEN: | 284 case ROTATE_SCREEN: |
332 case ROTATE_WINDOW: | 285 case ROTATE_WINDOW: |
333 case SCALE_UI_DOWN: | 286 case SCALE_UI_DOWN: |
334 case SCALE_UI_RESET: | 287 case SCALE_UI_RESET: |
335 case SCALE_UI_UP: | 288 case SCALE_UI_UP: |
336 case SHOW_MESSAGE_CENTER_BUBBLE: | 289 case SHOW_MESSAGE_CENTER_BUBBLE: |
337 case SHOW_SYSTEM_TRAY_BUBBLE: | 290 case SHOW_SYSTEM_TRAY_BUBBLE: |
338 case TAKE_PARTIAL_SCREENSHOT: | 291 case TAKE_PARTIAL_SCREENSHOT: |
(...skipping 22 matching lines...) Expand all Loading... |
361 break; | 314 break; |
362 } | 315 } |
363 return false; | 316 return false; |
364 } | 317 } |
365 | 318 |
366 bool AcceleratorControllerDelegateAura::CanPerformAction( | 319 bool AcceleratorControllerDelegateAura::CanPerformAction( |
367 AcceleratorAction action, | 320 AcceleratorAction action, |
368 const ui::Accelerator& accelerator, | 321 const ui::Accelerator& accelerator, |
369 const ui::Accelerator& previous_accelerator) { | 322 const ui::Accelerator& previous_accelerator) { |
370 switch (action) { | 323 switch (action) { |
371 case DEBUG_TOGGLE_WALLPAPER_MODE: | |
372 case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR: | 324 case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR: |
373 case DEBUG_TOGGLE_ROOT_WINDOW_FULL_SCREEN: | 325 case DEBUG_TOGGLE_ROOT_WINDOW_FULL_SCREEN: |
374 case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS: | 326 case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS: |
375 case DEBUG_TOGGLE_SHOW_FPS_COUNTER: | 327 case DEBUG_TOGGLE_SHOW_FPS_COUNTER: |
376 case DEBUG_TOGGLE_SHOW_PAINT_RECTS: | 328 case DEBUG_TOGGLE_SHOW_PAINT_RECTS: |
377 return debug::DebugAcceleratorsEnabled(); | 329 return debug::DebugAcceleratorsEnabled(); |
378 case MAGNIFY_SCREEN_ZOOM_IN: | 330 case MAGNIFY_SCREEN_ZOOM_IN: |
379 case MAGNIFY_SCREEN_ZOOM_OUT: | 331 case MAGNIFY_SCREEN_ZOOM_OUT: |
380 return CanHandleMagnifyScreen(); | 332 return CanHandleMagnifyScreen(); |
381 case SCALE_UI_DOWN: | 333 case SCALE_UI_DOWN: |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 NOTREACHED(); | 372 NOTREACHED(); |
421 break; | 373 break; |
422 } | 374 } |
423 return false; | 375 return false; |
424 } | 376 } |
425 | 377 |
426 void AcceleratorControllerDelegateAura::PerformAction( | 378 void AcceleratorControllerDelegateAura::PerformAction( |
427 AcceleratorAction action, | 379 AcceleratorAction action, |
428 const ui::Accelerator& accelerator) { | 380 const ui::Accelerator& accelerator) { |
429 switch (action) { | 381 switch (action) { |
430 case DEBUG_TOGGLE_WALLPAPER_MODE: | |
431 HandleToggleWallpaperMode(); | |
432 break; | |
433 case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR: | 382 case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR: |
434 Shell::GetInstance()->display_manager()->ToggleDisplayScaleFactor(); | 383 Shell::GetInstance()->display_manager()->ToggleDisplayScaleFactor(); |
435 break; | 384 break; |
436 case DEBUG_TOGGLE_ROOT_WINDOW_FULL_SCREEN: | 385 case DEBUG_TOGGLE_ROOT_WINDOW_FULL_SCREEN: |
437 Shell::GetPrimaryRootWindowController()->ash_host()->ToggleFullScreen(); | 386 Shell::GetPrimaryRootWindowController()->ash_host()->ToggleFullScreen(); |
438 break; | 387 break; |
439 case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS: | 388 case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS: |
440 debug::ToggleShowDebugBorders(); | 389 debug::ToggleShowDebugBorders(); |
441 break; | 390 break; |
442 case DEBUG_TOGGLE_SHOW_FPS_COUNTER: | 391 case DEBUG_TOGGLE_SHOW_FPS_COUNTER: |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 message_center::NotifierId( | 496 message_center::NotifierId( |
548 message_center::NotifierId::SYSTEM_COMPONENT, | 497 message_center::NotifierId::SYSTEM_COMPONENT, |
549 system_notifier::kNotifierDeprecatedAccelerator), | 498 system_notifier::kNotifierDeprecatedAccelerator), |
550 message_center::RichNotificationData(), | 499 message_center::RichNotificationData(), |
551 new DeprecatedAcceleratorNotificationDelegate)); | 500 new DeprecatedAcceleratorNotificationDelegate)); |
552 message_center::MessageCenter::Get()->AddNotification( | 501 message_center::MessageCenter::Get()->AddNotification( |
553 std::move(notification)); | 502 std::move(notification)); |
554 } | 503 } |
555 | 504 |
556 } // namespace ash | 505 } // namespace ash |
OLD | NEW |