| 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/context_interface_factory.h" |
| 13 #include "mojo/services/public/cpp/view_manager/node.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.h" |
| 15 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 16 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
| 17 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" |
| 16 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 18 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
| 17 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 19 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
| 18 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" | 20 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" |
| 19 #include "mojo/views/native_widget_view_manager.h" | 21 #include "mojo/views/native_widget_view_manager.h" |
| 20 #include "mojo/views/views_init.h" | 22 #include "mojo/views/views_init.h" |
| 21 #include "ui/events/event.h" | 23 #include "ui/events/event.h" |
| 22 #include "ui/views/layout/fill_layout.h" | 24 #include "ui/views/layout/fill_layout.h" |
| 23 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
| 24 #include "ui/views/widget/widget_delegate.h" | 26 #include "ui/views/widget/widget_delegate.h" |
| 25 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 26 | 28 |
| 27 using mojo::view_manager::Id; | 29 using mojo::view_manager::Id; |
| 28 | 30 |
| 29 namespace mojo { | 31 namespace mojo { |
| 30 namespace examples { | 32 namespace examples { |
| 31 | 33 |
| 32 class Keyboard; | 34 class Keyboard; |
| 33 | 35 |
| 34 class KeyboardServiceImpl : public InterfaceImpl<KeyboardService> { | 36 class KeyboardServiceImpl : public InterfaceImpl<KeyboardService> { |
| 35 public: | 37 public: |
| 36 KeyboardServiceImpl(ApplicationConnection* connection, Keyboard* keyboard); | 38 explicit KeyboardServiceImpl(Keyboard* keyboard); |
| 37 virtual ~KeyboardServiceImpl() {} | 39 virtual ~KeyboardServiceImpl() {} |
| 38 | 40 |
| 39 // KeyboardService: | 41 // KeyboardService: |
| 40 virtual void SetTarget(uint32_t node_id) OVERRIDE; | 42 virtual void SetTarget(uint32_t node_id) OVERRIDE; |
| 41 | 43 |
| 42 private: | 44 private: |
| 43 Keyboard* keyboard_; | 45 Keyboard* keyboard_; |
| 44 | 46 |
| 45 DISALLOW_COPY_AND_ASSIGN(KeyboardServiceImpl); | 47 DISALLOW_COPY_AND_ASSIGN(KeyboardServiceImpl); |
| 46 }; | 48 }; |
| 47 | 49 |
| 48 class Keyboard : public ApplicationDelegate, | 50 class Keyboard : public ApplicationDelegate, |
| 49 public view_manager::ViewManagerDelegate, | 51 public view_manager::ViewManagerDelegate, |
| 50 public KeyboardDelegate { | 52 public KeyboardDelegate, |
| 53 public ContextInterfaceFactory<KeyboardServiceImpl, Keyboard> { |
| 51 public: | 54 public: |
| 52 Keyboard() : view_manager_(NULL), keyboard_service_(NULL), target_(0) {} | 55 Keyboard() |
| 56 : ContextInterfaceFactory(this), |
| 57 view_manager_(NULL), |
| 58 view_manager_client_factory_(this), |
| 59 keyboard_service_(NULL), |
| 60 target_(0) {} |
| 53 | 61 |
| 54 virtual ~Keyboard() { | 62 virtual ~Keyboard() { |
| 55 } | 63 } |
| 56 | 64 |
| 57 void set_target(Id id) { target_ = id; } | 65 void set_target(Id id) { target_ = id; } |
| 58 | 66 |
| 59 void set_keyboard_service(KeyboardServiceImpl* keyboard) { | 67 void set_keyboard_service(KeyboardServiceImpl* keyboard) { |
| 60 keyboard_service_ = keyboard; | 68 keyboard_service_ = keyboard; |
| 61 } | 69 } |
| 62 | 70 |
| 63 private: | 71 private: |
| 64 // Overridden from ApplicationDelegate: | 72 // Overridden from ApplicationDelegate: |
| 65 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 73 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
| 66 MOJO_OVERRIDE { | 74 MOJO_OVERRIDE { |
| 67 views_init_.reset(new ViewsInit); | 75 views_init_.reset(new ViewsInit); |
| 68 view_manager::ViewManager::ConfigureIncomingConnection(connection, this); | 76 connection->AddServiceFactory(&view_manager_client_factory_); |
| 69 connection->AddService<KeyboardServiceImpl>(this); | 77 connection->AddServiceFactory(this); |
| 70 return true; | 78 return true; |
| 71 } | 79 } |
| 72 | 80 |
| 73 void CreateWidget(view_manager::Node* node) { | 81 void CreateWidget(view_manager::Node* node) { |
| 74 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; | 82 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; |
| 75 widget_delegate->GetContentsView()->AddChildView(new KeyboardView(this)); | 83 widget_delegate->GetContentsView()->AddChildView(new KeyboardView(this)); |
| 76 widget_delegate->GetContentsView()->SetLayoutManager(new views::FillLayout); | 84 widget_delegate->GetContentsView()->SetLayoutManager(new views::FillLayout); |
| 77 | 85 |
| 78 views::Widget* widget = new views::Widget; | 86 views::Widget* widget = new views::Widget; |
| 79 views::Widget::InitParams params( | 87 views::Widget::InitParams params( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 104 virtual void OnKeyPressed(int key_code, int event_flags) OVERRIDE { | 112 virtual void OnKeyPressed(int key_code, int event_flags) OVERRIDE { |
| 105 if (!target_) | 113 if (!target_) |
| 106 return; | 114 return; |
| 107 keyboard_service_->client()->OnKeyboardEvent(target_, key_code, | 115 keyboard_service_->client()->OnKeyboardEvent(target_, key_code, |
| 108 event_flags); | 116 event_flags); |
| 109 } | 117 } |
| 110 | 118 |
| 111 scoped_ptr<ViewsInit> views_init_; | 119 scoped_ptr<ViewsInit> views_init_; |
| 112 | 120 |
| 113 view_manager::ViewManager* view_manager_; | 121 view_manager::ViewManager* view_manager_; |
| 122 view_manager::ViewManagerClientFactory view_manager_client_factory_; |
| 114 | 123 |
| 115 KeyboardServiceImpl* keyboard_service_; | 124 KeyboardServiceImpl* keyboard_service_; |
| 116 | 125 |
| 117 Id target_; | 126 Id target_; |
| 118 | 127 |
| 119 DISALLOW_COPY_AND_ASSIGN(Keyboard); | 128 DISALLOW_COPY_AND_ASSIGN(Keyboard); |
| 120 }; | 129 }; |
| 121 | 130 |
| 122 KeyboardServiceImpl::KeyboardServiceImpl(ApplicationConnection* connection, | 131 KeyboardServiceImpl::KeyboardServiceImpl(Keyboard* keyboard) |
| 123 Keyboard* keyboard) | |
| 124 : keyboard_(keyboard) { | 132 : keyboard_(keyboard) { |
| 125 keyboard_->set_keyboard_service(this); | 133 keyboard_->set_keyboard_service(this); |
| 126 } | 134 } |
| 127 | 135 |
| 128 void KeyboardServiceImpl::SetTarget(uint32_t node_id) { | 136 void KeyboardServiceImpl::SetTarget(uint32_t node_id) { |
| 129 keyboard_->set_target(node_id); | 137 keyboard_->set_target(node_id); |
| 130 } | 138 } |
| 131 | 139 |
| 132 } // namespace examples | 140 } // namespace examples |
| 133 | 141 |
| 134 // static | 142 // static |
| 135 ApplicationDelegate* ApplicationDelegate::Create() { | 143 ApplicationDelegate* ApplicationDelegate::Create() { |
| 136 return new examples::Keyboard; | 144 return new examples::Keyboard; |
| 137 } | 145 } |
| 138 | 146 |
| 139 } // namespace mojo | 147 } // namespace mojo |
| OLD | NEW |