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

Side by Side Diff: ash/system/tray/system_tray_bubble.cc

Issue 11028134: Re-factor Ash Message Center code part 2/4 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « ash/system/tray/system_tray_bubble.h ('k') | ash/system/tray/tray_background_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ash/system/tray/system_tray_bubble.h" 5 #include "ash/system/tray/system_tray_bubble.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/system/tray/system_tray.h" 8 #include "ash/system/tray/system_tray.h"
9 #include "ash/system/tray/system_tray_delegate.h" 9 #include "ash/system/tray/system_tray_delegate.h"
10 #include "ash/system/tray/system_tray_item.h" 10 #include "ash/system/tray/system_tray_item.h"
11 #include "ash/system/tray/tray_bubble_wrapper.h"
11 #include "ash/system/tray/tray_constants.h" 12 #include "ash/system/tray/tray_constants.h"
12 #include "base/message_loop.h" 13 #include "base/message_loop.h"
13 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
14 #include "ui/compositor/layer.h" 15 #include "ui/compositor/layer.h"
15 #include "ui/compositor/layer_animation_observer.h" 16 #include "ui/compositor/layer_animation_observer.h"
16 #include "ui/compositor/scoped_layer_animation_settings.h" 17 #include "ui/compositor/scoped_layer_animation_settings.h"
17 #include "ui/gfx/canvas.h" 18 #include "ui/gfx/canvas.h"
18 #include "ui/views/layout/box_layout.h" 19 #include "ui/views/layout/box_layout.h"
19 #include "ui/views/view.h" 20 #include "ui/views/view.h"
20 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 namespace internal { 120 namespace internal {
120 121
121 // SystemTrayBubble 122 // SystemTrayBubble
122 123
123 SystemTrayBubble::SystemTrayBubble( 124 SystemTrayBubble::SystemTrayBubble(
124 ash::SystemTray* tray, 125 ash::SystemTray* tray,
125 const std::vector<ash::SystemTrayItem*>& items, 126 const std::vector<ash::SystemTrayItem*>& items,
126 BubbleType bubble_type) 127 BubbleType bubble_type)
127 : tray_(tray), 128 : tray_(tray),
128 bubble_view_(NULL), 129 bubble_view_(NULL),
129 bubble_widget_(NULL),
130 items_(items), 130 items_(items),
131 bubble_type_(bubble_type), 131 bubble_type_(bubble_type),
132 autoclose_delay_(0) { 132 autoclose_delay_(0) {
133 } 133 }
134 134
135 SystemTrayBubble::~SystemTrayBubble() { 135 SystemTrayBubble::~SystemTrayBubble() {
136 DestroyItemViews(); 136 DestroyItemViews();
137 // Reset the host pointer in bubble_view_ in case its destruction is deferred. 137 // Reset the host pointer in bubble_view_ in case its destruction is deferred.
138 if (bubble_view_) 138 if (bubble_view_)
139 bubble_view_->reset_host(); 139 bubble_view_->reset_delegate();
140 if (bubble_widget_) {
141 bubble_widget_->RemoveObserver(this);
142 // This triggers the destruction of bubble_view_.
143 bubble_widget_->Close();
144 }
145 } 140 }
146 141
147 void SystemTrayBubble::UpdateView( 142 void SystemTrayBubble::UpdateView(
148 const std::vector<ash::SystemTrayItem*>& items, 143 const std::vector<ash::SystemTrayItem*>& items,
149 BubbleType bubble_type) { 144 BubbleType bubble_type) {
150 DCHECK(bubble_type != BUBBLE_TYPE_NOTIFICATION); 145 DCHECK(bubble_type != BUBBLE_TYPE_NOTIFICATION);
151 DCHECK(bubble_type != bubble_type_); 146 DCHECK(bubble_type != bubble_type_);
152 147
153 const int kSwipeDelayMS = 150; 148 const int kSwipeDelayMS = 150;
154 base::TimeDelta swipe_duration = 149 base::TimeDelta swipe_duration =
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 items_ = items; 197 items_ = items;
203 bubble_type_ = bubble_type; 198 bubble_type_ = bubble_type;
204 CreateItemViews(Shell::GetInstance()->tray_delegate()->GetUserLoginStatus()); 199 CreateItemViews(Shell::GetInstance()->tray_delegate()->GetUserLoginStatus());
205 200
206 // Close bubble view if we failed to create the item view. 201 // Close bubble view if we failed to create the item view.
207 if (!bubble_view_->has_children()) { 202 if (!bubble_view_->has_children()) {
208 Close(); 203 Close();
209 return; 204 return;
210 } 205 }
211 206
212 bubble_widget_->GetContentsView()->Layout(); 207 bubble_view_->GetWidget()->GetContentsView()->Layout();
213 // Make sure that the bubble is large enough for the default view. 208 // Make sure that the bubble is large enough for the default view.
214 if (bubble_type_ == BUBBLE_TYPE_DEFAULT) { 209 if (bubble_type_ == BUBBLE_TYPE_DEFAULT) {
215 bubble_view_->SetMaxHeight(0); // Clear max height limit. 210 bubble_view_->SetMaxHeight(0); // Clear max height limit.
216 } 211 }
217 212
218 // When transitioning from default view to detailed view, animate the new 213 // When transitioning from default view to detailed view, animate the new
219 // view (slide in from the right). 214 // view (slide in from the right).
220 if (bubble_type == BUBBLE_TYPE_DETAILED) { 215 if (bubble_type == BUBBLE_TYPE_DETAILED) {
221 ui::Layer* new_layer = bubble_view_->layer(); 216 ui::Layer* new_layer = bubble_view_->layer();
222 gfx::Rect bounds = new_layer->bounds(); 217 gfx::Rect bounds = new_layer->bounds();
223 ui::Transform transform; 218 ui::Transform transform;
224 transform.SetTranslateX(bounds.width()); 219 transform.SetTranslateX(bounds.width());
225 new_layer->SetTransform(transform); 220 new_layer->SetTransform(transform);
226 { 221 {
227 ui::ScopedLayerAnimationSettings settings(new_layer->GetAnimator()); 222 ui::ScopedLayerAnimationSettings settings(new_layer->GetAnimator());
228 settings.AddObserver(new AnimationObserverDeleteLayer(layer)); 223 settings.AddObserver(new AnimationObserverDeleteLayer(layer));
229 settings.SetTransitionDuration(swipe_duration); 224 settings.SetTransitionDuration(swipe_duration);
230 settings.SetTweenType(ui::Tween::EASE_OUT); 225 settings.SetTweenType(ui::Tween::EASE_OUT);
231 new_layer->SetTransform(ui::Transform()); 226 new_layer->SetTransform(ui::Transform());
232 } 227 }
233 } 228 }
234 } 229 }
235 230
236 void SystemTrayBubble::InitView(views::View* anchor, 231 void SystemTrayBubble::InitView(views::View* anchor,
237 TrayBubbleView::InitParams init_params, 232 user::LoginStatus login_status,
238 user::LoginStatus login_status) { 233 TrayBubbleView::InitParams* init_params) {
239 DCHECK(bubble_view_ == NULL); 234 DCHECK(bubble_view_ == NULL);
240 235
241 if (bubble_type_ == BUBBLE_TYPE_DETAILED && 236 if (bubble_type_ == BUBBLE_TYPE_DETAILED &&
242 init_params.max_height < kDetailedBubbleMaxHeight) { 237 init_params->max_height < kDetailedBubbleMaxHeight) {
243 init_params.max_height = kDetailedBubbleMaxHeight; 238 init_params->max_height = kDetailedBubbleMaxHeight;
244 } else if (bubble_type_ == BUBBLE_TYPE_NOTIFICATION) { 239 } else if (bubble_type_ == BUBBLE_TYPE_NOTIFICATION) {
245 init_params.close_on_deactivate = false; 240 init_params->close_on_deactivate = false;
246 } 241 }
247 bubble_view_ = TrayBubbleView::Create(anchor, this, init_params); 242 bubble_view_ = TrayBubbleView::Create(
243 tray_->GetBubbleWindowContainer(), anchor, this, init_params);
248 244
249 CreateItemViews(login_status); 245 CreateItemViews(login_status);
250 246
251 DCHECK(bubble_widget_ == NULL); 247 bubble_wrapper_.reset(new internal::TrayBubbleWrapper(tray_, bubble_view_));
252 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_);
253 bubble_widget_->AddObserver(this);
254
255 InitializeAndShowBubble(bubble_widget_, bubble_view_, tray_);
256 } 248 }
257 249
258 void SystemTrayBubble::BubbleViewDestroyed() { 250 void SystemTrayBubble::BubbleViewDestroyed() {
259 DestroyItemViews(); 251 DestroyItemViews();
260 bubble_view_ = NULL; 252 bubble_view_ = NULL;
261 } 253 }
262 254
263 void SystemTrayBubble::OnMouseEnteredView() { 255 void SystemTrayBubble::OnMouseEnteredView() {
264 StopAutoCloseTimer(); 256 StopAutoCloseTimer();
265 } 257 }
266 258
267 void SystemTrayBubble::OnMouseExitedView() { 259 void SystemTrayBubble::OnMouseExitedView() {
268 RestartAutoCloseTimer(); 260 RestartAutoCloseTimer();
269 } 261 }
270 262
271 void SystemTrayBubble::OnClickedOutsideView() {
272 if (bubble_type_ != BUBBLE_TYPE_NOTIFICATION)
273 bubble_widget_->Close();
274 }
275
276 string16 SystemTrayBubble::GetAccessibleName() { 263 string16 SystemTrayBubble::GetAccessibleName() {
277 return tray_->GetAccessibleName(); 264 return tray_->GetAccessibleName();
278 } 265 }
279 266
267 gfx::Rect SystemTrayBubble::GetAnchorRect(
268 views::Widget* anchor_widget,
269 TrayBubbleView::AnchorType anchor_type,
270 TrayBubbleView::AnchorAlignment anchor_alignment) {
271 return tray_->GetAnchorRect(anchor_widget, anchor_type, anchor_alignment);
272 }
273
280 void SystemTrayBubble::DestroyItemViews() { 274 void SystemTrayBubble::DestroyItemViews() {
281 for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin(); 275 for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin();
282 it != items_.end(); 276 it != items_.end();
283 ++it) { 277 ++it) {
284 switch (bubble_type_) { 278 switch (bubble_type_) {
285 case BUBBLE_TYPE_DEFAULT: 279 case BUBBLE_TYPE_DEFAULT:
286 (*it)->DestroyDefaultView(); 280 (*it)->DestroyDefaultView();
287 break; 281 break;
288 case BUBBLE_TYPE_DETAILED: 282 case BUBBLE_TYPE_DETAILED:
289 (*it)->DestroyDetailedView(); 283 (*it)->DestroyDetailedView();
(...skipping 18 matching lines...) Expand all
308 void SystemTrayBubble::StopAutoCloseTimer() { 302 void SystemTrayBubble::StopAutoCloseTimer() {
309 autoclose_.Stop(); 303 autoclose_.Stop();
310 } 304 }
311 305
312 void SystemTrayBubble::RestartAutoCloseTimer() { 306 void SystemTrayBubble::RestartAutoCloseTimer() {
313 if (autoclose_delay_) 307 if (autoclose_delay_)
314 StartAutoCloseTimer(autoclose_delay_); 308 StartAutoCloseTimer(autoclose_delay_);
315 } 309 }
316 310
317 void SystemTrayBubble::Close() { 311 void SystemTrayBubble::Close() {
318 if (bubble_widget_) 312 tray_->HideBubbleWithView(bubble_view());
319 bubble_widget_->Close();
320 } 313 }
321 314
322 void SystemTrayBubble::SetVisible(bool is_visible) { 315 void SystemTrayBubble::SetVisible(bool is_visible) {
323 if (!bubble_widget_) 316 if (!bubble_view_)
324 return; 317 return;
318 views::Widget* bubble_widget = bubble_view_->GetWidget();
325 if (is_visible) 319 if (is_visible)
326 bubble_widget_->Show(); 320 bubble_widget->Show();
327 else 321 else
328 bubble_widget_->Hide(); 322 bubble_widget->Hide();
329 } 323 }
330 324
331 bool SystemTrayBubble::IsVisible() { 325 bool SystemTrayBubble::IsVisible() {
332 return bubble_widget_ && bubble_widget_->IsVisible(); 326 return bubble_view() && bubble_view()->GetWidget()->IsVisible();
333 } 327 }
334 328
335 void SystemTrayBubble::CreateItemViews(user::LoginStatus login_status) { 329 void SystemTrayBubble::CreateItemViews(user::LoginStatus login_status) {
336 for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin(); 330 for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin();
337 it != items_.end(); 331 it != items_.end();
338 ++it) { 332 ++it) {
339 views::View* view = NULL; 333 views::View* view = NULL;
340 switch (bubble_type_) { 334 switch (bubble_type_) {
341 case BUBBLE_TYPE_DEFAULT: 335 case BUBBLE_TYPE_DEFAULT:
342 view = (*it)->CreateDefaultView(login_status); 336 view = (*it)->CreateDefaultView(login_status);
343 break; 337 break;
344 case BUBBLE_TYPE_DETAILED: 338 case BUBBLE_TYPE_DETAILED:
345 view = (*it)->CreateDetailedView(login_status); 339 view = (*it)->CreateDetailedView(login_status);
346 break; 340 break;
347 case BUBBLE_TYPE_NOTIFICATION: 341 case BUBBLE_TYPE_NOTIFICATION:
348 view = (*it)->CreateNotificationView(login_status); 342 view = (*it)->CreateNotificationView(login_status);
349 break; 343 break;
350 } 344 }
351 if (view) { 345 if (view) {
352 bubble_view_->AddChildView(new TrayPopupItemContainer( 346 bubble_view_->AddChildView(new TrayPopupItemContainer(
353 view, tray_->shelf_alignment(), bubble_type_ == BUBBLE_TYPE_DEFAULT)); 347 view, tray_->shelf_alignment(), bubble_type_ == BUBBLE_TYPE_DEFAULT));
354 } 348 }
355 } 349 }
356 } 350 }
357 351
358 void SystemTrayBubble::OnWidgetClosing(views::Widget* widget) {
359 CHECK_EQ(bubble_widget_, widget);
360 bubble_widget_ = NULL;
361 tray_->RemoveBubble(this);
362 }
363
364 } // namespace internal 352 } // namespace internal
365 } // namespace ash 353 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray/system_tray_bubble.h ('k') | ash/system/tray/tray_background_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698