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/task_runner_util.h" | 7 #include "base/task_runner_util.h" |
8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
9 #include "ui/views/controls/button/label_button.h" | 9 #include "ui/views/controls/button/label_button.h" |
10 | 10 |
11 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
12 #include <windows.h> | 12 #include <windows.h> |
13 #include <shellapi.h> | 13 #include <shellapi.h> |
14 #include "base/win/win_util.h" | 14 #include "base/win/win_util.h" |
15 #include "base/win/windows_version.h" | 15 #include "base/win/windows_version.h" |
16 #include "ui/gfx/icon_util.h" | 16 #include "ui/gfx/icon_util.h" |
| 17 #include "ui/gfx/win/dpi.h" |
17 #endif | 18 #endif |
18 | 19 |
19 | 20 |
20 // Helpers -------------------------------------------------------------------- | 21 // Helpers -------------------------------------------------------------------- |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 scoped_ptr<SkBitmap> GetElevationIcon() { | 25 scoped_ptr<SkBitmap> GetElevationIcon() { |
25 scoped_ptr<SkBitmap> icon; | 26 scoped_ptr<SkBitmap> icon; |
26 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 base::Bind(&GetElevationIcon), | 65 base::Bind(&GetElevationIcon), |
65 base::Bind(&ElevationIconSetter::SetButtonIcon, | 66 base::Bind(&ElevationIconSetter::SetButtonIcon, |
66 weak_factory_.GetWeakPtr())); | 67 weak_factory_.GetWeakPtr())); |
67 } | 68 } |
68 | 69 |
69 ElevationIconSetter::~ElevationIconSetter() { | 70 ElevationIconSetter::~ElevationIconSetter() { |
70 } | 71 } |
71 | 72 |
72 void ElevationIconSetter::SetButtonIcon(scoped_ptr<SkBitmap> icon) { | 73 void ElevationIconSetter::SetButtonIcon(scoped_ptr<SkBitmap> icon) { |
73 if (icon) { | 74 if (icon) { |
74 button_->SetImage(views::Button::STATE_NORMAL, | 75 float device_scale_factor = 1.0f; |
75 gfx::ImageSkia::CreateFrom1xBitmap(*icon)); | 76 #if defined(OS_WIN) |
| 77 // Windows gives us back a correctly-scaled image for the current DPI, so |
| 78 // mark this image as having been scaled for the current DPI already. |
| 79 device_scale_factor = gfx::GetDPIScale(); |
| 80 #endif |
| 81 button_->SetImage( |
| 82 views::Button::STATE_NORMAL, |
| 83 gfx::ImageSkia(gfx::ImageSkiaRep(*icon, device_scale_factor))); |
76 button_->SizeToPreferredSize(); | 84 button_->SizeToPreferredSize(); |
77 if (button_->parent()) | 85 if (button_->parent()) |
78 button_->parent()->Layout(); | 86 button_->parent()->Layout(); |
79 } | 87 } |
80 } | 88 } |
OLD | NEW |