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" |
(...skipping 10 matching lines...) Expand all Loading... |
21 namespace internal { | 21 namespace internal { |
22 | 22 |
23 // For our scaling ratios we need to round positive numbers. | 23 // For our scaling ratios we need to round positive numbers. |
24 static int RoundPositive(double x) { | 24 static int RoundPositive(double x) { |
25 return static_cast<int>(floor(x + 0.5)); | 25 return static_cast<int>(floor(x + 0.5)); |
26 } | 26 } |
27 | 27 |
28 //////////////////////////////////////////////////////////////////////////////// | 28 //////////////////////////////////////////////////////////////////////////////// |
29 // DesktopBackgroundView, public: | 29 // DesktopBackgroundView, public: |
30 | 30 |
31 DesktopBackgroundView::DesktopBackgroundView() { | 31 DesktopBackgroundView::DesktopBackgroundView(const SkBitmap& wallpaper) { |
32 wallpaper_ = *ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 32 wallpaper_ = wallpaper; |
33 IDR_AURA_WALLPAPER_1).ToSkBitmap(); | |
34 wallpaper_.buildMipMap(false); | 33 wallpaper_.buildMipMap(false); |
35 } | 34 } |
36 | 35 |
37 DesktopBackgroundView::~DesktopBackgroundView() { | 36 DesktopBackgroundView::~DesktopBackgroundView() { |
38 } | 37 } |
39 | 38 |
| 39 void DesktopBackgroundView::SetWallpaper(const SkBitmap& wallpaper) { |
| 40 wallpaper_ = wallpaper; |
| 41 wallpaper_.buildMipMap(false); |
| 42 SchedulePaint(); |
| 43 } |
| 44 |
40 //////////////////////////////////////////////////////////////////////////////// | 45 //////////////////////////////////////////////////////////////////////////////// |
41 // DesktopBackgroundView, views::View overrides: | 46 // DesktopBackgroundView, views::View overrides: |
42 | 47 |
43 void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) { | 48 void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) { |
44 // Scale the image while maintaining the aspect ratio, cropping as | 49 // Scale the image while maintaining the aspect ratio, cropping as |
45 // necessary to fill the background. Ideally the image should be larger | 50 // necessary to fill the background. Ideally the image should be larger |
46 // than the largest display supported, if not we will center it rather than | 51 // than the largest display supported, if not we will center it rather than |
47 // streching to avoid upsampling artifacts (Note that we could tile too, but | 52 // streching to avoid upsampling artifacts (Note that we could tile too, but |
48 // decided not to do this at the moment). | 53 // decided not to do this at the moment). |
49 gfx::Rect wallpaper_rect(0, 0, wallpaper_.width(), wallpaper_.height()); | 54 gfx::Rect wallpaper_rect(0, 0, wallpaper_.width(), wallpaper_.height()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 86 |
82 bool DesktopBackgroundView::OnMousePressed(const views::MouseEvent& event) { | 87 bool DesktopBackgroundView::OnMousePressed(const views::MouseEvent& event) { |
83 return true; | 88 return true; |
84 } | 89 } |
85 | 90 |
86 void DesktopBackgroundView::OnMouseReleased(const views::MouseEvent& event) { | 91 void DesktopBackgroundView::OnMouseReleased(const views::MouseEvent& event) { |
87 if (event.IsRightMouseButton()) | 92 if (event.IsRightMouseButton()) |
88 Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), event.location()); | 93 Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), event.location()); |
89 } | 94 } |
90 | 95 |
91 views::Widget* CreateDesktopBackground() { | 96 views::Widget* CreateDesktopBackground(const SkBitmap& wallpaper) { |
92 views::Widget* desktop_widget = new views::Widget; | 97 views::Widget* desktop_widget = new views::Widget; |
93 views::Widget::InitParams params( | 98 views::Widget::InitParams params( |
94 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 99 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
95 DesktopBackgroundView* view = new DesktopBackgroundView; | 100 DesktopBackgroundView* view = new DesktopBackgroundView(wallpaper); |
96 params.delegate = view; | 101 params.delegate = view; |
97 params.parent = | 102 params.parent = |
98 Shell::GetInstance()->GetContainer( | 103 Shell::GetInstance()->GetContainer( |
99 ash::internal::kShellWindowId_DesktopBackgroundContainer); | 104 ash::internal::kShellWindowId_DesktopBackgroundContainer); |
100 desktop_widget->Init(params); | 105 desktop_widget->Init(params); |
101 desktop_widget->SetContentsView(view); | 106 desktop_widget->SetContentsView(view); |
102 desktop_widget->Show(); | 107 desktop_widget->Show(); |
103 desktop_widget->GetNativeView()->SetName("DesktopBackgroundView"); | 108 desktop_widget->GetNativeView()->SetName("DesktopBackgroundView"); |
104 return desktop_widget; | 109 return desktop_widget; |
105 } | 110 } |
106 | 111 |
107 } // namespace internal | 112 } // namespace internal |
108 } // namespace ash | 113 } // namespace ash |
OLD | NEW |