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

Side by Side Diff: mash/screenlock/screenlock.cc

Issue 2569953002: Removes example code that isn't correctly wired up (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « mash/screenlock/screenlock.h ('k') | mash/session/BUILD.gn » ('j') | 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/screenlock/screenlock.h"
6
7 #include "ash/public/cpp/shell_window_ids.h"
8 #include "base/macros.h"
9 #include "base/memory/ptr_util.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "mash/session/public/interfaces/constants.mojom.h"
12 #include "mash/session/public/interfaces/session.mojom.h"
13 #include "mojo/public/cpp/bindings/binding.h"
14 #include "services/service_manager/public/cpp/connector.h"
15 #include "services/service_manager/public/cpp/service_context.h"
16 #include "services/ui/public/cpp/property_type_converters.h"
17 #include "ui/views/background.h"
18 #include "ui/views/controls/button/md_text_button.h"
19 #include "ui/views/mus/aura_init.h"
20 #include "ui/views/mus/native_widget_mus.h"
21 #include "ui/views/mus/window_manager_connection.h"
22 #include "ui/views/widget/widget_delegate.h"
23
24 namespace mash {
25 namespace screenlock {
26 namespace {
27
28 class ScreenlockView : public views::WidgetDelegateView,
29 public views::ButtonListener {
30 public:
31 explicit ScreenlockView(service_manager::Connector* connector)
32 : connector_(connector),
33 unlock_button_(
34 views::MdTextButton::Create(this, base::ASCIIToUTF16("Unlock"))) {
35 set_background(views::Background::CreateSolidBackground(SK_ColorYELLOW));
36 AddChildView(unlock_button_);
37 }
38 ~ScreenlockView() override {}
39
40 private:
41 // Overridden from views::WidgetDelegate:
42 base::string16 GetWindowTitle() const override {
43 // TODO(beng): use resources.
44 return base::ASCIIToUTF16("Screenlock");
45 }
46
47 // Overridden from views::View:
48 void Layout() override {
49 gfx::Rect bounds = GetLocalBounds();
50 bounds.Inset(10, 10);
51
52 gfx::Size ps = unlock_button_->GetPreferredSize();
53 bounds.set_height(bounds.height() - ps.height() - 10);
54
55 unlock_button_->SetBounds(bounds.width() - ps.width(),
56 bounds.bottom() + 10,
57 ps.width(), ps.height());
58 }
59
60 // Overridden from views::ButtonListener:
61 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
62 DCHECK_EQ(sender, unlock_button_);
63 mash::session::mojom::SessionPtr session;
64 connector_->ConnectToInterface(session::mojom::kServiceName, &session);
65 session->UnlockScreen();
66 }
67
68 service_manager::Connector* connector_;
69 views::MdTextButton* unlock_button_;
70
71 DISALLOW_COPY_AND_ASSIGN(ScreenlockView);
72 };
73
74 } // namespace
75
76 Screenlock::Screenlock() {}
77 Screenlock::~Screenlock() {}
78
79 void Screenlock::OnStart() {
80 tracing_.Initialize(context()->connector(), context()->identity().name());
81
82 mash::session::mojom::SessionPtr session;
83 context()->connector()->ConnectToInterface(session::mojom::kServiceName,
84 &session);
85 session->AddScreenlockStateListener(
86 bindings_.CreateInterfacePtrAndBind(this));
87
88 aura_init_ = base::MakeUnique<views::AuraInit>(
89 context()->connector(), context()->identity(), "views_mus_resources.pak");
90 window_manager_connection_ = views::WindowManagerConnection::Create(
91 context()->connector(), context()->identity());
92
93 views::Widget* widget = new views::Widget;
94 views::Widget::InitParams params(
95 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
96 params.delegate = new ScreenlockView(context()->connector());
97
98 std::map<std::string, std::vector<uint8_t>> properties;
99 properties[ui::mojom::WindowManager::kContainerId_InitProperty] =
100 mojo::ConvertTo<std::vector<uint8_t>>(
101 ash::kShellWindowId_LockScreenContainer);
102 ui::Window* window =
103 views::WindowManagerConnection::Get()->NewTopLevelWindow(properties);
104 params.native_widget = new views::NativeWidgetMus(
105 widget, window, ui::mojom::CompositorFrameSinkType::DEFAULT);
106 widget->Init(params);
107 widget->Show();
108 }
109
110 bool Screenlock::OnConnect(
111 const service_manager::ServiceInfo& remote_info,
112 service_manager::InterfaceRegistry* registry) {
113 return false;
114 }
115
116 void Screenlock::ScreenlockStateChanged(bool screen_locked) {
117 if (!screen_locked)
118 base::MessageLoop::current()->QuitWhenIdle();
119 }
120
121 } // namespace screenlock
122 } // namespace mash
OLDNEW
« no previous file with comments | « mash/screenlock/screenlock.h ('k') | mash/session/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698