Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Side by Side Diff: mojo/examples/png_viewer/png_viewer.cc

Issue 380413003: Mojo: Use InterfaceFactory<Interface> for service registration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix network_service_loader Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/examples/nesting_app/nesting_app.cc ('k') | mojo/examples/surfaces_app/child_app.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/strings/string_tokenizer.h" 8 #include "base/strings/string_tokenizer.h"
9 #include "mojo/examples/media_viewer/media_viewer.mojom.h" 9 #include "mojo/examples/media_viewer/media_viewer.mojom.h"
10 #include "mojo/public/cpp/application/application_connection.h" 10 #include "mojo/public/cpp/application/application_connection.h"
11 #include "mojo/public/cpp/application/application_delegate.h" 11 #include "mojo/public/cpp/application/application_delegate.h"
12 #include "mojo/public/cpp/application/interface_factory_with_context.h"
12 #include "mojo/services/public/cpp/view_manager/node.h" 13 #include "mojo/services/public/cpp/view_manager/node.h"
13 #include "mojo/services/public/cpp/view_manager/node_observer.h" 14 #include "mojo/services/public/cpp/view_manager/node_observer.h"
14 #include "mojo/services/public/cpp/view_manager/types.h" 15 #include "mojo/services/public/cpp/view_manager/types.h"
15 #include "mojo/services/public/cpp/view_manager/view.h" 16 #include "mojo/services/public/cpp/view_manager/view.h"
16 #include "mojo/services/public/cpp/view_manager/view_manager.h" 17 #include "mojo/services/public/cpp/view_manager/view_manager.h"
18 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h"
17 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" 19 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
18 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" 20 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
19 #include "skia/ext/platform_canvas.h" 21 #include "skia/ext/platform_canvas.h"
20 #include "skia/ext/refptr.h" 22 #include "skia/ext/refptr.h"
21 #include "third_party/skia/include/core/SkBitmap.h" 23 #include "third_party/skia/include/core/SkBitmap.h"
22 #include "third_party/skia/include/core/SkCanvas.h" 24 #include "third_party/skia/include/core/SkCanvas.h"
23 #include "third_party/skia/include/core/SkPaint.h" 25 #include "third_party/skia/include/core/SkPaint.h"
24 #include "third_party/skia/include/core/SkScalar.h" 26 #include "third_party/skia/include/core/SkScalar.h"
25 #include "ui/gfx/codec/png_codec.h" 27 #include "ui/gfx/codec/png_codec.h"
26 28
27 namespace mojo { 29 namespace mojo {
28 namespace examples { 30 namespace examples {
29 31
30 class PNGViewer; 32 class PNGViewer;
31 33
32 class ZoomableMediaImpl : public InterfaceImpl<ZoomableMedia> { 34 class ZoomableMediaImpl : public InterfaceImpl<ZoomableMedia> {
33 public: 35 public:
34 ZoomableMediaImpl(ApplicationConnection* connection, 36 explicit ZoomableMediaImpl(PNGViewer* viewer) : viewer_(viewer) {}
35 PNGViewer* viewer) : viewer_(viewer) {}
36 virtual ~ZoomableMediaImpl() {} 37 virtual ~ZoomableMediaImpl() {}
37 38
38 private: 39 private:
39 // Overridden from ZoomableMedia: 40 // Overridden from ZoomableMedia:
40 virtual void ZoomIn() OVERRIDE; 41 virtual void ZoomIn() OVERRIDE;
41 virtual void ZoomOut() OVERRIDE; 42 virtual void ZoomOut() OVERRIDE;
42 virtual void ZoomToActualSize() OVERRIDE; 43 virtual void ZoomToActualSize() OVERRIDE;
43 44
44 PNGViewer* viewer_; 45 PNGViewer* viewer_;
45 46
46 DISALLOW_COPY_AND_ASSIGN(ZoomableMediaImpl); 47 DISALLOW_COPY_AND_ASSIGN(ZoomableMediaImpl);
47 }; 48 };
48 49
49 class NavigatorImpl : public InterfaceImpl<navigation::Navigator> { 50 class NavigatorImpl : public InterfaceImpl<navigation::Navigator> {
50 public: 51 public:
51 NavigatorImpl(ApplicationConnection* connection, 52 explicit NavigatorImpl(PNGViewer* viewer) : viewer_(viewer) {}
52 PNGViewer* viewer) : viewer_(viewer) {}
53 virtual ~NavigatorImpl() {} 53 virtual ~NavigatorImpl() {}
54 54
55 private: 55 private:
56 // Overridden from navigation::Navigate: 56 // Overridden from navigation::Navigate:
57 virtual void Navigate( 57 virtual void Navigate(
58 uint32_t node_id, 58 uint32_t node_id,
59 navigation::NavigationDetailsPtr navigation_details, 59 navigation::NavigationDetailsPtr navigation_details,
60 navigation::ResponseDetailsPtr response_details) OVERRIDE { 60 navigation::ResponseDetailsPtr response_details) OVERRIDE {
61 int content_length = GetContentLength(response_details->response->headers); 61 int content_length = GetContentLength(response_details->response->headers);
62 unsigned char* data = new unsigned char[content_length]; 62 unsigned char* data = new unsigned char[content_length];
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 } 104 }
105 } 105 }
106 return 0; 106 return 0;
107 } 107 }
108 108
109 PNGViewer* viewer_; 109 PNGViewer* viewer_;
110 110
111 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); 111 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl);
112 }; 112 };
113 113
114 class PNGViewer : public ApplicationDelegate, 114 class PNGViewer
115 public view_manager::ViewManagerDelegate, 115 : public ApplicationDelegate,
116 public view_manager::NodeObserver { 116 public view_manager::ViewManagerDelegate,
117 public view_manager::NodeObserver,
118 public InterfaceFactoryWithContext<NavigatorImpl, PNGViewer>,
119 public InterfaceFactoryWithContext<ZoomableMediaImpl, PNGViewer> {
117 public: 120 public:
118 PNGViewer() 121 PNGViewer()
119 : content_view_(NULL), 122 : InterfaceFactoryWithContext<NavigatorImpl, PNGViewer>(this),
123 InterfaceFactoryWithContext<ZoomableMediaImpl, PNGViewer>(this),
124 content_view_(NULL),
120 root_(NULL), 125 root_(NULL),
121 zoom_percentage_(kDefaultZoomPercentage) {} 126 zoom_percentage_(kDefaultZoomPercentage),
127 view_manager_client_factory_(this) {}
122 virtual ~PNGViewer() { 128 virtual ~PNGViewer() {
123 if (root_) 129 if (root_)
124 root_->RemoveObserver(this); 130 root_->RemoveObserver(this);
125 } 131 }
126 132
127 void UpdateView(view_manager::Id node_id, const SkBitmap& bitmap) { 133 void UpdateView(view_manager::Id node_id, const SkBitmap& bitmap) {
128 bitmap_ = bitmap; 134 bitmap_ = bitmap;
129 zoom_percentage_ = kDefaultZoomPercentage; 135 zoom_percentage_ = kDefaultZoomPercentage;
130 DrawBitmap(); 136 DrawBitmap();
131 } 137 }
(...skipping 21 matching lines...) Expand all
153 159
154 private: 160 private:
155 static const uint16_t kMaxZoomPercentage = 400; 161 static const uint16_t kMaxZoomPercentage = 400;
156 static const uint16_t kMinZoomPercentage = 20; 162 static const uint16_t kMinZoomPercentage = 20;
157 static const uint16_t kDefaultZoomPercentage = 100; 163 static const uint16_t kDefaultZoomPercentage = 100;
158 static const uint16_t kZoomStep = 20; 164 static const uint16_t kZoomStep = 20;
159 165
160 // Overridden from ApplicationDelegate: 166 // Overridden from ApplicationDelegate:
161 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) 167 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
162 MOJO_OVERRIDE { 168 MOJO_OVERRIDE {
163 connection->AddService<NavigatorImpl>(this); 169 connection->AddService<navigation::Navigator>(this);
164 connection->AddService<ZoomableMediaImpl>(this); 170 connection->AddService<ZoomableMedia>(this);
165 view_manager::ViewManager::ConfigureIncomingConnection(connection, this); 171 connection->AddService(&view_manager_client_factory_);
166 return true; 172 return true;
167 } 173 }
168 174
169 // Overridden from view_manager::ViewManagerDelegate: 175 // Overridden from view_manager::ViewManagerDelegate:
170 virtual void OnRootAdded(view_manager::ViewManager* view_manager, 176 virtual void OnRootAdded(view_manager::ViewManager* view_manager,
171 view_manager::Node* root) OVERRIDE { 177 view_manager::Node* root) OVERRIDE {
172 root_ = root; 178 root_ = root;
173 root_->AddObserver(this); 179 root_->AddObserver(this);
174 content_view_ = view_manager::View::Create(view_manager); 180 content_view_ = view_manager::View::Create(view_manager);
175 root_->SetActiveView(content_view_); 181 root_->SetActiveView(content_view_);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 virtual void OnNodeDestroyed(view_manager::Node* node) OVERRIDE { 215 virtual void OnNodeDestroyed(view_manager::Node* node) OVERRIDE {
210 DCHECK_EQ(node, root_); 216 DCHECK_EQ(node, root_);
211 node->RemoveObserver(this); 217 node->RemoveObserver(this);
212 root_ = NULL; 218 root_ = NULL;
213 } 219 }
214 220
215 view_manager::View* content_view_; 221 view_manager::View* content_view_;
216 view_manager::Node* root_; 222 view_manager::Node* root_;
217 SkBitmap bitmap_; 223 SkBitmap bitmap_;
218 uint16_t zoom_percentage_; 224 uint16_t zoom_percentage_;
225 view_manager::ViewManagerClientFactory view_manager_client_factory_;
219 226
220 DISALLOW_COPY_AND_ASSIGN(PNGViewer); 227 DISALLOW_COPY_AND_ASSIGN(PNGViewer);
221 }; 228 };
222 229
223 void ZoomableMediaImpl::ZoomIn() { 230 void ZoomableMediaImpl::ZoomIn() {
224 viewer_->ZoomIn(); 231 viewer_->ZoomIn();
225 } 232 }
226 233
227 void ZoomableMediaImpl::ZoomOut() { 234 void ZoomableMediaImpl::ZoomOut() {
228 viewer_->ZoomOut(); 235 viewer_->ZoomOut();
229 } 236 }
230 237
231 void ZoomableMediaImpl::ZoomToActualSize() { 238 void ZoomableMediaImpl::ZoomToActualSize() {
232 viewer_->ZoomToActualSize(); 239 viewer_->ZoomToActualSize();
233 } 240 }
234 241
235 void NavigatorImpl::UpdateView(view_manager::Id node_id, 242 void NavigatorImpl::UpdateView(view_manager::Id node_id,
236 const SkBitmap& bitmap) { 243 const SkBitmap& bitmap) {
237 viewer_->UpdateView(node_id, bitmap); 244 viewer_->UpdateView(node_id, bitmap);
238 } 245 }
239 246
240 } // namespace examples 247 } // namespace examples
241 248
242 // static 249 // static
243 ApplicationDelegate* ApplicationDelegate::Create() { 250 ApplicationDelegate* ApplicationDelegate::Create() {
244 return new examples::PNGViewer; 251 return new examples::PNGViewer;
245 } 252 }
246 253
247 } // namespace mojo 254 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/examples/nesting_app/nesting_app.cc ('k') | mojo/examples/surfaces_app/child_app.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698