| 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) {} | 92 : tray_background_view_(tray_background_view), alpha_(0) {} |
| 93 | 93 |
| 94 ~TrayBackground() override {} | 94 ~TrayBackground() override {} |
| 95 | 95 |
| 96 void set_alpha(int alpha) { alpha_ = alpha; } |
| 97 |
| 96 private: | 98 private: |
| 97 WmShelf* GetShelf() const { return tray_background_view_->shelf(); } | 99 WmShelf* GetShelf() const { return tray_background_view_->shelf(); } |
| 98 | 100 |
| 99 void PaintMaterial(gfx::Canvas* canvas, views::View* view) const { | 101 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. | |
| 109 SkPaint background_paint; | 102 SkPaint background_paint; |
| 110 background_paint.setFlags(SkPaint::kAntiAlias_Flag); | 103 background_paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 111 background_paint.setColor(background_color); | 104 background_paint.setColor(SkColorSetA(kShelfBaseColor, alpha_)); |
| 112 canvas->DrawRoundRect(view->GetLocalBounds(), kTrayRoundedBorderRadius, | 105 canvas->DrawRoundRect(view->GetLocalBounds(), kTrayRoundedBorderRadius, |
| 113 background_paint); | 106 background_paint); |
| 114 | 107 |
| 115 if (tray_background_view_->draw_background_as_active()) { | 108 if (tray_background_view_->draw_background_as_active()) { |
| 116 SkPaint highlight_paint; | 109 SkPaint highlight_paint; |
| 117 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag); | 110 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 118 highlight_paint.setColor(kShelfButtonActivatedHighlightColor); | 111 highlight_paint.setColor(kShelfButtonActivatedHighlightColor); |
| 119 canvas->DrawRoundRect(view->GetLocalBounds(), kTrayRoundedBorderRadius, | 112 canvas->DrawRoundRect(view->GetLocalBounds(), kTrayRoundedBorderRadius, |
| 120 highlight_paint); | 113 highlight_paint); |
| 121 } | 114 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 void Paint(gfx::Canvas* canvas, views::View* view) const override { | 151 void Paint(gfx::Canvas* canvas, views::View* view) const override { |
| 159 if (MaterialDesignController::IsShelfMaterial()) | 152 if (MaterialDesignController::IsShelfMaterial()) |
| 160 PaintMaterial(canvas, view); | 153 PaintMaterial(canvas, view); |
| 161 else | 154 else |
| 162 PaintNonMaterial(canvas, view); | 155 PaintNonMaterial(canvas, view); |
| 163 } | 156 } |
| 164 | 157 |
| 165 // Reference to the TrayBackgroundView for which this is a background. | 158 // Reference to the TrayBackgroundView for which this is a background. |
| 166 TrayBackgroundView* tray_background_view_; | 159 TrayBackgroundView* tray_background_view_; |
| 167 | 160 |
| 161 int alpha_; |
| 162 |
| 168 DISALLOW_COPY_AND_ASSIGN(TrayBackground); | 163 DISALLOW_COPY_AND_ASSIGN(TrayBackground); |
| 169 }; | 164 }; |
| 170 | 165 |
| 171 TrayBackgroundView::TrayContainer::TrayContainer(ShelfAlignment alignment) | 166 TrayBackgroundView::TrayContainer::TrayContainer(ShelfAlignment alignment) |
| 172 : alignment_(alignment) { | 167 : alignment_(alignment) { |
| 173 UpdateLayout(); | 168 UpdateLayout(); |
| 174 } | 169 } |
| 175 | 170 |
| 176 void TrayBackgroundView::TrayContainer::SetAlignment(ShelfAlignment alignment) { | 171 void TrayBackgroundView::TrayContainer::SetAlignment(ShelfAlignment alignment) { |
| 177 if (alignment_ == alignment) | 172 if (alignment_ == alignment) |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | 347 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { |
| 353 SetDrawBackgroundAsActive(true); | 348 SetDrawBackgroundAsActive(true); |
| 354 } else if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN || | 349 } else if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN || |
| 355 event->type() == ui::ET_GESTURE_TAP_CANCEL) { | 350 event->type() == ui::ET_GESTURE_TAP_CANCEL) { |
| 356 SetDrawBackgroundAsActive(false); | 351 SetDrawBackgroundAsActive(false); |
| 357 } | 352 } |
| 358 } | 353 } |
| 359 ActionableView::OnGestureEvent(event); | 354 ActionableView::OnGestureEvent(event); |
| 360 } | 355 } |
| 361 | 356 |
| 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 | |
| 369 void TrayBackgroundView::SetContents(views::View* contents) { | 357 void TrayBackgroundView::SetContents(views::View* contents) { |
| 370 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 358 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 371 AddChildView(contents); | 359 AddChildView(contents); |
| 372 } | 360 } |
| 373 void TrayBackgroundView::SetContentsBackground() { | 361 void TrayBackgroundView::SetContentsBackground() { |
| 374 background_ = new TrayBackground(this); | 362 background_ = new TrayBackground(this); |
| 375 tray_container_->set_background(background_); | 363 tray_container_->set_background(background_); |
| 376 } | 364 } |
| 377 | 365 |
| 378 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { | 366 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 if (!background_) | 491 if (!background_) |
| 504 return; | 492 return; |
| 505 SchedulePaint(); | 493 SchedulePaint(); |
| 506 } | 494 } |
| 507 | 495 |
| 508 void TrayBackgroundView::UpdateBubbleViewArrow( | 496 void TrayBackgroundView::UpdateBubbleViewArrow( |
| 509 views::TrayBubbleView* bubble_view) { | 497 views::TrayBubbleView* bubble_view) { |
| 510 // Nothing to do here. | 498 // Nothing to do here. |
| 511 } | 499 } |
| 512 | 500 |
| 501 void TrayBackgroundView::UpdateShelfItemBackground(int alpha) { |
| 502 if (background_) { |
| 503 background_->set_alpha(alpha); |
| 504 SchedulePaint(); |
| 505 } |
| 506 } |
| 507 |
| 513 } // namespace ash | 508 } // namespace ash |
| OLD | NEW |