chromium/chrome/browser/ui/views/tabs/tab.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.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "chrome/browser/ui/views/tabs/tab.h"

#include <stddef.h>

#include <algorithm>
#include <limits>
#include <memory>
#include <utility>

#include "base/debug/alias.h"
#include "base/functional/bind.h"
#include "base/i18n/rtl.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/user_metrics.h"
#include "base/numerics/safe_conversions.h"
#include "base/scoped_observation.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "cc/paint/paint_flags.h"
#include "cc/paint/paint_recorder.h"
#include "cc/paint/paint_shader.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_element_identifiers.h"
#include "chrome/browser/ui/color/chrome_color_id.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/tab_contents/core_tab_helper.h"
#include "chrome/browser/ui/tabs/tab_style.h"
#include "chrome/browser/ui/tabs/tab_utils.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/tabs/alert_indicator_button.h"
#include "chrome/browser/ui/views/tabs/browser_tab_strip_controller.h"
#include "chrome/browser/ui/views/tabs/tab_close_button.h"
#include "chrome/browser/ui/views/tabs/tab_drag_controller.h"
#include "chrome/browser/ui/views/tabs/tab_hover_card_bubble_view.h"
#include "chrome/browser/ui/views/tabs/tab_icon.h"
#include "chrome/browser/ui/views/tabs/tab_slot_controller.h"
#include "chrome/browser/ui/views/tabs/tab_slot_view.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/browser/ui/views/tabs/tab_strip_layout.h"
#include "chrome/browser/ui/views/tabs/tab_style_views.h"
#include "chrome/common/chrome_features.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h"
#include "components/grit/components_scaled_resources.h"
#include "components/tab_groups/tab_group_color.h"
#include "components/tab_groups/tab_group_visual_data.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "third_party/skia/include/pathops/SkPathOps.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/models/list_selection_model.h"
#include "ui/base/pointer/touch_ui_controller.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/theme_provider.h"
#include "ui/compositor/clip_recorder.h"
#include "ui/compositor/compositor.h"
#include "ui/gfx/animation/tween.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/favicon_size.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/skia_conversions.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/scoped_canvas.h"
#include "ui/resources/grit/ui_resources.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/border.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/focus_ring.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/controls/label.h"
#include "ui/views/rect_based_targeting_utils.h"
#include "ui/views/view.h"
#include "ui/views/view_class_properties.h"
#include "ui/views/view_targeter.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)
#include "ui/views/win/pen_event_handler_util.h"
#endif

#if defined(USE_AURA)
#include "ui/aura/env.h"
#endif

UserMetricsAction;
namespace {

// When a non-pinned tab becomes a pinned tab the width of the tab animates. If
// the width of a pinned tab is at least kPinnedTabExtraWidthToRenderAsNormal
// larger than the desired pinned tab width then the tab is rendered as a normal
// tab. This is done to avoid having the title immediately disappear when
// transitioning a tab from normal to pinned tab.
constexpr int kPinnedTabExtraWidthToRenderAsNormal =;

// Additional padding of close button to the right of the tab
// indicator when `extra_alert_indicator_padding_` is true.
constexpr int kTabAlertIndicatorCloseButtonPaddingAdjustmentTouchUI =;
constexpr int kTabAlertIndicatorCloseButtonPaddingAdjustment =;

// When the DiscardRingImprovements feature is enabled, increase the radius of
// the discard ring by this amount if there is enough space.
constexpr int kIncreasedDiscardIndicatorRadiusDp =;

bool g_show_hover_card_on_mouse_hover =;

// Helper functions ------------------------------------------------------------

// Returns the coordinate for an object of size |item_size| centered in a region
// of size |size|, biasing towards placing any extra space ahead of the object.
int Center(int size, int item_size) {}

class TabStyleHighlightPathGenerator : public views::HighlightPathGenerator {};

}  // namespace

// Helper class that observes the tab's close button.
class Tab::TabCloseButtonObserver : public views::ViewObserver {};

// Tab -------------------------------------------------------------------------

// static
void Tab::SetShowHoverCardOnMouseHoverForTesting(bool value) {}

Tab::Tab(TabSlotController* controller)
    :{}

Tab::~Tab() {}

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

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

bool Tab::GetHitTestMask(SkPath* mask) const {}

void Tab::Layout(PassKey) {}

bool Tab::OnKeyPressed(const ui::KeyEvent& event) {}

bool Tab::OnKeyReleased(const ui::KeyEvent& event) {}

namespace {
bool IsSelectionModifierDown(const ui::MouseEvent& event) {}
}  // namespace

bool Tab::OnMousePressed(const ui::MouseEvent& event) {}

bool Tab::OnMouseDragged(const ui::MouseEvent& event) {}

void Tab::OnMouseReleased(const ui::MouseEvent& event) {}

void Tab::OnMouseCaptureLost() {}

void Tab::OnMouseMoved(const ui::MouseEvent& event) {}

void Tab::OnMouseEntered(const ui::MouseEvent& event) {}

void Tab::MaybeUpdateHoverStatus(const ui::MouseEvent& event) {}

void Tab::OnMouseExited(const ui::MouseEvent& event) {}

void Tab::OnGestureEvent(ui::GestureEvent* event) {}

std::u16string Tab::GetTooltipText(const gfx::Point& p) const {}

void Tab::GetAccessibleNodeData(ui::AXNodeData* node_data) {}

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

void Tab::PaintChildren(const views::PaintInfo& info) {}

void Tab::OnPaint(gfx::Canvas* canvas) {}

void Tab::AddedToWidget() {}

void Tab::RemovedFromWidget() {}

void Tab::OnFocus() {}

void Tab::OnBlur() {}

void Tab::OnThemeChanged() {}

TabSlotView::ViewType Tab::GetTabSlotViewType() const {}

TabSizeInfo Tab::GetTabSizeInfo() const {}

void Tab::SetClosing(bool closing) {}

std::optional<SkColor> Tab::GetGroupColor() const {}

ui::ColorId Tab::GetAlertIndicatorColor(TabAlertState state) const {}

bool Tab::IsActive() const {}

void Tab::ActiveStateChanged() {}

void Tab::AlertStateChanged() {}

void Tab::SelectedStateChanged() {}

bool Tab::IsSelected() const {}

bool Tab::IsDiscarded() const {}

bool Tab::HasThumbnail() const {}

void Tab::SetData(TabRendererData data) {}

void Tab::StepLoadingAnimation(const base::TimeDelta& elapsed_time) {}

void Tab::SetTabNeedsAttention(bool attention) {}

void Tab::CreateFreezingVote(content::WebContents* contents) {}

void Tab::ReleaseFreezingVote() {}

// static
std::u16string Tab::GetTooltipText(const std::u16string& title,
                                   std::optional<TabAlertState> alert_state) {}

// static
std::optional<TabAlertState> Tab::GetAlertStateToShow(
    const std::vector<TabAlertState>& alert_states) {}

void Tab::SetShouldShowDiscardIndicator(bool enabled) {}

void Tab::MaybeAdjustLeftForPinnedTab(gfx::Rect* bounds,
                                      int visual_width) const {}

void Tab::UpdateIconVisibility() {}

bool Tab::ShouldRenderAsNormalTab() const {}

void Tab::UpdateTabIconNeedsAttentionBlocked() {}

int Tab::GetWidthOfLargestSelectableRegion() const {}

void Tab::UpdateForegroundColors() {}

void Tab::CloseButtonPressed(const ui::Event& event) {}

BEGIN_METADATA()