Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(853)

Unified Diff: ui/message_center/views/desktop_popup_alignment_delegate.cc

Issue 2078773003: Realign message center popups when displays are added or removed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Realign message center popups when displays are added or removed Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/message_center/views/desktop_popup_alignment_delegate.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/message_center/views/desktop_popup_alignment_delegate.cc
diff --git a/ui/message_center/views/desktop_popup_alignment_delegate.cc b/ui/message_center/views/desktop_popup_alignment_delegate.cc
index f67200def64ace65e3e331bb51c73008d401fac8..d51021d5bb75f28789ede39ed7b338c4dd7a6fcc 100644
--- a/ui/message_center/views/desktop_popup_alignment_delegate.cc
+++ b/ui/message_center/views/desktop_popup_alignment_delegate.cc
@@ -14,7 +14,7 @@ namespace message_center {
DesktopPopupAlignmentDelegate::DesktopPopupAlignmentDelegate()
: alignment_(POPUP_ALIGNMENT_BOTTOM | POPUP_ALIGNMENT_RIGHT),
- display_id_(display::Display::kInvalidDisplayID),
+ primary_display_id_(display::Display::kInvalidDisplayID),
screen_(NULL) {}
DesktopPopupAlignmentDelegate::~DesktopPopupAlignmentDelegate() {
@@ -29,7 +29,7 @@ void DesktopPopupAlignmentDelegate::StartObserving(display::Screen* screen) {
screen_ = screen;
screen_->AddObserver(this);
display::Display display = screen_->GetPrimaryDisplay();
- display_id_ = display.id();
+ primary_display_id_ = display.id();
RecomputeAlignment(display);
}
@@ -83,19 +83,36 @@ void DesktopPopupAlignmentDelegate::RecomputeAlignment(
: POPUP_ALIGNMENT_RIGHT;
}
+// Anytime the display configuration changes, we need to recompute the alignment
+// on the primary display.
+void DesktopPopupAlignmentDelegate::UpdatePrimaryDisplay() {
+ display::Display primary_display = screen_->GetPrimaryDisplay();
+ if (primary_display.id() != primary_display_id_) {
+ primary_display_id_ = primary_display.id();
+ RecomputeAlignment(primary_display);
+ DoUpdateIfPossible();
+ }
+}
+
void DesktopPopupAlignmentDelegate::OnDisplayAdded(
- const display::Display& new_display) {}
+ const display::Display& added_display) {
+ // The added display could be the new primary display.
+ UpdatePrimaryDisplay();
+}
void DesktopPopupAlignmentDelegate::OnDisplayRemoved(
- const display::Display& old_display) {}
+ const display::Display& removed_display) {
+ // The removed display may have been the primary display.
+ UpdatePrimaryDisplay();
+}
void DesktopPopupAlignmentDelegate::OnDisplayMetricsChanged(
const display::Display& display,
uint32_t metrics) {
- if (display.id() == display_id_) {
- RecomputeAlignment(display);
- DoUpdateIfPossible();
- }
+ // Set to kInvalidDisplayID so the alignment is updated regardless of whether
dewittj 2016/06/27 17:37:27 Why always recompute the alignment?
osandov 2016/06/27 19:22:52 I wanted to reuse the helper to handle all of the
+ // the primary display actually changed.
+ primary_display_id_ = display::Display::kInvalidDisplayID;
+ UpdatePrimaryDisplay();
}
} // namespace message_center
« no previous file with comments | « ui/message_center/views/desktop_popup_alignment_delegate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698