| OLD | NEW |
| 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_bubble_wrapper.h" |
| 12 #include "ash/system/tray/tray_constants.h" | 12 #include "ash/system/tray/tray_constants.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 15 #include "ui/compositor/layer.h" | 15 #include "ui/compositor/layer.h" |
| 16 #include "ui/compositor/layer_animation_observer.h" | 16 #include "ui/compositor/layer_animation_observer.h" |
| 17 #include "ui/compositor/scoped_layer_animation_settings.h" | 17 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 18 #include "ui/gfx/canvas.h" | 18 #include "ui/gfx/canvas.h" |
| 19 #include "ui/views/layout/box_layout.h" | 19 #include "ui/views/layout/fill_layout.h" |
| 20 #include "ui/views/view.h" | 20 #include "ui/views/view.h" |
| 21 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 22 | 22 |
| 23 using views::TrayBubbleView; | 23 using views::TrayBubbleView; |
| 24 | 24 |
| 25 namespace ash { | 25 namespace ash { |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 // Normally a detailed view is the same size as the default view. However, | 29 // Normally a detailed view is the same size as the default view. However, |
| 30 // when showing a detailed view directly (e.g. clicking on a notification), | 30 // when showing a detailed view directly (e.g. clicking on a notification), |
| 31 // we may not know the height of the default view, or the default view may | 31 // we may not know the height of the default view, or the default view may |
| 32 // be too short, so we use this as a default and minimum height for any | 32 // be too short, so we use this as a default and minimum height for any |
| 33 // detailed view. | 33 // detailed view. |
| 34 const int kDetailedBubbleMaxHeight = kTrayPopupItemHeight * 5; | 34 const int kDetailedBubbleMaxHeight = kTrayPopupItemHeight * 5; |
| 35 | 35 |
| 36 // A view with some special behaviour for tray items in the popup: | 36 // A view with some special behaviour for tray items in the popup: |
| 37 // - optionally changes background color on hover. | 37 // - optionally changes background color on hover. |
| 38 class TrayPopupItemContainer : public views::View { | 38 class TrayPopupItemContainer : public views::View { |
| 39 public: | 39 public: |
| 40 TrayPopupItemContainer(views::View* view, | 40 TrayPopupItemContainer(views::View* view, |
| 41 ShelfAlignment alignment, | 41 ShelfAlignment alignment, |
| 42 bool change_background) | 42 bool change_background) |
| 43 : hover_(false), | 43 : hover_(false), |
| 44 change_background_(change_background) { | 44 change_background_(change_background) { |
| 45 set_notify_enter_exit_on_child(true); | 45 set_notify_enter_exit_on_child(true); |
| 46 views::BoxLayout* layout = new views::BoxLayout( | 46 SetLayoutManager(new views::FillLayout); |
| 47 views::BoxLayout::kVertical, 0, 0, 0); | |
| 48 layout->set_spread_blank_space(true); | |
| 49 SetLayoutManager(layout); | |
| 50 SetPaintToLayer(view->layer() != NULL); | 47 SetPaintToLayer(view->layer() != NULL); |
| 51 if (view->layer()) | 48 if (view->layer()) |
| 52 SetFillsBoundsOpaquely(view->layer()->fills_bounds_opaquely()); | 49 SetFillsBoundsOpaquely(view->layer()->fills_bounds_opaquely()); |
| 53 AddChildView(view); | 50 AddChildView(view); |
| 54 SetVisible(view->visible()); | 51 SetVisible(view->visible()); |
| 55 } | 52 } |
| 56 | 53 |
| 57 virtual ~TrayPopupItemContainer() {} | 54 virtual ~TrayPopupItemContainer() {} |
| 58 | 55 |
| 59 private: | 56 private: |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 for (std::vector<ash::SystemTrayItem*>::const_iterator it = items_.begin(); | 307 for (std::vector<ash::SystemTrayItem*>::const_iterator it = items_.begin(); |
| 311 it != items_.end(); | 308 it != items_.end(); |
| 312 ++it) { | 309 ++it) { |
| 313 if ((*it)->ShouldShowLauncher()) | 310 if ((*it)->ShouldShowLauncher()) |
| 314 return true; | 311 return true; |
| 315 } | 312 } |
| 316 return false; | 313 return false; |
| 317 } | 314 } |
| 318 | 315 |
| 319 void SystemTrayBubble::CreateItemViews(user::LoginStatus login_status) { | 316 void SystemTrayBubble::CreateItemViews(user::LoginStatus login_status) { |
| 317 const int bubble_width = bubble_view_->GetPreferredSize().width(); |
| 320 for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin(); | 318 for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin(); |
| 321 it != items_.end(); | 319 it != items_.end(); |
| 322 ++it) { | 320 ++it) { |
| 323 views::View* view = NULL; | 321 views::View* view = NULL; |
| 324 switch (bubble_type_) { | 322 switch (bubble_type_) { |
| 325 case BUBBLE_TYPE_DEFAULT: | 323 case BUBBLE_TYPE_DEFAULT: |
| 326 view = (*it)->CreateDefaultView(login_status); | 324 view = (*it)->CreateDefaultView(login_status, bubble_width); |
| 327 break; | 325 break; |
| 328 case BUBBLE_TYPE_DETAILED: | 326 case BUBBLE_TYPE_DETAILED: |
| 329 view = (*it)->CreateDetailedView(login_status); | 327 view = (*it)->CreateDetailedView(login_status); |
| 330 break; | 328 break; |
| 331 case BUBBLE_TYPE_NOTIFICATION: | 329 case BUBBLE_TYPE_NOTIFICATION: |
| 332 view = (*it)->CreateNotificationView(login_status); | 330 view = (*it)->CreateNotificationView(login_status); |
| 333 break; | 331 break; |
| 334 } | 332 } |
| 335 if (view) { | 333 if (view) { |
| 336 bubble_view_->AddChildView(new TrayPopupItemContainer( | 334 bubble_view_->AddChildView(new TrayPopupItemContainer( |
| 337 view, tray_->shelf_alignment(), bubble_type_ == BUBBLE_TYPE_DEFAULT)); | 335 view, tray_->shelf_alignment(), bubble_type_ == BUBBLE_TYPE_DEFAULT)); |
| 336 if (bubble_type_ == BUBBLE_TYPE_DEFAULT && |
| 337 (*it)->GuaranteeDefaultViewPreferredSize(login_status)) { |
| 338 bubble_view_->SetMinWidth(view->GetPreferredSize().width()); |
| 339 } |
| 338 } | 340 } |
| 339 } | 341 } |
| 340 } | 342 } |
| 341 | 343 |
| 342 } // namespace internal | 344 } // namespace internal |
| 343 } // namespace ash | 345 } // namespace ash |
| OLD | NEW |