| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/ui/views/elevation_icon_setter.h" | 5 #include "chrome/browser/ui/views/elevation_icon_setter.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/task_scheduler/post_task.h" | 8 #include "base/task_scheduler/post_task.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "ui/views/controls/button/label_button.h" | 10 #include "ui/views/controls/button/label_button.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 } // namespace | 55 } // namespace |
| 56 | 56 |
| 57 | 57 |
| 58 // ElevationIconSetter -------------------------------------------------------- | 58 // ElevationIconSetter -------------------------------------------------------- |
| 59 | 59 |
| 60 ElevationIconSetter::ElevationIconSetter(views::LabelButton* button, | 60 ElevationIconSetter::ElevationIconSetter(views::LabelButton* button, |
| 61 const base::Closure& callback) | 61 const base::Closure& callback) |
| 62 : button_(button), | 62 : button_(button), |
| 63 weak_factory_(this) { | 63 weak_factory_(this) { |
| 64 base::PostTaskWithTraitsAndReplyWithResult( | 64 base::PostTaskWithTraitsAndReplyWithResult( |
| 65 FROM_HERE, base::TaskTraits().MayBlock().WithPriority( | 65 FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_BLOCKING}, |
| 66 base::TaskPriority::USER_BLOCKING), | |
| 67 base::Bind(&GetElevationIcon), | 66 base::Bind(&GetElevationIcon), |
| 68 base::Bind(&ElevationIconSetter::SetButtonIcon, | 67 base::Bind(&ElevationIconSetter::SetButtonIcon, |
| 69 weak_factory_.GetWeakPtr(), callback)); | 68 weak_factory_.GetWeakPtr(), callback)); |
| 70 } | 69 } |
| 71 | 70 |
| 72 ElevationIconSetter::~ElevationIconSetter() { | 71 ElevationIconSetter::~ElevationIconSetter() { |
| 73 } | 72 } |
| 74 | 73 |
| 75 void ElevationIconSetter::SetButtonIcon(const base::Closure& callback, | 74 void ElevationIconSetter::SetButtonIcon(const base::Closure& callback, |
| 76 std::unique_ptr<SkBitmap> icon) { | 75 std::unique_ptr<SkBitmap> icon) { |
| 77 if (icon) { | 76 if (icon) { |
| 78 float device_scale_factor = 1.0f; | 77 float device_scale_factor = 1.0f; |
| 79 #if defined(OS_WIN) | 78 #if defined(OS_WIN) |
| 80 // Windows gives us back a correctly-scaled image for the current DPI, so | 79 // Windows gives us back a correctly-scaled image for the current DPI, so |
| 81 // mark this image as having been scaled for the current DPI already. | 80 // mark this image as having been scaled for the current DPI already. |
| 82 device_scale_factor = display::win::GetDPIScale(); | 81 device_scale_factor = display::win::GetDPIScale(); |
| 83 #endif | 82 #endif |
| 84 button_->SetImage( | 83 button_->SetImage( |
| 85 views::Button::STATE_NORMAL, | 84 views::Button::STATE_NORMAL, |
| 86 gfx::ImageSkia(gfx::ImageSkiaRep(*icon, device_scale_factor))); | 85 gfx::ImageSkia(gfx::ImageSkiaRep(*icon, device_scale_factor))); |
| 87 button_->SizeToPreferredSize(); | 86 button_->SizeToPreferredSize(); |
| 88 if (button_->parent()) | 87 if (button_->parent()) |
| 89 button_->parent()->Layout(); | 88 button_->parent()->Layout(); |
| 90 if (!callback.is_null()) | 89 if (!callback.is_null()) |
| 91 callback.Run(); | 90 callback.Run(); |
| 92 } | 91 } |
| 93 } | 92 } |
| OLD | NEW |