diff --git a/shell/browser/api/electron_api_base_window.cc b/shell/browser/api/electron_api_base_window.cc index aa6e515fefc..431fc66f963 100644 --- a/shell/browser/api/electron_api_base_window.cc +++ b/shell/browser/api/electron_api_base_window.cc @@ -79,6 +79,14 @@ v8::Local ToBuffer(v8::Isolate* isolate, void* val, int size) { return buffer.ToLocalChecked(); } +[[nodiscard]] constexpr std::array ToArray(const gfx::Size size) { + return {size.width(), size.height()}; +} + +[[nodiscard]] constexpr std::array ToArray(const gfx::Point point) { + return {point.x(), point.y()}; +} + } // namespace BaseWindow::BaseWindow(v8::Isolate* isolate, @@ -467,12 +475,8 @@ void BaseWindow::SetSize(int width, int height, gin_helper::Arguments* args) { window_->SetSize(size, animate); } -std::vector BaseWindow::GetSize() const { - std::vector result(2); - gfx::Size size = window_->GetSize(); - result[0] = size.width(); - result[1] = size.height(); - return result; +std::array BaseWindow::GetSize() const { + return ToArray(window_->GetSize()); } void BaseWindow::SetContentSize(int width, @@ -483,36 +487,24 @@ void BaseWindow::SetContentSize(int width, window_->SetContentSize(gfx::Size(width, height), animate); } -std::vector BaseWindow::GetContentSize() const { - std::vector result(2); - gfx::Size size = window_->GetContentSize(); - result[0] = size.width(); - result[1] = size.height(); - return result; +std::array BaseWindow::GetContentSize() const { + return ToArray(window_->GetContentSize()); } void BaseWindow::SetMinimumSize(int width, int height) { window_->SetMinimumSize(gfx::Size(width, height)); } -std::vector BaseWindow::GetMinimumSize() const { - std::vector result(2); - gfx::Size size = window_->GetMinimumSize(); - result[0] = size.width(); - result[1] = size.height(); - return result; +std::array BaseWindow::GetMinimumSize() const { + return ToArray(window_->GetMinimumSize()); } void BaseWindow::SetMaximumSize(int width, int height) { window_->SetMaximumSize(gfx::Size(width, height)); } -std::vector BaseWindow::GetMaximumSize() const { - std::vector result(2); - gfx::Size size = window_->GetMaximumSize(); - result[0] = size.width(); - result[1] = size.height(); - return result; +std::array BaseWindow::GetMaximumSize() const { + return ToArray(window_->GetMaximumSize()); } void BaseWindow::SetSheetOffset(double offsetY, gin_helper::Arguments* args) { @@ -594,12 +586,8 @@ void BaseWindow::SetPosition(int x, int y, gin_helper::Arguments* args) { window_->SetPosition(gfx::Point(x, y), animate); } -std::vector BaseWindow::GetPosition() const { - std::vector result(2); - gfx::Point pos = window_->GetPosition(); - result[0] = pos.x(); - result[1] = pos.y(); - return result; +std::array BaseWindow::GetPosition() const { + return ToArray(window_->GetPosition()); } void BaseWindow::MoveAbove(const std::string& sourceId, gin_helper::Arguments* args) { diff --git a/shell/browser/api/electron_api_base_window.h b/shell/browser/api/electron_api_base_window.h index 72e69ad4b89..b652a6ffa3a 100644 --- a/shell/browser/api/electron_api_base_window.h +++ b/shell/browser/api/electron_api_base_window.h @@ -5,6 +5,7 @@ #ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_BASE_WINDOW_H_ #define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_BASE_WINDOW_H_ +#include #include #include #include @@ -119,17 +120,17 @@ class BaseWindow : public gin_helper::TrackableObject, void SetBounds(const gfx::Rect& bounds, gin_helper::Arguments* args); gfx::Rect GetBounds() const; void SetSize(int width, int height, gin_helper::Arguments* args); - std::vector GetSize() const; + std::array GetSize() const; void SetContentSize(int width, int height, gin_helper::Arguments* args); - std::vector GetContentSize() const; + std::array GetContentSize() const; void SetContentBounds(const gfx::Rect& bounds, gin_helper::Arguments* args); gfx::Rect GetContentBounds() const; bool IsNormal() const; gfx::Rect GetNormalBounds() const; void SetMinimumSize(int width, int height); - std::vector GetMinimumSize() const; + std::array GetMinimumSize() const; void SetMaximumSize(int width, int height); - std::vector GetMaximumSize() const; + std::array GetMaximumSize() const; void SetSheetOffset(double offsetY, gin_helper::Arguments* args); void SetResizable(bool resizable); bool IsResizable() const; @@ -149,7 +150,7 @@ class BaseWindow : public gin_helper::TrackableObject, bool IsAlwaysOnTop() const; void Center(); void SetPosition(int x, int y, gin_helper::Arguments* args); - std::vector GetPosition() const; + std::array GetPosition() const; void SetTitle(const std::string& title); std::string GetTitle() const; void SetAccessibleTitle(const std::string& title); diff --git a/shell/common/gin_converters/std_converter.h b/shell/common/gin_converters/std_converter.h index 4ea06b487de..08704341a8a 100644 --- a/shell/common/gin_converters/std_converter.h +++ b/shell/common/gin_converters/std_converter.h @@ -5,6 +5,7 @@ #ifndef ELECTRON_SHELL_COMMON_GIN_CONVERTERS_STD_CONVERTER_H_ #define ELECTRON_SHELL_COMMON_GIN_CONVERTERS_STD_CONVERTER_H_ +#include #include #include #include