Chromium Code Reviews| 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 kDisplayFontSize = 13; | |
| 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 // If the default font size is larger than the expected one, derive | |
| 65 // the correct font size to match it. | |
| 66 int font_size = GetFontList().GetFontSize(); | |
| 67 if (font_size > kDisplayFontSize) { | |
| 68 SetFontList(GetFontList().DeriveWithSizeDelta( | |
|
msw
2014/08/25 19:17:20
I think we might need to use the font height inste
noms (inactive)
2014/08/25 19:19:36
I originally had the font height, but it didn't se
msw
2014/08/25 19:43:48
Unfortunately, what you had may have been "right".
noms (inactive)
2014/08/25 20:06:02
So what I had was:
const int kDisplayFontSize =
msw
2014/08/25 20:13:51
No, you can't interchange font height and size val
| |
| 69 kDisplayFontSize - font_size - 1)); | |
| 70 } | |
| 71 | |
| 62 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 72 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 63 if (button_style == THEMED_BUTTON) { | 73 if (button_style == THEMED_BUTTON) { |
| 64 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL); | 74 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL); |
| 65 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER); | 75 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER); |
| 66 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED); | 76 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED); |
| 67 | 77 |
| 68 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); | 78 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); |
| 69 set_menu_marker( | 79 set_menu_marker( |
| 70 rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_DROPARROW).ToImageSkia()); | 80 rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_DROPARROW).ToImageSkia()); |
| 71 #if defined(OS_WIN) | 81 #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. | 161 // We want the button to resize if the new text is shorter. |
| 152 SetText(profiles::GetAvatarButtonTextForProfile(browser_->profile())); | 162 SetText(profiles::GetAvatarButtonTextForProfile(browser_->profile())); |
| 153 SetMinSize(gfx::Size()); | 163 SetMinSize(gfx::Size()); |
| 154 InvalidateLayout(); | 164 InvalidateLayout(); |
| 155 | 165 |
| 156 // Because the width of the button might have changed, the parent browser | 166 // Because the width of the button might have changed, the parent browser |
| 157 // frame needs to recalculate the button bounds and redraw it. | 167 // frame needs to recalculate the button bounds and redraw it. |
| 158 if (parent()) | 168 if (parent()) |
| 159 parent()->Layout(); | 169 parent()->Layout(); |
| 160 } | 170 } |
| OLD | NEW |