| 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" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 int index = parent->GetIndexOf(owner_); | 65 int index = parent->GetIndexOf(owner_); |
| 66 insets->Set(index == 0, 1, index != parent->child_count() - 1, 1); | 66 insets->Set(index == 0, 1, index != parent->child_count() - 1, 1); |
| 67 } | 67 } |
| 68 | 68 |
| 69 views::View* owner_; | 69 views::View* owner_; |
| 70 | 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(TrayPopupItemBorder); | 71 DISALLOW_COPY_AND_ASSIGN(TrayPopupItemBorder); |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 // A view with some special behaviour for tray items in the popup: | 74 // A view with some special behaviour for tray items in the popup: |
| 75 // - changes background color on hover. | 75 // - optionally changes background color on hover. |
| 76 class TrayPopupItemContainer : public views::View { | 76 class TrayPopupItemContainer : public views::View { |
| 77 public: | 77 public: |
| 78 explicit TrayPopupItemContainer(views::View* view) : hover_(false) { | 78 TrayPopupItemContainer(views::View* view, bool change_background) |
| 79 : hover_(false), |
| 80 change_background_(change_background) { |
| 79 set_notify_enter_exit_on_child(true); | 81 set_notify_enter_exit_on_child(true); |
| 80 set_border(new TrayPopupItemBorder(this)); | 82 set_border(new TrayPopupItemBorder(this)); |
| 81 views::BoxLayout* layout = new views::BoxLayout( | 83 views::BoxLayout* layout = new views::BoxLayout( |
| 82 views::BoxLayout::kVertical, 0, 0, 0); | 84 views::BoxLayout::kVertical, 0, 0, 0); |
| 83 layout->set_spread_blank_space(true); | 85 layout->set_spread_blank_space(true); |
| 84 SetLayoutManager(layout); | 86 SetLayoutManager(layout); |
| 85 SetPaintToLayer(view->layer() != NULL); | 87 SetPaintToLayer(view->layer() != NULL); |
| 86 if (view->layer()) | 88 if (view->layer()) |
| 87 SetFillsBoundsOpaquely(view->layer()->fills_bounds_opaquely()); | 89 SetFillsBoundsOpaquely(view->layer()->fills_bounds_opaquely()); |
| 88 AddChildView(view); | 90 AddChildView(view); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 113 hover_ = false; | 115 hover_ = false; |
| 114 SchedulePaint(); | 116 SchedulePaint(); |
| 115 } | 117 } |
| 116 | 118 |
| 117 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE { | 119 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE { |
| 118 if (child_count() == 0) | 120 if (child_count() == 0) |
| 119 return; | 121 return; |
| 120 | 122 |
| 121 views::View* view = child_at(0); | 123 views::View* view = child_at(0); |
| 122 if (!view->background()) { | 124 if (!view->background()) { |
| 123 canvas->FillRect(gfx::Rect(size()), | 125 canvas->FillRect(gfx::Rect(size()), (hover_ && change_background_) ? |
| 124 hover_ ? kHoverBackgroundColor : kBackgroundColor); | 126 kHoverBackgroundColor : kBackgroundColor); |
| 125 } | 127 } |
| 126 } | 128 } |
| 127 | 129 |
| 128 bool hover_; | 130 bool hover_; |
| 131 bool change_background_; |
| 129 | 132 |
| 130 DISALLOW_COPY_AND_ASSIGN(TrayPopupItemContainer); | 133 DISALLOW_COPY_AND_ASSIGN(TrayPopupItemContainer); |
| 131 }; | 134 }; |
| 132 | 135 |
| 133 // Implicit animation observer that deletes itself and the layer at the end of | 136 // Implicit animation observer that deletes itself and the layer at the end of |
| 134 // the animation. | 137 // the animation. |
| 135 class AnimationObserverDeleteLayer : public ui::ImplicitAnimationObserver { | 138 class AnimationObserverDeleteLayer : public ui::ImplicitAnimationObserver { |
| 136 public: | 139 public: |
| 137 explicit AnimationObserverDeleteLayer(ui::Layer* layer) | 140 explicit AnimationObserverDeleteLayer(ui::Layer* layer) |
| 138 : layer_(layer) { | 141 : layer_(layer) { |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 case BUBBLE_TYPE_DEFAULT: | 449 case BUBBLE_TYPE_DEFAULT: |
| 447 view = (*it)->CreateDefaultView(login_status); | 450 view = (*it)->CreateDefaultView(login_status); |
| 448 break; | 451 break; |
| 449 case BUBBLE_TYPE_DETAILED: | 452 case BUBBLE_TYPE_DETAILED: |
| 450 view = (*it)->CreateDetailedView(login_status); | 453 view = (*it)->CreateDetailedView(login_status); |
| 451 break; | 454 break; |
| 452 case BUBBLE_TYPE_NOTIFICATION: | 455 case BUBBLE_TYPE_NOTIFICATION: |
| 453 view = (*it)->CreateNotificationView(login_status); | 456 view = (*it)->CreateNotificationView(login_status); |
| 454 break; | 457 break; |
| 455 } | 458 } |
| 456 if (view) | 459 if (view) { |
| 457 bubble_view_->AddChildView(new TrayPopupItemContainer(view)); | 460 bubble_view_->AddChildView(new TrayPopupItemContainer( |
| 461 view, bubble_type_ == BUBBLE_TYPE_DEFAULT)); |
| 462 } |
| 458 } | 463 } |
| 459 } | 464 } |
| 460 | 465 |
| 461 void SystemTrayBubble::OnWidgetClosing(views::Widget* widget) { | 466 void SystemTrayBubble::OnWidgetClosing(views::Widget* widget) { |
| 462 CHECK_EQ(bubble_widget_, widget); | 467 CHECK_EQ(bubble_widget_, widget); |
| 463 bubble_widget_ = NULL; | 468 bubble_widget_ = NULL; |
| 464 tray_->RemoveBubble(this); | 469 tray_->RemoveBubble(this); |
| 465 } | 470 } |
| 466 | 471 |
| 467 } // namespace internal | 472 } // namespace internal |
| 468 } // namespace ash | 473 } // namespace ash |
| OLD | NEW |