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

Code before:
      break;
    default:
      button_flags = 0;
      break;
  }

  ui::MouseEvent ui_event{event.GetTypeAsUiEventType(),
                          event.PositionInWidget(),
                          event.PositionInWidget(),
                          ui::EventTimeForNow(),
                          button_flags,
                          button_flags};
  ui_event.SetClickCount(event.click_count);

  return ui_event;
}

ui::MouseWheelEvent UiMouseWheelEventFromWebMouseEvent(
    blink::WebMouseWheelEvent event) {
  return {UiMouseEventFromWebMouseEvent(event),
          base::ClampFloor<int>(event.delta_x),
          base::ClampFloor<int>(event.delta_y)};
}

// TODO(reito): Remove this function and use default 1.0f when breaking change
// is announced for a sufficient period.
float GetDefaultDeviceScaleFactorFromDisplayInfo() {
  display::Display display =
      display::Screen::Get()->GetDisplayNearestView(gfx::NativeView());

  const float factor = display.device_scale_factor();
  return factor > 0 ? factor : 1.0f;
}

}  // namespace

class ElectronDelegatedFrameHostClient
    : public content::DelegatedFrameHostClient {
 public:
  explicit ElectronDelegatedFrameHostClient(OffScreenRenderWidgetHostView* view)
      : view_(view) {}

  // disable copy
  ElectronDelegatedFrameHostClient(const ElectronDelegatedFrameHostClient&) =
      delete;
  ElectronDelegatedFrameHostClient& operator=(
      const ElectronDelegatedFrameHostClient&) = delete;

  // content::DelegatedFrameHostClient
  [[nodiscard]] ui::Layer* DelegatedFrameHostGetLayer() const override {
    return view_->root_layer();

Review comment (suggestion):
_(nit)_ I don't think I have enough context from this PR to know what a sufficient period is. I think this is probably also gonna be true for maintainers who come across this comment in the codebase.

Please let's use "This can be removed in Electron ${version}" or "This can be removed after ${date}".


Code after:
      break;
    default:
      button_flags = 0;
      break;
  }

  ui::MouseEvent ui_event{event.GetTypeAsUiEventType(),
                          event.PositionInWidget(),
                          event.PositionInWidget(),
                          ui::EventTimeForNow(),
                          button_flags,
                          button_flags};
  ui_event.SetClickCount(event.click_count);

  return ui_event;
}

ui::MouseWheelEvent UiMouseWheelEventFromWebMouseEvent(
    blink::WebMouseWheelEvent event) {
  return {UiMouseEventFromWebMouseEvent(event),
          base::ClampFloor<int>(event.delta_x),
          base::ClampFloor<int>(event.delta_y)};
}

// TODO(reito): Remove this function and use default 1.0f when Electron 42.
float GetDefaultDeviceScaleFactorFromDisplayInfo() {
  display::Display display =
      display::Screen::Get()->GetDisplayNearestView(gfx::NativeView());

  const float factor = display.device_scale_factor();
  return factor > 0 ? factor : 1.0f;
}

}  // namespace

class ElectronDelegatedFrameHostClient
    : public content::DelegatedFrameHostClient {
 public:
  explicit ElectronDelegatedFrameHostClient(OffScreenRenderWidgetHostView* view)
      : view_(view) {}

  // disable copy
  ElectronDelegatedFrameHostClient(const ElectronDelegatedFrameHostClient&) =
      delete;
  ElectronDelegatedFrameHostClient& operator=(
      const ElectronDelegatedFrameHostClient&) = delete;

  // content::DelegatedFrameHostClient
  [[nodiscard]] ui::Layer* DelegatedFrameHostGetLayer() const override {
    return view_->root_layer();
  }