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

Side by Side Diff: ui/views/controls/textfield/textfield.cc

Issue 2119813002: views::Textfield: Implement yank editing command. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments. Created 4 years, 5 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
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/textfield/textfield.h" 5 #include "ui/views/controls/textfield/textfield.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1486 return readable && model_->HasSelection(); 1486 return readable && model_->HasSelection();
1487 case ui::TextEditCommand::PASTE: 1487 case ui::TextEditCommand::PASTE:
1488 ui::Clipboard::GetForCurrentThread()->ReadText( 1488 ui::Clipboard::GetForCurrentThread()->ReadText(
1489 ui::CLIPBOARD_TYPE_COPY_PASTE, &result); 1489 ui::CLIPBOARD_TYPE_COPY_PASTE, &result);
1490 return editable && !result.empty(); 1490 return editable && !result.empty();
1491 case ui::TextEditCommand::SELECT_ALL: 1491 case ui::TextEditCommand::SELECT_ALL:
1492 return !text().empty(); 1492 return !text().empty();
1493 case ui::TextEditCommand::TRANSPOSE: 1493 case ui::TextEditCommand::TRANSPOSE:
1494 return editable && !model_->HasSelection() && 1494 return editable && !model_->HasSelection() &&
1495 !model_->HasCompositionText(); 1495 !model_->HasCompositionText();
1496 case ui::TextEditCommand::YANK:
1497 return editable;
1496 case ui::TextEditCommand::MOVE_DOWN: 1498 case ui::TextEditCommand::MOVE_DOWN:
1497 case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION: 1499 case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION:
1498 case ui::TextEditCommand::MOVE_PAGE_DOWN: 1500 case ui::TextEditCommand::MOVE_PAGE_DOWN:
1499 case ui::TextEditCommand::MOVE_PAGE_DOWN_AND_MODIFY_SELECTION: 1501 case ui::TextEditCommand::MOVE_PAGE_DOWN_AND_MODIFY_SELECTION:
1500 case ui::TextEditCommand::MOVE_PAGE_UP: 1502 case ui::TextEditCommand::MOVE_PAGE_UP:
1501 case ui::TextEditCommand::MOVE_PAGE_UP_AND_MODIFY_SELECTION: 1503 case ui::TextEditCommand::MOVE_PAGE_UP_AND_MODIFY_SELECTION:
1502 case ui::TextEditCommand::MOVE_UP: 1504 case ui::TextEditCommand::MOVE_UP:
1503 case ui::TextEditCommand::MOVE_UP_AND_MODIFY_SELECTION: 1505 case ui::TextEditCommand::MOVE_UP_AND_MODIFY_SELECTION:
1504 case ui::TextEditCommand::INSERT_TEXT: 1506 case ui::TextEditCommand::INSERT_TEXT:
1505 case ui::TextEditCommand::SET_MARK: 1507 case ui::TextEditCommand::SET_MARK:
(...skipping 30 matching lines...) Expand all
1536 base::string16 Textfield::GetSelectionClipboardText() const { 1538 base::string16 Textfield::GetSelectionClipboardText() const {
1537 base::string16 selection_clipboard_text; 1539 base::string16 selection_clipboard_text;
1538 ui::Clipboard::GetForCurrentThread()->ReadText( 1540 ui::Clipboard::GetForCurrentThread()->ReadText(
1539 ui::CLIPBOARD_TYPE_SELECTION, &selection_clipboard_text); 1541 ui::CLIPBOARD_TYPE_SELECTION, &selection_clipboard_text);
1540 return selection_clipboard_text; 1542 return selection_clipboard_text;
1541 } 1543 }
1542 1544
1543 void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) { 1545 void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) {
1544 DestroyTouchSelection(); 1546 DestroyTouchSelection();
1545 1547
1548 bool add_to_kill_buffer = false;
1549
1546 // Some codepaths may bypass GetCommandForKeyEvent, so any selection-dependent 1550 // Some codepaths may bypass GetCommandForKeyEvent, so any selection-dependent
1547 // modifications of the command should happen here. 1551 // modifications of the command should happen here.
1548 if (HasSelection()) { 1552 switch (command) {
1549 switch (command) { 1553 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE:
1550 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: 1554 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH:
1551 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH: 1555 case ui::TextEditCommand::DELETE_TO_END_OF_LINE:
1552 case ui::TextEditCommand::DELETE_TO_END_OF_LINE: 1556 case ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH:
1553 case ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH: 1557 add_to_kill_buffer = true;
msw 2016/07/22 17:44:03 Should this still be true if there's a selection a
karandeepb 2016/07/25 06:38:11 Yes to both.
1554 case ui::TextEditCommand::DELETE_WORD_BACKWARD: 1558 // Fall through.
1555 case ui::TextEditCommand::DELETE_WORD_FORWARD: 1559 case ui::TextEditCommand::DELETE_WORD_BACKWARD:
1560 case ui::TextEditCommand::DELETE_WORD_FORWARD:
1561 if (HasSelection())
1556 command = ui::TextEditCommand::DELETE_FORWARD; 1562 command = ui::TextEditCommand::DELETE_FORWARD;
1557 break; 1563 break;
1558 default: 1564 default:
1559 break; 1565 break;
1560 }
1561 } 1566 }
1562 1567
1563 // We only execute the commands enabled in Textfield::IsTextEditCommandEnabled 1568 // We only execute the commands enabled in Textfield::IsTextEditCommandEnabled
1564 // below. Hence don't do a virtual IsTextEditCommandEnabled call. 1569 // below. Hence don't do a virtual IsTextEditCommandEnabled call.
1565 if (!Textfield::IsTextEditCommandEnabled(command)) 1570 if (!Textfield::IsTextEditCommandEnabled(command))
1566 return; 1571 return;
1567 1572
1568 bool text_changed = false; 1573 bool text_changed = false;
1569 bool cursor_changed = false; 1574 bool cursor_changed = false;
1570 bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT; 1575 bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT;
1571 gfx::VisualCursorDirection begin = rtl ? gfx::CURSOR_RIGHT : gfx::CURSOR_LEFT; 1576 gfx::VisualCursorDirection begin = rtl ? gfx::CURSOR_RIGHT : gfx::CURSOR_LEFT;
1572 gfx::VisualCursorDirection end = rtl ? gfx::CURSOR_LEFT : gfx::CURSOR_RIGHT; 1577 gfx::VisualCursorDirection end = rtl ? gfx::CURSOR_LEFT : gfx::CURSOR_RIGHT;
1573 gfx::SelectionModel selection_model = GetSelectionModel(); 1578 gfx::SelectionModel selection_model = GetSelectionModel();
1574 1579
1575 OnBeforeUserAction(); 1580 OnBeforeUserAction();
1576 switch (command) { 1581 switch (command) {
1577 case ui::TextEditCommand::DELETE_BACKWARD: 1582 case ui::TextEditCommand::DELETE_BACKWARD:
1578 text_changed = cursor_changed = model_->Backspace(); 1583 text_changed = cursor_changed = model_->Backspace(add_to_kill_buffer);
1579 break; 1584 break;
1580 case ui::TextEditCommand::DELETE_FORWARD: 1585 case ui::TextEditCommand::DELETE_FORWARD:
1581 text_changed = cursor_changed = model_->Delete(); 1586 text_changed = cursor_changed = model_->Delete(add_to_kill_buffer);
1582 break; 1587 break;
1583 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: 1588 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE:
1584 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH: 1589 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH:
1585 model_->MoveCursor(gfx::LINE_BREAK, begin, true); 1590 model_->MoveCursor(gfx::LINE_BREAK, begin, true);
1586 text_changed = cursor_changed = model_->Backspace(); 1591 text_changed = cursor_changed = model_->Backspace(add_to_kill_buffer);
1587 break; 1592 break;
1588 case ui::TextEditCommand::DELETE_TO_END_OF_LINE: 1593 case ui::TextEditCommand::DELETE_TO_END_OF_LINE:
1589 case ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH: 1594 case ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH:
1590 model_->MoveCursor(gfx::LINE_BREAK, end, true); 1595 model_->MoveCursor(gfx::LINE_BREAK, end, true);
1591 text_changed = cursor_changed = model_->Delete(); 1596 text_changed = cursor_changed = model_->Delete(add_to_kill_buffer);
1592 break; 1597 break;
1593 case ui::TextEditCommand::DELETE_WORD_BACKWARD: 1598 case ui::TextEditCommand::DELETE_WORD_BACKWARD:
1594 model_->MoveCursor(gfx::WORD_BREAK, begin, true); 1599 model_->MoveCursor(gfx::WORD_BREAK, begin, true);
1595 text_changed = cursor_changed = model_->Backspace(); 1600 text_changed = cursor_changed = model_->Backspace(add_to_kill_buffer);
1596 break; 1601 break;
1597 case ui::TextEditCommand::DELETE_WORD_FORWARD: 1602 case ui::TextEditCommand::DELETE_WORD_FORWARD:
1598 model_->MoveCursor(gfx::WORD_BREAK, end, true); 1603 model_->MoveCursor(gfx::WORD_BREAK, end, true);
1599 text_changed = cursor_changed = model_->Delete(); 1604 text_changed = cursor_changed = model_->Delete(add_to_kill_buffer);
1600 break; 1605 break;
1601 case ui::TextEditCommand::MOVE_BACKWARD: 1606 case ui::TextEditCommand::MOVE_BACKWARD:
1602 model_->MoveCursor(gfx::CHARACTER_BREAK, begin, false); 1607 model_->MoveCursor(gfx::CHARACTER_BREAK, begin, false);
1603 break; 1608 break;
1604 case ui::TextEditCommand::MOVE_BACKWARD_AND_MODIFY_SELECTION: 1609 case ui::TextEditCommand::MOVE_BACKWARD_AND_MODIFY_SELECTION:
1605 model_->MoveCursor(gfx::CHARACTER_BREAK, begin, true); 1610 model_->MoveCursor(gfx::CHARACTER_BREAK, begin, true);
1606 break; 1611 break;
1607 case ui::TextEditCommand::MOVE_FORWARD: 1612 case ui::TextEditCommand::MOVE_FORWARD:
1608 model_->MoveCursor(gfx::CHARACTER_BREAK, end, false); 1613 model_->MoveCursor(gfx::CHARACTER_BREAK, end, false);
1609 break; 1614 break;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1682 break; 1687 break;
1683 case ui::TextEditCommand::PASTE: 1688 case ui::TextEditCommand::PASTE:
1684 text_changed = cursor_changed = Paste(); 1689 text_changed = cursor_changed = Paste();
1685 break; 1690 break;
1686 case ui::TextEditCommand::SELECT_ALL: 1691 case ui::TextEditCommand::SELECT_ALL:
1687 SelectAll(false); 1692 SelectAll(false);
1688 break; 1693 break;
1689 case ui::TextEditCommand::TRANSPOSE: 1694 case ui::TextEditCommand::TRANSPOSE:
1690 text_changed = cursor_changed = model_->Transpose(); 1695 text_changed = cursor_changed = model_->Transpose();
1691 break; 1696 break;
1697 case ui::TextEditCommand::YANK:
1698 text_changed = cursor_changed = model_->Yank();
1699 break;
1692 case ui::TextEditCommand::MOVE_DOWN: 1700 case ui::TextEditCommand::MOVE_DOWN:
1693 case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION: 1701 case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION:
1694 case ui::TextEditCommand::MOVE_PAGE_DOWN: 1702 case ui::TextEditCommand::MOVE_PAGE_DOWN:
1695 case ui::TextEditCommand::MOVE_PAGE_DOWN_AND_MODIFY_SELECTION: 1703 case ui::TextEditCommand::MOVE_PAGE_DOWN_AND_MODIFY_SELECTION:
1696 case ui::TextEditCommand::MOVE_PAGE_UP: 1704 case ui::TextEditCommand::MOVE_PAGE_UP:
1697 case ui::TextEditCommand::MOVE_PAGE_UP_AND_MODIFY_SELECTION: 1705 case ui::TextEditCommand::MOVE_PAGE_UP_AND_MODIFY_SELECTION:
1698 case ui::TextEditCommand::MOVE_UP: 1706 case ui::TextEditCommand::MOVE_UP:
1699 case ui::TextEditCommand::MOVE_UP_AND_MODIFY_SELECTION: 1707 case ui::TextEditCommand::MOVE_UP_AND_MODIFY_SELECTION:
1700 case ui::TextEditCommand::INSERT_TEXT: 1708 case ui::TextEditCommand::INSERT_TEXT:
1701 case ui::TextEditCommand::SET_MARK: 1709 case ui::TextEditCommand::SET_MARK:
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1968 RequestFocus(); 1976 RequestFocus();
1969 model_->MoveCursorTo(mouse); 1977 model_->MoveCursorTo(mouse);
1970 if (!selection_clipboard_text.empty()) { 1978 if (!selection_clipboard_text.empty()) {
1971 model_->InsertText(selection_clipboard_text); 1979 model_->InsertText(selection_clipboard_text);
1972 UpdateAfterChange(true, true); 1980 UpdateAfterChange(true, true);
1973 } 1981 }
1974 OnAfterUserAction(); 1982 OnAfterUserAction();
1975 } 1983 }
1976 1984
1977 } // namespace views 1985 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698