Commit 659dbe9b authored by sky@chromium.org's avatar sky@chromium.org

Makes tree commit edits when focus is lost rather than

cancelling. This matches behavior of the win32 control.

BUG=163711
TEST=covered by unit tests
R=ben@chromium.org


Review URL: https://chromiumcodereview.appspot.com/13646008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192616 0039d316-1c4b-4281-b951-d872f2087c98
parent 44b84ded
...@@ -197,9 +197,11 @@ void TreeView::CommitEdit() { ...@@ -197,9 +197,11 @@ void TreeView::CommitEdit() {
return; return;
DCHECK(selected_node_); DCHECK(selected_node_);
const bool editor_has_focus = editor_->HasFocus();
model_->SetTitle(GetSelectedNode(), editor_->text()); model_->SetTitle(GetSelectedNode(), editor_->text());
CancelEdit(); CancelEdit();
RequestFocus(); if (editor_has_focus)
RequestFocus();
} }
TreeModelNode* TreeView::GetEditingNode() { TreeModelNode* TreeView::GetEditingNode() {
...@@ -457,13 +459,11 @@ bool TreeView::HandleKeyEvent(Textfield* sender, ...@@ -457,13 +459,11 @@ bool TreeView::HandleKeyEvent(Textfield* sender,
} }
} }
void TreeView::OnWillChangeFocus(View* focused_before, void TreeView::OnWillChangeFocus(View* focused_before, View* focused_now) {
View* focused_now) {
} }
void TreeView::OnDidChangeFocus(View* focused_before, void TreeView::OnDidChangeFocus(View* focused_before, View* focused_now) {
View* focused_now) { CommitEdit();
CancelEdit();
} }
gfx::Point TreeView::GetKeyboardContextMenuLocation() { gfx::Point TreeView::GetKeyboardContextMenuLocation() {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/string_util.h" #include "base/string_util.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "ui/base/models/tree_node_model.h" #include "ui/base/models/tree_node_model.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/test/views_test_base.h" #include "ui/views/test/views_test_base.h"
using ui::TreeModel; using ui::TreeModel;
...@@ -381,4 +382,17 @@ TEST_F(TreeViewViewsTest, ExpandOrSelectChild) { ...@@ -381,4 +382,17 @@ TEST_F(TreeViewViewsTest, ExpandOrSelectChild) {
EXPECT_EQ("b1", GetSelectedNodeTitle()); EXPECT_EQ("b1", GetSelectedNodeTitle());
} }
// Verifies edits are committed when focus is lost.
TEST_F(TreeViewViewsTest, CommitOnFocusLost) {
tree_.SetModel(&model_);
tree_.SetSelectedNode(GetNodeByTitle("root"));
ExpandOrSelectChild();
tree_.SetEditable(true);
tree_.StartEditing(GetNodeByTitle("a"));
tree_.editor()->SetText(ASCIIToUTF16("a changed"));
tree_.OnDidChangeFocus(NULL, NULL);
EXPECT_TRUE(GetNodeByTitle("a changed") != NULL);
}
} // namespace views } // namespace views
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment