1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_VIEWS_CONTROLS_TABLE_TABLE_HEADER_H_
6 #define UI_VIEWS_CONTROLS_TABLE_TABLE_HEADER_H_
8 #include "ui/gfx/font_list.h"
9 #include "ui/views/view.h"
10 #include "ui/views/views_export.h"
16 // Views used to render the header for the table.
17 class VIEWS_EXPORT TableHeader
: public views::View
{
19 // Internal class name.
20 static const char kViewClassName
[];
22 // Amount the text is padded on the left/right side.
23 static const int kHorizontalPadding
;
25 // Amount of space reserved for the indicator and padding.
26 static const int kSortIndicatorWidth
;
28 explicit TableHeader(TableView
* table
);
29 ~TableHeader() override
;
31 const gfx::FontList
& font_list() const { return font_list_
; }
33 // views::View overrides.
34 void Layout() override
;
35 void OnPaint(gfx::Canvas
* canvas
) override
;
36 const char* GetClassName() const override
;
37 gfx::Size
GetPreferredSize() const override
;
38 gfx::NativeCursor
GetCursor(const ui::MouseEvent
& event
) override
;
39 bool OnMousePressed(const ui::MouseEvent
& event
) override
;
40 bool OnMouseDragged(const ui::MouseEvent
& event
) override
;
41 void OnMouseReleased(const ui::MouseEvent
& event
) override
;
42 void OnMouseCaptureLost() override
;
43 void OnGestureEvent(ui::GestureEvent
* event
) override
;
46 // Used to track the column being resized.
47 struct ColumnResizeDetails
{
48 ColumnResizeDetails() : column_index(0), initial_x(0), initial_width(0) {}
50 // Index into table_->visible_columns() that is being resized.
53 // X-coordinate of the mouse at the time the resize started.
56 // Width of the column when the drag started.
60 // If not already resizing and |event| is over a resizable column starts
62 bool StartResize(const ui::LocatedEvent
& event
);
64 // Continues a resize operation. Does nothing if not in the process of
66 void ContinueResize(const ui::LocatedEvent
& event
);
68 // Toggles the sort order of the column at the location in |event|.
69 void ToggleSortOrder(const ui::LocatedEvent
& event
);
71 // Returns the column to resize given the specified x-coordinate, or -1 if |x|
72 // is not in the resize range of any columns.
73 int GetResizeColumn(int x
) const;
75 bool is_resizing() const { return resize_details_
.get() != NULL
; }
77 const gfx::FontList font_list_
;
81 // If non-null a resize is in progress.
82 scoped_ptr
<ColumnResizeDetails
> resize_details_
;
84 DISALLOW_COPY_AND_ASSIGN(TableHeader
);
89 #endif // UI_VIEWS_CONTROLS_TABLE_TABLE_HEADER_H_