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
|
// 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.
#ifndef UI_VIEWS_CONTROLS_TABLE_TABLE_HEADER_H_
#define UI_VIEWS_CONTROLS_TABLE_TABLE_HEADER_H_
#include <memory>
#include "base/memory/weak_ptr.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/gfx/font_list.h"
#include "ui/views/controls/table/table_view.h"
#include "ui/views/view.h"
#include "ui/views/views_export.h"
namespace views {
// Views used to render the header for the table.
class VIEWS_EXPORT TableHeader : public View {
METADATA_HEADER(TableHeader, View)
public:
explicit TableHeader(base::WeakPtr<TableView> table);
TableHeader(const TableHeader&) = delete;
TableHeader& operator=(const TableHeader&) = delete;
~TableHeader() override;
const gfx::FontList& font_list() const { return font_list_; }
void ResizeColumnViaKeyboard(size_t index,
TableView::AdvanceDirection direction);
void InstallFocusRing();
// Call to update TableHeader objects that rely on the focus state of its
// corresponding virtual accessibility views.
void UpdateFocusState();
// TableHeader customization getters.
int GetCellVerticalPadding() const;
int GetCellHorizontalPadding() const;
int GetResizeBarVerticalPadding() const;
int GetSeparatorHorizontalPadding() const;
ui::ColorId GetSeparatorHorizontalColorId() const;
ui::ColorId GetSeparatorVerticalColorId() const;
ui::ColorId GetBackgroundColorId() const;
int GetSortIndicatorWidth() const;
gfx::Font::Weight GetFontWeight() const;
float GetFocusRingUpperRadius() const;
// views::View overrides.
void OnPaint(gfx::Canvas* canvas) override;
gfx::Size CalculatePreferredSize(
const SizeBounds& /*available_size*/) const override;
bool GetNeedsNotificationWhenVisibleBoundsChange() const override;
void OnVisibleBoundsChanged() override;
void AddedToWidget() override;
ui::Cursor GetCursor(const ui::MouseEvent& event) override;
bool OnMousePressed(const ui::MouseEvent& event) override;
bool OnMouseDragged(const ui::MouseEvent& event) override;
void OnMouseReleased(const ui::MouseEvent& event) override;
void OnMouseCaptureLost() override;
void OnGestureEvent(ui::GestureEvent* event) override;
void OnThemeChanged() override;
private:
class HighlightPathGenerator;
// Used to track the column being resized.
struct ColumnResizeDetails {
ColumnResizeDetails() = default;
// Index into table_->visible_columns() that is being resized.
size_t column_index = 0;
// X-coordinate of the mouse at the time the resize started.
int initial_x = 0;
// Width of the column when the drag started.
int initial_width = 0;
};
// Returns true if the TableView's header has focus.
bool GetHeaderRowHasFocus() const;
// Gets the bounds of the currently active header cell.
gfx::Rect GetActiveHeaderCellBounds() const;
// Returns true if one of the TableHeader's cells has a focus indicator.
bool HasFocusIndicator() const;
// Calculates the default radius, accounting for the focus ring thickness.
float GetDefaultFocusRingRadius() const;
// If not already resizing and |event| is over a resizable column starts
// resizing.
bool StartResize(const ui::LocatedEvent& event);
// Continues a resize operation. Does nothing if not in the process of
// resizing.
void ContinueResize(const ui::LocatedEvent& event);
// Toggles the sort order of the column at the location in |event|.
void ToggleSortOrder(const ui::LocatedEvent& event);
// Returns the column to resize given the specified x-coordinate, or nullopt
// if |x| is not in the resize range of any columns.
std::optional<size_t> GetResizeColumn(int x) const;
bool is_resizing() const { return resize_details_.get() != nullptr; }
// The table body that this `TableHeader` belongs to. The table body has
// nearly the same lifetime as the header, but during destruction of the
// `ScrollView` that contains both the body and the header, the body may be
// destroyed first.
const base::WeakPtr<TableView> table_;
const gfx::FontList font_list_;
// If non-null a resize is in progress.
std::unique_ptr<ColumnResizeDetails> resize_details_;
};
} // namespace views
#endif // UI_VIEWS_CONTROLS_TABLE_TABLE_HEADER_H_
|