| 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/system/user/tray_user.h" | 5 #include "ash/system/user/tray_user.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/system/tray/system_tray_delegate.h" | 8 #include "ash/system/tray/system_tray_delegate.h" |
| 9 #include "ash/system/tray/tray_constants.h" | 9 #include "ash/system/tray/tray_constants.h" |
| 10 #include "ash/system/tray/tray_item_view.h" |
| 10 #include "ash/system/tray/tray_views.h" | 11 #include "ash/system/tray/tray_views.h" |
| 11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 12 #include "grit/ash_strings.h" | 13 #include "grit/ash_strings.h" |
| 13 #include "skia/ext/image_operations.h" | 14 #include "skia/ext/image_operations.h" |
| 14 #include "third_party/skia/include/core/SkCanvas.h" | 15 #include "third_party/skia/include/core/SkCanvas.h" |
| 15 #include "third_party/skia/include/core/SkPaint.h" | 16 #include "third_party/skia/include/core/SkPaint.h" |
| 16 #include "third_party/skia/include/core/SkPath.h" | 17 #include "third_party/skia/include/core/SkPath.h" |
| 17 #include "third_party/skia/include/core/SkShader.h" | 18 #include "third_party/skia/include/core/SkShader.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/canvas.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 views::View* update_; | 177 views::View* update_; |
| 177 | 178 |
| 178 TrayPopupTextButton* shutdown_; | 179 TrayPopupTextButton* shutdown_; |
| 179 TrayPopupTextButton* signout_; | 180 TrayPopupTextButton* signout_; |
| 180 TrayPopupTextButton* lock_; | 181 TrayPopupTextButton* lock_; |
| 181 | 182 |
| 182 DISALLOW_COPY_AND_ASSIGN(UserView); | 183 DISALLOW_COPY_AND_ASSIGN(UserView); |
| 183 }; | 184 }; |
| 184 | 185 |
| 185 // A custom image view with rounded edges. | 186 // A custom image view with rounded edges. |
| 186 class RoundedImageView : public views::View { | 187 class RoundedImageView : public TrayItemView { |
| 187 public: | 188 public: |
| 188 // Constructs a new rounded image view with rounded corners of radius | 189 // Constructs a new rounded image view with rounded corners of radius |
| 189 // |corner_radius|. | 190 // |corner_radius|. |
| 190 explicit RoundedImageView(int corner_radius) : corner_radius_(corner_radius) { | 191 explicit RoundedImageView(int corner_radius) : corner_radius_(corner_radius) { |
| 191 } | 192 } |
| 192 | 193 |
| 193 virtual ~RoundedImageView() { | 194 virtual ~RoundedImageView() { |
| 194 } | 195 } |
| 195 | 196 |
| 196 // Set the bitmap that should be displayed from a pointer. The pointer | 197 // Set the bitmap that should be displayed from a pointer. The pointer |
| 197 // contents is copied in the receiver's bitmap. | 198 // contents is copied in the receiver's bitmap. |
| 198 void SetImage(const SkBitmap& bm, const gfx::Size& size) { | 199 void SetImage(const SkBitmap& bm, const gfx::Size& size) { |
| 199 image_ = bm; | 200 image_ = bm; |
| 200 image_size_ = size; | 201 image_size_ = size; |
| 201 | 202 |
| 202 // Try to get the best image quality for the avatar. | 203 // Try to get the best image quality for the avatar. |
| 203 resized_ = skia::ImageOperations::Resize(image_, | 204 resized_ = skia::ImageOperations::Resize(image_, |
| 204 skia::ImageOperations::RESIZE_BEST, size.width(), size.height()); | 205 skia::ImageOperations::RESIZE_BEST, size.width(), size.height()); |
| 205 PreferredSizeChanged(); | 206 if (GetWidget() && visible()) { |
| 206 SchedulePaint(); | 207 PreferredSizeChanged(); |
| 208 SchedulePaint(); |
| 209 } |
| 207 } | 210 } |
| 208 | 211 |
| 209 // Overridden from views::View. | 212 // Overridden from TrayItemView. |
| 210 virtual gfx::Size GetPreferredSize() OVERRIDE { | 213 virtual gfx::Size DesiredSize() OVERRIDE { |
| 211 return gfx::Size(image_size_.width() + GetInsets().width(), | 214 return gfx::Size(image_size_.width() + GetInsets().width(), |
| 212 image_size_.height() + GetInsets().height()); | 215 image_size_.height() + GetInsets().height()); |
| 213 } | 216 } |
| 214 | 217 |
| 218 virtual int GetAnimationDurationMS() OVERRIDE { |
| 219 return 750; |
| 220 } |
| 221 |
| 222 // Overridden from views::View. |
| 215 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | 223 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
| 216 View::OnPaint(canvas); | 224 View::OnPaint(canvas); |
| 217 gfx::Rect image_bounds(GetPreferredSize()); | 225 gfx::Rect image_bounds(DesiredSize()); |
| 218 image_bounds.Inset(GetInsets()); | 226 image_bounds.Inset(GetInsets()); |
| 219 const SkScalar kRadius = SkIntToScalar(corner_radius_); | 227 const SkScalar kRadius = SkIntToScalar(corner_radius_); |
| 220 SkPath path; | 228 SkPath path; |
| 221 path.addRoundRect(gfx::RectToSkRect(image_bounds), kRadius, kRadius); | 229 path.addRoundRect(gfx::RectToSkRect(image_bounds), kRadius, kRadius); |
| 222 | 230 |
| 223 SkPaint paint; | 231 SkPaint paint; |
| 224 SkShader* shader = SkShader::CreateBitmapShader(resized_, | 232 SkShader* shader = SkShader::CreateBitmapShader(resized_, |
| 225 SkShader::kRepeat_TileMode, | 233 SkShader::kRepeat_TileMode, |
| 226 SkShader::kRepeat_TileMode); | 234 SkShader::kRepeat_TileMode); |
| 227 SkMatrix shader_matrix; | 235 SkMatrix shader_matrix; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 } | 298 } |
| 291 | 299 |
| 292 void TrayUser::OnUserUpdate() { | 300 void TrayUser::OnUserUpdate() { |
| 293 avatar_->SetImage( | 301 avatar_->SetImage( |
| 294 ash::Shell::GetInstance()->tray_delegate()->GetUserImage(), | 302 ash::Shell::GetInstance()->tray_delegate()->GetUserImage(), |
| 295 gfx::Size(kUserIconSize, kUserIconSize)); | 303 gfx::Size(kUserIconSize, kUserIconSize)); |
| 296 } | 304 } |
| 297 | 305 |
| 298 } // namespace internal | 306 } // namespace internal |
| 299 } // namespace ash | 307 } // namespace ash |
| OLD | NEW |