File: menu_controller_cocoa_delegate_params.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (45 lines) | stat: -rw-r--r-- 1,907 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/views/controls/menu/menu_controller_cocoa_delegate_params.h"

#include "base/numerics/safe_conversions.h"
#include "components/remote_cocoa/common/menu.mojom.h"
#include "ui/color/color_provider.h"
#include "ui/views/badge_painter.h"
#include "ui/views/controls/menu/menu_config.h"
#include "ui/views/layout/layout_provider.h"
#include "ui/views/widget/widget.h"

namespace views {

remote_cocoa::mojom::MenuControllerParamsPtr MenuControllerParamsForWidget(
    Widget* widget) {
  auto* color_provider = widget->GetColorProvider();
  auto params = remote_cocoa::mojom::MenuControllerParams::New();

  // The preferred font is slightly smaller and slightly more bold than the
  // menu font. The size change is required to make it look correct in the
  // badge; we add a small degree of bold to prevent color smearing/blurring
  // due to font smoothing. This ensures readability on all platforms and in
  // both light and dark modes.
  params->badge_font =
      BadgePainter::GetBadgeFont(MenuConfig::instance().font_list)
          .GetPrimaryFont();
  params->badge_color =
      color_provider->GetColor(ui::kColorBadgeInCocoaMenuBackground);
  params->badge_text_color =
      color_provider->GetColor(ui::kColorBadgeInCocoaMenuForeground);
  params->badge_horizontal_margin = BadgePainter::kBadgeHorizontalMargin;
  params->badge_internal_padding = BadgePainter::kBadgeInternalPadding;
  params->badge_min_height = BadgePainter::kBadgeMinHeightCocoa;
  params->badge_radius =
      base::checked_cast<uint32_t>(LayoutProvider::Get()->GetCornerRadiusMetric(
          ShapeContextTokens::kBadgeRadius));
  params->iph_dot_color =
      color_provider->GetColor(ui::kColorButtonBackgroundProminent);
  return params;
}

}  // namespace views