Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "base/macros.h" | |
| 6 #include "base/strings/string_util.h" | |
| 7 #include "base/strings/utf_string_conversions.h" | |
| 8 #include "mash/task_viewer/task_viewer_application_delegate.h" | |
| 9 #include "mojo/application/public/cpp/application_delegate.h" | |
| 10 #include "mojo/application/public/cpp/application_impl.h" | |
| 11 #include "mojo/application/public/cpp/application_runner.h" | |
| 12 #include "mojo/public/c/system/main.h" | |
| 13 #include "mojo/services/tracing/public/cpp/tracing_impl.h" | |
| 14 #include "ui/views/background.h" | |
| 15 #include "ui/views/controls/textfield/textfield.h" | |
| 16 #include "ui/views/controls/textfield/textfield_controller.h" | |
| 17 #include "ui/views/mus/aura_init.h" | |
| 18 #include "ui/views/mus/window_manager_connection.h" | |
| 19 #include "ui/views/widget/widget_delegate.h" | |
| 20 #include "url/gurl.h" | |
| 21 | |
| 22 namespace views { | |
| 23 class AuraInit; | |
| 24 } | |
| 25 | |
| 26 namespace mash { | |
| 27 namespace quick_launch { | |
| 28 | |
| 29 class QuickLaunchUI : public views::WidgetDelegateView, | |
| 30 public views::TextfieldController { | |
| 31 public: | |
| 32 QuickLaunchUI(mojo::ApplicationImpl* app) | |
|
sky
2016/01/05 23:33:56
nit: explicit
| |
| 33 : app_(app), | |
| 34 prompt_(new views::Textfield) { | |
| 35 set_background(views::Background::CreateStandardPanelBackground()); | |
| 36 prompt_->set_controller(this); | |
| 37 AddChildView(prompt_); | |
| 38 } | |
| 39 ~QuickLaunchUI() override {} | |
| 40 | |
| 41 private: | |
| 42 // Overridden from views::WidgetDelegate: | |
| 43 views::View* GetContentsView() override { return this; } | |
| 44 base::string16 GetWindowTitle() const override { | |
| 45 // TODO(beng): use resources. | |
| 46 return base::ASCIIToUTF16("QuickLaunch"); | |
| 47 } | |
| 48 | |
| 49 // Overridden from views::View: | |
| 50 void Layout() override { | |
| 51 gfx::Rect bounds = GetLocalBounds(); | |
| 52 bounds.Inset(5, 5); | |
| 53 prompt_->SetBoundsRect(bounds); | |
| 54 } | |
| 55 | |
| 56 // Overridden from views::TextFieldController: | |
| 57 bool HandleKeyEvent(views::Textfield* sender, | |
| 58 const ui::KeyEvent& key_event) override { | |
| 59 if (key_event.key_code() == ui::VKEY_RETURN) { | |
| 60 std::string url = Canonicalize(prompt_->text()); | |
| 61 connections_.push_back(std::move(app_->ConnectToApplication(url))); | |
| 62 prompt_->SetText(base::string16()); | |
| 63 } | |
| 64 return false; | |
| 65 } | |
| 66 | |
| 67 std::string Canonicalize(const base::string16& input) const { | |
| 68 std::string working = base::UTF16ToUTF8(input); | |
| 69 base::TrimWhitespaceASCII(working, base::TRIM_ALL, &working); | |
|
sky
2016/01/05 23:33:56
Isn't working utf8, and not ascii? Seems like you
| |
| 70 GURL url(working); | |
| 71 if (url.scheme() != "mojo" && url.scheme() != "exe") | |
| 72 working = "mojo:" + working; | |
| 73 return working; | |
| 74 } | |
| 75 | |
| 76 mojo::ApplicationImpl* app_; | |
| 77 views::Textfield* prompt_; | |
| 78 std::vector<scoped_ptr<mojo::ApplicationConnection>> connections_; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(QuickLaunchUI); | |
| 81 }; | |
| 82 | |
| 83 class QuickLaunchApplicationDelegate : public mojo::ApplicationDelegate { | |
| 84 public: | |
| 85 QuickLaunchApplicationDelegate() {} | |
| 86 ~QuickLaunchApplicationDelegate() override {} | |
| 87 | |
| 88 private: | |
| 89 // mojo::ApplicationDelegate: | |
| 90 void Initialize(mojo::ApplicationImpl* app) override { | |
| 91 tracing_.Initialize(app); | |
| 92 | |
| 93 aura_init_.reset(new views::AuraInit(app, "views_mus_resources.pak")); | |
| 94 views::WindowManagerConnection::Create(app); | |
| 95 | |
| 96 views::Widget* window = views::Widget::CreateWindowWithBounds( | |
| 97 new QuickLaunchUI(app), gfx::Rect(10, 625, 500, 75)); | |
|
sky
2016/01/05 23:33:56
Wouldn't it be better to let the preferred height
| |
| 98 window->Show(); | |
| 99 } | |
| 100 | |
| 101 mojo::TracingImpl tracing_; | |
| 102 scoped_ptr<views::AuraInit> aura_init_; | |
| 103 | |
| 104 DISALLOW_COPY_AND_ASSIGN(QuickLaunchApplicationDelegate); | |
| 105 }; | |
| 106 | |
| 107 } // namespace quick_launch | |
| 108 } // namespace mash | |
| 109 | |
| 110 MojoResult MojoMain(MojoHandle shell_handle) { | |
| 111 mojo::ApplicationRunner runner( | |
| 112 new mash::quick_launch::QuickLaunchApplicationDelegate); | |
| 113 return runner.Run(shell_handle); | |
| 114 } | |
| OLD | NEW |