summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authoroshima <oshima@chromium.org>2015-04-22 19:52:30 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-23 02:52:33 +0000
commit9528e837025866c614005f9e1339e1d6dda5506c (patch)
tree69c604fcfad74809e7d0dd2a3dc06fecdd55228c /ash
parent40adb0489b01f68fe59ae0117cb97f21df47bf9d (diff)
downloadchromium_src-9528e837025866c614005f9e1339e1d6dda5506c.zip
chromium_src-9528e837025866c614005f9e1339e1d6dda5506c.tar.gz
chromium_src-9528e837025866c614005f9e1339e1d6dda5506c.tar.bz2
DisplayManager cleanup 3
Removed unnecessary function decl, member functions/variables. Repalced IsActiveDisplay with GetDisplayForId. use range based for loop where possible BUG=None Review URL: https://codereview.chromium.org/1101713003 Cr-Commit-Position: refs/heads/master@{#326434}
Diffstat (limited to 'ash')
-rw-r--r--ash/ash_switches.h9
-rw-r--r--ash/display/display_controller.cc4
-rw-r--r--ash/display/display_manager.cc108
-rw-r--r--ash/display/display_manager.h23
4 files changed, 54 insertions, 90 deletions
diff --git a/ash/ash_switches.h b/ash/ash_switches.h
index 0623d3b..40aba02 100644
--- a/ash/ash_switches.h
+++ b/ash/ash_switches.h
@@ -47,15 +47,6 @@ ASH_EXPORT extern const char kAuraLegacyPowerButton[];
ASH_EXPORT extern const char kForceAshToDesktop[];
#endif
-// Returns true if items can be dragged off the shelf to unpin.
-ASH_EXPORT bool UseDragOffShelf();
-
-#if defined(OS_CHROMEOS)
-// Returns true if a notification should appear when a low-power USB charger
-// is connected.
-ASH_EXPORT bool UseUsbChargerNotification();
-#endif
-
} // namespace switches
} // namespace ash
diff --git a/ash/display/display_controller.cc b/ash/display/display_controller.cc
index 3dd1bef..0068e95 100644
--- a/ash/display/display_controller.cc
+++ b/ash/display/display_controller.cc
@@ -479,10 +479,10 @@ void DisplayController::SetPrimaryDisplay(
const gfx::Display& new_primary_display) {
DisplayManager* display_manager = GetDisplayManager();
DCHECK(new_primary_display.is_valid());
- DCHECK(display_manager->IsActiveDisplay(new_primary_display));
+ DCHECK(display_manager->GetDisplayForId(new_primary_display.id()).is_valid());
if (!new_primary_display.is_valid() ||
- !display_manager->IsActiveDisplay(new_primary_display)) {
+ !display_manager->GetDisplayForId(new_primary_display.id()).is_valid()) {
LOG(ERROR) << "Invalid or non-existent display is requested:"
<< new_primary_display.ToString();
return;
diff --git a/ash/display/display_manager.cc b/ash/display/display_manager.cc
index 6ae9d6b..3dcbadd 100644
--- a/ash/display/display_manager.cc
+++ b/ash/display/display_manager.cc
@@ -109,10 +109,19 @@ void MaybeInitInternalDisplay(DisplayInfo* info) {
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_ash_(new ScreenAsh),
- screen_(screen_ash_.get()),
+ screen_(new ScreenAsh),
layout_store_(new DisplayLayoutStore),
first_display_id_(gfx::Display::kInvalidDisplayID),
num_connected_displays_(0),
@@ -130,16 +139,14 @@ DisplayManager::DisplayManager()
change_display_upon_host_resize_ = !base::SysInfo::IsRunningOnChromeOS();
#endif
- gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_ALTERNATE,
- screen_ash_.get());
+ gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_ALTERNATE, screen_.get());
gfx::Screen* current_native =
gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE);
// If there is no native, or the native was for shutdown,
// use ash's screen.
if (!current_native ||
current_native == screen_for_shutdown) {
- gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE,
- screen_ash_.get());
+ gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
}
}
@@ -196,23 +203,6 @@ void DisplayManager::RefreshFontParams() {
#endif // OS_CHROMEOS
}
-bool DisplayManager::IsActiveDisplay(const gfx::Display& display) const {
- for (DisplayList::const_iterator iter = active_display_list_.begin();
- iter != active_display_list_.end(); ++iter) {
- if ((*iter).id() == display.id())
- return true;
- }
- return false;
-}
-
-bool DisplayManager::HasInternalDisplay() const {
- return gfx::Display::InternalDisplayId() != gfx::Display::kInvalidDisplayID;
-}
-
-bool DisplayManager::IsInternalDisplayId(int64 id) const {
- return gfx::Display::InternalDisplayId() == id;
-}
-
DisplayLayout DisplayManager::GetCurrentDisplayLayout() {
DCHECK_LE(2U, num_connected_displays());
// Invert if the primary was swapped.
@@ -281,10 +271,10 @@ void DisplayManager::SetLayoutForCurrentDisplays(
// Primary's bounds stay the same. Just notify bounds change
// on the secondary.
- screen_ash_->NotifyMetricsChanged(
+ screen_->NotifyMetricsChanged(
ScreenUtil::GetSecondaryDisplay(),
gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS |
- gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA);
+ gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA);
if (delegate_)
delegate_->PostDisplayConfigurationChange();
}
@@ -298,13 +288,12 @@ const gfx::Display& DisplayManager::GetDisplayForId(int64 id) const {
const gfx::Display& DisplayManager::FindDisplayContainingPoint(
const gfx::Point& point_in_screen) const {
- for (DisplayList::const_iterator iter = active_display_list_.begin();
- iter != active_display_list_.end(); ++iter) {
- const gfx::Display& display = *iter;
- if (display.bounds().Contains(point_in_screen))
- return display;
- }
- return GetInvalidDisplay();
+ auto iter =
+ std::find_if(active_display_list_.begin(), active_display_list_.end(),
+ [point_in_screen](const gfx::Display& display) {
+ return display.bounds().Contains(point_in_screen);
+ });
+ return iter != active_display_list_.end() ? *iter : GetInvalidDisplay();
}
bool DisplayManager::UpdateWorkAreaOfDisplay(int64 display_id,
@@ -320,9 +309,8 @@ void DisplayManager::SetOverscanInsets(int64 display_id,
const gfx::Insets& insets_in_dip) {
bool update = false;
DisplayInfoList display_info_list;
- for (DisplayList::const_iterator iter = active_display_list_.begin();
- iter != active_display_list_.end(); ++iter) {
- DisplayInfo info = GetDisplayInfo(iter->id());
+ for (const auto& display : active_display_list_) {
+ DisplayInfo info = GetDisplayInfo(display.id());
if (info.id() == display_id) {
if (insets_in_dip.empty()) {
info.set_clear_overscan_insets(true);
@@ -345,9 +333,8 @@ void DisplayManager::SetOverscanInsets(int64 display_id,
void DisplayManager::SetDisplayRotation(int64 display_id,
gfx::Display::Rotation rotation) {
DisplayInfoList display_info_list;
- for (DisplayList::const_iterator iter = active_display_list_.begin();
- iter != active_display_list_.end(); ++iter) {
- DisplayInfo info = GetDisplayInfo(iter->id());
+ for (const auto& display : active_display_list_) {
+ DisplayInfo info = GetDisplayInfo(display.id());
if (info.id() == display_id) {
if (info.rotation() == rotation)
return;
@@ -368,9 +355,8 @@ bool DisplayManager::SetDisplayUIScale(int64 display_id,
bool found = false;
// TODO(mukai): merge this implementation into SetDisplayMode().
DisplayInfoList display_info_list;
- for (DisplayList::const_iterator iter = active_display_list_.begin();
- iter != active_display_list_.end(); ++iter) {
- DisplayInfo info = GetDisplayInfo(iter->id());
+ for (const auto& display : active_display_list_) {
+ DisplayInfo info = GetDisplayInfo(display.id());
if (info.id() == display_id) {
found = true;
if (info.configured_ui_scale() == ui_scale)
@@ -423,9 +409,8 @@ bool DisplayManager::SetDisplayMode(int64 display_id,
DisplayInfoList display_info_list;
bool display_property_changed = false;
bool resolution_changed = false;
- for (DisplayList::const_iterator iter = active_display_list_.begin();
- iter != active_display_list_.end(); ++iter) {
- DisplayInfo info = GetDisplayInfo(iter->id());
+ for (const auto& display : active_display_list_) {
+ DisplayInfo info = GetDisplayInfo(display.id());
if (info.id() == display_id) {
const std::vector<DisplayMode>& modes = info.display_modes();
std::vector<DisplayMode>::const_iterator iter =
@@ -659,10 +644,8 @@ void DisplayManager::OnNativeDisplaysChanged(
void DisplayManager::UpdateDisplays() {
DisplayInfoList display_info_list;
- for (DisplayList::const_iterator iter = active_display_list_.begin();
- iter != active_display_list_.end(); ++iter) {
- display_info_list.push_back(GetDisplayInfo(iter->id()));
- }
+ for (const auto& display : active_display_list_)
+ display_info_list.push_back(GetDisplayInfo(display.id()));
AddMirrorDisplayInfoIfAny(&display_info_list);
UpdateDisplays(display_info_list);
}
@@ -769,7 +752,7 @@ void DisplayManager::UpdateDisplays(
}
gfx::Display old_primary;
if (delegate_)
- old_primary = screen_ash_->GetPrimaryDisplay();
+ old_primary = screen_->GetPrimaryDisplay();
// Clear focus if the display has been removed, but don't clear focus if
// the destkop has been moved from one display to another
@@ -810,13 +793,13 @@ void DisplayManager::UpdateDisplays(
for (DisplayList::const_reverse_iterator iter = removed_displays.rbegin();
iter != removed_displays.rend(); ++iter) {
- screen_ash_->NotifyDisplayRemoved(active_display_list_.back());
+ screen_->NotifyDisplayRemoved(active_display_list_.back());
active_display_list_.pop_back();
}
for (std::vector<size_t>::iterator iter = added_display_indices.begin();
iter != added_display_indices.end(); ++iter) {
- screen_ash_->NotifyDisplayAdded(active_display_list_[*iter]);
+ screen_->NotifyDisplayAdded(active_display_list_[*iter]);
}
bool notify_primary_change =
@@ -833,7 +816,7 @@ void DisplayManager::UpdateDisplays(
metrics |= gfx::DisplayObserver::DISPLAY_METRIC_PRIMARY;
notify_primary_change = false;
}
- screen_ash_->NotifyMetricsChanged(updated_display, metrics);
+ screen_->NotifyMetricsChanged(updated_display, metrics);
}
if (notify_primary_change) {
@@ -849,7 +832,7 @@ void DisplayManager::UpdateDisplays(
if (primary.device_scale_factor() != old_primary.device_scale_factor())
metrics |= gfx::DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR;
- screen_ash_->NotifyMetricsChanged(primary, metrics);
+ screen_->NotifyMetricsChanged(primary, metrics);
}
}
@@ -1007,8 +990,8 @@ bool DisplayManager::UpdateDisplayBounds(int64 display_id,
return false;
gfx::Display* display = FindDisplayForId(display_id);
display->SetSize(display_info_[display_id].size_in_pixel());
- screen_ash_->NotifyMetricsChanged(
- *display, gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS);
+ screen_->NotifyMetricsChanged(*display,
+ gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS);
return true;
}
return false;
@@ -1028,10 +1011,9 @@ void DisplayManager::CreateMirrorWindowAsyncIfAny() {
void DisplayManager::CreateScreenForShutdown() const {
bool native_is_ash =
- gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE) ==
- screen_ash_.get();
+ gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE) == screen_.get();
delete screen_for_shutdown;
- screen_for_shutdown = screen_ash_->CloneForShutdown();
+ screen_for_shutdown = screen_->CloneForShutdown();
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_ALTERNATE,
screen_for_shutdown);
if (native_is_ash) {
@@ -1073,11 +1055,11 @@ void DisplayManager::CreateSoftwareMirroringDisplay(
}
gfx::Display* DisplayManager::FindDisplayForId(int64 id) {
- for (DisplayList::iterator iter = active_display_list_.begin();
- iter != active_display_list_.end(); ++iter) {
- if ((*iter).id() == id)
- return &(*iter);
- }
+ auto iter = std::find_if(
+ active_display_list_.begin(), active_display_list_.end(),
+ [id](const gfx::Display& display) { return display.id() == id; });
+ if (iter != active_display_list_.end())
+ return &(*iter);
DLOG(WARNING) << "Could not find display:" << id;
return NULL;
}
diff --git a/ash/display/display_manager.h b/ash/display/display_manager.h
index f0e82e8..c8480b0 100644
--- a/ash/display/display_manager.h
+++ b/ash/display/display_manager.h
@@ -79,6 +79,11 @@ 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;
@@ -90,13 +95,9 @@ class ASH_EXPORT DisplayManager
return layout_store_.get();
}
- gfx::Screen* screen() {
- return screen_;
- }
-
void set_delegate(Delegate* delegate) { delegate_ = delegate; }
- // When set to true, the MonitorManager calls OnDisplayMetricsChanged
+ // When set to true, the DisplayManager calls OnDisplayMetricsChanged
// even if the display's bounds didn't change. Used to swap primary
// display.
void set_force_bounds_changed(bool force_bounds_changed) {
@@ -117,14 +118,6 @@ class ASH_EXPORT DisplayManager
// configuration.
void RefreshFontParams();
- // True if the given |display| is currently connected.
- bool IsActiveDisplay(const gfx::Display& display) const;
-
- // True if there is an internal display.
- bool HasInternalDisplay() const;
-
- bool IsInternalDisplayId(int64 id) const;
-
// Returns the display layout used for current displays.
DisplayLayout GetCurrentDisplayLayout();
@@ -369,9 +362,7 @@ private:
Delegate* delegate_; // not owned.
- scoped_ptr<ScreenAsh> screen_ash_;
- // This is to have an accessor without ScreenAsh definition.
- gfx::Screen* screen_;
+ scoped_ptr<ScreenAsh> screen_;
scoped_ptr<DisplayLayoutStore> layout_store_;