Chromium Code Reviews| 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/tray_background_view.h" | 5 #include "ash/system/tray/tray_background_view.h" |
| 6 | 6 |
| 7 #include "ash/launcher/background_animator.h" | 7 #include "ash/launcher/background_animator.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
| 10 #include "ash/system/tray/tray_constants.h" | 10 #include "ash/system/tray/tray_constants.h" |
| 11 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 12 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
| 13 #include "ui/gfx/skia_util.h" | 13 #include "ui/gfx/skia_util.h" |
| 14 #include "ui/views/background.h" | 14 #include "ui/views/background.h" |
| 15 #include "ui/views/layout/box_layout.h" | 15 #include "ui/views/layout/box_layout.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 const SkColor kTrayBackgroundAlpha = 100; | 19 const SkColor kTrayBackgroundAlpha = 100; |
| 20 const SkColor kTrayBackgroundHoverAlpha = 150; | 20 const SkColor kTrayBackgroundHoverAlpha = 150; |
| 21 | 21 |
| 22 // Adjust the size of SystemTrayContainer with additional padding. | |
|
jennyz
2012/08/03 00:32:33
SystemTrayContainer -> TrayContainer.
stevenjb
2012/08/03 01:34:10
Done.
| |
| 23 const int kTrayContainerVerticalPaddingBottomAlignment = 1; | |
| 24 const int kTrayContainerHorizontalPaddingBottomAlignment = 1; | |
| 25 const int kTrayContainerVerticalPaddingVerticalAlignment = 1; | |
| 26 const int kTrayContainerHorizontalPaddingVerticalAlignment = 1; | |
| 27 | |
| 22 } // namespace | 28 } // namespace |
| 23 | 29 |
| 24 namespace ash { | 30 namespace ash { |
| 25 namespace internal { | 31 namespace internal { |
| 26 | 32 |
| 27 class TrayBackground : public views::Background { | 33 class TrayBackground : public views::Background { |
| 28 public: | 34 public: |
| 29 TrayBackground() : alpha_(kTrayBackgroundAlpha) {} | 35 TrayBackground() : alpha_(kTrayBackgroundAlpha) {} |
| 30 virtual ~TrayBackground() {} | 36 virtual ~TrayBackground() {} |
| 31 | 37 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 43 SkScalar radius = SkIntToScalar(kTrayRoundedBorderRadius); | 49 SkScalar radius = SkIntToScalar(kTrayRoundedBorderRadius); |
| 44 path.addRoundRect(gfx::RectToSkRect(bounds), radius, radius); | 50 path.addRoundRect(gfx::RectToSkRect(bounds), radius, radius); |
| 45 canvas->DrawPath(path, paint); | 51 canvas->DrawPath(path, paint); |
| 46 } | 52 } |
| 47 | 53 |
| 48 int alpha_; | 54 int alpha_; |
| 49 | 55 |
| 50 DISALLOW_COPY_AND_ASSIGN(TrayBackground); | 56 DISALLOW_COPY_AND_ASSIGN(TrayBackground); |
| 51 }; | 57 }; |
| 52 | 58 |
| 59 TrayBackgroundView::TrayContainer::TrayContainer(ShelfAlignment alignment) | |
| 60 : alignment_(alignment) { | |
| 61 UpdateLayout(); | |
| 62 } | |
| 63 | |
| 64 void TrayBackgroundView::TrayContainer::SetAlignment(ShelfAlignment alignment) { | |
| 65 if (alignment_ == alignment) | |
| 66 return; | |
| 67 alignment_ = alignment; | |
| 68 UpdateLayout(); | |
| 69 } | |
| 70 | |
| 71 gfx::Size TrayBackgroundView::TrayContainer::GetPreferredSize() { | |
| 72 if (size_.IsEmpty()) | |
| 73 return views::View::GetPreferredSize(); | |
| 74 return size_; | |
| 75 } | |
| 76 | |
| 77 void TrayBackgroundView::TrayContainer::ChildPreferredSizeChanged( | |
| 78 views::View* child) { | |
| 79 PreferredSizeChanged(); | |
| 80 } | |
| 81 | |
| 82 void TrayBackgroundView::TrayContainer::ChildVisibilityChanged(View* child) { | |
| 83 PreferredSizeChanged(); | |
| 84 } | |
| 85 | |
| 86 void TrayBackgroundView::TrayContainer::ViewHierarchyChanged(bool is_add, | |
| 87 View* parent, | |
| 88 View* child) { | |
| 89 if (parent == this) | |
| 90 PreferredSizeChanged(); | |
| 91 } | |
| 92 | |
| 93 void TrayBackgroundView::TrayContainer::UpdateLayout() { | |
| 94 // Adjust the size of status tray dark background by adding additional | |
| 95 // empty border. | |
| 96 if (alignment_ == SHELF_ALIGNMENT_BOTTOM) { | |
| 97 set_border(views::Border::CreateEmptyBorder( | |
| 98 kTrayContainerVerticalPaddingBottomAlignment, | |
| 99 kTrayContainerHorizontalPaddingBottomAlignment, | |
| 100 kTrayContainerVerticalPaddingBottomAlignment, | |
| 101 kTrayContainerHorizontalPaddingBottomAlignment)); | |
| 102 views::BoxLayout* layout = | |
| 103 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | |
| 104 layout->set_spread_blank_space(true); | |
| 105 views::View::SetLayoutManager(layout); | |
| 106 } else { | |
| 107 set_border(views::Border::CreateEmptyBorder( | |
| 108 kTrayContainerVerticalPaddingVerticalAlignment, | |
| 109 kTrayContainerHorizontalPaddingVerticalAlignment, | |
| 110 kTrayContainerVerticalPaddingVerticalAlignment, | |
| 111 kTrayContainerHorizontalPaddingVerticalAlignment)); | |
| 112 views::BoxLayout* layout = | |
| 113 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); | |
| 114 layout->set_spread_blank_space(true); | |
| 115 views::View::SetLayoutManager(layout); | |
| 116 } | |
| 117 PreferredSizeChanged(); | |
| 118 } | |
| 119 | |
| 53 //////////////////////////////////////////////////////////////////////////////// | 120 //////////////////////////////////////////////////////////////////////////////// |
| 54 // TrayBackgroundView | 121 // TrayBackgroundView |
| 55 | 122 |
| 56 TrayBackgroundView::TrayBackgroundView() | 123 TrayBackgroundView::TrayBackgroundView( |
| 57 : shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), | 124 internal::StatusAreaWidget* status_area_widget) |
| 125 : status_area_widget_(status_area_widget), | |
| 126 tray_container_(NULL), | |
| 127 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), | |
| 58 background_(NULL), | 128 background_(NULL), |
| 59 ALLOW_THIS_IN_INITIALIZER_LIST(hide_background_animator_( | 129 ALLOW_THIS_IN_INITIALIZER_LIST(hide_background_animator_( |
| 60 this, 0, kTrayBackgroundAlpha)), | 130 this, 0, kTrayBackgroundAlpha)), |
| 61 ALLOW_THIS_IN_INITIALIZER_LIST(hover_background_animator_( | 131 ALLOW_THIS_IN_INITIALIZER_LIST(hover_background_animator_( |
| 62 this, 0, kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha)) { | 132 this, 0, kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha)) { |
| 63 set_notify_enter_exit_on_child(true); | 133 set_notify_enter_exit_on_child(true); |
| 64 | 134 |
| 65 // Initially we want to paint the background, but without the hover effect. | 135 // Initially we want to paint the background, but without the hover effect. |
| 66 SetPaintsBackground(true, internal::BackgroundAnimator::CHANGE_IMMEDIATE); | 136 SetPaintsBackground(true, internal::BackgroundAnimator::CHANGE_IMMEDIATE); |
| 67 hover_background_animator_.SetPaintsBackground(false, | 137 hover_background_animator_.SetPaintsBackground(false, |
| 68 internal::BackgroundAnimator::CHANGE_IMMEDIATE); | 138 internal::BackgroundAnimator::CHANGE_IMMEDIATE); |
| 139 | |
| 140 SetBorder(); | |
| 141 | |
| 142 tray_container_ = new TrayContainer(shelf_alignment_); | |
| 143 SetContents(tray_container_); | |
| 69 } | 144 } |
| 70 | 145 |
| 71 TrayBackgroundView::~TrayBackgroundView() { | 146 TrayBackgroundView::~TrayBackgroundView() { |
| 72 } | 147 } |
| 73 | 148 |
| 74 void TrayBackgroundView::OnMouseEntered(const views::MouseEvent& event) { | 149 void TrayBackgroundView::OnMouseEntered(const views::MouseEvent& event) { |
| 75 hover_background_animator_.SetPaintsBackground(true, | 150 hover_background_animator_.SetPaintsBackground(true, |
| 76 internal::BackgroundAnimator::CHANGE_ANIMATE); | 151 internal::BackgroundAnimator::CHANGE_ANIMATE); |
| 77 } | 152 } |
| 78 | 153 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 106 } | 181 } |
| 107 | 182 |
| 108 void TrayBackgroundView::SetPaintsBackground( | 183 void TrayBackgroundView::SetPaintsBackground( |
| 109 bool value, | 184 bool value, |
| 110 internal::BackgroundAnimator::ChangeType change_type) { | 185 internal::BackgroundAnimator::ChangeType change_type) { |
| 111 hide_background_animator_.SetPaintsBackground(value, change_type); | 186 hide_background_animator_.SetPaintsBackground(value, change_type); |
| 112 } | 187 } |
| 113 | 188 |
| 114 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { | 189 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { |
| 115 shelf_alignment_ = alignment; | 190 shelf_alignment_ = alignment; |
| 191 SetBorder(); | |
| 192 tray_container_->SetAlignment(alignment); | |
| 193 } | |
| 194 | |
| 195 void TrayBackgroundView::SetBorder() { | |
| 196 // Change the border padding for different shelf alignment. | |
| 197 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { | |
| 198 set_border(views::Border::CreateEmptyBorder(0, 0, | |
| 199 kPaddingFromBottomOfScreenBottomAlignment, | |
| 200 kPaddingFromRightEdgeOfScreenBottomAlignment)); | |
| 201 } else if (shelf_alignment() == SHELF_ALIGNMENT_LEFT) { | |
| 202 set_border(views::Border::CreateEmptyBorder(0, | |
| 203 kPaddingFromOuterEdgeOfLauncherVerticalAlignment, | |
| 204 kPaddingFromBottomOfScreenVerticalAlignment, | |
| 205 kPaddingFromInnerEdgeOfLauncherVerticalAlignment)); | |
| 206 } else { | |
| 207 set_border(views::Border::CreateEmptyBorder(0, | |
| 208 kPaddingFromInnerEdgeOfLauncherVerticalAlignment, | |
| 209 kPaddingFromBottomOfScreenVerticalAlignment, | |
| 210 kPaddingFromOuterEdgeOfLauncherVerticalAlignment)); | |
| 211 } | |
| 116 } | 212 } |
| 117 | 213 |
| 118 } // namespace internal | 214 } // namespace internal |
| 119 } // namespace ash | 215 } // namespace ash |
| OLD | NEW |