chromium/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc

// 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.

#include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"

#include <stdint.h>

#include <algorithm>
#include <limits>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>

#include "base/callback_list.h"
#include "base/check_op.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/i18n/rtl.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/user_metrics.h"
#include "base/notreached.h"
#include "base/observer_list.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/bookmarks/managed_bookmark_service_factory.h"
#include "chrome/browser/browser_features.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/favicon/favicon_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h"
#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
#include "chrome/browser/ui/bookmarks/bookmark_utils.h"
#include "chrome/browser/ui/bookmarks/bookmark_utils_desktop.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_element_identifiers.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/color/chrome_color_id.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/tabs/saved_tab_groups/saved_tab_group_utils.h"
#include "chrome/browser/ui/tabs/saved_tab_groups/tab_group_sync_service_proxy.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_bar_view_observer.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_button.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_button_util.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_menu_button_base.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_menu_controller_views.h"
#include "chrome/browser/ui/views/bookmarks/saved_tab_groups/saved_tab_group_bar.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/event_utils.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/side_panel/side_panel_ui.h"
#include "chrome/browser/ui/views/side_panel/side_panel_util.h"
#include "chrome/browser/ui/views/toolbar/toolbar_ink_drop_util.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/extension_metrics.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/bookmark_node.h"
#include "components/bookmarks/browser/bookmark_utils.h"
#include "components/bookmarks/common/bookmark_pref_names.h"
#include "components/bookmarks/managed/managed_bookmark_service.h"
#include "components/metrics/metrics_service.h"
#include "components/prefs/pref_service.h"
#include "components/profile_metrics/browser_profile_type.h"
#include "components/saved_tab_groups/features.h"
#include "components/url_formatter/elide_url.h"
#include "components/url_formatter/url_formatter.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_set.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/mojom/drag_drop_types.mojom-shared.h"
#include "ui/base/dragdrop/mojom/drag_drop_types.mojom.h"
#include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/models/image_model_utils.h"
#include "ui/base/page_transition_types.h"
#include "ui/base/pointer/touch_ui_controller.h"
#include "ui/base/resource/resource_bundle.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/paint_recorder.h"
#include "ui/events/event_constants.h"
#include "ui/events/types/event_type.h"
#include "ui/gfx/animation/slide_animation.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/favicon_size.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/scoped_canvas.h"
#include "ui/gfx/text_constants.h"
#include "ui/gfx/text_elider.h"
#include "ui/resources/grit/ui_resources.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/animation/flood_fill_ink_drop_ripple.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/animation/ink_drop_mask.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/button_drag_utils.h"
#include "ui/views/cascading_property.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/label_button_border.h"
#include "ui/views/controls/button/menu_button.h"
#include "ui/views/controls/button/menu_button_controller.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/separator.h"
#include "ui/views/drag_utils.h"
#include "ui/views/metrics.h"
#include "ui/views/view_class_properties.h"
#include "ui/views/view_constants.h"
#include "ui/views/view_utils.h"
#include "ui/views/widget/tooltip_manager.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/non_client_view.h"

namespace {

BookmarkModel;
BookmarkNode;
DragOperation;
Background;
Border;
LabelButtonBorder;
MenuButton;

// Used to globally disable rich animations.
bool animations_enabled =;

// Thickness of the separator (|) in dips (density-independent pixels).
constexpr int kBookmarkBarSeparatorThickness =;

gfx::ImageSkia* GetImageSkiaNamed(int id) {}

const std::u16string& GetFolderButtonAccessibleName(
    const std::u16string& folder_title) {}

// ShortcutButton -------------------------------------------------------------

// Buttons used for the shortcuts on the bookmark bar.

class ShortcutButton : public BookmarkButtonBase {};

BEGIN_METADATA()

// BookmarkFolderButton -------------------------------------------------------

// Buttons used for folders on the bookmark bar, including the 'other folders'
// button.
class BookmarkFolderButton : public BookmarkMenuButtonBase {};

BEGIN_METADATA()

// BookmarkTabGroupButton
// -------------------------------------------------------

void RecordAppLaunch(Profile* profile, const GURL& url) {}

}  // namespace

// DropLocation ---------------------------------------------------------------

struct BookmarkBarView::DropLocation {};

// DropInfo -------------------------------------------------------------------

// Tracks drops on the BookmarkBarView.

struct BookmarkBarView::DropInfo {};

// ButtonSeparatorView  --------------------------------------------------------

class BookmarkBarView::ButtonSeparatorView : public views::Separator {};

BEGIN_METADATA()
END_METADATA

// BookmarkBarView ------------------------------------------------------------

BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view)
    :{}

BookmarkBarView::~BookmarkBarView() {}

// static
bool BookmarkBarView::GetAnimationsEnabled() {}

void BookmarkBarView::DisableAnimationsForTesting(bool disabled) {}

