Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Instance Methods | List of all members
MainView Class Reference

#include <Window_ios.h>

Inheritance diagram for MainView:
GLView GraphiteMetalView MetalView RasterView

Instance Methods

(MainView *) - initWithWindow:
 
(MainView *) - initWithWindow:
 
(void) - panGestureAction: [implementation]
 
(void) - tapGestureAction: [implementation]
 
(void) - pinchGestureAction: [implementation]
 
(void) - swipeRightGestureAction: [implementation]
 
(void) - swipeLeftGestureAction: [implementation]
 
(void) - dealloc [implementation]
 
(BOOL- isOpaque [implementation]
 
(BOOL- canBecomeKeyView [implementation]
 
(BOOL- acceptsFirstResponder [implementation]
 
(void) - updateTrackingAreas [implementation]
 
(skui::ModifierKey- updateModifierKeys: [implementation]
 
(BOOL- performKeyEquivalent: [implementation]
 
(void) - keyDown: [implementation]
 
(void) - keyUp: [implementation]
 
(void) - flagsChanged: [implementation]
 
(void) - mouseDown: [implementation]
 
(void) - mouseUp: [implementation]
 
(void) - mouseDragged: [implementation]
 
(void) - mouseMoved: [implementation]
 
(void) - scrollWheel: [implementation]
 
(void) - drawRect: [implementation]
 

Detailed Description

Definition at line 53 of file Window_ios.h.

Method Documentation

◆ acceptsFirstResponder

- (BOOL) acceptsFirstResponder
implementation

Definition at line 286 of file Window_mac.mm.

314 {
315 return YES;
316}

◆ canBecomeKeyView

- (BOOL) canBecomeKeyView
implementation

Definition at line 286 of file Window_mac.mm.

310 {
311 return YES;
312}

◆ dealloc

- (void) dealloc
implementation

Definition at line 286 of file Window_mac.mm.

301{
302 [fTrackingArea release];
303 [super dealloc];
304}

◆ drawRect:

- (void) drawRect: (NSRect)  rect
implementation

Definition at line 286 of file Window_mac.mm.

472 :(NSRect)rect {
473 fWindow->onPaint();
474}

◆ flagsChanged:

- (void) flagsChanged: (NSEvent *)  event
implementation

Definition at line 286 of file Window_mac.mm.

412 :(NSEvent *)event {
413 [self updateModifierKeys:event];
414}
FlKeyEvent * event

◆ initWithWindow: [1/2]

- (MainView *) initWithWindow: (sk_app::Window_ios*)  initWindow

Definition at line 117 of file Window_ios.mm.

229 :(sk_app::Window_ios *)initWindow {
230 self = [super init];
231
232 UIPanGestureRecognizer* panGestureRecognizer = [[UIPanGestureRecognizer alloc] init];
233 panGestureRecognizer.maximumNumberOfTouches = 1;
234 [panGestureRecognizer addTarget:self action:@selector(panGestureAction:)];
235 [self addGestureRecognizer:panGestureRecognizer];
236
237 UITapGestureRecognizer* tapGestureRecognizer = [[UITapGestureRecognizer alloc] init];
238 [tapGestureRecognizer addTarget:self action:@selector(tapGestureAction:)];
239 [self addGestureRecognizer:tapGestureRecognizer];
240
241 UIPinchGestureRecognizer* pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] init];
242 [pinchGestureRecognizer addTarget:self action:@selector(pinchGestureAction:)];
243 [self addGestureRecognizer:pinchGestureRecognizer];
244
245 UISwipeGestureRecognizer* swipeRightGestureRecognizer = [[UISwipeGestureRecognizer alloc] init];
246 swipeRightGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
247 [swipeRightGestureRecognizer addTarget:self action:@selector(swipeRightGestureAction:)];
248 [self addGestureRecognizer:swipeRightGestureRecognizer];
249
250 UISwipeGestureRecognizer* swipeLeftGestureRecognizer = [[UISwipeGestureRecognizer alloc] init];
251 swipeLeftGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
252 [swipeLeftGestureRecognizer addTarget:self action:@selector(swipeLeftGestureAction:)];
253 [self addGestureRecognizer:swipeLeftGestureRecognizer];
254
255 // disable pan recognition until swipes fail
256 [panGestureRecognizer requireGestureRecognizerToFail:swipeLeftGestureRecognizer];
257 [panGestureRecognizer requireGestureRecognizerToFail:swipeRightGestureRecognizer];
258
259 fWindow = initWindow;
260
261 return self;
262}

◆ initWithWindow: [2/2]

- (MainView *) initWithWindow: (sk_app::Window_mac*)  initWindow

Definition at line 286 of file Window_mac.mm.

289 :(sk_app::Window_mac *)initWindow {
290 self = [super init];
291
292 fWindow = initWindow;
293 fTrackingArea = nil;
294
295 [self updateTrackingAreas];
296
297 return self;
298}
NSTrackingArea * fTrackingArea

◆ isOpaque

- (BOOL) isOpaque
implementation

Definition at line 286 of file Window_mac.mm.

306 {
307 return YES;
308}

◆ keyDown:

- (void) keyDown: (NSEvent *)  event
implementation

Definition at line 286 of file Window_mac.mm.

379 :(NSEvent *)event {
380 skui::ModifierKey modifiers = [self updateModifierKeys:event];
381
382 skui::Key key = get_key([event keyCode]);
383 if (key != skui::Key::kNONE) {
384 if (!fWindow->onKey(key, skui::InputState::kDown, modifiers)) {
385 if (skui::Key::kEscape == key) {
386 [NSApp terminate:fWindow->window()];
387 }
388 }
389 }
390
391 NSString* characters = [event charactersIgnoringModifiers];
392 NSUInteger len = [characters length];
393 if (len > 0) {
394 unichar* charBuffer = new unichar[len+1];
395 [characters getCharacters:charBuffer range:NSMakeRange(0, len)];
396 for (NSUInteger i = 0; i < len; ++i) {
397 (void) fWindow->onChar((SkUnichar) charBuffer[i], modifiers);
398 }
399 delete [] charBuffer;
400 }
401}
int32_t SkUnichar
Definition SkTypes.h:175
static skui::Key get_key(unsigned short vk)
ModifierKey
Definition ModifierKey.h:9
Key
Definition Key.h:6

◆ keyUp:

- (void) keyUp: (NSEvent *)  event
implementation

Definition at line 286 of file Window_mac.mm.

403 :(NSEvent *)event {
404 skui::ModifierKey modifiers = [self updateModifierKeys:event];
405
406 skui::Key key = get_key([event keyCode]);
407 if (key != skui::Key::kNONE) {
408 (void) fWindow->onKey(key, skui::InputState::kUp, modifiers);
409 }
410}

◆ mouseDown:

- (void) mouseDown: (NSEvent *)  event
implementation

Definition at line 286 of file Window_mac.mm.

416 :(NSEvent *)event {
417 NSView* view = fWindow->window().contentView;
418 CGFloat backingScaleFactor = skwindow::GetBackingScaleFactor(view);
419
420 skui::ModifierKey modifiers = [self updateModifierKeys:event];
421
422 const NSPoint pos = [event locationInWindow];
423 const NSRect rect = [view frame];
424 fWindow->onMouse(pos.x * backingScaleFactor, (rect.size.height - pos.y) * backingScaleFactor,
425 skui::InputState::kDown, modifiers);
426}
SkPoint pos
sk_sp< SkBlender > blender SkRect rect
Definition SkRecords.h:350
static CGFloat GetBackingScaleFactor(NSView *view)
constexpr float y() const
constexpr float x() const

◆ mouseDragged:

- (void) mouseDragged: (NSEvent *)  event
implementation

Definition at line 286 of file Window_mac.mm.

440 :(NSEvent *)event {
441 [self updateModifierKeys:event];
442 [self mouseMoved:event];
443}

◆ mouseMoved:

- (void) mouseMoved: (NSEvent *)  event
implementation

Definition at line 286 of file Window_mac.mm.

445 :(NSEvent *)event {
446 NSView* view = fWindow->window().contentView;
447 CGFloat backingScaleFactor = skwindow::GetBackingScaleFactor(view);
448
449 skui::ModifierKey modifiers = [self updateModifierKeys:event];
450
451 const NSPoint pos = [event locationInWindow];
452 const NSRect rect = [view frame];
453 fWindow->onMouse(pos.x * backingScaleFactor, (rect.size.height - pos.y) * backingScaleFactor,
454 skui::InputState::kMove, modifiers);
455}

◆ mouseUp:

- (void) mouseUp: (NSEvent *)  event
implementation

Definition at line 286 of file Window_mac.mm.

428 :(NSEvent *)event {
429 NSView* view = fWindow->window().contentView;
430 CGFloat backingScaleFactor = skwindow::GetBackingScaleFactor(view);
431
432 skui::ModifierKey modifiers = [self updateModifierKeys:event];
433
434 const NSPoint pos = [event locationInWindow];
435 const NSRect rect = [view frame];
436 fWindow->onMouse(pos.x * backingScaleFactor, (rect.size.height - pos.y) * backingScaleFactor,
437 skui::InputState::kUp, modifiers);
438}

◆ panGestureAction:

- (void) panGestureAction: (UIGestureRecognizer*)  sender
implementation

Definition at line 117 of file Window_ios.mm.

157 :(UIGestureRecognizer*)sender {
158 CGPoint location = [sender locationInView:self];
159 switch (sender.state) {
160 case UIGestureRecognizerStateBegan:
161 fWindow->onMouse(location.x, location.y,
163 break;
164 case UIGestureRecognizerStateChanged:
165 fWindow->onMouse(location.x, location.y,
167 break;
168 case UIGestureRecognizerStateEnded:
169 fWindow->onMouse(location.x, location.y,
171 break;
172 case UIGestureRecognizerStateCancelled:
173 fWindow->onMouse(location.x, location.y,
175 break;
176 default:
177 break;
178 }
179}

◆ performKeyEquivalent:

- (BOOL) performKeyEquivalent: (NSEvent *)  event
implementation

Definition at line 286 of file Window_mac.mm.

367 :(NSEvent *)event {
368 [self updateModifierKeys:event];
369
370 // By default, unhandled key equivalents send -keyDown events; unfortunately, they do not send
371 // a matching -keyUp. In other words, we can claim that we didn't handle the event and OS X will
372 // turn this event into a -keyDown automatically, but we need to synthesize a matching -keyUp on
373 // a later frame. Since we only read the modifiers and key code from the event, we can reuse
374 // this "key-equivalent" event as a "key up".
375 [self performSelector:@selector(keyUp:) withObject:event afterDelay:0.1];
376 return NO;
377}

◆ pinchGestureAction:

- (void) pinchGestureAction: (UIGestureRecognizer*)  sender
implementation

Definition at line 117 of file Window_ios.mm.

195 :(UIGestureRecognizer*)sender {
196 CGPoint location = [sender locationInView:self];
197 UIPinchGestureRecognizer* pinchGestureRecognizer = (UIPinchGestureRecognizer*) sender;
198 float scale = pinchGestureRecognizer.scale;
199 switch (sender.state) {
200 case UIGestureRecognizerStateBegan:
201 fWindow->onPinch(skui::InputState::kDown, scale, location.x, location.y);
202 break;
203 case UIGestureRecognizerStateChanged:
204 fWindow->onPinch(skui::InputState::kMove, scale, location.x, location.y);
205 break;
206 case UIGestureRecognizerStateEnded:
207 fWindow->onPinch(skui::InputState::kUp, scale, location.x, location.y);
208 break;
209 case UIGestureRecognizerStateCancelled:
210 fWindow->onPinch(skui::InputState::kUp, scale, location.x, location.y);
211 break;
212 default:
213 break;
214 }
215}
const Scalar scale

◆ scrollWheel:

- (void) scrollWheel: (NSEvent *)  event
implementation

Definition at line 286 of file Window_mac.mm.

457 :(NSEvent *)event {
458 NSView* view = fWindow->window().contentView;
459 CGFloat backingScaleFactor = skwindow::GetBackingScaleFactor(view);
460
461 skui::ModifierKey modifiers = [self updateModifierKeys:event];
462
463 // TODO: support hasPreciseScrollingDeltas?
464 const NSPoint pos = [event locationInWindow];
465 const NSRect rect = [view frame];
466 fWindow->onMouseWheel([event scrollingDeltaY],
467 pos.x * backingScaleFactor,
468 (rect.size.height - pos.y) * backingScaleFactor,
469 modifiers);
470}

◆ swipeLeftGestureAction:

- (void) swipeLeftGestureAction: (UIGestureRecognizer*)  sender
implementation

Definition at line 117 of file Window_ios.mm.

223 :(UIGestureRecognizer*)sender {
224 if (UIGestureRecognizerStateEnded == sender.state) {
225 fWindow->onFling(skui::InputState::kLeft);
226 }
227}

◆ swipeRightGestureAction:

- (void) swipeRightGestureAction: (UIGestureRecognizer*)  sender
implementation

Definition at line 117 of file Window_ios.mm.

217 :(UIGestureRecognizer*)sender {
218 if (UIGestureRecognizerStateEnded == sender.state) {
219 fWindow->onFling(skui::InputState::kRight);
220 }
221}

◆ tapGestureAction:

- (void) tapGestureAction: (UIGestureRecognizer*)  sender
implementation

Definition at line 117 of file Window_ios.mm.

181 :(UIGestureRecognizer*)sender {
182 CGPoint location = [sender locationInView:self];
183 switch (sender.state) {
184 case UIGestureRecognizerStateEnded:
185 fWindow->onMouse(location.x, location.y,
187 fWindow->onMouse(location.x, location.y,
189 break;
190 default:
191 break;
192 }
193}

◆ updateModifierKeys:

- (ModifierKey) MainView: (NSEvent*)  event
implementation

Definition at line 286 of file Window_mac.mm.

340 :(NSEvent*) event {
341 using sknonstd::Any;
342
344 skui::ModifierKey changed = modifiers ^ fLastModifiers;
345 fLastModifiers = modifiers;
346
347 struct ModMap {
348 skui::ModifierKey modifier;
350 };
351
352 // Map each modifier bit to the equivalent skui Key and send key-up/down events.
353 for (const ModMap& cur : {ModMap{skui::ModifierKey::kCommand, skui::Key::kSuper},
354 ModMap{skui::ModifierKey::kShift, skui::Key::kShift},
355 ModMap{skui::ModifierKey::kControl, skui::Key::kCtrl},
356 ModMap{skui::ModifierKey::kOption, skui::Key::kOption}}) {
357 if (Any(changed & cur.modifier)) {
358 const skui::InputState state = Any(modifiers & cur.modifier) ? skui::InputState::kDown
360 (void) fWindow->onKey(cur.key, state, modifiers);
361 }
362 }
363
364 return modifiers;
365}
static skui::ModifierKey get_modifiers(const NSEvent *event)
skui::ModifierKey fLastModifiers
AtkStateType state
std::enable_if_t< sknonstd::is_bitmask_enum< E >::value, bool > constexpr Any(E e)
InputState
Definition InputState.h:6

◆ updateTrackingAreas

- (void) updateTrackingAreas
implementation

Definition at line 286 of file Window_mac.mm.

318 {
319 if (fTrackingArea != nil) {
320 [self removeTrackingArea:fTrackingArea];
321 [fTrackingArea release];
322 }
323
324 const NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited |
325 NSTrackingActiveInKeyWindow |
326 NSTrackingEnabledDuringMouseDrag |
327 NSTrackingCursorUpdate |
328 NSTrackingInVisibleRect |
329 NSTrackingAssumeInside;
330
331 fTrackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds]
332 options:options
333 owner:self
334 userInfo:nil];
335
336 [self addTrackingArea:fTrackingArea];
337 [super updateTrackingAreas];
338}
const char * options

The documentation for this class was generated from the following files: