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 "chrome/browser/ui/views/profiles/profile_chooser_view.h" | 12 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" |
13 #include "grit/theme_resources.h" | 13 #include "grit/theme_resources.h" |
14 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
15 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
16 #include "ui/views/border.h" | 16 #include "ui/views/border.h" |
17 #include "ui/views/controls/button/label_button_border.h" | 17 #include "ui/views/controls/button/label_button_border.h" |
18 #include "ui/views/painter.h" | 18 #include "ui/views/painter.h" |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // The largest text height that fits in the control. If the font list height | |
23 // is larger than this, it will be shrunk to match it. | |
24 const int kDisplayFontHeight = 15; | |
msw
2014/08/29 17:25:58
nit: move this constant down to where its used (fu
noms (inactive)
2014/08/29 18:03:20
Done.
| |
25 | |
22 scoped_ptr<views::Border> CreateBorder(const int normal_image_set[], | 26 scoped_ptr<views::Border> CreateBorder(const int normal_image_set[], |
23 const int hot_image_set[], | 27 const int hot_image_set[], |
24 const int pushed_image_set[]) { | 28 const int pushed_image_set[]) { |
25 scoped_ptr<views::LabelButtonBorder> border( | 29 scoped_ptr<views::LabelButtonBorder> border( |
26 new views::LabelButtonBorder(views::Button::STYLE_TEXTBUTTON)); | 30 new views::LabelButtonBorder(views::Button::STYLE_TEXTBUTTON)); |
27 border->SetPainter(false, views::Button::STATE_NORMAL, | 31 border->SetPainter(false, views::Button::STATE_NORMAL, |
28 views::Painter::CreateImageGridPainter(normal_image_set)); | 32 views::Painter::CreateImageGridPainter(normal_image_set)); |
29 border->SetPainter(false, views::Button::STATE_HOVERED, | 33 border->SetPainter(false, views::Button::STATE_HOVERED, |
30 views::Painter::CreateImageGridPainter(hot_image_set)); | 34 views::Painter::CreateImageGridPainter(hot_image_set)); |
31 border->SetPainter(false, views::Button::STATE_PRESSED, | 35 border->SetPainter(false, views::Button::STATE_PRESSED, |
(...skipping 22 matching lines...) Expand all Loading... | |
54 browser_(browser), | 58 browser_(browser), |
55 suppress_mouse_released_action_(false) { | 59 suppress_mouse_released_action_(false) { |
56 set_animate_on_state_change(false); | 60 set_animate_on_state_change(false); |
57 SetTextColor(views::Button::STATE_NORMAL, SK_ColorWHITE); | 61 SetTextColor(views::Button::STATE_NORMAL, SK_ColorWHITE); |
58 SetTextColor(views::Button::STATE_HOVERED, SK_ColorWHITE); | 62 SetTextColor(views::Button::STATE_HOVERED, SK_ColorWHITE); |
59 SetTextColor(views::Button::STATE_PRESSED, SK_ColorWHITE); | 63 SetTextColor(views::Button::STATE_PRESSED, SK_ColorWHITE); |
60 SetTextShadows(gfx::ShadowValues(10, | 64 SetTextShadows(gfx::ShadowValues(10, |
61 gfx::ShadowValue(gfx::Point(), 1.0f, SK_ColorDKGRAY))); | 65 gfx::ShadowValue(gfx::Point(), 1.0f, SK_ColorDKGRAY))); |
62 SetTextSubpixelRenderingEnabled(false); | 66 SetTextSubpixelRenderingEnabled(false); |
63 | 67 |
68 // Shrink large fonts to make them fit. | |
69 SetFontList(GetFontList().DeriveWithHeightUpperBound(kDisplayFontHeight)); | |
70 | |
64 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 71 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
65 if (button_style == THEMED_BUTTON) { | 72 if (button_style == THEMED_BUTTON) { |
66 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL); | 73 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL); |
67 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER); | 74 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER); |
68 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED); | 75 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED); |
69 | 76 |
70 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); | 77 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); |
71 set_menu_marker( | 78 set_menu_marker( |
72 rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_DROPARROW).ToImageSkia()); | 79 rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_DROPARROW).ToImageSkia()); |
73 #if defined(OS_WIN) | 80 #if defined(OS_WIN) |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 // We want the button to resize if the new text is shorter. | 178 // We want the button to resize if the new text is shorter. |
172 SetText(profiles::GetAvatarButtonTextForProfile(browser_->profile())); | 179 SetText(profiles::GetAvatarButtonTextForProfile(browser_->profile())); |
173 SetMinSize(gfx::Size()); | 180 SetMinSize(gfx::Size()); |
174 InvalidateLayout(); | 181 InvalidateLayout(); |
175 | 182 |
176 // Because the width of the button might have changed, the parent browser | 183 // Because the width of the button might have changed, the parent browser |
177 // frame needs to recalculate the button bounds and redraw it. | 184 // frame needs to recalculate the button bounds and redraw it. |
178 if (parent()) | 185 if (parent()) |
179 parent()->Layout(); | 186 parent()->Layout(); |
180 } | 187 } |
OLD | NEW |