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

Side by Side Diff: chrome/browser/chromeos/login/username_view.cc

Issue 8142026: Revert 104076 - Change std::wstring to string16 for views::Link (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 2 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/chromeos/login/username_view.h" 5 #include "chrome/browser/chromeos/login/username_view.h"
6 6
7 #include <algorithm>
8
9 #include "base/logging.h" 7 #include "base/logging.h"
10 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/chromeos/login/rounded_view.h" 9 #include "chrome/browser/chromeos/login/rounded_view.h"
12 #include "grit/generated_resources.h" 10 #include "grit/generated_resources.h"
13 #include "third_party/skia/include/core/SkColorShader.h" 11 #include "third_party/skia/include/core/SkColorShader.h"
14 #include "third_party/skia/include/core/SkComposeShader.h" 12 #include "third_party/skia/include/core/SkComposeShader.h"
15 #include "third_party/skia/include/effects/SkGradientShader.h" 13 #include "third_party/skia/include/effects/SkGradientShader.h"
16 #include "ui/base/l10n/l10n_util.h" 14 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/resource/resource_bundle.h" 15 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/gfx/canvas.h" 16 #include "ui/gfx/canvas.h"
19 #include "ui/gfx/canvas_skia.h" 17 #include "ui/gfx/canvas_skia.h"
20 #include "ui/gfx/gtk_util.h" 18 #include "ui/gfx/gtk_util.h"
21 #include "ui/gfx/rect.h" 19 #include "ui/gfx/rect.h"
22 20
23 namespace chromeos { 21 namespace chromeos {
24 22
25 namespace { 23 namespace {
26 // Username label background color. 24 // Username label background color.
27 const SkColor kLabelBackgoundColor = 0x55000000; 25 const SkColor kLabelBackgoundColor = 0x55000000;
28 // Holds margin to height ratio. 26 // Holds margin to height ratio.
29 const double kMarginRatio = 1.0 / 3.0; 27 const double kMarginRatio = 1.0 / 3.0;
28 // Holds the frame width for the small shaped username view.
29 const SkScalar kSmallShapeFrameWidth = SkIntToScalar(1);
30
30 } // namespace 31 } // namespace
31 32
32 UsernameView::UsernameView(const std::wstring& username, bool use_small_shape) 33 UsernameView::UsernameView(const std::wstring& username, bool use_small_shape)
33 : views::Label(username.empty() 34 : views::Label(username.empty()
34 ? l10n_util::GetStringUTF16(IDS_GUEST) : WideToUTF16Hack(username)), 35 ? UTF16ToWide(l10n_util::GetStringUTF16(IDS_GUEST)) : username),
35 use_small_shape_(use_small_shape), 36 use_small_shape_(use_small_shape),
36 is_guest_(username.empty()) { 37 is_guest_(username.empty()) {
37 } 38 }
38 39
39 UsernameView::~UsernameView() {} 40 UsernameView::~UsernameView() {}
40 41
41 void UsernameView::OnPaint(gfx::Canvas* canvas) { 42 void UsernameView::OnPaint(gfx::Canvas* canvas) {
42 gfx::Rect bounds = GetContentsBounds(); 43 gfx::Rect bounds = GetContentsBounds();
43 if (text_image_ == NULL) 44 if (text_image_ == NULL)
44 PaintUsername(bounds); 45 PaintUsername(bounds);
(...skipping 17 matching lines...) Expand all
62 margin_width_ = bounds.height() * kMarginRatio; 63 margin_width_ = bounds.height() * kMarginRatio;
63 gfx::CanvasSkia canvas(bounds.width(), bounds.height(), false); 64 gfx::CanvasSkia canvas(bounds.width(), bounds.height(), false);
64 // Draw transparent background. 65 // Draw transparent background.
65 canvas.drawColor(0); 66 canvas.drawColor(0);
66 67
67 // Calculate needed space. 68 // Calculate needed space.
68 int flags = gfx::Canvas::TEXT_ALIGN_LEFT | 69 int flags = gfx::Canvas::TEXT_ALIGN_LEFT |
69 gfx::Canvas::TEXT_VALIGN_MIDDLE | 70 gfx::Canvas::TEXT_VALIGN_MIDDLE |
70 gfx::Canvas::NO_ELLIPSIS; 71 gfx::Canvas::NO_ELLIPSIS;
71 int text_height, text_width; 72 int text_height, text_width;
72 gfx::CanvasSkia::SizeStringInt(GetText(), font(), 73 gfx::CanvasSkia::SizeStringInt(WideToUTF16Hack(GetText()), font(),
73 &text_width, &text_height, 74 &text_width, &text_height,
74 flags); 75 flags);
75 text_width += margin_width_; 76 text_width += margin_width_;
76 77
77 // Also leave the right margin. 78 // Also leave the right margin.
78 bool use_fading_for_text = text_width + margin_width_ >= bounds.width(); 79 bool use_fading_for_text = text_width + margin_width_ >= bounds.width();
79 80
80 // Only alpha channel counts. 81 // Only alpha channel counts.
81 SkColor gradient_colors[2]; 82 SkColor gradient_colors[2];
82 gradient_colors[0] = 0xFFFFFFFF; 83 gradient_colors[0] = 0xFFFFFFFF;
(...skipping 24 matching lines...) Expand all
107 108
108 SkPaint paint; 109 SkPaint paint;
109 paint.setShader(composite_shader)->unref(); 110 paint.setShader(composite_shader)->unref();
110 canvas.drawPaint(paint); 111 canvas.drawPaint(paint);
111 } 112 }
112 113
113 // Draw the text. 114 // Draw the text.
114 // Note, direct call of the DrawStringInt method produces the green dots 115 // Note, direct call of the DrawStringInt method produces the green dots
115 // along the text perimeter (when the label is place on the white background). 116 // along the text perimeter (when the label is place on the white background).
116 SkColor kInvisibleHaloColor = 0x00000000; 117 SkColor kInvisibleHaloColor = 0x00000000;
117 canvas.DrawStringWithHalo(GetText(), font(), GetColor(), 118 canvas.DrawStringWithHalo(WideToUTF16Hack(GetText()), font(), GetColor(),
118 kInvisibleHaloColor, bounds.x() + margin_width_, 119 kInvisibleHaloColor, bounds.x() + margin_width_,
119 bounds.y(), bounds.width() - 2 * margin_width_, 120 bounds.y(), bounds.width() - 2 * margin_width_,
120 bounds.height(), flags); 121 bounds.height(), flags);
121 122
122 text_image_.reset(new SkBitmap(canvas.ExtractBitmap())); 123 text_image_.reset(new SkBitmap(canvas.ExtractBitmap()));
123 124
124 if (use_fading_for_text) { 125 if (use_fading_for_text) {
125 // Fade out only the text in the end. Use regular background. 126 // Fade out only the text in the end. Use regular background.
126 canvas.drawColor(kLabelBackgoundColor, SkXfermode::kSrc_Mode); 127 canvas.drawColor(kLabelBackgoundColor, SkXfermode::kSrc_Mode);
127 SkShader* image_shader = SkShader::CreateBitmapShader( 128 SkShader* image_shader = SkShader::CreateBitmapShader(
128 *text_image_, 129 *text_image_,
129 SkShader::kRepeat_TileMode, 130 SkShader::kRepeat_TileMode,
130 SkShader::kRepeat_TileMode); 131 SkShader::kRepeat_TileMode);
131 SkXfermode* mode = SkXfermode::Create(SkXfermode::kSrcIn_Mode); 132 SkXfermode* mode = SkXfermode::Create(SkXfermode::kSrcIn_Mode);
132 SkShader* composite_shader = new SkComposeShader(gradient_shader, 133 SkShader* composite_shader = new SkComposeShader(gradient_shader,
133 image_shader, mode); 134 image_shader, mode);
134 gradient_shader->unref(); 135 gradient_shader->unref();
135 image_shader->unref(); 136 image_shader->unref();
136 137
137 SkPaint paint; 138 SkPaint paint;
138 paint.setShader(composite_shader)->unref(); 139 paint.setShader(composite_shader)->unref();
139 canvas.drawPaint(paint); 140 canvas.drawPaint(paint);
140 text_image_.reset(new SkBitmap(canvas.ExtractBitmap())); 141 text_image_.reset(new SkBitmap(canvas.ExtractBitmap()));
141 } 142 }
142 } 143 }
143 144
144 void UsernameView::OnLocaleChanged() { 145 void UsernameView::OnLocaleChanged() {
145 if (is_guest_) { 146 if (is_guest_) {
146 SetText(l10n_util::GetStringUTF16(IDS_GUEST)); 147 SetText(UTF16ToWide(l10n_util::GetStringUTF16(IDS_GUEST)));
147 } 148 }
148 // Repaint because the font may have changed. 149 // Repaint because the font may have changed.
149 text_image_.reset(); 150 text_image_.reset();
150 SchedulePaint(); 151 SchedulePaint();
151 } 152 }
152 153
153 } // namespace chromeos 154 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/user_view.cc ('k') | chrome/browser/chromeos/login/web_page_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698