Flutter Engine
The Flutter Engine
Instance Methods | List of all members
MainView Class Reference

#import <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 291 of file Window_mac.mm.

319 {
320 return YES;
321}

◆ canBecomeKeyView

- (BOOL) canBecomeKeyView
implementation

Definition at line 291 of file Window_mac.mm.

315 {
316 return YES;
317}

◆ dealloc

- (void) dealloc
implementation

Definition at line 291 of file Window_mac.mm.

306{
307 [fTrackingArea release];
308 [super dealloc];
309}

◆ drawRect:

- (void) drawRect: (NSRect)  rect
implementation

Definition at line 291 of file Window_mac.mm.

477 :(NSRect)rect {
478 fWindow->onPaint();
479}
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350

◆ flagsChanged:

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

Definition at line 291 of file Window_mac.mm.

417 :(NSEvent *)event {
418 [self updateModifierKeys:event];
419}
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 291 of file Window_mac.mm.

294 :(sk_app::Window_mac *)initWindow {
295 self = [super init];
296
297 fWindow = initWindow;
298 fTrackingArea = nil;
299
300 [self updateTrackingAreas];
301
302 return self;
303}
NSTrackingArea * fTrackingArea
Definition: Window_mac.mm:288

◆ isOpaque

- (BOOL) isOpaque
implementation

Definition at line 291 of file Window_mac.mm.

311 {
312 return YES;
313}

◆ keyDown:

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

Definition at line 291 of file Window_mac.mm.

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

◆ keyUp:

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

Definition at line 291 of file Window_mac.mm.

408 :(NSEvent *)event {
409 skui::ModifierKey modifiers = [self updateModifierKeys:event];
410
411 skui::Key key = get_key([event keyCode]);
412 if (key != skui::Key::kNONE) {
413 (void) fWindow->onKey(key, skui::InputState::kUp, modifiers);
414 }
415}

◆ mouseDown:

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

Definition at line 291 of file Window_mac.mm.

421 :(NSEvent *)event {
422 NSView* view = fWindow->window().contentView;
423 CGFloat backingScaleFactor = skwindow::GetBackingScaleFactor(view);
424
425 skui::ModifierKey modifiers = [self updateModifierKeys:event];
426
427 const NSPoint pos = [event locationInWindow];
428 const NSRect rect = [view frame];
429 fWindow->onMouse(pos.x * backingScaleFactor, (rect.size.height - pos.y) * backingScaleFactor,
430 skui::InputState::kDown, modifiers);
431}
SkPoint pos
static CGFloat GetBackingScaleFactor(NSView *view)
constexpr float y() const
Definition: SkPoint_impl.h:187
constexpr float x() const
Definition: SkPoint_impl.h:181

◆ mouseDragged:

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

Definition at line 291 of file Window_mac.mm.

445 :(NSEvent *)event {
446 [self updateModifierKeys:event];
447 [self mouseMoved:event];
448}

◆ mouseMoved:

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

Definition at line 291 of file Window_mac.mm.

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

◆ mouseUp:

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

Definition at line 291 of file Window_mac.mm.

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

◆ 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 291 of file Window_mac.mm.

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

◆ 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 291 of file Window_mac.mm.

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

◆ 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 291 of file Window_mac.mm.

345 :(NSEvent*) event {
346 using sknonstd::Any;
347
349 skui::ModifierKey changed = modifiers ^ fLastModifiers;
350 fLastModifiers = modifiers;
351
352 struct ModMap {
353 skui::ModifierKey modifier;
355 };
356
357 // Map each modifier bit to the equivalent skui Key and send key-up/down events.
358 for (const ModMap& cur : {ModMap{skui::ModifierKey::kCommand, skui::Key::kSuper},
362 if (Any(changed & cur.modifier)) {
363 const skui::InputState state = Any(modifiers & cur.modifier) ? skui::InputState::kDown
365 (void) fWindow->onKey(cur.key, state, modifiers);
366 }
367 }
368
369 return modifiers;
370}
static skui::ModifierKey get_modifiers(const NSEvent *event)
Definition: Window_mac.mm:261
skui::ModifierKey fLastModifiers
Definition: Window_mac.mm:291
AtkStateType state
std::enable_if_t< sknonstd::is_bitmask_enum< E >::value, bool > constexpr Any(E e)
Definition: SkBitmaskEnum.h:16
InputState
Definition: InputState.h:6

◆ updateTrackingAreas

- (void) updateTrackingAreas
implementation

Definition at line 291 of file Window_mac.mm.

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

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