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/wm/resize_shadow_controller.h" | 5 #include "ash/wm/resize_shadow_controller.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "ash/wm/resize_shadow.h" | 9 #include "ash/wm/resize_shadow.h" |
10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
11 | 11 |
12 namespace ash { | 12 namespace ash { |
13 | 13 |
14 ResizeShadowController::ResizeShadowController() {} | 14 ResizeShadowController::ResizeShadowController() {} |
15 | 15 |
16 ResizeShadowController::~ResizeShadowController() { | 16 ResizeShadowController::~ResizeShadowController() { |
17 for (WindowShadowMap::const_iterator it = window_shadows_.begin(); | 17 for (const auto& shadow : window_shadows_) |
18 it != window_shadows_.end(); ++it) { | 18 shadow.first->RemoveObserver(this); |
19 it->first->RemoveObserver(this); | |
20 } | |
21 } | 19 } |
22 | 20 |
23 void ResizeShadowController::ShowShadow(aura::Window* window, int hit_test) { | 21 void ResizeShadowController::ShowShadow(aura::Window* window, int hit_test) { |
24 ResizeShadow* shadow = GetShadowForWindow(window); | 22 ResizeShadow* shadow = GetShadowForWindow(window); |
25 if (!shadow) | 23 if (!shadow) |
26 shadow = CreateShadow(window); | 24 shadow = CreateShadow(window); |
27 shadow->ShowForHitTest(hit_test); | 25 shadow->ShowForHitTest(hit_test); |
28 } | 26 } |
29 | 27 |
30 void ResizeShadowController::HideShadow(aura::Window* window) { | 28 void ResizeShadowController::HideShadow(aura::Window* window) { |
(...skipping 14 matching lines...) Expand all Loading... |
45 ResizeShadow* shadow = GetShadowForWindow(window); | 43 ResizeShadow* shadow = GetShadowForWindow(window); |
46 if (shadow) | 44 if (shadow) |
47 shadow->Layout(new_bounds); | 45 shadow->Layout(new_bounds); |
48 } | 46 } |
49 | 47 |
50 void ResizeShadowController::OnWindowDestroyed(aura::Window* window) { | 48 void ResizeShadowController::OnWindowDestroyed(aura::Window* window) { |
51 window_shadows_.erase(window); | 49 window_shadows_.erase(window); |
52 } | 50 } |
53 | 51 |
54 ResizeShadow* ResizeShadowController::CreateShadow(aura::Window* window) { | 52 ResizeShadow* ResizeShadowController::CreateShadow(aura::Window* window) { |
55 linked_ptr<ResizeShadow> shadow(new ResizeShadow()); | 53 auto shadow = base::MakeUnique<ResizeShadow>(); |
56 window_shadows_.insert(std::make_pair(window, shadow)); | |
57 // Attach the layers to this window. | 54 // Attach the layers to this window. |
58 shadow->Init(window); | 55 shadow->Init(window); |
59 // Ensure initial bounds are correct. | 56 // Ensure initial bounds are correct. |
60 shadow->Layout(window->bounds()); | 57 shadow->Layout(window->bounds()); |
61 // Watch for bounds changes. | 58 // Watch for bounds changes. |
62 window->AddObserver(this); | 59 window->AddObserver(this); |
63 return shadow.get(); | 60 |
| 61 ResizeShadow* raw_shadow = shadow.get(); |
| 62 window_shadows_.insert(std::make_pair(window, std::move(shadow))); |
| 63 return raw_shadow; |
64 } | 64 } |
65 | 65 |
66 ResizeShadow* ResizeShadowController::GetShadowForWindow(aura::Window* window) { | 66 ResizeShadow* ResizeShadowController::GetShadowForWindow(aura::Window* window) { |
67 WindowShadowMap::const_iterator it = window_shadows_.find(window); | 67 auto it = window_shadows_.find(window); |
68 return it != window_shadows_.end() ? it->second.get() : NULL; | 68 return it != window_shadows_.end() ? it->second.get() : nullptr; |
69 } | 69 } |
70 | 70 |
71 } // namespace ash | 71 } // namespace ash |
OLD | NEW |