| 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/common/session/session_state_delegate.h" | 10 #include "ash/common/session/session_state_delegate.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 // Fill the canvas with black background to make it opaque | 143 // Fill the canvas with black background to make it opaque |
| 144 // before painting wallpaper | 144 // before painting wallpaper |
| 145 canvas->FillRect(GetLocalBounds(), SK_ColorBLACK); | 145 canvas->FillRect(GetLocalBounds(), SK_ColorBLACK); |
| 146 | 146 |
| 147 if (wallpaper.isNull()) | 147 if (wallpaper.isNull()) |
| 148 return; | 148 return; |
| 149 | 149 |
| 150 if (wallpaper_layout == WALLPAPER_LAYOUT_CENTER_CROPPED) { | 150 if (wallpaper_layout == WALLPAPER_LAYOUT_CENTER_CROPPED) { |
| 151 // The dimension with the smallest ratio must be cropped, the other one | 151 // The dimension with the smallest ratio must be cropped, the other one |
| 152 // is preserved. Both are set in gfx::Size cropped_size. | 152 // is preserved. Both are set in gfx::Size cropped_size. |
| 153 double horizontal_ratio = static_cast<double>(width()) / | 153 double horizontal_ratio = |
| 154 static_cast<double>(wallpaper.width()); | 154 static_cast<double>(width()) / static_cast<double>(wallpaper.width()); |
| 155 double vertical_ratio = static_cast<double>(height()) / | 155 double vertical_ratio = |
| 156 static_cast<double>(wallpaper.height()); | 156 static_cast<double>(height()) / static_cast<double>(wallpaper.height()); |
| 157 | 157 |
| 158 gfx::Size cropped_size; | 158 gfx::Size cropped_size; |
| 159 if (vertical_ratio > horizontal_ratio) { | 159 if (vertical_ratio > horizontal_ratio) { |
| 160 cropped_size = gfx::Size( | 160 cropped_size = gfx::Size( |
| 161 gfx::ToFlooredInt(static_cast<double>(width()) / vertical_ratio), | 161 gfx::ToFlooredInt(static_cast<double>(width()) / vertical_ratio), |
| 162 wallpaper.height()); | 162 wallpaper.height()); |
| 163 } else { | 163 } else { |
| 164 cropped_size = gfx::Size( | 164 cropped_size = gfx::Size( |
| 165 wallpaper.width(), | 165 wallpaper.width(), |
| 166 gfx::ToFlooredInt(static_cast<double>(height()) / horizontal_ratio)); | 166 gfx::ToFlooredInt(static_cast<double>(height()) / horizontal_ratio)); |
| 167 } | 167 } |
| 168 | 168 |
| 169 gfx::Rect wallpaper_cropped_rect( | 169 gfx::Rect wallpaper_cropped_rect(0, 0, wallpaper.width(), |
| 170 0, 0, wallpaper.width(), wallpaper.height()); | 170 wallpaper.height()); |
| 171 wallpaper_cropped_rect.ClampToCenteredSize(cropped_size); | 171 wallpaper_cropped_rect.ClampToCenteredSize(cropped_size); |
| 172 canvas->DrawImageInt(wallpaper, | 172 canvas->DrawImageInt( |
| 173 wallpaper_cropped_rect.x(), wallpaper_cropped_rect.y(), | 173 wallpaper, wallpaper_cropped_rect.x(), wallpaper_cropped_rect.y(), |
| 174 wallpaper_cropped_rect.width(), wallpaper_cropped_rect.height(), | 174 wallpaper_cropped_rect.width(), wallpaper_cropped_rect.height(), 0, 0, |
| 175 0, 0, width(), height(), | 175 width(), height(), true); |
| 176 true); | |
| 177 } else if (wallpaper_layout == WALLPAPER_LAYOUT_TILE) { | 176 } else if (wallpaper_layout == WALLPAPER_LAYOUT_TILE) { |
| 178 canvas->TileImageInt(wallpaper, 0, 0, width(), height()); | 177 canvas->TileImageInt(wallpaper, 0, 0, width(), height()); |
| 179 } else if (wallpaper_layout == WALLPAPER_LAYOUT_STRETCH) { | 178 } else if (wallpaper_layout == WALLPAPER_LAYOUT_STRETCH) { |
| 180 // This is generally not recommended as it may show artifacts. | 179 // This is generally not recommended as it may show artifacts. |
| 181 canvas->DrawImageInt(wallpaper, 0, 0, wallpaper.width(), | 180 canvas->DrawImageInt(wallpaper, 0, 0, wallpaper.width(), wallpaper.height(), |
| 182 wallpaper.height(), 0, 0, width(), height(), true); | 181 0, 0, width(), height(), true); |
| 183 } else { | 182 } else { |
| 184 float image_scale = canvas->image_scale(); | 183 float image_scale = canvas->image_scale(); |
| 185 gfx::Rect wallpaper_rect(0, 0, wallpaper.width() / image_scale, | 184 gfx::Rect wallpaper_rect(0, 0, wallpaper.width() / image_scale, |
| 186 wallpaper.height() / image_scale); | 185 wallpaper.height() / image_scale); |
| 187 // All other are simply centered, and not scaled (but may be clipped). | 186 // All other are simply centered, and not scaled (but may be clipped). |
| 188 canvas->DrawImageInt( | 187 canvas->DrawImageInt(wallpaper, 0, 0, wallpaper.width(), wallpaper.height(), |
| 189 wallpaper, | 188 (width() - wallpaper_rect.width()) / 2, |
| 190 0, 0, wallpaper.width(), wallpaper.height(), | 189 (height() - wallpaper_rect.height()) / 2, |
| 191 (width() - wallpaper_rect.width()) / 2, | 190 wallpaper_rect.width(), wallpaper_rect.height(), true); |
| 192 (height() - wallpaper_rect.height()) / 2, | |
| 193 wallpaper_rect.width(), | |
| 194 wallpaper_rect.height(), | |
| 195 true); | |
| 196 } | 191 } |
| 197 } | 192 } |
| 198 | 193 |
| 199 bool DesktopBackgroundView::OnMousePressed(const ui::MouseEvent& event) { | 194 bool DesktopBackgroundView::OnMousePressed(const ui::MouseEvent& event) { |
| 200 return true; | 195 return true; |
| 201 } | 196 } |
| 202 | 197 |
| 203 void DesktopBackgroundView::ShowContextMenuForView( | 198 void DesktopBackgroundView::ShowContextMenuForView( |
| 204 views::View* source, | 199 views::View* source, |
| 205 const gfx::Point& point, | 200 const gfx::Point& point, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 // Disable animation if transition to login screen from an empty background. | 246 // Disable animation if transition to login screen from an empty background. |
| 252 ::wm::SetWindowVisibilityAnimationTransition( | 247 ::wm::SetWindowVisibilityAnimationTransition( |
| 253 desktop_widget->GetNativeView(), ::wm::ANIMATE_NONE); | 248 desktop_widget->GetNativeView(), ::wm::ANIMATE_NONE); |
| 254 } | 249 } |
| 255 | 250 |
| 256 desktop_widget->SetBounds(params.parent->bounds()); | 251 desktop_widget->SetBounds(params.parent->bounds()); |
| 257 return desktop_widget; | 252 return desktop_widget; |
| 258 } | 253 } |
| 259 | 254 |
| 260 } // namespace ash | 255 } // namespace ash |
| OLD | NEW |