Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1025)

Side by Side Diff: views/controls/table/group_table_view.cc

Issue 3337006: Revert 58388 - Revert 58215 - Revert 58186 - Move the keyboard files from bas... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/controls/table/group_table_view.h ('k') | views/controls/table/native_table_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 for (int i = group_range.start; 54 for (int i = group_range.start;
55 i < group_range.start + group_range.length; ++i) { 55 i < group_range.start + group_range.length; ++i) {
56 SetSelectedState(i, true); 56 SetSelectedState(i, true);
57 } 57 }
58 } 58 }
59 index += group_range.length; 59 index += group_range.length;
60 } 60 }
61 } 61 }
62 } 62 }
63 63
64 bool GroupTableView::OnKeyDown(app::KeyboardCode virtual_keycode) { 64 bool GroupTableView::OnKeyDown(base::KeyboardCode virtual_keycode) {
65 // In a list view, multiple items can be selected but only one item has the 65 // In a list view, multiple items can be selected but only one item has the
66 // focus. This creates a problem when the arrow keys are used for navigating 66 // focus. This creates a problem when the arrow keys are used for navigating
67 // between items in the list view. An example will make this more clear: 67 // between items in the list view. An example will make this more clear:
68 // 68 //
69 // Suppose we have 5 items in the list view, and three of these items are 69 // Suppose we have 5 items in the list view, and three of these items are
70 // part of one group: 70 // part of one group:
71 // 71 //
72 // Index0: ItemA (No Group) 72 // Index0: ItemA (No Group)
73 // Index1: ItemB (GroupX) 73 // Index1: ItemB (GroupX)
74 // Index2: ItemC (GroupX) 74 // Index2: ItemC (GroupX)
75 // Index3: ItemD (GroupX) 75 // Index3: ItemD (GroupX)
76 // Index4: ItemE (No Group) 76 // Index4: ItemE (No Group)
77 // 77 //
78 // When GroupX is selected (say, by clicking on ItemD with the mouse), 78 // When GroupX is selected (say, by clicking on ItemD with the mouse),
79 // GroupTableView::SyncSelection() will make sure ItemB, ItemC and ItemD are 79 // GroupTableView::SyncSelection() will make sure ItemB, ItemC and ItemD are
80 // selected. Also, the item with the focus will be ItemD (simply because 80 // selected. Also, the item with the focus will be ItemD (simply because
81 // this is the item the user happened to click on). If then the UP arrow is 81 // this is the item the user happened to click on). If then the UP arrow is
82 // pressed once, the focus will be switched to ItemC and not to ItemA and the 82 // pressed once, the focus will be switched to ItemC and not to ItemA and the
83 // end result is that we are stuck in GroupX even though the intention was to 83 // end result is that we are stuck in GroupX even though the intention was to
84 // switch to ItemA. 84 // switch to ItemA.
85 // 85 //
86 // For that exact reason, we need to set the focus appropriately when we 86 // For that exact reason, we need to set the focus appropriately when we
87 // detect that one of the arrow keys is pressed. Thus, when it comes time 87 // detect that one of the arrow keys is pressed. Thus, when it comes time
88 // for the list view control to actually switch the focus, the right item 88 // for the list view control to actually switch the focus, the right item
89 // will be selected. 89 // will be selected.
90 if ((virtual_keycode != app::VKEY_UP) && 90 if ((virtual_keycode != base::VKEY_UP) &&
91 (virtual_keycode != app::VKEY_DOWN)) { 91 (virtual_keycode != base::VKEY_DOWN)) {
92 return TableView::OnKeyDown(virtual_keycode); 92 return TableView::OnKeyDown(virtual_keycode);
93 } 93 }
94 94
95 // We start by finding the index of the item with the focus. If no item 95 // We start by finding the index of the item with the focus. If no item
96 // currently has the focus, then this routine doesn't do anything. 96 // currently has the focus, then this routine doesn't do anything.
97 int focused_index; 97 int focused_index;
98 int row_count = model_->RowCount(); 98 int row_count = model_->RowCount();
99 for (focused_index = 0; focused_index < row_count; focused_index++) { 99 for (focused_index = 0; focused_index < row_count; focused_index++) {
100 if (ItemHasTheFocus(focused_index)) { 100 if (ItemHasTheFocus(focused_index)) {
101 break; 101 break;
102 } 102 }
103 } 103 }
104 104
105 if (focused_index == row_count) 105 if (focused_index == row_count)
106 return false; 106 return false;
107 107
108 DCHECK_LT(focused_index, row_count); 108 DCHECK_LT(focused_index, row_count);
109 109
110 // Nothing to do if the item which has the focus is not part of a group. 110 // Nothing to do if the item which has the focus is not part of a group.
111 GroupRange group_range; 111 GroupRange group_range;
112 model_->GetGroupRangeForItem(focused_index, &group_range); 112 model_->GetGroupRangeForItem(focused_index, &group_range);
113 if (group_range.length == 1) 113 if (group_range.length == 1)
114 return false; 114 return false;
115 115
116 // If the user pressed the UP key, then the focus should be set to the 116 // If the user pressed the UP key, then the focus should be set to the
117 // topmost element in the group. If the user pressed the DOWN key, the focus 117 // topmost element in the group. If the user pressed the DOWN key, the focus
118 // should be set to the bottommost element. 118 // should be set to the bottommost element.
119 if (virtual_keycode == app::VKEY_UP) { 119 if (virtual_keycode == base::VKEY_UP) {
120 SetFocusOnItem(group_range.start); 120 SetFocusOnItem(group_range.start);
121 } else { 121 } else {
122 DCHECK_EQ(virtual_keycode, app::VKEY_DOWN); 122 DCHECK_EQ(virtual_keycode, base::VKEY_DOWN);
123 SetFocusOnItem(group_range.start + group_range.length - 1); 123 SetFocusOnItem(group_range.start + group_range.length - 1);
124 } 124 }
125 125
126 return false; 126 return false;
127 } 127 }
128 128
129 void GroupTableView::PrepareForSort() { 129 void GroupTableView::PrepareForSort() {
130 GroupRange range; 130 GroupRange range;
131 int row_count = RowCount(); 131 int row_count = RowCount();
132 model_index_to_range_start_map_.clear(); 132 model_index_to_range_start_map_.clear();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 } 186 }
187 SelectObject(hdc, hPenOld); 187 SelectObject(hdc, hPenOld);
188 DeleteObject(hPen); 188 DeleteObject(hPen);
189 } 189 }
190 190
191 std::string GroupTableView::GetClassName() const { 191 std::string GroupTableView::GetClassName() const {
192 return kViewClassName; 192 return kViewClassName;
193 } 193 }
194 194
195 } // namespace views 195 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/table/group_table_view.h ('k') | views/controls/table/native_table_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698