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 "third_party/skia/include/core/SkColor.h" | 7 #include "third_party/skia/include/core/SkColor.h" |
| 8 #include "ui/base/cursor/cursor.h" |
8 #include "ui/gfx/canvas.h" | 9 #include "ui/gfx/canvas.h" |
9 #include "ui/gfx/text_utils.h" | 10 #include "ui/gfx/text_utils.h" |
10 #include "ui/native_theme/native_theme.h" | 11 #include "ui/native_theme/native_theme.h" |
11 #include "ui/views/background.h" | 12 #include "ui/views/background.h" |
12 #include "ui/views/controls/table/table_utils.h" | 13 #include "ui/views/controls/table/table_utils.h" |
13 #include "ui/views/controls/table/table_view.h" | 14 #include "ui/views/controls/table/table_view.h" |
14 | 15 |
15 #if defined(USE_AURA) | |
16 #include "ui/base/cursor/cursor.h" | |
17 #endif | |
18 | |
19 namespace views { | 16 namespace views { |
20 | 17 |
21 namespace { | 18 namespace { |
22 | 19 |
23 const int kVerticalPadding = 4; | 20 const int kVerticalPadding = 4; |
24 | 21 |
25 // The minimum width we allow a column to go down to. | 22 // The minimum width we allow a column to go down to. |
26 const int kMinColumnWidth = 10; | 23 const int kMinColumnWidth = 10; |
27 | 24 |
28 // Distace from edge columns can be resized by. | 25 // Distace from edge columns can be resized by. |
29 const int kResizePadding = 5; | 26 const int kResizePadding = 5; |
30 | 27 |
31 // Amount of space above/below the separator. | 28 // Amount of space above/below the separator. |
32 const int kSeparatorPadding = 4; | 29 const int kSeparatorPadding = 4; |
33 | 30 |
34 const SkColor kTextColor = SK_ColorBLACK; | 31 const SkColor kTextColor = SK_ColorBLACK; |
35 const SkColor kBackgroundColor1 = SkColorSetRGB(0xF9, 0xF9, 0xF9); | 32 const SkColor kBackgroundColor1 = SkColorSetRGB(0xF9, 0xF9, 0xF9); |
36 const SkColor kBackgroundColor2 = SkColorSetRGB(0xE8, 0xE8, 0xE8); | 33 const SkColor kBackgroundColor2 = SkColorSetRGB(0xE8, 0xE8, 0xE8); |
37 const SkColor kSeparatorColor = SkColorSetRGB(0xAA, 0xAA, 0xAA); | 34 const SkColor kSeparatorColor = SkColorSetRGB(0xAA, 0xAA, 0xAA); |
38 | 35 |
39 // Size of the sort indicator (doesn't include padding). | 36 // Size of the sort indicator (doesn't include padding). |
40 const int kSortIndicatorSize = 8; | 37 const int kSortIndicatorSize = 8; |
41 | 38 |
42 gfx::NativeCursor GetResizeCursor() { | |
43 #if defined(USE_AURA) | |
44 return ui::kCursorColumnResize; | |
45 #elif defined(OS_WIN) | |
46 static HCURSOR g_hand_cursor = LoadCursor(NULL, IDC_SIZEWE); | |
47 return g_hand_cursor; | |
48 #endif | |
49 } | |
50 | |
51 } // namespace | 39 } // namespace |
52 | 40 |
53 // static | 41 // static |
54 const int TableHeader::kHorizontalPadding = 7; | 42 const int TableHeader::kHorizontalPadding = 7; |
55 // static | 43 // static |
56 const int TableHeader::kSortIndicatorWidth = kSortIndicatorSize + | 44 const int TableHeader::kSortIndicatorWidth = kSortIndicatorSize + |
57 TableHeader::kHorizontalPadding * 2; | 45 TableHeader::kHorizontalPadding * 2; |
58 | 46 |
59 typedef std::vector<TableView::VisibleColumn> Columns; | 47 typedef std::vector<TableView::VisibleColumn> Columns; |
60 | 48 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 } | 157 } |
170 } | 158 } |
171 } | 159 } |
172 | 160 |
173 gfx::Size TableHeader::GetPreferredSize() { | 161 gfx::Size TableHeader::GetPreferredSize() { |
174 return gfx::Size(1, kVerticalPadding * 2 + font_list_.GetHeight()); | 162 return gfx::Size(1, kVerticalPadding * 2 + font_list_.GetHeight()); |
175 } | 163 } |
176 | 164 |
177 gfx::NativeCursor TableHeader::GetCursor(const ui::MouseEvent& event) { | 165 gfx::NativeCursor TableHeader::GetCursor(const ui::MouseEvent& event) { |
178 return GetResizeColumn(GetMirroredXInView(event.x())) != -1 ? | 166 return GetResizeColumn(GetMirroredXInView(event.x())) != -1 ? |
179 GetResizeCursor() : View::GetCursor(event); | 167 ui::kCursorColumnResize : View::GetCursor(event); |
180 } | 168 } |
181 | 169 |
182 bool TableHeader::OnMousePressed(const ui::MouseEvent& event) { | 170 bool TableHeader::OnMousePressed(const ui::MouseEvent& event) { |
183 if (event.IsOnlyLeftMouseButton()) { | 171 if (event.IsOnlyLeftMouseButton()) { |
184 StartResize(event); | 172 StartResize(event); |
185 return true; | 173 return true; |
186 } | 174 } |
187 | 175 |
188 // Return false so that context menus on ancestors work. | 176 // Return false so that context menus on ancestors work. |
189 return false; | 177 return false; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 if (index > 0 && x >= column.x - kResizePadding && | 268 if (index > 0 && x >= column.x - kResizePadding && |
281 x <= column.x + kResizePadding) { | 269 x <= column.x + kResizePadding) { |
282 return index - 1; | 270 return index - 1; |
283 } | 271 } |
284 const int max_x = column.x + column.width; | 272 const int max_x = column.x + column.width; |
285 return (x >= max_x - kResizePadding && x <= max_x + kResizePadding) ? | 273 return (x >= max_x - kResizePadding && x <= max_x + kResizePadding) ? |
286 index : -1; | 274 index : -1; |
287 } | 275 } |
288 | 276 |
289 } // namespace views | 277 } // namespace views |
OLD | NEW |