Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: mash/login/ui.cc

Issue 1801133002: Restructure login (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« mash/login/login.cc ('K') | « mash/login/ui.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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 "mash/login/ui.h"
6
7 #include "base/guid.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "components/mus/public/cpp/property_type_converters.h"
10 #include "mash/login/login.h"
11 #include "mash/wm/public/interfaces/container.mojom.h"
12 #include "mojo/shell/public/cpp/connector.h"
13 #include "ui/views/background.h"
14 #include "ui/views/mus/native_widget_mus.h"
15 #include "ui/views/mus/window_manager_connection.h"
16
17 namespace mash {
18 namespace login {
19
20 // static
21 bool UI::is_showing_ = false;
22
23 // static
24 void UI::Show(mojo::Connector* connector, LoginController* login_controller) {
25 // It's possible multiple clients may have a connection to the Login service,
26 // so make sure that only one login UI can be shown at a time.
27 if (is_showing_)
28 return;
29
30 UI* ui = new UI(login_controller, connector);
31
32 views::WindowManagerConnection::Create(connector);
33
34 views::Widget* widget = new views::Widget;
35 views::Widget::InitParams params(
36 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
37 params.delegate = ui;
38
39 std::map<std::string, std::vector<uint8_t>> properties;
40 properties[mash::wm::mojom::kWindowContainer_Property] =
41 mojo::TypeConverter<const std::vector<uint8_t>, int32_t>::Convert(
42 static_cast<int32_t>(mash::wm::mojom::Container::LOGIN_WINDOWS));
43 mus::Window* window =
44 views::WindowManagerConnection::Get()->NewWindow(properties);
45 params.native_widget = new views::NativeWidgetMus(
46 widget, connector, window, mus::mojom::SurfaceType::DEFAULT);
47 widget->Init(params);
48 widget->Show();
49
50 is_showing_ = true;
51 }
52
53 UI::UI(LoginController* login_controller, mojo::Connector* connector)
54 : login_controller_(login_controller),
55 connector_(connector),
56 user_id_1_("00000000-0000-4000-8000-000000000000"),
57 user_id_2_("00000000-0000-4000-8000-000000000001"),
58 login_button_1_(
59 new views::LabelButton(this, base::ASCIIToUTF16("Timothy"))),
60 login_button_2_(
61 new views::LabelButton(this, base::ASCIIToUTF16("Jimothy"))) {
62 connector_->ConnectToInterface("mojo:mus", &user_access_manager_);
63 user_access_manager_->SetActiveUser(login_controller->login_user_id());
64 StartWindowManager();
65
66 set_background(views::Background::CreateSolidBackground(SK_ColorRED));
67 login_button_1_->SetStyle(views::Button::STYLE_BUTTON);
68 login_button_2_->SetStyle(views::Button::STYLE_BUTTON);
69 AddChildView(login_button_1_);
70 AddChildView(login_button_2_);
71 }
72
73 UI::~UI() {
74 // Avoids a window manager restart during destruction.
75 window_manager_connection_->SetConnectionLostClosure(base::Closure());
76 is_showing_ = false;
77 }
78
79 views::View* UI::GetContentsView() { return this; }
80
81 base::string16 UI::GetWindowTitle() const {
82 // TODO(beng): use resources.
83 return base::ASCIIToUTF16("Login");
84 }
85
86 void UI::DeleteDelegate() {
87 delete this;
88 }
89
90 void UI::Layout() {
91 gfx::Rect button_box = GetLocalBounds();
92 button_box.Inset(10, 10);
93
94 gfx::Size ps1 = login_button_1_->GetPreferredSize();
95 gfx::Size ps2 = login_button_2_->GetPreferredSize();
96
97 DCHECK(ps1.height() == ps2.height());
98
99 // The 10 is inter-button spacing.
100 button_box.set_x((button_box.width() - ps1.width() - ps2.width() - 10) / 2);
101 button_box.set_y((button_box.height() - ps1.height()) / 2);
102
103 login_button_1_->SetBounds(button_box.x(), button_box.y(), ps1.width(),
104 ps1.height());
105 login_button_2_->SetBounds(login_button_1_->bounds().right() + 10,
106 button_box.y(), ps2.width(), ps2.height());
107 }
108
109 void UI::ButtonPressed(views::Button* sender, const ui::Event& event) {
110 // Login...
111 if (sender == login_button_1_) {
112 user_access_manager_->SetActiveUser(user_id_1_);
113 login_controller_->init()->StartService("mojo:mash_shell", user_id_1_);
114 } else if (sender == login_button_2_) {
115 user_access_manager_->SetActiveUser(user_id_2_);
116 login_controller_->init()->StartService("mojo:mash_shell", user_id_2_);
117 } else {
118 NOTREACHED();
119 }
120 GetWidget()->Close();
121 }
122
123 void UI::StartWindowManager() {
124 mojo::Connector::ConnectParams params(
125 mojo::Identity("mojo:desktop_wm", login_controller_->login_user_id()));
126 window_manager_connection_ = connector_->Connect(&params);
127 window_manager_connection_->SetConnectionLostClosure(
128 base::Bind(&UI::StartWindowManager, base::Unretained(this)));
129 }
130
131 } // namespace login
132 } // namespace mash
OLDNEW
« mash/login/login.cc ('K') | « mash/login/ui.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698