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.h" | 5 #include "ash/system/tray/system_tray.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell/panel_window.h" | 8 #include "ash/shell/panel_window.h" |
9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
10 #include "ash/system/audio/tray_volume.h" | 10 #include "ash/system/audio/tray_volume.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 SkScalar radius = SkIntToScalar(kTrayRoundedBorderRadius); | 78 SkScalar radius = SkIntToScalar(kTrayRoundedBorderRadius); |
79 path.addRoundRect(gfx::RectToSkRect(bounds), radius, radius); | 79 path.addRoundRect(gfx::RectToSkRect(bounds), radius, radius); |
80 canvas->DrawPath(path, paint); | 80 canvas->DrawPath(path, paint); |
81 } | 81 } |
82 | 82 |
83 int alpha_; | 83 int alpha_; |
84 | 84 |
85 DISALLOW_COPY_AND_ASSIGN(SystemTrayBackground); | 85 DISALLOW_COPY_AND_ASSIGN(SystemTrayBackground); |
86 }; | 86 }; |
87 | 87 |
| 88 // Container for all the items in the tray. The container auto-resizes the |
| 89 // widget when necessary. |
| 90 class SystemTrayContainer : public views::View { |
| 91 public: |
| 92 SystemTrayContainer() {} |
| 93 virtual ~SystemTrayContainer() {} |
| 94 |
| 95 private: |
| 96 void UpdateWidgetSize() { |
| 97 if (GetWidget()) |
| 98 GetWidget()->SetSize(GetWidget()->GetContentsView()->GetPreferredSize()); |
| 99 } |
| 100 |
| 101 // Overridden from views::View. |
| 102 virtual void ChildPreferredSizeChanged(views::View* child) { |
| 103 views::View::ChildPreferredSizeChanged(child); |
| 104 UpdateWidgetSize(); |
| 105 } |
| 106 |
| 107 virtual void ChildVisibilityChanged(View* child) OVERRIDE { |
| 108 views::View::ChildVisibilityChanged(child); |
| 109 UpdateWidgetSize(); |
| 110 } |
| 111 |
| 112 virtual void ViewHierarchyChanged(bool is_add, |
| 113 View* parent, |
| 114 View* child) OVERRIDE { |
| 115 if (parent == this) |
| 116 UpdateWidgetSize(); |
| 117 } |
| 118 |
| 119 DISALLOW_COPY_AND_ASSIGN(SystemTrayContainer); |
| 120 }; |
| 121 |
88 // Observe the tray layer animation and update the anchor when it changes. | 122 // Observe the tray layer animation and update the anchor when it changes. |
89 // TODO(stevenjb): Observe or mirror the actual animation, not just the start | 123 // TODO(stevenjb): Observe or mirror the actual animation, not just the start |
90 // and end points. | 124 // and end points. |
91 class SystemTrayLayerAnimationObserver : public ui::LayerAnimationObserver { | 125 class SystemTrayLayerAnimationObserver : public ui::LayerAnimationObserver { |
92 public: | 126 public: |
93 explicit SystemTrayLayerAnimationObserver(SystemTray* host) : host_(host) {} | 127 explicit SystemTrayLayerAnimationObserver(SystemTray* host) : host_(host) {} |
94 | 128 |
95 virtual void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) { | 129 virtual void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) { |
96 host_->UpdateNotificationAnchor(); | 130 host_->UpdateNotificationAnchor(); |
97 } | 131 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 power_status_observer_(NULL), | 165 power_status_observer_(NULL), |
132 update_observer_(NULL), | 166 update_observer_(NULL), |
133 user_observer_(NULL), | 167 user_observer_(NULL), |
134 widget_(NULL), | 168 widget_(NULL), |
135 background_(new internal::SystemTrayBackground), | 169 background_(new internal::SystemTrayBackground), |
136 should_show_launcher_(false), | 170 should_show_launcher_(false), |
137 ALLOW_THIS_IN_INITIALIZER_LIST(hide_background_animator_(this, | 171 ALLOW_THIS_IN_INITIALIZER_LIST(hide_background_animator_(this, |
138 0, kTrayBackgroundAlpha)), | 172 0, kTrayBackgroundAlpha)), |
139 ALLOW_THIS_IN_INITIALIZER_LIST(hover_background_animator_(this, | 173 ALLOW_THIS_IN_INITIALIZER_LIST(hover_background_animator_(this, |
140 0, kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha)) { | 174 0, kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha)) { |
141 tray_container_ = new views::View; | 175 tray_container_ = new internal::SystemTrayContainer; |
142 tray_container_->SetLayoutManager(new views::BoxLayout( | 176 tray_container_->SetLayoutManager(new views::BoxLayout( |
143 views::BoxLayout::kHorizontal, 0, 0, 0)); | 177 views::BoxLayout::kHorizontal, 0, 0, 0)); |
144 tray_container_->set_background(background_); | 178 tray_container_->set_background(background_); |
145 tray_container_->set_border( | 179 tray_container_->set_border( |
146 views::Border::CreateEmptyBorder(1, 1, 1, 1)); | 180 views::Border::CreateEmptyBorder(1, 1, 1, 1)); |
147 set_border(views::Border::CreateEmptyBorder(0, 0, | 181 set_border(views::Border::CreateEmptyBorder(0, 0, |
148 kPaddingFromBottomOfScreen, kPaddingFromRightEdgeOfScreen)); | 182 kPaddingFromBottomOfScreen, kPaddingFromRightEdgeOfScreen)); |
149 set_notify_enter_exit_on_child(true); | 183 set_notify_enter_exit_on_child(true); |
150 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 184 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
151 AddChildView(tray_container_); | 185 AddChildView(tray_container_); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 canvas->DrawFocusRect(tray_container_->bounds()); | 469 canvas->DrawFocusRect(tray_container_->bounds()); |
436 } | 470 } |
437 | 471 |
438 void SystemTray::UpdateBackground(int alpha) { | 472 void SystemTray::UpdateBackground(int alpha) { |
439 background_->set_alpha(hide_background_animator_.alpha() + | 473 background_->set_alpha(hide_background_animator_.alpha() + |
440 hover_background_animator_.alpha()); | 474 hover_background_animator_.alpha()); |
441 SchedulePaint(); | 475 SchedulePaint(); |
442 } | 476 } |
443 | 477 |
444 } // namespace ash | 478 } // namespace ash |
OLD | NEW |