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 <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/context_interface_provider.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/types.h" | 14 #include "mojo/services/public/cpp/view_manager/types.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" |
16 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 17 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
17 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" | 18 #include "mojo/services/public/interfaces/navigation/navigation.mojom.h" |
18 #include "skia/ext/platform_canvas.h" | 19 #include "skia/ext/platform_canvas.h" |
19 #include "skia/ext/refptr.h" | 20 #include "skia/ext/refptr.h" |
20 #include "third_party/skia/include/core/SkBitmap.h" | 21 #include "third_party/skia/include/core/SkBitmap.h" |
21 #include "third_party/skia/include/core/SkCanvas.h" | 22 #include "third_party/skia/include/core/SkCanvas.h" |
22 #include "third_party/skia/include/core/SkPaint.h" | 23 #include "third_party/skia/include/core/SkPaint.h" |
23 #include "third_party/skia/include/core/SkScalar.h" | 24 #include "third_party/skia/include/core/SkScalar.h" |
24 #include "ui/gfx/codec/png_codec.h" | 25 #include "ui/gfx/codec/png_codec.h" |
25 | 26 |
26 namespace mojo { | 27 namespace mojo { |
27 namespace examples { | 28 namespace examples { |
28 | 29 |
29 class PNGViewer; | 30 class PNGViewer; |
30 | 31 |
31 class ZoomableMediaImpl : public InterfaceImpl<ZoomableMedia> { | 32 class ZoomableMediaImpl : public InterfaceImpl<ZoomableMedia> { |
32 public: | 33 public: |
33 ZoomableMediaImpl(ApplicationConnection* connection, | 34 explicit ZoomableMediaImpl(PNGViewer* viewer) : viewer_(viewer) {} |
34 PNGViewer* viewer) : viewer_(viewer) {} | |
35 virtual ~ZoomableMediaImpl() {} | 35 virtual ~ZoomableMediaImpl() {} |
36 | 36 |
37 private: | 37 private: |
38 // Overridden from ZoomableMedia: | 38 // Overridden from ZoomableMedia: |
39 virtual void ZoomIn() OVERRIDE; | 39 virtual void ZoomIn() OVERRIDE; |
40 virtual void ZoomOut() OVERRIDE; | 40 virtual void ZoomOut() OVERRIDE; |
41 virtual void ZoomToActualSize() OVERRIDE; | 41 virtual void ZoomToActualSize() OVERRIDE; |
42 | 42 |
43 PNGViewer* viewer_; | 43 PNGViewer* viewer_; |
44 | 44 |
45 DISALLOW_COPY_AND_ASSIGN(ZoomableMediaImpl); | 45 DISALLOW_COPY_AND_ASSIGN(ZoomableMediaImpl); |
46 }; | 46 }; |
47 | 47 |
48 class NavigatorImpl : public InterfaceImpl<navigation::Navigator> { | 48 class NavigatorImpl : public InterfaceImpl<navigation::Navigator> { |
49 public: | 49 public: |
50 NavigatorImpl(ApplicationConnection* connection, | 50 explicit NavigatorImpl(PNGViewer* viewer) : viewer_(viewer) {} |
51 PNGViewer* viewer) : viewer_(viewer) {} | |
52 virtual ~NavigatorImpl() {} | 51 virtual ~NavigatorImpl() {} |
53 | 52 |
54 private: | 53 private: |
55 // Overridden from navigation::Navigate: | 54 // Overridden from navigation::Navigate: |
56 virtual void Navigate( | 55 virtual void Navigate( |
57 uint32_t node_id, | 56 uint32_t node_id, |
58 navigation::NavigationDetailsPtr navigation_details, | 57 navigation::NavigationDetailsPtr navigation_details, |
59 navigation::ResponseDetailsPtr response_details) OVERRIDE { | 58 navigation::ResponseDetailsPtr response_details) OVERRIDE { |
60 int content_length = GetContentLength(response_details->response->headers); | 59 int content_length = GetContentLength(response_details->response->headers); |
61 unsigned char* data = new unsigned char[content_length]; | 60 unsigned char* data = new unsigned char[content_length]; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 } | 102 } |
104 } | 103 } |
105 return 0; | 104 return 0; |
106 } | 105 } |
107 | 106 |
108 PNGViewer* viewer_; | 107 PNGViewer* viewer_; |
109 | 108 |
110 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); | 109 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); |
111 }; | 110 }; |
112 | 111 |
113 class PNGViewer : public ApplicationDelegate, | 112 class PNGViewer |
114 public view_manager::ViewManagerDelegate { | 113 : public ApplicationDelegate, |
| 114 public view_manager::ViewManagerDelegate, |
| 115 public ContextInterfaceProvider<NavigatorImpl, PNGViewer>, |
| 116 public ContextInterfaceProvider<ZoomableMediaImpl, PNGViewer> { |
115 public: | 117 public: |
116 PNGViewer() : content_view_(NULL), zoom_percentage_(kDefaultZoomPercentage) {} | 118 PNGViewer() |
| 119 : ContextInterfaceProvider<NavigatorImpl, PNGViewer>(this), |
| 120 ContextInterfaceProvider<ZoomableMediaImpl, PNGViewer>(this), |
| 121 content_view_(NULL), |
| 122 zoom_percentage_(kDefaultZoomPercentage) {} |
117 virtual ~PNGViewer() {} | 123 virtual ~PNGViewer() {} |
118 | 124 |
119 void UpdateView(view_manager::Id node_id, const SkBitmap& bitmap) { | 125 void UpdateView(view_manager::Id node_id, const SkBitmap& bitmap) { |
120 bitmap_ = bitmap; | 126 bitmap_ = bitmap; |
121 zoom_percentage_ = kDefaultZoomPercentage; | 127 zoom_percentage_ = kDefaultZoomPercentage; |
122 DrawBitmap(); | 128 DrawBitmap(); |
123 } | 129 } |
124 | 130 |
125 void ZoomIn() { | 131 void ZoomIn() { |
126 if (zoom_percentage_ >= kMaxZoomPercentage) | 132 if (zoom_percentage_ >= kMaxZoomPercentage) |
(...skipping 18 matching lines...) Expand all Loading... |
145 | 151 |
146 private: | 152 private: |
147 static const uint16_t kMaxZoomPercentage = 400; | 153 static const uint16_t kMaxZoomPercentage = 400; |
148 static const uint16_t kMinZoomPercentage = 20; | 154 static const uint16_t kMinZoomPercentage = 20; |
149 static const uint16_t kDefaultZoomPercentage = 100; | 155 static const uint16_t kDefaultZoomPercentage = 100; |
150 static const uint16_t kZoomStep = 20; | 156 static const uint16_t kZoomStep = 20; |
151 | 157 |
152 // Overridden from ApplicationDelegate: | 158 // Overridden from ApplicationDelegate: |
153 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 159 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
154 MOJO_OVERRIDE { | 160 MOJO_OVERRIDE { |
155 connection->AddService<NavigatorImpl>(this); | 161 connection->AddServiceProvider<navigation::Navigator>(this); |
156 connection->AddService<ZoomableMediaImpl>(this); | 162 connection->AddServiceProvider<ZoomableMedia>(this); |
157 view_manager::ViewManager::ConfigureIncomingConnection(connection, this); | 163 view_manager::ViewManager::ConfigureIncomingConnection(connection, this); |
158 return true; | 164 return true; |
159 } | 165 } |
160 | 166 |
161 // Overridden from view_manager::ViewManagerDelegate: | 167 // Overridden from view_manager::ViewManagerDelegate: |
162 virtual void OnRootAdded(view_manager::ViewManager* view_manager, | 168 virtual void OnRootAdded(view_manager::ViewManager* view_manager, |
163 view_manager::Node* root) OVERRIDE { | 169 view_manager::Node* root) OVERRIDE { |
164 content_view_ = view_manager::View::Create(view_manager); | 170 content_view_ = view_manager::View::Create(view_manager); |
165 root->SetActiveView(content_view_); | 171 root->SetActiveView(content_view_); |
166 content_view_->SetColor(SK_ColorGRAY); | 172 content_view_->SetColor(SK_ColorGRAY); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 } | 220 } |
215 | 221 |
216 } // namespace examples | 222 } // namespace examples |
217 | 223 |
218 // static | 224 // static |
219 ApplicationDelegate* ApplicationDelegate::Create() { | 225 ApplicationDelegate* ApplicationDelegate::Create() { |
220 return new examples::PNGViewer; | 226 return new examples::PNGViewer; |
221 } | 227 } |
222 | 228 |
223 } // namespace mojo | 229 } // namespace mojo |
OLD | NEW |