| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "views/controls/table/group_table_view.h" | 5 #include "views/controls/table/group_table_view.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/task.h" | 9 #include "base/task.h" |
| 10 #include "gfx/canvas.h" | 10 #include "gfx/canvas.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 for (int i = group_range.start; | 56 for (int i = group_range.start; |
| 57 i < group_range.start + group_range.length; ++i) { | 57 i < group_range.start + group_range.length; ++i) { |
| 58 SetSelectedState(i, true); | 58 SetSelectedState(i, true); |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 index += group_range.length; | 61 index += group_range.length; |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 bool GroupTableView::OnKeyDown(app::KeyboardCode virtual_keycode) { | 66 bool GroupTableView::OnKeyDown(ui::KeyboardCode virtual_keycode) { |
| 67 // In a list view, multiple items can be selected but only one item has the | 67 // In a list view, multiple items can be selected but only one item has the |
| 68 // focus. This creates a problem when the arrow keys are used for navigating | 68 // focus. This creates a problem when the arrow keys are used for navigating |
| 69 // between items in the list view. An example will make this more clear: | 69 // between items in the list view. An example will make this more clear: |
| 70 // | 70 // |
| 71 // Suppose we have 5 items in the list view, and three of these items are | 71 // Suppose we have 5 items in the list view, and three of these items are |
| 72 // part of one group: | 72 // part of one group: |
| 73 // | 73 // |
| 74 // Index0: ItemA (No Group) | 74 // Index0: ItemA (No Group) |
| 75 // Index1: ItemB (GroupX) | 75 // Index1: ItemB (GroupX) |
| 76 // Index2: ItemC (GroupX) | 76 // Index2: ItemC (GroupX) |
| 77 // Index3: ItemD (GroupX) | 77 // Index3: ItemD (GroupX) |
| 78 // Index4: ItemE (No Group) | 78 // Index4: ItemE (No Group) |
| 79 // | 79 // |
| 80 // When GroupX is selected (say, by clicking on ItemD with the mouse), | 80 // When GroupX is selected (say, by clicking on ItemD with the mouse), |
| 81 // GroupTableView::SyncSelection() will make sure ItemB, ItemC and ItemD are | 81 // GroupTableView::SyncSelection() will make sure ItemB, ItemC and ItemD are |
| 82 // selected. Also, the item with the focus will be ItemD (simply because | 82 // selected. Also, the item with the focus will be ItemD (simply because |
| 83 // this is the item the user happened to click on). If then the UP arrow is | 83 // this is the item the user happened to click on). If then the UP arrow is |
| 84 // pressed once, the focus will be switched to ItemC and not to ItemA and the | 84 // pressed once, the focus will be switched to ItemC and not to ItemA and the |
| 85 // end result is that we are stuck in GroupX even though the intention was to | 85 // end result is that we are stuck in GroupX even though the intention was to |
| 86 // switch to ItemA. | 86 // switch to ItemA. |
| 87 // | 87 // |
| 88 // For that exact reason, we need to set the focus appropriately when we | 88 // For that exact reason, we need to set the focus appropriately when we |
| 89 // detect that one of the arrow keys is pressed. Thus, when it comes time | 89 // detect that one of the arrow keys is pressed. Thus, when it comes time |
| 90 // for the list view control to actually switch the focus, the right item | 90 // for the list view control to actually switch the focus, the right item |
| 91 // will be selected. | 91 // will be selected. |
| 92 if ((virtual_keycode != app::VKEY_UP) && | 92 if ((virtual_keycode != ui::VKEY_UP) && |
| 93 (virtual_keycode != app::VKEY_DOWN)) { | 93 (virtual_keycode != ui::VKEY_DOWN)) { |
| 94 return TableView::OnKeyDown(virtual_keycode); | 94 return TableView::OnKeyDown(virtual_keycode); |
| 95 } | 95 } |
| 96 | 96 |
| 97 // We start by finding the index of the item with the focus. If no item | 97 // We start by finding the index of the item with the focus. If no item |
| 98 // currently has the focus, then this routine doesn't do anything. | 98 // currently has the focus, then this routine doesn't do anything. |
| 99 int focused_index; | 99 int focused_index; |
| 100 int row_count = model_->RowCount(); | 100 int row_count = model_->RowCount(); |
| 101 for (focused_index = 0; focused_index < row_count; focused_index++) { | 101 for (focused_index = 0; focused_index < row_count; focused_index++) { |
| 102 if (ItemHasTheFocus(focused_index)) { | 102 if (ItemHasTheFocus(focused_index)) { |
| 103 break; | 103 break; |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 | 106 |
| 107 if (focused_index == row_count) | 107 if (focused_index == row_count) |
| 108 return false; | 108 return false; |
| 109 | 109 |
| 110 DCHECK_LT(focused_index, row_count); | 110 DCHECK_LT(focused_index, row_count); |
| 111 | 111 |
| 112 // Nothing to do if the item which has the focus is not part of a group. | 112 // Nothing to do if the item which has the focus is not part of a group. |
| 113 GroupRange group_range; | 113 GroupRange group_range; |
| 114 model_->GetGroupRangeForItem(focused_index, &group_range); | 114 model_->GetGroupRangeForItem(focused_index, &group_range); |
| 115 if (group_range.length == 1) | 115 if (group_range.length == 1) |
| 116 return false; | 116 return false; |
| 117 | 117 |
| 118 // If the user pressed the UP key, then the focus should be set to the | 118 // If the user pressed the UP key, then the focus should be set to the |
| 119 // topmost element in the group. If the user pressed the DOWN key, the focus | 119 // topmost element in the group. If the user pressed the DOWN key, the focus |
| 120 // should be set to the bottommost element. | 120 // should be set to the bottommost element. |
| 121 if (virtual_keycode == app::VKEY_UP) { | 121 if (virtual_keycode == ui::VKEY_UP) { |
| 122 SetFocusOnItem(group_range.start); | 122 SetFocusOnItem(group_range.start); |
| 123 } else { | 123 } else { |
| 124 DCHECK_EQ(virtual_keycode, app::VKEY_DOWN); | 124 DCHECK_EQ(virtual_keycode, ui::VKEY_DOWN); |
| 125 SetFocusOnItem(group_range.start + group_range.length - 1); | 125 SetFocusOnItem(group_range.start + group_range.length - 1); |
| 126 } | 126 } |
| 127 | 127 |
| 128 return false; | 128 return false; |
| 129 } | 129 } |
| 130 | 130 |
| 131 void GroupTableView::PrepareForSort() { | 131 void GroupTableView::PrepareForSort() { |
| 132 GroupRange range; | 132 GroupRange range; |
| 133 int row_count = RowCount(); | 133 int row_count = RowCount(); |
| 134 model_index_to_range_start_map_.clear(); | 134 model_index_to_range_start_map_.clear(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 } | 191 } |
| 192 SelectObject(hdc, hPenOld); | 192 SelectObject(hdc, hPenOld); |
| 193 DeleteObject(hPen); | 193 DeleteObject(hPen); |
| 194 } | 194 } |
| 195 | 195 |
| 196 std::string GroupTableView::GetClassName() const { | 196 std::string GroupTableView::GetClassName() const { |
| 197 return kViewClassName; | 197 return kViewClassName; |
| 198 } | 198 } |
| 199 | 199 |
| 200 } // namespace views | 200 } // namespace views |
| OLD | NEW |