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

Unified Diff: mandoline/ui/browser/desktop/desktop_ui.cc

Issue 1136593004: Add a simple browser UI (with url bar) (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/browser/desktop/desktop_ui.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mandoline/ui/browser/desktop/desktop_ui.cc
diff --git a/mandoline/ui/browser/desktop/desktop_ui.cc b/mandoline/ui/browser/desktop/desktop_ui.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d2fc9278cb768ab8b33d56719df12e3e95f1c964
--- /dev/null
+++ b/mandoline/ui/browser/desktop/desktop_ui.cc
@@ -0,0 +1,99 @@
+// 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/browser/desktop/desktop_ui.h"
+
+#include "base/strings/string16.h"
+#include "mandoline/ui/aura/native_widget_view_manager.h"
+#include "mandoline/ui/browser/browser.h"
+#include "mojo/common/common_type_converters.h"
+#include "mojo/converters/geometry/geometry_type_converters.h"
+#include "ui/views/background.h"
+#include "ui/views/controls/textfield/textfield.h"
+#include "ui/views/widget/widget_delegate.h"
+
+namespace mandoline {
+
+////////////////////////////////////////////////////////////////////////////////
+// DesktopUI, public:
+
+DesktopUI::DesktopUI(Browser* browser, mojo::Shell* shell)
+ : browser_(browser),
+ shell_(shell),
+ omnibox_(new views::Textfield),
+ root_(nullptr),
+ content_(nullptr) {
+ omnibox_->set_controller(this);
+}
+
+DesktopUI::~DesktopUI() {}
+
+////////////////////////////////////////////////////////////////////////////////
+// DesktopUI, BrowserUI implementation:
+
+void DesktopUI::Init(mojo::View* root, mojo::View* content) {
+ root_ = root;
+ content_ = content;
+
+ views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView;
+ widget_delegate->GetContentsView()->set_background(
+ views::Background::CreateSolidBackground(0xFFDDDDDD));
+ widget_delegate->GetContentsView()->AddChildView(omnibox_);
+ widget_delegate->GetContentsView()->SetLayoutManager(this);
+
+ views::Widget* widget = new views::Widget;
+ views::Widget::InitParams params(
+ views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
+ params.native_widget = new NativeWidgetViewManager(widget, shell_, root_);
+ params.delegate = widget_delegate;
+ params.bounds = root_->bounds().To<gfx::Rect>();
+ widget->Init(params);
+ widget->Show();
+ root_->SetFocus();
+ omnibox_->RequestFocus();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// DesktopUI, views::LayoutManager implementation:
+
+gfx::Size DesktopUI::GetPreferredSize(const views::View* view) const {
+ return gfx::Size();
+}
+
+void DesktopUI::Layout(views::View* host) {
+ gfx::Rect omnibox_bounds = host->bounds();
+ omnibox_bounds.Inset(10, 10, 10, host->bounds().height() - 40);
+ omnibox_->SetBoundsRect(omnibox_bounds);
+
+ mojo::Rect content_bounds_mojo;
+ content_bounds_mojo.x = omnibox_bounds.x();
+ content_bounds_mojo.y = omnibox_bounds.bottom() + 10;
+ content_bounds_mojo.width = omnibox_bounds.width();
+ content_bounds_mojo.height =
+ host->bounds().height() - content_bounds_mojo.y - 10;
+ content_->SetBounds(content_bounds_mojo);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// DesktopUI, views::TextfieldController implementation:
+
+bool DesktopUI::HandleKeyEvent(views::Textfield* sender,
+ const ui::KeyEvent& key_event) {
+ if (key_event.key_code() == ui::VKEY_RETURN) {
+ browser_->ReplaceContentWithURL(
+ mojo::String::From<base::string16>(sender->text()));
+ return true;
+ }
+ return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// BrowserUI, public:
+
+// static
+BrowserUI* BrowserUI::Create(Browser* browser, mojo::Shell* shell) {
+ return new DesktopUI(browser, shell);
+}
+
+} // namespace mandoline
« no previous file with comments | « mandoline/ui/browser/desktop/desktop_ui.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698