File: browser_view_layout.h

package info (click to toggle)
chromium 140.0.7339.127-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,201,772 kB
  • sloc: cpp: 35,093,800; ansic: 7,161,670; javascript: 4,199,694; python: 1,441,798; asm: 949,904; xml: 747,503; pascal: 187,748; perl: 88,691; sh: 88,248; objc: 79,953; sql: 52,714; cs: 44,599; fortran: 24,137; makefile: 22,119; tcl: 15,277; php: 13,980; yacc: 9,000; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (217 lines) | stat: -rw-r--r-- 9,195 bytes parent folder | download | duplicates (5)
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// 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 CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_VIEW_LAYOUT_H_
#define CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_VIEW_LAYOUT_H_

#include <memory>

#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/layout/layout_manager.h"

class BookmarkBarView;
class BrowserView;
class BrowserViewLayoutDelegate;
class InfoBarContainerView;
class MultiContentsView;
class TabStrip;
class TabStripRegionView;
class WebAppFrameToolbarView;

namespace views {
class View;
class Label;
class Widget;
}  // namespace views

namespace web_modal {
class WebContentsModalDialogHost;
}

// The layout manager used in chrome browser.
class BrowserViewLayout : public views::LayoutManager {
 public:
  // The minimum width for the normal (tabbed or web app) browser window's
  // contents area. This should be wide enough that WebUI pages (e.g.
  // chrome://settings) and the various associated WebUI dialogs (e.g. Import
  // Bookmarks) can still be functional. This value provides a trade-off between
  // browser usability and privacy - specifically, the ability to browse in a
  // very small window, even on large monitors (which is why a minimum height is
  // not specified). This value is used for the main browser window only, not
  // for popups.
  static constexpr int kMainBrowserContentsMinimumWidth = 500;

  // |browser_view| may be null in tests.
  BrowserViewLayout(std::unique_ptr<BrowserViewLayoutDelegate> delegate,
                    BrowserView* browser_view,
                    views::View* window_scrim,
                    views::View* top_container,
                    WebAppFrameToolbarView* web_app_frame_toolbar,
                    views::Label* web_app_window_title,
                    TabStripRegionView* tab_strip_region_view,
                    TabStrip* tab_strip,
                    views::View* toolbar,
                    InfoBarContainerView* infobar_container,
                    views::View* contents_container,
                    MultiContentsView* multi_contents_view,
                    views::View* vertical_tab_strip_container,
                    views::View* left_aligned_side_panel_separator,
                    views::View* unified_side_panel,
                    views::View* right_aligned_side_panel_separator,
                    views::View* side_panel_rounded_corner,
                    views::View* contents_separator);

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

  ~BrowserViewLayout() override;

  // Sets or updates views that are not available when |this| is initialized.
  void set_tab_strip(TabStrip* tab_strip) { tab_strip_ = tab_strip; }
  void set_webui_tab_strip(views::View* webui_tab_strip) {
    webui_tab_strip_ = webui_tab_strip;
  }
  void set_loading_bar(views::View* loading_bar) { loading_bar_ = loading_bar; }
  void set_bookmark_bar(BookmarkBarView* bookmark_bar) {
    bookmark_bar_ = bookmark_bar;
  }
  void set_contents_border_widget(views::Widget* contents_border_widget) {
    contents_border_widget_ = contents_border_widget;
  }
  views::Widget* contents_border_widget() { return contents_border_widget_; }

  void SetUseBrowserContentMinimumSize(bool use_browser_content_minimum_size);

  // Sets the bounds for the contents border.
  // * If nullopt, no specific bounds are set, and the border will be drawn
  //   around the entire contents area.
  // * Otherwise, the blue border will be drawn around the indicated Rect,
  //   which is in View coordinates.
  // Note that *whether* the border is drawn is an orthogonal issue;
  // this function only controls where it's drawn when it is in fact drawn.
  void SetContentBorderBounds(
      const std::optional<gfx::Rect>& region_capture_rect);

  web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost();

  // views::LayoutManager overrides:
  void Layout(views::View* host) override;
  gfx::Size GetMinimumSize(const views::View* host) const override;
  gfx::Size GetPreferredSize(
      const views::View* host,
      const views::SizeBounds& available_size) const override;
  gfx::Size GetPreferredSize(const views::View* host) const override;
  std::vector<raw_ptr<views::View, VectorExperimental>>
  GetChildViewsInPaintOrder(const views::View* host) const override;

  // Returns the minimum acceptable width for the browser web contents.
  int GetMinWebContentsWidthForTesting() const;

  // Returns true if an infobar is showing.
  bool IsInfobarVisible() const;

