#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include <algorithm>
#include <memory>
#include <utility>
#include "base/command_line.h"
#include "base/containers/fixed_flat_map.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/i18n/number_formatting.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "base/ranges/algorithm.h"
#include "base/strings/utf_string_conversions.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/apps/link_capturing/link_capturing_features.h"
#include "chrome/browser/command_updater.h"
#include "chrome/browser/companion/core/features.h"
#include "chrome/browser/download/bubble/download_bubble_prefs.h"
#include "chrome/browser/media/router/media_router_feature.h"
#include "chrome/browser/performance_manager/public/user_tuning/user_tuning_utils.h"
#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_command_controller.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h"
#include "chrome/browser/ui/browser_element_identifiers.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/browser_window/public/browser_window_features.h"
#include "chrome/browser/ui/color/chrome_color_id.h"
#include "chrome/browser/ui/global_error/global_error_service.h"
#include "chrome/browser/ui/global_error/global_error_service_factory.h"
#include "chrome/browser/ui/intent_picker_tab_helper.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/side_search/side_search_utils.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/toolbar/chrome_labs/chrome_labs_model.h"
#include "chrome/browser/ui/toolbar/chrome_labs/chrome_labs_prefs.h"
#include "chrome/browser/ui/toolbar/chrome_labs/chrome_labs_utils.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h"
#include "chrome/browser/ui/views/download/bubble/download_toolbar_button_view.h"
#include "chrome/browser/ui/views/enterprise/management_toolbar_button.h"
#include "chrome/browser/ui/views/extensions/extension_popup.h"
#include "chrome/browser/ui/views/extensions/extensions_toolbar_button.h"
#include "chrome/browser/ui/views/extensions/extensions_toolbar_container.h"
#include "chrome/browser/ui/views/extensions/extensions_toolbar_coordinator.h"
#include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/top_container_background.h"
#include "chrome/browser/ui/views/global_media_controls/media_toolbar_button_contextual_menu.h"
#include "chrome/browser/ui/views/global_media_controls/media_toolbar_button_view.h"
#include "chrome/browser/ui/views/location_bar/intent_chip_button.h"
#include "chrome/browser/ui/views/location_bar/star_view.h"
#include "chrome/browser/ui/views/media_router/cast_toolbar_button.h"
#include "chrome/browser/ui/views/page_action/page_action_icon_container.h"
#include "chrome/browser/ui/views/page_action/page_action_icon_controller.h"
#include "chrome/browser/ui/views/performance_controls/battery_saver_button.h"
#include "chrome/browser/ui/views/performance_controls/performance_intervention_button.h"
#include "chrome/browser/ui/views/send_tab_to_self/send_tab_to_self_toolbar_icon_view.h"
#include "chrome/browser/ui/views/side_panel/companion/companion_utils.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/browser/ui/views/toolbar/app_menu.h"
#include "chrome/browser/ui/views/toolbar/back_forward_button.h"
#include "chrome/browser/ui/views/toolbar/browser_app_menu_button.h"
#include "chrome/browser/ui/views/toolbar/chrome_labs/chrome_labs_button.h"
#include "chrome/browser/ui/views/toolbar/home_button.h"
#include "chrome/browser/ui/views/toolbar/pinned_toolbar_actions_container.h"
#include "chrome/browser/ui/views/toolbar/reload_button.h"
#include "chrome/browser/ui/views/toolbar/toolbar_button.h"
#include "chrome/browser/ui/views/toolbar/toolbar_controller.h"
#include "chrome/browser/ui/web_applications/app_browser_controller.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/branded_strings.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/omnibox/browser/omnibox_view.h"
#include "components/performance_manager/public/features.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/send_tab_to_self/features.h"
#include "components/signin/public/base/signin_buildflags.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "media/base/media_switches.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/theme_provider.h"
#include "ui/base/ui_base_features.h"
#include "ui/base/window_open_disposition.h"
#include "ui/base/window_open_disposition_utils.h"
#include "ui/color/color_id.h"
#include "ui/color/color_provider.h"
#include "ui/compositor/layer.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/canvas_image_source.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/scoped_canvas.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/background.h"
#include "ui/views/cascading_property.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/flex_layout.h"
#include "ui/views/layout/proposed_layout.h"
#include "ui/views/view_class_properties.h"
#include "ui/views/widget/tooltip_manager.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/non_client_view.h"
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
#include "chrome/browser/recovery/recovery_install_global_error_factory.h"
#endif
#if !BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ui/bookmarks/bookmark_bubble_sign_in_delegate.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chromeos/components/mgs/managed_guest_session_utils.h"
#endif
#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
#include "chrome/browser/ui/views/frame/webui_tab_strip_container_view.h"
#endif
#if defined(USE_AURA)
#include "ui/aura/window_occlusion_tracker.h"
#endif
UserMetricsAction;
WebContents;
DEFINE_UI_CLASS_PROPERTY_KEY(…)
namespace {
ToolbarView::DisplayMode GetDisplayMode(Browser* browser) { … }
auto& GetViewCommandMap() { … }
constexpr int kBrowserAppMenuRefreshExpandedMargin = …;
constexpr int kBrowserAppMenuRefreshCollapsedMargin = …;
class TabstripLikeBackground : public views::Background { … };
}
class ToolbarView::ContainerView : public views::View { … };
BEGIN_METADATA(…)
END_METADATA
ToolbarView::ToolbarView(Browser* browser, BrowserView* browser_view)
: … { … }
ToolbarView::~ToolbarView() { … }
void ToolbarView::Init() { … }
void ToolbarView::AnimationEnded(const gfx::Animation* animation) { … }
void ToolbarView::AnimationProgressed(const gfx::Animation* animation) { … }
void ToolbarView::Update(WebContents* tab) { … }
bool ToolbarView::UpdateSecurityState() { … }
void ToolbarView::SetToolbarVisibility(bool visible) { … }
void ToolbarView::UpdateCustomTabBarVisibility(bool visible, bool animate) { … }
void ToolbarView::UpdateForWebUITabStrip() { … }
void ToolbarView::ResetTabState(WebContents* tab) { … }
void ToolbarView::SetPaneFocusAndFocusAppMenu() { … }
bool ToolbarView::GetAppMenuFocused() const { … }
void ToolbarView::ShowIntentPickerBubble(
std::vector<IntentPickerBubbleView::AppInfo> app_info,
bool show_stay_in_chrome,
bool show_remember_selection,
IntentPickerBubbleView::BubbleType bubble_type,
const std::optional<url::Origin>& initiating_origin,
IntentPickerResponse callback) { … }
void ToolbarView::ShowBookmarkBubble(const GURL& url, bool already_bookmarked) { … }
views::Button* ToolbarView::GetChromeLabsButton() const { … }
ExtensionsToolbarButton* ToolbarView::GetExtensionsButton() const { … }
WebContents* ToolbarView::GetWebContents() { … }
LocationBarModel* ToolbarView::GetLocationBarModel() { … }
const LocationBarModel* ToolbarView::GetLocationBarModel() const { … }
ContentSettingBubbleModelDelegate*
ToolbarView::GetContentSettingBubbleModelDelegate() { … }
void ToolbarView::EnabledStateChangedForCommand(int id, bool enabled) { … }
bool ToolbarView::GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) const { … }
gfx::Size ToolbarView::CalculatePreferredSize(
const views::SizeBounds& available_size) const { … }
gfx::Size ToolbarView::GetMinimumSize() const { … }
void ToolbarView::Layout(PassKey) { … }
void ToolbarView::OnThemeChanged() { … }
void ToolbarView::UpdateClipPath() { … }
void ToolbarView::ActiveStateChanged() { … }
void ToolbarView::NewTabButtonPressed(const ui::Event& event) { … }
bool ToolbarView::AcceleratorPressed(const ui::Accelerator& accelerator) { … }
void ToolbarView::ChildPreferredSizeChanged(views::View* child) { … }
views::View* ToolbarView::GetDefaultFocusableChild() { … }
void ToolbarView::InitLayout() { … }
void ToolbarView::LayoutCommon() { … }
void ToolbarView::UpdateTypeAndSeverity(
AppMenuIconController::TypeAndSeverity type_and_severity) { … }
ExtensionsToolbarContainer* ToolbarView::GetExtensionsToolbarContainer() { … }
gfx::Size ToolbarView::GetToolbarButtonSize() const { … }
views::View* ToolbarView::GetDefaultExtensionDialogAnchorView() { … }
PageActionIconView* ToolbarView::GetPageActionIconView(
PageActionIconType type) { … }
AppMenuButton* ToolbarView::GetAppMenuButton() { … }
gfx::Rect ToolbarView::GetFindBarBoundingBox(int contents_bottom) { … }
void ToolbarView::FocusToolbar() { … }
views::AccessiblePaneView* ToolbarView::GetAsAccessiblePaneView() { … }
views::View* ToolbarView::GetAnchorView(
std::optional<PageActionIconType> type) { … }
void ToolbarView::ZoomChangedForActiveTab(bool can_show_bubble) { … }
AvatarToolbarButton* ToolbarView::GetAvatarToolbarButton() { … }
ManagementToolbarButton* ToolbarView::GetManagementToolbarButton() { … }
ToolbarButton* ToolbarView::GetBackButton() { … }
ReloadButton* ToolbarView::GetReloadButton() { … }
IntentChipButton* ToolbarView::GetIntentChipButton() { … }
DownloadToolbarButtonView* ToolbarView::GetDownloadButton() { … }
std::optional<BrowserRootView::DropIndex> ToolbarView::GetDropIndex(
const ui::DropTargetEvent& event) { … }
BrowserRootView::DropTarget* ToolbarView::GetDropTarget(
gfx::Point loc_in_local_coords) { … }
views::View* ToolbarView::GetViewForDrop() { … }
void ToolbarView::OnChromeLabsPrefChanged() { … }
void ToolbarView::LoadImages() { … }
void ToolbarView::OnShowForwardButtonChanged() { … }
void ToolbarView::OnShowHomeButtonChanged() { … }
void ToolbarView::OnTouchUiChanged() { … }
BEGIN_METADATA(…)