Home | History | Annotate | Download | only in login
      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 
     17 class GURL;
     18 
     19 namespace gfx {
     20 class Rect;
     21 class Size;
     22 }  // namespace gfx
     23 
     24 namespace views {
     25 class Label;
     26 class MenuButton;
     27 class Painter;
     28 class SmoothedThrobber;
     29 class Textfield;
     30 class Throbber;
     31 class Widget;
     32 }  // namespace views
     33 
     34 namespace chromeos {
     35 
     36 class NetworkLibrary;
     37 
     38 // View that provides interface for start/stop throbber above the view.
     39 class 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.
     72 views::SmoothedThrobber* CreateDefaultSmoothedThrobber();
     73 
     74 // Creates default throbber.
     75 views::Throbber* CreateDefaultThrobber();
     76 
     77 // Creates painter for login background.
     78 views::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.
     83 gfx::Rect CalculateScreenBounds(const gfx::Size& size);
     84 
     85 // Corrects font size for Label control.
     86 void CorrectLabelFontSize(views::Label* label);
     87 
     88 // Corrects font size for MenuButton control.
     89 void CorrectMenuButtonFontSize(views::MenuButton* button);
     90 
     91 // Corrects font size for NativeButton control.
     92 void CorrectNativeButtonFontSize(views::NativeButton* button);
     93 
     94 // Corrects font size for Textfield control.
     95 void CorrectTextfieldFontSize(views::Textfield* textfield);
     96 
     97 // Sets font and corrects font size for Textfield control.
     98 void SetAndCorrectTextfieldFont(views::Textfield* textfield,
     99                                 const gfx::Font& font);
    100 
    101 // Returns URL used for account recovery.
    102 GURL 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.
    109 string16 GetCurrentNetworkName(NetworkLibrary* network_library);
    110 
    111 // Define the constants in |login| namespace to avoid potential
    112 // conflict with other chromeos components.
    113 namespace login {
    114 
    115 // Command tag for buttons on the lock screen.
    116 enum Command {
    117   SIGN_OUT,
    118 };
    119 
    120 // Gap between edge and image view, and image view and controls.
    121 const int kBorderSize = 10;
    122 
    123 // The size of user image.
    124 const int kUserImageSize = 256;
    125 
    126 // Background color of the login controls.
    127 const SkColor kBackgroundColor = SK_ColorWHITE;
    128 
    129 // Text color on the login controls.
    130 const SkColor kTextColor = SK_ColorWHITE;
    131 
    132 // Default link color on login/OOBE controls.
    133 const SkColor kLinkColor = 0xFF0066CC;
    134 
    135 // Right margin for placing throbber above the view.
    136 const 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.
    140 const int kWizardScreenWidth = 800;
    141 const int kWizardScreenHeight = 450;
    142 
    143 const int kScreenCornerRadius = 10;
    144 const int kUserCornerRadius = 6;
    145 
    146 // Username label height in different states.
    147 const int kSelectedLabelHeight = 25;
    148 const int kUnselectedLabelHeight = 20;
    149 
    150 // Minimal width for the button.
    151 const int kButtonMinWidth = 90;
    152 
    153 class 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)
    172 const int kFontSizeCorrectionDelta = 1;
    173 const int kNetworkSelectionLabelFontDelta = 1;
    174 const int kSelectedUsernameFontDelta = 1;
    175 const int kUnselectedUsernameFontDelta = 1;
    176 const int kWelcomeTitleFontDelta = 8;
    177 const int kLoginTitleFontDelta = 3;
    178 #else
    179 const int kFontSizeCorrectionDelta = 2;
    180 const int kNetworkSelectionLabelFontDelta = 1;
    181 const int kSelectedUsernameFontDelta = 1;
    182 const int kUnselectedUsernameFontDelta = 2;
    183 const int kWelcomeTitleFontDelta = 9;
    184 const int kLoginTitleFontDelta = 4;
    185 #endif
    186 
    187 // New pod sizes.
    188 const int kNewUserPodFullWidth = 372;
    189 const int kNewUserPodFullHeight = 372;
    190 const int kNewUserPodSmallWidth = 360;
    191 const int kNewUserPodSmallHeight = 322;
    192 
    193 }  // namespace chromeos
    194 
    195 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_HELPER_H_
    196