void BookmarkBarView::AddObserver(BookmarkBarViewObserver* observer) {}

void BookmarkBarView::RemoveObserver(BookmarkBarViewObserver* observer) {}

void BookmarkBarView::SetPageNavigator(content::PageNavigator* navigator) {}

void BookmarkBarView::SetInfoBarVisible(bool infobar_visible) {}

bool BookmarkBarView::GetInfoBarVisible() const {}

void BookmarkBarView::SetBookmarkBarState(
    BookmarkBar::State state,
    BookmarkBar::AnimateChangeType animate_type) {}

const BookmarkNode* BookmarkBarView::GetNodeForButtonAtModelIndex(
    const gfx::Point& loc,
    size_t* model_start_index) {}

MenuButton* BookmarkBarView::GetMenuButtonForNode(const BookmarkNode* node) {}

void BookmarkBarView::GetAnchorPositionForButton(
    MenuButton* button,
    views::MenuAnchorPosition* anchor) {}

int BookmarkBarView::GetLeadingMargin() const {}

const views::MenuItemView* BookmarkBarView::GetMenu() const {}

views::MenuItemView* BookmarkBarView::GetContextMenu() {}

views::MenuItemView* BookmarkBarView::GetDropMenu() {}

// static
std::u16string BookmarkBarView::CreateToolTipForURLAndTitle(
    int max_width,
    const gfx::FontList& tt_fonts,
    const GURL& url,
    const std::u16string& title) {}

gfx::Size BookmarkBarView::CalculatePreferredSize(
    const views::SizeBounds& available_size) const {}

gfx::Size BookmarkBarView::GetMinimumSize() const {}

// TODO(crbug.com/40648316, crbug.com/330763840): Remove Layout override and
// transition BookmarkBarView to use a layout manager. Afterwards, for most if
// not all calls to LayoutAndPaint can be migrated to only schedule paint and
// not invalidate layout because the layout manager will invalidate layout
// automatically for things like adding and removing child views.
void BookmarkBarView::Layout(PassKey) {}

void BookmarkBarView::ViewHierarchyChanged(
    const views::ViewHierarchyChangedDetails& details) {}

void BookmarkBarView::PaintChildren(const views::PaintInfo& paint_info) {}

bool BookmarkBarView::GetDropFormats(
    int* formats,
    std::set<ui::ClipboardFormatType>* format_types) {}

bool BookmarkBarView::AreDropTypesRequired() {}

bool BookmarkBarView::CanDrop(const ui::OSExchangeData& data) {}

void BookmarkBarView::OnDragEntered(const ui::DropTargetEvent& event) {}

int BookmarkBarView::OnDragUpdated(const ui::DropTargetEvent& event) {}

void BookmarkBarView::OnDragExited() {}

views::View::DropCallback BookmarkBarView::GetDropCallback(
    const ui::DropTargetEvent& event) {}

void BookmarkBarView::OnThemeChanged() {}

void BookmarkBarView::VisibilityChanged(View* starting_from, bool is_visible) {}

void BookmarkBarView::ChildPreferredSizeChanged(views::View* child) {}

void BookmarkBarView::AddedToWidget() {}

void BookmarkBarView::AnimationProgressed(const gfx::Animation* animation) {}

void BookmarkBarView::AnimationEnded(const gfx::Animation* animation) {}

void BookmarkBarView::BookmarkMenuControllerDeleted(
    BookmarkMenuController* controller) {}

void BookmarkBarView::BookmarkModelLoaded(bool ids_reassigned) {}

void BookmarkBarView::BookmarkModelBeingDeleted() {}

void BookmarkBarView::BookmarkNodeMoved(const BookmarkNode* old_parent,
                                        size_t old_index,
                                        const BookmarkNode* new_parent,
                                        size_t new_index) {}

void BookmarkBarView::BookmarkNodeAdded(const BookmarkNode* parent,
                                        size_t index,
                                        bool added_by_user) {}

void BookmarkBarView::BookmarkNodeRemoved(const BookmarkNode* parent,
                                          size_t old_index,
                                          const BookmarkNode* node,
                                          const std::set<GURL>& removed_urls,
                                          const base::Location& location) {}

void BookmarkBarView::BookmarkAllUserNodesRemoved(
    const std::set<GURL>& removed_urls,
    const base::Location& location) {}

void BookmarkBarView::BookmarkNodeChanged(const BookmarkNode* node) {}

void BookmarkBarView::BookmarkNodeChildrenReordered(const BookmarkNode* node) {}

void BookmarkBarView::BookmarkNodeFaviconChanged(const BookmarkNode* node) {}

void BookmarkBarView::WriteDragDataForView(View* sender,
                                           const gfx::Point& press_pt,
                                           ui::OSExchangeData* data) {}

int BookmarkBarView::GetDragOperationsForView(View* sender,
                                              const gfx::Point& p) {}

