| 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/browser/desktop/desktop_ui.h" | 5 #include "mandoline/ui/browser/desktop/desktop_ui.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 "mandoline/ui/aura/native_widget_view_manager.h" | 9 #include "mandoline/ui/aura/native_widget_view_manager.h" |
| 9 #include "mandoline/ui/browser/browser.h" | 10 #include "mandoline/ui/browser/browser.h" |
| 11 #include "mandoline/ui/browser/omnibox.mojom.h" |
| 10 #include "mojo/common/common_type_converters.h" | 12 #include "mojo/common/common_type_converters.h" |
| 11 #include "mojo/converters/geometry/geometry_type_converters.h" | 13 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 12 #include "ui/views/background.h" | 14 #include "ui/views/background.h" |
| 13 #include "ui/views/controls/textfield/textfield.h" | 15 #include "ui/views/controls/button/label_button.h" |
| 14 #include "ui/views/widget/widget_delegate.h" | 16 #include "ui/views/widget/widget_delegate.h" |
| 15 | 17 |
| 16 namespace mandoline { | 18 namespace mandoline { |
| 17 | 19 |
| 18 //////////////////////////////////////////////////////////////////////////////// | 20 //////////////////////////////////////////////////////////////////////////////// |
| 19 // DesktopUI, public: | 21 // DesktopUI, public: |
| 20 | 22 |
| 21 DesktopUI::DesktopUI(Browser* browser, mojo::Shell* shell) | 23 DesktopUI::DesktopUI(Browser* browser, mojo::ApplicationImpl* application_impl) |
| 22 : browser_(browser), | 24 : browser_(browser), |
| 23 shell_(shell), | 25 application_impl_(application_impl), |
| 24 omnibox_(new views::Textfield), | 26 omnibox_launcher_( |
| 27 new views::LabelButton(this, base::ASCIIToUTF16("Open Omnibox"))), |
| 25 root_(nullptr), | 28 root_(nullptr), |
| 26 content_(nullptr) { | 29 client_binding_(browser) { |
| 27 omnibox_->set_controller(this); | |
| 28 } | 30 } |
| 29 | 31 |
| 30 DesktopUI::~DesktopUI() {} | 32 DesktopUI::~DesktopUI() {} |
| 31 | 33 |
| 32 //////////////////////////////////////////////////////////////////////////////// | 34 //////////////////////////////////////////////////////////////////////////////// |
| 33 // DesktopUI, BrowserUI implementation: | 35 // DesktopUI, BrowserUI implementation: |
| 34 | 36 |
| 35 void DesktopUI::Init(mojo::View* root, mojo::View* content) { | 37 void DesktopUI::Init(mojo::View* root) { |
| 36 root_ = root; | 38 root_ = root; |
| 37 content_ = content; | |
| 38 | 39 |
| 39 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; | 40 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; |
| 40 widget_delegate->GetContentsView()->set_background( | 41 widget_delegate->GetContentsView()->set_background( |
| 41 views::Background::CreateSolidBackground(0xFFDDDDDD)); | 42 views::Background::CreateSolidBackground(0xFFDDDDDD)); |
| 42 widget_delegate->GetContentsView()->AddChildView(omnibox_); | 43 widget_delegate->GetContentsView()->AddChildView(omnibox_launcher_); |
| 43 widget_delegate->GetContentsView()->SetLayoutManager(this); | 44 widget_delegate->GetContentsView()->SetLayoutManager(this); |
| 44 | 45 |
| 45 views::Widget* widget = new views::Widget; | 46 views::Widget* widget = new views::Widget; |
| 46 views::Widget::InitParams params( | 47 views::Widget::InitParams params( |
| 47 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 48 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 48 params.native_widget = new NativeWidgetViewManager(widget, shell_, root_); | 49 params.native_widget = |
| 50 new NativeWidgetViewManager(widget, application_impl_->shell(), root_); |
| 49 params.delegate = widget_delegate; | 51 params.delegate = widget_delegate; |
| 50 params.bounds = root_->bounds().To<gfx::Rect>(); | 52 params.bounds = root_->bounds().To<gfx::Rect>(); |
| 51 widget->Init(params); | 53 widget->Init(params); |
| 52 widget->Show(); | 54 widget->Show(); |
| 53 root_->SetFocus(); | 55 root_->SetFocus(); |
| 54 omnibox_->RequestFocus(); | 56 } |
| 57 |
| 58 void DesktopUI::OnURLChanged() { |
| 59 omnibox_launcher_->SetText(browser_->current_url().To<base::string16>()); |
| 55 } | 60 } |
| 56 | 61 |
| 57 //////////////////////////////////////////////////////////////////////////////// | 62 //////////////////////////////////////////////////////////////////////////////// |
| 58 // DesktopUI, views::LayoutManager implementation: | 63 // DesktopUI, views::LayoutManager implementation: |
| 59 | 64 |
| 60 gfx::Size DesktopUI::GetPreferredSize(const views::View* view) const { | 65 gfx::Size DesktopUI::GetPreferredSize(const views::View* view) const { |
| 61 return gfx::Size(); | 66 return gfx::Size(); |
| 62 } | 67 } |
| 63 | 68 |
| 64 void DesktopUI::Layout(views::View* host) { | 69 void DesktopUI::Layout(views::View* host) { |
| 65 gfx::Rect omnibox_bounds = host->bounds(); | 70 gfx::Rect omnibox_launcher_bounds = host->bounds(); |
| 66 omnibox_bounds.Inset(10, 10, 10, host->bounds().height() - 40); | 71 omnibox_launcher_bounds.Inset(10, 10, 10, host->bounds().height() - 40); |
| 67 omnibox_->SetBoundsRect(omnibox_bounds); | 72 omnibox_launcher_->SetBoundsRect(omnibox_launcher_bounds); |
| 68 | 73 |
| 69 mojo::Rect content_bounds_mojo; | 74 mojo::Rect content_bounds_mojo; |
| 70 content_bounds_mojo.x = omnibox_bounds.x(); | 75 content_bounds_mojo.x = omnibox_launcher_bounds.x(); |
| 71 content_bounds_mojo.y = omnibox_bounds.bottom() + 10; | 76 content_bounds_mojo.y = omnibox_launcher_bounds.bottom() + 10; |
| 72 content_bounds_mojo.width = omnibox_bounds.width(); | 77 content_bounds_mojo.width = omnibox_launcher_bounds.width(); |
| 73 content_bounds_mojo.height = | 78 content_bounds_mojo.height = |
| 74 host->bounds().height() - content_bounds_mojo.y - 10; | 79 host->bounds().height() - content_bounds_mojo.y - 10; |
| 75 content_->SetBounds(content_bounds_mojo); | 80 browser_->content()->SetBounds(content_bounds_mojo); |
| 81 |
| 82 if (browser_->omnibox()) { |
| 83 browser_->omnibox()->SetBounds( |
| 84 mojo::TypeConverter<mojo::Rect, gfx::Rect>::Convert(host->bounds())); |
| 85 } |
| 76 } | 86 } |
| 77 | 87 |
| 78 //////////////////////////////////////////////////////////////////////////////// | 88 //////////////////////////////////////////////////////////////////////////////// |
| 79 // DesktopUI, views::TextfieldController implementation: | 89 // DesktopUI, views::ButtonListener implementation: |
| 80 | 90 |
| 81 bool DesktopUI::HandleKeyEvent(views::Textfield* sender, | 91 void DesktopUI::ButtonPressed(views::Button* sender, const ui::Event& event) { |
| 82 const ui::KeyEvent& key_event) { | 92 if (!omnibox_.get()) { |
| 83 if (key_event.key_code() == ui::VKEY_RETURN) { | 93 DCHECK(!client_binding_.is_bound()); |
| 84 browser_->ReplaceContentWithURL( | 94 application_impl_->ConnectToService("mojo:omnibox", &omnibox_); |
| 85 mojo::String::From<base::string16>(sender->text())); | 95 OmniboxClientPtr client; |
| 86 return true; | 96 client_binding_.Bind(&client); |
| 97 omnibox_->SetClient(client.Pass()); |
| 87 } | 98 } |
| 88 return false; | 99 omnibox_->ShowForURL(browser_->current_url()); |
| 89 } | 100 } |
| 90 | 101 |
| 91 //////////////////////////////////////////////////////////////////////////////// | 102 //////////////////////////////////////////////////////////////////////////////// |
| 92 // BrowserUI, public: | 103 // BrowserUI, public: |
| 93 | 104 |
| 94 // static | 105 // static |
| 95 BrowserUI* BrowserUI::Create(Browser* browser, mojo::Shell* shell) { | 106 BrowserUI* BrowserUI::Create(Browser* browser, |
| 96 return new DesktopUI(browser, shell); | 107 mojo::ApplicationImpl* application_impl) { |
| 108 return new DesktopUI(browser, application_impl); |
| 97 } | 109 } |
| 98 | 110 |
| 99 } // namespace mandoline | 111 } // namespace mandoline |
| OLD | NEW |