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 3// found in the LICENSE file. 4// 5// This file contains helper functions used by Chromium OS login. 6 7#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_HELPER_H_ 8#define CHROME_BROWSER_CHROMEOS_LOGIN_HELPER_H_ 9#pragma once 10 11#include "base/string16.h" 12#include "third_party/skia/include/core/SkColor.h" 13#include "views/controls/button/native_button.h" 14#include "views/view.h" 15#include "views/widget/widget_gtk.h" 16 17class GURL; 18 19namespace gfx { 20class Rect; 21class Size; 22} // namespace gfx 23 24namespace views { 25class Label; 26class MenuButton; 27class Painter; 28class SmoothedThrobber; 29class Textfield; 30class Throbber; 31class Widget; 32} // namespace views 33 34namespace chromeos { 35 36class NetworkLibrary; 37 38// View that provides interface for start/stop throbber above the view. 39class ThrobberHostView : public views::View { 40 public: 41 ThrobberHostView(); 42 virtual ~ThrobberHostView(); 43 44 // Creates throbber above the view in the right side with the default 45 // margin. Also places throbber in the middle of the vertical host size. 46 // Override |CalculateThrobberBounds| method to change the throbber placing. 47 virtual void StartThrobber(); 48 49 // Stops the throbber. 50 virtual void StopThrobber(); 51 52 protected: 53 // Calculates the bounds of the throbber relatively to the host view. 54 // Default position is vertically centered right side of the host view. 55 virtual gfx::Rect CalculateThrobberBounds(views::Throbber* throbber); 56 57 void set_host_view(views::View* host_view) { 58 host_view_ = host_view; 59 } 60 61 private: 62 // View to show the throbber above (default is |this|). 63 views::View* host_view_; 64 65 // Popup that contains the throbber. 66 views::Widget* throbber_widget_; 67 68 DISALLOW_COPY_AND_ASSIGN(ThrobberHostView); 69}; 70 71// Creates default smoothed throbber for time consuming operations on login. 72views::SmoothedThrobber* CreateDefaultSmoothedThrobber(); 73 74// Creates default throbber. 75views::Throbber* CreateDefaultThrobber(); 76 77// Creates painter for login background. 78views::Painter* CreateBackgroundPainter(); 79 80// Returns bounds of the screen to use for login wizard. 81// The rect is centered within the default monitor and sized accordingly if 82// |size| is not empty. Otherwise the whole monitor is occupied. 83gfx::Rect CalculateScreenBounds(const gfx::Size& size); 84 85// Corrects font size for Label control. 86void CorrectLabelFontSize(views::Label* label); 87 88// Corrects font size for MenuButton control. 89void CorrectMenuButtonFontSize(views::MenuButton* button); 90 91// Corrects font size for NativeButton control. 92void CorrectNativeButtonFontSize(views::NativeButton* button); 93 94// Corrects font size for Textfield control. 95void CorrectTextfieldFontSize(views::Textfield* textfield); 96 97// Sets font and corrects font size for Textfield control. 98void SetAndCorrectTextfieldFont(views::Textfield* textfield, 99 const gfx::Font& font); 100 101// Returns URL used for account recovery. 102GURL GetAccountRecoveryHelpUrl(); 103 104// Returns name of the currently connected network. 105// If there are no connected networks, returns name of the network 106// that is in the "connecting" state. Otherwise empty string is returned. 107// If there are multiple connected networks, network priority: 108// Ethernet > WiFi > Cellular. Same for connecting network. 109string16 GetCurrentNetworkName(NetworkLibrary* network_library); 110 111// Define the constants in |login| namespace to avoid potential 112// conflict with other chromeos components. 113namespace login { 114 115// Command tag for buttons on the lock screen. 116enum Command { 117 SIGN_OUT, 118}; 119 120// Gap between edge and image view, and image view and controls. 121const int kBorderSize = 10; 122 123// The size of user image. 124const int kUserImageSize = 256; 125 126// Background color of the login controls. 127const SkColor kBackgroundColor = SK_ColorWHITE; 128 129// Text color on the login controls. 130const SkColor kTextColor = SK_ColorWHITE; 131 132// Default link color on login/OOBE controls. 133const SkColor kLinkColor = 0xFF0066CC; 134 135// Right margin for placing throbber above the view. 136const int kThrobberRightMargin = 10; 137 138// Default size of the OOBE screen. Includes 10px shadow from each side. 139// See rounded_rect_painter.cc for border definitions. 140const int kWizardScreenWidth = 800; 141const int kWizardScreenHeight = 450; 142 143const int kScreenCornerRadius = 10; 144const int kUserCornerRadius = 6; 145 146// Username label height in different states. 147const int kSelectedLabelHeight = 25; 148const int kUnselectedLabelHeight = 20; 149 150// Minimal width for the button. 151const int kButtonMinWidth = 90; 152 153class WideButton : public views::NativeButton { 154 public: 155 WideButton(views::ButtonListener* listener, const std::wstring& text) 156 : NativeButton(listener, text) { 157 CorrectNativeButtonFontSize(this); 158 } 159 160 ~WideButton() {} 161 162 private: 163 virtual gfx::Size GetPreferredSize(); 164 165 DISALLOW_COPY_AND_ASSIGN(WideButton); 166}; 167 168} // namespace login 169 170// Font size correction in pixels for login/oobe controls. 171#if defined(CROS_FONTS_USING_BCI) 172const int kFontSizeCorrectionDelta = 1; 173const int kNetworkSelectionLabelFontDelta = 1; 174const int kSelectedUsernameFontDelta = 1; 175const int kUnselectedUsernameFontDelta = 1; 176const int kWelcomeTitleFontDelta = 8; 177const int kLoginTitleFontDelta = 3; 178#else 179const int kFontSizeCorrectionDelta = 2; 180const int kNetworkSelectionLabelFontDelta = 1; 181const int kSelectedUsernameFontDelta = 1; 182const int kUnselectedUsernameFontDelta = 2; 183const int kWelcomeTitleFontDelta = 9; 184const int kLoginTitleFontDelta = 4; 185#endif 186 187// New pod sizes. 188const int kNewUserPodFullWidth = 372; 189const int kNewUserPodFullHeight = 372; 190const int kNewUserPodSmallWidth = 360; 191const int kNewUserPodSmallHeight = 322; 192 193} // namespace chromeos 194 195#endif // CHROME_BROWSER_CHROMEOS_LOGIN_HELPER_H_ 196