| 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/quick_launch/quick_launch_application.h" | 5 #include "mash/quick_launch/quick_launch_application.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "mojo/public/c/system/main.h" | 10 #include "mojo/public/c/system/main.h" |
| 11 #include "mojo/services/tracing/public/cpp/tracing_impl.h" | 11 #include "mojo/services/tracing/public/cpp/tracing_impl.h" |
| 12 #include "mojo/shell/public/cpp/application_runner.h" | 12 #include "mojo/shell/public/cpp/application_runner.h" |
| 13 #include "mojo/shell/public/cpp/shell.h" | 13 #include "mojo/shell/public/cpp/connector.h" |
| 14 #include "mojo/shell/public/cpp/shell_client.h" | 14 #include "mojo/shell/public/cpp/shell_client.h" |
| 15 #include "ui/views/background.h" | 15 #include "ui/views/background.h" |
| 16 #include "ui/views/controls/textfield/textfield.h" | 16 #include "ui/views/controls/textfield/textfield.h" |
| 17 #include "ui/views/controls/textfield/textfield_controller.h" | 17 #include "ui/views/controls/textfield/textfield_controller.h" |
| 18 #include "ui/views/mus/aura_init.h" | 18 #include "ui/views/mus/aura_init.h" |
| 19 #include "ui/views/mus/window_manager_connection.h" | 19 #include "ui/views/mus/window_manager_connection.h" |
| 20 #include "ui/views/widget/widget_delegate.h" | 20 #include "ui/views/widget/widget_delegate.h" |
| 21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 22 | 22 |
| 23 namespace views { | 23 namespace views { |
| 24 class AuraInit; | 24 class AuraInit; |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace mash { | 27 namespace mash { |
| 28 namespace quick_launch { | 28 namespace quick_launch { |
| 29 | 29 |
| 30 class QuickLaunchUI : public views::WidgetDelegateView, | 30 class QuickLaunchUI : public views::WidgetDelegateView, |
| 31 public views::TextfieldController { | 31 public views::TextfieldController { |
| 32 public: | 32 public: |
| 33 QuickLaunchUI(mojo::Shell* shell) | 33 QuickLaunchUI(mojo::Connector* connector) |
| 34 : shell_(shell), prompt_(new views::Textfield) { | 34 : connector_(connector), prompt_(new views::Textfield) { |
| 35 set_background(views::Background::CreateStandardPanelBackground()); | 35 set_background(views::Background::CreateStandardPanelBackground()); |
| 36 prompt_->set_controller(this); | 36 prompt_->set_controller(this); |
| 37 AddChildView(prompt_); | 37 AddChildView(prompt_); |
| 38 } | 38 } |
| 39 ~QuickLaunchUI() override {} | 39 ~QuickLaunchUI() override {} |
| 40 | 40 |
| 41 private: | 41 private: |
| 42 // Overridden from views::WidgetDelegate: | 42 // Overridden from views::WidgetDelegate: |
| 43 views::View* GetContentsView() override { return this; } | 43 views::View* GetContentsView() override { return this; } |
| 44 base::string16 GetWindowTitle() const override { | 44 base::string16 GetWindowTitle() const override { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 56 gfx::Size ps = prompt_->GetPreferredSize(); | 56 gfx::Size ps = prompt_->GetPreferredSize(); |
| 57 ps.Enlarge(500, 10); | 57 ps.Enlarge(500, 10); |
| 58 return ps; | 58 return ps; |
| 59 } | 59 } |
| 60 | 60 |
| 61 // Overridden from views::TextFieldController: | 61 // Overridden from views::TextFieldController: |
| 62 bool HandleKeyEvent(views::Textfield* sender, | 62 bool HandleKeyEvent(views::Textfield* sender, |
| 63 const ui::KeyEvent& key_event) override { | 63 const ui::KeyEvent& key_event) override { |
| 64 if (key_event.key_code() == ui::VKEY_RETURN) { | 64 if (key_event.key_code() == ui::VKEY_RETURN) { |
| 65 std::string url = Canonicalize(prompt_->text()); | 65 std::string url = Canonicalize(prompt_->text()); |
| 66 connections_.push_back(shell_->Connect(url)); | 66 connections_.push_back(connector_->Connect(url)); |
| 67 prompt_->SetText(base::string16()); | 67 prompt_->SetText(base::string16()); |
| 68 } | 68 } |
| 69 return false; | 69 return false; |
| 70 } | 70 } |
| 71 | 71 |
| 72 std::string Canonicalize(const base::string16& input) const { | 72 std::string Canonicalize(const base::string16& input) const { |
| 73 base::string16 working; | 73 base::string16 working; |
| 74 base::TrimWhitespace(input, base::TRIM_ALL, &working); | 74 base::TrimWhitespace(input, base::TRIM_ALL, &working); |
| 75 GURL url(working); | 75 GURL url(working); |
| 76 if (url.scheme() != "mojo" && url.scheme() != "exe") | 76 if (url.scheme() != "mojo" && url.scheme() != "exe") |
| 77 working = base::ASCIIToUTF16("mojo:") + working; | 77 working = base::ASCIIToUTF16("mojo:") + working; |
| 78 return base::UTF16ToUTF8(working); | 78 return base::UTF16ToUTF8(working); |
| 79 } | 79 } |
| 80 | 80 |
| 81 mojo::Shell* shell_; | 81 mojo::Connector* connector_; |
| 82 views::Textfield* prompt_; | 82 views::Textfield* prompt_; |
| 83 std::vector<scoped_ptr<mojo::Connection>> connections_; | 83 std::vector<scoped_ptr<mojo::Connection>> connections_; |
| 84 | 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(QuickLaunchUI); | 85 DISALLOW_COPY_AND_ASSIGN(QuickLaunchUI); |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 QuickLaunchApplication::QuickLaunchApplication() {} | 88 QuickLaunchApplication::QuickLaunchApplication() {} |
| 89 QuickLaunchApplication::~QuickLaunchApplication() {} | 89 QuickLaunchApplication::~QuickLaunchApplication() {} |
| 90 | 90 |
| 91 void QuickLaunchApplication::Initialize(mojo::Shell* shell, | 91 void QuickLaunchApplication::Initialize(mojo::Connector* connector, |
| 92 const std::string& url, | 92 const std::string& url, |
| 93 uint32_t id, | 93 uint32_t id, |
| 94 uint32_t user_id) { | 94 uint32_t user_id) { |
| 95 tracing_.Initialize(shell, url); | 95 tracing_.Initialize(connector, url); |
| 96 | 96 |
| 97 aura_init_.reset(new views::AuraInit(shell, "views_mus_resources.pak")); | 97 aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak")); |
| 98 views::WindowManagerConnection::Create(shell); | 98 views::WindowManagerConnection::Create(connector); |
| 99 | 99 |
| 100 views::Widget* window = views::Widget::CreateWindowWithBounds( | 100 views::Widget* window = views::Widget::CreateWindowWithBounds( |
| 101 new QuickLaunchUI(shell), gfx::Rect(10, 640, 0, 0)); | 101 new QuickLaunchUI(connector), gfx::Rect(10, 640, 0, 0)); |
| 102 window->Show(); | 102 window->Show(); |
| 103 } | 103 } |
| 104 | 104 |
| 105 bool QuickLaunchApplication::AcceptConnection(mojo::Connection* connection) { | 105 bool QuickLaunchApplication::AcceptConnection(mojo::Connection* connection) { |
| 106 return true; | 106 return true; |
| 107 } | 107 } |
| 108 | 108 |
| 109 } // namespace quick_launch | 109 } // namespace quick_launch |
| 110 } // namespace mash | 110 } // namespace mash |
| OLD | NEW |