8#include <Carbon/Carbon.h>
36 Window_mac*
window =
new Window_mac();
37 if (!
window->initWindow()) {
53 if (nil == delegate) {
58 constexpr int initialWidth = 1280;
59 constexpr int initialHeight = 960;
60 NSRect windowRect = NSMakeRect(100, 100, initialWidth, initialHeight);
62 NSUInteger windowStyle = (NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask |
63 NSMiniaturizableWindowMask);
65 fWindow = [[NSWindow alloc] initWithContentRect:windowRect styleMask:windowStyle
66 backing:NSBackingStoreBuffered defer:NO];
80 [fWindow setContentView:view];
81 [fWindow makeFirstResponder:view];
82 [fWindow setDelegate:delegate];
83 [fWindow setAcceptsMouseMovedEvents:YES];
84 [fWindow setRestorable:NO];
89 fWindowNumber = fWindow.windowNumber;
97 gWindowMap.remove(fWindowNumber);
98 if (sk_app::Window_mac::gWindowMap.
count() < 1) {
99 [NSApp terminate:fWindow];
107 if (NSString* titleStr = [NSString stringWithUTF8String:title]) {
108 [fWindow setTitle:titleStr];
113 [fWindow orderFront:nil];
115 [NSApp activateIgnoringOtherApps:YES];
116 [fWindow makeKeyAndOrderFront:NSApp];
123 info.fMainView = [fWindow contentView];
124 switch (attachType) {
126 case kANGLE_BackendType:
131#if defined(SK_GRAPHITE)
132 case kGraphiteDawn_BackendType:
138 case kVulkan_BackendType:
141#if defined(SK_GRAPHITE)
142 case kGraphiteVulkan_BackendType:
148 case kMetal_BackendType:
151#if defined(SK_GRAPHITE)
152 case kGraphiteMetal_BackendType:
158 case kNativeGL_BackendType:
179 if (
window->fIsContentInvalidated) {
194 fWindow = initWindow;
199- (void)windowDidResize:(NSNotification *)notification {
200 NSView* view = fWindow->window().contentView;
202 fWindow->onResize(view.bounds.size.width *
scale, view.bounds.size.height *
scale);
206- (
BOOL)windowShouldClose:(NSWindow*)sender {
207 fWindow->closeWindow();
219 static const struct {
253 if (gPair[
i].fVK ==
vk) {
254 return gPair[i].fKey;
262 NSUInteger modifierFlags = [event modifierFlags];
265 if (modifierFlags & NSEventModifierFlagCommand) {
268 if (modifierFlags & NSEventModifierFlagShift) {
271 if (modifierFlags & NSEventModifierFlagControl) {
274 if (modifierFlags & NSEventModifierFlagOption) {
297 fWindow = initWindow;
300 [
self updateTrackingAreas];
307 [fTrackingArea release];
315- (
BOOL)canBecomeKeyView {
319- (
BOOL)acceptsFirstResponder {
323- (void)updateTrackingAreas {
325 [
self removeTrackingArea:fTrackingArea];
326 [fTrackingArea release];
329 const NSTrackingAreaOptions
options = NSTrackingMouseEnteredAndExited |
330 NSTrackingActiveInKeyWindow |
331 NSTrackingEnabledDuringMouseDrag |
332 NSTrackingCursorUpdate |
333 NSTrackingInVisibleRect |
334 NSTrackingAssumeInside;
336 fTrackingArea = [[NSTrackingArea alloc] initWithRect:[
self bounds]
341 [
self addTrackingArea:fTrackingArea];
342 [
super updateTrackingAreas];
345- (
skui::ModifierKey) updateModifierKeys:(NSEvent*) event {
362 if (
Any(changed & cur.modifier)) {
365 (void) fWindow->onKey(cur.key,
state, modifiers);
372- (
BOOL)performKeyEquivalent:(NSEvent *)event {
373 [
self updateModifierKeys:event];
380 [
self performSelector:@selector(keyUp:) withObject:event afterDelay:0.1];
384- (void)keyDown:(NSEvent *)event {
391 [NSApp terminate:fWindow->window()];
396 NSString* characters = [event charactersIgnoringModifiers];
397 NSUInteger
len = [characters length];
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);
404 delete [] charBuffer;
408- (void)keyUp:(NSEvent *)event {
417-(void)flagsChanged:(NSEvent *)event {
418 [
self updateModifierKeys:event];
421- (void)mouseDown:(NSEvent *)event {
422 NSView* view = fWindow->window().contentView;
427 const NSPoint
pos = [event locationInWindow];
428 const NSRect
rect = [view frame];
429 fWindow->onMouse(
pos.
x * backingScaleFactor, (
rect.size.height -
pos.
y) * backingScaleFactor,
433- (void)mouseUp:(NSEvent *)event {
434 NSView* view = fWindow->window().contentView;
439 const NSPoint
pos = [event locationInWindow];
440 const NSRect
rect = [view frame];
441 fWindow->onMouse(
pos.
x * backingScaleFactor, (
rect.size.height -
pos.
y) * backingScaleFactor,
445- (void)mouseDragged:(NSEvent *)event {
446 [
self updateModifierKeys:event];
447 [
self mouseMoved:event];
450- (void)mouseMoved:(NSEvent *)event {
451 NSView* view = fWindow->window().contentView;
456 const NSPoint
pos = [event locationInWindow];
457 const NSRect
rect = [view frame];
458 fWindow->onMouse(
pos.
x * backingScaleFactor, (
rect.size.height -
pos.
y) * backingScaleFactor,
462- (void)scrollWheel:(NSEvent *)event {
463 NSView* view = fWindow->window().contentView;
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,
477- (void)drawRect:(NSRect)rect {
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
#define SkASSERT_RELEASE(cond)
static constexpr bool SkToBool(const T &x)
static skui::ModifierKey get_modifiers(const NSEvent *event)
static skui::Key get_key(unsigned short vk)
NSTrackingArea * fTrackingArea
skui::ModifierKey fLastModifiers
void setTitle(const char *) override
float scaleFactor() const override
static void PaintWindows()
bool attach(BackendType) override
static Window * CreateNativeWindow(void *platformData)
DisplayParams fRequestedDisplayParams
std::unique_ptr< skwindow::WindowContext > fWindowContext
sk_sp< SkBlender > blender SkRect rect
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
std::enable_if_t< sknonstd::is_bitmask_enum< E >::value, bool > constexpr Any(E e)
@ kHome
the home key - added to match android
std::unique_ptr< WindowContext > MakeGraphiteDawnMetalForMac(const MacWindowInfo &info, const DisplayParams ¶ms)
std::unique_ptr< WindowContext > MakeGLForMac(const MacWindowInfo &info, const DisplayParams ¶ms)
std::unique_ptr< WindowContext > MakeRasterForMac(const MacWindowInfo &info, const DisplayParams ¶ms)
std::unique_ptr< WindowContext > MakeMetalForMac(const MacWindowInfo &info, const DisplayParams ¶ms)
std::unique_ptr< WindowContext > MakeANGLEForMac(const MacWindowInfo &info, const DisplayParams ¶ms)
static CGFloat GetBackingScaleFactor(NSView *view)
std::unique_ptr< WindowContext > MakeGraphiteMetalForMac(const MacWindowInfo &info, const DisplayParams ¶ms)
constexpr float y() const
constexpr float x() const