summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoraltimofeev@chromium.org <altimofeev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-13 12:18:02 +0000
committeraltimofeev@chromium.org <altimofeev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-13 12:18:02 +0000
commitfdcf1be8a11acd9060fc3db1947dd1d78b568d9d (patch)
treea9bb4194fdf7e109e9bb27032b9b10d6a6ff58cd /chrome
parent4d83195858cce2e8bfdd58c36828be2bde9a34fa (diff)
downloadchromium_src-fdcf1be8a11acd9060fc3db1947dd1d78b568d9d.zip
chromium_src-fdcf1be8a11acd9060fc3db1947dd1d78b568d9d.tar.gz
chromium_src-fdcf1be8a11acd9060fc3db1947dd1d78b568d9d.tar.bz2
Username label customization.
Implemented left margin. Also implemented fade out in the end of the label. BUG=chromeos:7896 TEST=Compare with the mocks from the issue. Review URL: http://codereview.chromium.org/4708010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66060 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/chromeos/login/user_controller.cc35
-rw-r--r--chrome/browser/chromeos/login/username_view.cc108
-rw-r--r--chrome/browser/chromeos/login/username_view.h43
3 files changed, 110 insertions, 76 deletions
diff --git a/chrome/browser/chromeos/login/user_controller.cc b/chrome/browser/chromeos/login/user_controller.cc
index 022cc70..0fcb805 100644
--- a/chrome/browser/chromeos/login/user_controller.cc
+++ b/chrome/browser/chromeos/login/user_controller.cc
@@ -49,6 +49,13 @@ const int kUserNameGap = 4;
// case to make border window size close to existing users.
const int kControlsHeight = 28;
+// Username label height in different states.
+const int kSelectedLabelHeight = 25;
+const int kUnselectedLabelHeight = 20;
+
+// Delta for the unselected username font.
+const int kUnselectedUsernameFontDelta = 1;
+
// Widget that notifies window manager about clicking on itself.
// Doesn't send anything if user is selected.
class ClickNotifyingWidget : public views::WidgetGtk {
@@ -437,8 +444,9 @@ WidgetGtk* UserController::CreateLabelWindow(int index,
WmIpcWindowType type) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
const gfx::Font& font = (type == WM_IPC_WINDOW_LOGIN_LABEL) ?
- rb.GetFont(ResourceBundle::LargeFont).DeriveFont(0, gfx::Font::BOLD) :
- rb.GetFont(ResourceBundle::BaseFont).DeriveFont(0, gfx::Font::BOLD);
+ rb.GetFont(ResourceBundle::MediumBoldFont) :
+ rb.GetFont(ResourceBundle::BaseFont).DeriveFont(
+ kUnselectedUsernameFontDelta, gfx::Font::BOLD);
std::wstring text;
if (is_guest_) {
text = l10n_util::GetString(IDS_GUEST);
@@ -451,19 +459,11 @@ WidgetGtk* UserController::CreateLabelWindow(int index,
text = UTF8ToWide(user_.GetDisplayName());
}
- views::Label *label;
- views::View *view;
- if (is_new_user_) {
- label = new views::Label(text);
- label->SetColor(kTextColor);
- label->SetFont(font);
- view = label;
- } else {
- UsernameView* username_view = new UsernameView(text);
- username_view->SetFont(font);
- label = username_view->label();
- view = username_view;
- }
+ views::Label *label = is_new_user_ ?
+ new views::Label(text) : new UsernameView(text);
+
+ label->SetColor(kTextColor);
+ label->SetFont(font);
if (type == WM_IPC_WINDOW_LOGIN_LABEL)
label_view_ = label;
@@ -476,13 +476,14 @@ WidgetGtk* UserController::CreateLabelWindow(int index,
// Make label as small as possible to don't show tooltip.
width = 0;
}
- int height = label->GetPreferredSize().height();
+ int height = (type == WM_IPC_WINDOW_LOGIN_LABEL) ?
+ kSelectedLabelHeight : kUnselectedLabelHeight;
WidgetGtk* window = new ClickNotifyingWidget(WidgetGtk::TYPE_WINDOW, this);
ConfigureLoginWindow(window,
index,
gfx::Rect(0, 0, width, height),
type,
- view);
+ label);
return window;
}
diff --git a/chrome/browser/chromeos/login/username_view.cc b/chrome/browser/chromeos/login/username_view.cc
index 783c9cd..750c788 100644
--- a/chrome/browser/chromeos/login/username_view.cc
+++ b/chrome/browser/chromeos/login/username_view.cc
@@ -4,56 +4,92 @@
#include "chrome/browser/chromeos/login/username_view.h"
-#include "chrome/browser/chromeos/login/helper.h"
+#include "base/logging.h"
+#include "gfx/canvas.h"
+#include "gfx/canvas_skia.h"
+#include "gfx/rect.h"
+#include "third_party/skia/include/core/SkComposeShader.h"
+#include "third_party/skia/include/effects/SkGradientShader.h"
#include "views/background.h"
-#include "views/painter.h"
-#include "views/controls/label.h"
namespace {
// Username label background color.
const SkColor kLabelBackgoundColor = 0x55000000;
+// Holds margin to height ratio.
+const double kMarginRatio = 1.0 / 3.0;
} // namespace
namespace chromeos {
-UsernameView::UsernameView(const std::wstring& username) {
- label_ = new views::Label(username);
- label_->SetColor(login::kTextColor);
- label_->set_background(
- views::Background::CreateSolidBackground(kLabelBackgoundColor));
- label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- AddChildView(label_);
-
- gradient_ = new views::View;
- gradient_->SetVisible(false);
- views::Background* gradient_background =
- views::Background::CreateBackgroundPainter(true,
- views::Painter::CreateHorizontalGradient(
- kLabelBackgoundColor, 0x00000000));
- gradient_->set_background(gradient_background);
- AddChildView(gradient_);
+UsernameView::UsernameView(const std::wstring& username)
+ : views::Label(username) {
}
-void UsernameView::SetFont(const gfx::Font& font) {
- label_->SetFont(font);
-}
+void UsernameView::Paint(gfx::Canvas* canvas) {
+ gfx::Rect bounds = GetLocalBounds(false);
+ if (!text_image_.get())
+ PaintUsername(bounds);
+
+ DCHECK(bounds.size() ==
+ gfx::Size(text_image_->width(), text_image_->height()));
+
+ // Only alpha channel counts.
+ SkColor gradient_colors[2];
+ gradient_colors[0] = 0xFFFFFFFF;
+ gradient_colors[1] = 0x00FFFFFF;
+
+ int gradient_start = std::min(margin_width_ + text_width_,
+ bounds.width() - bounds.height());
-// views::View
-void UsernameView::Layout() {
- int text_width = std::min(label_->GetPreferredSize().width(), width());
- label_->SetBounds(0, 0, text_width, height());
- int gradient_width = std::min(width() - text_width, height());
- if (gradient_width > 0) {
- gradient_->SetVisible(true);
- gradient_->SetBounds(0 + text_width, 0, gradient_width, height());
- } else {
- // No place for the gradient part.
- gradient_->SetVisible(false);
- }
+ SkPoint gradient_borders[2];
+ gradient_borders[0].set(SkIntToScalar(gradient_start), SkIntToScalar(0));
+ gradient_borders[1].set(SkIntToScalar(
+ gradient_start + bounds.height()), SkIntToScalar(0));
+
+ SkShader* gradient_shader =
+ SkGradientShader::CreateLinear(gradient_borders, gradient_colors, NULL, 2,
+ SkShader::kClamp_TileMode, NULL);
+ SkShader* image_shader = SkShader::CreateBitmapShader(
+ *text_image_,
+ SkShader::kRepeat_TileMode,
+ SkShader::kRepeat_TileMode);
+
+ SkXfermode* mode = SkXfermode::Create(SkXfermode::kSrcIn_Mode);
+ SkShader* composite_shader = new SkComposeShader(gradient_shader,
+ image_shader, mode);
+ gradient_shader->unref();
+ image_shader->unref();
+
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setFilterBitmap(true);
+ paint.setShader(composite_shader)->unref();
+ canvas->DrawRectInt(bounds.x(), bounds.y(),
+ bounds.width(), bounds.height(), paint);
}
-gfx::Size UsernameView::GetPreferredSize() {
- return label_->GetPreferredSize();
+void UsernameView::PaintUsername(const gfx::Rect& bounds) {
+ margin_width_ = bounds.height() * kMarginRatio;
+ gfx::CanvasSkia canvas(bounds.width(), bounds.height(), false);
+ // Draw background.
+ canvas.drawColor(kLabelBackgoundColor);
+ // Calculate needed space.
+ int flags = gfx::Canvas::TEXT_ALIGN_LEFT |
+ gfx::Canvas::TEXT_VALIGN_MIDDLE |
+ gfx::Canvas::NO_ELLIPSIS;
+ int text_height;
+ gfx::CanvasSkia::SizeStringInt(GetText(), font(),
+ &text_width_, &text_height,
+ flags);
+ text_width_ = std::min(text_width_, bounds.width() - margin_width_);
+ // Draw the text.
+ canvas.DrawStringInt(GetText(), font(), GetColor(),
+ bounds.x() + margin_width_, bounds.y(),
+ bounds.width() - margin_width_, bounds.height(),
+ flags);
+
+ text_image_.reset(new SkBitmap(canvas.ExtractBitmap()));
+ text_image_->buildMipMap(false);
}
} // namespace chromeos
diff --git a/chrome/browser/chromeos/login/username_view.h b/chrome/browser/chromeos/login/username_view.h
index 856a609..f1ad180 100644
--- a/chrome/browser/chromeos/login/username_view.h
+++ b/chrome/browser/chromeos/login/username_view.h
@@ -8,39 +8,36 @@
#include <string>
-#include "views/view.h"
+#include "views/controls/label.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+// Forward declaration.
namespace gfx {
-class Font;
-} // namespace gfx
-
-namespace views {
-class Label;
-} // namespace views
+ class Rect;
+}
namespace chromeos {
-// View that contains two parts. First one is a label with username, second one
-// is an empty view with gradient transparency background.
-class UsernameView : public views::View {
+// Label with customized paddings and long text fade out.
+class UsernameView : public views::Label {
public:
- explicit UsernameView(const std::wstring& username);
+ UsernameView(const std::wstring& username);
virtual ~UsernameView() {}
- // Set the font of the username text.
- void SetFont(const gfx::Font& font);
+ // Overriden from views::Label.
+ virtual void Paint(gfx::Canvas* canvas);
+
+ private:
+ // Paints username to the bitmap with the bounds given.
+ void PaintUsername(const gfx::Rect& bounds);
- // Returns username label.
- views::Label* label() const {
- return label_;
- }
+ // Holds painted username.
+ scoped_ptr<SkBitmap> text_image_;
- // views::View overrides.
- virtual void Layout();
- virtual gfx::Size GetPreferredSize();
+ // Holds width of the text drawn.
+ int text_width_;
- private:
- views::Label* label_;
- views::View* gradient_;
+ // Holds margins width (depends on the height).
+ int margin_width_;
DISALLOW_COPY_AND_ASSIGN(UsernameView);
};