File: contents_layout_manager.cc

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • 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 (134 lines) | stat: -rw-r--r-- 5,201 bytes parent folder | download | duplicates (3)
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
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/views/frame/contents_layout_manager.h"

#include "base/check.h"
#include "ui/views/view.h"

constexpr int kNewTabFooterSeparatorHeight = 1;
constexpr int kNewTabFooterHeight = 56;

ContentsLayoutManager::ContentsLayoutManager(
    views::View* devtools_view,
    views::View* devtools_scrim_view,
    views::View* contents_view,
    views::View* lens_overlay_view,
    views::View* scrim_view,
    views::View* border_view,
    views::View* watermark_view,
    views::View* new_tab_footer_view_separator,
    views::View* new_tab_footer_view)
    : devtools_view_(devtools_view),
      devtools_scrim_view_(devtools_scrim_view),
      contents_view_(contents_view),
      lens_overlay_view_(lens_overlay_view),
      scrim_view_(scrim_view),
      border_view_(border_view),
      watermark_view_(watermark_view),
      new_tab_footer_view_separator_(new_tab_footer_view_separator),
      new_tab_footer_view_(new_tab_footer_view) {}

ContentsLayoutManager::~ContentsLayoutManager() = default;

void ContentsLayoutManager::SetContentsResizingStrategy(
    const DevToolsContentsResizingStrategy& strategy) {
  if (strategy_.Equals(strategy)) {
    return;
  }

  strategy_.CopyFrom(strategy);
  InvalidateHost(true);
}

views::ProposedLayout ContentsLayoutManager::CalculateProposedLayout(
    const views::SizeBounds& size_bounds) const {
  views::ProposedLayout layouts;

  // If the |size_bounds| isn't bounded, the preferred size is being requested.
  if (!size_bounds.is_fully_bounded()) {
    return layouts;
  }
  int height = size_bounds.height().value();
  int width = size_bounds.width().value();

  gfx::Size container_size(width, height);
  gfx::Rect new_devtools_bounds;
  gfx::Rect new_contents_bounds;
  gfx::Size devtools_and_content_size = container_size;

  if (new_tab_footer_view_ && new_tab_footer_view_->GetVisible()) {
    const int footer_total_height =
        kNewTabFooterHeight + kNewTabFooterSeparatorHeight;
    devtools_and_content_size.set_height(devtools_and_content_size.height() -
                                         footer_total_height);

    layouts.child_layouts.emplace_back(
        new_tab_footer_view_separator_.get(),
        new_tab_footer_view_separator_->GetVisible(),
        gfx::Rect(0, devtools_and_content_size.height(), container_size.width(),
                  kNewTabFooterSeparatorHeight),
        views::SizeBounds(container_size));

    layouts.child_layouts.emplace_back(
        new_tab_footer_view_.get(), new_tab_footer_view_->GetVisible(),
        gfx::Rect(
            0,
            devtools_and_content_size.height() + kNewTabFooterSeparatorHeight,
            container_size.width(), kNewTabFooterHeight),
        views::SizeBounds(container_size));
  }

  ApplyDevToolsContentsResizingStrategy(strategy_, devtools_and_content_size,
                                        &new_devtools_bounds,
                                        &new_contents_bounds);

  // DevTools cares about the specific position, so we have to compensate RTL
  // layout here.
  layouts.child_layouts.emplace_back(
      devtools_view_.get(), devtools_view_->GetVisible(),
      host_view()->GetMirroredRect(new_devtools_bounds),
      views::SizeBounds(container_size));
  layouts.child_layouts.emplace_back(
      devtools_scrim_view_.get(), devtools_scrim_view_->GetVisible(),
      host_view()->GetMirroredRect(new_devtools_bounds),
      views::SizeBounds(container_size));

  const auto& contents_rect = host_view()->GetMirroredRect(new_contents_bounds);
  views::SizeBounds optional_size_bound = views::SizeBounds(container_size);
  layouts.child_layouts.emplace_back(contents_view_.get(),
                                     contents_view_->GetVisible(),
                                     contents_rect, optional_size_bound);

  // The scrim view bounds are the same as the contents view.
  CHECK(scrim_view_);
  layouts.child_layouts.emplace_back(scrim_view_.get(),
                                     scrim_view_->GetVisible(), contents_rect,
                                     optional_size_bound);

  // The Lens overlay view bounds are the same as the contents view.
  CHECK(lens_overlay_view_);
  layouts.child_layouts.emplace_back(lens_overlay_view_.get(),
                                     lens_overlay_view_->GetVisible(),
                                     contents_rect, optional_size_bound);

  if (border_view_) {
    layouts.child_layouts.push_back(
        {.child_view = border_view_.get(),
         .visible = border_view_->GetVisible(),
         // The border shares the same bounds with the ContentWebView.
         .bounds = contents_rect,
         .available_size = optional_size_bound});
  }

  // Enterprise watermark view is always overlaid, even when empty.
  if (watermark_view_) {
    layouts.child_layouts.emplace_back(
        watermark_view_.get(), watermark_view_->GetVisible(),
        gfx::Rect(0, 0, width, height), views::SizeBounds(container_size));
  }

  layouts.host_size = gfx::Size(width, height);
  return layouts;
}