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

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

Issue 9557001: Change Aura desktop background behavior. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Applied comments. 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ash/ash_export.h" 7 #include "ash/ash_export.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/shell_window_ids.h" 9 #include "ash/shell_window_ids.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 15 matching lines...) Expand all
26 wallpaper_.buildMipMap(false); 26 wallpaper_.buildMipMap(false);
27 } 27 }
28 28
29 DesktopBackgroundView::~DesktopBackgroundView() { 29 DesktopBackgroundView::~DesktopBackgroundView() {
30 } 30 }
31 31
32 //////////////////////////////////////////////////////////////////////////////// 32 ////////////////////////////////////////////////////////////////////////////////
33 // DesktopBackgroundView, views::View overrides: 33 // DesktopBackgroundView, views::View overrides:
34 34
35 void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) { 35 void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) {
36 canvas->DrawBitmapInt(wallpaper_, 36 // Scale the image while maintaining the aspect ratio, cropping as
37 0, 0, wallpaper_.width(), wallpaper_.height(), 37 // necessary to fill the background. Ideally the image should be larger
38 0, 0, width(), height(), 38 // than the largest display supported, if not we will center it rather than
39 true); 39 // streching to avoid upsampling artifacts (Note that we could tile too, but
40 // decided not to do this at the moment).
41 gfx::Rect wallpaper_rect(0, 0, wallpaper_.width(), wallpaper_.height());
42 if (wallpaper_.width() > width() && wallpaper_.height() > height()) {
43 // The dimension with the smallest ratio must be cropped, the other one
44 // is preserved. Both are set in gfx::Size cropped_size.
45 double horizontal_ratio = static_cast<double>(width()) /
46 static_cast<double>(wallpaper_.width());
47 double vertical_ratio = static_cast<double>(height()) /
48 static_cast<double>(wallpaper_.height());
49
50 gfx::Size cropped_size;
51 if (vertical_ratio > horizontal_ratio) {
52 cropped_size = gfx::Size(
53 static_cast<int>(static_cast<double>(width()) / vertical_ratio),
54 wallpaper_.height());
55 } else {
56 cropped_size = gfx::Size(wallpaper_.width(),
57 static_cast<int>(static_cast<double>(height()) / horizontal_ratio));
58 }
59
60 gfx::Rect wallpaper_cropped_rect = wallpaper_rect.Center(cropped_size);
61 canvas->DrawBitmapInt(wallpaper_,
62 wallpaper_cropped_rect.x(), wallpaper_cropped_rect.y(),
63 wallpaper_cropped_rect.width(), wallpaper_cropped_rect.height(),
64 0, 0, width(), height(),
65 true);
66 }
67 else {
68 // Center the wallpaper and crop to the destination rectangle.
69 gfx::Rect wallpaper_centered_rect = wallpaper_rect.Center(gfx::Size(
Daniel Erat 2012/02/29 22:10:40 you don't need this anymore
Emmanuel Saint-loubert-Bié 2012/02/29 22:32:58 Done.
70 std::min(wallpaper_.width(), width()),
71 std::min(wallpaper_.height(), height())));
72 canvas->DrawBitmapInt(wallpaper_, (width() - wallpaper_.width()) / 2,
73 (height() - wallpaper_.height()) / 2);
74 }
40 } 75 }
41 76
42 bool DesktopBackgroundView::OnMousePressed(const views::MouseEvent& event) { 77 bool DesktopBackgroundView::OnMousePressed(const views::MouseEvent& event) {
43 return true; 78 return true;
44 } 79 }
45 80
46 void DesktopBackgroundView::OnMouseReleased(const views::MouseEvent& event) { 81 void DesktopBackgroundView::OnMouseReleased(const views::MouseEvent& event) {
47 if (event.IsRightMouseButton()) 82 if (event.IsRightMouseButton())
48 Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), event.location()); 83 Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), event.location());
49 } 84 }
50 85
51 views::Widget* CreateDesktopBackground() { 86 views::Widget* CreateDesktopBackground() {
52 views::Widget* desktop_widget = new views::Widget; 87 views::Widget* desktop_widget = new views::Widget;
53 views::Widget::InitParams params( 88 views::Widget::InitParams params(
54 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 89 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
55 DesktopBackgroundView* view = new DesktopBackgroundView; 90 DesktopBackgroundView* view = new DesktopBackgroundView;
56 params.delegate = view; 91 params.delegate = view;
57 params.parent = 92 params.parent =
58 Shell::GetInstance()->GetContainer( 93 Shell::GetInstance()->GetContainer(
59 ash::internal::kShellWindowId_DesktopBackgroundContainer); 94 ash::internal::kShellWindowId_DesktopBackgroundContainer);
60 desktop_widget->Init(params); 95 desktop_widget->Init(params);
61 desktop_widget->SetContentsView(view); 96 desktop_widget->SetContentsView(view);
62 desktop_widget->Show(); 97 desktop_widget->Show();
63 desktop_widget->GetNativeView()->SetName("DesktopBackgroundView"); 98 desktop_widget->GetNativeView()->SetName("DesktopBackgroundView");
64 return desktop_widget; 99 return desktop_widget;
65 } 100 }
66 101
67 } // namespace internal 102 } // namespace internal
68 } // namespace ash 103 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698