| Index: ui/views/controls/textfield/textfield.cc
|
| diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc
|
| index fdfe19b095fc0cdb63d857ba800f0d88b509abf0..f5eb928b5f38e58acdcbfc1b0900493bd94df301 100644
|
| --- a/ui/views/controls/textfield/textfield.cc
|
| +++ b/ui/views/controls/textfield/textfield.cc
|
| @@ -883,8 +883,8 @@ int Textfield::OnPerformDrop(const ui::DropTargetEvent& event) {
|
| model_->InsertText(new_text);
|
| }
|
| skip_input_method_cancel_composition_ = false;
|
| - UpdateAfterChange(true, true);
|
| OnAfterUserAction();
|
| + UpdateAfterChange(true, true);
|
| return move ? ui::DragDropTypes::DRAG_MOVE : ui::DragDropTypes::DRAG_COPY;
|
| }
|
|
|
| @@ -1263,8 +1263,8 @@ void Textfield::SetCompositionText(const ui::CompositionText& composition) {
|
| skip_input_method_cancel_composition_ = true;
|
| model_->SetCompositionText(composition);
|
| skip_input_method_cancel_composition_ = false;
|
| - UpdateAfterChange(true, true);
|
| OnAfterUserAction();
|
| + UpdateAfterChange(true, true);
|
| }
|
|
|
| void Textfield::ConfirmCompositionText() {
|
| @@ -1275,8 +1275,8 @@ void Textfield::ConfirmCompositionText() {
|
| skip_input_method_cancel_composition_ = true;
|
| model_->ConfirmCompositionText();
|
| skip_input_method_cancel_composition_ = false;
|
| - UpdateAfterChange(true, true);
|
| OnAfterUserAction();
|
| + UpdateAfterChange(true, true);
|
| }
|
|
|
| void Textfield::ClearCompositionText() {
|
| @@ -1287,8 +1287,8 @@ void Textfield::ClearCompositionText() {
|
| skip_input_method_cancel_composition_ = true;
|
| model_->CancelCompositionText();
|
| skip_input_method_cancel_composition_ = false;
|
| - UpdateAfterChange(true, true);
|
| OnAfterUserAction();
|
| + UpdateAfterChange(true, true);
|
| }
|
|
|
| void Textfield::InsertText(const base::string16& new_text) {
|
| @@ -1300,8 +1300,8 @@ void Textfield::InsertText(const base::string16& new_text) {
|
| skip_input_method_cancel_composition_ = true;
|
| model_->InsertText(new_text);
|
| skip_input_method_cancel_composition_ = false;
|
| - UpdateAfterChange(true, true);
|
| OnAfterUserAction();
|
| + UpdateAfterChange(true, true);
|
| }
|
|
|
| void Textfield::InsertChar(const ui::KeyEvent& event) {
|
| @@ -1583,8 +1583,8 @@ void Textfield::DoInsertChar(base::char16 ch) {
|
| model_->InsertChar(ch);
|
| skip_input_method_cancel_composition_ = false;
|
|
|
| - UpdateAfterChange(true, true);
|
| OnAfterUserAction();
|
| + UpdateAfterChange(true, true);
|
| }
|
|
|
| gfx::RenderText* Textfield::GetRenderText() const {
|
| @@ -1605,7 +1605,13 @@ base::string16 Textfield::GetSelectionClipboardText() const {
|
| void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) {
|
| DestroyTouchSelection();
|
|
|
| - bool add_to_kill_buffer = false;
|
| + // We only execute the commands enabled in Textfield::IsTextEditCommandEnabled
|
| + // below. Hence don't do a virtual IsTextEditCommandEnabled call.
|
| + if (!Textfield::IsTextEditCommandEnabled(command))
|
| + return;
|
| +
|
| + gfx::SelectionModel selection_model = GetSelectionModel();
|
| + OnBeforeUserAction();
|
|
|
| // Some codepaths may bypass GetCommandForKeyEvent, so any selection-dependent
|
| // modifications of the command should happen here.
|
| @@ -1614,8 +1620,6 @@ void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) {
|
| case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH:
|
| case ui::TextEditCommand::DELETE_TO_END_OF_LINE:
|
| case ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH:
|
| - add_to_kill_buffer = text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD;
|
| - // Fall through.
|
| case ui::TextEditCommand::DELETE_WORD_BACKWARD:
|
| case ui::TextEditCommand::DELETE_WORD_FORWARD:
|
| if (HasSelection())
|
| @@ -1624,44 +1628,61 @@ void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) {
|
| default:
|
| break;
|
| }
|
| + bool text_changed = ExecuteTextEditCommandImpl(command);
|
| + bool cursor_changed = text_changed;
|
|
|
| - // We only execute the commands enabled in Textfield::IsTextEditCommandEnabled
|
| - // below. Hence don't do a virtual IsTextEditCommandEnabled call.
|
| - if (!Textfield::IsTextEditCommandEnabled(command))
|
| - return;
|
| + cursor_changed |= GetSelectionModel() != selection_model;
|
| + if (cursor_changed && HasSelection())
|
| + UpdateSelectionClipboard();
|
| + OnAfterUserAction();
|
| + UpdateAfterChange(text_changed, cursor_changed);
|
| +}
|
| +
|
| +bool Textfield::ExecuteTextEditCommandImpl(ui::TextEditCommand command) {
|
| + bool add_to_kill_buffer = false;
|
| +
|
| + // Some codepaths may bypass GetCommandForKeyEvent, so any selection-dependent
|
| + // modifications of the command should happen here.
|
| + switch (command) {
|
| + case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE:
|
| + case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH:
|
| + case ui::TextEditCommand::DELETE_TO_END_OF_LINE:
|
| + case ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH:
|
| + add_to_kill_buffer = text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD;
|
| + break;
|
| + default:
|
| + break;
|
| + }
|
|
|
| - bool text_changed = false;
|
| - bool cursor_changed = false;
|
| bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT;
|
| gfx::VisualCursorDirection begin = rtl ? gfx::CURSOR_RIGHT : gfx::CURSOR_LEFT;
|
| gfx::VisualCursorDirection end = rtl ? gfx::CURSOR_LEFT : gfx::CURSOR_RIGHT;
|
| - gfx::SelectionModel selection_model = GetSelectionModel();
|
| + bool is_text_changed = false;
|
|
|
| - OnBeforeUserAction();
|
| switch (command) {
|
| case ui::TextEditCommand::DELETE_BACKWARD:
|
| - text_changed = cursor_changed = model_->Backspace(add_to_kill_buffer);
|
| + is_text_changed = model_->Backspace(add_to_kill_buffer);
|
| break;
|
| case ui::TextEditCommand::DELETE_FORWARD:
|
| - text_changed = cursor_changed = model_->Delete(add_to_kill_buffer);
|
| + is_text_changed = model_->Delete(add_to_kill_buffer);
|
| break;
|
| case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE:
|
| case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH:
|
| model_->MoveCursor(gfx::LINE_BREAK, begin, gfx::SELECTION_RETAIN);
|
| - text_changed = cursor_changed = model_->Backspace(add_to_kill_buffer);
|
| + is_text_changed = model_->Backspace(add_to_kill_buffer);
|
| break;
|
| case ui::TextEditCommand::DELETE_TO_END_OF_LINE:
|
| case ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH:
|
| model_->MoveCursor(gfx::LINE_BREAK, end, gfx::SELECTION_RETAIN);
|
| - text_changed = cursor_changed = model_->Delete(add_to_kill_buffer);
|
| + is_text_changed = model_->Delete(add_to_kill_buffer);
|
| break;
|
| case ui::TextEditCommand::DELETE_WORD_BACKWARD:
|
| model_->MoveCursor(gfx::WORD_BREAK, begin, gfx::SELECTION_RETAIN);
|
| - text_changed = cursor_changed = model_->Backspace(add_to_kill_buffer);
|
| + is_text_changed = model_->Backspace(add_to_kill_buffer);
|
| break;
|
| case ui::TextEditCommand::DELETE_WORD_FORWARD:
|
| model_->MoveCursor(gfx::WORD_BREAK, end, gfx::SELECTION_RETAIN);
|
| - text_changed = cursor_changed = model_->Delete(add_to_kill_buffer);
|
| + is_text_changed = model_->Delete(add_to_kill_buffer);
|
| break;
|
| case ui::TextEditCommand::MOVE_BACKWARD:
|
| model_->MoveCursor(gfx::CHARACTER_BREAK, begin, gfx::SELECTION_NONE);
|
| @@ -1761,28 +1782,28 @@ void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) {
|
| kWordSelectionBehavior);
|
| break;
|
| case ui::TextEditCommand::UNDO:
|
| - text_changed = cursor_changed = model_->Undo();
|
| + is_text_changed = model_->Undo();
|
| break;
|
| case ui::TextEditCommand::REDO:
|
| - text_changed = cursor_changed = model_->Redo();
|
| + is_text_changed = model_->Redo();
|
| break;
|
| case ui::TextEditCommand::CUT:
|
| - text_changed = cursor_changed = Cut();
|
| + is_text_changed = Cut();
|
| break;
|
| case ui::TextEditCommand::COPY:
|
| Copy();
|
| break;
|
| case ui::TextEditCommand::PASTE:
|
| - text_changed = cursor_changed = Paste();
|
| + is_text_changed = Paste();
|
| break;
|
| case ui::TextEditCommand::SELECT_ALL:
|
| SelectAll(false);
|
| break;
|
| case ui::TextEditCommand::TRANSPOSE:
|
| - text_changed = cursor_changed = model_->Transpose();
|
| + is_text_changed = model_->Transpose();
|
| break;
|
| case ui::TextEditCommand::YANK:
|
| - text_changed = cursor_changed = model_->Yank();
|
| + is_text_changed = model_->Yank();
|
| break;
|
| case ui::TextEditCommand::INSERT_TEXT:
|
| case ui::TextEditCommand::SET_MARK:
|
| @@ -1791,12 +1812,7 @@ void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) {
|
| NOTREACHED();
|
| break;
|
| }
|
| -
|
| - cursor_changed |= GetSelectionModel() != selection_model;
|
| - if (cursor_changed && HasSelection())
|
| - UpdateSelectionClipboard();
|
| - UpdateAfterChange(text_changed, cursor_changed);
|
| - OnAfterUserAction();
|
| + return is_text_changed;
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
|
|