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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 #include "base/sys_info.h" | 72 #include "base/sys_info.h" |
| 73 #include "ui/base/ime/chromeos/ime_keyboard.h" | 73 #include "ui/base/ime/chromeos/ime_keyboard.h" |
| 74 #include "ui/base/ime/chromeos/input_method_manager.h" | 74 #include "ui/base/ime/chromeos/input_method_manager.h" |
| 75 #endif // defined(OS_CHROMEOS) | 75 #endif // defined(OS_CHROMEOS) |
| 76 | 76 |
| 77 namespace ash { | 77 namespace ash { |
| 78 namespace { | 78 namespace { |
| 79 | 79 |
| 80 using base::UserMetricsAction; | 80 using base::UserMetricsAction; |
| 81 | 81 |
| 82 bool CanHandleAccessibleFocusCycle() { | 82 inline ui::Accelerator CreateAccelerator(ui::KeyboardCode keycode, |
|
oshima
2015/06/24 22:14:33
remove "inline"
David Tseng
2015/06/24 22:24:27
Acknowledged.
| |
| 83 if (!Shell::GetInstance()->accessibility_delegate()-> | 83 int modifiers, |
| 84 IsSpokenFeedbackEnabled()) { | 84 bool trigger_on_press) { |
| 85 return false; | 85 ui::Accelerator accelerator(keycode, modifiers); |
| 86 } | 86 accelerator.set_type(trigger_on_press ? ui::ET_KEY_PRESSED |
| 87 aura::Window* active_window = ash::wm::GetActiveWindow(); | 87 : ui::ET_KEY_RELEASED); |
| 88 if (!active_window) | 88 return accelerator; |
| 89 return false; | |
| 90 views::Widget* widget = | |
| 91 views::Widget::GetWidgetForNativeWindow(active_window); | |
| 92 if (!widget) | |
| 93 return false; | |
| 94 views::FocusManager* focus_manager = widget->GetFocusManager(); | |
| 95 if (!focus_manager) | |
| 96 return false; | |
| 97 views::View* view = focus_manager->GetFocusedView(); | |
| 98 return view && strcmp(view->GetClassName(), views::WebView::kViewClassName); | |
| 99 } | 89 } |
| 100 | 90 |
| 101 void HandleAccessibleFocusCycle(bool reverse) { | 91 void ShowDeprecatedAcceleratorNotification(int message_id) { |
| 102 if (reverse) | 92 const base::string16 message = l10n_util::GetStringUTF16(message_id); |
| 103 base::RecordAction(UserMetricsAction("Accel_Accessible_Focus_Previous")); | 93 scoped_ptr<message_center::Notification> notification( |
| 104 else | 94 new message_center::Notification( |
| 105 base::RecordAction(UserMetricsAction("Accel_Accessible_Focus_Next")); | 95 message_center::NOTIFICATION_TYPE_SIMPLE, |
| 96 kDeprecatedAcceleratorNotificationId, base::string16(), message, | |
| 97 gfx::Image(), base::string16(), | |
| 98 message_center::NotifierId( | |
| 99 message_center::NotifierId::SYSTEM_COMPONENT, | |
| 100 system_notifier::kNotifierDeprecatedAccelerator), | |
| 101 message_center::RichNotificationData(), nullptr)); | |
| 102 message_center::MessageCenter::Get()->AddNotification(notification.Pass()); | |
| 103 } | |
|
oshima
2015/06/24 22:14:33
These changes were reverted yesterday (https://cod
David Tseng
2015/06/24 22:24:27
Done.
| |
| 106 | 104 |
| 107 aura::Window* active_window = ash::wm::GetActiveWindow(); | 105 void RecordUmaHistogram(const char* histogram_name, |
| 108 views::Widget* widget = | 106 DeprecatedAcceleratorUsage sample) { |
| 109 views::Widget::GetWidgetForNativeWindow(active_window); | 107 auto histogram = base::LinearHistogram::FactoryGet( |
| 110 widget->GetFocusManager()->AdvanceFocus(reverse); | 108 histogram_name, 1, DEPRECATED_USAGE_COUNT, DEPRECATED_USAGE_COUNT + 1, |
| 109 base::HistogramBase::kUmaTargetedHistogramFlag); | |
| 110 histogram->Add(sample); | |
| 111 } | 111 } |
| 112 | 112 |
| 113 void HandleCycleBackwardMRU(const ui::Accelerator& accelerator) { | 113 void HandleCycleBackwardMRU(const ui::Accelerator& accelerator) { |
| 114 if (accelerator.key_code() == ui::VKEY_TAB) | 114 if (accelerator.key_code() == ui::VKEY_TAB) |
| 115 base::RecordAction(base::UserMetricsAction("Accel_PrevWindow_Tab")); | 115 base::RecordAction(base::UserMetricsAction("Accel_PrevWindow_Tab")); |
| 116 | 116 |
| 117 Shell::GetInstance()->window_cycle_controller()->HandleCycleWindow( | 117 Shell::GetInstance()->window_cycle_controller()->HandleCycleWindow( |
| 118 WindowCycleController::BACKWARD); | 118 WindowCycleController::BACKWARD); |
| 119 } | 119 } |
| 120 | 120 |
| (...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 873 if (restriction != RESTRICTION_NONE) | 873 if (restriction != RESTRICTION_NONE) |
| 874 return restriction == RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; | 874 return restriction == RESTRICTION_PREVENT_PROCESSING_AND_PROPAGATION; |
| 875 | 875 |
| 876 const ui::Accelerator& previous_accelerator = | 876 const ui::Accelerator& previous_accelerator = |
| 877 accelerator_history_->previous_accelerator(); | 877 accelerator_history_->previous_accelerator(); |
| 878 | 878 |
| 879 // True should be returned if running |action| does something. Otherwise, | 879 // True should be returned if running |action| does something. Otherwise, |
| 880 // false should be returned to give the web contents a chance at handling the | 880 // false should be returned to give the web contents a chance at handling the |
| 881 // accelerator. | 881 // accelerator. |
| 882 switch (action) { | 882 switch (action) { |
| 883 case ACCESSIBLE_FOCUS_NEXT: | |
| 884 case ACCESSIBLE_FOCUS_PREVIOUS: | |
| 885 return CanHandleAccessibleFocusCycle(); | |
| 886 case DEBUG_PRINT_LAYER_HIERARCHY: | 883 case DEBUG_PRINT_LAYER_HIERARCHY: |
| 887 case DEBUG_PRINT_VIEW_HIERARCHY: | 884 case DEBUG_PRINT_VIEW_HIERARCHY: |
| 888 case DEBUG_PRINT_WINDOW_HIERARCHY: | 885 case DEBUG_PRINT_WINDOW_HIERARCHY: |
| 889 case DEBUG_TOGGLE_DESKTOP_BACKGROUND_MODE: | 886 case DEBUG_TOGGLE_DESKTOP_BACKGROUND_MODE: |
| 890 case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR: | 887 case DEBUG_TOGGLE_DEVICE_SCALE_FACTOR: |
| 891 case DEBUG_TOGGLE_ROOT_WINDOW_FULL_SCREEN: | 888 case DEBUG_TOGGLE_ROOT_WINDOW_FULL_SCREEN: |
| 892 case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS: | 889 case DEBUG_TOGGLE_SHOW_DEBUG_BORDERS: |
| 893 case DEBUG_TOGGLE_SHOW_FPS_COUNTER: | 890 case DEBUG_TOGGLE_SHOW_FPS_COUNTER: |
| 894 case DEBUG_TOGGLE_SHOW_PAINT_RECTS: | 891 case DEBUG_TOGGLE_SHOW_PAINT_RECTS: |
| 895 return debug::DebugAcceleratorsEnabled(); | 892 return debug::DebugAcceleratorsEnabled(); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1006 const ui::Accelerator& accelerator) { | 1003 const ui::Accelerator& accelerator) { |
| 1007 AcceleratorProcessingRestriction restriction = | 1004 AcceleratorProcessingRestriction restriction = |
| 1008 GetAcceleratorProcessingRestriction(action); | 1005 GetAcceleratorProcessingRestriction(action); |
| 1009 if (restriction != RESTRICTION_NONE) | 1006 if (restriction != RESTRICTION_NONE) |
| 1010 return; | 1007 return; |
| 1011 | 1008 |
| 1012 // If your accelerator invokes more than one line of code, please either | 1009 // If your accelerator invokes more than one line of code, please either |
| 1013 // implement it in your module's controller code (like TOGGLE_MIRROR_MODE | 1010 // implement it in your module's controller code (like TOGGLE_MIRROR_MODE |
| 1014 // below) or pull it into a HandleFoo() function above. | 1011 // below) or pull it into a HandleFoo() function above. |
| 1015 switch (action) { | 1012 switch (action) { |
| 1016 case ACCESSIBLE_FOCUS_NEXT: | |
| 1017 HandleAccessibleFocusCycle(false); | |
| 1018 break; | |
| 1019 case ACCESSIBLE_FOCUS_PREVIOUS: | |
| 1020 HandleAccessibleFocusCycle(true); | |
| 1021 break; | |
| 1022 case CYCLE_BACKWARD_MRU: | 1013 case CYCLE_BACKWARD_MRU: |
| 1023 HandleCycleBackwardMRU(accelerator); | 1014 HandleCycleBackwardMRU(accelerator); |
| 1024 break; | 1015 break; |
| 1025 case CYCLE_FORWARD_MRU: | 1016 case CYCLE_FORWARD_MRU: |
| 1026 HandleCycleForwardMRU(accelerator); | 1017 HandleCycleForwardMRU(accelerator); |
| 1027 break; | 1018 break; |
| 1028 case DEBUG_PRINT_LAYER_HIERARCHY: | 1019 case DEBUG_PRINT_LAYER_HIERARCHY: |
| 1029 case DEBUG_PRINT_VIEW_HIERARCHY: | 1020 case DEBUG_PRINT_VIEW_HIERARCHY: |
| 1030 case DEBUG_PRINT_WINDOW_HIERARCHY: | 1021 case DEBUG_PRINT_WINDOW_HIERARCHY: |
| 1031 case DEBUG_TOGGLE_DESKTOP_BACKGROUND_MODE: | 1022 case DEBUG_TOGGLE_DESKTOP_BACKGROUND_MODE: |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1328 } | 1319 } |
| 1329 | 1320 |
| 1330 void AcceleratorController::SetKeyboardBrightnessControlDelegate( | 1321 void AcceleratorController::SetKeyboardBrightnessControlDelegate( |
| 1331 scoped_ptr<KeyboardBrightnessControlDelegate> | 1322 scoped_ptr<KeyboardBrightnessControlDelegate> |
| 1332 keyboard_brightness_control_delegate) { | 1323 keyboard_brightness_control_delegate) { |
| 1333 keyboard_brightness_control_delegate_ = | 1324 keyboard_brightness_control_delegate_ = |
| 1334 keyboard_brightness_control_delegate.Pass(); | 1325 keyboard_brightness_control_delegate.Pass(); |
| 1335 } | 1326 } |
| 1336 | 1327 |
| 1337 } // namespace ash | 1328 } // namespace ash |
| OLD | NEW |