Roll src/third_party/skia ff271c2:b679ca8
[chromium-blink-merge.git] / ash / wm / resize_shadow_controller.cc
blobe5ed6c329b2b6b1c7a614b73a9bda8a4a2b04a08
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"
7 #include <utility>
9 #include "ash/wm/resize_shadow.h"
10 #include "ui/aura/window.h"
12 namespace ash {
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);
26 if (!shadow)
27 shadow = CreateShadow(window);
28 shadow->ShowForHitTest(hit_test);
31 void ResizeShadowController::HideShadow(aura::Window* window) {
32 ResizeShadow* shadow = GetShadowForWindow(window);
33 if (shadow)
34 shadow->Hide();
37 ResizeShadow* ResizeShadowController::GetShadowForWindowForTest(
38 aura::Window* window) {
39 return GetShadowForWindow(window);
42 void 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);
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.
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();
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;
72 } // namespace ash