| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/strings/string_util.h" | 6 #include "base/strings/string_util.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "mojo/examples/keyboard/keyboard.mojom.h" | 8 #include "mojo/examples/keyboard/keyboard.mojom.h" |
| 9 #include "mojo/examples/keyboard/keyboard_delegate.h" | 9 #include "mojo/examples/keyboard/keyboard_delegate.h" |
| 10 #include "mojo/examples/keyboard/keyboard_view.h" | 10 #include "mojo/examples/keyboard/keyboard_view.h" |
| 11 #include "mojo/public/cpp/application/application_connection.h" | 11 #include "mojo/public/cpp/application/application_connection.h" |
| 12 #include "mojo/public/cpp/application/application_delegate.h" | 12 #include "mojo/public/cpp/application/application_delegate.h" |
| 13 #include "mojo/public/cpp/application/interface_factory_impl.h" | 13 #include "mojo/public/cpp/application/interface_factory_impl.h" |
| 14 #include "mojo/services/public/cpp/view_manager/node.h" | 14 #include "mojo/services/public/cpp/view_manager/view.h" |
| 15 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 15 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
| 16 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" | 16 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" |
| 17 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 17 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
| 18 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" | 18 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" |
| 19 #include "mojo/views/native_widget_view_manager.h" | 19 #include "mojo/views/native_widget_view_manager.h" |
| 20 #include "mojo/views/views_init.h" | 20 #include "mojo/views/views_init.h" |
| 21 #include "ui/events/event.h" | 21 #include "ui/events/event.h" |
| 22 #include "ui/views/layout/fill_layout.h" | 22 #include "ui/views/layout/fill_layout.h" |
| 23 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
| 24 #include "ui/views/widget/widget_delegate.h" | 24 #include "ui/views/widget/widget_delegate.h" |
| 25 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 26 | 26 |
| 27 namespace mojo { | 27 namespace mojo { |
| 28 namespace examples { | 28 namespace examples { |
| 29 | 29 |
| 30 class Keyboard; | 30 class Keyboard; |
| 31 | 31 |
| 32 class KeyboardServiceImpl : public InterfaceImpl<KeyboardService> { | 32 class KeyboardServiceImpl : public InterfaceImpl<KeyboardService> { |
| 33 public: | 33 public: |
| 34 explicit KeyboardServiceImpl(Keyboard* keyboard); | 34 explicit KeyboardServiceImpl(Keyboard* keyboard); |
| 35 virtual ~KeyboardServiceImpl() {} | 35 virtual ~KeyboardServiceImpl() {} |
| 36 | 36 |
| 37 // KeyboardService: | 37 // KeyboardService: |
| 38 virtual void SetTarget(uint32_t node_id) OVERRIDE; | 38 virtual void SetTarget(uint32_t view_id) OVERRIDE; |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 Keyboard* keyboard_; | 41 Keyboard* keyboard_; |
| 42 | 42 |
| 43 DISALLOW_COPY_AND_ASSIGN(KeyboardServiceImpl); | 43 DISALLOW_COPY_AND_ASSIGN(KeyboardServiceImpl); |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 class Keyboard : public ApplicationDelegate, | 46 class Keyboard : public ApplicationDelegate, |
| 47 public ViewManagerDelegate, | 47 public ViewManagerDelegate, |
| 48 public KeyboardDelegate { | 48 public KeyboardDelegate { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 66 private: | 66 private: |
| 67 // Overridden from ApplicationDelegate: | 67 // Overridden from ApplicationDelegate: |
| 68 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 68 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
| 69 MOJO_OVERRIDE { | 69 MOJO_OVERRIDE { |
| 70 views_init_.reset(new ViewsInit); | 70 views_init_.reset(new ViewsInit); |
| 71 connection->AddService(&view_manager_client_factory_); | 71 connection->AddService(&view_manager_client_factory_); |
| 72 connection->AddService(&keyboard_service_factory_); | 72 connection->AddService(&keyboard_service_factory_); |
| 73 return true; | 73 return true; |
| 74 } | 74 } |
| 75 | 75 |
| 76 void CreateWidget(Node* node) { | 76 void CreateWidget(View* view) { |
| 77 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; | 77 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; |
| 78 widget_delegate->GetContentsView()->AddChildView(new KeyboardView(this)); | 78 widget_delegate->GetContentsView()->AddChildView(new KeyboardView(this)); |
| 79 widget_delegate->GetContentsView()->SetLayoutManager(new views::FillLayout); | 79 widget_delegate->GetContentsView()->SetLayoutManager(new views::FillLayout); |
| 80 | 80 |
| 81 views::Widget* widget = new views::Widget; | 81 views::Widget* widget = new views::Widget; |
| 82 views::Widget::InitParams params( | 82 views::Widget::InitParams params( |
| 83 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 83 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 84 params.native_widget = new NativeWidgetViewManager(widget, node); | 84 params.native_widget = new NativeWidgetViewManager(widget, view); |
| 85 params.delegate = widget_delegate; | 85 params.delegate = widget_delegate; |
| 86 params.bounds = gfx::Rect(node->bounds().width(), node->bounds().height()); | 86 params.bounds = gfx::Rect(view->bounds().width(), view->bounds().height()); |
| 87 widget->Init(params); | 87 widget->Init(params); |
| 88 widget->Show(); | 88 widget->Show(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 // ViewManagerDelegate: | 91 // ViewManagerDelegate: |
| 92 virtual void OnEmbed(ViewManager* view_manager, | 92 virtual void OnEmbed(ViewManager* view_manager, |
| 93 Node* root, | 93 View* root, |
| 94 ServiceProviderImpl* exported_services, | 94 ServiceProviderImpl* exported_services, |
| 95 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { | 95 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { |
| 96 // TODO: deal with OnEmbed() being invoked multiple times. | 96 // TODO: deal with OnEmbed() being invoked multiple times. |
| 97 view_manager_ = view_manager; | 97 view_manager_ = view_manager; |
| 98 CreateWidget(root); | 98 CreateWidget(root); |
| 99 } | 99 } |
| 100 virtual void OnViewManagerDisconnected( | 100 virtual void OnViewManagerDisconnected( |
| 101 ViewManager* view_manager) OVERRIDE { | 101 ViewManager* view_manager) OVERRIDE { |
| 102 DCHECK_EQ(view_manager_, view_manager); | 102 DCHECK_EQ(view_manager_, view_manager); |
| 103 view_manager_ = NULL; | 103 view_manager_ = NULL; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 125 Id target_; | 125 Id target_; |
| 126 | 126 |
| 127 DISALLOW_COPY_AND_ASSIGN(Keyboard); | 127 DISALLOW_COPY_AND_ASSIGN(Keyboard); |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 KeyboardServiceImpl::KeyboardServiceImpl(Keyboard* keyboard) | 130 KeyboardServiceImpl::KeyboardServiceImpl(Keyboard* keyboard) |
| 131 : keyboard_(keyboard) { | 131 : keyboard_(keyboard) { |
| 132 keyboard_->set_keyboard_service(this); | 132 keyboard_->set_keyboard_service(this); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void KeyboardServiceImpl::SetTarget(uint32_t node_id) { | 135 void KeyboardServiceImpl::SetTarget(uint32_t view_id) { |
| 136 keyboard_->set_target(node_id); | 136 keyboard_->set_target(view_id); |
| 137 } | 137 } |
| 138 | 138 |
| 139 } // namespace examples | 139 } // namespace examples |
| 140 | 140 |
| 141 // static | 141 // static |
| 142 ApplicationDelegate* ApplicationDelegate::Create() { | 142 ApplicationDelegate* ApplicationDelegate::Create() { |
| 143 return new examples::Keyboard; | 143 return new examples::Keyboard; |
| 144 } | 144 } |
| 145 | 145 |
| 146 } // namespace mojo | 146 } // namespace mojo |
| OLD | NEW |