File: tab_strip_region_view.h

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 (162 lines) | stat: -rw-r--r-- 6,415 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
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
// Copyright 2019 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_TAB_STRIP_REGION_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_FRAME_TAB_STRIP_REGION_VIEW_H_

#include "base/memory/raw_ptr.h"
#include "chrome/browser/ui/views/tabs/tab_search_container.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/pointer/touch_ui_controller.h"
#include "ui/views/accessible_pane_view.h"

namespace glic {
class GlicButton;
}
namespace views {
class Button;
}
class NewTabButton;
class TabStripActionContainer;
class TabSearchButton;
class TabStrip;
class TabStripComboButton;
class TabStripScrollContainer;
class ProductSpecificationsButton;
class TabSearchPositionMetricsLogger;

// Container for the tabstrip and the other views sharing space with it -
// with the exception of the caption buttons.
class TabStripRegionView final : public views::AccessiblePaneView {
  METADATA_HEADER(TabStripRegionView, views::AccessiblePaneView)

 public:
  // These values are persisted to logs. Entries should not be renumbered and
  // numeric values should never be reused.
  //
  // LINT.IfChange(TabSearchPositionEnum)
  enum class TabSearchPositionEnum {
    kLeading = 0,
    kTrailing = 1,
    kMaxValue = kTrailing,
  };
  // LINT.ThenChange(//tools/metrics/histograms/metadata/tab/enums.xml:TabSearchPosition)

  explicit TabStripRegionView(std::unique_ptr<TabStrip> tab_strip);
  TabStripRegionView(const TabStripRegionView&) = delete;
  TabStripRegionView& operator=(const TabStripRegionView&) = delete;
  ~TabStripRegionView() override;

  // Returns true if the specified rect intersects the window caption area of
  // the browser window. |rect| is in the local coordinate space
  // of |this|.
  bool IsRectInWindowCaption(const gfx::Rect& rect);

  // A convenience function which calls |IsRectInWindowCaption()| with a rect of
  // size 1x1 and an origin of |point|. |point| is in the local coordinate space
  // of |this|.
  bool IsPositionInWindowCaption(const gfx::Point& point);

  views::Button* GetNewTabButton();

  TabSearchButton* GetTabSearchButton();

  TabStripActionContainer* GetTabStripActionContainer();

  TabStripComboButton* tab_strip_combo_button() {
    return tab_strip_combo_button_;
  }

  ProductSpecificationsButton* GetProductSpecificationsButton();

  glic::GlicButton* GetGlicButton();

  // May be nullptr if combo button is enabled. |Use GetNewTabButton()| to
  // access the new tab button inside the combo button.
  views::Button* new_tab_button_for_testing() { return new_tab_button_; }

  // May be nullptr if combo button is enabled.
  TabSearchContainer* tab_search_container_for_testing() {
    return tab_search_container_;
  }

  views::View* reserved_grab_handle_space_for_testing() {
    return reserved_grab_handle_space_;
  }

  // views::View:
  // The TabSearchButton and NewTabButton may need to be rendered above the
  // TabStrip, but FlexLayout needs the children to be stored in the correct
  // order in the view.
  views::View::Views GetChildrenInZOrder() override;

  // Calls the parent Layout, but in some cases may also need to manually
  // position the TabSearchButton to layer over the TabStrip.
  void Layout(PassKey) override;

  // These system drag & drop methods forward the events to TabDragController to
  // support its fallback tab dragging mode in the case where the platform
  // can't support the usual run loop based mode.
  // We need to handle this here instead of in TabStrip, because TabStrip's
  // bounds don't contain the empty space to the right of the last tab.
  bool CanDrop(const OSExchangeData& data) override;
  bool GetDropFormats(int* formats,
                      std::set<ui::ClipboardFormatType>* format_types) override;
  void OnDragEntered(const ui::DropTargetEvent& event) override;
  int OnDragUpdated(const ui::DropTargetEvent& event) override;
  void OnDragExited() override;
  // We don't override GetDropCallback() because we don't actually want to
  // transfer any data.

  // views::AccessiblePaneView:
  void ChildPreferredSizeChanged(views::View* child) override;
  gfx::Size GetMinimumSize() const override;
  views::View* GetDefaultFocusableChild() override;

  views::View* GetTabStripContainerForTesting() { return tab_strip_container_; }

  const Profile* profile() { return profile_; }

 private:
  // Updates the border padding for `new_tab_button_` and
  // `tab_search_container_`, if present.  This should be called whenever any
  // input of the computation of the border's sizing changes.
  void UpdateButtonBorders();

  // Updates the left and right margins for the tab strip. This should be
  // called whenever `tab_search_container_` changes size, if
  // `render_tab_search_before_tab_strip_` is true.
  void UpdateTabStripMargin();

  // Gets called on `Layout` and adjusts the x-axis position of the `view` based
  // on `offset`. This should only used for views that show before tab strip.
  void AdjustViewBoundsRect(View* view, int offset);

  raw_ptr<const Profile> profile_ = nullptr;
  raw_ptr<TabStripActionContainer> tab_strip_action_container_ = nullptr;
  raw_ptr<views::View> tab_strip_container_ = nullptr;
  raw_ptr<views::View> reserved_grab_handle_space_ = nullptr;
  raw_ptr<TabStrip> tab_strip_ = nullptr;
  raw_ptr<TabStripScrollContainer> tab_strip_scroll_container_ = nullptr;
  raw_ptr<views::Button> new_tab_button_ = nullptr;
  raw_ptr<TabSearchContainer> tab_search_container_ = nullptr;
  raw_ptr<TabStripComboButton> tab_strip_combo_button_ = nullptr;
  raw_ptr<ProductSpecificationsButton> product_specifications_button_ = nullptr;

  // On some platforms for Chrome Refresh, the TabSearchButton should be
  // laid out before the TabStrip. Storing this configuration prevents
  // rechecking the child order on every layout.
  const bool render_tab_search_before_tab_strip_;

  std::unique_ptr<TabSearchPositionMetricsLogger>
      tab_search_position_metrics_logger_;

  const base::CallbackListSubscription subscription_ =
      ui::TouchUiController::Get()->RegisterCallback(
          base::BindRepeating(&TabStripRegionView::UpdateButtonBorders,
                              base::Unretained(this)));
};

#endif  // CHROME_BROWSER_UI_VIEWS_FRAME_TAB_STRIP_REGION_VIEW_H_