Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(841)

Unified Diff: mandoline/ui/omnibox/omnibox_impl.cc

Issue 1133893003: Omnibox app (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mandoline/ui/omnibox/omnibox_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mandoline/ui/omnibox/omnibox_impl.cc
diff --git a/mandoline/ui/omnibox/omnibox_impl.cc b/mandoline/ui/omnibox/omnibox_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cef777ced0dcb1881df5d4c37d7d08bf9a960c40
--- /dev/null
+++ b/mandoline/ui/omnibox/omnibox_impl.cc
@@ -0,0 +1,138 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mandoline/ui/omnibox/omnibox_impl.h"
+
+#include "base/strings/string16.h"
+#include "components/view_manager/public/cpp/view_manager_client_factory.h"
+#include "components/window_manager/public/interfaces/window_manager.mojom.h"
+#include "mandoline/ui/aura/aura_init.h"
+#include "mandoline/ui/aura/native_widget_view_manager.h"
+#include "mojo/common/common_type_converters.h"
+#include "mojo/converters/geometry/geometry_type_converters.h"
+#include "third_party/mojo/src/mojo/public/cpp/application/application_impl.h"
+#include "ui/views/background.h"
+#include "ui/views/controls/textfield/textfield.h"
+#include "ui/views/widget/widget_delegate.h"
+
+namespace mandoline {
+
+////////////////////////////////////////////////////////////////////////////////
+// OmniboxImpl, public:
+
+OmniboxImpl::OmniboxImpl()
+ : app_impl_(nullptr),
+ edit_(nullptr) {
+}
+OmniboxImpl::~OmniboxImpl() {}
+
+////////////////////////////////////////////////////////////////////////////////
+// OmniboxImpl, mojo::ApplicationDelegate implementation:
+
+void OmniboxImpl::Initialize(mojo::ApplicationImpl* app) {
+ app_impl_ = app;
+ view_manager_client_factory_.reset(
+ new mojo::ViewManagerClientFactory(app->shell(), this));
+}
+
+bool OmniboxImpl::ConfigureIncomingConnection(
+ mojo::ApplicationConnection* connection) {
+ connection->AddService<Omnibox>(this);
+ connection->AddService(view_manager_client_factory_.get());
+ return true;
+}
+
+bool OmniboxImpl::ConfigureOutgoingConnection(
+ mojo::ApplicationConnection* connection) {
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// OmniboxImpl, mojo::ViewManagerDelegate implementation:
+
+void OmniboxImpl::OnEmbed(mojo::View* root,
+ mojo::InterfaceRequest<mojo::ServiceProvider> services,
+ mojo::ServiceProviderPtr exposed_services) {
+ if (!aura_init_.get()) {
+ aura_init_.reset(new AuraInit);
+ edit_ = new views::Textfield;
+ edit_->set_controller(this);
+ }
+
+ views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView;
+ widget_delegate->GetContentsView()->set_background(
+ views::Background::CreateSolidBackground(0xFFDDDDDD));
+ widget_delegate->GetContentsView()->AddChildView(edit_);
+ widget_delegate->GetContentsView()->SetLayoutManager(this);
+
+ // TODO(beng): we may be leaking these on subsequent calls to OnEmbed()...
+ // probably should only allow once instance per view.
+ views::Widget* widget = new views::Widget;
+ views::Widget::InitParams params(
+ views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
+ params.native_widget =
+ new NativeWidgetViewManager(widget, app_impl_->shell(), root);
+ params.delegate = widget_delegate;
+ params.bounds = root->bounds().To<gfx::Rect>();
+ widget->Init(params);
+ widget->Show();
+ root->SetFocus();
+ edit_->SetText(url_.To<base::string16>());
+ edit_->SelectAll(false);
+ edit_->RequestFocus();
+}
+
+void OmniboxImpl::OnViewManagerDisconnected(mojo::ViewManager* view_manager) {}
+
+////////////////////////////////////////////////////////////////////////////////
+// OmniboxImpl, views::LayoutManager implementation:
+
+gfx::Size OmniboxImpl::GetPreferredSize(const views::View* view) const {
+ return gfx::Size();
+}
+
+void OmniboxImpl::Layout(views::View* host) {
+ gfx::Rect edit_bounds = host->bounds();
+ edit_bounds.Inset(10, 10, 10, host->bounds().height() - 40);
+ edit_->SetBoundsRect(edit_bounds);
+
+ // TODO(beng): layout dropdown...
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// OmniboxImpl, views::TextfieldController implementation:
+
+bool OmniboxImpl::HandleKeyEvent(views::Textfield* sender,
+ const ui::KeyEvent& key_event) {
+ if (key_event.key_code() == ui::VKEY_RETURN) {
+ // TODO(beng): call back to browser.
+ client_->OpenURL(mojo::String::From<base::string16>(sender->text()));
+ return true;
+ }
+ return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// OmniboxImpl, mojo::InterfaceFactory<Omnibox> implementation:
+
+void OmniboxImpl::Create(mojo::ApplicationConnection* connection,
+ mojo::InterfaceRequest<Omnibox> request) {
+ bindings_.AddBinding(this, request.Pass());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// OmniboxImpl, Omnibox implementation:
+
+void OmniboxImpl::SetClient(OmniboxClientPtr client) {
+ client_ = client.Pass();
+}
+
+void OmniboxImpl::ShowForURL(const mojo::String& url) {
+ url_ = url;
+ mojo::WindowManagerPtr window_manager;
+ app_impl_->ConnectToService("mojo:window_manager", &window_manager);
+ window_manager->Embed("mojo:omnibox", nullptr, nullptr);
+}
+
+} // namespace mandoline
« no previous file with comments | « mandoline/ui/omnibox/omnibox_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698