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

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

Issue 1637113003: Add simplistic screenlock application. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 10 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
« no previous file with comments | « mash/screenlock/screenlock.h ('k') | mash/shell/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 "base/macros.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "components/mus/public/cpp/property_type_converters.h"
10 #include "mash/shell/public/interfaces/shell.mojom.h"
11 #include "mash/wm/public/interfaces/container.mojom.h"
12 #include "mojo/public/cpp/bindings/binding.h"
13 #include "mojo/shell/public/cpp/application_impl.h"
14 #include "ui/views/background.h"
15 #include "ui/views/controls/button/label_button.h"
16 #include "ui/views/mus/aura_init.h"
17 #include "ui/views/mus/native_widget_mus.h"
18 #include "ui/views/mus/window_manager_connection.h"
19 #include "ui/views/widget/widget_delegate.h"
20
21 namespace mash {
22 namespace screenlock {
23 namespace {
24
25 class ScreenlockView : public views::WidgetDelegateView,
26 public views::ButtonListener {
27 public:
28 explicit ScreenlockView(mojo::ApplicationImpl* app)
29 : app_(app),
30 unlock_button_(
31 new views::LabelButton(this, base::ASCIIToUTF16("Unlock"))) {
32 set_background(views::Background::CreateSolidBackground(SK_ColorYELLOW));
33 unlock_button_->SetStyle(views::Button::STYLE_BUTTON);
34 AddChildView(unlock_button_);
35 }
36 ~ScreenlockView() override {}
37
38 private:
39 // Overridden from views::WidgetDelegate:
40 views::View* GetContentsView() override { return this; }
41 base::string16 GetWindowTitle() const override {
42 // TODO(beng): use resources.
43 return base::ASCIIToUTF16("Screenlock");
44 }
45
46 // Overridden from views::View:
47 void Layout() override {
48 gfx::Rect bounds = GetLocalBounds();
49 bounds.Inset(10, 10);
50
51 gfx::Size ps = unlock_button_->GetPreferredSize();
52 bounds.set_height(bounds.height() - ps.height() - 10);
53
54 unlock_button_->SetBounds(bounds.width() - ps.width(),
55 bounds.bottom() + 10,
56 ps.width(), ps.height());
57 }
58
59 // Overridden from views::ButtonListener:
60 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
61 DCHECK_EQ(sender, unlock_button_);
62 mash::shell::mojom::ShellPtr shell;
63 app_->ConnectToService("mojo:mash_shell", &shell);
64 shell->UnlockScreen();
65 }
66
67 mojo::ApplicationImpl* app_;
68 views::LabelButton* unlock_button_;
69
70 DISALLOW_COPY_AND_ASSIGN(ScreenlockView);
71 };
72
73 } // namespace
74
75 Screenlock::Screenlock() : app_(nullptr) {}
76 Screenlock::~Screenlock() {}
77
78 void Screenlock::Initialize(mojo::ApplicationImpl* app) {
79 app_ = app;
80 tracing_.Initialize(app);
81
82 aura_init_.reset(new views::AuraInit(app, "views_mus_resources.pak"));
83 views::WindowManagerConnection::Create(app);
84
85 views::Widget* widget = new views::Widget;
86 views::Widget::InitParams params(
87 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
88 params.delegate = new ScreenlockView(app);
89
90 std::map<std::string, std::vector<uint8_t>> properties;
91 properties[mash::wm::mojom::kWindowContainer_Property] =
92 mojo::TypeConverter<const std::vector<uint8_t>, int32_t>::Convert(
93 static_cast<int32_t>(mash::wm::mojom::Container::LOGIN_WINDOWS));
94 mus::Window* window =
95 views::WindowManagerConnection::Get()->NewWindow(properties);
96 params.native_widget = new views::NativeWidgetMus(
97 widget, app->shell(), window, mus::mojom::SurfaceType::DEFAULT);
98 widget->Init(params);
99 widget->Show();
100 }
101
102 bool Screenlock::ConfigureIncomingConnection(
103 mojo::ApplicationConnection* connection) {
104 connection->AddService<mash::screenlock::mojom::Screenlock>(this);
105 return true;
106 }
107
108 void Screenlock::Quit() {
109 app_->Quit();
110 }
111
112 void Screenlock::Create(
113 mojo::ApplicationConnection* connection,
114 mojo::InterfaceRequest<mash::screenlock::mojom::Screenlock> r) {
115 bindings_.AddBinding(this, std::move(r));
116 }
117
118 } // namespace screenlock
119 } // namespace main
OLDNEW
« no previous file with comments | « mash/screenlock/screenlock.h ('k') | mash/shell/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698