Skip to content

Commit 22d56a9

Browse files
authored
Various fixes (#42)
- Removes linux embedder code - macOS cleanup + test - Make things compile with flutter web
2 parents 06b22b4 + d491d84 commit 22d56a9

File tree

12 files changed

+175
-571
lines changed

12 files changed

+175
-571
lines changed

engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterWindowController.h

+57
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
// Copyright 2013 The Flutter 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+
15
#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERWINDOWCONTROLLER_H_
26
#define FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERWINDOWCONTROLLER_H_
37

48
#import <Cocoa/Cocoa.h>
59

10+
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
11+
#import "flutter/shell/platform/darwin/macos/framework/Headers/FlutterViewController.h"
12+
613
@class FlutterEngine;
714

815
@interface FlutterWindowController : NSObject
@@ -11,4 +18,54 @@
1118

1219
@end
1320

21+
struct FlutterWindowCreationRequest {
22+
double width;
23+
double height;
24+
double min_width;
25+
double min_height;
26+
double max_width;
27+
double max_height;
28+
void (*on_close)();
29+
void (*on_size_change)();
30+
};
31+
32+
struct FlutterWindowSize {
33+
double width;
34+
double height;
35+
};
36+
37+
extern "C" {
38+
39+
// NOLINTBEGIN(google-objc-function-naming)
40+
41+
FLUTTER_DARWIN_EXPORT
42+
int64_t FlutterCreateRegularWindow(int64_t engine_id, const FlutterWindowCreationRequest* request);
43+
44+
FLUTTER_DARWIN_EXPORT
45+
void FlutterDestroyWindow(int64_t engine_id, void* window);
46+
47+
FLUTTER_DARWIN_EXPORT
48+
void* FlutterGetWindowHandle(int64_t engine_id, FlutterViewIdentifier view_id);
49+
50+
FLUTTER_DARWIN_EXPORT
51+
void* FlutterGetWindowHandle(int64_t engine_id, FlutterViewIdentifier view_id);
52+
53+
FLUTTER_DARWIN_EXPORT
54+
void FlutterGetWindowSize(void* window, FlutterWindowSize* size);
55+
56+
FLUTTER_DARWIN_EXPORT
57+
void FlutterSetWindowSize(void* window, double width, double height);
58+
59+
FLUTTER_DARWIN_EXPORT
60+
void FlutterSetWindowTitle(void* window, const char* title);
61+
62+
FLUTTER_DARWIN_EXPORT
63+
int64_t FlutterGetWindowState(void* window);
64+
65+
FLUTTER_DARWIN_EXPORT
66+
void FlutterSetWindowState(void* window, int64_t state);
67+
68+
// NOLINTEND(google-objc-function-naming)
69+
}
70+
1471
#endif // FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERWINDOWCONTROLLER_H_

engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterWindowController.mm

+12-35
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright 2013 The Flutter 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+
15
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterWindowController.h"
26

37
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"
@@ -7,17 +11,6 @@
711

812
#include "flutter/shell/platform/common/isolate_scope.h"
913

10-
struct FlutterWindowCreationRequest {
11-
double width;
12-
double height;
13-
double min_width;
14-
double min_height;
15-
double max_width;
16-
double max_height;
17-
void (*on_close)();
18-
void (*on_size_change)();
19-
};
20-
2114
/// A delegate for a Flutter managed window.
2215
@interface FlutterWindowOwner : NSObject <NSWindowDelegate> {
2316
/// Strong reference to the window. This is the only strong reference to the
@@ -134,57 +127,43 @@ - (void)destroyWindow:(NSWindow*)window {
134127

135128
@end
136129

137-
extern "C" {
138130
// NOLINTBEGIN(google-objc-function-naming)
139131

140-
FLUTTER_DARWIN_EXPORT
141-
int64_t flutter_create_regular_window(int64_t engine_id,
142-
const FlutterWindowCreationRequest* request) {
132+
int64_t FlutterCreateRegularWindow(int64_t engine_id, const FlutterWindowCreationRequest* request) {
143133
FlutterEngine* engine = [FlutterEngine engineForIdentifier:engine_id];
144134
[engine enableMultiView];
145135
return [engine.windowController createRegularWindow:request];
146136
}
147137

148-
FLUTTER_DARWIN_EXPORT
149-
void flutter_destroy_window(int64_t engine_id, void* window) {
138+
void FlutterDestroyWindow(int64_t engine_id, void* window) {
150139
NSWindow* w = (__bridge NSWindow*)window;
151140
FlutterEngine* engine = [FlutterEngine engineForIdentifier:engine_id];
152141
[engine.windowController destroyWindow:w];
153142
}
154143

155-
FLUTTER_DARWIN_EXPORT
156-
void* flutter_get_window_handle(int64_t engine_id, FlutterViewIdentifier view_id) {
144+
void* FlutterGetWindowHandle(int64_t engine_id, FlutterViewIdentifier view_id) {
157145
FlutterEngine* engine = [FlutterEngine engineForIdentifier:engine_id];
158146
FlutterViewController* controller = [engine viewControllerForIdentifier:view_id];
159147
return (__bridge void*)controller.view.window;
160148
}
161149

162-
struct FlutterWindowSize {
163-
double width;
164-
double height;
165-
};
166-
167-
FLUTTER_DARWIN_EXPORT
168-
void flutter_get_window_size(void* window, FlutterWindowSize* size) {
150+
void FlutterGetWindowSize(void* window, FlutterWindowSize* size) {
169151
NSWindow* w = (__bridge NSWindow*)window;
170152
size->width = w.frame.size.width;
171153
size->height = w.frame.size.height;
172154
}
173155

174-
FLUTTER_DARWIN_EXPORT
175-
void flutter_set_window_size(void* window, double width, double height) {
156+
void FlutterSetWindowSize(void* window, double width, double height) {
176157
NSWindow* w = (__bridge NSWindow*)window;
177158
[w setContentSize:NSMakeSize(width, height)];
178159
}
179160

180-
FLUTTER_DARWIN_EXPORT
181-
void flutter_set_window_title(void* window, const char* title) {
161+
void FlutterSetWindowTitle(void* window, const char* title) {
182162
NSWindow* w = (__bridge NSWindow*)window;
183163
w.title = [NSString stringWithUTF8String:title];
184164
}
185165

186-
FLUTTER_DARWIN_EXPORT
187-
int64_t flutter_get_window_state(void* window) {
166+
int64_t FlutterGetWindowState(void* window) {
188167
NSWindow* w = (__bridge NSWindow*)window;
189168
if (w.isZoomed) {
190169
return 1;
@@ -195,8 +174,7 @@ int64_t flutter_get_window_state(void* window) {
195174
}
196175
}
197176

198-
FLUTTER_DARWIN_EXPORT
199-
void flutter_set_window_state(void* window, int64_t state) {
177+
void FlutterSetWindowState(void* window, int64_t state) {
200178
NSWindow* w = (__bridge NSWindow*)window;
201179
if (state == 1) {
202180
[w zoom:nil];
@@ -217,4 +195,3 @@ void flutter_set_window_state(void* window, int64_t state) {
217195
}
218196

219197
// NOLINTEND(google-objc-function-naming)
220-
} // extern "C"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2013 The Flutter 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 "flutter/shell/platform/common/isolate_scope.h"
6+
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngineTestUtils.h"
7+
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterWindowController.h"
8+
#import "flutter/testing/testing.h"
9+
#import "third_party/googletest/googletest/include/gtest/gtest.h"
10+
11+
namespace flutter::testing {
12+
13+
using FlutterWindowControllerTest = FlutterEngineTest;
14+
15+
TEST_F(FlutterWindowControllerTest, Test1) {
16+
FlutterEngine* engine = GetFlutterEngine();
17+
FlutterWindowController* controller = [[FlutterWindowController alloc] init];
18+
controller.engine = engine;
19+
20+
std::unique_ptr<flutter::Isolate> isolate;
21+
bool signalled = false;
22+
23+
AddNativeCallback("SignalNativeTest", CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
24+
fprintf(stderr, "Signal native test\n");
25+
isolate = std::make_unique<flutter::Isolate>();
26+
signalled = true;
27+
}));
28+
29+
EXPECT_TRUE([engine runWithEntrypoint:@"testWindowController"]);
30+
while (!signalled) {
31+
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, YES);
32+
}
33+
34+
FlutterWindowCreationRequest request{
35+
.width = 800,
36+
.height = 600,
37+
.on_close = [] {},
38+
.on_size_change = [] {},
39+
};
40+
41+
int64_t engine_id = reinterpret_cast<int64_t>(engine);
42+
43+
IsolateScope isolate_scope(*isolate.get());
44+
int64_t handle = FlutterCreateRegularWindow(engine_id, &request);
45+
EXPECT_EQ(handle, 1);
46+
}
47+
} // namespace flutter::testing

engine/src/flutter/shell/platform/darwin/macos/framework/Source/fixtures/flutter_desktop_test.dart

+5
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,8 @@ external void notifyEngineId(int? engineId);
9393
void testEngineId() {
9494
notifyEngineId(PlatformDispatcher.instance.engineId);
9595
}
96+
97+
@pragma('vm:entry-point')
98+
void testWindowController() {
99+
signalNativeTest();
100+
}

engine/src/flutter/shell/platform/linux/BUILD.gn

-2
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ source_set("flutter_linux_sources") {
159159
"fl_view.cc",
160160
"fl_view_accessible.cc",
161161
"fl_window_state_monitor.cc",
162-
"fl_windowing.cc",
163-
"fl_windowing.h",
164162
"fl_windowing_channel.cc",
165163
"fl_windowing_handler.cc",
166164
"key_mapping.g.cc",

0 commit comments

Comments
 (0)