blob: e5ed6c329b2b6b1c7a614b73a9bda8a4a2b04a08 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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.
4
5#include "ash/wm/resize_shadow_controller.h"
6
7#include <utility>
8
9#include "ash/wm/resize_shadow.h"
10#include "ui/aura/window.h"
11
12namespace ash {
Torne (Richard Coles)58218062012-11-14 11:43:16 +000013
14ResizeShadowController::ResizeShadowController() {
15}
16
17ResizeShadowController::~ResizeShadowController() {
18 for (WindowShadowMap::const_iterator it = window_shadows_.begin();
19 it != window_shadows_.end(); ++it) {
20 it->first->RemoveObserver(this);
21 }
22}
23
24void ResizeShadowController::ShowShadow(aura::Window* window, int hit_test) {
25 ResizeShadow* shadow = GetShadowForWindow(window);
26 if (!shadow)
27 shadow = CreateShadow(window);
28 shadow->ShowForHitTest(hit_test);
29}
30
31void ResizeShadowController::HideShadow(aura::Window* window) {
32 ResizeShadow* shadow = GetShadowForWindow(window);
33 if (shadow)
34 shadow->Hide();
35}
36
Ben Murdochba5b9a62013-08-12 14:20:17 +010037ResizeShadow* ResizeShadowController::GetShadowForWindowForTest(
38 aura::Window* window) {
39 return GetShadowForWindow(window);
40}
41
Torne (Richard Coles)58218062012-11-14 11:43:16 +000042void ResizeShadowController::OnWindowBoundsChanged(
43 aura::Window* window,
44 const gfx::Rect& old_bounds,
45 const gfx::Rect& new_bounds) {
46 ResizeShadow* shadow = GetShadowForWindow(window);
47 if (shadow)
48 shadow->Layout(new_bounds);
49}
50
51void ResizeShadowController::OnWindowDestroyed(aura::Window* window) {
52 window_shadows_.erase(window);
53}
54
55ResizeShadow* 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.
59 shadow->Init(window);
60 // Ensure initial bounds are correct.
61 shadow->Layout(window->bounds());
62 // Watch for bounds changes.
63 window->AddObserver(this);
64 return shadow.get();
65}
66
67ResizeShadow* ResizeShadowController::GetShadowForWindow(aura::Window* window) {
68 WindowShadowMap::const_iterator it = window_shadows_.find(window);
69 return it != window_shadows_.end() ? it->second.get() : NULL;
70}
71
Torne (Richard Coles)58218062012-11-14 11:43:16 +000072} // namespace ash