refactor: simplify some BaseWindow
JS getters (#46542)
* refactor: return a std::array<int 2> from BaseWindow::GetMaximumSize() * refactor: return a std::array<int 2> from BaseWindow::GetMinimumSize() * refactor: return a std::array<int 2> from BaseWindow::GetPosition() * refactor: return a std::array<int 2> from BaseWindow::GetSize() * refactor: return a std::array<int 2> from BaseWindow::GetContentSize() * refactor: extract helper method ToArray(const gfx::Size) * refactor: #include correctness
This commit is contained in:
parent
1a6de10da8
commit
636cbc19ac
3 changed files with 25 additions and 35 deletions
|
@ -79,6 +79,14 @@ v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
|
||||||
return buffer.ToLocalChecked();
|
return buffer.ToLocalChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr std::array<int, 2U> ToArray(const gfx::Size size) {
|
||||||
|
return {size.width(), size.height()};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr std::array<int, 2U> ToArray(const gfx::Point point) {
|
||||||
|
return {point.x(), point.y()};
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
BaseWindow::BaseWindow(v8::Isolate* isolate,
|
BaseWindow::BaseWindow(v8::Isolate* isolate,
|
||||||
|
@ -467,12 +475,8 @@ void BaseWindow::SetSize(int width, int height, gin_helper::Arguments* args) {
|
||||||
window_->SetSize(size, animate);
|
window_->SetSize(size, animate);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int> BaseWindow::GetSize() const {
|
std::array<int, 2U> BaseWindow::GetSize() const {
|
||||||
std::vector<int> result(2);
|
return ToArray(window_->GetSize());
|
||||||
gfx::Size size = window_->GetSize();
|
|
||||||
result[0] = size.width();
|
|
||||||
result[1] = size.height();
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseWindow::SetContentSize(int width,
|
void BaseWindow::SetContentSize(int width,
|
||||||
|
@ -483,36 +487,24 @@ void BaseWindow::SetContentSize(int width,
|
||||||
window_->SetContentSize(gfx::Size(width, height), animate);
|
window_->SetContentSize(gfx::Size(width, height), animate);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int> BaseWindow::GetContentSize() const {
|
std::array<int, 2U> BaseWindow::GetContentSize() const {
|
||||||
std::vector<int> result(2);
|
return ToArray(window_->GetContentSize());
|
||||||
gfx::Size size = window_->GetContentSize();
|
|
||||||
result[0] = size.width();
|
|
||||||
result[1] = size.height();
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseWindow::SetMinimumSize(int width, int height) {
|
void BaseWindow::SetMinimumSize(int width, int height) {
|
||||||
window_->SetMinimumSize(gfx::Size(width, height));
|
window_->SetMinimumSize(gfx::Size(width, height));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int> BaseWindow::GetMinimumSize() const {
|
std::array<int, 2U> BaseWindow::GetMinimumSize() const {
|
||||||
std::vector<int> result(2);
|
return ToArray(window_->GetMinimumSize());
|
||||||
gfx::Size size = window_->GetMinimumSize();
|
|
||||||
result[0] = size.width();
|
|
||||||
result[1] = size.height();
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseWindow::SetMaximumSize(int width, int height) {
|
void BaseWindow::SetMaximumSize(int width, int height) {
|
||||||
window_->SetMaximumSize(gfx::Size(width, height));
|
window_->SetMaximumSize(gfx::Size(width, height));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int> BaseWindow::GetMaximumSize() const {
|
std::array<int, 2U> BaseWindow::GetMaximumSize() const {
|
||||||
std::vector<int> result(2);
|
return ToArray(window_->GetMaximumSize());
|
||||||
gfx::Size size = window_->GetMaximumSize();
|
|
||||||
result[0] = size.width();
|
|
||||||
result[1] = size.height();
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseWindow::SetSheetOffset(double offsetY, gin_helper::Arguments* args) {
|
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);
|
window_->SetPosition(gfx::Point(x, y), animate);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int> BaseWindow::GetPosition() const {
|
std::array<int, 2U> BaseWindow::GetPosition() const {
|
||||||
std::vector<int> result(2);
|
return ToArray(window_->GetPosition());
|
||||||
gfx::Point pos = window_->GetPosition();
|
|
||||||
result[0] = pos.x();
|
|
||||||
result[1] = pos.y();
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
void BaseWindow::MoveAbove(const std::string& sourceId,
|
void BaseWindow::MoveAbove(const std::string& sourceId,
|
||||||
gin_helper::Arguments* args) {
|
gin_helper::Arguments* args) {
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_BASE_WINDOW_H_
|
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_BASE_WINDOW_H_
|
||||||
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_BASE_WINDOW_H_
|
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_BASE_WINDOW_H_
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
@ -119,17 +120,17 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
|
||||||
void SetBounds(const gfx::Rect& bounds, gin_helper::Arguments* args);
|
void SetBounds(const gfx::Rect& bounds, gin_helper::Arguments* args);
|
||||||
gfx::Rect GetBounds() const;
|
gfx::Rect GetBounds() const;
|
||||||
void SetSize(int width, int height, gin_helper::Arguments* args);
|
void SetSize(int width, int height, gin_helper::Arguments* args);
|
||||||
std::vector<int> GetSize() const;
|
std::array<int, 2U> GetSize() const;
|
||||||
void SetContentSize(int width, int height, gin_helper::Arguments* args);
|
void SetContentSize(int width, int height, gin_helper::Arguments* args);
|
||||||
std::vector<int> GetContentSize() const;
|
std::array<int, 2U> GetContentSize() const;
|
||||||
void SetContentBounds(const gfx::Rect& bounds, gin_helper::Arguments* args);
|
void SetContentBounds(const gfx::Rect& bounds, gin_helper::Arguments* args);
|
||||||
gfx::Rect GetContentBounds() const;
|
gfx::Rect GetContentBounds() const;
|
||||||
bool IsNormal() const;
|
bool IsNormal() const;
|
||||||
gfx::Rect GetNormalBounds() const;
|
gfx::Rect GetNormalBounds() const;
|
||||||
void SetMinimumSize(int width, int height);
|
void SetMinimumSize(int width, int height);
|
||||||
std::vector<int> GetMinimumSize() const;
|
std::array<int, 2U> GetMinimumSize() const;
|
||||||
void SetMaximumSize(int width, int height);
|
void SetMaximumSize(int width, int height);
|
||||||
std::vector<int> GetMaximumSize() const;
|
std::array<int, 2U> GetMaximumSize() const;
|
||||||
void SetSheetOffset(double offsetY, gin_helper::Arguments* args);
|
void SetSheetOffset(double offsetY, gin_helper::Arguments* args);
|
||||||
void SetResizable(bool resizable);
|
void SetResizable(bool resizable);
|
||||||
bool IsResizable() const;
|
bool IsResizable() const;
|
||||||
|
@ -149,7 +150,7 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
|
||||||
bool IsAlwaysOnTop() const;
|
bool IsAlwaysOnTop() const;
|
||||||
void Center();
|
void Center();
|
||||||
void SetPosition(int x, int y, gin_helper::Arguments* args);
|
void SetPosition(int x, int y, gin_helper::Arguments* args);
|
||||||
std::vector<int> GetPosition() const;
|
std::array<int, 2U> GetPosition() const;
|
||||||
void SetTitle(const std::string& title);
|
void SetTitle(const std::string& title);
|
||||||
std::string GetTitle() const;
|
std::string GetTitle() const;
|
||||||
void SetAccessibleTitle(const std::string& title);
|
void SetAccessibleTitle(const std::string& title);
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#ifndef ELECTRON_SHELL_COMMON_GIN_CONVERTERS_STD_CONVERTER_H_
|
#ifndef ELECTRON_SHELL_COMMON_GIN_CONVERTERS_STD_CONVERTER_H_
|
||||||
#define ELECTRON_SHELL_COMMON_GIN_CONVERTERS_STD_CONVERTER_H_
|
#define ELECTRON_SHELL_COMMON_GIN_CONVERTERS_STD_CONVERTER_H_
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue