void NativeWindowMac::SetVibrancy()

in shell/browser/native_window_mac.mm [1387:1487]


void NativeWindowMac::SetVibrancy(const std::string& type) {
  NSVisualEffectView* vibrantView = [window_ vibrantView];

  if (type.empty()) {
    if (vibrantView == nil)
      return;

    [vibrantView removeFromSuperview];
    [window_ setVibrantView:nil];

    return;
  }

  std::string dep_warn = " has been deprecated and removed as of macOS 10.15.";
  node::Environment* env =
      node::Environment::GetCurrent(JavascriptEnvironment::GetIsolate());

  NSVisualEffectMaterial vibrancyType{};
  if (type == "appearance-based") {
    EmitWarning(env, "NSVisualEffectMaterialAppearanceBased" + dep_warn,
                "electron");
    vibrancyType = NSVisualEffectMaterialAppearanceBased;
  } else if (type == "light") {
    EmitWarning(env, "NSVisualEffectMaterialLight" + dep_warn, "electron");
    vibrancyType = NSVisualEffectMaterialLight;
  } else if (type == "dark") {
    EmitWarning(env, "NSVisualEffectMaterialDark" + dep_warn, "electron");
    vibrancyType = NSVisualEffectMaterialDark;
  } else if (type == "titlebar") {
    vibrancyType = NSVisualEffectMaterialTitlebar;
  }

  if (type == "selection") {
    vibrancyType = NSVisualEffectMaterialSelection;
  } else if (type == "menu") {
    vibrancyType = NSVisualEffectMaterialMenu;
  } else if (type == "popover") {
    vibrancyType = NSVisualEffectMaterialPopover;
  } else if (type == "sidebar") {
    vibrancyType = NSVisualEffectMaterialSidebar;
  } else if (type == "medium-light") {
    EmitWarning(env, "NSVisualEffectMaterialMediumLight" + dep_warn,
                "electron");
    vibrancyType = NSVisualEffectMaterialMediumLight;
  } else if (type == "ultra-dark") {
    EmitWarning(env, "NSVisualEffectMaterialUltraDark" + dep_warn, "electron");
    vibrancyType = NSVisualEffectMaterialUltraDark;
  }

  if (@available(macOS 10.14, *)) {
    if (type == "header") {
      vibrancyType = NSVisualEffectMaterialHeaderView;
    } else if (type == "sheet") {
      vibrancyType = NSVisualEffectMaterialSheet;
    } else if (type == "window") {
      vibrancyType = NSVisualEffectMaterialWindowBackground;
    } else if (type == "hud") {
      vibrancyType = NSVisualEffectMaterialHUDWindow;
    } else if (type == "fullscreen-ui") {
      vibrancyType = NSVisualEffectMaterialFullScreenUI;
    } else if (type == "tooltip") {
      vibrancyType = NSVisualEffectMaterialToolTip;
    } else if (type == "content") {
      vibrancyType = NSVisualEffectMaterialContentBackground;
    } else if (type == "under-window") {
      vibrancyType = NSVisualEffectMaterialUnderWindowBackground;
    } else if (type == "under-page") {
      vibrancyType = NSVisualEffectMaterialUnderPageBackground;
    }
  }

  if (vibrancyType) {
    vibrancy_type_ = type;

    if (vibrantView == nil) {
      vibrantView = [[[NSVisualEffectView alloc]
          initWithFrame:[[window_ contentView] bounds]] autorelease];
      [window_ setVibrantView:vibrantView];

      [vibrantView
          setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
      [vibrantView setBlendingMode:NSVisualEffectBlendingModeBehindWindow];

      if (visual_effect_state_ == VisualEffectState::kActive) {
        [vibrantView setState:NSVisualEffectStateActive];
      } else if (visual_effect_state_ == VisualEffectState::kInactive) {
        [vibrantView setState:NSVisualEffectStateInactive];
      } else {
        [vibrantView setState:NSVisualEffectStateFollowsWindowActiveState];
      }

      [[window_ contentView] addSubview:vibrantView
                             positioned:NSWindowBelow
                             relativeTo:nil];

      UpdateVibrancyRadii(IsFullscreen());
    }

    [vibrantView setMaterial:vibrancyType];
  }
}