OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "mandoline/ui/browser/desktop/desktop_ui.h" |
| 6 |
| 7 #include "base/strings/string16.h" |
| 8 #include "mandoline/ui/aura/native_widget_view_manager.h" |
| 9 #include "mandoline/ui/browser/browser.h" |
| 10 #include "mojo/common/common_type_converters.h" |
| 11 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 12 #include "ui/views/background.h" |
| 13 #include "ui/views/controls/textfield/textfield.h" |
| 14 #include "ui/views/widget/widget_delegate.h" |
| 15 |
| 16 namespace mandoline { |
| 17 |
| 18 //////////////////////////////////////////////////////////////////////////////// |
| 19 // DesktopUI, public: |
| 20 |
| 21 DesktopUI::DesktopUI(Browser* browser, mojo::Shell* shell) |
| 22 : browser_(browser), |
| 23 shell_(shell), |
| 24 omnibox_(new views::Textfield), |
| 25 root_(nullptr), |
| 26 content_(nullptr) { |
| 27 omnibox_->set_controller(this); |
| 28 } |
| 29 |
| 30 DesktopUI::~DesktopUI() {} |
| 31 |
| 32 //////////////////////////////////////////////////////////////////////////////// |
| 33 // DesktopUI, BrowserUI implementation: |
| 34 |
| 35 void DesktopUI::Init(mojo::View* root, mojo::View* content) { |
| 36 root_ = root; |
| 37 content_ = content; |
| 38 |
| 39 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; |
| 40 widget_delegate->GetContentsView()->set_background( |
| 41 views::Background::CreateSolidBackground(0xFFDDDDDD)); |
| 42 widget_delegate->GetContentsView()->AddChildView(omnibox_); |
| 43 widget_delegate->GetContentsView()->SetLayoutManager(this); |
| 44 |
| 45 views::Widget* widget = new views::Widget; |
| 46 views::Widget::InitParams params( |
| 47 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 48 params.native_widget = new NativeWidgetViewManager(widget, shell_, root_); |
| 49 params.delegate = widget_delegate; |
| 50 params.bounds = root_->bounds().To<gfx::Rect>(); |
| 51 widget->Init(params); |
| 52 widget->Show(); |
| 53 root_->SetFocus(); |
| 54 omnibox_->RequestFocus(); |
| 55 } |
| 56 |
| 57 //////////////////////////////////////////////////////////////////////////////// |
| 58 // DesktopUI, views::LayoutManager implementation: |
| 59 |
| 60 gfx::Size DesktopUI::GetPreferredSize(const views::View* view) const { |
| 61 return gfx::Size(); |
| 62 } |
| 63 |
| 64 void DesktopUI::Layout(views::View* host) { |
| 65 gfx::Rect omnibox_bounds = host->bounds(); |
| 66 omnibox_bounds.Inset(10, 10, 10, host->bounds().height() - 40); |
| 67 omnibox_->SetBoundsRect(omnibox_bounds); |
| 68 |
| 69 mojo::Rect content_bounds_mojo; |
| 70 content_bounds_mojo.x = omnibox_bounds.x(); |
| 71 content_bounds_mojo.y = omnibox_bounds.bottom() + 10; |
| 72 content_bounds_mojo.width = omnibox_bounds.width(); |
| 73 content_bounds_mojo.height = |
| 74 host->bounds().height() - content_bounds_mojo.y - 10; |
| 75 content_->SetBounds(content_bounds_mojo); |
| 76 } |
| 77 |
| 78 //////////////////////////////////////////////////////////////////////////////// |
| 79 // DesktopUI, views::TextfieldController implementation: |
| 80 |
| 81 bool DesktopUI::HandleKeyEvent(views::Textfield* sender, |
| 82 const ui::KeyEvent& key_event) { |
| 83 if (key_event.key_code() == ui::VKEY_RETURN) { |
| 84 browser_->ReplaceContentWithURL( |
| 85 mojo::String::From<base::string16>(sender->text())); |
| 86 return true; |
| 87 } |
| 88 return false; |
| 89 } |
| 90 |
| 91 //////////////////////////////////////////////////////////////////////////////// |
| 92 // BrowserUI, public: |
| 93 |
| 94 // static |
| 95 BrowserUI* BrowserUI::Create(Browser* browser, mojo::Shell* shell) { |
| 96 return new DesktopUI(browser, shell); |
| 97 } |
| 98 |
| 99 } // namespace mandoline |
OLD | NEW |