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" | |
27 | 26 |
28 namespace ash { | 27 namespace ash { |
29 namespace internal { | 28 namespace internal { |
30 namespace { | 29 namespace { |
31 | 30 |
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 | |
67 class ShowWallpaperAnimationObserver : public ui::ImplicitAnimationObserver { | 31 class ShowWallpaperAnimationObserver : public ui::ImplicitAnimationObserver { |
68 public: | 32 public: |
69 ShowWallpaperAnimationObserver(aura::RootWindow* root_window, | 33 ShowWallpaperAnimationObserver(aura::RootWindow* root_window, |
70 int container_id, | 34 int container_id, |
71 views::Widget* desktop_widget) | 35 views::Widget* desktop_widget) |
72 : root_window_(root_window), | 36 : root_window_(root_window), |
73 container_id_(container_id), | 37 container_id_(container_id), |
74 desktop_widget_(desktop_widget) { | 38 desktop_widget_(desktop_widget) { |
75 } | 39 } |
76 | 40 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 void DesktopBackgroundView::ShowContextMenuForView(views::View* source, | 142 void DesktopBackgroundView::ShowContextMenuForView(views::View* source, |
179 const gfx::Point& point) { | 143 const gfx::Point& point) { |
180 Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), point); | 144 Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), point); |
181 } | 145 } |
182 | 146 |
183 views::Widget* CreateDesktopBackground(aura::RootWindow* root_window, | 147 views::Widget* CreateDesktopBackground(aura::RootWindow* root_window, |
184 int container_id) { | 148 int container_id) { |
185 DesktopBackgroundController* controller = ash::Shell::GetInstance()-> | 149 DesktopBackgroundController* controller = ash::Shell::GetInstance()-> |
186 desktop_background_controller(); | 150 desktop_background_controller(); |
187 views::Widget* desktop_widget = new views::Widget; | 151 views::Widget* desktop_widget = new views::Widget; |
188 DesktopBackgroundViewCleanup* cleanup; | |
189 cleanup = new DesktopBackgroundViewCleanup(desktop_widget, root_window); | |
190 views::Widget::InitParams params( | 152 views::Widget::InitParams params( |
191 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 153 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
192 DesktopBackgroundView* view = new DesktopBackgroundView(); | 154 DesktopBackgroundView* view = new DesktopBackgroundView(); |
193 params.delegate = view; | 155 params.delegate = view; |
194 if (controller->GetWallpaper().isNull()) | 156 if (controller->GetWallpaper().isNull()) |
195 params.transparent = true; | 157 params.transparent = true; |
196 params.delegate = cleanup; | |
197 params.parent = root_window->GetChildById(container_id); | 158 params.parent = root_window->GetChildById(container_id); |
198 desktop_widget->Init(params); | 159 desktop_widget->Init(params); |
199 desktop_widget->SetContentsView(view); | 160 desktop_widget->SetContentsView(view); |
200 ash::WindowVisibilityAnimationType animation_type = | 161 ash::WindowVisibilityAnimationType animation_type = |
201 ash::Shell::GetInstance()->user_wallpaper_delegate()->GetAnimationType(); | 162 ash::Shell::GetInstance()->user_wallpaper_delegate()->GetAnimationType(); |
202 ash::SetWindowVisibilityAnimationType(desktop_widget->GetNativeView(), | 163 ash::SetWindowVisibilityAnimationType(desktop_widget->GetNativeView(), |
203 animation_type); | 164 animation_type); |
204 // Disable animation when creating the first widget. Otherwise, wallpaper | 165 // Disable animation when creating the first widget. Otherwise, wallpaper |
205 // will animate from a white screen. Note that boot animation is different. | 166 // will animate from a white screen. Note that boot animation is different. |
206 // It animates from a white background. | 167 // It animates from a white background. |
(...skipping 12 matching lines...) Expand all Loading... |
219 settings.AddObserver(new ShowWallpaperAnimationObserver(root_window, | 180 settings.AddObserver(new ShowWallpaperAnimationObserver(root_window, |
220 container_id, | 181 container_id, |
221 desktop_widget)); | 182 desktop_widget)); |
222 desktop_widget->Show(); | 183 desktop_widget->Show(); |
223 desktop_widget->GetNativeView()->SetName("DesktopBackgroundView"); | 184 desktop_widget->GetNativeView()->SetName("DesktopBackgroundView"); |
224 return desktop_widget; | 185 return desktop_widget; |
225 } | 186 } |
226 | 187 |
227 } // namespace internal | 188 } // namespace internal |
228 } // namespace ash | 189 } // namespace ash |
OLD | NEW |