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/profiles/new_avatar_button.h" | 5 #include "chrome/browser/ui/views/profiles/new_avatar_button.h" |
6 | 6 |
7 #include "base/win/windows_version.h" | 7 #include "base/win/windows_version.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/profiles/profile_manager.h" | 9 #include "chrome/browser/profiles/profile_manager.h" |
10 #include "chrome/browser/profiles/profiles_state.h" | 10 #include "chrome/browser/profiles/profiles_state.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "grit/theme_resources.h" | 12 #include "grit/theme_resources.h" |
13 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
14 #include "ui/gfx/canvas.h" | 14 #include "ui/gfx/canvas.h" |
15 #include "ui/views/border.h" | 15 #include "ui/views/border.h" |
16 #include "ui/views/controls/button/label_button_border.h" | 16 #include "ui/views/controls/button/label_button_border.h" |
17 #include "ui/views/painter.h" | 17 #include "ui/views/painter.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 const int kDisplayFontHeight = 15; | |
Peter Kasting
2014/08/28 19:34:17
Where does this come from? Can we derive this fro
msw
2014/08/28 19:40:03
Was this height derived visually from the button a
noms (inactive)
2014/08/28 20:36:25
Hmm, it was, yes. Working on getting something bet
msw
2014/08/28 21:43:50
Give it a shot, I'd be okay with a literal (and a
noms (inactive)
2014/08/29 17:10:29
I went with adding a comment. Button height + inse
| |
22 | |
21 scoped_ptr<views::Border> CreateBorder(const int normal_image_set[], | 23 scoped_ptr<views::Border> CreateBorder(const int normal_image_set[], |
22 const int hot_image_set[], | 24 const int hot_image_set[], |
23 const int pushed_image_set[]) { | 25 const int pushed_image_set[]) { |
24 scoped_ptr<views::LabelButtonBorder> border( | 26 scoped_ptr<views::LabelButtonBorder> border( |
25 new views::LabelButtonBorder(views::Button::STYLE_TEXTBUTTON)); | 27 new views::LabelButtonBorder(views::Button::STYLE_TEXTBUTTON)); |
26 border->SetPainter(false, views::Button::STATE_NORMAL, | 28 border->SetPainter(false, views::Button::STATE_NORMAL, |
27 views::Painter::CreateImageGridPainter(normal_image_set)); | 29 views::Painter::CreateImageGridPainter(normal_image_set)); |
28 border->SetPainter(false, views::Button::STATE_HOVERED, | 30 border->SetPainter(false, views::Button::STATE_HOVERED, |
29 views::Painter::CreateImageGridPainter(hot_image_set)); | 31 views::Painter::CreateImageGridPainter(hot_image_set)); |
30 border->SetPainter(false, views::Button::STATE_PRESSED, | 32 border->SetPainter(false, views::Button::STATE_PRESSED, |
(...skipping 21 matching lines...) Expand all Loading... | |
52 true), | 54 true), |
53 browser_(browser) { | 55 browser_(browser) { |
54 set_animate_on_state_change(false); | 56 set_animate_on_state_change(false); |
55 SetTextColor(views::Button::STATE_NORMAL, SK_ColorWHITE); | 57 SetTextColor(views::Button::STATE_NORMAL, SK_ColorWHITE); |
56 SetTextColor(views::Button::STATE_HOVERED, SK_ColorWHITE); | 58 SetTextColor(views::Button::STATE_HOVERED, SK_ColorWHITE); |
57 SetTextColor(views::Button::STATE_PRESSED, SK_ColorWHITE); | 59 SetTextColor(views::Button::STATE_PRESSED, SK_ColorWHITE); |
58 SetTextShadows(gfx::ShadowValues(10, | 60 SetTextShadows(gfx::ShadowValues(10, |
59 gfx::ShadowValue(gfx::Point(), 1.0f, SK_ColorDKGRAY))); | 61 gfx::ShadowValue(gfx::Point(), 1.0f, SK_ColorDKGRAY))); |
60 SetTextSubpixelRenderingEnabled(false); | 62 SetTextSubpixelRenderingEnabled(false); |
61 | 63 |
64 // Shrink large fonts to make them fit. | |
65 SetFontList(GetFontList().GetLargestFontListWithHeightBound( | |
66 kDisplayFontHeight)); | |
67 | |
62 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 68 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
63 if (button_style == THEMED_BUTTON) { | 69 if (button_style == THEMED_BUTTON) { |
64 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL); | 70 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL); |
65 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER); | 71 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER); |
66 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED); | 72 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED); |
67 | 73 |
68 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); | 74 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); |
69 set_menu_marker( | 75 set_menu_marker( |
70 rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_DROPARROW).ToImageSkia()); | 76 rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_DROPARROW).ToImageSkia()); |
71 #if defined(OS_WIN) | 77 #if defined(OS_WIN) |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 // We want the button to resize if the new text is shorter. | 157 // We want the button to resize if the new text is shorter. |
152 SetText(profiles::GetAvatarButtonTextForProfile(browser_->profile())); | 158 SetText(profiles::GetAvatarButtonTextForProfile(browser_->profile())); |
153 SetMinSize(gfx::Size()); | 159 SetMinSize(gfx::Size()); |
154 InvalidateLayout(); | 160 InvalidateLayout(); |
155 | 161 |
156 // Because the width of the button might have changed, the parent browser | 162 // Because the width of the button might have changed, the parent browser |
157 // frame needs to recalculate the button bounds and redraw it. | 163 // frame needs to recalculate the button bounds and redraw it. |
158 if (parent()) | 164 if (parent()) |
159 parent()->Layout(); | 165 parent()->Layout(); |
160 } | 166 } |
OLD | NEW |