Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(696)

Side by Side Diff: ash/desktop_background/desktop_background_view.cc

Issue 9580023: Enable user change background image in settings page in Aura build. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Address review Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 11 matching lines...) Expand all
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() {
32 wallpaper_ = *ui::ResourceBundle::GetSharedInstance().GetImageNamed(
33 IDR_AURA_WALLPAPER_1).ToSkBitmap();
34 wallpaper_.buildMipMap(false);
35 } 32 }
36 33
37 DesktopBackgroundView::~DesktopBackgroundView() { 34 DesktopBackgroundView::~DesktopBackgroundView() {
38 } 35 }
39 36
37 void DesktopBackgroundView::SetWallpaper(const SkBitmap& wallpaper) {
38 wallpaper_ = wallpaper;
39 wallpaper_.buildMipMap(false);
40 SchedulePaint();
41 }
42
40 //////////////////////////////////////////////////////////////////////////////// 43 ////////////////////////////////////////////////////////////////////////////////
41 // DesktopBackgroundView, views::View overrides: 44 // DesktopBackgroundView, views::View overrides:
42 45
43 void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) { 46 void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) {
44 // Scale the image while maintaining the aspect ratio, cropping as 47 // Scale the image while maintaining the aspect ratio, cropping as
45 // necessary to fill the background. Ideally the image should be larger 48 // 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 49 // 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 50 // streching to avoid upsampling artifacts (Note that we could tile too, but
48 // decided not to do this at the moment). 51 // decided not to do this at the moment).
49 gfx::Rect wallpaper_rect(0, 0, wallpaper_.width(), wallpaper_.height()); 52 gfx::Rect wallpaper_rect(0, 0, wallpaper_.width(), wallpaper_.height());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 88
86 void DesktopBackgroundView::OnMouseReleased(const views::MouseEvent& event) { 89 void DesktopBackgroundView::OnMouseReleased(const views::MouseEvent& event) {
87 if (event.IsRightMouseButton()) 90 if (event.IsRightMouseButton())
88 Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), event.location()); 91 Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), event.location());
89 } 92 }
90 93
91 views::Widget* CreateDesktopBackground() { 94 views::Widget* CreateDesktopBackground() {
92 views::Widget* desktop_widget = new views::Widget; 95 views::Widget* desktop_widget = new views::Widget;
93 views::Widget::InitParams params( 96 views::Widget::InitParams params(
94 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 97 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
95 DesktopBackgroundView* view = new DesktopBackgroundView; 98 DesktopBackgroundView* view = new DesktopBackgroundView();
96 params.delegate = view; 99 params.delegate = view;
97 params.parent = 100 params.parent =
98 Shell::GetInstance()->GetContainer( 101 Shell::GetInstance()->GetContainer(
99 ash::internal::kShellWindowId_DesktopBackgroundContainer); 102 ash::internal::kShellWindowId_DesktopBackgroundContainer);
100 desktop_widget->Init(params); 103 desktop_widget->Init(params);
101 desktop_widget->SetContentsView(view); 104 desktop_widget->SetContentsView(view);
102 desktop_widget->Show(); 105 desktop_widget->Show();
103 desktop_widget->GetNativeView()->SetName("DesktopBackgroundView"); 106 desktop_widget->GetNativeView()->SetName("DesktopBackgroundView");
104 return desktop_widget; 107 return desktop_widget;
105 } 108 }
106 109
107 } // namespace internal 110 } // namespace internal
108 } // namespace ash 111 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698