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"
14 ResizeShadowController::ResizeShadowController() {
17 ResizeShadowController::~ResizeShadowController() {
18 for (WindowShadowMap::const_iterator it
= window_shadows_
.begin();
19 it
!= window_shadows_
.end(); ++it
) {
20 it
->first
->RemoveObserver(this);
24 void ResizeShadowController::ShowShadow(aura::Window
* window
, int hit_test
) {
25 ResizeShadow
* shadow
= GetShadowForWindow(window
);
27 shadow
= CreateShadow(window
);
28 shadow
->ShowForHitTest(hit_test
);
31 void ResizeShadowController::HideShadow(aura::Window
* window
) {
32 ResizeShadow
* shadow
= GetShadowForWindow(window
);
37 ResizeShadow
* ResizeShadowController::GetShadowForWindowForTest(
38 aura::Window
* window
) {
39 return GetShadowForWindow(window
);
42 void ResizeShadowController::OnWindowBoundsChanged(
44 const gfx::Rect
& old_bounds
,
45 const gfx::Rect
& new_bounds
) {
46 ResizeShadow
* shadow
= GetShadowForWindow(window
);
48 shadow
->Layout(new_bounds
);
51 void ResizeShadowController::OnWindowDestroyed(aura::Window
* window
) {
52 window_shadows_
.erase(window
);
55 ResizeShadow
* ResizeShadowController::CreateShadow(aura::Window
* window
) {
56 linked_ptr
<ResizeShadow
> shadow(new ResizeShadow());
57 window_shadows_
.insert(std::make_pair(window
, shadow
));
58 // Attach the layers to this window.
60 // Ensure initial bounds are correct.
61 shadow
->Layout(window
->bounds());
62 // Watch for bounds changes.
63 window
->AddObserver(this);
67 ResizeShadow
* ResizeShadowController::GetShadowForWindow(aura::Window
* window
) {
68 WindowShadowMap::const_iterator it
= window_shadows_
.find(window
);
69 return it
!= window_shadows_
.end() ? it
->second
.get() : NULL
;