Compare commits

...

5 Commits

Author SHA1 Message Date
Charles Kerr
0e525aa7a5 refactor: remove call DeprecatedLayoutImmediately() 2024-05-09 20:41:50 -05:00
Charles Kerr
1573cc4132 refactor: in NativeWindowViews::SetContentView(), remove redundant calls to content_view() 2024-05-09 20:40:57 -05:00
Charles Kerr
525c18a6fb refactor: in NativeWindowViews::SetContentView(), remove redundant calls to main_view() 2024-05-09 20:40:19 -05:00
Charles Kerr
a0ddbf7390 refactor: RootView::main_view() returns a reference instead of a pointer
It can never be nullptr, so return a reference
2024-05-09 20:23:51 -05:00
Charles Kerr
0e6849c52f refactor: aggregate RootView::main_view_
its lifespan always equals the RootView's, so let's aggregate it.
2024-05-09 20:20:23 -05:00
3 changed files with 13 additions and 11 deletions

View File

@@ -469,13 +469,15 @@ void NativeWindowViews::SetGTKDarkThemeEnabled(bool use_dark_theme) {
} }
void NativeWindowViews::SetContentView(views::View* view) { void NativeWindowViews::SetContentView(views::View* view) {
if (content_view()) { auto& main_view = root_view_.main_view();
root_view_.GetMainView()->RemoveChildView(content_view());
} if (auto* prev_view = content_view())
main_view.RemoveChildView(prev_view);
set_content_view(view); set_content_view(view);
focused_view_ = view; focused_view_ = view;
root_view_.GetMainView()->AddChildView(content_view()); main_view.AddChildView(view);
root_view_.GetMainView()->DeprecatedLayoutImmediately(); main_view.InvalidateLayout();
} }
void NativeWindowViews::Close() { void NativeWindowViews::Close() {
@@ -1680,7 +1682,7 @@ std::u16string NativeWindowViews::GetWindowTitle() const {
} }
views::View* NativeWindowViews::GetContentsView() { views::View* NativeWindowViews::GetContentsView() {
return root_view_.GetMainView(); return &root_view_.main_view();
} }
bool NativeWindowViews::ShouldDescendIntoChildForEventHandling( bool NativeWindowViews::ShouldDescendIntoChildForEventHandling(

View File

@@ -38,9 +38,9 @@ RootView::RootView(NativeWindow* window)
views::BoxLayout* layout = views::BoxLayout* layout =
SetLayoutManager(std::make_unique<views::BoxLayout>( SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical)); views::BoxLayout::Orientation::kVertical));
main_view_ = AddChildView(std::make_unique<views::View>()); AddChildView(&main_view_);
main_view_->SetUseDefaultFillLayout(true); main_view_.SetUseDefaultFillLayout(true);
layout->SetFlexForView(main_view_, 1); layout->SetFlexForView(&main_view_, 1);
} }
RootView::~RootView() = default; RootView::~RootView() = default;

View File

@@ -46,7 +46,7 @@ class RootView : public views::View {
void RegisterAcceleratorsWithFocusManager(ElectronMenuModel* menu_model); void RegisterAcceleratorsWithFocusManager(ElectronMenuModel* menu_model);
void UnregisterAcceleratorsWithFocusManager(); void UnregisterAcceleratorsWithFocusManager();
views::View* GetMainView() { return main_view_; } [[nodiscard]] views::View& main_view() { return main_view_; }
// views::View: // views::View:
gfx::Size GetMinimumSize() const override; gfx::Size GetMinimumSize() const override;
@@ -64,7 +64,7 @@ class RootView : public views::View {
bool menu_bar_alt_pressed_ = false; bool menu_bar_alt_pressed_ = false;
// Main view area. // Main view area.
raw_ptr<views::View> main_view_; views::View main_view_;
// Map from accelerator to menu item's command id. // Map from accelerator to menu item's command id.
accelerator_util::AcceleratorTable accelerator_table_; accelerator_util::AcceleratorTable accelerator_table_;