Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 1470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1481 case ui::TextEditCommand::CUT: | 1481 case ui::TextEditCommand::CUT: |
| 1482 return editable && readable && model_->HasSelection(); | 1482 return editable && readable && model_->HasSelection(); |
| 1483 case ui::TextEditCommand::COPY: | 1483 case ui::TextEditCommand::COPY: |
| 1484 return readable && model_->HasSelection(); | 1484 return readable && model_->HasSelection(); |
| 1485 case ui::TextEditCommand::PASTE: | 1485 case ui::TextEditCommand::PASTE: |
| 1486 ui::Clipboard::GetForCurrentThread()->ReadText( | 1486 ui::Clipboard::GetForCurrentThread()->ReadText( |
| 1487 ui::CLIPBOARD_TYPE_COPY_PASTE, &result); | 1487 ui::CLIPBOARD_TYPE_COPY_PASTE, &result); |
| 1488 return editable && !result.empty(); | 1488 return editable && !result.empty(); |
| 1489 case ui::TextEditCommand::SELECT_ALL: | 1489 case ui::TextEditCommand::SELECT_ALL: |
| 1490 return !text().empty(); | 1490 return !text().empty(); |
| 1491 case ui::TextEditCommand::YANK: | |
| 1492 return editable; | |
| 1491 case ui::TextEditCommand::MOVE_DOWN: | 1493 case ui::TextEditCommand::MOVE_DOWN: |
| 1492 case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION: | 1494 case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION: |
| 1493 case ui::TextEditCommand::MOVE_PAGE_DOWN: | 1495 case ui::TextEditCommand::MOVE_PAGE_DOWN: |
| 1494 case ui::TextEditCommand::MOVE_PAGE_DOWN_AND_MODIFY_SELECTION: | 1496 case ui::TextEditCommand::MOVE_PAGE_DOWN_AND_MODIFY_SELECTION: |
| 1495 case ui::TextEditCommand::MOVE_PAGE_UP: | 1497 case ui::TextEditCommand::MOVE_PAGE_UP: |
| 1496 case ui::TextEditCommand::MOVE_PAGE_UP_AND_MODIFY_SELECTION: | 1498 case ui::TextEditCommand::MOVE_PAGE_UP_AND_MODIFY_SELECTION: |
| 1497 case ui::TextEditCommand::MOVE_UP: | 1499 case ui::TextEditCommand::MOVE_UP: |
| 1498 case ui::TextEditCommand::MOVE_UP_AND_MODIFY_SELECTION: | 1500 case ui::TextEditCommand::MOVE_UP_AND_MODIFY_SELECTION: |
| 1499 case ui::TextEditCommand::INSERT_TEXT: | 1501 case ui::TextEditCommand::INSERT_TEXT: |
| 1500 case ui::TextEditCommand::SET_MARK: | 1502 case ui::TextEditCommand::SET_MARK: |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1531 base::string16 Textfield::GetSelectionClipboardText() const { | 1533 base::string16 Textfield::GetSelectionClipboardText() const { |
| 1532 base::string16 selection_clipboard_text; | 1534 base::string16 selection_clipboard_text; |
| 1533 ui::Clipboard::GetForCurrentThread()->ReadText( | 1535 ui::Clipboard::GetForCurrentThread()->ReadText( |
| 1534 ui::CLIPBOARD_TYPE_SELECTION, &selection_clipboard_text); | 1536 ui::CLIPBOARD_TYPE_SELECTION, &selection_clipboard_text); |
| 1535 return selection_clipboard_text; | 1537 return selection_clipboard_text; |
| 1536 } | 1538 } |
| 1537 | 1539 |
| 1538 void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) { | 1540 void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) { |
| 1539 DestroyTouchSelection(); | 1541 DestroyTouchSelection(); |
| 1540 | 1542 |
| 1543 bool add_to_kill_buffer = false; | |
| 1544 | |
| 1541 // Some codepaths may bypass GetCommandForKeyEvent, so any selection-dependent | 1545 // Some codepaths may bypass GetCommandForKeyEvent, so any selection-dependent |
| 1542 // modifications of the command should happen here. | 1546 // modifications of the command should happen here. |
| 1543 if (HasSelection()) { | 1547 switch (command) { |
| 1544 switch (command) { | 1548 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: |
| 1545 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: | 1549 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH: |
| 1546 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH: | 1550 case ui::TextEditCommand::DELETE_TO_END_OF_LINE: |
| 1547 case ui::TextEditCommand::DELETE_TO_END_OF_LINE: | 1551 case ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH: |
| 1548 case ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH: | 1552 add_to_kill_buffer = true; |
|
karandeepb
2016/07/01 05:49:16
Interestingly Command+X(Cut) also adds text to the
| |
| 1549 case ui::TextEditCommand::DELETE_WORD_BACKWARD: | 1553 // Fall through. |
| 1550 case ui::TextEditCommand::DELETE_WORD_FORWARD: | 1554 case ui::TextEditCommand::DELETE_WORD_BACKWARD: |
| 1555 case ui::TextEditCommand::DELETE_WORD_FORWARD: | |
| 1556 if (HasSelection()) | |
| 1551 command = ui::TextEditCommand::DELETE_FORWARD; | 1557 command = ui::TextEditCommand::DELETE_FORWARD; |
| 1552 break; | 1558 break; |
| 1553 default: | 1559 default: |
| 1554 break; | 1560 break; |
| 1555 } | |
| 1556 } | 1561 } |
| 1557 | 1562 |
| 1558 // We only execute the commands enabled in Textfield::IsTextEditCommandEnabled | 1563 // We only execute the commands enabled in Textfield::IsTextEditCommandEnabled |
| 1559 // below. Hence don't do a virtual IsTextEditCommandEnabled call. | 1564 // below. Hence don't do a virtual IsTextEditCommandEnabled call. |
| 1560 if (!Textfield::IsTextEditCommandEnabled(command)) | 1565 if (!Textfield::IsTextEditCommandEnabled(command)) |
| 1561 return; | 1566 return; |
| 1562 | 1567 |
| 1563 bool text_changed = false; | 1568 bool text_changed = false; |
| 1564 bool cursor_changed = false; | 1569 bool cursor_changed = false; |
| 1565 bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT; | 1570 bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT; |
| 1566 gfx::VisualCursorDirection begin = rtl ? gfx::CURSOR_RIGHT : gfx::CURSOR_LEFT; | 1571 gfx::VisualCursorDirection begin = rtl ? gfx::CURSOR_RIGHT : gfx::CURSOR_LEFT; |
| 1567 gfx::VisualCursorDirection end = rtl ? gfx::CURSOR_LEFT : gfx::CURSOR_RIGHT; | 1572 gfx::VisualCursorDirection end = rtl ? gfx::CURSOR_LEFT : gfx::CURSOR_RIGHT; |
| 1568 gfx::SelectionModel selection_model = GetSelectionModel(); | 1573 gfx::SelectionModel selection_model = GetSelectionModel(); |
| 1569 | 1574 |
| 1570 OnBeforeUserAction(); | 1575 OnBeforeUserAction(); |
| 1571 switch (command) { | 1576 switch (command) { |
| 1572 case ui::TextEditCommand::DELETE_BACKWARD: | 1577 case ui::TextEditCommand::DELETE_BACKWARD: |
| 1573 text_changed = cursor_changed = model_->Backspace(); | 1578 text_changed = cursor_changed = model_->Backspace(add_to_kill_buffer); |
| 1574 break; | 1579 break; |
| 1575 case ui::TextEditCommand::DELETE_FORWARD: | 1580 case ui::TextEditCommand::DELETE_FORWARD: |
| 1576 text_changed = cursor_changed = model_->Delete(); | 1581 text_changed = cursor_changed = model_->Delete(add_to_kill_buffer); |
| 1577 break; | 1582 break; |
| 1578 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: | 1583 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: |
| 1579 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH: | 1584 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH: |
| 1580 model_->MoveCursor(gfx::LINE_BREAK, begin, true); | 1585 model_->MoveCursor(gfx::LINE_BREAK, begin, true); |
| 1581 text_changed = cursor_changed = model_->Backspace(); | 1586 text_changed = cursor_changed = model_->Backspace(add_to_kill_buffer); |
| 1582 break; | 1587 break; |
| 1583 case ui::TextEditCommand::DELETE_TO_END_OF_LINE: | 1588 case ui::TextEditCommand::DELETE_TO_END_OF_LINE: |
| 1584 case ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH: | 1589 case ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH: |
| 1585 model_->MoveCursor(gfx::LINE_BREAK, end, true); | 1590 model_->MoveCursor(gfx::LINE_BREAK, end, true); |
| 1586 text_changed = cursor_changed = model_->Delete(); | 1591 text_changed = cursor_changed = model_->Delete(add_to_kill_buffer); |
| 1587 break; | 1592 break; |
| 1588 case ui::TextEditCommand::DELETE_WORD_BACKWARD: | 1593 case ui::TextEditCommand::DELETE_WORD_BACKWARD: |
| 1589 model_->MoveCursor(gfx::WORD_BREAK, begin, true); | 1594 model_->MoveCursor(gfx::WORD_BREAK, begin, true); |
| 1590 text_changed = cursor_changed = model_->Backspace(); | 1595 text_changed = cursor_changed = model_->Backspace(add_to_kill_buffer); |
| 1591 break; | 1596 break; |
| 1592 case ui::TextEditCommand::DELETE_WORD_FORWARD: | 1597 case ui::TextEditCommand::DELETE_WORD_FORWARD: |
| 1593 model_->MoveCursor(gfx::WORD_BREAK, end, true); | 1598 model_->MoveCursor(gfx::WORD_BREAK, end, true); |
| 1594 text_changed = cursor_changed = model_->Delete(); | 1599 text_changed = cursor_changed = model_->Delete(add_to_kill_buffer); |
| 1595 break; | 1600 break; |
| 1596 case ui::TextEditCommand::MOVE_BACKWARD: | 1601 case ui::TextEditCommand::MOVE_BACKWARD: |
| 1597 model_->MoveCursor(gfx::CHARACTER_BREAK, begin, false); | 1602 model_->MoveCursor(gfx::CHARACTER_BREAK, begin, false); |
| 1598 break; | 1603 break; |
| 1599 case ui::TextEditCommand::MOVE_BACKWARD_AND_MODIFY_SELECTION: | 1604 case ui::TextEditCommand::MOVE_BACKWARD_AND_MODIFY_SELECTION: |
| 1600 model_->MoveCursor(gfx::CHARACTER_BREAK, begin, true); | 1605 model_->MoveCursor(gfx::CHARACTER_BREAK, begin, true); |
| 1601 break; | 1606 break; |
| 1602 case ui::TextEditCommand::MOVE_FORWARD: | 1607 case ui::TextEditCommand::MOVE_FORWARD: |
| 1603 model_->MoveCursor(gfx::CHARACTER_BREAK, end, false); | 1608 model_->MoveCursor(gfx::CHARACTER_BREAK, end, false); |
| 1604 break; | 1609 break; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1674 break; | 1679 break; |
| 1675 case ui::TextEditCommand::COPY: | 1680 case ui::TextEditCommand::COPY: |
| 1676 Copy(); | 1681 Copy(); |
| 1677 break; | 1682 break; |
| 1678 case ui::TextEditCommand::PASTE: | 1683 case ui::TextEditCommand::PASTE: |
| 1679 text_changed = cursor_changed = Paste(); | 1684 text_changed = cursor_changed = Paste(); |
| 1680 break; | 1685 break; |
| 1681 case ui::TextEditCommand::SELECT_ALL: | 1686 case ui::TextEditCommand::SELECT_ALL: |
| 1682 SelectAll(false); | 1687 SelectAll(false); |
| 1683 break; | 1688 break; |
| 1689 case ui::TextEditCommand::YANK: | |
| 1690 text_changed = cursor_changed = model_->Yank(); | |
| 1691 break; | |
| 1684 case ui::TextEditCommand::MOVE_DOWN: | 1692 case ui::TextEditCommand::MOVE_DOWN: |
| 1685 case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION: | 1693 case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION: |
| 1686 case ui::TextEditCommand::MOVE_PAGE_DOWN: | 1694 case ui::TextEditCommand::MOVE_PAGE_DOWN: |
| 1687 case ui::TextEditCommand::MOVE_PAGE_DOWN_AND_MODIFY_SELECTION: | 1695 case ui::TextEditCommand::MOVE_PAGE_DOWN_AND_MODIFY_SELECTION: |
| 1688 case ui::TextEditCommand::MOVE_PAGE_UP: | 1696 case ui::TextEditCommand::MOVE_PAGE_UP: |
| 1689 case ui::TextEditCommand::MOVE_PAGE_UP_AND_MODIFY_SELECTION: | 1697 case ui::TextEditCommand::MOVE_PAGE_UP_AND_MODIFY_SELECTION: |
| 1690 case ui::TextEditCommand::MOVE_UP: | 1698 case ui::TextEditCommand::MOVE_UP: |
| 1691 case ui::TextEditCommand::MOVE_UP_AND_MODIFY_SELECTION: | 1699 case ui::TextEditCommand::MOVE_UP_AND_MODIFY_SELECTION: |
| 1692 case ui::TextEditCommand::INSERT_TEXT: | 1700 case ui::TextEditCommand::INSERT_TEXT: |
| 1693 case ui::TextEditCommand::SET_MARK: | 1701 case ui::TextEditCommand::SET_MARK: |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1960 RequestFocus(); | 1968 RequestFocus(); |
| 1961 model_->MoveCursorTo(mouse); | 1969 model_->MoveCursorTo(mouse); |
| 1962 if (!selection_clipboard_text.empty()) { | 1970 if (!selection_clipboard_text.empty()) { |
| 1963 model_->InsertText(selection_clipboard_text); | 1971 model_->InsertText(selection_clipboard_text); |
| 1964 UpdateAfterChange(true, true); | 1972 UpdateAfterChange(true, true); |
| 1965 } | 1973 } |
| 1966 OnAfterUserAction(); | 1974 OnAfterUserAction(); |
| 1967 } | 1975 } |
| 1968 | 1976 |
| 1969 } // namespace views | 1977 } // namespace views |
| OLD | NEW |