| 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_runner_util.h" | 8 #include "base/task_runner_util.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "ui/views/controls/button/label_button.h" | 11 #include "ui/views/controls/button/label_button.h" |
| 12 | 12 |
| 13 #if defined(OS_WIN) | 13 #if defined(OS_WIN) |
| 14 #include <windows.h> | 14 #include <windows.h> |
| 15 #include <shellapi.h> | 15 #include <shellapi.h> |
| 16 #include "base/win/win_util.h" | 16 #include "base/win/win_util.h" |
| 17 #include "base/win/windows_version.h" | 17 #include "base/win/windows_version.h" |
| 18 #include "ui/gfx/icon_util.h" | 18 #include "ui/gfx/icon_util.h" |
| 19 #include "ui/gfx/win/dpi.h" | 19 #include "ui/gfx/win/dpi.h" |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 | 22 |
| 23 // Helpers -------------------------------------------------------------------- | 23 // Helpers -------------------------------------------------------------------- |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 scoped_ptr<SkBitmap> GetElevationIcon() { | 27 std::unique_ptr<SkBitmap> GetElevationIcon() { |
| 28 scoped_ptr<SkBitmap> icon; | 28 std::unique_ptr<SkBitmap> icon; |
| 29 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
| 30 if ((base::win::GetVersion() < base::win::VERSION_VISTA) || | 30 if ((base::win::GetVersion() < base::win::VERSION_VISTA) || |
| 31 !base::win::UserAccountControlIsEnabled()) | 31 !base::win::UserAccountControlIsEnabled()) |
| 32 return icon; | 32 return icon; |
| 33 | 33 |
| 34 SHSTOCKICONINFO icon_info = { sizeof(SHSTOCKICONINFO) }; | 34 SHSTOCKICONINFO icon_info = { sizeof(SHSTOCKICONINFO) }; |
| 35 typedef HRESULT (STDAPICALLTYPE *GetStockIconInfo)(SHSTOCKICONID, | 35 typedef HRESULT (STDAPICALLTYPE *GetStockIconInfo)(SHSTOCKICONID, |
| 36 UINT, | 36 UINT, |
| 37 SHSTOCKICONINFO*); | 37 SHSTOCKICONINFO*); |
| 38 // Even with the runtime guard above, we have to use GetProcAddress() | 38 // Even with the runtime guard above, we have to use GetProcAddress() |
| (...skipping 29 matching lines...) Expand all Loading... |
| 68 base::Bind(&GetElevationIcon), | 68 base::Bind(&GetElevationIcon), |
| 69 base::Bind(&ElevationIconSetter::SetButtonIcon, | 69 base::Bind(&ElevationIconSetter::SetButtonIcon, |
| 70 weak_factory_.GetWeakPtr(), | 70 weak_factory_.GetWeakPtr(), |
| 71 callback)); | 71 callback)); |
| 72 } | 72 } |
| 73 | 73 |
| 74 ElevationIconSetter::~ElevationIconSetter() { | 74 ElevationIconSetter::~ElevationIconSetter() { |
| 75 } | 75 } |
| 76 | 76 |
| 77 void ElevationIconSetter::SetButtonIcon(const base::Closure& callback, | 77 void ElevationIconSetter::SetButtonIcon(const base::Closure& callback, |
| 78 scoped_ptr<SkBitmap> icon) { | 78 std::unique_ptr<SkBitmap> icon) { |
| 79 if (icon) { | 79 if (icon) { |
| 80 float device_scale_factor = 1.0f; | 80 float device_scale_factor = 1.0f; |
| 81 #if defined(OS_WIN) | 81 #if defined(OS_WIN) |
| 82 // Windows gives us back a correctly-scaled image for the current DPI, so | 82 // Windows gives us back a correctly-scaled image for the current DPI, so |
| 83 // mark this image as having been scaled for the current DPI already. | 83 // mark this image as having been scaled for the current DPI already. |
| 84 device_scale_factor = gfx::GetDPIScale(); | 84 device_scale_factor = gfx::GetDPIScale(); |
| 85 #endif | 85 #endif |
| 86 button_->SetImage( | 86 button_->SetImage( |
| 87 views::Button::STATE_NORMAL, | 87 views::Button::STATE_NORMAL, |
| 88 gfx::ImageSkia(gfx::ImageSkiaRep(*icon, device_scale_factor))); | 88 gfx::ImageSkia(gfx::ImageSkiaRep(*icon, device_scale_factor))); |
| 89 button_->SizeToPreferredSize(); | 89 button_->SizeToPreferredSize(); |
| 90 if (button_->parent()) | 90 if (button_->parent()) |
| 91 button_->parent()->Layout(); | 91 button_->parent()->Layout(); |
| 92 if (!callback.is_null()) | 92 if (!callback.is_null()) |
| 93 callback.Run(); | 93 callback.Run(); |
| 94 } | 94 } |
| 95 } | 95 } |
| OLD | NEW |