bool BookmarkBarView::CanStartDragForView(views::View* sender,
                                          const gfx::Point& press_pt,
                                          const gfx::Point& p) {}

void BookmarkBarView::AppsPageShortcutPressed(const ui::Event& event) {}

void BookmarkBarView::OnButtonPressed(const bookmarks::BookmarkNode* node,
                                      const ui::Event& event) {}

void BookmarkBarView::OnMenuButtonPressed(const bookmarks::BookmarkNode* node,
                                          const ui::Event& event) {}

void BookmarkBarView::ShowContextMenuForViewImpl(
    views::View* source,
    const gfx::Point& point,
    ui::MenuSourceType source_type) {}

// Calculate the available width for the saved tab group bar.
// The following rules are applied to prevent one allocate too much space over
// another.
//
// 1. If saved tab group bar and bookmark buttons can both fit into the space,
// allocate as much as they need to both of them.
//
// 2. When saved tab group bar and bookmark buttons can't both fit into the
// space, if one of them is smaller than half of the available width and the
// other is bigger than it, then allocate enough space to fit the smaller one
// and the rest for the bigger one.
//
// 3. When saved tab group bar and bookmark buttons can't both fit into the
// space, if both of them are bigger than half of the available width, then
// allocate half of the available to each of them.
int BookmarkBarView::GetAvailableWidthForSavedTabGroupsBar(
    int saved_tab_group_bar_width,
    int bookmark_buttons_width,
    int available_width) {}

void BookmarkBarView::Init() {}

size_t BookmarkBarView::GetFirstHiddenNodeIndex() const {}

std::unique_ptr<MenuButton> BookmarkBarView::CreateAllBookmarksButton() {}

std::unique_ptr<MenuButton> BookmarkBarView::CreateManagedBookmarksButton() {}

std::unique_ptr<MenuButton> BookmarkBarView::CreateOverflowButton() {}

std::unique_ptr<views::View> BookmarkBarView::CreateBookmarkButton(
    const BookmarkNode* node) {}

std::unique_ptr<views::LabelButton>
BookmarkBarView::CreateAppsPageShortcutButton() {}

void BookmarkBarView::ConfigureButton(const BookmarkNode* node,
                                      views::LabelButton* button) {}

bool BookmarkBarView::BookmarkNodeAddedImpl(const BookmarkNode* parent,
                                            size_t index) {}

bool BookmarkBarView::BookmarkNodeRemovedImpl(const BookmarkNode* parent,
                                              size_t index) {}

void BookmarkBarView::BookmarkNodeChangedImpl(const BookmarkNode* node) {}

void BookmarkBarView::ShowDropFolderForNode(const BookmarkNode* node) {}

void BookmarkBarView::StopShowFolderDropMenuTimer() {}

void BookmarkBarView::StartShowFolderDropMenuTimer(const BookmarkNode* node) {}

void BookmarkBarView::CalculateDropLocation(
    const ui::DropTargetEvent& event,
    const bookmarks::BookmarkNodeData& data,
    DropLocation* location) {}

void BookmarkBarView::InvalidateDrop() {}

const BookmarkNode* BookmarkBarView::GetNodeForSender(View* sender) const {}

void BookmarkBarView::WriteBookmarkDragData(const BookmarkNode* node,
                                            ui::OSExchangeData* data) {}

void BookmarkBarView::UpdateAppearanceForTheme() {}

bool BookmarkBarView::UpdateOtherAndManagedButtonsVisibility() {}

void BookmarkBarView::UpdateBookmarksSeparatorVisibility() {}

void BookmarkBarView::OnAppsPageShortcutVisibilityPrefChanged() {}

void BookmarkBarView::OnTabGroupsVisibilityPrefChanged() {}

void BookmarkBarView::OnShowManagedBookmarksPrefChanged() {}

void BookmarkBarView::OnCompactModeChanged() {}

void BookmarkBarView::InsertBookmarkButtonAtIndex(
    std::unique_ptr<views::View> bookmark_button,
    size_t index) {}

size_t BookmarkBarView::GetIndexForButton(views::View* button) {}

const BookmarkNode* BookmarkBarView::GetParentNodeAndIndexForDrop(
    size_t& index) {}

void BookmarkBarView::PerformDrop(
    const bookmarks::BookmarkNodeData data,
    const BookmarkNode* parent_node,
    const size_t index,
    const bool copy,
    const ui::DropTargetEvent& event,
    ui::mojom::DragOperation& output_drag_op,
    std::unique_ptr<ui::LayerTreeOwner> drag_image_layer_owner) {}

int BookmarkBarView::GetDropLocationModelIndexForTesting() const {}
const views::View* BookmarkBarView::GetSavedTabGroupsSeparatorViewForTesting()
    const {}

void BookmarkBarView::MaybeShowSavedTabGroupsIntroPromo() const {}

BEGIN_METADATA()