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.h" | 9 #include "components/mus/public/cpp/view.h" |
10 #include "components/mus/public/cpp/view_tree_connection.h" | 10 #include "components/mus/public/cpp/view_tree_connection.h" |
11 #include "components/mus/public/cpp/view_tree_delegate.h" | 11 #include "components/mus/public/cpp/view_tree_delegate.h" |
12 #include "components/url_formatter/url_fixer.h" | 12 #include "components/url_formatter/url_fixer.h" |
13 #include "mandoline/ui/aura/aura_init.h" | |
14 #include "mandoline/ui/aura/native_widget_view_manager.h" | |
15 #include "mandoline/ui/desktop_ui/public/interfaces/view_embedder.mojom.h" | 13 #include "mandoline/ui/desktop_ui/public/interfaces/view_embedder.mojom.h" |
16 #include "mojo/application/public/cpp/application_impl.h" | 14 #include "mojo/application/public/cpp/application_impl.h" |
17 #include "mojo/common/common_type_converters.h" | 15 #include "mojo/common/common_type_converters.h" |
18 #include "mojo/converters/geometry/geometry_type_converters.h" | 16 #include "mojo/converters/geometry/geometry_type_converters.h" |
19 #include "ui/views/background.h" | 17 #include "ui/views/background.h" |
20 #include "ui/views/controls/textfield/textfield.h" | 18 #include "ui/views/controls/textfield/textfield.h" |
21 #include "ui/views/controls/textfield/textfield_controller.h" | 19 #include "ui/views/controls/textfield/textfield_controller.h" |
22 #include "ui/views/layout/layout_manager.h" | 20 #include "ui/views/layout/layout_manager.h" |
| 21 #include "ui/views/mus/aura_init.h" |
| 22 #include "ui/views/mus/native_widget_view_manager.h" |
23 #include "ui/views/widget/widget_delegate.h" | 23 #include "ui/views/widget/widget_delegate.h" |
24 | 24 |
25 namespace mandoline { | 25 namespace mandoline { |
26 | 26 |
27 //////////////////////////////////////////////////////////////////////////////// | 27 //////////////////////////////////////////////////////////////////////////////// |
28 // OmniboxImpl | 28 // OmniboxImpl |
29 | 29 |
30 class OmniboxImpl : public mus::ViewTreeDelegate, | 30 class OmniboxImpl : public mus::ViewTreeDelegate, |
31 public views::LayoutManager, | 31 public views::LayoutManager, |
32 public views::TextfieldController, | 32 public views::TextfieldController, |
(...skipping 18 matching lines...) Expand all Loading... |
51 const ui::KeyEvent& key_event) override; | 51 const ui::KeyEvent& key_event) override; |
52 | 52 |
53 // Overridden from Omnibox: | 53 // Overridden from Omnibox: |
54 void GetViewTreeClient( | 54 void GetViewTreeClient( |
55 mojo::InterfaceRequest<mojo::ViewTreeClient> request) override; | 55 mojo::InterfaceRequest<mojo::ViewTreeClient> request) override; |
56 void ShowForURL(const mojo::String& url) override; | 56 void ShowForURL(const mojo::String& url) override; |
57 | 57 |
58 void HideWindow(); | 58 void HideWindow(); |
59 void ShowWindow(); | 59 void ShowWindow(); |
60 | 60 |
61 scoped_ptr<AuraInit> aura_init_; | 61 scoped_ptr<views::AuraInit> aura_init_; |
62 mojo::ApplicationImpl* app_; | 62 mojo::ApplicationImpl* app_; |
63 mus::View* root_; | 63 mus::View* root_; |
64 mojo::String url_; | 64 mojo::String url_; |
65 views::Textfield* edit_; | 65 views::Textfield* edit_; |
66 mojo::Binding<Omnibox> binding_; | 66 mojo::Binding<Omnibox> binding_; |
67 ViewEmbedderPtr view_embedder_; | 67 ViewEmbedderPtr view_embedder_; |
68 | 68 |
69 DISALLOW_COPY_AND_ASSIGN(OmniboxImpl); | 69 DISALLOW_COPY_AND_ASSIGN(OmniboxImpl); |
70 }; | 70 }; |
71 | 71 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 } | 110 } |
111 OmniboxImpl::~OmniboxImpl() {} | 111 OmniboxImpl::~OmniboxImpl() {} |
112 | 112 |
113 //////////////////////////////////////////////////////////////////////////////// | 113 //////////////////////////////////////////////////////////////////////////////// |
114 // OmniboxImpl, mus::ViewTreeDelegate implementation: | 114 // OmniboxImpl, mus::ViewTreeDelegate implementation: |
115 | 115 |
116 void OmniboxImpl::OnEmbed(mus::View* root) { | 116 void OmniboxImpl::OnEmbed(mus::View* root) { |
117 root_ = root; | 117 root_ = root; |
118 | 118 |
119 if (!aura_init_.get()) { | 119 if (!aura_init_.get()) { |
120 aura_init_.reset(new AuraInit(root, app_->shell(), "mandoline_ui.pak")); | 120 aura_init_.reset( |
| 121 new views::AuraInit(root, app_->shell(), "mandoline_ui.pak")); |
121 edit_ = new views::Textfield; | 122 edit_ = new views::Textfield; |
122 edit_->set_controller(this); | 123 edit_->set_controller(this); |
123 edit_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); | 124 edit_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); |
124 } | 125 } |
125 | 126 |
126 const int kOpacity = 0xC0; | 127 const int kOpacity = 0xC0; |
127 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; | 128 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; |
128 widget_delegate->GetContentsView()->set_background( | 129 widget_delegate->GetContentsView()->set_background( |
129 views::Background::CreateSolidBackground( | 130 views::Background::CreateSolidBackground( |
130 SkColorSetA(0xDDDDDD, kOpacity))); | 131 SkColorSetA(0xDDDDDD, kOpacity))); |
131 widget_delegate->GetContentsView()->AddChildView(edit_); | 132 widget_delegate->GetContentsView()->AddChildView(edit_); |
132 widget_delegate->GetContentsView()->SetLayoutManager(this); | 133 widget_delegate->GetContentsView()->SetLayoutManager(this); |
133 | 134 |
134 // TODO(beng): we may be leaking these on subsequent calls to OnEmbed()... | 135 // TODO(beng): we may be leaking these on subsequent calls to OnEmbed()... |
135 // probably should only allow once instance per view. | 136 // probably should only allow once instance per view. |
136 views::Widget* widget = new views::Widget; | 137 views::Widget* widget = new views::Widget; |
137 views::Widget::InitParams params( | 138 views::Widget::InitParams params( |
138 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 139 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
139 params.native_widget = | 140 params.native_widget = |
140 new NativeWidgetViewManager(widget, app_->shell(), root); | 141 new views::NativeWidgetViewManager(widget, app_->shell(), root); |
141 params.delegate = widget_delegate; | 142 params.delegate = widget_delegate; |
142 params.bounds = root->bounds().To<gfx::Rect>(); | 143 params.bounds = root->bounds().To<gfx::Rect>(); |
143 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 144 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
144 widget->Init(params); | 145 widget->Init(params); |
145 widget->Show(); | 146 widget->Show(); |
146 widget->GetCompositor()->SetBackgroundColor( | 147 widget->GetCompositor()->SetBackgroundColor( |
147 SkColorSetA(SK_ColorBLACK, kOpacity)); | 148 SkColorSetA(SK_ColorBLACK, kOpacity)); |
148 | 149 |
149 ShowWindow(); | 150 ShowWindow(); |
150 } | 151 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 edit_->SelectAll(false); | 220 edit_->SelectAll(false); |
220 edit_->RequestFocus(); | 221 edit_->RequestFocus(); |
221 } | 222 } |
222 | 223 |
223 void OmniboxImpl::HideWindow() { | 224 void OmniboxImpl::HideWindow() { |
224 DCHECK(root_); | 225 DCHECK(root_); |
225 root_->SetVisible(false); | 226 root_->SetVisible(false); |
226 } | 227 } |
227 | 228 |
228 } // namespace mandoline | 229 } // namespace mandoline |
OLD | NEW |