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 | 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) { | 131 void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) { |
| 132 // Scale the image while maintaining the aspect ratio, cropping as | 132 // Scale the image while maintaining the aspect ratio, cropping as |
| 133 // necessary to fill the background. Ideally the image should be larger | 133 // necessary to fill the background. Ideally the image should be larger |
| 134 // than the largest display supported, if not we will scale and center it if | 134 // than the largest display supported, if not we will scale and center it if |
| 135 // the layout is WALLPAPER_LAYOUT_CENTER_CROPPED. | 135 // the layout is WALLPAPER_LAYOUT_CENTER_CROPPED. |
| 136 DesktopBackgroundController* controller = | 136 DesktopBackgroundController* controller = |
| 137 Shell::GetInstance()->desktop_background_controller(); | 137 Shell::GetInstance()->desktop_background_controller(); |
| 138 gfx::ImageSkia wallpaper = controller->GetWallpaper(); | 138 gfx::ImageSkia wallpaper = controller->GetWallpaper(); |
| 139 WallpaperLayout wallpaper_layout = controller->GetWallpaperLayout(); | 139 WallpaperLayout wallpaper_layout = controller->GetWallpaperLayout(); |
| 140 | 140 |
| 141 // Wallpapers with png format could be partially transparent. | |
| 142 // Reset the canvas before rendering wallpaper. | |
|
xdai1
2016/05/19 23:27:55
Might be better to say "Fill the canvas with black
xiaoyinh(OOO Sep 11-29)
2016/05/20 00:06:12
Done.
| |
| 143 canvas->FillRect(GetLocalBounds(), SK_ColorBLACK); | |
| 144 | |
|
xdai1
2016/05/19 23:27:55
Move this part after if(wallpaper.isNull())...
xiaoyinh(OOO Sep 11-29)
2016/05/20 00:06:11
Discussed with xdai1@, this will remain as is.
| |
| 141 if (wallpaper.isNull()) { | 145 if (wallpaper.isNull()) { |
|
xdai1
2016/05/19 23:27:55
No brace please
xiaoyinh(OOO Sep 11-29)
2016/05/20 00:06:12
Done.
| |
| 142 canvas->FillRect(GetLocalBounds(), SK_ColorBLACK); | |
| 143 return; | 146 return; |
| 144 } | 147 } |
| 145 | 148 |
| 146 if (wallpaper_layout == WALLPAPER_LAYOUT_CENTER_CROPPED) { | 149 if (wallpaper_layout == WALLPAPER_LAYOUT_CENTER_CROPPED) { |
| 147 // The dimension with the smallest ratio must be cropped, the other one | 150 // The dimension with the smallest ratio must be cropped, the other one |
| 148 // is preserved. Both are set in gfx::Size cropped_size. | 151 // is preserved. Both are set in gfx::Size cropped_size. |
| 149 double horizontal_ratio = static_cast<double>(width()) / | 152 double horizontal_ratio = static_cast<double>(width()) / |
| 150 static_cast<double>(wallpaper.width()); | 153 static_cast<double>(wallpaper.width()); |
| 151 double vertical_ratio = static_cast<double>(height()) / | 154 double vertical_ratio = static_cast<double>(height()) / |
| 152 static_cast<double>(wallpaper.height()); | 155 static_cast<double>(wallpaper.height()); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 171 0, 0, width(), height(), | 174 0, 0, width(), height(), |
| 172 true); | 175 true); |
| 173 } else if (wallpaper_layout == WALLPAPER_LAYOUT_TILE) { | 176 } else if (wallpaper_layout == WALLPAPER_LAYOUT_TILE) { |
| 174 canvas->TileImageInt(wallpaper, 0, 0, width(), height()); | 177 canvas->TileImageInt(wallpaper, 0, 0, width(), height()); |
| 175 } else if (wallpaper_layout == WALLPAPER_LAYOUT_STRETCH) { | 178 } else if (wallpaper_layout == WALLPAPER_LAYOUT_STRETCH) { |
| 176 // This is generally not recommended as it may show artifacts. | 179 // This is generally not recommended as it may show artifacts. |
| 177 canvas->DrawImageInt(wallpaper, 0, 0, wallpaper.width(), | 180 canvas->DrawImageInt(wallpaper, 0, 0, wallpaper.width(), |
| 178 wallpaper.height(), 0, 0, width(), height(), true); | 181 wallpaper.height(), 0, 0, width(), height(), true); |
| 179 } else { | 182 } else { |
| 180 // Fill with black to make sure that the entire area is opaque. | 183 // Fill with black to make sure that the entire area is opaque. |
| 181 canvas->FillRect(GetLocalBounds(), SK_ColorBLACK); | 184 canvas->FillRect(GetLocalBounds(), SK_ColorBLACK); |
|
xdai1
2016/05/19 23:27:55
Remove this line.
xiaoyinh(OOO Sep 11-29)
2016/05/20 00:06:11
Done.
| |
| 182 float image_scale = canvas->image_scale(); | 185 float image_scale = canvas->image_scale(); |
| 183 gfx::Rect wallpaper_rect(0, 0, wallpaper.width() / image_scale, | 186 gfx::Rect wallpaper_rect(0, 0, wallpaper.width() / image_scale, |
| 184 wallpaper.height() / image_scale); | 187 wallpaper.height() / image_scale); |
| 185 // All other are simply centered, and not scaled (but may be clipped). | 188 // All other are simply centered, and not scaled (but may be clipped). |
| 186 canvas->DrawImageInt( | 189 canvas->DrawImageInt( |
| 187 wallpaper, | 190 wallpaper, |
| 188 0, 0, wallpaper.width(), wallpaper.height(), | 191 0, 0, wallpaper.width(), wallpaper.height(), |
| 189 (width() - wallpaper_rect.width()) / 2, | 192 (width() - wallpaper_rect.width()) / 2, |
| 190 (height() - wallpaper_rect.height()) / 2, | 193 (height() - wallpaper_rect.height()) / 2, |
| 191 wallpaper_rect.width(), | 194 wallpaper_rect.width(), |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 // Disable animation if transition to login screen from an empty background. | 252 // Disable animation if transition to login screen from an empty background. |
| 250 ::wm::SetWindowVisibilityAnimationTransition( | 253 ::wm::SetWindowVisibilityAnimationTransition( |
| 251 desktop_widget->GetNativeView(), ::wm::ANIMATE_NONE); | 254 desktop_widget->GetNativeView(), ::wm::ANIMATE_NONE); |
| 252 } | 255 } |
| 253 | 256 |
| 254 desktop_widget->SetBounds(params.parent->bounds()); | 257 desktop_widget->SetBounds(params.parent->bounds()); |
| 255 return desktop_widget; | 258 return desktop_widget; |
| 256 } | 259 } |
| 257 | 260 |
| 258 } // namespace ash | 261 } // namespace ash |
| OLD | NEW |