File: frame_background.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (137 lines) | stat: -rw-r--r-- 4,906 bytes parent folder | download | duplicates (6)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright 2012 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_VIEWS_WINDOW_FRAME_BACKGROUND_H_
#define UI_VIEWS_WINDOW_FRAME_BACKGROUND_H_

#include "base/memory/raw_ptr.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/views/views_export.h"

namespace gfx {
class Canvas;
}

namespace ui {
class ColorProvider;
class NativeTheme;
}  // namespace ui

namespace views {

class View;

// FrameBackground handles painting for all the various window frames we
// support in Chrome. It intends to consolidate paint code that historically
// was copied. One frame to rule them all!
class VIEWS_EXPORT FrameBackground {
 public:
  FrameBackground();

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

  ~FrameBackground();

  // Sets the color to draw under the frame images.
  void set_frame_color(SkColor color) { frame_color_ = color; }

  void set_use_custom_frame(bool use_custom_frame) {
    use_custom_frame_ = use_custom_frame;
  }

  // Sets whether the frame to be drawn should have focus.
  void set_is_active(bool is_active) { is_active_ = is_active; }

  // Sets the theme image for the top of the window.  May be null (empty).
  // Memory is owned by the caller.
  void set_theme_image(const gfx::ImageSkia& image) { theme_image_ = image; }

  // Sets an inset into the theme image to begin painting at. This must be
  // further modified by the origin of the frame.
  void set_theme_image_inset(gfx::Point theme_image_inset) {
    theme_image_inset_ = theme_image_inset;
  }

  // Sets an image that overlays the top window image.  Usually used to add
  // edge highlighting to provide the illusion of depth.  May be null (empty).
  // Memory is owned by the caller.
  void set_theme_overlay_image(const gfx::ImageSkia& image) {
    theme_overlay_image_ = image;
  }

  // Sets the height of the top area to fill with the default frame color,
  // which must extend behind the tab strip.
  void set_top_area_height(int height) { top_area_height_ = height; }

  // Vertical inset for theme image when drawing maximized.
  void set_maximized_top_inset(int inset) { maximized_top_inset_ = inset; }

  // Sets images used when drawing the sides of the frame.
  // Caller owns the memory.
  void SetSideImages(const gfx::ImageSkia* left,
                     const gfx::ImageSkia* top,
                     const gfx::ImageSkia* right,
                     const gfx::ImageSkia* bottom);

  // Sets images used when drawing the corners of the frame.
  // Caller owns the memory.
  void SetCornerImages(const gfx::ImageSkia* top_left,
                       const gfx::ImageSkia* top_right,
                       const gfx::ImageSkia* bottom_left,
                       const gfx::ImageSkia* bottom_right);

  // Paints the border for a standard, non-maximized window.  Also paints the
  // background of the title bar area, since the top frame border and the
  // title bar background are a contiguous component.
  void PaintRestored(gfx::Canvas* canvas, const View* view) const;

  // Paints the border for a maximized window, which does not include the
  // window edges.
  void PaintMaximized(gfx::Canvas* canvas, const View* view) const;

  void PaintMaximized(gfx::Canvas* canvas,
                      const ui::NativeTheme* native_theme,
                      const ui::ColorProvider* color_provider,
                      int x,
                      int y,
                      int width) const;

  // Fills the frame side and bottom borders with the frame color.
  void FillFrameBorders(gfx::Canvas* canvas,
                        const View* view,
                        int left_edge_width,
                        int right_edge_width,
                        int bottom_edge_height) const;

 private:
  SkColor frame_color_ = 0;
  bool use_custom_frame_ = true;
  bool is_active_ = true;
  gfx::ImageSkia theme_image_;
  gfx::Point theme_image_inset_;
  gfx::ImageSkia theme_overlay_image_;
  int top_area_height_ = 0;

  // Images for the sides of the frame.
  raw_ptr<const gfx::ImageSkia> left_edge_ = nullptr;
  raw_ptr<const gfx::ImageSkia> top_edge_ = nullptr;
  raw_ptr<const gfx::ImageSkia> right_edge_ = nullptr;
  raw_ptr<const gfx::ImageSkia> bottom_edge_ = nullptr;

  // Images for the corners of the frame.
  raw_ptr<const gfx::ImageSkia> top_left_corner_ = nullptr;
  raw_ptr<const gfx::ImageSkia> top_right_corner_ = nullptr;
  raw_ptr<const gfx::ImageSkia> bottom_left_corner_ = nullptr;
  raw_ptr<const gfx::ImageSkia> bottom_right_corner_ = nullptr;

  // Vertical inset for theme image when drawing maximized.
  int maximized_top_inset_ = 0;
};

}  // namespace views

#endif  // UI_VIEWS_WINDOW_FRAME_BACKGROUND_H_