OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mash/login/login.h" | 5 #include "mash/login/login.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "ash/public/interfaces/container.mojom.h" | 10 #include "ash/public/interfaces/container.mojom.h" |
11 #include "base/guid.h" | 11 #include "base/guid.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "mash/init/public/interfaces/init.mojom.h" | 15 #include "mash/init/public/interfaces/init.mojom.h" |
16 #include "mash/login/public/interfaces/login.mojom.h" | 16 #include "mash/login/public/interfaces/login.mojom.h" |
17 #include "mojo/public/cpp/bindings/binding_set.h" | 17 #include "mojo/public/cpp/bindings/binding_set.h" |
18 #include "services/shell/public/cpp/connector.h" | 18 #include "services/shell/public/cpp/connector.h" |
19 #include "services/shell/public/cpp/service.h" | 19 #include "services/shell/public/cpp/service.h" |
20 #include "services/tracing/public/cpp/provider.h" | 20 #include "services/tracing/public/cpp/provider.h" |
21 #include "services/ui/public/cpp/property_type_converters.h" | 21 #include "services/ui/public/cpp/property_type_converters.h" |
22 #include "services/ui/public/interfaces/user_access_manager.mojom.h" | 22 #include "services/ui/public/interfaces/user_access_manager.mojom.h" |
23 #include "ui/views/background.h" | 23 #include "ui/views/background.h" |
24 #include "ui/views/controls/button/label_button.h" | 24 #include "ui/views/controls/button/md_text_button.h" |
25 #include "ui/views/mus/aura_init.h" | 25 #include "ui/views/mus/aura_init.h" |
26 #include "ui/views/mus/native_widget_mus.h" | 26 #include "ui/views/mus/native_widget_mus.h" |
27 #include "ui/views/mus/window_manager_connection.h" | 27 #include "ui/views/mus/window_manager_connection.h" |
28 #include "ui/views/widget/widget_delegate.h" | 28 #include "ui/views/widget/widget_delegate.h" |
29 | 29 |
30 namespace mash { | 30 namespace mash { |
31 namespace login { | 31 namespace login { |
32 namespace { | 32 namespace { |
33 | 33 |
34 class Login; | 34 class Login; |
(...skipping 24 matching lines...) Expand all Loading... |
59 widget->Show(); | 59 widget->Show(); |
60 } | 60 } |
61 | 61 |
62 private: | 62 private: |
63 UI(Login* login, shell::Connector* connector) | 63 UI(Login* login, shell::Connector* connector) |
64 : login_(login), | 64 : login_(login), |
65 connector_(connector), | 65 connector_(connector), |
66 user_id_1_("00000000-0000-4000-8000-000000000000"), | 66 user_id_1_("00000000-0000-4000-8000-000000000000"), |
67 user_id_2_("00000000-0000-4000-8000-000000000001"), | 67 user_id_2_("00000000-0000-4000-8000-000000000001"), |
68 login_button_1_( | 68 login_button_1_( |
69 new views::LabelButton(this, base::ASCIIToUTF16("Timothy"))), | 69 views::MdTextButton::Create(this, base::ASCIIToUTF16("Timothy"))), |
70 login_button_2_( | 70 login_button_2_( |
71 new views::LabelButton(this, base::ASCIIToUTF16("Jimothy"))) { | 71 views::MdTextButton::Create(this, base::ASCIIToUTF16("Jimothy"))) { |
72 set_background(views::Background::CreateSolidBackground(SK_ColorRED)); | 72 set_background(views::Background::CreateSolidBackground(SK_ColorRED)); |
73 login_button_1_->SetStyle(views::Button::STYLE_BUTTON); | |
74 login_button_2_->SetStyle(views::Button::STYLE_BUTTON); | |
75 AddChildView(login_button_1_); | 73 AddChildView(login_button_1_); |
76 AddChildView(login_button_2_); | 74 AddChildView(login_button_2_); |
77 } | 75 } |
78 ~UI() override { | 76 ~UI() override { |
79 // Prevent the window manager from restarting during graceful shutdown. | 77 // Prevent the window manager from restarting during graceful shutdown. |
80 mash_wm_connection_->SetConnectionLostClosure(base::Closure()); | 78 mash_wm_connection_->SetConnectionLostClosure(base::Closure()); |
81 base::MessageLoop::current()->QuitWhenIdle(); | 79 base::MessageLoop::current()->QuitWhenIdle(); |
82 } | 80 } |
83 | 81 |
84 // Overridden from views::WidgetDelegate: | 82 // Overridden from views::WidgetDelegate: |
(...skipping 12 matching lines...) Expand all Loading... |
97 gfx::Size ps1 = login_button_1_->GetPreferredSize(); | 95 gfx::Size ps1 = login_button_1_->GetPreferredSize(); |
98 gfx::Size ps2 = login_button_2_->GetPreferredSize(); | 96 gfx::Size ps2 = login_button_2_->GetPreferredSize(); |
99 | 97 |
100 DCHECK(ps1.height() == ps2.height()); | 98 DCHECK(ps1.height() == ps2.height()); |
101 | 99 |
102 // The 10 is inter-button spacing. | 100 // The 10 is inter-button spacing. |
103 button_box.set_x((button_box.width() - ps1.width() - ps2.width() - 10) / 2); | 101 button_box.set_x((button_box.width() - ps1.width() - ps2.width() - 10) / 2); |
104 button_box.set_y((button_box.height() - ps1.height()) / 2); | 102 button_box.set_y((button_box.height() - ps1.height()) / 2); |
105 | 103 |
106 login_button_1_->SetBounds(button_box.x(), button_box.y(), ps1.width(), | 104 login_button_1_->SetBounds(button_box.x(), button_box.y(), ps1.width(), |
107 ps1.height()); | 105 ps1.height()); |
108 login_button_2_->SetBounds(login_button_1_->bounds().right() + 10, | 106 login_button_2_->SetBounds(login_button_1_->bounds().right() + 10, |
109 button_box.y(), ps2.width(), ps2.height()); | 107 button_box.y(), ps2.width(), ps2.height()); |
110 } | 108 } |
111 | 109 |
112 // Overridden from views::ButtonListener: | 110 // Overridden from views::ButtonListener: |
113 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 111 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
114 | 112 |
115 void StartWindowManager(const shell::Identity& identity) { | 113 void StartWindowManager(const shell::Identity& identity) { |
116 mash_wm_connection_ = connector_->Connect("mojo:ash"); | 114 mash_wm_connection_ = connector_->Connect("mojo:ash"); |
117 mash_wm_connection_->SetConnectionLostClosure( | 115 mash_wm_connection_->SetConnectionLostClosure( |
118 base::Bind(&UI::StartWindowManager, base::Unretained(this), identity)); | 116 base::Bind(&UI::StartWindowManager, base::Unretained(this), identity)); |
119 window_manager_connection_ = | 117 window_manager_connection_ = |
120 views::WindowManagerConnection::Create(connector_, identity); | 118 views::WindowManagerConnection::Create(connector_, identity); |
121 } | 119 } |
122 | 120 |
123 Login* login_; | 121 Login* login_; |
124 shell::Connector* connector_; | 122 shell::Connector* connector_; |
125 const std::string user_id_1_; | 123 const std::string user_id_1_; |
126 const std::string user_id_2_; | 124 const std::string user_id_2_; |
127 views::LabelButton* login_button_1_; | 125 views::MdTextButton* login_button_1_; |
128 views::LabelButton* login_button_2_; | 126 views::MdTextButton* login_button_2_; |
129 std::unique_ptr<shell::Connection> mash_wm_connection_; | 127 std::unique_ptr<shell::Connection> mash_wm_connection_; |
130 std::unique_ptr<views::WindowManagerConnection> window_manager_connection_; | 128 std::unique_ptr<views::WindowManagerConnection> window_manager_connection_; |
131 | 129 |
132 DISALLOW_COPY_AND_ASSIGN(UI); | 130 DISALLOW_COPY_AND_ASSIGN(UI); |
133 }; | 131 }; |
134 | 132 |
135 class Login : public shell::Service, | 133 class Login : public shell::Service, |
136 public shell::InterfaceFactory<mojom::Login>, | 134 public shell::InterfaceFactory<mojom::Login>, |
137 public mojom::Login { | 135 public mojom::Login { |
138 public: | 136 public: |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 } | 200 } |
203 | 201 |
204 } // namespace | 202 } // namespace |
205 | 203 |
206 shell::Service* CreateLogin() { | 204 shell::Service* CreateLogin() { |
207 return new Login; | 205 return new Login; |
208 } | 206 } |
209 | 207 |
210 } // namespace login | 208 } // namespace login |
211 } // namespace main | 209 } // namespace main |
OLD | NEW |