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

Code before:
void View::RemoveChildView(gin_helper::Handle<View> child) {
  if (!view_)
    return;

  const auto it =
      std::ranges::find_if(child_views_, [&](const ChildPair& child_view) {
        return child_view.first == child->view();
      });
  if (it != child_views_.end()) {
#if BUILDFLAG(IS_MAC)
    ScopedCAActionDisabler disable_animations;
#endif
    // Remove from child_views first so that OnChildViewRemoved doesn't try to
    // remove it again
    child_views_.erase(it);
    // It's possible for the child's view to be invalid here
    // if the child's webContents was closed or destroyed.
    if (child->view())
      view_->RemoveChildView(child->view());
  }
}

void View::SetBounds(const gfx::Rect& bounds, gin::Arguments* const args) {
  bool animate = false;
  int duration = 250;
  std::string easing = "linear";

  gin_helper::Dictionary options;
  if (args->GetNext(&options)) {
    options.Get("animate", &animate);
    options.Get("duration", &duration);
    options.Get("easing", &easing);
  }

  if (duration < 0)
    duration = 0;

  if (!view_)
    return;

  if (!animate) {
    view_->SetBoundsRect(bounds);

    return;
  }

  gfx::Tween::Type tween_type = gfx::Tween::LINEAR;

  if (easing == "ease-in") {
    tween_type = gfx::Tween::EASE_IN;
  } else if (easing == "ease-out") {

Review comment (suggestion):
We should use a gin converter here - this would then become:
```
gfx::Tween::Type easing = gfx::Tween::LINEAR;
```


Code after:
    return;
  }

  child_views_.emplace(child_views_.begin() + index,  // index
                       child->view(),
                       v8::Global<v8::Object>(isolate(), child->GetWrapper()));
#if BUILDFLAG(IS_MAC)
  // Disable the implicit CALayer animations that happen by default when adding
  // or removing sublayers.
  // See
  // https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CoreAnimation_guide/ReactingtoLayerChanges/ReactingtoLayerChanges.html
  // and https://github.com/electron/electron/pull/14911
  // TODO(nornagon): Disabling these CALayer animations (which are specific to
  // WebContentsView, I think) seems like this is something that remote_cocoa
  // or views should be taking care of, but isn't. This should be pushed
  // upstream.
  ScopedCAActionDisabler disable_animations;
#endif
  view_->AddChildViewAt(child->view(), index);
}

void View::RemoveChildView(gin_helper::Handle<View> child) {
  if (!view_)
    return;

  const auto it =
      std::ranges::find_if(child_views_, [&](const ChildPair& child_view) {
        return child_view.first == child->view();
      });
  if (it != child_views_.end()) {
#if BUILDFLAG(IS_MAC)
    ScopedCAActionDisabler disable_animations;
#endif
    // Remove from child_views first so that OnChildViewRemoved doesn't try to
    // remove it again
    child_views_.erase(it);
    // It's possible for the child's view to be invalid here
    // if the child's webContents was closed or destroyed.
    if (child->view())
      view_->RemoveChildView(child->view());
  }
}

ui::Layer* View::GetLayer() {
  if (!view_)
    return nullptr;

  if (view_->layer())
    return view_->layer();

  view_->SetPaintToLayer();