This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Add support for setting window size limits for glfw #13415
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
shell/platform/glfw/client_wrapper/flutter_window_unittests.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #include "flutter/shell/platform/glfw/client_wrapper/include/flutter/flutter_window.h" | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include "flutter/shell/platform/glfw/client_wrapper/testing/stub_flutter_glfw_api.h" | ||
| #include "gtest/gtest.h" | ||
|
|
||
| namespace flutter { | ||
|
|
||
| namespace { | ||
|
|
||
| // Stub implementation to validate calls to the API. | ||
| class TestGlfwApi : public testing::StubFlutterGlfwApi { | ||
| public: | ||
| // |flutter::testing::StubFlutterGlfwApi| | ||
| void SetSizeLimits(FlutterDesktopSize minimum_size, | ||
| FlutterDesktopSize maximum_size) override { | ||
| set_size_limits_called_ = true; | ||
| } | ||
|
|
||
| bool set_size_limits_called() { return set_size_limits_called_; } | ||
|
|
||
| private: | ||
| bool set_size_limits_called_ = false; | ||
| }; | ||
|
|
||
| } // namespace | ||
|
|
||
| TEST(FlutterWindowTest, SetSizeLimits) { | ||
| const std::string icu_data_path = "fake/path/to/icu"; | ||
| testing::ScopedStubFlutterGlfwApi scoped_api_stub( | ||
| std::make_unique<TestGlfwApi>()); | ||
| auto test_api = static_cast<TestGlfwApi*>(scoped_api_stub.stub()); | ||
| // This is not actually used so any non-zero value works. | ||
| auto raw_window = reinterpret_cast<FlutterDesktopWindowRef>(1); | ||
|
|
||
| auto window = std::make_unique<FlutterWindow>(raw_window); | ||
|
|
||
| FlutterDesktopSize minimum_size = {}; | ||
| minimum_size.width = 100; | ||
| minimum_size.height = 100; | ||
|
|
||
| FlutterDesktopSize maximum_size = {}; | ||
| maximum_size.width = -1; | ||
| maximum_size.height = -1; | ||
|
|
||
| window->SetSizeLimits(minimum_size, maximum_size); | ||
|
|
||
| EXPECT_EQ(test_api->set_size_limits_called(), true); | ||
| } | ||
|
|
||
| } // namespace flutter | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,6 +88,13 @@ class FlutterWindow { | |
| FlutterDesktopWindowSetPixelRatioOverride(window_, pixel_ratio); | ||
| } | ||
|
|
||
| // Sets the min/max size of |flutter_window| in screen coordinates. Use | ||
| // kFlutterDesktopDontCare for any dimension you wish to leave unconstrained. | ||
| void SetSizeLimits(FlutterDesktopSize minimum_size, | ||
| FlutterDesktopSize maximum_size) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may want to use different structs/constants rather than relying on the wrapped API's types, but that's fine to revisit later. |
||
| FlutterDesktopWindowSetSizeLimits(window_, minimum_size, maximum_size); | ||
| } | ||
|
|
||
| private: | ||
| // Handle for interacting with the C API's window. | ||
| // | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this file! I forgot this hadn't been done for the window class yet; desktop embedding testing is not in a good state yet obviously, so getting more of the initial test files set up is great.