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 | |
Nikita (slow)
2012/08/28 17:42:38
nit: drop empty line
| |
35 DesktopBackgroundViewCleanup(views::Widget* widget, | |
36 aura::RootWindow* root_window) | |
37 : widget_(widget_), | |
38 root_window_(root_window) { | |
39 } | |
40 | |
41 | |
42 // Called when the window closes. The delegate MUST NOT delete itself during | |
43 // this call, since it can be called afterwards. See DeleteDelegate(). | |
44 virtual void WindowClosing() OVERRIDE { | |
45 DesktopBackgroundController* controller = ash::Shell::GetInstance()-> | |
46 desktop_background_controller(); | |
47 controller->CleanUpView(root_window_); | |
48 } | |
49 | |
50 virtual const views::Widget* GetWidget() OVERRIDE const { | |
51 return widget_; | |
52 } | |
53 | |
54 virtual views::Widget* GetWidget() OVERRIDE { | |
55 return widget_; | |
56 } | |
57 | |
58 virtual void DeleteDelegate() OVERRIDE { | |
59 delete this; | |
60 } | |
61 | |
62 private: | |
63 views::Widget* widget_; | |
64 aura::RootWindow* root_window_; | |
65 | |
66 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundViewCleanup); | |
67 }; | |
68 | |
31 class ShowWallpaperAnimationObserver : public ui::ImplicitAnimationObserver { | 69 class ShowWallpaperAnimationObserver : public ui::ImplicitAnimationObserver { |
32 public: | 70 public: |
33 ShowWallpaperAnimationObserver(aura::RootWindow* root_window, | 71 ShowWallpaperAnimationObserver(aura::RootWindow* root_window, |
34 int container_id, | 72 int container_id, |
35 views::Widget* desktop_widget) | 73 views::Widget* desktop_widget) |
36 : root_window_(root_window), | 74 : root_window_(root_window), |
37 container_id_(container_id), | 75 container_id_(container_id), |
38 desktop_widget_(desktop_widget) { | 76 desktop_widget_(desktop_widget) { |
39 } | 77 } |
40 | 78 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 void DesktopBackgroundView::ShowContextMenuForView(views::View* source, | 180 void DesktopBackgroundView::ShowContextMenuForView(views::View* source, |
143 const gfx::Point& point) { | 181 const gfx::Point& point) { |
144 Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), point); | 182 Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), point); |
145 } | 183 } |
146 | 184 |
147 views::Widget* CreateDesktopBackground(aura::RootWindow* root_window, | 185 views::Widget* CreateDesktopBackground(aura::RootWindow* root_window, |
148 int container_id) { | 186 int container_id) { |
149 DesktopBackgroundController* controller = ash::Shell::GetInstance()-> | 187 DesktopBackgroundController* controller = ash::Shell::GetInstance()-> |
150 desktop_background_controller(); | 188 desktop_background_controller(); |
151 views::Widget* desktop_widget = new views::Widget; | 189 views::Widget* desktop_widget = new views::Widget; |
190 DesktopBackgroundViewCleanup* cleanup; | |
191 cleanup = new DesktopBackgroundViewCleanup(desktop_widget, root_window); | |
152 views::Widget::InitParams params( | 192 views::Widget::InitParams params( |
153 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 193 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
154 DesktopBackgroundView* view = new DesktopBackgroundView(); | 194 DesktopBackgroundView* view = new DesktopBackgroundView(); |
155 params.delegate = view; | 195 params.delegate = view; |
156 if (controller->GetWallpaper().isNull()) | 196 if (controller->GetWallpaper().isNull()) |
157 params.transparent = true; | 197 params.transparent = true; |
198 params.delegate = cleanup; | |
158 params.parent = root_window->GetChildById(container_id); | 199 params.parent = root_window->GetChildById(container_id); |
159 desktop_widget->Init(params); | 200 desktop_widget->Init(params); |
160 desktop_widget->SetContentsView(view); | 201 desktop_widget->SetContentsView(view); |
161 ash::WindowVisibilityAnimationType animation_type = | 202 ash::WindowVisibilityAnimationType animation_type = |
162 ash::Shell::GetInstance()->user_wallpaper_delegate()->GetAnimationType(); | 203 ash::Shell::GetInstance()->user_wallpaper_delegate()->GetAnimationType(); |
163 ash::SetWindowVisibilityAnimationType(desktop_widget->GetNativeView(), | 204 ash::SetWindowVisibilityAnimationType(desktop_widget->GetNativeView(), |
164 animation_type); | 205 animation_type); |
165 // Disable animation when creating the first widget. Otherwise, wallpaper | 206 // Disable animation when creating the first widget. Otherwise, wallpaper |
166 // will animate from a white screen. Note that boot animation is different. | 207 // will animate from a white screen. Note that boot animation is different. |
167 // It animates from a white background. | 208 // It animates from a white background. |
(...skipping 12 matching lines...) Expand all Loading... | |
180 settings.AddObserver(new ShowWallpaperAnimationObserver(root_window, | 221 settings.AddObserver(new ShowWallpaperAnimationObserver(root_window, |
181 container_id, | 222 container_id, |
182 desktop_widget)); | 223 desktop_widget)); |
183 desktop_widget->Show(); | 224 desktop_widget->Show(); |
184 desktop_widget->GetNativeView()->SetName("DesktopBackgroundView"); | 225 desktop_widget->GetNativeView()->SetName("DesktopBackgroundView"); |
185 return desktop_widget; | 226 return desktop_widget; |
186 } | 227 } |
187 | 228 |
188 } // namespace internal | 229 } // namespace internal |
189 } // namespace ash | 230 } // namespace ash |
OLD | NEW |