| 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) |
| 32 : desktop_widget_(desktop_widget) { |
| 33 } |
| 34 |
| 35 virtual ~ShowWallpaperAnimationObserver() { |
| 36 } |
| 37 |
| 38 private: |
| 39 // Overridden from ui::ImplicitAnimationObserver: |
| 40 virtual void OnImplicitAnimationsCompleted() OVERRIDE { |
| 41 internal::RootWindowLayoutManager* root_window_layout = |
| 42 Shell::GetInstance()->root_window_layout(); |
| 43 root_window_layout->SetBackgroundWidget(desktop_widget_); |
| 44 delete this; |
| 45 } |
| 46 |
| 47 views::Widget* desktop_widget_; |
| 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(ShowWallpaperAnimationObserver); |
| 50 }; |
| 51 |
| 52 } // namespace |
| 23 | 53 |
| 24 // For our scaling ratios we need to round positive numbers. | 54 // For our scaling ratios we need to round positive numbers. |
| 25 static int RoundPositive(double x) { | 55 static int RoundPositive(double x) { |
| 26 return static_cast<int>(floor(x + 0.5)); | 56 return static_cast<int>(floor(x + 0.5)); |
| 27 } | 57 } |
| 28 | 58 |
| 29 //////////////////////////////////////////////////////////////////////////////// | 59 //////////////////////////////////////////////////////////////////////////////// |
| 30 // DesktopBackgroundView, public: | 60 // DesktopBackgroundView, public: |
| 31 | 61 |
| 32 DesktopBackgroundView::DesktopBackgroundView(const SkBitmap& wallpaper, | 62 DesktopBackgroundView::DesktopBackgroundView(const SkBitmap& wallpaper, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 119 |
| 90 bool DesktopBackgroundView::OnMousePressed(const views::MouseEvent& event) { | 120 bool DesktopBackgroundView::OnMousePressed(const views::MouseEvent& event) { |
| 91 return true; | 121 return true; |
| 92 } | 122 } |
| 93 | 123 |
| 94 void DesktopBackgroundView::OnMouseReleased(const views::MouseEvent& event) { | 124 void DesktopBackgroundView::OnMouseReleased(const views::MouseEvent& event) { |
| 95 if (event.IsRightMouseButton()) | 125 if (event.IsRightMouseButton()) |
| 96 Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), event.location()); | 126 Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), event.location()); |
| 97 } | 127 } |
| 98 | 128 |
| 99 views::Widget* CreateDesktopBackground(const SkBitmap& wallpaper, | 129 void CreateDesktopBackground(const SkBitmap& wallpaper, ImageLayout layout) { |
| 100 ImageLayout layout) { | |
| 101 views::Widget* desktop_widget = new views::Widget; | 130 views::Widget* desktop_widget = new views::Widget; |
| 102 views::Widget::InitParams params( | 131 views::Widget::InitParams params( |
| 103 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 132 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 104 DesktopBackgroundView* view = new DesktopBackgroundView(wallpaper, layout); | 133 DesktopBackgroundView* view = new DesktopBackgroundView(wallpaper, layout); |
| 105 params.delegate = view; | 134 params.delegate = view; |
| 106 params.parent = | 135 params.parent = |
| 107 Shell::GetInstance()->GetContainer( | 136 Shell::GetInstance()->GetContainer( |
| 108 ash::internal::kShellWindowId_DesktopBackgroundContainer); | 137 ash::internal::kShellWindowId_DesktopBackgroundContainer); |
| 109 desktop_widget->Init(params); | 138 desktop_widget->Init(params); |
| 110 desktop_widget->SetContentsView(view); | 139 desktop_widget->SetContentsView(view); |
| 111 ash::SetWindowVisibilityAnimationType( | 140 ash::SetWindowVisibilityAnimationType( |
| 112 desktop_widget->GetNativeView(), | 141 desktop_widget->GetNativeView(), |
| 113 ash::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | 142 ash::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); |
| 143 ash::SetWindowVisibilityAnimationTransition( |
| 144 desktop_widget->GetNativeView(), |
| 145 ash::ANIMATE_SHOW); |
| 114 desktop_widget->SetBounds(params.parent->bounds()); | 146 desktop_widget->SetBounds(params.parent->bounds()); |
| 147 ui::ScopedLayerAnimationSettings settings(desktop_widget->GetNativeView()-> |
| 148 layer()->GetAnimator()); |
| 149 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); |
| 150 settings.AddObserver(new ShowWallpaperAnimationObserver(desktop_widget)); |
| 115 desktop_widget->Show(); | 151 desktop_widget->Show(); |
| 116 desktop_widget->GetNativeView()->SetName("DesktopBackgroundView"); | 152 desktop_widget->GetNativeView()->SetName("DesktopBackgroundView"); |
| 117 return desktop_widget; | |
| 118 } | 153 } |
| 119 | 154 |
| 120 } // namespace internal | 155 } // namespace internal |
| 121 } // namespace ash | 156 } // namespace ash |
| OLD | NEW |