chromium/ui/views/controls/table/table_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 "ui/views/controls/table/table_view.h"

#include <stddef.h>
#include <stdint.h>

#include <algorithm>
#include <map>
#include <optional>
#include <utility>

#include "base/auto_reset.h"
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/i18n/rtl.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/ranges/algorithm.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "build/build_config.h"
#include "cc/paint/paint_flags.h"
#include "ui/accessibility/ax_action_data.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/color/color_id.h"
#include "ui/color/color_provider.h"
#include "ui/events/event.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/skia_conversions.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/text_utils.h"
#include "ui/strings/grit/ui_strings.h"
#include "ui/views/accessibility/ax_virtual_view.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/focus_ring.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/table/table_grouper.h"
#include "ui/views/controls/table/table_header.h"
#include "ui/views/controls/table/table_utils.h"
#include "ui/views/controls/table/table_view_observer.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/views/layout/layout_provider.h"
#include "ui/views/style/platform_style.h"
#include "ui/views/style/typography.h"
#include "ui/views/style/typography_provider.h"
#include "ui/views/view_utils.h"

namespace views {

namespace {

constexpr int kGroupingIndicatorSize =;

// Returns result, unless ascending is false in which case -result is returned.
int SwapCompareResult(int result, bool ascending) {}

// Populates |model_index_to_range_start| based on the |grouper|.
void GetModelIndexToRangeStart(
    TableGrouper* grouper,
    size_t row_count,
    std::map<size_t, size_t>* model_index_to_range_start) {}

// Returns the color id for the background of selected text. |has_focus|
// indicates if the table has focus.
ui::ColorId text_background_color_id(bool has_focus) {}

// Returns the color id for text. |has_focus| indicates if the table has focus.
ui::ColorId selected_text_color_id(bool has_focus) {}

// Whether the platform "command" key is down.
bool IsCmdOrCtrl(const ui::Event& event) {}

}  // namespace

// Used as the comparator to sort the contents of the table.
struct TableView::SortHelper {};

// Used as the comparator to sort the contents of the table when a TableGrouper
// is present. When groups are present we sort the groups based on the first row
// in the group and within the groups we keep the same order as the model.
struct TableView::GroupSortHelper {};

TableView::VisibleColumn::VisibleColumn() = default;

TableView::VisibleColumn::~VisibleColumn() = default;

TableView::PaintRegion::PaintRegion() = default;

TableView::PaintRegion::~PaintRegion() = default;

class TableView::HighlightPathGenerator : public views::HighlightPathGenerator {};

TableView::TableView() :{}

TableView::TableView(ui::TableModel* model,
                     const std::vector<ui::TableColumn>& columns,
                     TableType table_type,
                     bool single_selection)
    :{}

TableView::~TableView() {}

// static
std::unique_ptr<ScrollView> TableView::CreateScrollViewWithTable(
    std::unique_ptr<TableView> table) {}

// static
Builder<ScrollView> TableView::CreateScrollViewBuilderWithTable(
    Builder<TableView>&& table) {}

void TableView::Init(ui::TableModel* model,
                     const std::vector<ui::TableColumn>& columns,
                     TableType table_type,
                     bool single_selection) {}

// TODO(sky): this doesn't support arbitrarily changing the model, rename this
// to ClearModel() or something.
void TableView::SetModel(ui::TableModel* model) {}

void TableView::SetColumns(const std::vector<ui::TableColumn>& columns) {}

void TableView::SetTableType(TableType table_type) {}

TableType TableView::GetTableType() const {}

void TableView::SetSingleSelection(bool single_selection) {}

bool TableView::GetSingleSelection() const {}

void TableView::SetGrouper(TableGrouper* grouper) {}

size_t TableView::GetRowCount() const {}

void TableView::Select(std::optional<size_t> model_row) {}

void TableView::SetSelectionAll(bool select) {}

std::optional<size_t> TableView::GetFirstSelectedRow() const {}

// TODO(dpenning) : Prevent the last column from being closed. See
// crbug.com/1324306 for details.
void TableView::SetColumnVisibility(int id, bool is_visible) {}

void TableView::ToggleSortOrder(size_t visible_column_index) {}

void TableView::SetSortDescriptors(const SortDescriptors& sort_descriptors) {}

bool TableView::IsColumnVisible(int id) const {}

bool TableView::HasColumn(int id) const {}

bool TableView::GetHasFocusIndicator() const {}

void TableView::SetObserver(TableViewObserver* observer) {}

TableViewObserver* TableView::GetObserver() const {}

const TableView::VisibleColumn& TableView::GetVisibleColumn(size_t index) {}

void TableView::SetVisibleColumnWidth(size_t index, int width) {}

size_t TableView::ModelToView(size_t model_index) const {}

size_t TableView::ViewToModel(size_t view_index) const {}

bool TableView::GetSelectOnRemove() const {}

void TableView::SetSelectOnRemove(bool select_on_remove) {}

bool TableView::GetSortOnPaint() const {}

void TableView::SetSortOnPaint(bool sort_on_paint) {}

ax::mojom::SortDirection TableView::GetFirstSortDescriptorDirection() const {}

void TableView::Layout(PassKey) {}

gfx::Size TableView::CalculatePreferredSize(
    const SizeBounds& /*available_size*/) const {}

bool TableView::GetNeedsNotificationWhenVisibleBoundsChange() const {}

void TableView::OnVisibleBoundsChanged() {}

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

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

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

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

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

bool TableView::HandleAccessibleAction(const ui::AXActionData& action_data) {}

void TableView::OnBoundsChanged(const gfx::Rect& previous_bounds) {}

void TableView::OnModelChanged() {}

void TableView::OnItemsChanged(size_t start, size_t length) {}

void TableView::OnItemsAdded(size_t start, size_t length) {}

void TableView::OnItemsMoved(size_t old_start,
                             size_t length,
                             size_t new_start) {}

void TableView::OnItemsRemoved(size_t start, size_t length) {}

gfx::Point TableView::GetKeyboardContextMenuLocation() {}

void TableView::OnFocus() {}

void TableView::OnBlur() {}

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

void TableView::OnPaintImpl(gfx::Canvas* canvas) {}

int TableView::GetCellMargin() const {}

int TableView::GetCellElementSpacing() const {}


void TableView::SortItemsAndUpdateMapping(bool schedule_paint) {}

int TableView::CompareRows(size_t model_row1, size_t model_row2) {}

gfx::Rect TableView::GetRowBounds(size_t row) const {}

gfx::Rect TableView::GetCellBounds(size_t row,
                                   size_t visible_column_index) const {}

gfx::Rect TableView::GetActiveCellBounds() const {}

void TableView::AdjustCellBoundsForText(size_t visible_column_index,
                                        gfx::Rect* bounds) const {}

void TableView::CreateHeaderIfNecessary(ScrollView* scroll_view) {}

void TableView::UpdateVisibleColumnSizes() {}

// The default drawing size for icons in a table view is 16 * 16. If the cell
// size is not sufficient, the original image needs to be clipped. e.g if the
// original image size is 32 * 32, the normal bounds would be src bounds (0, 0,
// 32, 32) and dest bounds (x, y, 16, 16). If the dest bounds are (x, y, 8, 16),
// the original image needs to be clipped to prevent stretching during drawing.
// For LTR (left-to-right) layout, the src bounds would be (0, 0, 16, 32), and
// the width would be calculated as width = image_size.width() *
// image_dest_width / ui::TableModel::kIconSize.
// For RTL (right-to-left) layout, the src bounds would be (16, 0, 16, 32),
// and the `x` would be calculated as x = image_size.width() - src_image_width.
// (https://crbug.com/1494675)
gfx::Rect TableView::GetPaintIconSrcBounds(const gfx::Size& image_size,
                                           int image_dest_width) const {}

gfx::Rect TableView::GetPaintIconDestBounds(const gfx::Rect& cell_bounds,
                                            int text_bounds_x) const {}

TableView::PaintRegion TableView::GetPaintRegion(
    const gfx::Rect& bounds) const {}

gfx::Rect TableView::GetPaintBounds(gfx::Canvas* canvas) const {}

void TableView::SchedulePaintForSelection() {}

ui::TableColumn TableView::FindColumnByID(int id) const {}

void TableView::AdvanceActiveVisibleColumn(AdvanceDirection direction) {}

std::optional<size_t> TableView::GetActiveVisibleColumnIndex() const {}

void TableView::SetActiveVisibleColumnIndex(std::optional<size_t> index) {}

void TableView::SelectByViewIndex(std::optional<size_t> view_index) {}

void TableView::SetSelectionModel(ui::ListSelectionModel new_selection) {}

void TableView::AdvanceSelection(AdvanceDirection direction) {}

void TableView::ConfigureSelectionModelForEvent(
    const ui::LocatedEvent& event,
    ui::ListSelectionModel* model) const {}

void TableView::SelectRowsInRangeFrom(size_t view_index,
                                      bool select,
                                      ui::ListSelectionModel* model) const {}

GroupRange TableView::GetGroupRange(size_t model_index) const {}

void TableView::RebuildVirtualAccessibilityChildren() {}

void TableView::UpdateAccessibleNameForIndex(size_t start_view_index,
                                             size_t length) {}

void TableView::ClearVirtualAccessibilityChildren() {}

void TableView::UpdateVirtualAccessibilityChildrenVisibilityState() {}

void TableView::SetAccessibleSelectionForIndex(size_t view_index,
                                               bool selected) const {}

void TableView::SetAccessibleSelectionForRange(size_t start_view_index,
                                               size_t end_view_index,
                                               bool selected) const {}

void TableView::ClearAccessibleSelection() const {}

void TableView::UpdateAccessibleSelectionForColumnIndex(
    size_t visible_column_index) const {}

std::unique_ptr<AXVirtualView> TableView::CreateRowAccessibilityView(
    size_t row_index) {}

std::unique_ptr<AXVirtualView> TableView::CreateCellAccessibilityView(
    size_t row_index,
    size_t column_index) {}

void TableView::UpdateFocusRings() {}

std::unique_ptr<AXVirtualView> TableView::CreateHeaderAccessibilityView() {}

bool TableView::UpdateVirtualAccessibilityRowData(AXVirtualView* ax_row,
                                                  int view_index,
                                                  int model_index) {}

void TableView::UpdateVirtualAccessibilityChildrenBounds() {}

gfx::Rect TableView::CalculateHeaderRowAccessibilityBounds() const {}

gfx::Rect TableView::CalculateHeaderCellAccessibilityBounds(
    const size_t visible_column_index) const {}

gfx::Rect TableView::CalculateTableRowAccessibilityBounds(
    const size_t row_index) const {}

gfx::Rect TableView::CalculateTableCellAccessibilityBounds(
    const size_t row_index,
    const size_t visible_column_index) const {}

void TableView::ScheduleUpdateAccessibilityFocusIfNeeded() {}

void TableView::UpdateAccessibilityFocus(
    UpdateAccessibilityFocusPassKey pass_key) {}

AXVirtualView* TableView::GetVirtualAccessibilityBodyRow(size_t row) const {}

AXVirtualView* TableView::GetVirtualAccessibilityHeaderRow() {}

AXVirtualView* TableView::GetVirtualAccessibilityCell(
    size_t row,
    size_t visible_column_index) const {}

AXVirtualView* TableView::GetVirtualAccessibilityCellImpl(
    AXVirtualView* ax_row,
    size_t visible_column_index) const {}

BEGIN_METADATA()

}  // namespace views

DEFINE_ENUM_CONVERTERS()