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/gfx/display.h" | 7 #include "ui/display/display.h" |
| 8 #include "ui/display/screen.h" |
8 #include "ui/gfx/geometry/rect.h" | 9 #include "ui/gfx/geometry/rect.h" |
9 #include "ui/gfx/screen.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_(gfx::Display::kInvalidDisplayID), | 17 display_id_(display::Display::kInvalidDisplayID), |
18 screen_(NULL) { | 18 screen_(NULL) {} |
19 } | |
20 | 19 |
21 DesktopPopupAlignmentDelegate::~DesktopPopupAlignmentDelegate() { | 20 DesktopPopupAlignmentDelegate::~DesktopPopupAlignmentDelegate() { |
22 if (screen_) | 21 if (screen_) |
23 screen_->RemoveObserver(this); | 22 screen_->RemoveObserver(this); |
24 } | 23 } |
25 | 24 |
26 void DesktopPopupAlignmentDelegate::StartObserving(gfx::Screen* screen) { | 25 void DesktopPopupAlignmentDelegate::StartObserving(display::Screen* screen) { |
27 if (screen_ || !screen) | 26 if (screen_ || !screen) |
28 return; | 27 return; |
29 | 28 |
30 screen_ = screen; | 29 screen_ = screen; |
31 screen_->AddObserver(this); | 30 screen_->AddObserver(this); |
32 gfx::Display display = screen_->GetPrimaryDisplay(); | 31 display::Display display = screen_->GetPrimaryDisplay(); |
33 display_id_ = display.id(); | 32 display_id_ = display.id(); |
34 RecomputeAlignment(display); | 33 RecomputeAlignment(display); |
35 } | 34 } |
36 | 35 |
37 int DesktopPopupAlignmentDelegate::GetToastOriginX( | 36 int DesktopPopupAlignmentDelegate::GetToastOriginX( |
38 const gfx::Rect& toast_bounds) const { | 37 const gfx::Rect& toast_bounds) const { |
39 if (IsFromLeft()) | 38 if (IsFromLeft()) |
40 return work_area_.x() + kMarginBetweenItems; | 39 return work_area_.x() + kMarginBetweenItems; |
41 return work_area_.right() - kMarginBetweenItems - toast_bounds.width(); | 40 return work_area_.right() - kMarginBetweenItems - toast_bounds.width(); |
42 } | 41 } |
(...skipping 10 matching lines...) Expand all Loading... |
53 | 52 |
54 bool DesktopPopupAlignmentDelegate::IsTopDown() const { | 53 bool DesktopPopupAlignmentDelegate::IsTopDown() const { |
55 return (alignment_ & POPUP_ALIGNMENT_TOP) != 0; | 54 return (alignment_ & POPUP_ALIGNMENT_TOP) != 0; |
56 } | 55 } |
57 | 56 |
58 bool DesktopPopupAlignmentDelegate::IsFromLeft() const { | 57 bool DesktopPopupAlignmentDelegate::IsFromLeft() const { |
59 return (alignment_ & POPUP_ALIGNMENT_LEFT) != 0; | 58 return (alignment_ & POPUP_ALIGNMENT_LEFT) != 0; |
60 } | 59 } |
61 | 60 |
62 void DesktopPopupAlignmentDelegate::RecomputeAlignment( | 61 void DesktopPopupAlignmentDelegate::RecomputeAlignment( |
63 const gfx::Display& display) { | 62 const display::Display& display) { |
64 if (work_area_ == display.work_area()) | 63 if (work_area_ == display.work_area()) |
65 return; | 64 return; |
66 | 65 |
67 work_area_ = display.work_area(); | 66 work_area_ = display.work_area(); |
68 | 67 |
69 // If the taskbar is at the top, render notifications top down. Some platforms | 68 // If the taskbar is at the top, render notifications top down. Some platforms |
70 // like Gnome can have taskbars at top and bottom. In this case it's more | 69 // like Gnome can have taskbars at top and bottom. In this case it's more |
71 // likely that the systray is on the top one. | 70 // likely that the systray is on the top one. |
72 alignment_ = work_area_.y() > display.bounds().y() ? POPUP_ALIGNMENT_TOP | 71 alignment_ = work_area_.y() > display.bounds().y() ? POPUP_ALIGNMENT_TOP |
73 : POPUP_ALIGNMENT_BOTTOM; | 72 : POPUP_ALIGNMENT_BOTTOM; |
74 | 73 |
75 // If the taskbar is on the left show the notifications on the left. Otherwise | 74 // If the taskbar is on the left show the notifications on the left. Otherwise |
76 // show it on right since it's very likely that the systray is on the right if | 75 // show it on right since it's very likely that the systray is on the right if |
77 // the taskbar is on the top or bottom. | 76 // the taskbar is on the top or bottom. |
78 // Since on some platforms like Ubuntu Unity there's also a launcher along | 77 // Since on some platforms like Ubuntu Unity there's also a launcher along |
79 // with a taskbar (panel), we need to check that there is really nothing at | 78 // with a taskbar (panel), we need to check that there is really nothing at |
80 // the top before concluding that the taskbar is at the left. | 79 // the top before concluding that the taskbar is at the left. |
81 alignment_ |= (work_area_.x() > display.bounds().x() && | 80 alignment_ |= (work_area_.x() > display.bounds().x() && |
82 work_area_.y() == display.bounds().y()) | 81 work_area_.y() == display.bounds().y()) |
83 ? POPUP_ALIGNMENT_LEFT | 82 ? POPUP_ALIGNMENT_LEFT |
84 : POPUP_ALIGNMENT_RIGHT; | 83 : POPUP_ALIGNMENT_RIGHT; |
85 } | 84 } |
86 | 85 |
87 void DesktopPopupAlignmentDelegate::OnDisplayAdded( | 86 void DesktopPopupAlignmentDelegate::OnDisplayAdded( |
88 const gfx::Display& new_display) { | 87 const display::Display& new_display) {} |
89 } | |
90 | 88 |
91 void DesktopPopupAlignmentDelegate::OnDisplayRemoved( | 89 void DesktopPopupAlignmentDelegate::OnDisplayRemoved( |
92 const gfx::Display& old_display) { | 90 const display::Display& old_display) {} |
93 } | |
94 | 91 |
95 void DesktopPopupAlignmentDelegate::OnDisplayMetricsChanged( | 92 void DesktopPopupAlignmentDelegate::OnDisplayMetricsChanged( |
96 const gfx::Display& display, | 93 const display::Display& display, |
97 uint32_t metrics) { | 94 uint32_t metrics) { |
98 if (display.id() == display_id_) { | 95 if (display.id() == display_id_) { |
99 RecomputeAlignment(display); | 96 RecomputeAlignment(display); |
100 DoUpdateIfPossible(); | 97 DoUpdateIfPossible(); |
101 } | 98 } |
102 } | 99 } |
103 | 100 |
104 } // namespace message_center | 101 } // namespace message_center |
OLD | NEW |