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

Side by Side Diff: ui/views/controls/tree/tree_view.cc

Issue 13646008: Makes tree commit edits when focus is lost rather than (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 | « no previous file | ui/views/controls/tree/tree_view_unittest.cc » ('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) 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/tree/tree_view.h" 5 #include "ui/views/controls/tree/tree_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 190
191 RemoveAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); 191 RemoveAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE));
192 RemoveAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); 192 RemoveAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
193 } 193 }
194 194
195 void TreeView::CommitEdit() { 195 void TreeView::CommitEdit() {
196 if (!editing_) 196 if (!editing_)
197 return; 197 return;
198 198
199 DCHECK(selected_node_); 199 DCHECK(selected_node_);
200 const bool editor_has_focus = editor_->HasFocus();
200 model_->SetTitle(GetSelectedNode(), editor_->text()); 201 model_->SetTitle(GetSelectedNode(), editor_->text());
201 CancelEdit(); 202 CancelEdit();
202 RequestFocus(); 203 if (editor_has_focus)
204 RequestFocus();
203 } 205 }
204 206
205 TreeModelNode* TreeView::GetEditingNode() { 207 TreeModelNode* TreeView::GetEditingNode() {
206 return editing_ ? selected_node_->model_node() : NULL; 208 return editing_ ? selected_node_->model_node() : NULL;
207 } 209 }
208 210
209 void TreeView::SetSelectedNode(TreeModelNode* model_node) { 211 void TreeView::SetSelectedNode(TreeModelNode* model_node) {
210 if (editing_ || model_node != selected_node_) 212 if (editing_ || model_node != selected_node_)
211 CancelEdit(); 213 CancelEdit();
212 if (model_node && model_->GetParent(model_node)) 214 if (model_node && model_->GetParent(model_node))
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 case ui::VKEY_ESCAPE: 452 case ui::VKEY_ESCAPE:
451 CancelEdit(); 453 CancelEdit();
452 RequestFocus(); 454 RequestFocus();
453 return true; 455 return true;
454 456
455 default: 457 default:
456 return false; 458 return false;
457 } 459 }
458 } 460 }
459 461
460 void TreeView::OnWillChangeFocus(View* focused_before, 462 void TreeView::OnWillChangeFocus(View* focused_before, View* focused_now) {
461 View* focused_now) {
462 } 463 }
463 464
464 void TreeView::OnDidChangeFocus(View* focused_before, 465 void TreeView::OnDidChangeFocus(View* focused_before, View* focused_now) {
465 View* focused_now) { 466 CommitEdit();
466 CancelEdit();
467 } 467 }
468 468
469 gfx::Point TreeView::GetKeyboardContextMenuLocation() { 469 gfx::Point TreeView::GetKeyboardContextMenuLocation() {
470 int y = height() / 2; 470 int y = height() / 2;
471 if (selected_node_) { 471 if (selected_node_) {
472 gfx::Rect node_bounds(GetBoundsForNode(selected_node_)); 472 gfx::Rect node_bounds(GetBoundsForNode(selected_node_));
473 gfx::Rect vis_bounds(GetVisibleBounds()); 473 gfx::Rect vis_bounds(GetVisibleBounds());
474 if (node_bounds.y() >= vis_bounds.y() && 474 if (node_bounds.y() >= vis_bounds.y() &&
475 node_bounds.y() < vis_bounds.bottom()) { 475 node_bounds.y() < vis_bounds.bottom()) {
476 y = node_bounds.y(); 476 y = node_bounds.y();
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 if (!is_expanded_) 969 if (!is_expanded_)
970 return max_width; 970 return max_width;
971 for (int i = 0; i < child_count(); ++i) { 971 for (int i = 0; i < child_count(); ++i) {
972 max_width = std::max(max_width, 972 max_width = std::max(max_width,
973 GetChild(i)->GetMaxWidth(indent, depth + 1)); 973 GetChild(i)->GetMaxWidth(indent, depth + 1));
974 } 974 }
975 return max_width; 975 return max_width;
976 } 976 }
977 977
978 } // namespace views 978 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | ui/views/controls/tree/tree_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698