 private:
  FRIEND_TEST_ALL_PREFIXES(BrowserViewLayoutTest, BrowserViewLayout);
  FRIEND_TEST_ALL_PREFIXES(BrowserViewLayoutTest, Layout);
  class WebContentsModalDialogHostViews;

  // Layout the following controls, updating `available_bounds` to leave the
  // remaining space available for future controls.
  void LayoutTitleBarForWebApp(gfx::Rect& available_bounds);
  void LayoutVerticalTabStrip(gfx::Rect& available_bounds);
  void LayoutTabStripRegion(gfx::Rect& available_bounds);
  void LayoutWebUITabStrip(gfx::Rect& available_bounds);
  void LayoutToolbar(gfx::Rect& available_bounds);
  void LayoutBookmarkAndInfoBars(gfx::Rect& available_bounds,
                                 int browser_view_y);
  void LayoutBookmarkBar(gfx::Rect& available_bounds);
  void LayoutInfoBar(gfx::Rect& available_bounds);

  // Helper struct and function for LayoutContentsContainerView that calculates
  // bounds for `contents_container_` and `unified_side_panel_`.
  struct ContentsContainerLayoutResult;
  ContentsContainerLayoutResult CalculateContentsContainerLayout(
      const gfx::Rect& available_bounds) const;

  // Layout the `contents_container_` within the available bounds.
  // See browser_view.h for details of the relationship between
  // `contents_container_` and other views. Also lays out `unified_side_panel_`.
  void LayoutContentsContainerView(const gfx::Rect& available_bounds);

  // Updates `top_container_`'s bounds. The new bounds depend on the size of
  // the bookmark bar and the toolbar.
  void UpdateTopContainerBounds(const gfx::Rect& available_bounds);

  // Layout the contents border, which indicates the tab is being captured.
  void LayoutContentBorder();

  // Returns the minimum acceptable width for the browser web contents. If split
  // view is active, this includes the full split view.
  int GetMinWebContentsWidth() const;

  void UpdateSplitViewInsets();

  // The delegate interface. May be a mock in tests.
  const std::unique_ptr<BrowserViewLayoutDelegate> delegate_;

  // The owning browser view.
  const raw_ptr<BrowserView> browser_view_;

  // Child views that the layout manager manages.
  // NOTE: If you add a view, try to add it as a views::View, which makes
  // testing much easier.
  const raw_ptr<views::View> window_scrim_;
  const raw_ptr<views::View> top_container_;
  const raw_ptr<WebAppFrameToolbarView> web_app_frame_toolbar_;
  const raw_ptr<views::Label> web_app_window_title_;
  const raw_ptr<TabStripRegionView> tab_strip_region_view_;
  const raw_ptr<views::View> toolbar_;
  const raw_ptr<InfoBarContainerView> infobar_container_;
  const raw_ptr<views::View> contents_container_;
  const raw_ptr<MultiContentsView> multi_contents_view_;
  const raw_ptr<views::View> vertical_tab_strip_container_;
  const raw_ptr<views::View> left_aligned_side_panel_separator_;
  const raw_ptr<views::View> unified_side_panel_;
  const raw_ptr<views::View> right_aligned_side_panel_separator_;
  const raw_ptr<views::View> side_panel_rounded_corner_;
  const raw_ptr<views::View> contents_separator_;

  // These views are dynamically set.
  raw_ptr<views::View> webui_tab_strip_ = nullptr;
  raw_ptr<views::View> loading_bar_ = nullptr;
  raw_ptr<TabStrip> tab_strip_ = nullptr;
  raw_ptr<BookmarkBarView> bookmark_bar_ = nullptr;

  // The widget displaying a border on top of contents container for
  // highlighting the content. Not created by default.
  // TODO(crbug.com/393551539): reset the pointer at appropriate time and
  // remove the DanglingUntriaged tag.
  raw_ptr<views::Widget, DanglingUntriaged> contents_border_widget_ = nullptr;

  // The host for use in positioning the web contents modal dialog.
  std::unique_ptr<WebContentsModalDialogHostViews> dialog_host_;

  // The latest dialog bounds applied during a layout pass.
  gfx::Rect latest_dialog_bounds_in_screen_;

  // The latest contents bounds applied during a layout pass, in screen
  // coordinates.
  gfx::Rect latest_contents_bounds_;

  // Directly tied to SetContentBorderBounds() - more details there.
  std::optional<gfx::Rect> dynamic_content_border_bounds_;

  // The distance the web contents modal dialog is from the top of the dialog
  // host widget.
  int dialog_top_y_ = -1;

  // Whether or not to use the browser based content minimum size.
  bool use_browser_content_minimum_size_ = false;
};

#endif  // CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_VIEW_LAYOUT_H_