Flutter Engine
stub_flutter_windows_api.cc
Go to the documentation of this file.
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 #include "flutter/shell/platform/windows/client_wrapper/testing/stub_flutter_windows_api.h"
6 
8 
9 namespace flutter {
10 namespace testing {
11 
12 // static
14  s_stub_implementation = stub;
15 }
16 
17 // static
19  return s_stub_implementation;
20 }
21 
23  std::unique_ptr<StubFlutterWindowsApi> stub)
24  : stub_(std::move(stub)) {
25  previous_stub_ = StubFlutterWindowsApi::GetTestStub();
27 }
28 
30  StubFlutterWindowsApi::SetTestStub(previous_stub_);
31 }
32 
33 } // namespace testing
34 } // namespace flutter
35 
36 // Forwarding dummy implementations of the C API.
37 
39  int width,
40  int height,
42  if (s_stub_implementation) {
43  return s_stub_implementation->ViewControllerCreate(width, height, engine);
44  }
45  return nullptr;
46 }
47 
50  if (s_stub_implementation) {
51  s_stub_implementation->ViewControllerDestroy();
52  }
53 }
54 
57  // The stub ignores this, so just return an arbitrary non-zero value.
58  return reinterpret_cast<FlutterDesktopEngineRef>(1);
59 }
60 
63  // The stub ignores this, so just return an arbitrary non-zero value.
64  return reinterpret_cast<FlutterDesktopViewRef>(1);
65 }
66 
69  HWND hwnd,
70  UINT message,
71  WPARAM wparam,
72  LPARAM lparam,
73  LRESULT* result) {
74  if (s_stub_implementation) {
75  return s_stub_implementation->ViewControllerHandleTopLevelWindowProc(
76  hwnd, message, wparam, lparam, result);
77  }
78  return false;
79 }
80 
82  const FlutterDesktopEngineProperties& engine_properties) {
83  if (s_stub_implementation) {
84  return s_stub_implementation->EngineCreate(engine_properties);
85  }
86  return nullptr;
87 }
88 
90  if (s_stub_implementation) {
91  return s_stub_implementation->EngineDestroy();
92  }
93  return true;
94 }
95 
97  const char* entry_point) {
98  if (s_stub_implementation) {
99  return s_stub_implementation->EngineRun(entry_point);
100  }
101  return true;
102 }
103 
105  if (s_stub_implementation) {
106  return s_stub_implementation->EngineProcessMessages();
107  }
108  return 0;
109 }
110 
112  if (s_stub_implementation) {
113  s_stub_implementation->EngineReloadSystemFonts();
114  }
115 }
116 
119  const char* plugin_name) {
120  // The stub ignores this, so just return an arbitrary non-zero value.
121  return reinterpret_cast<FlutterDesktopPluginRegistrarRef>(1);
122 }
123 
126  // The stub ignores this, so just return an arbitrary non-zero value.
127  return reinterpret_cast<FlutterDesktopMessengerRef>(2);
128 }
129 
131  if (s_stub_implementation) {
132  return s_stub_implementation->ViewGetHWND();
133  }
134  return reinterpret_cast<HWND>(-1);
135 }
136 
139  // The stub ignores this, so just return an arbitrary non-zero value.
140  return reinterpret_cast<FlutterDesktopViewRef>(1);
141 }
142 
146  void* user_data) {
147  if (s_stub_implementation) {
148  return s_stub_implementation
150  user_data);
151  }
152 }
153 
157  if (s_stub_implementation) {
158  return s_stub_implementation
160  }
161 }
virtual bool ViewControllerHandleTopLevelWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, LRESULT *result)
ScopedStubFlutterWindowsApi(std::unique_ptr< StubFlutterWindowsApi > stub)
HWND FlutterDesktopViewGetHWND(FlutterDesktopViewRef controller)
FlutterDesktopEngineRef FlutterDesktopViewControllerGetEngine(FlutterDesktopViewControllerRef controller)
void FlutterDesktopEngineReloadSystemFonts(FlutterDesktopEngineRef engine)
void FlutterDesktopPluginRegistrarRegisterTopLevelWindowProcDelegate(FlutterDesktopPluginRegistrarRef registrar, FlutterDesktopWindowProcCallback delegate, void *user_data)
bool FlutterDesktopEngineDestroy(FlutterDesktopEngineRef engine_ref)
FlutterDesktopViewControllerRef FlutterDesktopViewControllerCreate(int width, int height, FlutterDesktopEngineRef engine)
Definition: ref_ptr.h:252
void FlutterDesktopViewControllerDestroy(FlutterDesktopViewControllerRef controller)
struct FlutterDesktopView * FlutterDesktopViewRef
G_BEGIN_DECLS FlValue gpointer user_data
uint64_t FlutterDesktopEngineProcessMessages(FlutterDesktopEngineRef engine)
FlutterDesktopMessengerRef FlutterDesktopEngineGetMessenger(FlutterDesktopEngineRef engine)
int32_t height
void FlutterDesktopPluginRegistrarUnregisterTopLevelWindowProcDelegate(FlutterDesktopPluginRegistrarRef registrar, FlutterDesktopWindowProcCallback delegate)
FlutterDesktopPluginRegistrarRef FlutterDesktopEngineGetPluginRegistrar(FlutterDesktopEngineRef engine, const char *plugin_name)
int32_t width
bool(* FlutterDesktopWindowProcCallback)(HWND, UINT, WPARAM, LPARAM, void *, LRESULT *result)
static flutter::testing::StubFlutterWindowsApi * s_stub_implementation
static void SetTestStub(StubFlutterWindowsApi *stub)
FlutterDesktopViewRef FlutterDesktopViewControllerGetView(FlutterDesktopViewControllerRef controller)
static StubFlutterWindowsApi * GetTestStub()
virtual void PluginRegistrarRegisterTopLevelWindowProcDelegate(FlutterDesktopWindowProcCallback delegate, void *user_data)
FlutterDesktopEngineRef FlutterDesktopEngineCreate(const FlutterDesktopEngineProperties &engine_properties)
bool FlutterDesktopViewControllerHandleTopLevelWindowProc(FlutterDesktopViewControllerRef controller, HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, LRESULT *result)
virtual FlutterDesktopViewControllerRef ViewControllerCreate(int width, int height, FlutterDesktopEngineRef engine)
virtual bool EngineRun(const char *entry_point)
virtual FlutterDesktopEngineRef EngineCreate(const FlutterDesktopEngineProperties &engine_properties)
FlutterDesktopViewRef FlutterDesktopPluginRegistrarGetView(FlutterDesktopPluginRegistrarRef controller)
bool FlutterDesktopEngineRun(FlutterDesktopEngineRef engine, const char *entry_point)
virtual void PluginRegistrarUnregisterTopLevelWindowProcDelegate(FlutterDesktopWindowProcCallback delegate)