Global Metrics

path: .metrics.nargs.average
old: 3.272727272727273
new: 0.8

path: .metrics.nargs.sum
old: 36.0
new: 4.0

path: .metrics.cyclomatic.average
old: 1.1666666666666667
new: 2.25

path: .metrics.cyclomatic.sum
old: 14.0
new: 18.0

path: .metrics.mi.mi_sei
old: 19.81403261730872
new: 25.03864074614938

path: .metrics.mi.mi_original
old: 45.121479015569136
new: 53.09477131753147

path: .metrics.mi.mi_visual_studio
old: 26.38682983366616
new: 31.049573869901444

path: .metrics.cognitive.average
old: 0.18181818181818185
new: 2.0

path: .metrics.cognitive.sum
old: 2.0
new: 10.0

path: .metrics.nexits.average
old: 0.9090909090909092
new: 1.8

path: .metrics.nexits.sum
old: 10.0
new: 9.0

path: .metrics.halstead.effort
old: 139691.24051485193
new: 34798.136977334725

path: .metrics.halstead.n2
old: 67.0
new: 53.0

path: .metrics.halstead.length
old: 590.0
new: 295.0

path: .metrics.halstead.difficulty
old: 36.940298507462686
new: 19.245283018867923

path: .metrics.halstead.time
old: 7760.62447304733
new: 1933.229832074151

path: .metrics.halstead.bugs
old: 0.8974112880776036
new: 0.3552898010592134

path: .metrics.halstead.purity_ratio
old: 0.816079026757004
new: 1.264632719976628

path: .metrics.halstead.N2
old: 275.0
new: 120.0

path: .metrics.halstead.vocabulary
old: 85.0
new: 70.0

path: .metrics.halstead.level
old: 0.02707070707070707
new: 0.05196078431372549

path: .metrics.halstead.n1
old: 18.0
new: 17.0

path: .metrics.halstead.volume
old: 3781.540652321244
new: 1808.1384899987652

path: .metrics.halstead.estimated_program_length
old: 481.4866257866323
new: 373.0666523931053

path: .metrics.halstead.N1
old: 315.0
new: 175.0

path: .metrics.loc.blank
old: 15.0
new: 11.0

path: .metrics.loc.sloc
old: 138.0
new: 101.0

path: .metrics.loc.cloc
old: 22.0
new: 9.0

path: .metrics.loc.lloc
old: 18.0
new: 24.0

path: .metrics.loc.ploc
old: 101.0
new: 81.0

path: .metrics.nom.functions
old: 11.0
new: 5.0

path: .metrics.nom.total
old: 11.0
new: 5.0

Spaces Data

Minimal test - lines (22, 101)

path: .spaces[0].metrics.halstead.volume
old: 350.0
new: 1674.0

path: .spaces[0].metrics.halstead.length
old: 70.0
new: 279.0

path: .spaces[0].metrics.halstead.n1
old: 15.0
new: 17.0

path: .spaces[0].metrics.halstead.purity_ratio
old: 1.829860389076908
new: 1.1847761445523466

path: .spaces[0].metrics.halstead.vocabulary
old: 32.0
new: 64.0

path: .spaces[0].metrics.halstead.level
old: 0.09444444444444444
new: 0.048932847475273294

path: .spaces[0].metrics.halstead.time
old: 205.8823529411765
new: 1900.563829787234

path: .spaces[0].metrics.halstead.estimated_program_length
old: 128.09022723538357
new: 330.5525443301047

path: .spaces[0].metrics.halstead.N1
old: 46.0
new: 166.0

path: .spaces[0].metrics.halstead.effort
old: 3705.8823529411766
new: 34210.14893617021

path: .spaces[0].metrics.halstead.n2
old: 17.0
new: 47.0

path: .spaces[0].metrics.halstead.N2
old: 24.0
new: 113.0

path: .spaces[0].metrics.halstead.bugs
old: 0.0798251660582055
new: 0.35127619663372156

path: .spaces[0].metrics.halstead.difficulty
old: 10.588235294117649
new: 20.43617021276596

path: .spaces[0].metrics.cyclomatic.sum
old: 2.0
new: 17.0

