File: window_frame_provider_gtk.h

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; 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 (85 lines) | stat: -rw-r--r-- 2,652 bytes parent folder | download | duplicates (4)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_GTK_WINDOW_FRAME_PROVIDER_GTK_H_
#define UI_GTK_WINDOW_FRAME_PROVIDER_GTK_H_

#include <optional>

#include "base/containers/flat_map.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/glib/scoped_gsignal.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/linux/window_frame_provider.h"

typedef struct _GtkParamSpec GtkParamSpec;
typedef struct _GtkSettings GtkSettings;

namespace gtk {

class WindowFrameProviderGtk : public ui::WindowFrameProvider {
 public:
  WindowFrameProviderGtk(bool solid_frame, bool tiled, bool maximized);

  WindowFrameProviderGtk(const WindowFrameProviderGtk&) = delete;
  WindowFrameProviderGtk& operator=(const WindowFrameProviderGtk&) = delete;

  ~WindowFrameProviderGtk() override;

  // ui::WindowFrameProvider:
  int GetTopCornerRadiusDip() override;
  bool IsTopFrameTranslucent() override;
  gfx::Insets GetFrameThicknessDip() override;
  void PaintWindowFrame(gfx::Canvas* canvas,
                        const gfx::Rect& rect,
                        int top_area_height,
                        bool focused,
                        const gfx::Insets& input_insets) override;

 private:
  // Data and metrics that depend on the scale.
  struct Asset {
    Asset();
    Asset(const Asset&);
    Asset& operator=(const Asset&);
    ~Asset();

    int frame_size_px = 0;

    // These are texture maps that we will sample from to draw the frame.  The
    // corners are drawn directly and the edges are tiled.
    SkBitmap focused_bitmap;
    SkBitmap unfocused_bitmap;
  };

  // Paint the window frame and update any metrics (like the frame thickness)
  // based on it.  Bitmaps and metrics are cached in |assets_|, so this is a
  // no-op if there is a cache entry created earlier.
  Asset& GetOrCreateAsset(float scale);

  int BitmapSizePx(const Asset& asset) const;

  void OnThemeChanged(GtkSettings* settings, GtkParamSpec* param);

  // Input parameters used for drawing.
  const bool solid_frame_;
  const bool tiled_;
  const bool maximized_;

  // Scale-independent metric calculated based on the bitmaps.
  std::optional<gfx::Insets> frame_thickness_dip_;
  std::optional<int> top_corner_radius_dip_;
  std::optional<bool> top_frame_is_translucent_;

  // Cached bitmaps and metrics.
  base::flat_map<float, Asset> assets_;

  // These signals invalidate the cache on change.
  ScopedGSignal theme_name_signal_;
  ScopedGSignal prefer_dark_signal_;
};

}  // namespace gtk

#endif  // UI_GTK_WINDOW_FRAME_PROVIDER_GTK_H_