| 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/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/shell_window_ids.h" | 12 #include "ash/shell_window_ids.h" |
| 13 #include "ash/wm/root_window_layout_manager.h" | |
| 14 #include "ash/wm/window_animations.h" | 13 #include "ash/wm/window_animations.h" |
| 15 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 16 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 17 #include "grit/ui_resources.h" | 16 #include "grit/ui_resources.h" |
| 18 #include "ui/aura/root_window.h" | 17 #include "ui/aura/root_window.h" |
| 19 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 20 #include "ui/compositor/layer.h" | 19 #include "ui/compositor/layer.h" |
| 21 #include "ui/compositor/layer_animation_observer.h" | 20 #include "ui/compositor/layer_animation_observer.h" |
| 22 #include "ui/compositor/scoped_layer_animation_settings.h" | 21 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 23 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
| 24 #include "ui/gfx/image/image.h" | 23 #include "ui/gfx/image/image.h" |
| 25 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
| 26 | 25 |
| 27 namespace ash { | 26 namespace ash { |
| 28 namespace internal { | 27 namespace internal { |
| 29 namespace { | 28 namespace { |
| 30 | 29 |
| 31 class ShowWallpaperAnimationObserver : public ui::ImplicitAnimationObserver { | 30 class ShowWallpaperAnimationObserver : public ui::ImplicitAnimationObserver { |
| 32 public: | 31 public: |
| 33 ShowWallpaperAnimationObserver(aura::RootWindow* root_window, | 32 ShowWallpaperAnimationObserver(aura::RootWindow* root_window, |
| 33 int container_id, |
| 34 views::Widget* desktop_widget) | 34 views::Widget* desktop_widget) |
| 35 : root_window_(root_window), | 35 : root_window_(root_window), |
| 36 container_id_(container_id), |
| 36 desktop_widget_(desktop_widget) { | 37 desktop_widget_(desktop_widget) { |
| 37 } | 38 } |
| 38 | 39 |
| 39 virtual ~ShowWallpaperAnimationObserver() { | 40 virtual ~ShowWallpaperAnimationObserver() { |
| 40 } | 41 } |
| 41 | 42 |
| 42 private: | 43 private: |
| 43 // Overridden from ui::ImplicitAnimationObserver: | 44 // Overridden from ui::ImplicitAnimationObserver: |
| 44 virtual void OnImplicitAnimationsCompleted() OVERRIDE { | 45 virtual void OnImplicitAnimationsCompleted() OVERRIDE { |
| 45 internal::RootWindowLayoutManager* root_window_layout = | |
| 46 static_cast<internal::RootWindowLayoutManager*>( | |
| 47 root_window_->layout_manager()); | |
| 48 root_window_layout->SetBackgroundWidget(desktop_widget_); | |
| 49 | |
| 50 ash::Shell::GetInstance()-> | 46 ash::Shell::GetInstance()-> |
| 51 user_wallpaper_delegate()->OnWallpaperAnimationFinished(); | 47 user_wallpaper_delegate()->OnWallpaperAnimationFinished(); |
| 52 | 48 |
| 53 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 49 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 54 } | 50 } |
| 55 | 51 |
| 56 aura::RootWindow* root_window_; | 52 aura::RootWindow* root_window_; |
| 53 int container_id_; |
| 57 views::Widget* desktop_widget_; | 54 views::Widget* desktop_widget_; |
| 58 | 55 |
| 59 DISALLOW_COPY_AND_ASSIGN(ShowWallpaperAnimationObserver); | 56 DISALLOW_COPY_AND_ASSIGN(ShowWallpaperAnimationObserver); |
| 60 }; | 57 }; |
| 61 | 58 |
| 62 } // namespace | 59 } // namespace |
| 63 | 60 |
| 64 // For our scaling ratios we need to round positive numbers. | 61 // For our scaling ratios we need to round positive numbers. |
| 65 static int RoundPositive(double x) { | 62 static int RoundPositive(double x) { |
| 66 return static_cast<int>(floor(x + 0.5)); | 63 return static_cast<int>(floor(x + 0.5)); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 128 |
| 132 bool DesktopBackgroundView::OnMousePressed(const views::MouseEvent& event) { | 129 bool DesktopBackgroundView::OnMousePressed(const views::MouseEvent& event) { |
| 133 return true; | 130 return true; |
| 134 } | 131 } |
| 135 | 132 |
| 136 void DesktopBackgroundView::ShowContextMenuForView(views::View* source, | 133 void DesktopBackgroundView::ShowContextMenuForView(views::View* source, |
| 137 const gfx::Point& point) { | 134 const gfx::Point& point) { |
| 138 Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), point); | 135 Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), point); |
| 139 } | 136 } |
| 140 | 137 |
| 141 void CreateDesktopBackground(aura::RootWindow* root_window) { | 138 views::Widget* CreateDesktopBackground(aura::RootWindow* root_window, |
| 139 int container_id) { |
| 142 DesktopBackgroundController* controller = ash::Shell::GetInstance()-> | 140 DesktopBackgroundController* controller = ash::Shell::GetInstance()-> |
| 143 desktop_background_controller(); | 141 desktop_background_controller(); |
| 144 views::Widget* desktop_widget = new views::Widget; | 142 views::Widget* desktop_widget = new views::Widget; |
| 145 views::Widget::InitParams params( | 143 views::Widget::InitParams params( |
| 146 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 144 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 147 DesktopBackgroundView* view = new DesktopBackgroundView(); | 145 DesktopBackgroundView* view = new DesktopBackgroundView(); |
| 148 params.delegate = view; | 146 params.delegate = view; |
| 149 if (controller->GetWallpaper().empty()) | 147 if (controller->GetWallpaper().empty()) |
| 150 params.transparent = true; | 148 params.transparent = true; |
| 151 params.parent = root_window->GetChildById( | 149 params.parent = root_window->GetChildById(container_id); |
| 152 ash::internal::kShellWindowId_DesktopBackgroundContainer); | |
| 153 desktop_widget->Init(params); | 150 desktop_widget->Init(params); |
| 154 desktop_widget->SetContentsView(view); | 151 desktop_widget->SetContentsView(view); |
| 155 ash::WindowVisibilityAnimationType animation_type = | 152 ash::WindowVisibilityAnimationType animation_type = |
| 156 ash::Shell::GetInstance()->user_wallpaper_delegate()->GetAnimationType(); | 153 ash::Shell::GetInstance()->user_wallpaper_delegate()->GetAnimationType(); |
| 157 ash::SetWindowVisibilityAnimationType(desktop_widget->GetNativeView(), | 154 ash::SetWindowVisibilityAnimationType(desktop_widget->GetNativeView(), |
| 158 animation_type); | 155 animation_type); |
| 159 ash::SetWindowVisibilityAnimationTransition(desktop_widget->GetNativeView(), | 156 ash::SetWindowVisibilityAnimationTransition(desktop_widget->GetNativeView(), |
| 160 ash::ANIMATE_SHOW); | 157 ash::ANIMATE_SHOW); |
| 161 desktop_widget->SetBounds(params.parent->bounds()); | 158 desktop_widget->SetBounds(params.parent->bounds()); |
| 162 ui::ScopedLayerAnimationSettings settings( | 159 ui::ScopedLayerAnimationSettings settings( |
| 163 desktop_widget->GetNativeView()->layer()->GetAnimator()); | 160 desktop_widget->GetNativeView()->layer()->GetAnimator()); |
| 164 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); | 161 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); |
| 165 settings.AddObserver(new ShowWallpaperAnimationObserver(root_window, | 162 settings.AddObserver(new ShowWallpaperAnimationObserver(root_window, |
| 163 container_id, |
| 166 desktop_widget)); | 164 desktop_widget)); |
| 167 desktop_widget->Show(); | 165 desktop_widget->Show(); |
| 168 desktop_widget->GetNativeView()->SetName("DesktopBackgroundView"); | 166 desktop_widget->GetNativeView()->SetName("DesktopBackgroundView"); |
| 167 return desktop_widget; |
| 169 } | 168 } |
| 170 | 169 |
| 171 } // namespace internal | 170 } // namespace internal |
| 172 } // namespace ash | 171 } // namespace ash |
| OLD | NEW |