| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/message_center/views/desktop_popup_alignment_delegate.h" | 5 #include "ui/message_center/views/desktop_popup_alignment_delegate.h" |
| 6 | 6 |
| 7 #include "ui/display/display.h" | 7 #include "ui/display/display.h" |
| 8 #include "ui/display/screen.h" | 8 #include "ui/display/screen.h" |
| 9 #include "ui/gfx/geometry/rect.h" | 9 #include "ui/gfx/geometry/rect.h" |
| 10 #include "ui/message_center/message_center_style.h" | 10 #include "ui/message_center/message_center_style.h" |
| 11 #include "ui/message_center/views/message_popup_collection.h" | 11 #include "ui/message_center/views/message_popup_collection.h" |
| 12 | 12 |
| 13 namespace message_center { | 13 namespace message_center { |
| 14 | 14 |
| 15 DesktopPopupAlignmentDelegate::DesktopPopupAlignmentDelegate() | 15 DesktopPopupAlignmentDelegate::DesktopPopupAlignmentDelegate() |
| 16 : alignment_(POPUP_ALIGNMENT_BOTTOM | POPUP_ALIGNMENT_RIGHT), | 16 : alignment_(POPUP_ALIGNMENT_BOTTOM | POPUP_ALIGNMENT_RIGHT), |
| 17 display_id_(display::Display::kInvalidDisplayID), | 17 primary_display_id_(display::Display::kInvalidDisplayID), |
| 18 screen_(NULL) {} | 18 screen_(NULL) {} |
| 19 | 19 |
| 20 DesktopPopupAlignmentDelegate::~DesktopPopupAlignmentDelegate() { | 20 DesktopPopupAlignmentDelegate::~DesktopPopupAlignmentDelegate() { |
| 21 if (screen_) | 21 if (screen_) |
| 22 screen_->RemoveObserver(this); | 22 screen_->RemoveObserver(this); |
| 23 } | 23 } |
| 24 | 24 |
| 25 void DesktopPopupAlignmentDelegate::StartObserving(display::Screen* screen) { | 25 void DesktopPopupAlignmentDelegate::StartObserving(display::Screen* screen) { |
| 26 if (screen_ || !screen) | 26 if (screen_ || !screen) |
| 27 return; | 27 return; |
| 28 | 28 |
| 29 screen_ = screen; | 29 screen_ = screen; |
| 30 screen_->AddObserver(this); | 30 screen_->AddObserver(this); |
| 31 display::Display display = screen_->GetPrimaryDisplay(); | 31 display::Display display = screen_->GetPrimaryDisplay(); |
| 32 display_id_ = display.id(); | 32 primary_display_id_ = display.id(); |
| 33 RecomputeAlignment(display); | 33 RecomputeAlignment(display); |
| 34 } | 34 } |
| 35 | 35 |
| 36 int DesktopPopupAlignmentDelegate::GetToastOriginX( | 36 int DesktopPopupAlignmentDelegate::GetToastOriginX( |
| 37 const gfx::Rect& toast_bounds) const { | 37 const gfx::Rect& toast_bounds) const { |
| 38 if (IsFromLeft()) | 38 if (IsFromLeft()) |
| 39 return work_area_.x() + kMarginBetweenItems; | 39 return work_area_.x() + kMarginBetweenItems; |
| 40 return work_area_.right() - kMarginBetweenItems - toast_bounds.width(); | 40 return work_area_.right() - kMarginBetweenItems - toast_bounds.width(); |
| 41 } | 41 } |
| 42 | 42 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 ? POPUP_ALIGNMENT_LEFT | 82 ? POPUP_ALIGNMENT_LEFT |
| 83 : POPUP_ALIGNMENT_RIGHT; | 83 : POPUP_ALIGNMENT_RIGHT; |
| 84 } | 84 } |
| 85 | 85 |
| 86 void DesktopPopupAlignmentDelegate::ConfigureWidgetInitParamsForContainer( | 86 void DesktopPopupAlignmentDelegate::ConfigureWidgetInitParamsForContainer( |
| 87 views::Widget* widget, | 87 views::Widget* widget, |
| 88 views::Widget::InitParams* init_params) { | 88 views::Widget::InitParams* init_params) { |
| 89 // Do nothing, which will use the default container. | 89 // Do nothing, which will use the default container. |
| 90 } | 90 } |
| 91 | 91 |
| 92 // Anytime the display configuration changes, we need to recompute the alignment |
| 93 // on the primary display. But, we get different events on different platforms. |
| 94 // On Windows, for example, when switching from a laptop display to an external |
| 95 // monitor, we get a OnDisplayMetricsChanged() event. On Linux, we get a |
| 96 // OnDisplayRemoved() and a OnDisplayAdded() instead. In order to account for |
| 97 // these slightly different abstractions, we update on every event. |
| 98 void DesktopPopupAlignmentDelegate::UpdatePrimaryDisplay() { |
| 99 display::Display primary_display = screen_->GetPrimaryDisplay(); |
| 100 if (primary_display.id() != primary_display_id_) { |
| 101 primary_display_id_ = primary_display.id(); |
| 102 RecomputeAlignment(primary_display); |
| 103 DoUpdateIfPossible(); |
| 104 } |
| 105 } |
| 106 |
| 92 void DesktopPopupAlignmentDelegate::OnDisplayAdded( | 107 void DesktopPopupAlignmentDelegate::OnDisplayAdded( |
| 93 const display::Display& new_display) {} | 108 const display::Display& added_display) { |
| 109 // The added display could be the new primary display. |
| 110 UpdatePrimaryDisplay(); |
| 111 } |
| 94 | 112 |
| 95 void DesktopPopupAlignmentDelegate::OnDisplayRemoved( | 113 void DesktopPopupAlignmentDelegate::OnDisplayRemoved( |
| 96 const display::Display& old_display) {} | 114 const display::Display& removed_display) { |
| 115 // The removed display may have been the primary display. |
| 116 UpdatePrimaryDisplay(); |
| 117 } |
| 97 | 118 |
| 98 void DesktopPopupAlignmentDelegate::OnDisplayMetricsChanged( | 119 void DesktopPopupAlignmentDelegate::OnDisplayMetricsChanged( |
| 99 const display::Display& display, | 120 const display::Display& display, |
| 100 uint32_t metrics) { | 121 uint32_t metrics) { |
| 101 if (display.id() == display_id_) { | 122 // Set to kInvalidDisplayID so the alignment is updated regardless of whether |
| 102 RecomputeAlignment(display); | 123 // the primary display actually changed. |
| 103 DoUpdateIfPossible(); | 124 primary_display_id_ = display::Display::kInvalidDisplayID; |
| 104 } | 125 UpdatePrimaryDisplay(); |
| 105 } | 126 } |
| 106 | 127 |
| 107 } // namespace message_center | 128 } // namespace message_center |
| OLD | NEW |