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/desktop_background/desktop_background_controller.h" | 10 #include "ash/desktop_background/desktop_background_controller.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 // necessary to fill the background. Ideally the image should be larger | 121 // necessary to fill the background. Ideally the image should be larger |
122 // than the largest display supported, if not we will center it rather than | 122 // than the largest display supported, if not we will center it rather than |
123 // streching to avoid upsampling artifacts (Note that we could tile too, but | 123 // streching to avoid upsampling artifacts (Note that we could tile too, but |
124 // decided not to do this at the moment). | 124 // decided not to do this at the moment). |
125 DesktopBackgroundController* controller = | 125 DesktopBackgroundController* controller = |
126 ash::Shell::GetInstance()->desktop_background_controller(); | 126 ash::Shell::GetInstance()->desktop_background_controller(); |
127 gfx::ImageSkia wallpaper = controller->GetWallpaper(); | 127 gfx::ImageSkia wallpaper = controller->GetWallpaper(); |
128 WallpaperLayout wallpaper_layout = controller->GetWallpaperLayout(); | 128 WallpaperLayout wallpaper_layout = controller->GetWallpaperLayout(); |
129 | 129 |
130 gfx::Rect wallpaper_rect(0, 0, wallpaper.width(), wallpaper.height()); | 130 gfx::Rect wallpaper_rect(0, 0, wallpaper.width(), wallpaper.height()); |
131 if (wallpaper_layout == ash::CENTER_CROPPED && wallpaper.width() > width() | 131 if (wallpaper_layout == WALLPAPER_LAYOUT_CENTER_CROPPED && |
132 && wallpaper.height() > height()) { | 132 wallpaper.width() > width() && wallpaper.height() > height()) { |
133 // The dimension with the smallest ratio must be cropped, the other one | 133 // The dimension with the smallest ratio must be cropped, the other one |
134 // is preserved. Both are set in gfx::Size cropped_size. | 134 // is preserved. Both are set in gfx::Size cropped_size. |
135 double horizontal_ratio = static_cast<double>(width()) / | 135 double horizontal_ratio = static_cast<double>(width()) / |
136 static_cast<double>(wallpaper.width()); | 136 static_cast<double>(wallpaper.width()); |
137 double vertical_ratio = static_cast<double>(height()) / | 137 double vertical_ratio = static_cast<double>(height()) / |
138 static_cast<double>(wallpaper.height()); | 138 static_cast<double>(wallpaper.height()); |
139 | 139 |
140 gfx::Size cropped_size; | 140 gfx::Size cropped_size; |
141 if (vertical_ratio > horizontal_ratio) { | 141 if (vertical_ratio > horizontal_ratio) { |
142 cropped_size = gfx::Size( | 142 cropped_size = gfx::Size( |
143 RoundPositive(static_cast<double>(width()) / vertical_ratio), | 143 RoundPositive(static_cast<double>(width()) / vertical_ratio), |
144 wallpaper.height()); | 144 wallpaper.height()); |
145 } else { | 145 } else { |
146 cropped_size = gfx::Size(wallpaper.width(), | 146 cropped_size = gfx::Size(wallpaper.width(), |
147 RoundPositive(static_cast<double>(height()) / horizontal_ratio)); | 147 RoundPositive(static_cast<double>(height()) / horizontal_ratio)); |
148 } | 148 } |
149 | 149 |
150 gfx::Rect wallpaper_cropped_rect = wallpaper_rect; | 150 gfx::Rect wallpaper_cropped_rect = wallpaper_rect; |
151 wallpaper_cropped_rect.ClampToCenteredSize(cropped_size); | 151 wallpaper_cropped_rect.ClampToCenteredSize(cropped_size); |
152 canvas->DrawImageInt(wallpaper, | 152 canvas->DrawImageInt(wallpaper, |
153 wallpaper_cropped_rect.x(), wallpaper_cropped_rect.y(), | 153 wallpaper_cropped_rect.x(), wallpaper_cropped_rect.y(), |
154 wallpaper_cropped_rect.width(), wallpaper_cropped_rect.height(), | 154 wallpaper_cropped_rect.width(), wallpaper_cropped_rect.height(), |
155 0, 0, width(), height(), | 155 0, 0, width(), height(), |
156 true); | 156 true); |
157 } else if (wallpaper_layout == ash::TILE) { | 157 } else if (wallpaper_layout == WALLPAPER_LAYOUT_TILE) { |
158 canvas->TileImageInt(wallpaper, 0, 0, width(), height()); | 158 canvas->TileImageInt(wallpaper, 0, 0, width(), height()); |
159 } else if (wallpaper_layout == ash::STRETCH) { | 159 } else if (wallpaper_layout == WALLPAPER_LAYOUT_STRETCH) { |
160 // This is generally not recommended as it may show artifacts. | 160 // This is generally not recommended as it may show artifacts. |
161 canvas->DrawImageInt(wallpaper, 0, 0, wallpaper.width(), | 161 canvas->DrawImageInt(wallpaper, 0, 0, wallpaper.width(), |
162 wallpaper.height(), 0, 0, width(), height(), true); | 162 wallpaper.height(), 0, 0, width(), height(), true); |
163 } else { | 163 } else { |
164 // All other are simply centered, and not scaled (but may be clipped). | 164 // All other are simply centered, and not scaled (but may be clipped). |
165 canvas->DrawImageInt(wallpaper, (width() - wallpaper.width()) / 2, | 165 canvas->DrawImageInt(wallpaper, (width() - wallpaper.width()) / 2, |
166 (height() - wallpaper.height()) / 2); | 166 (height() - wallpaper.height()) / 2); |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 settings.AddObserver(new ShowWallpaperAnimationObserver( | 213 settings.AddObserver(new ShowWallpaperAnimationObserver( |
214 root_window, desktop_widget, | 214 root_window, desktop_widget, |
215 wallpaper_delegate->ShouldShowInitialAnimation())); | 215 wallpaper_delegate->ShouldShowInitialAnimation())); |
216 desktop_widget->Show(); | 216 desktop_widget->Show(); |
217 desktop_widget->GetNativeView()->SetName("DesktopBackgroundView"); | 217 desktop_widget->GetNativeView()->SetName("DesktopBackgroundView"); |
218 return desktop_widget; | 218 return desktop_widget; |
219 } | 219 } |
220 | 220 |
221 } // namespace internal | 221 } // namespace internal |
222 } // namespace ash | 222 } // namespace ash |
OLD | NEW |