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