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

Side by Side Diff: sky/shell/ios/sky_surface.mm

Issue 1171573002: Basic Sky shell for iOS targets (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Service provider platform task runner refactor to be platform agnostic Created 5 years, 6 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
« no previous file with comments | « sky/shell/ios/sky_surface.h ('k') | sky/shell/ios/sky_view_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #import "sky_surface.h"
6
7 #import <QuartzCore/QuartzCore.h>
8 #import <OpenGLES/EAGL.h>
9 #import <OpenGLES/EAGLDrawable.h>
10
11 #include "sky/shell/ui_delegate.h"
12 #include "sky/shell/shell.h"
13 #include "sky/shell/ios/platform_view_ios.h"
14
15 #include "mojo/public/cpp/bindings/interface_request.h"
16 #include "sky/services/viewport/input_event.mojom.h"
17 #include "base/time/time.h"
18
19 static inline sky::EventType EventTypeFromUITouchPhase(UITouchPhase phase) {
20 switch (phase) {
21 case UITouchPhaseBegan:
22 return sky::EVENT_TYPE_POINTER_DOWN;
23 case UITouchPhaseMoved:
24 case UITouchPhaseStationary:
25 // There is no EVENT_TYPE_POINTER_STATIONARY. So we just pass a move type
26 // with the same coordinates
27 return sky::EVENT_TYPE_POINTER_MOVE;
28 case UITouchPhaseEnded:
29 return sky::EVENT_TYPE_POINTER_UP;
30 case UITouchPhaseCancelled:
31 return sky::EVENT_TYPE_POINTER_CANCEL;
32 }
33
34 return sky::EVENT_TYPE_UNKNOWN;
35 }
36
37 @implementation SkySurface {
38 BOOL _platformViewInitialized;
39
40 sky::ViewportObserverPtr _viewport_observer;
41 }
42
43 - (gfx::AcceleratedWidget)acceleratedWidget {
44 return (gfx::AcceleratedWidget)self.layer;
45 }
46
47 - (void)layoutSubviews {
48 [super layoutSubviews];
49
50 [self configureLayerDefaults];
51
52 [self setupPlatformViewIfNecessary];
53
54 CGSize size = self.bounds.size;
55 CGFloat scale = [UIScreen mainScreen].scale;
56
57 _viewport_observer->OnViewportMetricsChanged(size.width * scale,
58 size.height * scale, scale);
59 }
60
61 - (void)configureLayerDefaults {
62 CAEAGLLayer* layer = reinterpret_cast<CAEAGLLayer*>(self.layer);
63 layer.allowsGroupOpacity = YES;
64 layer.opaque = YES;
65 CGFloat screenScale = [UIScreen mainScreen].scale;
66 layer.contentsScale = screenScale;
67 // Note: shouldRasterize is still NO. This is just a defensive measure
68 layer.rasterizationScale = screenScale;
69 }
70
71 - (void)setupPlatformViewIfNecessary {
72 if (_platformViewInitialized) {
73 return;
74 }
75
76 _platformViewInitialized = YES;
77
78 [self notifySurfaceCreation];
79 [self connectToViewportObserverAndLoad];
80 }
81
82 - (sky::shell::PlatformViewIOS*)platformView {
83 auto view = static_cast<sky::shell::PlatformViewIOS*>(
84 sky::shell::Shell::Shared().view());
85 DCHECK(view);
86 return view;
87 }
88
89 - (void)notifySurfaceCreation {
90 self.platformView->SurfaceCreated(self.acceleratedWidget);
91 }
92
93 - (NSString*)skyInitialLoadURL {
94 return [NSBundle mainBundle].infoDictionary[@"com.google.sky.load_url"];
95 }
96
97 - (void)connectToViewportObserverAndLoad {
98 auto view = sky::shell::Shell::Shared().view();
99 auto interface_request = mojo::GetProxy(&_viewport_observer);
100 view->ConnectToViewportObserver(interface_request.Pass());
101
102 mojo::String string(self.skyInitialLoadURL.UTF8String);
103 _viewport_observer->LoadURL(string);
104 }
105
106 - (void)notifySurfaceDestruction {
107 self.platformView->SurfaceDestroyed();
108 }
109
110 #pragma mark - UIResponder overrides for raw touches
111
112 - (void)dispatchTouches:(NSSet*)touches phase:(UITouchPhase)phase {
113 auto eventType = EventTypeFromUITouchPhase(phase);
114 const CGFloat scale = [UIScreen mainScreen].scale;
115
116 for (UITouch* touch in touches) {
117 auto input = sky::InputEvent::New();
118 input->type = eventType;
119
120 auto timedelta = base::TimeDelta::FromSecondsD(touch.timestamp);
121 input->time_stamp = timedelta.InMilliseconds();
122
123 input->pointer_data = sky::PointerData::New();
124 input->pointer_data->kind = sky::POINTER_KIND_TOUCH;
125
126 CGPoint windowCoordinates = [touch locationInView:nil];
127
128 input->pointer_data->x = windowCoordinates.x * scale;
129 input->pointer_data->y = windowCoordinates.y * scale;
130
131 _viewport_observer->OnInputEvent(input.Pass());
132 }
133 }
134
135 - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
136 [self dispatchTouches:touches phase:UITouchPhaseBegan];
137 }
138
139 - (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
140 [self dispatchTouches:touches phase:UITouchPhaseMoved];
141 }
142
143 - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
144 [self dispatchTouches:touches phase:UITouchPhaseEnded];
145 }
146
147 - (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event {
148 [self dispatchTouches:touches phase:UITouchPhaseCancelled];
149 }
150
151 #pragma mark - Misc.
152
153 + (Class)layerClass {
154 return [CAEAGLLayer class];
155 }
156
157 - (void)dealloc {
158 [self notifySurfaceDestruction];
159 [super dealloc];
160 }
161
162 @end
OLDNEW
« no previous file with comments | « sky/shell/ios/sky_surface.h ('k') | sky/shell/ios/sky_view_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698