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 |
index d2fc9278cb768ab8b33d56719df12e3e95f1c964..a772060d42020553b75d37ce928ef3ccc04744bd 100644 |
--- a/mandoline/ui/browser/desktop/desktop_ui.cc |
+++ b/mandoline/ui/browser/desktop/desktop_ui.cc |
@@ -5,12 +5,14 @@ |
#include "mandoline/ui/browser/desktop/desktop_ui.h" |
#include "base/strings/string16.h" |
+#include "base/strings/utf_string_conversions.h" |
#include "mandoline/ui/aura/native_widget_view_manager.h" |
#include "mandoline/ui/browser/browser.h" |
+#include "mandoline/ui/browser/omnibox.mojom.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/controls/button/label_button.h" |
#include "ui/views/widget/widget_delegate.h" |
namespace mandoline { |
@@ -18,13 +20,13 @@ namespace mandoline { |
//////////////////////////////////////////////////////////////////////////////// |
// DesktopUI, public: |
-DesktopUI::DesktopUI(Browser* browser, mojo::Shell* shell) |
+DesktopUI::DesktopUI(Browser* browser, mojo::ApplicationImpl* application_impl) |
: browser_(browser), |
- shell_(shell), |
- omnibox_(new views::Textfield), |
+ application_impl_(application_impl), |
+ omnibox_launcher_( |
+ new views::LabelButton(this, base::ASCIIToUTF16("Open Omnibox"))), |
root_(nullptr), |
- content_(nullptr) { |
- omnibox_->set_controller(this); |
+ client_binding_(browser) { |
} |
DesktopUI::~DesktopUI() {} |
@@ -32,26 +34,29 @@ DesktopUI::~DesktopUI() {} |
//////////////////////////////////////////////////////////////////////////////// |
// DesktopUI, BrowserUI implementation: |
-void DesktopUI::Init(mojo::View* root, mojo::View* content) { |
+void DesktopUI::Init(mojo::View* root) { |
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()->AddChildView(omnibox_launcher_); |
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.native_widget = |
+ new NativeWidgetViewManager(widget, application_impl_->shell(), root_); |
params.delegate = widget_delegate; |
params.bounds = root_->bounds().To<gfx::Rect>(); |
widget->Init(params); |
widget->Show(); |
root_->SetFocus(); |
- omnibox_->RequestFocus(); |
+} |
+ |
+void DesktopUI::OnURLChanged() { |
+ omnibox_launcher_->SetText(base::UTF8ToUTF16(browser_->current_url().spec())); |
} |
//////////////////////////////////////////////////////////////////////////////// |
@@ -62,38 +67,45 @@ gfx::Size DesktopUI::GetPreferredSize(const views::View* view) const { |
} |
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); |
+ gfx::Rect omnibox_launcher_bounds = host->bounds(); |
+ omnibox_launcher_bounds.Inset(10, 10, 10, host->bounds().height() - 40); |
+ omnibox_launcher_->SetBoundsRect(omnibox_launcher_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.x = omnibox_launcher_bounds.x(); |
+ content_bounds_mojo.y = omnibox_launcher_bounds.bottom() + 10; |
+ content_bounds_mojo.width = omnibox_launcher_bounds.width(); |
content_bounds_mojo.height = |
host->bounds().height() - content_bounds_mojo.y - 10; |
- content_->SetBounds(content_bounds_mojo); |
+ browser_->content()->SetBounds(content_bounds_mojo); |
+ |
+ if (browser_->omnibox()) { |
+ browser_->omnibox()->SetBounds( |
+ mojo::TypeConverter<mojo::Rect, gfx::Rect>::Convert(host->bounds())); |
+ } |
} |
//////////////////////////////////////////////////////////////////////////////// |
-// 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; |
+// DesktopUI, views::ButtonListener implementation: |
+ |
+void DesktopUI::ButtonPressed(views::Button* sender, const ui::Event& event) { |
+ if (!omnibox_.get()) { |
+ DCHECK(!client_binding_.is_bound()); |
+ application_impl_->ConnectToService("mojo:omnibox", &omnibox_); |
+ OmniboxClientPtr client; |
+ client_binding_.Bind(&client); |
+ omnibox_->SetClient(client.Pass()); |
} |
- return false; |
+ omnibox_->ShowForURL(mojo::String::From(browser_->current_url().spec())); |
} |
//////////////////////////////////////////////////////////////////////////////// |
// BrowserUI, public: |
// static |
-BrowserUI* BrowserUI::Create(Browser* browser, mojo::Shell* shell) { |
- return new DesktopUI(browser, shell); |
+BrowserUI* BrowserUI::Create(Browser* browser, |
+ mojo::ApplicationImpl* application_impl) { |
+ return new DesktopUI(browser, application_impl); |
} |
} // namespace mandoline |