Repository: electron/electron
File: shell/browser/native_window_views.cc (C++)

Code before:

#if BUILDFLAG(IS_LINUX)
  // On linux after the widget is initialized we might have to force set the
  // bounds if the bounds are smaller than the current display
  SetBounds(gfx::Rect(GetPosition(), bounds.size()), false);
#endif
}

NativeWindowViews::~NativeWindowViews() {
  widget()->RemoveObserver(this);

#if BUILDFLAG(IS_WIN)
  // Disable mouse forwarding to relinquish resources, should any be held.
  SetForwardMouseMessages(false);
#endif

  if (aura::Window* const window = GetNativeWindow())
    window->RemovePreTargetHandler(this);

  if (is_modal()) {
    if (NativeWindow* const parent = this->parent()) {
      // Enable parent window after current window gets closed.
      static_cast<NativeWindowViews*>(parent)->DecrementChildModals();
      // Focus on parent window.
      parent->Focus(true);
    }
  }
}

void NativeWindowViews::SetGTKDarkThemeEnabled(bool use_dark_theme) {
#if BUILDFLAG(IS_LINUX)
  if (IsX11()) {
    const std::string color = use_dark_theme ? "dark" : "light";
    auto* connection = x11::Connection::Get();
    connection->SetStringProperty(
        static_cast<x11::Window>(GetAcceleratedWidget()),
        x11::GetAtom("_GTK_THEME_VARIANT"), x11::GetAtom("UTF8_STRING"), color);
  }
#endif
}

void NativeWindowViews::SetContentView(views::View* view) {
  if (content_view()) {
    root_view_.GetMainView()->RemoveChildView(content_view());
  }
  set_content_view(view);
  focused_view_ = view;
  root_view_.GetMainView()->AddChildViewRaw(content_view());
  root_view_.GetMainView()->DeprecatedLayoutImmediately();
}


Review comment (refactor):
Is there a case when `OnWidgetDestroying` won't be called, why duplicate it in the delegate destructor ?

Code after:

#if BUILDFLAG(IS_LINUX)
  // On linux after the widget is initialized we might have to force set the
  // bounds if the bounds are smaller than the current display
  SetBounds(gfx::Rect(GetPosition(), bounds.size()), false);
#endif
}

NativeWindowViews::~NativeWindowViews() {
  widget()->RemoveObserver(this);

#if BUILDFLAG(IS_WIN)
  // Disable mouse forwarding to relinquish resources, should any be held.
  SetForwardMouseMessages(false);
#endif

  aura::Window* window = GetNativeWindow();
  if (window)
    window->RemovePreTargetHandler(this);
}

void NativeWindowViews::SetGTKDarkThemeEnabled(bool use_dark_theme) {
#if BUILDFLAG(IS_LINUX)
  if (IsX11()) {
    const std::string color = use_dark_theme ? "dark" : "light";
    auto* connection = x11::Connection::Get();
    connection->SetStringProperty(
        static_cast<x11::Window>(GetAcceleratedWidget()),
        x11::GetAtom("_GTK_THEME_VARIANT"), x11::GetAtom("UTF8_STRING"), color);
  }
#endif
}

void NativeWindowViews::SetContentView(views::View* view) {
  if (content_view()) {
    root_view_.GetMainView()->RemoveChildView(content_view());
  }
  set_content_view(view);
  focused_view_ = view;
  root_view_.GetMainView()->AddChildViewRaw(content_view());
  root_view_.GetMainView()->DeprecatedLayoutImmediately();
}

void NativeWindowViews::Close() {
  if (!IsClosable()) {
    WindowList::WindowCloseCancelled(this);
    return;
  }

  widget()->Close();
}