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

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: review, test for many notifications Created 4 years, 7 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 UpdatePreferredSize();
98 if (preferred_size_ != new_size) {
99 preferred_size_ = new_size;
100 Layout();
101 }
102 if (a11y_feedback_for_updates) 97 if (a11y_feedback_for_updates)
103 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, false); 98 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, false);
104 } 99 }
105 100
106 void ToastContentsView::RevealWithAnimation(gfx::Point origin) { 101 void ToastContentsView::RevealWithAnimation(gfx::Point origin) {
107 // Place/move the toast widgets. Currently it stacks the widgets from the 102 // Place/move the toast widgets. Currently it stacks the widgets from the
108 // right-bottom of the work area. 103 // right-bottom of the work area.
109 // TODO(mukai): allow to specify the placement policy from outside of this 104 // TODO(mukai): allow to specify the placement policy from outside of this
110 // class. The policy should be specified from preference on Windows, or 105 // class. The policy should be specified from preference on Windows, or
111 // the launcher alignment on ChromeOS. 106 // the launcher alignment on ChromeOS.
112 origin_ = gfx::Point(origin.x() - preferred_size_.width(), 107 origin_ = gfx::Point(origin.x() - preferred_size_.width(),
113 origin.y() - preferred_size_.height()); 108 origin.y() - preferred_size_.height());
114 109
115 gfx::Rect stable_bounds(origin_, preferred_size_); 110 gfx::Rect stable_bounds(origin_, preferred_size_);
116 111
117 SetBoundsInstantly(GetClosedToastBounds(stable_bounds)); 112 SetBoundsInstantly(GetClosedToastBounds(stable_bounds));
118 StartFadeIn(); 113 StartFadeIn();
119 SetBoundsWithAnimation(stable_bounds); 114 SetBoundsWithAnimation(stable_bounds);
120 } 115 }
121 116
122 void ToastContentsView::CloseWithAnimation() { 117 void ToastContentsView::CloseWithAnimation() {
123 if (is_closing_) 118 if (is_closing_)
124 return; 119 return;
125 is_closing_ = true; 120 is_closing_ = true;
126 StartFadeOut(); 121 StartFadeOut();
127 } 122 }
128 123
129 void ToastContentsView::SetBoundsInstantly(gfx::Rect new_bounds) { 124 void ToastContentsView::SetBoundsInstantly(gfx::Rect new_bounds) {
130 if (new_bounds == bounds()) 125 DCHECK(new_bounds.size().width() <= preferred_size_.width() &&
126 new_bounds.size().height() <= preferred_size_.height())
127 << "we can not display widget bigger than notification";
128
129 if (!GetWidget())
130 return;
131
132 if (new_bounds == GetWidget()->GetWindowBoundsInScreen())
131 return; 133 return;
132 134
133 origin_ = new_bounds.origin(); 135 origin_ = new_bounds.origin();
134 if (!GetWidget())
135 return;
136 GetWidget()->SetBounds(new_bounds); 136 GetWidget()->SetBounds(new_bounds);
137 } 137 }
138 138
139 void ToastContentsView::SetBoundsWithAnimation(gfx::Rect new_bounds) { 139 void ToastContentsView::SetBoundsWithAnimation(gfx::Rect new_bounds) {
140 if (new_bounds == bounds()) 140 DCHECK(new_bounds.size().width() <= preferred_size_.width() &&
141 new_bounds.size().height() <= preferred_size_.height())
142 << "we can not display widget bigger than notification";
143
144 if (!GetWidget())
145 return;
146
147 if (new_bounds == GetWidget()->GetWindowBoundsInScreen())
141 return; 148 return;
142 149
143 origin_ = new_bounds.origin(); 150 origin_ = new_bounds.origin();
144 if (!GetWidget())
145 return;
146
147 // This picks up the current bounds, so if there was a previous animation 151 // 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. 152 // 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 153 // This is the only place that should query current location of the Widget
150 // on screen, the rest should refer to the bounds_. 154 // on screen, the rest should refer to the bounds_.
151 animated_bounds_start_ = GetWidget()->GetWindowBoundsInScreen(); 155 animated_bounds_start_ = GetWidget()->GetWindowBoundsInScreen();
152 animated_bounds_end_ = new_bounds; 156 animated_bounds_end_ = new_bounds;
153 157
154 if (collection_) 158 if (collection_)
155 collection_->IncrementDeferCounter(); 159 collection_->IncrementDeferCounter();
156 160
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 if (child_count() > 0) { 286 if (child_count() > 0) {
283 child_at(0)->SetBounds( 287 child_at(0)->SetBounds(
284 0, 0, preferred_size_.width(), preferred_size_.height()); 288 0, 0, preferred_size_.width(), preferred_size_.height());
285 } 289 }
286 } 290 }
287 291
288 gfx::Size ToastContentsView::GetPreferredSize() const { 292 gfx::Size ToastContentsView::GetPreferredSize() const {
289 return child_count() ? GetToastSizeForView(child_at(0)) : gfx::Size(); 293 return child_count() ? GetToastSizeForView(child_at(0)) : gfx::Size();
290 } 294 }
291 295
296 void ToastContentsView::UpdatePreferredSize() {
297 DCHECK_GT(child_count(), 0);
298 gfx::Size new_size = GetToastSizeForView(child_at(0));
299 if (preferred_size_ == new_size)
300 return;
301 preferred_size_ = new_size;
302 Layout();
303 SetBoundsInstantly(bounds());
Jun Mukai 2016/05/05 18:01:51 Based on the discussion for SetBoundsWithAnimation
304 }
305
292 void ToastContentsView::GetAccessibleState(ui::AXViewState* state) { 306 void ToastContentsView::GetAccessibleState(ui::AXViewState* state) {
293 if (child_count() > 0) 307 if (child_count() > 0)
294 child_at(0)->GetAccessibleState(state); 308 child_at(0)->GetAccessibleState(state);
295 state->role = ui::AX_ROLE_WINDOW; 309 state->role = ui::AX_ROLE_WINDOW;
296 } 310 }
297 311
298 void ToastContentsView::ClickOnNotification( 312 void ToastContentsView::ClickOnNotification(
299 const std::string& notification_id) { 313 const std::string& notification_id) {
300 if (collection_) 314 if (collection_)
301 collection_->ClickOnNotification(notification_id); 315 collection_->ClickOnNotification(notification_id);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 } 373 }
360 374
361 gfx::Rect ToastContentsView::GetClosedToastBounds(gfx::Rect bounds) { 375 gfx::Rect ToastContentsView::GetClosedToastBounds(gfx::Rect bounds) {
362 return gfx::Rect(bounds.x() + bounds.width() - kClosedToastWidth, 376 return gfx::Rect(bounds.x() + bounds.width() - kClosedToastWidth,
363 bounds.y(), 377 bounds.y(),
364 kClosedToastWidth, 378 kClosedToastWidth,
365 bounds.height()); 379 bounds.height());
366 } 380 }
367 381
368 } // namespace message_center 382 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698