Chromium Code Reviews| 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 #include "ash/desktop_background/desktop_background_controller.h" | |
|
flackr
2012/03/05 16:16:03
This include goes below with the others. desktop_b
bshe
2012/03/06 01:33:27
Done.
| |
| 6 | 7 |
| 7 #include <limits> | 8 #include <limits> |
| 8 | 9 |
| 9 #include "ash/ash_export.h" | 10 #include "ash/ash_export.h" |
| 10 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 11 #include "ash/shell_window_ids.h" | 12 #include "ash/shell_window_ids.h" |
| 12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 13 #include "grit/ui_resources.h" | 14 #include "grit/ui_resources.h" |
| 14 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
| 15 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
| 17 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
| 18 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 19 | 20 |
| 20 namespace ash { | 21 namespace ash { |
| 22 | |
|
flackr
2012/03/05 16:16:03
nit: no newline here.
bshe
2012/03/06 01:33:27
Done.
| |
| 21 namespace internal { | 23 namespace internal { |
| 22 | |
| 23 // For our scaling ratios we need to round positive numbers. | 24 // For our scaling ratios we need to round positive numbers. |
| 24 static int RoundPositive(double x) { | 25 static int RoundPositive(double x) { |
| 25 return static_cast<int>(floor(x + 0.5)); | 26 return static_cast<int>(floor(x + 0.5)); |
| 26 } | 27 } |
| 27 | 28 |
| 28 //////////////////////////////////////////////////////////////////////////////// | 29 //////////////////////////////////////////////////////////////////////////////// |
| 29 // DesktopBackgroundView, public: | 30 // DesktopBackgroundView, public: |
| 30 | 31 |
| 31 DesktopBackgroundView::DesktopBackgroundView() { | 32 DesktopBackgroundView::DesktopBackgroundView() { |
| 32 wallpaper_ = *ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 33 wallpaper_ = *ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 33 IDR_AURA_WALLPAPER_1).ToSkBitmap(); | 34 IDR_AURA_WALLPAPER_1).ToSkBitmap(); |
|
flackr
2012/03/05 16:16:03
If the user has a custom background set this will
bshe
2012/03/06 01:33:27
It seems this is constructed before NOTIFICATION_L
flackr
2012/03/06 17:16:49
It makes sense that this is constructed before the
bshe
2012/03/06 19:56:15
I am wondering is it also fine to dont set a speci
| |
| 34 wallpaper_.buildMipMap(false); | 35 wallpaper_.buildMipMap(false); |
| 35 } | 36 } |
| 36 | 37 |
| 37 DesktopBackgroundView::~DesktopBackgroundView() { | 38 DesktopBackgroundView::~DesktopBackgroundView() { |
| 38 } | 39 } |
| 39 | 40 |
| 41 void DesktopBackgroundView::SetWallpaper(const SkBitmap& wallpaper) { | |
| 42 wallpaper_ = wallpaper; | |
| 43 wallpaper_.buildMipMap(false); | |
| 44 SchedulePaint(); | |
| 45 } | |
| 46 | |
| 47 //static | |
| 48 DesktopBackgroundView* DesktopBackgroundView::GetInstance() { | |
| 49 return Singleton<DesktopBackgroundView>::get(); | |
| 50 } | |
| 51 | |
| 40 //////////////////////////////////////////////////////////////////////////////// | 52 //////////////////////////////////////////////////////////////////////////////// |
| 41 // DesktopBackgroundView, views::View overrides: | 53 // DesktopBackgroundView, views::View overrides: |
| 42 | 54 |
| 43 void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) { | 55 void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) { |
| 44 // Scale the image while maintaining the aspect ratio, cropping as | 56 // Scale the image while maintaining the aspect ratio, cropping as |
| 45 // necessary to fill the background. Ideally the image should be larger | 57 // 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 | 58 // 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 | 59 // streching to avoid upsampling artifacts (Note that we could tile too, but |
| 48 // decided not to do this at the moment). | 60 // decided not to do this at the moment). |
| 49 gfx::Rect wallpaper_rect(0, 0, wallpaper_.width(), wallpaper_.height()); | 61 gfx::Rect wallpaper_rect(0, 0, wallpaper_.width(), wallpaper_.height()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 | 97 |
| 86 void DesktopBackgroundView::OnMouseReleased(const views::MouseEvent& event) { | 98 void DesktopBackgroundView::OnMouseReleased(const views::MouseEvent& event) { |
| 87 if (event.IsRightMouseButton()) | 99 if (event.IsRightMouseButton()) |
| 88 Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), event.location()); | 100 Shell::GetInstance()->ShowBackgroundMenu(GetWidget(), event.location()); |
| 89 } | 101 } |
| 90 | 102 |
| 91 views::Widget* CreateDesktopBackground() { | 103 views::Widget* CreateDesktopBackground() { |
| 92 views::Widget* desktop_widget = new views::Widget; | 104 views::Widget* desktop_widget = new views::Widget; |
| 93 views::Widget::InitParams params( | 105 views::Widget::InitParams params( |
| 94 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 106 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 95 DesktopBackgroundView* view = new DesktopBackgroundView; | 107 DesktopBackgroundView* view = DesktopBackgroundView::GetInstance(); |
| 96 params.delegate = view; | 108 params.delegate = view; |
| 97 params.parent = | 109 params.parent = |
| 98 Shell::GetInstance()->GetContainer( | 110 Shell::GetInstance()->GetContainer( |
| 99 ash::internal::kShellWindowId_DesktopBackgroundContainer); | 111 ash::internal::kShellWindowId_DesktopBackgroundContainer); |
| 100 desktop_widget->Init(params); | 112 desktop_widget->Init(params); |
| 101 desktop_widget->SetContentsView(view); | 113 desktop_widget->SetContentsView(view); |
| 102 desktop_widget->Show(); | 114 desktop_widget->Show(); |
| 103 desktop_widget->GetNativeView()->SetName("DesktopBackgroundView"); | 115 desktop_widget->GetNativeView()->SetName("DesktopBackgroundView"); |
| 104 return desktop_widget; | 116 return desktop_widget; |
| 105 } | 117 } |
| 106 | 118 |
| 107 } // namespace internal | 119 } // namespace internal |
| 108 } // namespace ash | 120 } // namespace ash |
| OLD | NEW |