Home | History | Annotate | Download | only in login
      1 // Copyright (c) 2012 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 #include "chrome/browser/chromeos/login/helper.h"
      6 
      7 #include "ash/shell.h"
      8 #include "base/strings/utf_string_conversions.h"
      9 #include "chromeos/network/network_handler.h"
     10 #include "chromeos/network/network_state.h"
     11 #include "chromeos/network/network_state_handler.h"
     12 #include "grit/generated_resources.h"
     13 #include "grit/theme_resources.h"
     14 #include "third_party/cros_system_api/dbus/service_constants.h"
     15 #include "ui/base/l10n/l10n_util.h"
     16 #include "ui/base/resource/resource_bundle.h"
     17 #include "ui/gfx/screen.h"
     18 
     19 namespace chromeos {
     20 
     21 gfx::Rect CalculateScreenBounds(const gfx::Size& size) {
     22   gfx::Rect bounds(ash::Shell::GetScreen()->GetPrimaryDisplay().bounds());
     23   if (!size.IsEmpty()) {
     24     int horizontal_diff = bounds.width() - size.width();
     25     int vertical_diff = bounds.height() - size.height();
     26     bounds.Inset(horizontal_diff / 2, vertical_diff / 2);
     27   }
     28   return bounds;
     29 }
     30 
     31 int GetCurrentUserImageSize() {
     32   // The biggest size that the profile picture is displayed at is currently
     33   // 220px, used for the big preview on OOBE and Change Picture options page.
     34   static const int kBaseUserImageSize = 220;
     35   float scale_factor = gfx::Display::GetForcedDeviceScaleFactor();
     36   if (scale_factor > 1.0f)
     37     return static_cast<int>(scale_factor * kBaseUserImageSize);
     38   return kBaseUserImageSize *
     39       ui::GetScaleFactorScale(ui::GetMaxScaleFactor());
     40 }
     41 
     42 namespace login {
     43 
     44 NetworkStateHelper::NetworkStateHelper() {}
     45 NetworkStateHelper::~NetworkStateHelper() {}
     46 
     47 string16 NetworkStateHelper::GetCurrentNetworkName() const {
     48   NetworkStateHandler* nsh = NetworkHandler::Get()->network_state_handler();
     49   const NetworkState* network = nsh->ConnectedNetworkByType(
     50       NetworkStateHandler::kMatchTypeNonVirtual);
     51   if (network) {
     52     if (network->type() == flimflam::kTypeEthernet)
     53       return l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
     54     return UTF8ToUTF16(network->name());
     55   }
     56 
     57   network = nsh->ConnectingNetworkByType(
     58       NetworkStateHandler::kMatchTypeNonVirtual);
     59   if (network) {
     60     if (network->type() == flimflam::kTypeEthernet)
     61       return l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
     62     return UTF8ToUTF16(network->name());
     63   }
     64   return string16();
     65 }
     66 
     67 bool NetworkStateHelper::IsConnected() const {
     68   chromeos::NetworkStateHandler* nsh =
     69       chromeos::NetworkHandler::Get()->network_state_handler();
     70   return nsh->ConnectedNetworkByType(
     71       chromeos::NetworkStateHandler::kMatchTypeDefault) != NULL;
     72 }
     73 
     74 bool NetworkStateHelper::IsConnecting() const {
     75   chromeos::NetworkStateHandler* nsh =
     76       chromeos::NetworkHandler::Get()->network_state_handler();
     77   return nsh->ConnectingNetworkByType(
     78       chromeos::NetworkStateHandler::kMatchTypeDefault) != NULL;
     79 }
     80 
     81 }  // namespace login
     82 
     83 }  // namespace chromeos
     84