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/common/system/tray/tray_background_view.h" | 5 #include "ash/common/system/tray/tray_background_view.h" |
6 | 6 |
7 #include "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
8 #include "ash/common/shelf/shelf_constants.h" | 8 #include "ash/common/shelf/shelf_constants.h" |
9 #include "ash/common/shelf/wm_shelf.h" | 9 #include "ash/common/shelf/wm_shelf.h" |
10 #include "ash/common/shelf/wm_shelf_util.h" | 10 #include "ash/common/shelf/wm_shelf_util.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 const static int kImageTypeDefault = 0; | 82 const static int kImageTypeDefault = 0; |
83 const static int kImageTypeOnBlack = 1; | 83 const static int kImageTypeOnBlack = 1; |
84 const static int kImageTypePressed = 2; | 84 const static int kImageTypePressed = 2; |
85 const static int kNumStates = 3; | 85 const static int kNumStates = 3; |
86 | 86 |
87 const static int kImageHorizontal = 0; | 87 const static int kImageHorizontal = 0; |
88 const static int kImageVertical = 1; | 88 const static int kImageVertical = 1; |
89 const static int kNumOrientations = 2; | 89 const static int kNumOrientations = 2; |
90 | 90 |
91 explicit TrayBackground(TrayBackgroundView* tray_background_view) | 91 explicit TrayBackground(TrayBackgroundView* tray_background_view) |
92 : tray_background_view_(tray_background_view), alpha_(0) {} | 92 : tray_background_view_(tray_background_view) {} |
93 | 93 |
94 ~TrayBackground() override {} | 94 ~TrayBackground() override {} |
95 | 95 |
96 void set_alpha(int alpha) { alpha_ = alpha; } | |
97 | |
98 private: | 96 private: |
99 WmShelf* GetShelf() const { return tray_background_view_->shelf(); } | 97 WmShelf* GetShelf() const { return tray_background_view_->shelf(); } |
100 | 98 |
101 void PaintMaterial(gfx::Canvas* canvas, views::View* view) const { | 99 void PaintMaterial(gfx::Canvas* canvas, views::View* view) const { |
| 100 SkColor background_color = SK_ColorTRANSPARENT; |
| 101 if (GetShelf()->GetBackgroundType() == |
| 102 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT) { |
| 103 background_color = SkColorSetA(kShelfBaseColor, |
| 104 GetShelfConstant(SHELF_BACKGROUND_ALPHA)); |
| 105 } |
| 106 |
| 107 // TODO(bruthig|tdanderson): The background should be changed using a |
| 108 // fade in/out animation. |
102 SkPaint background_paint; | 109 SkPaint background_paint; |
103 background_paint.setFlags(SkPaint::kAntiAlias_Flag); | 110 background_paint.setFlags(SkPaint::kAntiAlias_Flag); |
104 background_paint.setColor(SkColorSetA(kShelfBaseColor, alpha_)); | 111 background_paint.setColor(background_color); |
105 canvas->DrawRoundRect(view->GetLocalBounds(), kTrayRoundedBorderRadius, | 112 canvas->DrawRoundRect(view->GetLocalBounds(), kTrayRoundedBorderRadius, |
106 background_paint); | 113 background_paint); |
107 | 114 |
108 if (tray_background_view_->draw_background_as_active()) { | 115 if (tray_background_view_->draw_background_as_active()) { |
109 SkPaint highlight_paint; | 116 SkPaint highlight_paint; |
110 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag); | 117 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag); |
111 highlight_paint.setColor(kShelfButtonActivatedHighlightColor); | 118 highlight_paint.setColor(kShelfButtonActivatedHighlightColor); |
112 canvas->DrawRoundRect(view->GetLocalBounds(), kTrayRoundedBorderRadius, | 119 canvas->DrawRoundRect(view->GetLocalBounds(), kTrayRoundedBorderRadius, |
113 highlight_paint); | 120 highlight_paint); |
114 } | 121 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 void Paint(gfx::Canvas* canvas, views::View* view) const override { | 158 void Paint(gfx::Canvas* canvas, views::View* view) const override { |
152 if (MaterialDesignController::IsShelfMaterial()) | 159 if (MaterialDesignController::IsShelfMaterial()) |
153 PaintMaterial(canvas, view); | 160 PaintMaterial(canvas, view); |
154 else | 161 else |
155 PaintNonMaterial(canvas, view); | 162 PaintNonMaterial(canvas, view); |
156 } | 163 } |
157 | 164 |
158 // Reference to the TrayBackgroundView for which this is a background. | 165 // Reference to the TrayBackgroundView for which this is a background. |
159 TrayBackgroundView* tray_background_view_; | 166 TrayBackgroundView* tray_background_view_; |
160 | 167 |
161 int alpha_; | |
162 | |
163 DISALLOW_COPY_AND_ASSIGN(TrayBackground); | 168 DISALLOW_COPY_AND_ASSIGN(TrayBackground); |
164 }; | 169 }; |
165 | 170 |
166 TrayBackgroundView::TrayContainer::TrayContainer(ShelfAlignment alignment) | 171 TrayBackgroundView::TrayContainer::TrayContainer(ShelfAlignment alignment) |
167 : alignment_(alignment) { | 172 : alignment_(alignment) { |
168 UpdateLayout(); | 173 UpdateLayout(); |
169 } | 174 } |
170 | 175 |
171 void TrayBackgroundView::TrayContainer::SetAlignment(ShelfAlignment alignment) { | 176 void TrayBackgroundView::TrayContainer::SetAlignment(ShelfAlignment alignment) { |
172 if (alignment_ == alignment) | 177 if (alignment_ == alignment) |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | 352 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { |
348 SetDrawBackgroundAsActive(true); | 353 SetDrawBackgroundAsActive(true); |
349 } else if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN || | 354 } else if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN || |
350 event->type() == ui::ET_GESTURE_TAP_CANCEL) { | 355 event->type() == ui::ET_GESTURE_TAP_CANCEL) { |
351 SetDrawBackgroundAsActive(false); | 356 SetDrawBackgroundAsActive(false); |
352 } | 357 } |
353 } | 358 } |
354 ActionableView::OnGestureEvent(event); | 359 ActionableView::OnGestureEvent(event); |
355 } | 360 } |
356 | 361 |
| 362 void TrayBackgroundView::UpdateBackground(int alpha) { |
| 363 // The animator should never fire when the alternate shelf layout is used. |
| 364 if (!background_ || draw_background_as_active_) |
| 365 return; |
| 366 SchedulePaint(); |
| 367 } |
| 368 |
357 void TrayBackgroundView::SetContents(views::View* contents) { | 369 void TrayBackgroundView::SetContents(views::View* contents) { |
358 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 370 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
359 AddChildView(contents); | 371 AddChildView(contents); |
360 } | 372 } |
361 void TrayBackgroundView::SetContentsBackground() { | 373 void TrayBackgroundView::SetContentsBackground() { |
362 background_ = new TrayBackground(this); | 374 background_ = new TrayBackground(this); |
363 tray_container_->set_background(background_); | 375 tray_container_->set_background(background_); |
364 } | 376 } |
365 | 377 |
366 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { | 378 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 if (!background_) | 503 if (!background_) |
492 return; | 504 return; |
493 SchedulePaint(); | 505 SchedulePaint(); |
494 } | 506 } |
495 | 507 |
496 void TrayBackgroundView::UpdateBubbleViewArrow( | 508 void TrayBackgroundView::UpdateBubbleViewArrow( |
497 views::TrayBubbleView* bubble_view) { | 509 views::TrayBubbleView* bubble_view) { |
498 // Nothing to do here. | 510 // Nothing to do here. |
499 } | 511 } |
500 | 512 |
501 void TrayBackgroundView::UpdateShelfItemBackground(int alpha) { | |
502 if (background_) { | |
503 background_->set_alpha(alpha); | |
504 SchedulePaint(); | |
505 } | |
506 } | |
507 | |
508 } // namespace ash | 513 } // namespace ash |
OLD | NEW |