| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/shelf/dimmer_view.h" | 5 #include "ash/shelf/dimmer_view.h" |
| 6 | 6 |
| 7 #include "ash/aura/wm_window_aura.h" | 7 #include "ash/aura/wm_window_aura.h" |
| 8 #include "ash/common/shelf/wm_shelf.h" | 8 #include "ash/common/shelf/wm_shelf.h" |
| 9 #include "ash/common/shelf/wm_shelf_util.h" | 9 #include "ash/common/shelf/wm_shelf_util.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 // possible force state has disappeared. | 55 // possible force state has disappeared. |
| 56 is_hovered_ = hovered; | 56 is_hovered_ = hovered; |
| 57 // Undim also if we were forced to by e.g. an open menu. | 57 // Undim also if we were forced to by e.g. an open menu. |
| 58 hovered |= force_hovered_; | 58 hovered |= force_hovered_; |
| 59 background_animator_.SetDuration(hovered ? kTimeToUnDimMs : kTimeToDimMs); | 59 background_animator_.SetDuration(hovered ? kTimeToUnDimMs : kTimeToDimMs); |
| 60 background_animator_.SetPaintsBackground( | 60 background_animator_.SetPaintsBackground( |
| 61 !hovered, disable_animations_for_test_ ? BACKGROUND_CHANGE_IMMEDIATE | 61 !hovered, disable_animations_for_test_ ? BACKGROUND_CHANGE_IMMEDIATE |
| 62 : BACKGROUND_CHANGE_ANIMATE); | 62 : BACKGROUND_CHANGE_ANIMATE); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void DimmerView::ForceUndimming(bool force) { | |
| 66 bool previous = force_hovered_; | |
| 67 force_hovered_ = force; | |
| 68 // If the forced change does change the result we apply the change. | |
| 69 if (is_hovered_ || force_hovered_ != is_hovered_ || previous) | |
| 70 SetHovered(is_hovered_); | |
| 71 } | |
| 72 | |
| 73 void DimmerView::OnPaintBackground(gfx::Canvas* canvas) { | 65 void DimmerView::OnPaintBackground(gfx::Canvas* canvas) { |
| 74 SkPaint paint; | 66 SkPaint paint; |
| 75 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 67 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 76 gfx::ImageSkia shelf_background = | 68 gfx::ImageSkia shelf_background = |
| 77 *rb->GetImageNamed(IDR_ASH_SHELF_DIMMING).ToImageSkia(); | 69 *rb->GetImageNamed(IDR_ASH_SHELF_DIMMING).ToImageSkia(); |
| 78 | 70 |
| 79 if (!IsHorizontalAlignment(shelf_->GetAlignment())) { | 71 if (!IsHorizontalAlignment(shelf_->GetAlignment())) { |
| 80 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( | 72 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( |
| 81 shelf_background, shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT | 73 shelf_background, shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT |
| 82 ? SkBitmapOperations::ROTATION_90_CW | 74 ? SkBitmapOperations::ROTATION_90_CW |
| (...skipping 13 matching lines...) Expand all Loading... |
| 96 return View::GetWidget(); | 88 return View::GetWidget(); |
| 97 } | 89 } |
| 98 | 90 |
| 99 void DimmerView::UpdateBackground(BackgroundAnimator* animator, int alpha) { | 91 void DimmerView::UpdateBackground(BackgroundAnimator* animator, int alpha) { |
| 100 alpha_ = alpha; | 92 alpha_ = alpha; |
| 101 SchedulePaint(); | 93 SchedulePaint(); |
| 102 } | 94 } |
| 103 | 95 |
| 104 void DimmerView::BackgroundAnimationEnded(BackgroundAnimator* animator) {} | 96 void DimmerView::BackgroundAnimationEnded(BackgroundAnimator* animator) {} |
| 105 | 97 |
| 98 views::Widget* DimmerView::GetDimmerWidget() { |
| 99 return GetWidget(); |
| 100 } |
| 101 |
| 102 void DimmerView::ForceUndimming(bool force) { |
| 103 bool previous = force_hovered_; |
| 104 force_hovered_ = force; |
| 105 // If the forced change does change the result we apply the change. |
| 106 if (is_hovered_ || force_hovered_ != is_hovered_ || previous) |
| 107 SetHovered(is_hovered_); |
| 108 } |
| 109 |
| 110 int DimmerView::GetDimmingAlphaForTest() { |
| 111 return alpha_; |
| 112 } |
| 113 |
| 106 void DimmerView::OnWindowBoundsChanged(WmWindow* window, | 114 void DimmerView::OnWindowBoundsChanged(WmWindow* window, |
| 107 const gfx::Rect& old_bounds, | 115 const gfx::Rect& old_bounds, |
| 108 const gfx::Rect& new_bounds) { | 116 const gfx::Rect& new_bounds) { |
| 109 // Coming here the shelf got repositioned and since the dimmer is placed | 117 // Coming here the shelf got repositioned and since the dimmer is placed |
| 110 // in screen coordinates and not relative to the parent it needs to be | 118 // in screen coordinates and not relative to the parent it needs to be |
| 111 // repositioned accordingly. | 119 // repositioned accordingly. |
| 112 GetWidget()->SetBounds(shelf_->GetWindow()->GetBoundsInScreen()); | 120 GetWidget()->SetBounds(shelf_->GetWindow()->GetBoundsInScreen()); |
| 113 } | 121 } |
| 114 | 122 |
| 115 DimmerView::DimmerView(WmShelf* shelf, bool disable_animations_for_test) | 123 DimmerView::DimmerView(WmShelf* shelf, bool disable_animations_for_test) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 &screen_point); | 173 &screen_point); |
| 166 touch_inside = owner_->GetBoundsInScreen().Contains(screen_point); | 174 touch_inside = owner_->GetBoundsInScreen().Contains(screen_point); |
| 167 } | 175 } |
| 168 | 176 |
| 169 if (mouse_inside_ || touch_inside_ != mouse_inside_ || touch_inside) | 177 if (mouse_inside_ || touch_inside_ != mouse_inside_ || touch_inside) |
| 170 owner_->SetHovered(mouse_inside_ || touch_inside); | 178 owner_->SetHovered(mouse_inside_ || touch_inside); |
| 171 touch_inside_ = touch_inside; | 179 touch_inside_ = touch_inside; |
| 172 } | 180 } |
| 173 | 181 |
| 174 } // namespace ash | 182 } // namespace ash |
| OLD | NEW |