OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views/controls/table/table_header.h" | 5 #include "ui/views/controls/table/table_header.h" |
6 | 6 |
7 #include "ui/gfx/canvas.h" | 7 #include "ui/gfx/canvas.h" |
8 #include "ui/views/controls/table/table_utils.h" | 8 #include "ui/views/controls/table/table_utils.h" |
9 #include "ui/views/controls/table/table_view.h" | 9 #include "ui/views/controls/table/table_view.h" |
10 | 10 |
11 #if defined(USE_AURA) | 11 #if defined(USE_AURA) |
12 #include "ui/base/cursor/cursor.h" | 12 #include "ui/base/cursor/cursor.h" |
13 #endif | 13 #endif |
14 | 14 |
15 namespace views { | 15 namespace views { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 const int kVerticalPadding = 6; | 19 const int kVerticalPadding = 6; |
20 const int kHorizontalPadding = 4; | |
21 | 20 |
22 // The minimum width we allow a column to go down to. | 21 // The minimum width we allow a column to go down to. |
23 const int kMinColumnWidth = 10; | 22 const int kMinColumnWidth = 10; |
24 | 23 |
25 // Distace from edge columns can be resized by. | 24 // Distace from edge columns can be resized by. |
26 const int kResizePadding = 5; | 25 const int kResizePadding = 5; |
27 | 26 |
28 const SkColor kTextColor = SK_ColorBLACK; | 27 const SkColor kTextColor = SK_ColorBLACK; |
29 | 28 |
30 gfx::NativeCursor GetResizeCursor() { | 29 gfx::NativeCursor GetResizeCursor() { |
31 #if defined(USE_AURA) | 30 #if defined(USE_AURA) |
32 return ui::kCursorColumnResize; | 31 return ui::kCursorColumnResize; |
33 #elif defined(OS_WIN) | 32 #elif defined(OS_WIN) |
34 static HCURSOR g_hand_cursor = LoadCursor(NULL, IDC_SIZEWE); | 33 static HCURSOR g_hand_cursor = LoadCursor(NULL, IDC_SIZEWE); |
35 return g_hand_cursor; | 34 return g_hand_cursor; |
36 #endif | 35 #endif |
37 } | 36 } |
38 | 37 |
39 } // namespace | 38 } // namespace |
40 | 39 |
| 40 // static |
| 41 const int TableHeader::kHorizontalPadding = 4; |
| 42 |
41 typedef std::vector<TableView::VisibleColumn> Columns; | 43 typedef std::vector<TableView::VisibleColumn> Columns; |
42 | 44 |
43 TableHeader::TableHeader(TableView* table) : table_(table) { | 45 TableHeader::TableHeader(TableView* table) : table_(table) { |
44 } | 46 } |
45 | 47 |
46 TableHeader::~TableHeader() { | 48 TableHeader::~TableHeader() { |
47 } | 49 } |
48 | 50 |
49 void TableHeader::Layout() { | 51 void TableHeader::Layout() { |
50 SetBounds(x(), y(), table_->width(), GetPreferredSize().height()); | 52 SetBounds(x(), y(), table_->width(), GetPreferredSize().height()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 if (event.IsOnlyLeftMouseButton()) { | 85 if (event.IsOnlyLeftMouseButton()) { |
84 const int index = GetResizeColumn(event.x()); | 86 const int index = GetResizeColumn(event.x()); |
85 if (index != -1) { | 87 if (index != -1) { |
86 DCHECK(!is_resizing()); | 88 DCHECK(!is_resizing()); |
87 resize_details_.reset(new ColumnResizeDetails); | 89 resize_details_.reset(new ColumnResizeDetails); |
88 resize_details_->column_index = index; | 90 resize_details_->column_index = index; |
89 resize_details_->initial_x = event.x(); | 91 resize_details_->initial_x = event.x(); |
90 resize_details_->initial_width = | 92 resize_details_->initial_width = |
91 table_->visible_columns()[index].width; | 93 table_->visible_columns()[index].width; |
92 } | 94 } |
| 95 return true; |
93 } | 96 } |
94 return true; | 97 // Return false so that context menus on ancestors work. |
| 98 return false; |
95 } | 99 } |
96 | 100 |
97 bool TableHeader::OnMouseDragged(const ui::MouseEvent& event) { | 101 bool TableHeader::OnMouseDragged(const ui::MouseEvent& event) { |
98 if (is_resizing()) { | 102 if (is_resizing()) { |
99 const int delta = event.x() - resize_details_->initial_x; | 103 const int delta = event.x() - resize_details_->initial_x; |
100 table_->SetVisibleColumnWidth( | 104 table_->SetVisibleColumnWidth( |
101 resize_details_->column_index, | 105 resize_details_->column_index, |
102 std::max(kMinColumnWidth, resize_details_->initial_width + delta)); | 106 std::max(kMinColumnWidth, resize_details_->initial_width + delta)); |
103 } | 107 } |
104 return true; | 108 return true; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 if (index > 0 && x >= column.x - kResizePadding && | 149 if (index > 0 && x >= column.x - kResizePadding && |
146 x <= column.x + kResizePadding) { | 150 x <= column.x + kResizePadding) { |
147 return index - 1; | 151 return index - 1; |
148 } | 152 } |
149 const int max_x = column.x + column.width; | 153 const int max_x = column.x + column.width; |
150 return (x >= max_x - kResizePadding && x <= max_x + kResizePadding) ? | 154 return (x >= max_x - kResizePadding && x <= max_x + kResizePadding) ? |
151 index : -1; | 155 index : -1; |
152 } | 156 } |
153 | 157 |
154 } // namespace views | 158 } // namespace views |
OLD | NEW |