Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: chrome/browser/ui/views/new_avatar_button.cc

Issue 145033006: views: Make View::set_border() take a scoped_ptr<>. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to ToT Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/new_avatar_button.h" 5 #include "chrome/browser/ui/views/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 "grit/generated_resources.h" 11 #include "grit/generated_resources.h"
12 #include "grit/theme_resources.h" 12 #include "grit/theme_resources.h"
13 #include "ui/base/l10n/l10n_util.h" 13 #include "ui/base/l10n/l10n_util.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/gfx/color_utils.h" 16 #include "ui/gfx/color_utils.h"
17 #include "ui/gfx/font_list.h" 17 #include "ui/gfx/font_list.h"
18 #include "ui/gfx/text_elider.h" 18 #include "ui/gfx/text_elider.h"
19 #include "ui/views/border.h" 19 #include "ui/views/border.h"
20 #include "ui/views/painter.h" 20 #include "ui/views/painter.h"
21 21
22 namespace { 22 namespace {
23 23
24 // Text padding within the button border. 24 // Text padding within the button border.
25 const int kInset = 10; 25 const int kInset = 10;
26 26
27 views::TextButtonDefaultBorder* CreateBorder(const int normal_image_set[], 27 scoped_ptr<views::Border> CreateBorder(const int normal_image_set[],
28 const int hot_image_set[], 28 const int hot_image_set[],
29 const int pushed_image_set[]) { 29 const int pushed_image_set[]) {
30 views::TextButtonDefaultBorder* border = new views::TextButtonDefaultBorder(); 30 scoped_ptr<views::TextButtonDefaultBorder> border(
31 new views::TextButtonDefaultBorder());
31 32
32 border->SetInsets(gfx::Insets(kInset, kInset, kInset, kInset)); 33 border->SetInsets(gfx::Insets(kInset, kInset, kInset, kInset));
33 border->set_normal_painter( 34 border->set_normal_painter(
34 views::Painter::CreateImageGridPainter(normal_image_set)); 35 views::Painter::CreateImageGridPainter(normal_image_set));
35 border->set_hot_painter( 36 border->set_hot_painter(
36 views::Painter::CreateImageGridPainter(hot_image_set)); 37 views::Painter::CreateImageGridPainter(hot_image_set));
37 border->set_pushed_painter( 38 border->set_pushed_painter(
38 views::Painter::CreateImageGridPainter(pushed_image_set)); 39 views::Painter::CreateImageGridPainter(pushed_image_set));
39 40
40 return border; 41 return border.PassAs<views::Border>();
41 } 42 }
42 43
43 base::string16 GetElidedText(const base::string16& original_text) { 44 base::string16 GetElidedText(const base::string16& original_text) {
44 // Maximum characters the button can be before the text will get elided. 45 // Maximum characters the button can be before the text will get elided.
45 const int kMaxCharactersToDisplay = 15; 46 const int kMaxCharactersToDisplay = 15;
46 47
47 const gfx::FontList font_list; 48 const gfx::FontList font_list;
48 return gfx::ElideText( 49 return gfx::ElideText(
49 original_text, 50 original_text,
50 font_list, 51 font_list,
(...skipping 17 matching lines...) Expand all
68 bool is_win8 = false; 69 bool is_win8 = false;
69 #if defined(OS_WIN) 70 #if defined(OS_WIN)
70 is_win8 = base::win::GetVersion() >= base::win::VERSION_WIN8; 71 is_win8 = base::win::GetVersion() >= base::win::VERSION_WIN8;
71 #endif 72 #endif
72 73
73 if (button_style == THEMED_BUTTON) { 74 if (button_style == THEMED_BUTTON) {
74 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL); 75 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL);
75 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER); 76 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER);
76 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED); 77 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED);
77 78
78 set_border(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); 79 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet));
79 set_menu_marker( 80 set_menu_marker(
80 rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_DROPARROW).ToImageSkia()); 81 rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_DROPARROW).ToImageSkia());
81 } else if (is_win8) { 82 } else if (is_win8) {
82 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_NORMAL); 83 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_NORMAL);
83 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_HOVER); 84 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_HOVER);
84 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_PRESSED); 85 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_PRESSED);
85 86
86 set_border(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); 87 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet));
87 set_menu_marker( 88 set_menu_marker(
88 rb->GetImageNamed(IDR_AVATAR_METRO_BUTTON_DROPARROW).ToImageSkia()); 89 rb->GetImageNamed(IDR_AVATAR_METRO_BUTTON_DROPARROW).ToImageSkia());
89 } else { 90 } else {
90 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL); 91 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL);
91 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_HOVER); 92 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_HOVER);
92 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED); 93 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED);
93 94
94 set_border(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); 95 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet));
95 set_menu_marker( 96 set_menu_marker(
96 rb->GetImageNamed(IDR_AVATAR_GLASS_BUTTON_DROPARROW).ToImageSkia()); 97 rb->GetImageNamed(IDR_AVATAR_GLASS_BUTTON_DROPARROW).ToImageSkia());
97 } 98 }
98 99
99 avatar_menu_.reset(new AvatarMenu( 100 avatar_menu_.reset(new AvatarMenu(
100 &g_browser_process->profile_manager()->GetProfileInfoCache(), 101 &g_browser_process->profile_manager()->GetProfileInfoCache(),
101 this, 102 this,
102 browser_)); 103 browser_));
103 avatar_menu_->RebuildMenu(); 104 avatar_menu_->RebuildMenu();
104 105
(...skipping 30 matching lines...) Expand all
135 136
136 void NewAvatarButton::OnAvatarMenuChanged(AvatarMenu* avatar_menu) { 137 void NewAvatarButton::OnAvatarMenuChanged(AvatarMenu* avatar_menu) {
137 // We want the button to resize if the new text is shorter. 138 // We want the button to resize if the new text is shorter.
138 ClearMaxTextSize(); 139 ClearMaxTextSize();
139 SetText(GetElidedText(profiles::GetActiveProfileDisplayName(browser_))); 140 SetText(GetElidedText(profiles::GetActiveProfileDisplayName(browser_)));
140 141
141 // Because the width of the button might have changed, the parent browser 142 // Because the width of the button might have changed, the parent browser
142 // frame needs to recalculate the button bounds and redraw it. 143 // frame needs to recalculate the button bounds and redraw it.
143 parent()->Layout(); 144 parent()->Layout();
144 } 145 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698