OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/desktop_background/desktop_background_view.h" | 5 #include "ash/desktop_background/desktop_background_view.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "ash/ash_export.h" | 9 #include "ash/ash_export.h" |
10 #include "ash/desktop_background/desktop_background_controller.h" | 10 #include "ash/desktop_background/desktop_background_controller.h" |
11 #include "ash/desktop_background/desktop_background_widget_controller.h" | 11 #include "ash/desktop_background/desktop_background_widget_controller.h" |
12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
13 #include "ash/shell_window_ids.h" | 13 #include "ash/shell_window_ids.h" |
14 #include "ash/wm/window_animations.h" | 14 #include "ash/wm/window_animations.h" |
15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "grit/ui_resources.h" | 17 #include "grit/ui_resources.h" |
18 #include "ui/aura/root_window.h" | 18 #include "ui/aura/root_window.h" |
19 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
20 #include "ui/compositor/layer.h" | 20 #include "ui/compositor/layer.h" |
21 #include "ui/compositor/layer_animation_observer.h" | 21 #include "ui/compositor/layer_animation_observer.h" |
22 #include "ui/compositor/scoped_layer_animation_settings.h" | 22 #include "ui/compositor/scoped_layer_animation_settings.h" |
23 #include "ui/gfx/canvas.h" | 23 #include "ui/gfx/canvas.h" |
24 #include "ui/gfx/image/image.h" | 24 #include "ui/gfx/image/image.h" |
25 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
| 26 #include "ui/views/widget/widget_delegate.h" |
26 | 27 |
27 namespace ash { | 28 namespace ash { |
28 namespace internal { | 29 namespace internal { |
29 namespace { | 30 namespace { |
30 | 31 |
| 32 class DesktopBackgroundViewCleanup : public views::WidgetDelegate { |
| 33 public: |
| 34 DesktopBackgroundViewCleanup(views::Widget* widget, |
| 35 aura::RootWindow* root_window) |
| 36 : widget_(widget_), |
| 37 root_window_(root_window) { |
| 38 } |
| 39 |
| 40 // Called when the window closes. The delegate MUST NOT delete itself during |
| 41 // this call, since it can be called afterwards. See DeleteDelegate(). |
| 42 virtual void WindowClosing() OVERRIDE { |
| 43 DesktopBackgroundController* controller = ash::Shell::GetInstance()-> |
| 44 desktop_background_controller(); |
| 45 controller->CleanupView(root_window_); |
| 46 } |
| 47 |
| 48 virtual const views::Widget* GetWidget() OVERRIDE const { |
| 49 return widget_; |
| 50 } |
| 51 |
| 52 virtual views::Widget* GetWidget() OVERRIDE { |
| 53 return widget_; |
| 54 } |
| 55 |
| 56 virtual void DeleteDelegate() OVERRIDE { |
| 57 delete this; |
| 58 } |
| 59 |
| 60 private: |
| 61 views::Widget* widget_; |
| 62 aura::RootWindow* root_window_; |
| 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundViewCleanup); |
| 65 }; |
| 66 |
31 class ShowWallpaperAnimationObserver : public ui::ImplicitAnimationObserver { | 67 class ShowWallpaperAnimationObserver : public ui::ImplicitAnimationObserver { |
32 public: | 68 public: |
33 ShowWallpaperAnimationObserver(aura::RootWindow* root_window, | 69 ShowWallpaperAnimationObserver(aura::RootWindow* root_window, |
34 int container_id, | 70 int container_id, |
35 views::Widget* desktop_widget) | 71 views::Widget* desktop_widget) |
36 : root_window_(root_window), | 72 : root_window_(root_window), |
37 container_id_(container_id), | 73 container_id_(container_id), |
38 desktop_widget_(desktop_widget) { | 74 desktop_widget_(desktop_widget) { |
39 } | 75 } |
40 | 76 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 void DesktopBackgroundView::ShowContextMenuForView(views::View* source, | 178 void DesktopBackgroundView::ShowContextMenuForView(views::View* source, |
143 const gfx::Point& point) { | 179 const gfx::Point& point) { |
144 Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), point); | 180 Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), point); |
145 } | 181 } |
146 | 182 |
147 views::Widget* CreateDesktopBackground(aura::RootWindow* root_window, | 183 views::Widget* CreateDesktopBackground(aura::RootWindow* root_window, |
148 int container_id) { | 184 int container_id) { |
149 DesktopBackgroundController* controller = ash::Shell::GetInstance()-> | 185 DesktopBackgroundController* controller = ash::Shell::GetInstance()-> |
150 desktop_background_controller(); | 186 desktop_background_controller(); |
151 views::Widget* desktop_widget = new views::Widget; | 187 views::Widget* desktop_widget = new views::Widget; |
| 188 DesktopBackgroundViewCleanup* cleanup; |
| 189 cleanup = new DesktopBackgroundViewCleanup(desktop_widget, root_window); |
152 views::Widget::InitParams params( | 190 views::Widget::InitParams params( |
153 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 191 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
154 DesktopBackgroundView* view = new DesktopBackgroundView(); | 192 DesktopBackgroundView* view = new DesktopBackgroundView(); |
155 params.delegate = view; | 193 params.delegate = view; |
156 if (controller->GetWallpaper().isNull()) | 194 if (controller->GetWallpaper().isNull()) |
157 params.transparent = true; | 195 params.transparent = true; |
| 196 params.delegate = cleanup; |
158 params.parent = root_window->GetChildById(container_id); | 197 params.parent = root_window->GetChildById(container_id); |
159 desktop_widget->Init(params); | 198 desktop_widget->Init(params); |
160 desktop_widget->SetContentsView(view); | 199 desktop_widget->SetContentsView(view); |
161 ash::WindowVisibilityAnimationType animation_type = | 200 ash::WindowVisibilityAnimationType animation_type = |
162 ash::Shell::GetInstance()->user_wallpaper_delegate()->GetAnimationType(); | 201 ash::Shell::GetInstance()->user_wallpaper_delegate()->GetAnimationType(); |
163 ash::SetWindowVisibilityAnimationType(desktop_widget->GetNativeView(), | 202 ash::SetWindowVisibilityAnimationType(desktop_widget->GetNativeView(), |
164 animation_type); | 203 animation_type); |
165 // Disable animation when creating the first widget. Otherwise, wallpaper | 204 // Disable animation when creating the first widget. Otherwise, wallpaper |
166 // will animate from a white screen. Note that boot animation is different. | 205 // will animate from a white screen. Note that boot animation is different. |
167 // It animates from a white background. | 206 // It animates from a white background. |
(...skipping 12 matching lines...) Expand all Loading... |
180 settings.AddObserver(new ShowWallpaperAnimationObserver(root_window, | 219 settings.AddObserver(new ShowWallpaperAnimationObserver(root_window, |
181 container_id, | 220 container_id, |
182 desktop_widget)); | 221 desktop_widget)); |
183 desktop_widget->Show(); | 222 desktop_widget->Show(); |
184 desktop_widget->GetNativeView()->SetName("DesktopBackgroundView"); | 223 desktop_widget->GetNativeView()->SetName("DesktopBackgroundView"); |
185 return desktop_widget; | 224 return desktop_widget; |
186 } | 225 } |
187 | 226 |
188 } // namespace internal | 227 } // namespace internal |
189 } // namespace ash | 228 } // namespace ash |
OLD | NEW |