| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/field_trial.h" | |
| 10 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 11 #include "ui/base/material_design/material_design_controller.h" | 10 #include "ui/base/material_design/material_design_controller.h" |
| 12 #include "ui/base/ui_base_switches.h" | 11 #include "ui/base/ui_base_switches.h" |
| 13 | 12 |
| 14 #if defined(OS_CHROMEOS) | 13 #if defined(OS_CHROMEOS) |
| 15 #include "ui/base/touch/touch_device.h" | 14 #include "ui/base/touch/touch_device.h" |
| 16 #include "ui/events/devices/device_data_manager.h" | 15 #include "ui/events/devices/device_data_manager.h" |
| 17 | 16 |
| 18 #if defined(USE_OZONE) | 17 #if defined(USE_OZONE) |
| 19 #include <fcntl.h> | 18 #include <fcntl.h> |
| 20 | 19 |
| 21 #include "base/files/file_enumerator.h" | 20 #include "base/files/file_enumerator.h" |
| 22 #include "base/threading/thread_restrictions.h" | 21 #include "base/threading/thread_restrictions.h" |
| 23 #include "ui/events/ozone/evdev/event_device_info.h" | 22 #include "ui/events/ozone/evdev/event_device_info.h" |
| 24 #endif // defined(USE_OZONE) | 23 #endif // defined(USE_OZONE) |
| 25 | 24 |
| 26 #endif // defined(OS_CHROMEOS) | 25 #endif // defined(OS_CHROMEOS) |
| 27 | 26 |
| 28 namespace ui { | 27 namespace ui { |
| 29 | 28 |
| 30 // static | |
| 31 bool MaterialDesignController::is_mode_initialized_ = false; | 29 bool MaterialDesignController::is_mode_initialized_ = false; |
| 30 |
| 32 MaterialDesignController::Mode MaterialDesignController::mode_ = | 31 MaterialDesignController::Mode MaterialDesignController::mode_ = |
| 33 MaterialDesignController::NON_MATERIAL; | 32 MaterialDesignController::NON_MATERIAL; |
| 34 | 33 |
| 35 bool MaterialDesignController::include_secondary_ui_ = false; | 34 bool MaterialDesignController::include_secondary_ui_ = false; |
| 36 | 35 |
| 37 // static | 36 // static |
| 38 void MaterialDesignController::Initialize() { | 37 void MaterialDesignController::Initialize() { |
| 39 InitializeWithDefaultMode(DefaultMode()); | |
| 40 } | |
| 41 | |
| 42 // static | |
| 43 void MaterialDesignController::InitializeWithDefaultMode(Mode mode) { | |
| 44 TRACE_EVENT0("startup", "MaterialDesignController::InitializeMode"); | 38 TRACE_EVENT0("startup", "MaterialDesignController::InitializeMode"); |
| 45 CHECK(!is_mode_initialized_); | 39 CHECK(!is_mode_initialized_); |
| 46 #if !defined(ENABLE_TOPCHROME_MD) | 40 #if !defined(ENABLE_TOPCHROME_MD) |
| 47 SetMode(NON_MATERIAL); | 41 SetMode(NON_MATERIAL); |
| 48 #else | 42 #else |
| 49 const std::string switch_value = | 43 const std::string switch_value = |
| 50 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 44 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 51 switches::kTopChromeMD); | 45 switches::kTopChromeMD); |
| 52 | 46 |
| 53 if (switch_value == switches::kTopChromeMDMaterial) { | 47 if (switch_value == switches::kTopChromeMDMaterial) { |
| 54 SetMode(MATERIAL_NORMAL); | 48 SetMode(MATERIAL_NORMAL); |
| 55 } else if (switch_value == switches::kTopChromeMDMaterialHybrid) { | 49 } else if (switch_value == switches::kTopChromeMDMaterialHybrid) { |
| 56 SetMode(MATERIAL_HYBRID); | 50 SetMode(MATERIAL_HYBRID); |
| 57 } else if (switch_value == switches::kTopChromeMDNonMaterial) { | 51 } else if (switch_value == switches::kTopChromeMDNonMaterial) { |
| 58 SetMode(NON_MATERIAL); | 52 SetMode(NON_MATERIAL); |
| 59 } else { | 53 } else { |
| 60 if (!switch_value.empty()) { | 54 if (!switch_value.empty()) { |
| 61 LOG(ERROR) << "Invalid value='" << switch_value | 55 LOG(ERROR) << "Invalid value='" << switch_value |
| 62 << "' for command line switch '" << switches::kTopChromeMD | 56 << "' for command line switch '" << switches::kTopChromeMD |
| 63 << "'."; | 57 << "'."; |
| 64 } | 58 } |
| 65 | 59 SetMode(DefaultMode()); |
| 66 // The field trial value, if any, overrides the provided default mode. | |
| 67 constexpr char kMaterialDesignModeFieldTrialName[] = "MaterialDesignMode"; | |
| 68 constexpr char kNonMaterialGroupName[] = "NonMaterial"; | |
| 69 constexpr char kMaterialNormalGroupName[] = "MaterialNormal"; | |
| 70 constexpr char kMaterialHybridGroupName[] = "MaterialHybrid"; | |
| 71 const std::string group = | |
| 72 base::FieldTrialList::FindFullName(kMaterialDesignModeFieldTrialName); | |
| 73 if (group == kNonMaterialGroupName) | |
| 74 mode = NON_MATERIAL; | |
| 75 else if (group == kMaterialNormalGroupName) | |
| 76 mode = MATERIAL_NORMAL; | |
| 77 else if (group == kMaterialHybridGroupName) | |
| 78 mode = MATERIAL_HYBRID; | |
| 79 | |
| 80 SetMode(mode); | |
| 81 } | 60 } |
| 82 | 61 |
| 83 include_secondary_ui_ = base::CommandLine::ForCurrentProcess()->HasSwitch( | 62 include_secondary_ui_ = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 84 switches::kExtendMdToSecondaryUi); | 63 switches::kExtendMdToSecondaryUi); |
| 85 #endif // !defined(ENABLE_TOPCHROME_MD) | 64 #endif // !defined(ENABLE_TOPCHROME_MD) |
| 86 } | 65 } |
| 87 | 66 |
| 88 // static | 67 // static |
| 89 MaterialDesignController::Mode MaterialDesignController::GetMode() { | 68 MaterialDesignController::Mode MaterialDesignController::GetMode() { |
| 90 CHECK(is_mode_initialized_); | 69 CHECK(is_mode_initialized_); |
| 91 return mode_; | 70 return mode_; |
| 92 } | 71 } |
| 93 | 72 |
| 94 // static | 73 // static |
| 95 bool MaterialDesignController::IsModeMaterial() { | 74 bool MaterialDesignController::IsModeMaterial() { |
| 96 return GetMode() == MATERIAL_NORMAL || GetMode() == MATERIAL_HYBRID; | 75 return GetMode() == MATERIAL_NORMAL || GetMode() == MATERIAL_HYBRID; |
| 97 } | 76 } |
| 98 | 77 |
| 99 // static | 78 // static |
| 100 bool MaterialDesignController::IsSecondaryUiMaterial() { | 79 bool MaterialDesignController::IsSecondaryUiMaterial() { |
| 101 return IsModeMaterial() && include_secondary_ui_; | 80 return IsModeMaterial() && include_secondary_ui_; |
| 102 } | 81 } |
| 103 | 82 |
| 104 // static | 83 // static |
| 105 void MaterialDesignController::Uninitialize() { | |
| 106 is_mode_initialized_ = false; | |
| 107 } | |
| 108 | |
| 109 // static | |
| 110 void MaterialDesignController::SetMode(MaterialDesignController::Mode mode) { | |
| 111 mode_ = mode; | |
| 112 is_mode_initialized_ = true; | |
| 113 } | |
| 114 | |
| 115 // static | |
| 116 MaterialDesignController::Mode MaterialDesignController::DefaultMode() { | 84 MaterialDesignController::Mode MaterialDesignController::DefaultMode() { |
| 117 #if defined(OS_CHROMEOS) | 85 #if defined(OS_CHROMEOS) |
| 118 // If a scan of available devices has already completed, use material-hybrid | 86 // If a scan of available devices has already completed, use material-hybrid |
| 119 // if a touchscreen is present. | 87 // if a touchscreen is present. |
| 120 if (DeviceDataManager::HasInstance() && | 88 if (DeviceDataManager::HasInstance() && |
| 121 DeviceDataManager::GetInstance()->device_lists_complete()) { | 89 DeviceDataManager::GetInstance()->device_lists_complete()) { |
| 122 return GetTouchScreensAvailability() == TouchScreensAvailability::ENABLED | 90 return GetTouchScreensAvailability() == TouchScreensAvailability::ENABLED |
| 123 ? MATERIAL_HYBRID | 91 ? MATERIAL_HYBRID |
| 124 : MATERIAL_NORMAL; | 92 : MATERIAL_NORMAL; |
| 125 } | 93 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 138 if (fd >= 0) { | 106 if (fd >= 0) { |
| 139 if (devinfo.Initialize(fd, path) && devinfo.HasTouchscreen()) { | 107 if (devinfo.Initialize(fd, path) && devinfo.HasTouchscreen()) { |
| 140 close(fd); | 108 close(fd); |
| 141 return MATERIAL_HYBRID; | 109 return MATERIAL_HYBRID; |
| 142 } | 110 } |
| 143 close(fd); | 111 close(fd); |
| 144 } | 112 } |
| 145 } | 113 } |
| 146 #endif // defined(USE_OZONE) | 114 #endif // defined(USE_OZONE) |
| 147 return MATERIAL_NORMAL; | 115 return MATERIAL_NORMAL; |
| 148 #elif defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN) | 116 #elif defined(OS_LINUX) || defined(OS_MACOSX) |
| 149 return MATERIAL_NORMAL; | 117 return MATERIAL_NORMAL; |
| 150 #else | 118 #else |
| 151 return NON_MATERIAL; | 119 return NON_MATERIAL; |
| 152 #endif // defined(OS_CHROMEOS) | 120 #endif // defined(OS_CHROMEOS) |
| 153 } | 121 } |
| 154 | 122 |
| 123 // static |
| 124 void MaterialDesignController::Uninitialize() { |
| 125 is_mode_initialized_ = false; |
| 126 } |
| 127 |
| 128 // static |
| 129 void MaterialDesignController::SetMode(MaterialDesignController::Mode mode) { |
| 130 mode_ = mode; |
| 131 is_mode_initialized_ = true; |
| 132 } |
| 133 |
| 155 } // namespace ui | 134 } // namespace ui |
| OLD | NEW |