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/shell.h" | 10 #include "ash/shell.h" |
11 #include "ash/shell_window_ids.h" | 11 #include "ash/shell_window_ids.h" |
12 #include "ash/wm/root_window_layout_manager.h" | |
12 #include "ash/wm/window_animations.h" | 13 #include "ash/wm/window_animations.h" |
13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
14 #include "grit/ui_resources.h" | 15 #include "grit/ui_resources.h" |
15 #include "ui/aura/root_window.h" | 16 #include "ui/aura/root_window.h" |
16 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
17 #include "ui/gfx/canvas.h" | 18 #include "ui/gfx/canvas.h" |
19 #include "ui/gfx/compositor/layer.h" | |
20 #include "ui/gfx/compositor/layer_animation_observer.h" | |
21 #include "ui/gfx/compositor/scoped_layer_animation_settings.h" | |
18 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
19 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
20 | 24 |
21 namespace ash { | 25 namespace ash { |
22 namespace internal { | 26 namespace internal { |
27 namespace { | |
28 | |
29 class ShowWallpaperAnimationObserver : public ui::ImplicitAnimationObserver { | |
30 public: | |
31 explicit ShowWallpaperAnimationObserver(views::Widget* desktop_widget) : | |
flackr
2012/04/20 19:04:51
nit: : goes on next line with desktop_widget_.
bshe
2012/04/20 19:13:58
Done.
| |
32 desktop_widget_(desktop_widget){ | |
33 } | |
flackr
2012/04/20 19:04:51
nit: newline between functions.
bshe
2012/04/20 19:13:58
Done.
| |
34 virtual ~ShowWallpaperAnimationObserver() { | |
35 } | |
36 | |
37 private: | |
38 // Overridden from ui::ImplicitAnimationObserver: | |
39 virtual void OnImplicitAnimationsCompleted() OVERRIDE { | |
40 internal::RootWindowLayoutManager* root_window_layout = | |
41 Shell::GetInstance()->root_window_layout(); | |
42 root_window_layout->SetBackgroundWidget(desktop_widget_); | |
43 delete this; | |
44 } | |
45 | |
46 views::Widget* desktop_widget_; | |
47 | |
48 DISALLOW_COPY_AND_ASSIGN(ShowWallpaperAnimationObserver); | |
49 }; | |
50 | |
51 } // namespace | |
flackr
2012/04/20 19:04:51
nit two spaces after }
bshe
2012/04/20 19:13:58
Done.
| |
23 | 52 |
24 // For our scaling ratios we need to round positive numbers. | 53 // For our scaling ratios we need to round positive numbers. |
25 static int RoundPositive(double x) { | 54 static int RoundPositive(double x) { |
26 return static_cast<int>(floor(x + 0.5)); | 55 return static_cast<int>(floor(x + 0.5)); |
27 } | 56 } |
28 | 57 |
29 //////////////////////////////////////////////////////////////////////////////// | 58 //////////////////////////////////////////////////////////////////////////////// |
30 // DesktopBackgroundView, public: | 59 // DesktopBackgroundView, public: |
31 | 60 |
32 DesktopBackgroundView::DesktopBackgroundView(const SkBitmap& wallpaper, | 61 DesktopBackgroundView::DesktopBackgroundView(const SkBitmap& wallpaper, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 | 118 |
90 bool DesktopBackgroundView::OnMousePressed(const views::MouseEvent& event) { | 119 bool DesktopBackgroundView::OnMousePressed(const views::MouseEvent& event) { |
91 return true; | 120 return true; |
92 } | 121 } |
93 | 122 |
94 void DesktopBackgroundView::OnMouseReleased(const views::MouseEvent& event) { | 123 void DesktopBackgroundView::OnMouseReleased(const views::MouseEvent& event) { |
95 if (event.IsRightMouseButton()) | 124 if (event.IsRightMouseButton()) |
96 Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), event.location()); | 125 Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), event.location()); |
97 } | 126 } |
98 | 127 |
99 views::Widget* CreateDesktopBackground(const SkBitmap& wallpaper, | 128 void CreateDesktopBackground(const SkBitmap& wallpaper, ImageLayout layout) { |
100 ImageLayout layout) { | |
101 views::Widget* desktop_widget = new views::Widget; | 129 views::Widget* desktop_widget = new views::Widget; |
102 views::Widget::InitParams params( | 130 views::Widget::InitParams params( |
103 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 131 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
104 DesktopBackgroundView* view = new DesktopBackgroundView(wallpaper, layout); | 132 DesktopBackgroundView* view = new DesktopBackgroundView(wallpaper, layout); |
105 params.delegate = view; | 133 params.delegate = view; |
106 params.parent = | 134 params.parent = |
107 Shell::GetInstance()->GetContainer( | 135 Shell::GetInstance()->GetContainer( |
108 ash::internal::kShellWindowId_DesktopBackgroundContainer); | 136 ash::internal::kShellWindowId_DesktopBackgroundContainer); |
109 desktop_widget->Init(params); | 137 desktop_widget->Init(params); |
110 desktop_widget->SetContentsView(view); | 138 desktop_widget->SetContentsView(view); |
111 ash::SetWindowVisibilityAnimationType( | 139 ash::SetWindowVisibilityAnimationType( |
112 desktop_widget->GetNativeView(), | 140 desktop_widget->GetNativeView(), |
113 ash::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | 141 ash::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); |
142 ash::SetWindowVisibilityAnimationTransition( | |
143 desktop_widget->GetNativeView(), | |
144 ash::ANIMATE_SHOW); | |
flackr
2012/04/20 19:04:51
nit: only indent 4 spaces.
| |
114 desktop_widget->SetBounds(params.parent->bounds()); | 145 desktop_widget->SetBounds(params.parent->bounds()); |
146 ui::ScopedLayerAnimationSettings settings(desktop_widget->GetNativeView()-> | |
147 layer()->GetAnimator()); | |
148 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); | |
149 settings.AddObserver(new ShowWallpaperAnimationObserver(desktop_widget)); | |
115 desktop_widget->Show(); | 150 desktop_widget->Show(); |
116 desktop_widget->GetNativeView()->SetName("DesktopBackgroundView"); | 151 desktop_widget->GetNativeView()->SetName("DesktopBackgroundView"); |
117 return desktop_widget; | |
118 } | 152 } |
119 | 153 |
120 } // namespace internal | 154 } // namespace internal |
121 } // namespace ash | 155 } // namespace ash |
OLD | NEW |