From eb8691f2ad14cbd09473a90e185bb89e721c505a Mon Sep 17 00:00:00 2001 From: Francisco Magdaleno Date: Thu, 6 Feb 2020 16:53:02 -0800 Subject: [PATCH] Code cleanup on destructors (#16481) --- .../windows/testing/win32_flutter_window_test.cc | 1 - .../windows/testing/win32_flutter_window_test.h | 2 +- shell/platform/windows/win32_flutter_window.cc | 8 +------- shell/platform/windows/win32_flutter_window.h | 14 ++++---------- shell/platform/windows/win32_window.cc | 4 ---- shell/platform/windows/win32_window.h | 11 ++++------- shell/platform/windows/win32_window_unittests.cc | 1 - 7 files changed, 10 insertions(+), 31 deletions(-) diff --git a/shell/platform/windows/testing/win32_flutter_window_test.cc b/shell/platform/windows/testing/win32_flutter_window_test.cc index 080262ae4bf88..bae1d9cd8d5b3 100644 --- a/shell/platform/windows/testing/win32_flutter_window_test.cc +++ b/shell/platform/windows/testing/win32_flutter_window_test.cc @@ -1,5 +1,4 @@ #include "flutter/shell/platform/windows/testing/win32_flutter_window_test.h" -#include namespace flutter { namespace testing { diff --git a/shell/platform/windows/testing/win32_flutter_window_test.h b/shell/platform/windows/testing/win32_flutter_window_test.h index 361a6960a5fc6..24a53f7c529c6 100644 --- a/shell/platform/windows/testing/win32_flutter_window_test.h +++ b/shell/platform/windows/testing/win32_flutter_window_test.h @@ -14,7 +14,7 @@ class Win32FlutterWindowTest : public Win32FlutterWindow { public: Win32FlutterWindowTest(int width, int height); - ~Win32FlutterWindowTest(); + virtual ~Win32FlutterWindowTest(); // |Win32Window| void OnFontChange() override; diff --git a/shell/platform/windows/win32_flutter_window.cc b/shell/platform/windows/win32_flutter_window.cc index 198b2b2e932e6..c0c786799285d 100644 --- a/shell/platform/windows/win32_flutter_window.cc +++ b/shell/platform/windows/win32_flutter_window.cc @@ -4,7 +4,7 @@ namespace flutter { -// the Windows DPI system is based on this +// The Windows DPI system is based on this // constant for machines running at 100% scaling. constexpr int base_dpi = 96; @@ -15,7 +15,6 @@ Win32FlutterWindow::Win32FlutterWindow(int width, int height) { Win32FlutterWindow::~Win32FlutterWindow() { DestroyRenderSurface(); - Win32Window::Destroy(); } FlutterDesktopViewControllerRef Win32FlutterWindow::CreateWin32FlutterWindow( @@ -177,10 +176,6 @@ void Win32FlutterWindow::OnScroll(double delta_x, double delta_y) { } } -void Win32FlutterWindow::OnClose() { - messageloop_running_ = false; -} - void Win32FlutterWindow::OnFontChange() { if (engine_ == nullptr) { return; @@ -358,5 +353,4 @@ void Win32FlutterWindow::DestroyRenderSurface() { } render_surface = EGL_NO_SURFACE; } - } // namespace flutter diff --git a/shell/platform/windows/win32_flutter_window.h b/shell/platform/windows/win32_flutter_window.h index da41c6c3775f7..5fa58aa295c8c 100644 --- a/shell/platform/windows/win32_flutter_window.h +++ b/shell/platform/windows/win32_flutter_window.h @@ -33,7 +33,7 @@ class Win32FlutterWindow : public Win32Window { // Create flutter Window for use as child window Win32FlutterWindow(int width, int height); - ~Win32FlutterWindow(); + virtual ~Win32FlutterWindow(); static FlutterDesktopViewControllerRef CreateWin32FlutterWindow(int width, int height); @@ -65,9 +65,6 @@ class Win32FlutterWindow : public Win32Window { // |Win32Window| void OnScroll(double delta_x, double delta_y) override; - // |Win32Window| - void OnClose() override; - // |Win32Window| void OnFontChange() override; @@ -85,9 +82,6 @@ class Win32FlutterWindow : public Win32Window { // Create a surface for Flutter engine to render into. void CreateRenderSurface(); - // Destroy current rendering surface if one has been allocated. - void DestroyRenderSurface(); - // Callbacks for clearing context, settings context and swapping buffers. bool ClearContext(); bool MakeCurrent(); @@ -99,6 +93,9 @@ class Win32FlutterWindow : public Win32Window { void SendWindowMetrics(); private: + // Destroy current rendering surface if one has been allocated. + void DestroyRenderSurface(); + // Reports a mouse movement to Flutter engine. void SendPointerMove(double x, double y); @@ -174,9 +171,6 @@ class Win32FlutterWindow : public Win32Window { // should we forword input messages or not bool process_events_ = false; - - // flag indicating if the message loop should be running - bool messageloop_running_ = false; }; } // namespace flutter diff --git a/shell/platform/windows/win32_window.cc b/shell/platform/windows/win32_window.cc index e499bfbd129f8..1ecd1926bfd64 100644 --- a/shell/platform/windows/win32_window.cc +++ b/shell/platform/windows/win32_window.cc @@ -112,10 +112,6 @@ Win32Window::MessageHandler(HWND hwnd, case kWmDpiChangedBeforeParent: return HandleDpiChange(window_handle_, wparam, lparam, false); break; - case WM_DESTROY: - window->OnClose(); - return 0; - break; case WM_SIZE: width = LOWORD(lparam); height = HIWORD(lparam); diff --git a/shell/platform/windows/win32_window.h b/shell/platform/windows/win32_window.h index 63a00c355dea6..d64e8097de645 100644 --- a/shell/platform/windows/win32_window.h +++ b/shell/platform/windows/win32_window.h @@ -37,7 +37,7 @@ struct MouseState { class Win32Window { public: Win32Window(); - ~Win32Window(); + virtual ~Win32Window(); // Initializes as a child window with size using |width| and |height| and // |title| to identify the windowclass. Does not show window, window must be @@ -46,9 +46,6 @@ class Win32Window { unsigned int width, unsigned int height); - // Release OS resources asociated with window. - virtual void Destroy(); - HWND GetWindowHandle(); protected: @@ -116,9 +113,6 @@ class Win32Window { // Called when mouse scrollwheel input occurs. virtual void OnScroll(double delta_x, double delta_y) = 0; - // Called when the user closes the Windows. - virtual void OnClose() = 0; - // Called when the system font change. virtual void OnFontChange() = 0; @@ -150,6 +144,9 @@ class Win32Window { void SetMouseButtons(uint64_t buttons) { mouse_state_.buttons = buttons; } private: + // Release OS resources asociated with window. + void Destroy(); + // Activates tracking for a "mouse leave" event. void TrackMouseLeaveEvent(HWND hwnd); diff --git a/shell/platform/windows/win32_window_unittests.cc b/shell/platform/windows/win32_window_unittests.cc index d04458492dff1..dece5a280f807 100644 --- a/shell/platform/windows/win32_window_unittests.cc +++ b/shell/platform/windows/win32_window_unittests.cc @@ -15,7 +15,6 @@ TEST(Win32FlutterWindowTest, CanFontChange) { LRESULT result = SendMessage(hwnd, WM_FONTCHANGE, NULL, NULL); ASSERT_EQ(result, 0); ASSERT_TRUE(window.OnFontChangeWasCalled()); - ASSERT_TRUE(TRUE); } } // namespace testing