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