username_view.h revision dc0f95d653279beabeb9817299e2902918ba123e
1// Copyright (c) 2010 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USERNAME_VIEW_H_ 6#define CHROME_BROWSER_CHROMEOS_LOGIN_USERNAME_VIEW_H_ 7#pragma once 8 9#include <string> 10 11#include "views/controls/label.h" 12#include "third_party/skia/include/core/SkBitmap.h" 13 14// Forward declaration. 15namespace gfx { 16 class Rect; 17} 18 19namespace chromeos { 20// Label with customized paddings and long text fade out. 21class UsernameView : public views::Label { 22 public: 23 virtual ~UsernameView() {} 24 25 // Returns the shaped username view to be used on the login screen. If 26 // |user_small_shape| is true, then one pixel margins are used. This is done 27 // to match the shape of the scaled frame of the user image. The caller gets 28 // the ownership. 29 // Empty |username| stands for guest user. 30 static UsernameView* CreateShapedUsernameView(const std::wstring& username, 31 bool use_small_shape); 32 33 protected: 34 // Constructs username view for the given |username|. Consider using 35 // |CreateShapedUsernameView| to match the login page style. 36 // Empty |username| stands for guest user. 37 UsernameView(const std::wstring& username, bool use_small_shape); 38 39 // Overriden from views::Label. 40 virtual void OnPaint(gfx::Canvas* canvas); 41 42 // True indicates that this UsernameView is used for a user pod not 43 // currently selected. 44 bool use_small_shape() const { return use_small_shape_; } 45 46 private: 47 // Overriden from View. 48 virtual gfx::NativeCursor GetCursorForPoint( 49 ui::EventType event_type, 50 const gfx::Point& p); 51 virtual void OnLocaleChanged(); 52 53 // Paints username to the bitmap with the bounds given. 54 void PaintUsername(const gfx::Rect& bounds); 55 56 // Holds painted username. 57 scoped_ptr<SkBitmap> text_image_; 58 59 // Holds margins width (depends on the height). 60 int margin_width_; 61 62 // Whether the shape for the smaller view should be used. 63 bool use_small_shape_; 64 65 // Whether it is a guest. 66 bool is_guest_; 67 68 DISALLOW_COPY_AND_ASSIGN(UsernameView); 69}; 70 71} // namespace chromeos 72 73#endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERNAME_VIEW_H_ 74