Repository: electron/electron
File: shell/browser/ui/views/client_frame_view_linux.cc (C++)

Code before:
    // Unretained() is safe because the window will outlive the frame and
    // buttons.
    button.button->SetCallback(
        base::BindRepeating(button.callback, base::Unretained(window)));
  }

  UpdateThemeValues();
}

gfx::Insets ClientFrameViewLinux::RestoredFrameBorderInsets() const {
  gfx::Insets insets = GetFrameProvider()->GetFrameThicknessDip();
  const gfx::Insets input = GetInputInsets();

  auto expand_if_visible = [](int side_thickness, int min_band) {
    return side_thickness > 0 ? std::max(side_thickness, min_band) : 0;
  };

  gfx::Insets merged;
  merged.set_top(expand_if_visible(insets.top(), input.top()));
  merged.set_left(expand_if_visible(insets.left(), input.left()));
  merged.set_bottom(expand_if_visible(insets.bottom(), input.bottom()));
  merged.set_right(expand_if_visible(insets.right(), input.right()));

  return base::i18n::IsRTL() ? gfx::Insets::TLBR(merged.top(), merged.right(),
                                                 merged.bottom(), merged.left())
                             : merged;
}

gfx::Insets ClientFrameViewLinux::GetInputInsets() const {
  bool showing_shadow = host_supports_client_frame_shadow_ &&
                        !frame_->IsMaximized() && !frame_->IsFullscreen();
  return gfx::Insets(showing_shadow ? kResizeBorder : 0);
}

gfx::Rect ClientFrameViewLinux::GetWindowContentBounds() const {
  gfx::Rect content_bounds = bounds();
  content_bounds.Inset(RestoredFrameBorderInsets());
  return content_bounds;
}

SkRRect ClientFrameViewLinux::GetRoundedWindowContentBounds() const {
  SkRect rect = gfx::RectToSkRect(GetWindowContentBounds());
  SkRRect rrect;

  if (!frame_->IsMaximized()) {
    SkPoint round_point{theme_values_.window_border_radius,
                        theme_values_.window_border_radius};
    SkPoint radii[] = {round_point, round_point, {}, {}};
    rrect.setRectRadii(rect, radii);
  } else {
    rrect.setRect(rect);

Review comment (suggestion):
The RTL mirror logic used to have its own method (`RestoredMirrorFrameBorderInsets`) but it should be applied any time the insets are needed, so I merged the two methods. 

Code after:
    // Unretained() is safe because the buttons are added as children to, and
    // thus owned by, this view. Thus, the buttons themselves will be destroyed
    // when this view is destroyed, and the frame's life must never outlive the
    // view.
    button.button->SetCallback(
        base::BindRepeating(button.callback, base::Unretained(frame)));
  }

  UpdateThemeValues();
}

gfx::Insets ClientFrameViewLinux::RestoredFrameBorderInsets() const {
  gfx::Insets insets = GetFrameProvider()->GetFrameThicknessDip();
  const gfx::Insets input = GetInputInsets();

  auto expand_if_visible = [](int side_thickness, int min_band) {
    return side_thickness > 0 ? std::max(side_thickness, min_band) : 0;
  };

  gfx::Insets merged;
  merged.set_top(expand_if_visible(insets.top(), input.top()));
  merged.set_left(expand_if_visible(insets.left(), input.left()));
  merged.set_bottom(expand_if_visible(insets.bottom(), input.bottom()));
  merged.set_right(expand_if_visible(insets.right(), input.right()));

  return base::i18n::IsRTL() ? gfx::Insets::TLBR(merged.top(), merged.right(),
                                                 merged.bottom(), merged.left())
                             : merged;
}

gfx::Insets ClientFrameViewLinux::GetInputInsets() const {
  bool showing_shadow = host_supports_client_frame_shadow_ &&
                        !frame_->IsMaximized() && !frame_->IsFullscreen();
  return gfx::Insets(showing_shadow ? kResizeBorder : 0);
}

gfx::Rect ClientFrameViewLinux::GetWindowContentBounds() const {
  gfx::Rect content_bounds = bounds();
  content_bounds.Inset(RestoredFrameBorderInsets());
  return content_bounds;
}

SkRRect ClientFrameViewLinux::GetRoundedWindowContentBounds() const {
  SkRect rect = gfx::RectToSkRect(GetWindowContentBounds());
  SkRRect rrect;

  if (!frame_->IsMaximized()) {
    SkPoint round_point{theme_values_.window_border_radius,
                        theme_values_.window_border_radius};
    SkPoint radii[] = {round_point, round_point, {}, {}};
    rrect.setRectRadii(rect, radii);