Chromium Code Reviews| Index: ash/display/display_change_observer_chromeos.cc |
| diff --git a/ash/display/display_change_observer_chromeos.cc b/ash/display/display_change_observer_chromeos.cc |
| index 352bd72341313143841576964f5891744beb0562..4b16348ddd96c410a6054d7fb3a8f42ac2fa769b 100644 |
| --- a/ash/display/display_change_observer_chromeos.cc |
| +++ b/ash/display/display_change_observer_chromeos.cc |
| @@ -11,15 +11,8 @@ |
| #include <utility> |
| #include <vector> |
| -#include "ash/common/wm_shell.h" |
| -#include "ash/display/display_util.h" |
| -#include "ash/shell.h" |
| -#include "base/command_line.h" |
| #include "base/logging.h" |
| -#include "grit/ash_strings.h" |
| -#include "ui/base/l10n/l10n_util.h" |
| #include "ui/base/user_activity/user_activity_detector.h" |
| -#include "ui/compositor/dip_util.h" |
| #include "ui/display/chromeos/touchscreen_util.h" |
| #include "ui/display/display.h" |
| #include "ui/display/manager/display_layout.h" |
| @@ -38,19 +31,6 @@ using ui::DisplayConfigurator; |
| namespace { |
| -// The DPI threshold to determine the device scale factor. |
| -// DPI higher than |dpi| will use |device_scale_factor|. |
| -struct DeviceScaleFactorDPIThreshold { |
| - float dpi; |
| - float device_scale_factor; |
| -}; |
| - |
| -const DeviceScaleFactorDPIThreshold kThresholdTable[] = { |
| - {200.0f, 2.0f}, |
| - {150.0f, 1.25f}, |
| - {0.0f, 1.0f}, |
| -}; |
|
oshima
2016/11/30 18:17:09
This is defined for readability/explanation purpos
kylechar
2016/11/30 21:46:03
Done.
|
| - |
| // 1 inch in mm. |
| const float kInchInMm = 25.4f; |
| @@ -58,7 +38,7 @@ const float kInchInMm = 25.4f; |
| const int kMinimumWidthFor4K = 3840; |
| // The list of device scale factors (in addition to 1.0f) which is |
| -// available in extrenal large monitors. |
| +// available in external large monitors. |
| const float kAdditionalDeviceScaleFactorsFor4k[] = {1.25f, 2.0f}; |
| void UpdateInternalDisplayId( |
| @@ -112,7 +92,7 @@ DisplayChangeObserver::GetExternalManagedDisplayModeList( |
| // Add the display mode if it isn't already present and override interlaced |
| // display modes with non-interlaced ones. |
| - DisplayModeMap::iterator display_mode_it = display_mode_map.find(size); |
| + auto display_mode_it = display_mode_map.find(size); |
| if (display_mode_it == display_mode_map.end()) |
| display_mode_map.insert(std::make_pair(size, display_mode)); |
| else if (display_mode_it->second->is_interlaced() && |
| @@ -127,7 +107,7 @@ DisplayChangeObserver::GetExternalManagedDisplayModeList( |
| if (output.native_mode()) { |
| const std::pair<int, int> size(native_mode->size().width(), |
| native_mode->size().height()); |
| - DisplayModeMap::iterator it = display_mode_map.find(size); |
| + auto it = display_mode_map.find(size); |
| DCHECK(it != display_mode_map.end()) |
| << "Native mode must be part of the mode list."; |
| @@ -150,14 +130,14 @@ DisplayChangeObserver::GetExternalManagedDisplayModeList( |
| return display_mode_list; |
| } |
| -DisplayChangeObserver::DisplayChangeObserver() { |
| - WmShell::Get()->AddShellObserver(this); |
| +DisplayChangeObserver::DisplayChangeObserver( |
| + std::unique_ptr<display::DisplayStringProvider> string_provider) |
| + : string_provider_(std::move(string_provider)) { |
| ui::InputDeviceManager::GetInstance()->AddObserver(this); |
| } |
| DisplayChangeObserver::~DisplayChangeObserver() { |
| ui::InputDeviceManager::GetInstance()->RemoveObserver(this); |
| - WmShell::Get()->RemoveShellObserver(this); |
| } |
| ui::MultipleDisplayState DisplayChangeObserver::GetStateForDisplayIds( |
| @@ -171,10 +151,8 @@ ui::MultipleDisplayState DisplayChangeObserver::GetStateForDisplayIds( |
| return display_state->display_id(); |
| }); |
| - const display::DisplayLayout& layout = Shell::GetInstance() |
| - ->display_manager() |
| - ->layout_store() |
| - ->GetRegisteredDisplayLayout(list); |
| + const display::DisplayLayout& layout = |
| + display_manager_->layout_store()->GetRegisteredDisplayLayout(list); |
| return layout.mirrored ? ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR |
| : ui::MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED; |
| } |
| @@ -182,8 +160,7 @@ ui::MultipleDisplayState DisplayChangeObserver::GetStateForDisplayIds( |
| bool DisplayChangeObserver::GetResolutionForDisplayId(int64_t display_id, |
| gfx::Size* size) const { |
| scoped_refptr<display::ManagedDisplayMode> mode = |
| - Shell::GetInstance()->display_manager()->GetSelectedModeForDisplayId( |
| - display_id); |
| + display_manager_->GetSelectedModeForDisplayId(display_id); |
| if (!mode) |
| return false; |
| *size = mode->size(); |
| @@ -212,8 +189,7 @@ void DisplayChangeObserver::OnDisplayModeChanged( |
| device_scale_factor = FindDeviceScaleFactor(dpi); |
| } else { |
| scoped_refptr<display::ManagedDisplayMode> mode = |
| - Shell::GetInstance()->display_manager()->GetSelectedModeForDisplayId( |
| - state->display_id()); |
| + display_manager_->GetSelectedModeForDisplayId(state->display_id()); |
| if (mode) { |
| device_scale_factor = mode->device_scale_factor(); |
| } else { |
| @@ -237,17 +213,17 @@ void DisplayChangeObserver::OnDisplayModeChanged( |
| std::string name; |
| switch (state->type()) { |
| case ui::DISPLAY_CONNECTION_TYPE_INTERNAL: |
| - name = l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME); |
| + name = string_provider_->GetInternalDisplayNameString(); |
| break; |
| case ui::DISPLAY_CONNECTION_TYPE_VIRTUAL: |
| - name = l10n_util::GetStringUTF8(IDS_ASH_VIRTUAL_DISPLAY_NAME); |
| + name = string_provider_->GetVirtualDisplayNameString(); |
| break; |
| default: |
| name = state->display_name(); |
| } |
| if (name.empty()) |
| - name = l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); |
| + name = string_provider_->GetUnknownDisplayNameString(); |
| bool has_overscan = state->has_overscan(); |
| int64_t id = state->display_id(); |
| @@ -271,17 +247,14 @@ void DisplayChangeObserver::OnDisplayModeChanged( |
| new_info.SetManagedDisplayModes(display_modes); |
| new_info.set_available_color_profiles( |
| - Shell::GetInstance() |
| - ->display_configurator() |
| - ->GetAvailableColorCalibrationProfiles(id)); |
| + display_configurator_->GetAvailableColorCalibrationProfiles(id)); |
| new_info.set_maximum_cursor_size(state->maximum_cursor_size()); |
| } |
| display::AssociateTouchscreens( |
| &displays, |
| ui::InputDeviceManager::GetInstance()->GetTouchscreenDevices()); |
| - // DisplayManager can be null during the boot. |
| - Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(displays); |
| + display_manager_->OnNativeDisplaysChanged(displays); |
| // For the purposes of user activity detection, ignore synthetic mouse events |
| // that are triggered by screen resizes: http://crbug.com/360634 |
| @@ -297,28 +270,22 @@ void DisplayChangeObserver::OnDisplayModeChangeFailed( |
| // If display configuration failed during startup, simply update the display |
| // manager with detected displays. If no display is detected, it will |
| // create a pseudo display. |
| - if (Shell::GetInstance()->display_manager()->GetNumDisplays() == 0) |
| + if (display_manager_->GetNumDisplays() == 0) |
| OnDisplayModeChanged(displays); |
| } |
| -void DisplayChangeObserver::OnAppTerminating() { |
| - // Stop handling display configuration events once the shutdown |
| - // process starts. crbug.com/177014. |
| - Shell::GetInstance()->display_configurator()->PrepareForExit(); |
| +void DisplayChangeObserver::OnTouchscreenDeviceConfigurationChanged() { |
| + OnDisplayModeChanged(display_configurator_->cached_displays()); |
| } |
| // static |
| float DisplayChangeObserver::FindDeviceScaleFactor(float dpi) { |
| - for (size_t i = 0; i < arraysize(kThresholdTable); ++i) { |
| - if (dpi > kThresholdTable[i].dpi) |
| - return kThresholdTable[i].device_scale_factor; |
| - } |
| - return 1.0f; |
| -} |
| - |
| -void DisplayChangeObserver::OnTouchscreenDeviceConfigurationChanged() { |
| - OnDisplayModeChanged( |
| - Shell::GetInstance()->display_configurator()->cached_displays()); |
| + if (dpi > 200.0f) |
| + return 2.0f; |
| + else if (dpi > 150.0f) |
| + return 1.25f; |
| + else |
| + return 1.0f; |
| } |
| } // namespace ash |