OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "mandoline/ui/omnibox/omnibox_application.h" | 5 #include "mandoline/ui/omnibox/omnibox_application.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "components/mus/public/cpp/window.h" | 12 #include "components/mus/public/cpp/window.h" |
13 #include "components/mus/public/cpp/window_tree_connection.h" | 13 #include "components/mus/public/cpp/window_tree_connection.h" |
14 #include "components/mus/public/cpp/window_tree_delegate.h" | 14 #include "components/mus/public/cpp/window_tree_delegate.h" |
15 #include "components/url_formatter/url_fixer.h" | 15 #include "components/url_formatter/url_fixer.h" |
16 #include "mandoline/ui/desktop_ui/public/interfaces/view_embedder.mojom.h" | 16 #include "mandoline/ui/desktop_ui/public/interfaces/view_embedder.mojom.h" |
17 #include "mojo/common/common_type_converters.h" | 17 #include "mojo/common/common_type_converters.h" |
18 #include "mojo/shell/public/cpp/application_impl.h" | 18 #include "mojo/shell/public/cpp/shell.h" |
19 #include "ui/mojo/init/ui_init.h" | 19 #include "ui/mojo/init/ui_init.h" |
20 #include "ui/views/background.h" | 20 #include "ui/views/background.h" |
21 #include "ui/views/controls/textfield/textfield.h" | 21 #include "ui/views/controls/textfield/textfield.h" |
22 #include "ui/views/controls/textfield/textfield_controller.h" | 22 #include "ui/views/controls/textfield/textfield_controller.h" |
23 #include "ui/views/layout/layout_manager.h" | 23 #include "ui/views/layout/layout_manager.h" |
24 #include "ui/views/mus/aura_init.h" | 24 #include "ui/views/mus/aura_init.h" |
25 #include "ui/views/mus/display_converter.h" | 25 #include "ui/views/mus/display_converter.h" |
26 #include "ui/views/mus/native_widget_mus.h" | 26 #include "ui/views/mus/native_widget_mus.h" |
27 #include "ui/views/widget/widget_delegate.h" | 27 #include "ui/views/widget/widget_delegate.h" |
28 | 28 |
29 namespace mandoline { | 29 namespace mandoline { |
30 | 30 |
31 //////////////////////////////////////////////////////////////////////////////// | 31 //////////////////////////////////////////////////////////////////////////////// |
32 // OmniboxImpl | 32 // OmniboxImpl |
33 | 33 |
34 class OmniboxImpl : public mus::WindowTreeDelegate, | 34 class OmniboxImpl : public mus::WindowTreeDelegate, |
35 public views::LayoutManager, | 35 public views::LayoutManager, |
36 public views::TextfieldController, | 36 public views::TextfieldController, |
37 public Omnibox { | 37 public Omnibox { |
38 public: | 38 public: |
39 OmniboxImpl(mojo::ApplicationImpl* app, | 39 OmniboxImpl(mojo::Shell* shell, |
40 mojo::ApplicationConnection* connection, | 40 mojo::ApplicationConnection* connection, |
41 mojo::InterfaceRequest<Omnibox> request); | 41 mojo::InterfaceRequest<Omnibox> request); |
42 ~OmniboxImpl() override; | 42 ~OmniboxImpl() override; |
43 | 43 |
44 private: | 44 private: |
45 // Overridden from mus::WindowTreeDelegate: | 45 // Overridden from mus::WindowTreeDelegate: |
46 void OnEmbed(mus::Window* root) override; | 46 void OnEmbed(mus::Window* root) override; |
47 void OnConnectionLost(mus::WindowTreeConnection* connection) override; | 47 void OnConnectionLost(mus::WindowTreeConnection* connection) override; |
48 | 48 |
49 // Overridden from views::LayoutManager: | 49 // Overridden from views::LayoutManager: |
50 gfx::Size GetPreferredSize(const views::View* view) const override; | 50 gfx::Size GetPreferredSize(const views::View* view) const override; |
51 void Layout(views::View* host) override; | 51 void Layout(views::View* host) override; |
52 | 52 |
53 // Overridden from views::TextfieldController: | 53 // Overridden from views::TextfieldController: |
54 bool HandleKeyEvent(views::Textfield* sender, | 54 bool HandleKeyEvent(views::Textfield* sender, |
55 const ui::KeyEvent& key_event) override; | 55 const ui::KeyEvent& key_event) override; |
56 | 56 |
57 // Overridden from Omnibox: | 57 // Overridden from Omnibox: |
58 void GetWindowTreeClient( | 58 void GetWindowTreeClient( |
59 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request) override; | 59 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request) override; |
60 void ShowForURL(const mojo::String& url) override; | 60 void ShowForURL(const mojo::String& url) override; |
61 | 61 |
62 void HideWindow(); | 62 void HideWindow(); |
63 void ShowWindow(); | 63 void ShowWindow(); |
64 | 64 |
65 scoped_ptr<ui::mojo::UIInit> ui_init_; | 65 scoped_ptr<ui::mojo::UIInit> ui_init_; |
66 scoped_ptr<views::AuraInit> aura_init_; | 66 scoped_ptr<views::AuraInit> aura_init_; |
67 mojo::ApplicationImpl* app_; | 67 mojo::Shell* shell_; |
68 mus::Window* root_; | 68 mus::Window* root_; |
69 mojo::String url_; | 69 mojo::String url_; |
70 views::Textfield* edit_; | 70 views::Textfield* edit_; |
71 mojo::Binding<Omnibox> binding_; | 71 mojo::Binding<Omnibox> binding_; |
72 ViewEmbedderPtr view_embedder_; | 72 ViewEmbedderPtr view_embedder_; |
73 | 73 |
74 DISALLOW_COPY_AND_ASSIGN(OmniboxImpl); | 74 DISALLOW_COPY_AND_ASSIGN(OmniboxImpl); |
75 }; | 75 }; |
76 | 76 |
77 //////////////////////////////////////////////////////////////////////////////// | 77 //////////////////////////////////////////////////////////////////////////////// |
78 // OmniboxApplication, public: | 78 // OmniboxApplication, public: |
79 | 79 |
80 OmniboxApplication::OmniboxApplication() : app_(nullptr) {} | 80 OmniboxApplication::OmniboxApplication() : shell_(nullptr) {} |
81 OmniboxApplication::~OmniboxApplication() {} | 81 OmniboxApplication::~OmniboxApplication() {} |
82 | 82 |
83 //////////////////////////////////////////////////////////////////////////////// | 83 //////////////////////////////////////////////////////////////////////////////// |
84 // OmniboxApplication, mojo::ApplicationDelegate implementation: | 84 // OmniboxApplication, mojo::ApplicationDelegate implementation: |
85 | 85 |
86 void OmniboxApplication::Initialize(mojo::ApplicationImpl* app) { | 86 void OmniboxApplication::Initialize(mojo::Shell* shell, const std::string& url, |
87 app_ = app; | 87 uint32_t id) { |
88 tracing_.Initialize(app); | 88 shell_ = shell; |
| 89 tracing_.Initialize(shell, url); |
89 } | 90 } |
90 | 91 |
91 bool OmniboxApplication::AcceptConnection( | 92 bool OmniboxApplication::AcceptConnection( |
92 mojo::ApplicationConnection* connection) { | 93 mojo::ApplicationConnection* connection) { |
93 connection->AddService<Omnibox>(this); | 94 connection->AddService<Omnibox>(this); |
94 return true; | 95 return true; |
95 } | 96 } |
96 | 97 |
97 //////////////////////////////////////////////////////////////////////////////// | 98 //////////////////////////////////////////////////////////////////////////////// |
98 // OmniboxApplication, mojo::InterfaceFactory<Omnibox> implementation: | 99 // OmniboxApplication, mojo::InterfaceFactory<Omnibox> implementation: |
99 | 100 |
100 void OmniboxApplication::Create(mojo::ApplicationConnection* connection, | 101 void OmniboxApplication::Create(mojo::ApplicationConnection* connection, |
101 mojo::InterfaceRequest<Omnibox> request) { | 102 mojo::InterfaceRequest<Omnibox> request) { |
102 new OmniboxImpl(app_, connection, std::move(request)); | 103 new OmniboxImpl(shell_, connection, std::move(request)); |
103 } | 104 } |
104 | 105 |
105 //////////////////////////////////////////////////////////////////////////////// | 106 //////////////////////////////////////////////////////////////////////////////// |
106 // OmniboxImpl, public: | 107 // OmniboxImpl, public: |
107 | 108 |
108 OmniboxImpl::OmniboxImpl(mojo::ApplicationImpl* app, | 109 OmniboxImpl::OmniboxImpl(mojo::Shell* shell, |
109 mojo::ApplicationConnection* connection, | 110 mojo::ApplicationConnection* connection, |
110 mojo::InterfaceRequest<Omnibox> request) | 111 mojo::InterfaceRequest<Omnibox> request) |
111 : app_(app), | 112 : shell_(shell), |
112 root_(nullptr), | 113 root_(nullptr), |
113 edit_(nullptr), | 114 edit_(nullptr), |
114 binding_(this, std::move(request)) { | 115 binding_(this, std::move(request)) { |
115 connection->ConnectToService(&view_embedder_); | 116 connection->ConnectToService(&view_embedder_); |
116 } | 117 } |
117 OmniboxImpl::~OmniboxImpl() {} | 118 OmniboxImpl::~OmniboxImpl() {} |
118 | 119 |
119 //////////////////////////////////////////////////////////////////////////////// | 120 //////////////////////////////////////////////////////////////////////////////// |
120 // OmniboxImpl, mus::WindowTreeDelegate implementation: | 121 // OmniboxImpl, mus::WindowTreeDelegate implementation: |
121 | 122 |
122 void OmniboxImpl::OnEmbed(mus::Window* root) { | 123 void OmniboxImpl::OnEmbed(mus::Window* root) { |
123 root_ = root; | 124 root_ = root; |
124 | 125 |
125 if (!aura_init_.get()) { | 126 if (!aura_init_.get()) { |
126 ui_init_.reset(new ui::mojo::UIInit(views::GetDisplaysFromWindow(root_))); | 127 ui_init_.reset(new ui::mojo::UIInit(views::GetDisplaysFromWindow(root_))); |
127 aura_init_.reset(new views::AuraInit(app_, "mandoline_ui.pak")); | 128 aura_init_.reset(new views::AuraInit(shell_, "mandoline_ui.pak")); |
128 edit_ = new views::Textfield; | 129 edit_ = new views::Textfield; |
129 edit_->set_controller(this); | 130 edit_->set_controller(this); |
130 edit_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); | 131 edit_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); |
131 } | 132 } |
132 | 133 |
133 const int kOpacity = 0xC0; | 134 const int kOpacity = 0xC0; |
134 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; | 135 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; |
135 widget_delegate->GetContentsView()->set_background( | 136 widget_delegate->GetContentsView()->set_background( |
136 views::Background::CreateSolidBackground( | 137 views::Background::CreateSolidBackground( |
137 SkColorSetA(0xDDDDDD, kOpacity))); | 138 SkColorSetA(0xDDDDDD, kOpacity))); |
138 widget_delegate->GetContentsView()->AddChildView(edit_); | 139 widget_delegate->GetContentsView()->AddChildView(edit_); |
139 widget_delegate->GetContentsView()->SetLayoutManager(this); | 140 widget_delegate->GetContentsView()->SetLayoutManager(this); |
140 | 141 |
141 // TODO(beng): we may be leaking these on subsequent calls to OnEmbed()... | 142 // TODO(beng): we may be leaking these on subsequent calls to OnEmbed()... |
142 // probably should only allow once instance per view. | 143 // probably should only allow once instance per view. |
143 views::Widget* widget = new views::Widget; | 144 views::Widget* widget = new views::Widget; |
144 views::Widget::InitParams params( | 145 views::Widget::InitParams params( |
145 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 146 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
146 params.native_widget = new views::NativeWidgetMus( | 147 params.native_widget = new views::NativeWidgetMus( |
147 widget, app_->shell(), root, mus::mojom::SurfaceType::DEFAULT); | 148 widget, shell_, root, mus::mojom::SurfaceType::DEFAULT); |
148 params.delegate = widget_delegate; | 149 params.delegate = widget_delegate; |
149 params.bounds = root->bounds(); | 150 params.bounds = root->bounds(); |
150 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 151 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
151 widget->Init(params); | 152 widget->Init(params); |
152 widget->Show(); | 153 widget->Show(); |
153 widget->GetCompositor()->SetBackgroundColor( | 154 widget->GetCompositor()->SetBackgroundColor( |
154 SkColorSetA(SK_ColorBLACK, kOpacity)); | 155 SkColorSetA(SK_ColorBLACK, kOpacity)); |
155 | 156 |
156 ShowWindow(); | 157 ShowWindow(); |
157 } | 158 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 edit_->SelectAll(false); | 227 edit_->SelectAll(false); |
227 edit_->RequestFocus(); | 228 edit_->RequestFocus(); |
228 } | 229 } |
229 | 230 |
230 void OmniboxImpl::HideWindow() { | 231 void OmniboxImpl::HideWindow() { |
231 DCHECK(root_); | 232 DCHECK(root_); |
232 root_->SetVisible(false); | 233 root_->SetVisible(false); |
233 } | 234 } |
234 | 235 |
235 } // namespace mandoline | 236 } // namespace mandoline |
OLD | NEW |