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
3 // found in the LICENSE file.
5 #include "ash/wm/resize_shadow_controller.h"
9 #include "ash/wm/resize_shadow.h"
10 #include "ui/aura/window.h"
15 ResizeShadowController::ResizeShadowController() {
18 ResizeShadowController::~ResizeShadowController() {
19 for (WindowShadowMap::const_iterator it
= window_shadows_
.begin();
20 it
!= window_shadows_
.end(); ++it
) {
21 it
->first
->RemoveObserver(this);
25 void ResizeShadowController::ShowShadow(aura::Window
* window
, int hit_test
) {
26 ResizeShadow
* shadow
= GetShadowForWindow(window
);
28 shadow
= CreateShadow(window
);
29 shadow
->ShowForHitTest(hit_test
);
32 void ResizeShadowController::HideShadow(aura::Window
* window
) {
33 ResizeShadow
* shadow
= GetShadowForWindow(window
);
38 ResizeShadow
* ResizeShadowController::GetShadowForWindowForTest(
39 aura::Window
* window
) {
40 return GetShadowForWindow(window
);
43 void ResizeShadowController::OnWindowBoundsChanged(
45 const gfx::Rect
& old_bounds
,
46 const gfx::Rect
& new_bounds
) {
47 ResizeShadow
* shadow
= GetShadowForWindow(window
);
49 shadow
->Layout(new_bounds
);
52 void ResizeShadowController::OnWindowDestroyed(aura::Window
* window
) {
53 window_shadows_
.erase(window
);
56 ResizeShadow
* ResizeShadowController::CreateShadow(aura::Window
* window
) {
57 linked_ptr
<ResizeShadow
> shadow(new ResizeShadow());
58 window_shadows_
.insert(std::make_pair(window
, shadow
));
59 // Attach the layers to this window.
61 // Ensure initial bounds are correct.
62 shadow
->Layout(window
->bounds());
63 // Watch for bounds changes.
64 window
->AddObserver(this);
68 ResizeShadow
* ResizeShadowController::GetShadowForWindow(aura::Window
* window
) {
69 WindowShadowMap::const_iterator it
= window_shadows_
.find(window
);
70 return it
!= window_shadows_
.end() ? it
->second
.get() : NULL
;
73 } // namespace internal