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

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

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

Powered by Google App Engine
This is Rietveld 408576698