path: .spaces[0].metrics.cyclomatic.average
old: 2.0
new: 2.4285714285714284

path: .spaces[0].metrics.nom.functions
old: 1.0
new: 5.0

path: .spaces[0].metrics.nom.total
old: 1.0
new: 5.0

path: .spaces[0].metrics.nexits.average
old: 0.0
new: 1.8

path: .spaces[0].metrics.nexits.sum
old: 0.0
new: 9.0

path: .spaces[0].metrics.cognitive.sum
old: 1.0
new: 10.0

path: .spaces[0].metrics.cognitive.average
old: 1.0
new: 2.0

path: .spaces[0].metrics.loc.blank
old: 0.0
new: 7.0

path: .spaces[0].metrics.loc.ploc
old: 13.0
new: 70.0

path: .spaces[0].metrics.loc.cloc
old: 1.0
new: 3.0

path: .spaces[0].metrics.loc.lloc
old: 3.0
new: 24.0

path: .spaces[0].metrics.loc.sloc
old: 14.0
new: 80.0

path: .spaces[0].metrics.nargs.average
old: 3.0
new: 0.8

path: .spaces[0].metrics.nargs.sum
old: 3.0
new: 4.0

path: .spaces[0].metrics.mi.mi_original
old: 97.32601885691884
new: 57.501718012826146

path: .spaces[0].metrics.mi.mi_visual_studio
old: 56.91580050112213
new: 33.626735680015294

path: .spaces[0].metrics.mi.mi_sei
old: 85.03008372152294
new: 23.76353937062993

Code

namespace mozilla {
namespace widget {

#ifndef __MINGW32__
static ComPtr GetInputPane(HWND aHwnd) {
  ComPtr inputPaneInterop;
  HRESULT hr = RoGetActivationFactory(
      HStringReference(RuntimeClass_Windows_UI_ViewManagement_InputPane).Get(),
      IID_PPV_ARGS(&inputPaneInterop));
  if (NS_WARN_IF(FAILED(hr))) {
    return nullptr;
  }

  ComPtr inputPane;
  hr = inputPaneInterop->GetForWindow(aHwnd, IID_PPV_ARGS(&inputPane));
  if (NS_WARN_IF(FAILED(hr))) {
    return nullptr;
  }

  ComPtr inputPane2;
  inputPane.As(&inputPane2);
  return inputPane2;
}

#  ifdef DEBUG
static bool IsInputPaneVisible(ComPtr& aInputPane2) {
  ComPtr inputPaneControl;
  aInputPane2.As(&inputPaneControl);
  if (NS_WARN_IF(!inputPaneControl)) {
    return false;
  }
  boolean visible = false;
  inputPaneControl->get_Visible(&visible);
  return visible;
}

static bool IsForegroundApp() {
  HWND foregroundWnd = ::GetForegroundWindow();
  if (!foregroundWnd) {
    return false;
  }
  DWORD pid;
  ::GetWindowThreadProcessId(foregroundWnd, &pid);
  return pid == ::GetCurrentProcessId();
}
#  endif
#endif

// static
void OSKInputPaneManager::ShowOnScreenKeyboard(HWND aWnd) {
#ifndef __MINGW32__
  ComPtr inputPane2 = GetInputPane(aWnd);
  if (!inputPane2) {
    return;
  }
  boolean result;
  inputPane2->TryShow(&result);
  NS_WARNING_ASSERTION(
      result || !IsForegroundApp() || IsInputPaneVisible(inputPane2),
      "IInputPane2::TryShow is failure");
#endif
}

// static
void OSKInputPaneManager::DismissOnScreenKeyboard(HWND aWnd) {
#ifndef __MINGW32__
  ComPtr inputPane2 = GetInputPane(aWnd);
  if (!inputPane2) {
    return;
  }
  boolean result;
  inputPane2->TryHide(&result);
  NS_WARNING_ASSERTION(
      result || !IsForegroundApp() || !IsInputPaneVisible(inputPane2),
      "IInputPane2::TryHide is failure");
#endif
}

}  // namespace widget
}  // namespace mozilla