Chromium Code Reviews| 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 |