| // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "chrome/browser/chromeos/login/helper.h" |
| |
| #include "ash/shell.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "chromeos/network/network_handler.h" |
| #include "chromeos/network/network_state.h" |
| #include "chromeos/network/network_state_handler.h" |
| #include "chromeos/network/shill_property_util.h" |
| #include "grit/generated_resources.h" |
| #include "grit/theme_resources.h" |
| #include "third_party/cros_system_api/dbus/service_constants.h" |
| #include "ui/base/l10n/l10n_util.h" |
| #include "ui/base/resource/resource_bundle.h" |
| #include "ui/gfx/image/image_skia.h" |
| #include "ui/gfx/screen.h" |
| |
| namespace chromeos { |
| |
| gfx::Rect CalculateScreenBounds(const gfx::Size& size) { |
| gfx::Rect bounds(ash::Shell::GetScreen()->GetPrimaryDisplay().bounds()); |
| if (!size.IsEmpty()) { |
| int horizontal_diff = bounds.width() - size.width(); |
| int vertical_diff = bounds.height() - size.height(); |
| bounds.Inset(horizontal_diff / 2, vertical_diff / 2); |
| } |
| return bounds; |
| } |
| |
| int GetCurrentUserImageSize() { |
| // The biggest size that the profile picture is displayed at is currently |
| // 220px, used for the big preview on OOBE and Change Picture options page. |
| static const int kBaseUserImageSize = 220; |
| float scale_factor = gfx::Display::GetForcedDeviceScaleFactor(); |
| if (scale_factor > 1.0f) |
| return static_cast<int>(scale_factor * kBaseUserImageSize); |
| return kBaseUserImageSize * gfx::ImageSkia::GetMaxSupportedScale(); |
| } |
| |
| namespace login { |
| |
| NetworkStateHelper::NetworkStateHelper() {} |
| NetworkStateHelper::~NetworkStateHelper() {} |
| |
| base::string16 NetworkStateHelper::GetCurrentNetworkName() const { |
| NetworkStateHandler* nsh = NetworkHandler::Get()->network_state_handler(); |
| const NetworkState* network = |
| nsh->ConnectedNetworkByType(NetworkTypePattern::NonVirtual()); |
| if (network) { |
| if (network->Matches(NetworkTypePattern::Ethernet())) |
| return l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET); |
| return UTF8ToUTF16(network->name()); |
| } |
| |
| network = nsh->ConnectingNetworkByType(NetworkTypePattern::NonVirtual()); |
| if (network) { |
| if (network->Matches(NetworkTypePattern::Ethernet())) |
| return l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET); |
| return UTF8ToUTF16(network->name()); |
| } |
| return base::string16(); |
| } |
| |
| bool NetworkStateHelper::IsConnected() const { |
| chromeos::NetworkStateHandler* nsh = |
| chromeos::NetworkHandler::Get()->network_state_handler(); |
| return nsh->ConnectedNetworkByType(chromeos::NetworkTypePattern::Default()) != |
| NULL; |
| } |
| |
| bool NetworkStateHelper::IsConnecting() const { |
| chromeos::NetworkStateHandler* nsh = |
| chromeos::NetworkHandler::Get()->network_state_handler(); |
| return nsh->ConnectingNetworkByType( |
| chromeos::NetworkTypePattern::Default()) != NULL; |
| } |
| |
| } // namespace login |
| |
| } // namespace chromeos |