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

Side by Side Diff: ui/message_center/views/toast_contents_view.cc

Issue 1913433004: Supporting shrinking/enlarging for notifications (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/toast_contents_view.h" 5 #include "ui/message_center/views/toast_contents_view.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 ToastContentsView::~ToastContentsView() { 71 ToastContentsView::~ToastContentsView() {
72 if (collection_) 72 if (collection_)
73 collection_->ForgetToast(this); 73 collection_->ForgetToast(this);
74 } 74 }
75 75
76 void ToastContentsView::SetContents(MessageView* view, 76 void ToastContentsView::SetContents(MessageView* view,
77 bool a11y_feedback_for_updates) { 77 bool a11y_feedback_for_updates) {
78 bool already_has_contents = child_count() > 0; 78 bool already_has_contents = child_count() > 0;
79 RemoveAllChildViews(true); 79 RemoveAllChildViews(true);
80 AddChildView(view); 80 AddChildView(view);
81 preferred_size_ = GetToastSizeForView(view); 81 UpdatePreferredSize();
82 Layout();
83 82
84 // If it has the contents already, this invocation means an update of the 83 // If it has the contents already, this invocation means an update of the
85 // popup toast, and the new contents should be read through a11y feature. 84 // popup toast, and the new contents should be read through a11y feature.
86 // The notification type should be ALERT, otherwise the accessibility message 85 // The notification type should be ALERT, otherwise the accessibility message
87 // won't be read for this view which returns ROLE_WINDOW. 86 // won't be read for this view which returns ROLE_WINDOW.
88 if (already_has_contents && a11y_feedback_for_updates) 87 if (already_has_contents && a11y_feedback_for_updates)
89 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, false); 88 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, false);
90 } 89 }
91 90
92 void ToastContentsView::UpdateContents(const Notification& notification, 91 void ToastContentsView::UpdateContents(const Notification& notification,
93 bool a11y_feedback_for_updates) { 92 bool a11y_feedback_for_updates) {
94 DCHECK_GT(child_count(), 0); 93 DCHECK_GT(child_count(), 0);
95 MessageView* message_view = static_cast<MessageView*>(child_at(0)); 94 MessageView* message_view = static_cast<MessageView*>(child_at(0));
96 message_view->UpdateWithNotification(notification); 95 message_view->UpdateWithNotification(notification);
97 gfx::Size new_size = GetToastSizeForView(message_view); 96 gfx::Size new_size = GetToastSizeForView(message_view);
Jun Mukai 2016/05/04 17:00:09 You can remove this line
stevenjb 2016/05/04 23:39:02 More than just "can" - this will fail to compile w
dyaroshev 2016/05/05 14:13:19 Done.
98 if (preferred_size_ != new_size) { 97 UpdatePreferredSize();
99 preferred_size_ = new_size;
100 Layout();
101 }
102 if (a11y_feedback_for_updates) 98 if (a11y_feedback_for_updates)
103 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, false); 99 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, false);
104 } 100 }
105 101
106 void ToastContentsView::RevealWithAnimation(gfx::Point origin) { 102 void ToastContentsView::RevealWithAnimation(gfx::Point origin) {
107 // Place/move the toast widgets. Currently it stacks the widgets from the 103 // Place/move the toast widgets. Currently it stacks the widgets from the
108 // right-bottom of the work area. 104 // right-bottom of the work area.
109 // TODO(mukai): allow to specify the placement policy from outside of this 105 // TODO(mukai): allow to specify the placement policy from outside of this
110 // class. The policy should be specified from preference on Windows, or 106 // class. The policy should be specified from preference on Windows, or
111 // the launcher alignment on ChromeOS. 107 // the launcher alignment on ChromeOS.
112 origin_ = gfx::Point(origin.x() - preferred_size_.width(), 108 origin_ = gfx::Point(origin.x() - preferred_size_.width(),
113 origin.y() - preferred_size_.height()); 109 origin.y() - preferred_size_.height());
114 110
115 gfx::Rect stable_bounds(origin_, preferred_size_); 111 gfx::Rect stable_bounds(origin_, preferred_size_);
116 112
117 SetBoundsInstantly(GetClosedToastBounds(stable_bounds)); 113 SetBoundsInstantly(GetClosedToastBounds(stable_bounds));
118 StartFadeIn(); 114 StartFadeIn();
119 SetBoundsWithAnimation(stable_bounds); 115 SetBoundsWithAnimation(stable_bounds);
120 } 116 }
121 117
122 void ToastContentsView::CloseWithAnimation() { 118 void ToastContentsView::CloseWithAnimation() {
123 if (is_closing_) 119 if (is_closing_)
124 return; 120 return;
125 is_closing_ = true; 121 is_closing_ = true;
126 StartFadeOut(); 122 StartFadeOut();
127 } 123 }
128 124
129 void ToastContentsView::SetBoundsInstantly(gfx::Rect new_bounds) { 125 void ToastContentsView::SetBoundsInstantly(gfx::Rect new_bounds) {
130 if (new_bounds == bounds()) 126 DCHECK(new_bounds.size().width() <= preferred_size_.width() &&
127 new_bounds.size().height() <= preferred_size_.height())
128 << "we can not display widget bigger than notification";
129
130 if (!GetWidget())
131 return;
132
133 if (new_bounds == GetWidget()->GetWindowBoundsInScreen())
131 return; 134 return;
132 135
133 origin_ = new_bounds.origin(); 136 origin_ = new_bounds.origin();
134 if (!GetWidget())
135 return;
136 GetWidget()->SetBounds(new_bounds); 137 GetWidget()->SetBounds(new_bounds);
137 } 138 }
138 139
139 void ToastContentsView::SetBoundsWithAnimation(gfx::Rect new_bounds) { 140 void ToastContentsView::SetBoundsWithAnimation(gfx::Rect new_bounds) {
140 if (new_bounds == bounds()) 141 DCHECK(new_bounds.size().width() <= preferred_size_.width() &&
142 new_bounds.size().height() <= preferred_size_.height())
143 << "we can not display widget bigger than notification";
144
145 if (!GetWidget())
146 return;
147
148 if (new_bounds == GetWidget()->GetWindowBoundsInScreen())
Jun Mukai 2016/05/04 17:00:09 This (and line 133) could be incorrect if this hap
dyaroshev 2016/05/05 14:13:19 1) It seems like I can check animated_bounds_end_
Jun Mukai 2016/05/05 18:01:51 Sorry, I was misunderstanding the (current) code a
141 return; 149 return;
142 150
143 origin_ = new_bounds.origin(); 151 origin_ = new_bounds.origin();
144 if (!GetWidget())
145 return;
146
147 // This picks up the current bounds, so if there was a previous animation 152 // This picks up the current bounds, so if there was a previous animation
148 // half-done, the next one will pick up from the current location. 153 // half-done, the next one will pick up from the current location.
149 // This is the only place that should query current location of the Widget 154 // This is the only place that should query current location of the Widget
150 // on screen, the rest should refer to the bounds_. 155 // on screen, the rest should refer to the bounds_.
151 animated_bounds_start_ = GetWidget()->GetWindowBoundsInScreen(); 156 animated_bounds_start_ = GetWidget()->GetWindowBoundsInScreen();
152 animated_bounds_end_ = new_bounds; 157 animated_bounds_end_ = new_bounds;
153 158
154 if (collection_) 159 if (collection_)
155 collection_->IncrementDeferCounter(); 160 collection_->IncrementDeferCounter();
156 161
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 if (child_count() > 0) { 287 if (child_count() > 0) {
283 child_at(0)->SetBounds( 288 child_at(0)->SetBounds(
284 0, 0, preferred_size_.width(), preferred_size_.height()); 289 0, 0, preferred_size_.width(), preferred_size_.height());
285 } 290 }
286 } 291 }
287 292
288 gfx::Size ToastContentsView::GetPreferredSize() const { 293 gfx::Size ToastContentsView::GetPreferredSize() const {
289 return child_count() ? GetToastSizeForView(child_at(0)) : gfx::Size(); 294 return child_count() ? GetToastSizeForView(child_at(0)) : gfx::Size();
290 } 295 }
291 296
297 void ToastContentsView::UpdatePreferredSize() {
298 DCHECK_GT(child_count(), 0);
299 gfx::Size new_size = GetToastSizeForView(child_at(0));
300 if (preferred_size_ == new_size)
301 return;
302 preferred_size_ = new_size;
303 Layout();
304 SetBoundsInstantly(bounds());
305 }
306
292 void ToastContentsView::GetAccessibleState(ui::AXViewState* state) { 307 void ToastContentsView::GetAccessibleState(ui::AXViewState* state) {
293 if (child_count() > 0) 308 if (child_count() > 0)
294 child_at(0)->GetAccessibleState(state); 309 child_at(0)->GetAccessibleState(state);
295 state->role = ui::AX_ROLE_WINDOW; 310 state->role = ui::AX_ROLE_WINDOW;
296 } 311 }
297 312
298 void ToastContentsView::ClickOnNotification( 313 void ToastContentsView::ClickOnNotification(
299 const std::string& notification_id) { 314 const std::string& notification_id) {
300 if (collection_) 315 if (collection_)
301 collection_->ClickOnNotification(notification_id); 316 collection_->ClickOnNotification(notification_id);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 } 374 }
360 375
361 gfx::Rect ToastContentsView::GetClosedToastBounds(gfx::Rect bounds) { 376 gfx::Rect ToastContentsView::GetClosedToastBounds(gfx::Rect bounds) {
362 return gfx::Rect(bounds.x() + bounds.width() - kClosedToastWidth, 377 return gfx::Rect(bounds.x() + bounds.width() - kClosedToastWidth,
363 bounds.y(), 378 bounds.y(),
364 kClosedToastWidth, 379 kClosedToastWidth,
365 bounds.height()); 380 bounds.height());
366 } 381 }
367 382
368 } // namespace message_center 383 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698