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

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

Issue 1674903003: Extract shell methods from ApplicationImpl into a base class, and pass this to Initialize() instead. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojom
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/example/window_type_launcher/window_type_launcher.cc ('k') | mash/screenlock/screenlock.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/macros.h" 5 #include "base/macros.h"
6 #include "base/strings/string_util.h" 6 #include "base/strings/string_util.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "mojo/public/c/system/main.h" 8 #include "mojo/public/c/system/main.h"
9 #include "mojo/services/tracing/public/cpp/tracing_impl.h" 9 #include "mojo/services/tracing/public/cpp/tracing_impl.h"
10 #include "mojo/shell/public/cpp/application_delegate.h" 10 #include "mojo/shell/public/cpp/application_delegate.h"
11 #include "mojo/shell/public/cpp/application_impl.h"
12 #include "mojo/shell/public/cpp/application_runner.h" 11 #include "mojo/shell/public/cpp/application_runner.h"
12 #include "mojo/shell/public/cpp/shell.h"
13 #include "ui/views/background.h" 13 #include "ui/views/background.h"
14 #include "ui/views/controls/textfield/textfield.h" 14 #include "ui/views/controls/textfield/textfield.h"
15 #include "ui/views/controls/textfield/textfield_controller.h" 15 #include "ui/views/controls/textfield/textfield_controller.h"
16 #include "ui/views/mus/aura_init.h" 16 #include "ui/views/mus/aura_init.h"
17 #include "ui/views/mus/window_manager_connection.h" 17 #include "ui/views/mus/window_manager_connection.h"
18 #include "ui/views/widget/widget_delegate.h" 18 #include "ui/views/widget/widget_delegate.h"
19 #include "url/gurl.h" 19 #include "url/gurl.h"
20 20
21 namespace views { 21 namespace views {
22 class AuraInit; 22 class AuraInit;
23 } 23 }
24 24
25 namespace mash { 25 namespace mash {
26 namespace quick_launch { 26 namespace quick_launch {
27 27
28 class QuickLaunchUI : public views::WidgetDelegateView, 28 class QuickLaunchUI : public views::WidgetDelegateView,
29 public views::TextfieldController { 29 public views::TextfieldController {
30 public: 30 public:
31 QuickLaunchUI(mojo::ApplicationImpl* app) 31 QuickLaunchUI(mojo::Shell* shell)
32 : app_(app), 32 : shell_(shell),
33 prompt_(new views::Textfield) { 33 prompt_(new views::Textfield) {
34 set_background(views::Background::CreateStandardPanelBackground()); 34 set_background(views::Background::CreateStandardPanelBackground());
35 prompt_->set_controller(this); 35 prompt_->set_controller(this);
36 AddChildView(prompt_); 36 AddChildView(prompt_);
37 } 37 }
38 ~QuickLaunchUI() override {} 38 ~QuickLaunchUI() override {}
39 39
40 private: 40 private:
41 // Overridden from views::WidgetDelegate: 41 // Overridden from views::WidgetDelegate:
42 views::View* GetContentsView() override { return this; } 42 views::View* GetContentsView() override { return this; }
(...skipping 12 matching lines...) Expand all
55 gfx::Size ps = prompt_->GetPreferredSize(); 55 gfx::Size ps = prompt_->GetPreferredSize();
56 ps.Enlarge(500, 10); 56 ps.Enlarge(500, 10);
57 return ps; 57 return ps;
58 } 58 }
59 59
60 // Overridden from views::TextFieldController: 60 // Overridden from views::TextFieldController:
61 bool HandleKeyEvent(views::Textfield* sender, 61 bool HandleKeyEvent(views::Textfield* sender,
62 const ui::KeyEvent& key_event) override { 62 const ui::KeyEvent& key_event) override {
63 if (key_event.key_code() == ui::VKEY_RETURN) { 63 if (key_event.key_code() == ui::VKEY_RETURN) {
64 std::string url = Canonicalize(prompt_->text()); 64 std::string url = Canonicalize(prompt_->text());
65 connections_.push_back(app_->ConnectToApplication(url)); 65 connections_.push_back(shell_->ConnectToApplication(url));
66 prompt_->SetText(base::string16()); 66 prompt_->SetText(base::string16());
67 } 67 }
68 return false; 68 return false;
69 } 69 }
70 70
71 std::string Canonicalize(const base::string16& input) const { 71 std::string Canonicalize(const base::string16& input) const {
72 base::string16 working; 72 base::string16 working;
73 base::TrimWhitespace(input, base::TRIM_ALL, &working); 73 base::TrimWhitespace(input, base::TRIM_ALL, &working);
74 GURL url(working); 74 GURL url(working);
75 if (url.scheme() != "mojo" && url.scheme() != "exe") 75 if (url.scheme() != "mojo" && url.scheme() != "exe")
76 working = base::ASCIIToUTF16("mojo:") + working; 76 working = base::ASCIIToUTF16("mojo:") + working;
77 return base::UTF16ToUTF8(working); 77 return base::UTF16ToUTF8(working);
78 } 78 }
79 79
80 mojo::ApplicationImpl* app_; 80 mojo::Shell* shell_;
81 views::Textfield* prompt_; 81 views::Textfield* prompt_;
82 std::vector<scoped_ptr<mojo::ApplicationConnection>> connections_; 82 std::vector<scoped_ptr<mojo::ApplicationConnection>> connections_;
83 83
84 DISALLOW_COPY_AND_ASSIGN(QuickLaunchUI); 84 DISALLOW_COPY_AND_ASSIGN(QuickLaunchUI);
85 }; 85 };
86 86
87 class QuickLaunchApplicationDelegate : public mojo::ApplicationDelegate { 87 class QuickLaunchApplicationDelegate : public mojo::ApplicationDelegate {
88 public: 88 public:
89 QuickLaunchApplicationDelegate() {} 89 QuickLaunchApplicationDelegate() {}
90 ~QuickLaunchApplicationDelegate() override {} 90 ~QuickLaunchApplicationDelegate() override {}
91 91
92 private: 92 private:
93 // mojo::ApplicationDelegate: 93 // mojo::ApplicationDelegate:
94 void Initialize(mojo::ApplicationImpl* app) override { 94 void Initialize(mojo::Shell* shell, const std::string& url,
95 tracing_.Initialize(app); 95 uint32_t id) override {
96 tracing_.Initialize(shell, url);
96 97
97 aura_init_.reset(new views::AuraInit(app, "views_mus_resources.pak")); 98 aura_init_.reset(new views::AuraInit(shell, "views_mus_resources.pak"));
98 views::WindowManagerConnection::Create(app); 99 views::WindowManagerConnection::Create(shell);
99 100
100 views::Widget* window = views::Widget::CreateWindowWithBounds( 101 views::Widget* window = views::Widget::CreateWindowWithBounds(
101 new QuickLaunchUI(app), gfx::Rect(10, 640, 0, 0)); 102 new QuickLaunchUI(shell), gfx::Rect(10, 640, 0, 0));
102 window->Show(); 103 window->Show();
103 } 104 }
104 105
105 mojo::TracingImpl tracing_; 106 mojo::TracingImpl tracing_;
106 scoped_ptr<views::AuraInit> aura_init_; 107 scoped_ptr<views::AuraInit> aura_init_;
107 108
108 DISALLOW_COPY_AND_ASSIGN(QuickLaunchApplicationDelegate); 109 DISALLOW_COPY_AND_ASSIGN(QuickLaunchApplicationDelegate);
109 }; 110 };
110 111
111 } // namespace quick_launch 112 } // namespace quick_launch
112 } // namespace mash 113 } // namespace mash
113 114
114 MojoResult MojoMain(MojoHandle shell_handle) { 115 MojoResult MojoMain(MojoHandle shell_handle) {
115 mojo::ApplicationRunner runner( 116 mojo::ApplicationRunner runner(
116 new mash::quick_launch::QuickLaunchApplicationDelegate); 117 new mash::quick_launch::QuickLaunchApplicationDelegate);
117 return runner.Run(shell_handle); 118 return runner.Run(shell_handle);
118 } 119 }
OLDNEW
« no previous file with comments | « mash/example/window_type_launcher/window_type_launcher.cc ('k') | mash/screenlock/screenlock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698