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

Side by Side Diff: ash/system/web_notification/ash_popup_alignment_delegate.cc

Issue 2103603002: mash: Remove StatusAreaWidget references from system tray classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments, rename SetSystemTrayHeight to SetTrayBubbleHeight Created 4 years, 5 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/system/web_notification/ash_popup_alignment_delegate.h"
6
7 #include "ash/common/shelf/shelf_constants.h"
8 #include "ash/common/shelf/shelf_types.h"
9 #include "ash/common/shelf/wm_shelf.h"
10 #include "ash/common/shell_window_ids.h"
11 #include "ash/common/wm_root_window_controller.h"
12 #include "ash/common/wm_shell.h"
13 #include "ash/common/wm_window.h"
14 #include "base/i18n/rtl.h"
15 #include "ui/display/display.h"
16 #include "ui/display/screen.h"
17 #include "ui/gfx/geometry/rect.h"
18 #include "ui/message_center/message_center_style.h"
19 #include "ui/message_center/views/message_popup_collection.h"
20
21 namespace ash {
22
23 namespace {
24
25 const int kToastMarginX = 3;
26
27 // If there should be no margin for the first item, this value needs to be
28 // substracted to flush the message to the shelf (the width of the border +
29 // shadow).
30 const int kNoToastMarginBorderAndShadowOffset = 2;
31
32 } // namespace
33
34 AshPopupAlignmentDelegate::AshPopupAlignmentDelegate(WmShelf* shelf)
35 : screen_(NULL), shelf_(shelf), system_tray_height_(0) {
36 shelf_->AddObserver(this);
37 }
38
39 AshPopupAlignmentDelegate::~AshPopupAlignmentDelegate() {
40 if (screen_)
41 screen_->RemoveObserver(this);
42 WmShell::Get()->RemoveShellObserver(this);
43 shelf_->RemoveObserver(this);
44 }
45
46 void AshPopupAlignmentDelegate::StartObserving(
47 display::Screen* screen,
48 const display::Display& display) {
49 screen_ = screen;
50 work_area_ = display.work_area();
51 screen->AddObserver(this);
52 WmShell::Get()->AddShellObserver(this);
53 if (system_tray_height_ > 0)
54 UpdateWorkArea();
55 }
56
57 void AshPopupAlignmentDelegate::SetSystemTrayHeight(int height) {
58 system_tray_height_ = height;
59
60 // If the shelf is shown during auto-hide state, the distance from the edge
61 // should be reduced by the height of shelf's shown height.
62 if (shelf_->GetVisibilityState() == SHELF_AUTO_HIDE &&
63 shelf_->GetAutoHideState() == SHELF_AUTO_HIDE_SHOWN) {
64 system_tray_height_ -= GetShelfConstant(SHELF_SIZE) -
65 GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE);
66 }
67
68 if (system_tray_height_ > 0)
69 system_tray_height_ += message_center::kMarginBetweenItems;
70 else
71 system_tray_height_ = 0;
72
73 DoUpdateIfPossible();
74 }
75
76 int AshPopupAlignmentDelegate::GetToastOriginX(
77 const gfx::Rect& toast_bounds) const {
78 // In Ash, RTL UI language mirrors the whole ash layout, so the toast
79 // widgets should be at the bottom-left instead of bottom right.
80 if (base::i18n::IsRTL())
81 return work_area_.x() + kToastMarginX;
82
83 if (IsFromLeft())
84 return work_area_.x() + kToastMarginX;
85 return work_area_.right() - kToastMarginX - toast_bounds.width();
86 }
87
88 int AshPopupAlignmentDelegate::GetBaseLine() const {
89 return work_area_.bottom() - kNoToastMarginBorderAndShadowOffset -
90 system_tray_height_;
91 }
92
93 int AshPopupAlignmentDelegate::GetWorkAreaBottom() const {
94 return work_area_.bottom() - system_tray_height_;
95 }
96
97 bool AshPopupAlignmentDelegate::IsTopDown() const {
98 return false;
99 }
100
101 bool AshPopupAlignmentDelegate::IsFromLeft() const {
102 return GetAlignment() == SHELF_ALIGNMENT_LEFT;
103 }
104
105 void AshPopupAlignmentDelegate::RecomputeAlignment(
106 const display::Display& display) {
107 // Nothing needs to be done.
108 }
109
110 void AshPopupAlignmentDelegate::ConfigureWidgetInitParamsForContainer(
111 views::Widget* widget,
112 views::Widget::InitParams* init_params) {
113 // On ash, popups go in the status container.
114 shelf_->GetWindow()
115 ->GetRootWindowController()
116 ->ConfigureWidgetInitParamsForContainer(
117 widget, kShellWindowId_StatusContainer, init_params);
118 }
119
120 ShelfAlignment AshPopupAlignmentDelegate::GetAlignment() const {
121 return shelf_->GetAlignment();
122 }
123
124 display::Display AshPopupAlignmentDelegate::GetCurrentDisplay() const {
125 return shelf_->GetWindow()->GetDisplayNearestWindow();
126 }
127
128 void AshPopupAlignmentDelegate::UpdateWorkArea() {
129 work_area_ = shelf_->GetUserWorkAreaBounds();
130 DoUpdateIfPossible();
131 }
132
133 ///////////////////////////////////////////////////////////////////////////////
134 // ShellObserver:
135
136 void AshPopupAlignmentDelegate::OnDisplayWorkAreaInsetsChanged() {
137 UpdateWorkArea();
138 }
139
140 ///////////////////////////////////////////////////////////////////////////////
141 // WmShelfObserver:
142
143 void AshPopupAlignmentDelegate::WillChangeVisibilityState(
144 ShelfVisibilityState new_state) {
145 UpdateWorkArea();
146 }
147
148 void AshPopupAlignmentDelegate::OnAutoHideStateChanged(
149 ShelfAutoHideState new_state) {
150 UpdateWorkArea();
151 }
152
153 ///////////////////////////////////////////////////////////////////////////////
154 // display::DisplayObserver:
155
156 void AshPopupAlignmentDelegate::OnDisplayAdded(
157 const display::Display& new_display) {}
158
159 void AshPopupAlignmentDelegate::OnDisplayRemoved(
160 const display::Display& old_display) {}
161
162 void AshPopupAlignmentDelegate::OnDisplayMetricsChanged(
163 const display::Display& display,
164 uint32_t metrics) {
165 if (GetCurrentDisplay().id() == display.id())
166 UpdateWorkArea();
167 }
168
169 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698