summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/frame/viewport_data.h
blob: e3f539089eac48ba0a135d6d7406e2babf7bc3ae (plain)
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
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_VIEWPORT_DATA_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_VIEWPORT_DATA_H_

#include "third_party/blink/public/mojom/page/display_cutout.mojom-blink.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/page/viewport_description.h"
#include "third_party/blink/renderer/platform/heap/handle.h"

namespace blink {

class Document;

class ViewportData : public GarbageCollectedFinalized<ViewportData> {
 public:
  ViewportData(Document& document);
  void Trace(Visitor* visitor);
  void Shutdown();

  bool ShouldMergeWithLegacyDescription(ViewportDescription::Type) const;
  bool ShouldOverrideLegacyDescription(ViewportDescription::Type) const;
  CORE_EXPORT void SetViewportDescription(const ViewportDescription&);
  CORE_EXPORT ViewportDescription GetViewportDescription() const;
  Length ViewportDefaultMinWidth() const { return viewport_default_min_width_; }

  void UpdateViewportDescription();

  // When true this will force a kCover viewport fit value which will result in
  // the document expanding into the display cutout area.
  CORE_EXPORT void SetExpandIntoDisplayCutout(bool expand);
  mojom::ViewportFit GetCurrentViewportFitForTests() const {
    return viewport_fit_;
  }

 private:
  Member<Document> document_;

  ViewportDescription viewport_description_;
  ViewportDescription legacy_viewport_description_;
  Length viewport_default_min_width_;

  // Stores the current value viewport-fit value.
  mojom::ViewportFit viewport_fit_ = blink::mojom::ViewportFit::kAuto;
  bool force_expand_display_cutout_ = false;

  mojom::blink::DisplayCutoutHostAssociatedPtr display_cutout_host_;
};

inline bool ViewportData::ShouldOverrideLegacyDescription(
    ViewportDescription::Type origin) const {
  // The different (legacy) meta tags have different priorities based on the
  // type regardless of which order they appear in the DOM. The priority is
  // given by the ViewportDescription::Type enum.
  return origin >= legacy_viewport_description_.type;
}

}  // namespace blink
#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_VIEWPORT_DATA_H_