Mailbox support for texture layers.
[chromium-blink-merge.git] / ash / wm / resize_shadow_controller.cc
blobc8752651bcb06b777c80bab397077d5a0217ebd9
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 {
13 namespace internal {
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);
27 if (!shadow)
28 shadow = CreateShadow(window);
29 shadow->ShowForHitTest(hit_test);
32 void ResizeShadowController::HideShadow(aura::Window* window) {
33 ResizeShadow* shadow = GetShadowForWindow(window);
34 if (shadow)
35 shadow->Hide();
38 void ResizeShadowController::OnWindowBoundsChanged(
39 aura::Window* window,
40 const gfx::Rect& old_bounds,
41 const gfx::Rect& new_bounds) {
42 ResizeShadow* shadow = GetShadowForWindow(window);
43 if (shadow)
44 shadow->Layout(new_bounds);
47 void ResizeShadowController::OnWindowDestroyed(aura::Window* window) {
48 window_shadows_.erase(window);
51 ResizeShadow* ResizeShadowController::CreateShadow(aura::Window* window) {
52 linked_ptr<ResizeShadow> shadow(new ResizeShadow());
53 window_shadows_.insert(std::make_pair(window, shadow));
54 // Attach the layers to this window.
55 shadow->Init(window);
56 // Ensure initial bounds are correct.
57 shadow->Layout(window->bounds());
58 // Watch for bounds changes.
59 window->AddObserver(this);
60 return shadow.get();
63 ResizeShadow* ResizeShadowController::GetShadowForWindow(aura::Window* window) {
64 WindowShadowMap::const_iterator it = window_shadows_.find(window);
65 return it != window_shadows_.end() ? it->second.get() : NULL;
68 } // namespace internal
69 } // namespace ash