OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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 #ifndef UI_AURA_SHELL_SHADOW_CONTROLLER_H_ | |
6 #define UI_AURA_SHELL_SHADOW_CONTROLLER_H_ | |
7 #pragma once | |
8 | |
9 #include <map> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/compiler_specific.h" | |
13 #include "base/memory/linked_ptr.h" | |
14 #include "ui/aura/root_window_observer.h" | |
15 #include "ui/aura/window_observer.h" | |
16 #include "ui/aura_shell/aura_shell_export.h" | |
17 | |
18 namespace aura { | |
19 class Window; | |
20 } | |
21 namespace gfx { | |
22 class Rect; | |
23 } | |
24 | |
25 namespace aura_shell { | |
26 namespace internal { | |
27 | |
28 class Shadow; | |
29 | |
30 // ShadowController observes changes to windows and creates and updates drop | |
31 // shadows as needed. | |
32 class AURA_SHELL_EXPORT ShadowController : public aura::RootWindowObserver, | |
33 public aura::WindowObserver { | |
34 public: | |
35 class TestApi { | |
36 public: | |
37 explicit TestApi(ShadowController* controller) : controller_(controller) {} | |
38 ~TestApi() {} | |
39 | |
40 Shadow* GetShadowForWindow(aura::Window* window) { | |
41 return controller_->GetShadowForWindow(window); | |
42 } | |
43 | |
44 private: | |
45 ShadowController* controller_; // not owned | |
46 | |
47 DISALLOW_COPY_AND_ASSIGN(TestApi); | |
48 }; | |
49 | |
50 explicit ShadowController(); | |
51 virtual ~ShadowController(); | |
52 | |
53 // aura::RootWindowObserver override: | |
54 virtual void OnWindowInitialized(aura::Window* window) OVERRIDE; | |
55 | |
56 // aura::WindowObserver overrides: | |
57 virtual void OnWindowPropertyChanged( | |
58 aura::Window* window, const char* name, void* old) OVERRIDE; | |
59 virtual void OnWindowBoundsChanged( | |
60 aura::Window* window, const gfx::Rect& bounds) OVERRIDE; | |
61 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE; | |
62 | |
63 private: | |
64 typedef std::map<aura::Window*, linked_ptr<Shadow> > WindowShadowMap; | |
65 | |
66 // Checks if |window| is visible and contains a property requesting a shadow. | |
67 bool ShouldShowShadowForWindow(aura::Window* window) const; | |
68 | |
69 // Returns |window|'s shadow from |window_shadows_|, or NULL if no shadow | |
70 // exists. | |
71 Shadow* GetShadowForWindow(aura::Window* window); | |
72 | |
73 // Shows or hides |window|'s shadow as needed (creating the shadow if | |
74 // necessary). | |
75 void HandlePossibleShadowVisibilityChange(aura::Window* window); | |
76 | |
77 // Creates a new shadow for |window| and stores it in |window_shadows_|. The | |
78 // shadow's bounds are initialized and it is added to the window's layer. | |
79 void CreateShadowForWindow(aura::Window* window); | |
80 | |
81 WindowShadowMap window_shadows_; | |
82 | |
83 DISALLOW_COPY_AND_ASSIGN(ShadowController); | |
84 }; | |
85 | |
86 } // namepsace aura_shell | |
87 } // namepsace internal | |
88 | |
89 #endif // UI_AURA_SHELL_SHADOW_CONTROLLER_H_ | |
OLD | NEW |