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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 // the taskbar is on the top or bottom. 76 // the taskbar is on the top or bottom.
77 // 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
78 // 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
79 // the top before concluding that the taskbar is at the left. 79 // the top before concluding that the taskbar is at the left.
80 alignment_ |= (work_area_.x() > display.bounds().x() && 80 alignment_ |= (work_area_.x() > display.bounds().x() &&
81 work_area_.y() == display.bounds().y()) 81 work_area_.y() == display.bounds().y())
82 ? POPUP_ALIGNMENT_LEFT 82 ? POPUP_ALIGNMENT_LEFT
83 : POPUP_ALIGNMENT_RIGHT; 83 : POPUP_ALIGNMENT_RIGHT;
84 } 84 }
85 85
86 // Anytime the display configuration changes, we need to recompute the alignment
87 // on the primary display.
88 void DesktopPopupAlignmentDelegate::UpdatePrimaryDisplay() {
89 display::Display primary_display = screen_->GetPrimaryDisplay();
90 if (primary_display.id() != primary_display_id_) {
91 primary_display_id_ = primary_display.id();
92 RecomputeAlignment(primary_display);
93 DoUpdateIfPossible();
94 }
95 }
96
86 void DesktopPopupAlignmentDelegate::OnDisplayAdded( 97 void DesktopPopupAlignmentDelegate::OnDisplayAdded(
87 const display::Display& new_display) {} 98 const display::Display& added_display) {
99 // The added display could be the new primary display.
100 UpdatePrimaryDisplay();
101 }
88 102
89 void DesktopPopupAlignmentDelegate::OnDisplayRemoved( 103 void DesktopPopupAlignmentDelegate::OnDisplayRemoved(
90 const display::Display& old_display) {} 104 const display::Display& removed_display) {
105 // The removed display may have been the primary display.
106 UpdatePrimaryDisplay();
107 }
91 108
92 void DesktopPopupAlignmentDelegate::OnDisplayMetricsChanged( 109 void DesktopPopupAlignmentDelegate::OnDisplayMetricsChanged(
93 const display::Display& display, 110 const display::Display& display,
94 uint32_t metrics) { 111 uint32_t metrics) {
95 if (display.id() == display_id_) { 112 // 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
96 RecomputeAlignment(display); 113 // the primary display actually changed.
97 DoUpdateIfPossible(); 114 primary_display_id_ = display::Display::kInvalidDisplayID;
98 } 115 UpdatePrimaryDisplay();
99 } 116 }
100 117
101 } // namespace message_center 118 } // namespace message_center
OLDNEW
« 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