Chromium Code Reviews| 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_view.h" | 5 #include "ui/views/controls/table/table_view.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/auto_reset.h" | 13 #include "base/auto_reset.h" |
| 14 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | |
| 17 #include "cc/paint/paint_flags.h" | 18 #include "cc/paint/paint_flags.h" |
| 18 #include "ui/accessibility/ax_node_data.h" | 19 #include "ui/accessibility/ax_node_data.h" |
| 19 #include "ui/events/event.h" | 20 #include "ui/events/event.h" |
| 20 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
| 21 #include "ui/gfx/geometry/rect_conversions.h" | 22 #include "ui/gfx/geometry/rect_conversions.h" |
| 22 #include "ui/gfx/image/image_skia.h" | 23 #include "ui/gfx/image/image_skia.h" |
| 23 #include "ui/gfx/skia_util.h" | 24 #include "ui/gfx/skia_util.h" |
| 24 #include "ui/gfx/text_utils.h" | 25 #include "ui/gfx/text_utils.h" |
| 25 #include "ui/native_theme/native_theme.h" | 26 #include "ui/native_theme/native_theme.h" |
| 26 #include "ui/views/controls/scroll_view.h" | 27 #include "ui/views/controls/scroll_view.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 columns_(columns), | 134 columns_(columns), |
| 134 header_(NULL), | 135 header_(NULL), |
| 135 table_type_(table_type), | 136 table_type_(table_type), |
| 136 single_selection_(single_selection), | 137 single_selection_(single_selection), |
| 137 select_on_remove_(true), | 138 select_on_remove_(true), |
| 138 observer_(NULL), | 139 observer_(NULL), |
| 139 row_height_(font_list_.GetHeight() + kTextVerticalPadding * 2), | 140 row_height_(font_list_.GetHeight() + kTextVerticalPadding * 2), |
| 140 last_parent_width_(0), | 141 last_parent_width_(0), |
| 141 layout_width_(0), | 142 layout_width_(0), |
| 142 grouper_(NULL), | 143 grouper_(NULL), |
| 143 in_set_visible_column_width_(false) { | 144 in_set_visible_column_width_(false), |
| 145 weak_factory_(this) { | |
| 144 for (size_t i = 0; i < columns.size(); ++i) { | 146 for (size_t i = 0; i < columns.size(); ++i) { |
| 145 VisibleColumn visible_column; | 147 VisibleColumn visible_column; |
| 146 visible_column.column = columns[i]; | 148 visible_column.column = columns[i]; |
| 147 visible_columns_.push_back(visible_column); | 149 visible_columns_.push_back(visible_column); |
| 148 } | 150 } |
| 149 // Always focusable, even on Mac (consistent with NSTableView). | 151 // Always focusable, even on Mac (consistent with NSTableView). |
| 150 SetFocusBehavior(FocusBehavior::ALWAYS); | 152 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 151 SetModel(model); | 153 SetModel(model); |
| 152 } | 154 } |
| 153 | 155 |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 618 kGroupingIndicatorSize / 2, grouping_flags); | 620 kGroupingIndicatorSize / 2, grouping_flags); |
| 619 i = last + 1; | 621 i = last + 1; |
| 620 } | 622 } |
| 621 } | 623 } |
| 622 | 624 |
| 623 void TableView::OnFocus() { | 625 void TableView::OnFocus() { |
| 624 ScrollView* scroll_view = ScrollView::GetScrollViewForContents(this); | 626 ScrollView* scroll_view = ScrollView::GetScrollViewForContents(this); |
| 625 if (scroll_view) | 627 if (scroll_view) |
| 626 scroll_view->SetHasFocusIndicator(true); | 628 scroll_view->SetHasFocusIndicator(true); |
| 627 | 629 |
| 628 if (selection_model_.active() == -1 && RowCount()) | 630 base::ThreadTaskRunnerHandle::Get()->PostTask( |
|
sky
2017/03/30 03:25:49
We shouldn't need to delay this. The press handler
| |
| 629 SelectByViewIndex(0); | 631 FROM_HERE, base::Bind(&TableView::SelectFirstRowIfNoneSelected, |
| 632 weak_factory_.GetWeakPtr())); | |
| 630 | 633 |
| 631 SchedulePaintForSelection(); | 634 SchedulePaintForSelection(); |
| 632 NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true); | 635 NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true); |
| 633 } | 636 } |
| 634 | 637 |
| 635 void TableView::OnBlur() { | 638 void TableView::OnBlur() { |
| 636 ScrollView* scroll_view = ScrollView::GetScrollViewForContents(this); | 639 ScrollView* scroll_view = ScrollView::GetScrollViewForContents(this); |
| 637 if (scroll_view) | 640 if (scroll_view) |
| 638 scroll_view->SetHasFocusIndicator(false); | 641 scroll_view->SetHasFocusIndicator(false); |
| 639 SchedulePaintForSelection(); | 642 SchedulePaintForSelection(); |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 949 | 952 |
| 950 if (tooltip) | 953 if (tooltip) |
| 951 *tooltip = text; | 954 *tooltip = text; |
| 952 if (tooltip_origin) { | 955 if (tooltip_origin) { |
| 953 tooltip_origin->SetPoint(cell_bounds.x(), | 956 tooltip_origin->SetPoint(cell_bounds.x(), |
| 954 cell_bounds.y() + kTextVerticalPadding); | 957 cell_bounds.y() + kTextVerticalPadding); |
| 955 } | 958 } |
| 956 return true; | 959 return true; |
| 957 } | 960 } |
| 958 | 961 |
| 962 void TableView::SelectFirstRowIfNoneSelected() { | |
| 963 if (HasFocus() && selection_model_.active() == -1 && RowCount()) | |
| 964 SelectByViewIndex(0); | |
| 965 } | |
| 966 | |
| 959 } // namespace views | 967 } // namespace views |
| OLD | NEW |