| 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 "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "components/mus/public/cpp/view_tree_connection.h" | 9 #include "components/mus/public/cpp/view_tree_connection.h" |
| 10 #include "components/mus/public/cpp/view_tree_delegate.h" | 10 #include "components/mus/public/cpp/view_tree_delegate.h" |
| 11 #include "components/url_formatter/url_fixer.h" | 11 #include "components/url_formatter/url_fixer.h" |
| 12 #include "mandoline/ui/aura/aura_init.h" | 12 #include "mandoline/ui/aura/aura_init.h" |
| 13 #include "mandoline/ui/aura/native_widget_view_manager.h" | 13 #include "mandoline/ui/aura/native_widget_view_manager.h" |
| 14 #include "mandoline/ui/desktop_ui/public/interfaces/view_embedder.mojom.h" | 14 #include "mandoline/ui/desktop_ui/public/interfaces/view_embedder.mojom.h" |
| 15 #include "mojo/application/public/cpp/application_impl.h" | 15 #include "mojo/application/public/cpp/application_impl.h" |
| 16 #include "mojo/common/common_type_converters.h" | 16 #include "mojo/common/common_type_converters.h" |
| 17 #include "mojo/converters/geometry/geometry_type_converters.h" | 17 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 18 #include "ui/views/background.h" | 18 #include "ui/views/background.h" |
| 19 #include "ui/views/controls/textfield/textfield.h" | 19 #include "ui/views/controls/textfield/textfield.h" |
| 20 #include "ui/views/controls/textfield/textfield_controller.h" | 20 #include "ui/views/controls/textfield/textfield_controller.h" |
| 21 #include "ui/views/layout/layout_manager.h" | 21 #include "ui/views/layout/layout_manager.h" |
| 22 #include "ui/views/widget/widget_delegate.h" | 22 #include "ui/views/widget/widget_delegate.h" |
| 23 | 23 |
| 24 namespace mandoline { | 24 namespace mandoline { |
| 25 | 25 |
| 26 //////////////////////////////////////////////////////////////////////////////// | 26 //////////////////////////////////////////////////////////////////////////////// |
| 27 // OmniboxImpl | 27 // OmniboxImpl |
| 28 | 28 |
| 29 class OmniboxImpl : public mojo::ViewTreeDelegate, | 29 class OmniboxImpl : public mus::ViewTreeDelegate, |
| 30 public views::LayoutManager, | 30 public views::LayoutManager, |
| 31 public views::TextfieldController, | 31 public views::TextfieldController, |
| 32 public Omnibox { | 32 public Omnibox { |
| 33 public: | 33 public: |
| 34 OmniboxImpl(mojo::ApplicationImpl* app, | 34 OmniboxImpl(mojo::ApplicationImpl* app, |
| 35 mojo::ApplicationConnection* connection, | 35 mojo::ApplicationConnection* connection, |
| 36 mojo::InterfaceRequest<Omnibox> request); | 36 mojo::InterfaceRequest<Omnibox> request); |
| 37 ~OmniboxImpl() override; | 37 ~OmniboxImpl() override; |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 // Overridden from mojo::ViewTreeDelegate: | 40 // Overridden from mus::ViewTreeDelegate: |
| 41 void OnEmbed(mojo::View* root) override; | 41 void OnEmbed(mus::View* root) override; |
| 42 void OnConnectionLost(mojo::ViewTreeConnection* connection) override; | 42 void OnConnectionLost(mus::ViewTreeConnection* connection) override; |
| 43 | 43 |
| 44 // Overridden from views::LayoutManager: | 44 // Overridden from views::LayoutManager: |
| 45 gfx::Size GetPreferredSize(const views::View* view) const override; | 45 gfx::Size GetPreferredSize(const views::View* view) const override; |
| 46 void Layout(views::View* host) override; | 46 void Layout(views::View* host) override; |
| 47 | 47 |
| 48 // Overridden from views::TextfieldController: | 48 // Overridden from views::TextfieldController: |
| 49 bool HandleKeyEvent(views::Textfield* sender, | 49 bool HandleKeyEvent(views::Textfield* sender, |
| 50 const ui::KeyEvent& key_event) override; | 50 const ui::KeyEvent& key_event) override; |
| 51 | 51 |
| 52 // Overridden from Omnibox: | 52 // Overridden from Omnibox: |
| 53 void GetViewTreeClient( | 53 void GetViewTreeClient( |
| 54 mojo::InterfaceRequest<mojo::ViewTreeClient> request) override; | 54 mojo::InterfaceRequest<mojo::ViewTreeClient> request) override; |
| 55 void ShowForURL(const mojo::String& url) override; | 55 void ShowForURL(const mojo::String& url) override; |
| 56 | 56 |
| 57 void HideWindow(); | 57 void HideWindow(); |
| 58 void ShowWindow(); | 58 void ShowWindow(); |
| 59 | 59 |
| 60 scoped_ptr<AuraInit> aura_init_; | 60 scoped_ptr<AuraInit> aura_init_; |
| 61 mojo::ApplicationImpl* app_; | 61 mojo::ApplicationImpl* app_; |
| 62 mojo::View* root_; | 62 mus::View* root_; |
| 63 mojo::String url_; | 63 mojo::String url_; |
| 64 views::Textfield* edit_; | 64 views::Textfield* edit_; |
| 65 mojo::Binding<Omnibox> binding_; | 65 mojo::Binding<Omnibox> binding_; |
| 66 ViewEmbedderPtr view_embedder_; | 66 ViewEmbedderPtr view_embedder_; |
| 67 | 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(OmniboxImpl); | 68 DISALLOW_COPY_AND_ASSIGN(OmniboxImpl); |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 //////////////////////////////////////////////////////////////////////////////// | 71 //////////////////////////////////////////////////////////////////////////////// |
| 72 // OmniboxApplication, public: | 72 // OmniboxApplication, public: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 103 mojo::InterfaceRequest<Omnibox> request) | 103 mojo::InterfaceRequest<Omnibox> request) |
| 104 : app_(app), | 104 : app_(app), |
| 105 root_(nullptr), | 105 root_(nullptr), |
| 106 edit_(nullptr), | 106 edit_(nullptr), |
| 107 binding_(this, request.Pass()) { | 107 binding_(this, request.Pass()) { |
| 108 connection->ConnectToService(&view_embedder_); | 108 connection->ConnectToService(&view_embedder_); |
| 109 } | 109 } |
| 110 OmniboxImpl::~OmniboxImpl() {} | 110 OmniboxImpl::~OmniboxImpl() {} |
| 111 | 111 |
| 112 //////////////////////////////////////////////////////////////////////////////// | 112 //////////////////////////////////////////////////////////////////////////////// |
| 113 // OmniboxImpl, mojo::ViewTreeDelegate implementation: | 113 // OmniboxImpl, mus::ViewTreeDelegate implementation: |
| 114 | 114 |
| 115 void OmniboxImpl::OnEmbed(mojo::View* root) { | 115 void OmniboxImpl::OnEmbed(mus::View* root) { |
| 116 root_ = root; | 116 root_ = root; |
| 117 | 117 |
| 118 if (!aura_init_.get()) { | 118 if (!aura_init_.get()) { |
| 119 aura_init_.reset(new AuraInit(root, app_->shell())); | 119 aura_init_.reset(new AuraInit(root, app_->shell())); |
| 120 edit_ = new views::Textfield; | 120 edit_ = new views::Textfield; |
| 121 edit_->set_controller(this); | 121 edit_->set_controller(this); |
| 122 edit_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); | 122 edit_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); |
| 123 } | 123 } |
| 124 | 124 |
| 125 const int kOpacity = 0xC0; | 125 const int kOpacity = 0xC0; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 141 params.bounds = root->bounds().To<gfx::Rect>(); | 141 params.bounds = root->bounds().To<gfx::Rect>(); |
| 142 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 142 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 143 widget->Init(params); | 143 widget->Init(params); |
| 144 widget->Show(); | 144 widget->Show(); |
| 145 widget->GetCompositor()->SetBackgroundColor( | 145 widget->GetCompositor()->SetBackgroundColor( |
| 146 SkColorSetA(SK_ColorBLACK, kOpacity)); | 146 SkColorSetA(SK_ColorBLACK, kOpacity)); |
| 147 | 147 |
| 148 ShowWindow(); | 148 ShowWindow(); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void OmniboxImpl::OnConnectionLost(mojo::ViewTreeConnection* connection) { | 151 void OmniboxImpl::OnConnectionLost(mus::ViewTreeConnection* connection) { |
| 152 root_ = nullptr; | 152 root_ = nullptr; |
| 153 } | 153 } |
| 154 | 154 |
| 155 //////////////////////////////////////////////////////////////////////////////// | 155 //////////////////////////////////////////////////////////////////////////////// |
| 156 // OmniboxImpl, views::LayoutManager implementation: | 156 // OmniboxImpl, views::LayoutManager implementation: |
| 157 | 157 |
| 158 gfx::Size OmniboxImpl::GetPreferredSize(const views::View* view) const { | 158 gfx::Size OmniboxImpl::GetPreferredSize(const views::View* view) const { |
| 159 return gfx::Size(); | 159 return gfx::Size(); |
| 160 } | 160 } |
| 161 | 161 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 183 return true; | 183 return true; |
| 184 } | 184 } |
| 185 return false; | 185 return false; |
| 186 } | 186 } |
| 187 | 187 |
| 188 //////////////////////////////////////////////////////////////////////////////// | 188 //////////////////////////////////////////////////////////////////////////////// |
| 189 // OmniboxImpl, Omnibox implementation: | 189 // OmniboxImpl, Omnibox implementation: |
| 190 | 190 |
| 191 void OmniboxImpl::GetViewTreeClient( | 191 void OmniboxImpl::GetViewTreeClient( |
| 192 mojo::InterfaceRequest<mojo::ViewTreeClient> request) { | 192 mojo::InterfaceRequest<mojo::ViewTreeClient> request) { |
| 193 mojo::ViewTreeConnection::Create(this, request.Pass()); | 193 mus::ViewTreeConnection::Create(this, request.Pass()); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void OmniboxImpl::ShowForURL(const mojo::String& url) { | 196 void OmniboxImpl::ShowForURL(const mojo::String& url) { |
| 197 url_ = url; | 197 url_ = url; |
| 198 if (root_) { | 198 if (root_) { |
| 199 ShowWindow(); | 199 ShowWindow(); |
| 200 } else { | 200 } else { |
| 201 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 201 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
| 202 request->url = mojo::String::From("mojo:omnibox"); | 202 request->url = mojo::String::From("mojo:omnibox"); |
| 203 view_embedder_->Embed(request.Pass()); | 203 view_embedder_->Embed(request.Pass()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 216 edit_->SelectAll(false); | 216 edit_->SelectAll(false); |
| 217 edit_->RequestFocus(); | 217 edit_->RequestFocus(); |
| 218 } | 218 } |
| 219 | 219 |
| 220 void OmniboxImpl::HideWindow() { | 220 void OmniboxImpl::HideWindow() { |
| 221 DCHECK(root_); | 221 DCHECK(root_); |
| 222 root_->SetVisible(false); | 222 root_->SetVisible(false); |
| 223 } | 223 } |
| 224 | 224 |
| 225 } // namespace mandoline | 225 } // namespace mandoline |
| OLD | NEW |