| OLD | NEW |
| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/chromeos/login/rounded_view.h" | 9 #include "chrome/browser/chromeos/login/rounded_view.h" |
| 10 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 } | 56 } |
| 57 | 57 |
| 58 gfx::NativeCursor UsernameView::GetCursor(const views::MouseEvent& event) { | 58 gfx::NativeCursor UsernameView::GetCursor(const views::MouseEvent& event) { |
| 59 return use_small_shape_ ? gfx::GetCursor(GDK_HAND2) : NULL; | 59 return use_small_shape_ ? gfx::GetCursor(GDK_HAND2) : NULL; |
| 60 } | 60 } |
| 61 | 61 |
| 62 void UsernameView::PaintUsername(const gfx::Rect& bounds) { | 62 void UsernameView::PaintUsername(const gfx::Rect& bounds) { |
| 63 margin_width_ = bounds.height() * kMarginRatio; | 63 margin_width_ = bounds.height() * kMarginRatio; |
| 64 gfx::CanvasSkia canvas(bounds.width(), bounds.height(), false); | 64 gfx::CanvasSkia canvas(bounds.width(), bounds.height(), false); |
| 65 // Draw transparent background. | 65 // Draw transparent background. |
| 66 canvas.drawColor(0); | 66 canvas.sk_canvas()->drawColor(0); |
| 67 | 67 |
| 68 // Calculate needed space. | 68 // Calculate needed space. |
| 69 int flags = gfx::Canvas::TEXT_ALIGN_LEFT | | 69 int flags = gfx::Canvas::TEXT_ALIGN_LEFT | |
| 70 gfx::Canvas::TEXT_VALIGN_MIDDLE | | 70 gfx::Canvas::TEXT_VALIGN_MIDDLE | |
| 71 gfx::Canvas::NO_ELLIPSIS; | 71 gfx::Canvas::NO_ELLIPSIS; |
| 72 int text_height, text_width; | 72 int text_height, text_width; |
| 73 gfx::CanvasSkia::SizeStringInt(WideToUTF16Hack(GetText()), font(), | 73 gfx::CanvasSkia::SizeStringInt(WideToUTF16Hack(GetText()), font(), |
| 74 &text_width, &text_height, | 74 &text_width, &text_height, |
| 75 flags); | 75 flags); |
| 76 text_width += margin_width_; | 76 text_width += margin_width_; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 101 // Draw the final background with the fading in the end. | 101 // Draw the final background with the fading in the end. |
| 102 SkShader* solid_shader = new SkColorShader(kLabelBackgoundColor); | 102 SkShader* solid_shader = new SkColorShader(kLabelBackgoundColor); |
| 103 SkXfermode* mode = SkXfermode::Create(SkXfermode::kSrcIn_Mode); | 103 SkXfermode* mode = SkXfermode::Create(SkXfermode::kSrcIn_Mode); |
| 104 SkShader* composite_shader = new SkComposeShader(gradient_shader, | 104 SkShader* composite_shader = new SkComposeShader(gradient_shader, |
| 105 solid_shader, mode); | 105 solid_shader, mode); |
| 106 gradient_shader->unref(); | 106 gradient_shader->unref(); |
| 107 solid_shader->unref(); | 107 solid_shader->unref(); |
| 108 | 108 |
| 109 SkPaint paint; | 109 SkPaint paint; |
| 110 paint.setShader(composite_shader)->unref(); | 110 paint.setShader(composite_shader)->unref(); |
| 111 canvas.drawPaint(paint); | 111 canvas.sk_canvas()->drawPaint(paint); |
| 112 } | 112 } |
| 113 | 113 |
| 114 // Draw the text. | 114 // Draw the text. |
| 115 // Note, direct call of the DrawStringInt method produces the green dots | 115 // Note, direct call of the DrawStringInt method produces the green dots |
| 116 // 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). |
| 117 SkColor kInvisibleHaloColor = 0x00000000; | 117 SkColor kInvisibleHaloColor = 0x00000000; |
| 118 canvas.DrawStringWithHalo(WideToUTF16Hack(GetText()), font(), GetColor(), | 118 canvas.DrawStringWithHalo(WideToUTF16Hack(GetText()), font(), GetColor(), |
| 119 kInvisibleHaloColor, bounds.x() + margin_width_, | 119 kInvisibleHaloColor, bounds.x() + margin_width_, |
| 120 bounds.y(), bounds.width() - 2 * margin_width_, | 120 bounds.y(), bounds.width() - 2 * margin_width_, |
| 121 bounds.height(), flags); | 121 bounds.height(), flags); |
| 122 | 122 |
| 123 text_image_.reset(new SkBitmap(canvas.ExtractBitmap())); | 123 text_image_.reset(new SkBitmap(canvas.ExtractBitmap())); |
| 124 | 124 |
| 125 if (use_fading_for_text) { | 125 if (use_fading_for_text) { |
| 126 // Fade out only the text in the end. Use regular background. | 126 // Fade out only the text in the end. Use regular background. |
| 127 canvas.drawColor(kLabelBackgoundColor, SkXfermode::kSrc_Mode); | 127 canvas.sk_canvas()->drawColor(kLabelBackgoundColor, SkXfermode::kSrc_Mode); |
| 128 SkShader* image_shader = SkShader::CreateBitmapShader( | 128 SkShader* image_shader = SkShader::CreateBitmapShader( |
| 129 *text_image_, | 129 *text_image_, |
| 130 SkShader::kRepeat_TileMode, | 130 SkShader::kRepeat_TileMode, |
| 131 SkShader::kRepeat_TileMode); | 131 SkShader::kRepeat_TileMode); |
| 132 SkXfermode* mode = SkXfermode::Create(SkXfermode::kSrcIn_Mode); | 132 SkXfermode* mode = SkXfermode::Create(SkXfermode::kSrcIn_Mode); |
| 133 SkShader* composite_shader = new SkComposeShader(gradient_shader, | 133 SkShader* composite_shader = new SkComposeShader(gradient_shader, |
| 134 image_shader, mode); | 134 image_shader, mode); |
| 135 gradient_shader->unref(); | 135 gradient_shader->unref(); |
| 136 image_shader->unref(); | 136 image_shader->unref(); |
| 137 | 137 |
| 138 SkPaint paint; | 138 SkPaint paint; |
| 139 paint.setShader(composite_shader)->unref(); | 139 paint.setShader(composite_shader)->unref(); |
| 140 canvas.drawPaint(paint); | 140 canvas.sk_canvas()->drawPaint(paint); |
| 141 text_image_.reset(new SkBitmap(canvas.ExtractBitmap())); | 141 text_image_.reset(new SkBitmap(canvas.ExtractBitmap())); |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 | 144 |
| 145 void UsernameView::OnLocaleChanged() { | 145 void UsernameView::OnLocaleChanged() { |
| 146 if (is_guest_) { | 146 if (is_guest_) { |
| 147 SetText(UTF16ToWide(l10n_util::GetStringUTF16(IDS_GUEST))); | 147 SetText(UTF16ToWide(l10n_util::GetStringUTF16(IDS_GUEST))); |
| 148 } | 148 } |
| 149 // Repaint because the font may have changed. | 149 // Repaint because the font may have changed. |
| 150 text_image_.reset(); | 150 text_image_.reset(); |
| 151 SchedulePaint(); | 151 SchedulePaint(); |
| 152 } | 152 } |
| 153 | 153 |
| 154 } // namespace chromeos | 154 } // namespace chromeos |
| OLD | NEW |