ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / chromeos / login / helper.cc
blobefb98901b709eef42fe1e24b217786b51d76fc61
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.
5 #include "chrome/browser/chromeos/login/helper.h"
7 #include "base/command_line.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/grit/generated_resources.h"
10 #include "chromeos/chromeos_switches.h"
11 #include "chromeos/network/network_handler.h"
12 #include "chromeos/network/network_state.h"
13 #include "chromeos/network/network_state_handler.h"
14 #include "third_party/cros_system_api/dbus/service_constants.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/gfx/image/image_skia.h"
17 #include "ui/gfx/screen.h"
19 namespace chromeos {
21 gfx::Rect CalculateScreenBounds(const gfx::Size& size) {
22 gfx::Rect bounds =
23 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().bounds();
24 if (!size.IsEmpty()) {
25 int horizontal_diff = bounds.width() - size.width();
26 int vertical_diff = bounds.height() - size.height();
27 bounds.Inset(horizontal_diff / 2, vertical_diff / 2);
29 return bounds;
32 int GetCurrentUserImageSize() {
33 // The biggest size that the profile picture is displayed at is currently
34 // 220px, used for the big preview on OOBE and Change Picture options page.
35 static const int kBaseUserImageSize = 220;
36 float scale_factor = gfx::Display::GetForcedDeviceScaleFactor();
37 if (scale_factor > 1.0f)
38 return static_cast<int>(scale_factor * kBaseUserImageSize);
39 return kBaseUserImageSize * gfx::ImageSkia::GetMaxSupportedScale();
42 namespace login {
44 bool LoginScrollIntoViewEnabled() {
45 return !base::CommandLine::ForCurrentProcess()->HasSwitch(
46 chromeos::switches::kDisableLoginScrollIntoView);
49 NetworkStateHelper::NetworkStateHelper() {}
50 NetworkStateHelper::~NetworkStateHelper() {}
52 base::string16 NetworkStateHelper::GetCurrentNetworkName() const {
53 NetworkStateHandler* nsh = NetworkHandler::Get()->network_state_handler();
54 const NetworkState* network =
55 nsh->ConnectedNetworkByType(NetworkTypePattern::NonVirtual());
56 if (network) {
57 if (network->Matches(NetworkTypePattern::Ethernet()))
58 return l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
59 return base::UTF8ToUTF16(network->name());
62 network = nsh->ConnectingNetworkByType(NetworkTypePattern::NonVirtual());
63 if (network) {
64 if (network->Matches(NetworkTypePattern::Ethernet()))
65 return l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
66 return base::UTF8ToUTF16(network->name());
68 return base::string16();
71 bool NetworkStateHelper::IsConnected() const {
72 chromeos::NetworkStateHandler* nsh =
73 chromeos::NetworkHandler::Get()->network_state_handler();
74 return nsh->ConnectedNetworkByType(chromeos::NetworkTypePattern::Default()) !=
75 NULL;
78 bool NetworkStateHelper::IsConnecting() const {
79 chromeos::NetworkStateHandler* nsh =
80 chromeos::NetworkHandler::Get()->network_state_handler();
81 return nsh->ConnectingNetworkByType(
82 chromeos::NetworkTypePattern::Default()) != NULL;
85 } // namespace login
87 } // namespace chromeos