From 0b9377aad2963ed234fb41e5be10dcf60676f7a1 Mon Sep 17 00:00:00 2001 From: oshima Date: Thu, 23 Apr 2015 01:07:43 -0700 Subject: [PATCH] Move HasInternalDisplay to gfx::Display Remove IsInternalDisplay as it's not useful. BUG=None Review URL: https://codereview.chromium.org/1102713002 Cr-Commit-Position: refs/heads/master@{#326475} --- .../screen_orientation_controller_chromeos.cc | 32 ++++++++++------------ ash/display/display_manager.cc | 19 ++++--------- ash/display/display_manager.h | 5 ---- ash/display/resolution_notification_controller.cc | 2 +- ash/system/chromeos/brightness/tray_brightness.cc | 4 +-- ash/system/chromeos/tray_display.cc | 14 +++++----- .../chromeos/display/display_preferences.cc | 9 +++--- .../options/chromeos/display_options_handler.cc | 2 +- ui/gfx/display.cc | 7 +++++ ui/gfx/display.h | 3 ++ 10 files changed, 47 insertions(+), 50 deletions(-) diff --git a/ash/content/display/screen_orientation_controller_chromeos.cc b/ash/content/display/screen_orientation_controller_chromeos.cc index dbd44652a2e6..ac157263315f 100644 --- a/ash/content/display/screen_orientation_controller_chromeos.cc +++ b/ash/content/display/screen_orientation_controller_chromeos.cc @@ -37,13 +37,12 @@ const float kDisplayRotationStickyAngleDegrees = 60.0f; const float kMinimumAccelerationScreenRotation = 4.2f; blink::WebScreenOrientationLockType GetDisplayNaturalOrientation() { - ash::DisplayManager* display_manager = - ash::Shell::GetInstance()->display_manager(); - if (!display_manager->HasInternalDisplay()) + if (!gfx::Display::HasInternalDisplay()) return blink::WebScreenOrientationLockLandscape; ash::DisplayInfo info = - display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()); + ash::Shell::GetInstance()->display_manager()->GetDisplayInfo( + gfx::Display::InternalDisplayId()); gfx::Size size = info.size_in_pixel(); switch (info.rotation()) { case gfx::Display::ROTATE_0: @@ -102,19 +101,17 @@ void ScreenOrientationController::SetRotationLocked(bool rotation_locked) { rotation_locked_orientation_ = blink::WebScreenOrientationLockAny; FOR_EACH_OBSERVER(Observer, observers_, OnRotationLockChanged(rotation_locked_)); - DisplayManager* display_manager = Shell::GetInstance()->display_manager(); - if (!display_manager->HasInternalDisplay()) + if (!gfx::Display::HasInternalDisplay()) return; base::AutoReset auto_ignore_display_configuration_updates( &ignore_display_configuration_updates_, true); - display_manager->RegisterDisplayRotationProperties(rotation_locked_, - current_rotation_); + Shell::GetInstance()->display_manager()->RegisterDisplayRotationProperties( + rotation_locked_, current_rotation_); } void ScreenOrientationController::SetDisplayRotation( gfx::Display::Rotation rotation) { - DisplayManager* display_manager = Shell::GetInstance()->display_manager(); - if (!display_manager->HasInternalDisplay()) + if (!gfx::Display::HasInternalDisplay()) return; current_rotation_ = rotation; base::AutoReset auto_ignore_display_configuration_updates( @@ -196,9 +193,9 @@ void ScreenOrientationController::Unlock(content::WebContents* web_contents) { void ScreenOrientationController::OnDisplayConfigurationChanged() { if (ignore_display_configuration_updates_) return; - DisplayManager* display_manager = Shell::GetInstance()->display_manager(); - if (!display_manager->HasInternalDisplay()) + if (!gfx::Display::HasInternalDisplay()) return; + DisplayManager* display_manager = Shell::GetInstance()->display_manager(); gfx::Display::Rotation user_rotation = display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) .rotation(); @@ -212,13 +209,14 @@ void ScreenOrientationController::OnDisplayConfigurationChanged() { } void ScreenOrientationController::OnMaximizeModeStarted() { - DisplayManager* display_manager = Shell::GetInstance()->display_manager(); // Do not exit early, as the internal display can be determined after Maximize // Mode has started. (chrome-os-partner:38796) // Always start observing. - if (display_manager->HasInternalDisplay()) { + if (gfx::Display::HasInternalDisplay()) { current_rotation_ = user_rotation_ = - display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) + Shell::GetInstance() + ->display_manager() + ->GetDisplayInfo(gfx::Display::InternalDisplayId()) .rotation(); } if (!rotation_locked_) @@ -294,10 +292,10 @@ void ScreenOrientationController::LockRotationToSecondaryOrientation( void ScreenOrientationController::LockToRotationMatchingOrientation( blink::WebScreenOrientationLockType lock_orientation) { - DisplayManager* display_manager = Shell::GetInstance()->display_manager(); - if (!display_manager->HasInternalDisplay()) + if (!gfx::Display::HasInternalDisplay()) return; + DisplayManager* display_manager = Shell::GetInstance()->display_manager(); gfx::Display::Rotation rotation = display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) .rotation(); diff --git a/ash/display/display_manager.cc b/ash/display/display_manager.cc index 3dcbadd75841..d40917ac63e1 100644 --- a/ash/display/display_manager.cc +++ b/ash/display/display_manager.cc @@ -104,21 +104,15 @@ void MaybeInitInternalDisplay(DisplayInfo* info) { } } +bool IsInternalDisplayId(int64 id) { + return gfx::Display::InternalDisplayId() == id; +} + } // namespace using std::string; using std::vector; -// static -bool DisplayManager::HasInternalDisplay() { - return gfx::Display::InternalDisplayId() != gfx::Display::kInvalidDisplayID; -} - -// static -bool DisplayManager::IsInternalDisplayId(int64 id) { - return gfx::Display::InternalDisplayId() == id; -} - DisplayManager::DisplayManager() : delegate_(NULL), screen_(new ScreenAsh), @@ -628,10 +622,9 @@ void DisplayManager::OnNativeDisplaysChanged( else if (display_modes_.find(iter->id()) != display_modes_.end()) display_modes_[iter->id()] = *display_modes_iter; } - if (HasInternalDisplay() && - !internal_display_connected && + if (gfx::Display::HasInternalDisplay() && !internal_display_connected && display_info_.find(gfx::Display::InternalDisplayId()) == - display_info_.end()) { + display_info_.end()) { DisplayInfo internal_display_info( gfx::Display::InternalDisplayId(), l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME), diff --git a/ash/display/display_manager.h b/ash/display/display_manager.h index c8480b077856..9aa686c50526 100644 --- a/ash/display/display_manager.h +++ b/ash/display/display_manager.h @@ -79,11 +79,6 @@ class ASH_EXPORT DisplayManager MIRRORING }; - // True if there is an internal display. - static bool HasInternalDisplay(); - - static bool IsInternalDisplayId(int64 id); - DisplayManager(); #if defined(OS_CHROMEOS) ~DisplayManager() override; diff --git a/ash/display/resolution_notification_controller.cc b/ash/display/resolution_notification_controller.cc index bea5554d430e..a0e98ea12971 100644 --- a/ash/display/resolution_notification_controller.cc +++ b/ash/display/resolution_notification_controller.cc @@ -139,7 +139,7 @@ ResolutionNotificationController::ResolutionChangeInfo::ResolutionChangeInfo( accept_callback(accept_callback), timeout_count(0) { DisplayManager* display_manager = Shell::GetInstance()->display_manager(); - if (!display_manager->HasInternalDisplay() && + if (!gfx::Display::HasInternalDisplay() && display_manager->num_connected_displays() == 1u) { timeout_count = kTimeoutInSec; } diff --git a/ash/system/chromeos/brightness/tray_brightness.cc b/ash/system/chromeos/brightness/tray_brightness.cc index e874ccf169e9..3e8b33095638 100644 --- a/ash/system/chromeos/brightness/tray_brightness.cc +++ b/ash/system/chromeos/brightness/tray_brightness.cc @@ -8,7 +8,6 @@ #include "ash/accelerators/accelerator_controller.h" #include "ash/ash_constants.h" -#include "ash/display/display_manager.h" #include "ash/metrics/user_metrics_recorder.h" #include "ash/shell.h" #include "ash/shell_observer.h" @@ -26,6 +25,7 @@ #include "grit/ash_resources.h" #include "grit/ash_strings.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/display.h" #include "ui/gfx/image/image.h" #include "ui/views/controls/button/image_button.h" #include "ui/views/controls/image_view.h" @@ -273,7 +273,7 @@ void TrayBrightness::HandleBrightnessChanged(double percent, // Never show the bubble on systems that lack internal displays: if an // external display's brightness is changed, it may already display the new // level via an on-screen display. - if (!Shell::GetInstance()->display_manager()->HasInternalDisplay()) + if (!gfx::Display::HasInternalDisplay()) return; if (brightness_view_) diff --git a/ash/system/chromeos/tray_display.cc b/ash/system/chromeos/tray_display.cc index 9a61897c174d..aaeead2f7f15 100644 --- a/ash/system/chromeos/tray_display.cc +++ b/ash/system/chromeos/tray_display.cc @@ -92,9 +92,9 @@ base::string16 GetAllDisplayInfo() { std::vector lines; int64 internal_id = gfx::Display::kInvalidDisplayID; // Make sure to show the internal display first. - if (display_manager->HasInternalDisplay() && - display_manager->IsInternalDisplayId( - display_manager->first_display_id())) { + if (gfx::Display::HasInternalDisplay() && + gfx::Display::InternalDisplayId() == + display_manager->first_display_id()) { internal_id = display_manager->first_display_id(); lines.push_back(GetDisplayInfoLine(internal_id)); } @@ -228,7 +228,7 @@ class DisplayView : public ActionableView { base::string16* additional_message_out) { DisplayManager* display_manager = GetDisplayManager(); if (display_manager->GetNumDisplays() > 1) { - if (GetDisplayManager()->HasInternalDisplay()) { + if (gfx::Display::HasInternalDisplay()) { return l10n_util::GetStringFUTF16( IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetExternalDisplayName()); } @@ -237,7 +237,7 @@ class DisplayView : public ActionableView { } if (display_manager->IsInMirrorMode()) { - if (GetDisplayManager()->HasInternalDisplay()) { + if (gfx::Display::HasInternalDisplay()) { return l10n_util::GetStringFUTF16( IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, GetDisplayName(display_manager->mirroring_display_id())); @@ -247,8 +247,8 @@ class DisplayView : public ActionableView { } int64 primary_id = Shell::GetScreen()->GetPrimaryDisplay().id(); - if (display_manager->HasInternalDisplay() && - !display_manager->IsInternalDisplayId(primary_id)) { + if (gfx::Display::HasInternalDisplay() && + !(gfx::Display::InternalDisplayId() == primary_id)) { if (additional_message_out) { *additional_message_out = l10n_util::GetStringUTF16( IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION); diff --git a/chrome/browser/chromeos/display/display_preferences.cc b/chrome/browser/chromeos/display/display_preferences.cc index a71342ddcd4b..dca2e5a29d91 100644 --- a/chrome/browser/chromeos/display/display_preferences.cc +++ b/chrome/browser/chromeos/display/display_preferences.cc @@ -348,16 +348,17 @@ void StoreDisplayPrefs() { } void StoreDisplayRotationPrefs(bool rotation_lock) { - ash::DisplayManager* display_manager = GetDisplayManager(); - if (!display_manager->HasInternalDisplay()) + if (!gfx::Display::HasInternalDisplay()) return; PrefService* local_state = g_browser_process->local_state(); DictionaryPrefUpdate update(local_state, prefs::kDisplayRotationLock); base::DictionaryValue* pref_data = update.Get(); pref_data->SetBoolean("lock", rotation_lock); - gfx::Display::Rotation rotation = display_manager-> - GetDisplayInfo(gfx::Display::InternalDisplayId()).rotation(); + gfx::Display::Rotation rotation = + GetDisplayManager() + ->GetDisplayInfo(gfx::Display::InternalDisplayId()) + .rotation(); pref_data->SetInteger("orientation", static_cast(rotation)); } diff --git a/chrome/browser/ui/webui/options/chromeos/display_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/display_options_handler.cc index a345d8a8ddbf..ca4cc50c06a7 100644 --- a/chrome/browser/ui/webui/options/chromeos/display_options_handler.cc +++ b/chrome/browser/ui/webui/options/chromeos/display_options_handler.cc @@ -124,7 +124,7 @@ bool ConvertValueToDisplayMode(const base::DictionaryValue* dict, base::DictionaryValue* ConvertDisplayModeToValue(int64 display_id, const ash::DisplayMode& mode) { - bool is_internal = GetDisplayManager()->IsInternalDisplayId(display_id); + bool is_internal = gfx::Display::InternalDisplayId() == display_id; base::DictionaryValue* result = new base::DictionaryValue(); gfx::Size size_dip = mode.GetSizeInDIP(is_internal); result->SetInteger("width", size_dip.width()); diff --git a/ui/gfx/display.cc b/ui/gfx/display.cc index 63353713f49d..6ae51b6d5b8d 100644 --- a/ui/gfx/display.cc +++ b/ui/gfx/display.cc @@ -198,12 +198,19 @@ bool Display::IsInternal() const { return is_valid() && (id_ == internal_display_id_); } +// static int64 Display::InternalDisplayId() { return internal_display_id_; } +// static void Display::SetInternalDisplayId(int64 internal_display_id) { internal_display_id_ = internal_display_id; } +// static +bool Display::HasInternalDisplay() { + return internal_display_id_ != kInvalidDisplayID; +} + } // namespace gfx diff --git a/ui/gfx/display.h b/ui/gfx/display.h index fe2a40cf632b..6f29d424a8dc 100644 --- a/ui/gfx/display.h +++ b/ui/gfx/display.h @@ -122,6 +122,9 @@ class GFX_EXPORT Display { static int64 InternalDisplayId(); static void SetInternalDisplayId(int64 internal_display_id); + // True if there is an internal display. + static bool HasInternalDisplay(); + static const int64 kInvalidDisplayID; private: -- 2.11.4.GIT