File: safe_area_insets_host.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 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 (88 lines) | stat: -rw-r--r-- 3,734 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
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_DISPLAY_CUTOUT_SAFE_AREA_INSETS_HOST_H_
#define CONTENT_BROWSER_DISPLAY_CUTOUT_SAFE_AREA_INSETS_HOST_H_

#include "content/common/content_export.h"
#include "content/public/browser/render_frame_host_receiver_set.h"
#include "third_party/blink/public/mojom/page/display_cutout.mojom.h"
#include "ui/gfx/geometry/insets.h"

namespace content {

class RenderFrameHost;
class WebContentsImpl;

// Handles the connection between Blink and the browser / embedder for
// safe area insets.
// This is a `WebContents` scoped abstract base class for a Host that
// handles Safe Area Insets such
// as the Notch (Display Cutout) and the Android Edge To Edge feature.
// The implementation within this class handles communication with Blink.
// The viewport-fit metadata from a page is sent by Blink to
// the embedder through
// `NotifyViewportFitChanged`. When that triggers a change to the Safe
// Area, e.g. a `viewport-fit=cover` to allow drawing under the Notch, the
// embedder responds to Blink through `SetSafeArea` to allow the CSS of
// the page to adjust its drawing appropriately for that Safe Area, e.g.
// pad a header to extend below the Notch.
class CONTENT_EXPORT SafeAreaInsetsHost
    : public blink::mojom::DisplayCutoutHost {
 public:
  static std::unique_ptr<SafeAreaInsetsHost> Create(WebContentsImpl*);

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

  ~SafeAreaInsetsHost() override;

  // Binds a new Blink receiver for the specified frame.
  void BindReceiver(
      mojo::PendingAssociatedReceiver<blink::mojom::DisplayCutoutHost> receiver,
      RenderFrameHost* rfh);

  // blink::mojom::DisplayCutoutHost interface.
  void NotifyViewportFitChanged(blink::mojom::ViewportFit value) final;
  void NotifyComplexSafeAreaConstraintChanged(bool value) final;

  // Called by WebContents when various events occur.
  virtual void DidAcquireFullscreen(RenderFrameHost* rfh) = 0;
  virtual void DidExitFullscreen() = 0;
  virtual void DidFinishNavigation(NavigationHandle* navigation_handle) = 0;
  virtual void RenderFrameDeleted(RenderFrameHost* rfh) = 0;
  virtual void RenderFrameCreated(RenderFrameHost* rfh) = 0;

  // Updates the safe area insets on the current frame.
  // Exposes `SendSafeAreaToFrame` to subclasses.
  virtual void SetDisplayCutoutSafeArea(gfx::Insets insets) = 0;

 protected:
  explicit SafeAreaInsetsHost(WebContentsImpl*);

  // Stores the updated viewport fit value for a `frame` and notifies observers
  // if it has changed. Called directly by Blink through Mojo.
  virtual void ViewportFitChangedForFrame(RenderFrameHost* rfh,
                                          blink::mojom::ViewportFit value) = 0;

  // Send the safe area insets to Blink through the given `RenderFrameHost`
  // through the blink::mojom::DisplayCutoutclient interface.
  // Protected and virtual for testing only.
  virtual void SendSafeAreaToFrame(RenderFrameHost* rfh, gfx::Insets insets);

  // Notified that the complex safe-area-inset constraint state changed.
  virtual void ComplexSafeAreaConstraintChangedForFrame(RenderFrameHost* rfh,
                                                        bool has_constraint) {}

  // Weak pointer to the owning `WebContentsImpl` instance.
  raw_ptr<WebContentsImpl> web_contents_impl_;

 private:
  // Holds WebContents associated mojo receivers.
  RenderFrameHostReceiverSet<blink::mojom::DisplayCutoutHost> receivers_;
};

}  // namespace content

#endif  // CONTENT_BROWSER_DISPLAY_CUTOUT_SAFE_AREA_INSETS_HOST_H_