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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 54 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
55 #include "base/strings/utf_string_conversions.h" | 55 #include "base/strings/utf_string_conversions.h" |
56 #include "ui/base/ime/linux/text_edit_command_auralinux.h" | 56 #include "ui/base/ime/linux/text_edit_command_auralinux.h" |
57 #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" | 57 #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" |
58 #endif | 58 #endif |
59 | 59 |
60 namespace views { | 60 namespace views { |
61 | 61 |
62 namespace { | 62 namespace { |
63 | 63 |
64 #if defined(OS_MACOSX) | |
65 const gfx::SelectionBehavior kLineSelectionBehavior = gfx::SELECTION_EXTEND; | |
66 const gfx::SelectionBehavior kWordSelectionBehavior = gfx::SELECTION_CARET; | |
67 #else | |
68 const gfx::SelectionBehavior kLineSelectionBehavior = gfx::SELECTION_RETAIN; | |
69 const gfx::SelectionBehavior kWordSelectionBehavior = gfx::SELECTION_RETAIN; | |
70 #endif | |
71 | |
64 // Default placeholder text color. | 72 // Default placeholder text color. |
65 const SkColor kDefaultPlaceholderTextColor = SK_ColorLTGRAY; | 73 const SkColor kDefaultPlaceholderTextColor = SK_ColorLTGRAY; |
66 | 74 |
67 void ConvertRectToScreen(const View* src, gfx::Rect* r) { | 75 void ConvertRectToScreen(const View* src, gfx::Rect* r) { |
68 DCHECK(src); | 76 DCHECK(src); |
69 | 77 |
70 gfx::Point new_origin = r->origin(); | 78 gfx::Point new_origin = r->origin(); |
71 View::ConvertPointToScreen(src, &new_origin); | 79 View::ConvertPointToScreen(src, &new_origin); |
72 r->set_origin(new_origin); | 80 r->set_origin(new_origin); |
73 } | 81 } |
(...skipping 1387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1461 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION: | 1469 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION: |
1462 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_PARAGRAPH: | 1470 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_PARAGRAPH: |
1463 case ui::TextEditCommand:: | 1471 case ui::TextEditCommand:: |
1464 MOVE_TO_BEGINNING_OF_PARAGRAPH_AND_MODIFY_SELECTION: | 1472 MOVE_TO_BEGINNING_OF_PARAGRAPH_AND_MODIFY_SELECTION: |
1465 case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT: | 1473 case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT: |
1466 case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT_AND_MODIFY_SELECTION: | 1474 case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT_AND_MODIFY_SELECTION: |
1467 case ui::TextEditCommand::MOVE_TO_END_OF_LINE: | 1475 case ui::TextEditCommand::MOVE_TO_END_OF_LINE: |
1468 case ui::TextEditCommand::MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION: | 1476 case ui::TextEditCommand::MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION: |
1469 case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH: | 1477 case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH: |
1470 case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH_AND_MODIFY_SELECTION: | 1478 case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH_AND_MODIFY_SELECTION: |
1479 case ui::TextEditCommand::MOVE_PARAGRAPH_FORWARD_AND_MODIFY_SELECTION: | |
1480 case ui::TextEditCommand::MOVE_PARAGRAPH_BACKWARD_AND_MODIFY_SELECTION: | |
1471 case ui::TextEditCommand::MOVE_WORD_BACKWARD: | 1481 case ui::TextEditCommand::MOVE_WORD_BACKWARD: |
1472 case ui::TextEditCommand::MOVE_WORD_BACKWARD_AND_MODIFY_SELECTION: | 1482 case ui::TextEditCommand::MOVE_WORD_BACKWARD_AND_MODIFY_SELECTION: |
1473 case ui::TextEditCommand::MOVE_WORD_FORWARD: | 1483 case ui::TextEditCommand::MOVE_WORD_FORWARD: |
1474 case ui::TextEditCommand::MOVE_WORD_FORWARD_AND_MODIFY_SELECTION: | 1484 case ui::TextEditCommand::MOVE_WORD_FORWARD_AND_MODIFY_SELECTION: |
1475 case ui::TextEditCommand::MOVE_WORD_LEFT: | 1485 case ui::TextEditCommand::MOVE_WORD_LEFT: |
1476 case ui::TextEditCommand::MOVE_WORD_LEFT_AND_MODIFY_SELECTION: | 1486 case ui::TextEditCommand::MOVE_WORD_LEFT_AND_MODIFY_SELECTION: |
1477 case ui::TextEditCommand::MOVE_WORD_RIGHT: | 1487 case ui::TextEditCommand::MOVE_WORD_RIGHT: |
1478 case ui::TextEditCommand::MOVE_WORD_RIGHT_AND_MODIFY_SELECTION: | 1488 case ui::TextEditCommand::MOVE_WORD_RIGHT_AND_MODIFY_SELECTION: |
1479 return true; | 1489 return true; |
1480 case ui::TextEditCommand::UNDO: | 1490 case ui::TextEditCommand::UNDO: |
(...skipping 16 matching lines...) Expand all Loading... | |
1497 case ui::TextEditCommand::YANK: | 1507 case ui::TextEditCommand::YANK: |
1498 return editable; | 1508 return editable; |
1499 case ui::TextEditCommand::MOVE_DOWN: | 1509 case ui::TextEditCommand::MOVE_DOWN: |
1500 case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION: | 1510 case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION: |
1501 case ui::TextEditCommand::MOVE_PAGE_DOWN: | 1511 case ui::TextEditCommand::MOVE_PAGE_DOWN: |
1502 case ui::TextEditCommand::MOVE_PAGE_DOWN_AND_MODIFY_SELECTION: | 1512 case ui::TextEditCommand::MOVE_PAGE_DOWN_AND_MODIFY_SELECTION: |
1503 case ui::TextEditCommand::MOVE_PAGE_UP: | 1513 case ui::TextEditCommand::MOVE_PAGE_UP: |
1504 case ui::TextEditCommand::MOVE_PAGE_UP_AND_MODIFY_SELECTION: | 1514 case ui::TextEditCommand::MOVE_PAGE_UP_AND_MODIFY_SELECTION: |
1505 case ui::TextEditCommand::MOVE_UP: | 1515 case ui::TextEditCommand::MOVE_UP: |
1506 case ui::TextEditCommand::MOVE_UP_AND_MODIFY_SELECTION: | 1516 case ui::TextEditCommand::MOVE_UP_AND_MODIFY_SELECTION: |
1517 // On Mac, the textfield should respond to Up/Down arrows keys and | |
1518 // PageUp/PageDown. | |
1519 #if defined(OS_MACOSX) | |
1520 return true; | |
1521 #else | |
1522 return false; | |
1523 #endif | |
1507 case ui::TextEditCommand::INSERT_TEXT: | 1524 case ui::TextEditCommand::INSERT_TEXT: |
1508 case ui::TextEditCommand::SET_MARK: | 1525 case ui::TextEditCommand::SET_MARK: |
1509 case ui::TextEditCommand::UNSELECT: | 1526 case ui::TextEditCommand::UNSELECT: |
1510 case ui::TextEditCommand::INVALID_COMMAND: | 1527 case ui::TextEditCommand::INVALID_COMMAND: |
1511 return false; | 1528 return false; |
1512 } | 1529 } |
1513 NOTREACHED(); | 1530 NOTREACHED(); |
1514 return false; | 1531 return false; |
1515 } | 1532 } |
1516 | 1533 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1581 OnBeforeUserAction(); | 1598 OnBeforeUserAction(); |
1582 switch (command) { | 1599 switch (command) { |
1583 case ui::TextEditCommand::DELETE_BACKWARD: | 1600 case ui::TextEditCommand::DELETE_BACKWARD: |
1584 text_changed = cursor_changed = model_->Backspace(add_to_kill_buffer); | 1601 text_changed = cursor_changed = model_->Backspace(add_to_kill_buffer); |
1585 break; | 1602 break; |
1586 case ui::TextEditCommand::DELETE_FORWARD: | 1603 case ui::TextEditCommand::DELETE_FORWARD: |
1587 text_changed = cursor_changed = model_->Delete(add_to_kill_buffer); | 1604 text_changed = cursor_changed = model_->Delete(add_to_kill_buffer); |
1588 break; | 1605 break; |
1589 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: | 1606 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: |
1590 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH: | 1607 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH: |
1591 model_->MoveCursor(gfx::LINE_BREAK, begin, true); | 1608 model_->MoveCursor(gfx::LINE_BREAK, begin, gfx::SELECTION_RETAIN); |
1592 text_changed = cursor_changed = model_->Backspace(add_to_kill_buffer); | 1609 text_changed = cursor_changed = model_->Backspace(add_to_kill_buffer); |
1593 break; | 1610 break; |
1594 case ui::TextEditCommand::DELETE_TO_END_OF_LINE: | 1611 case ui::TextEditCommand::DELETE_TO_END_OF_LINE: |
1595 case ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH: | 1612 case ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH: |
1596 model_->MoveCursor(gfx::LINE_BREAK, end, true); | 1613 model_->MoveCursor(gfx::LINE_BREAK, end, gfx::SELECTION_RETAIN); |
1597 text_changed = cursor_changed = model_->Delete(add_to_kill_buffer); | 1614 text_changed = cursor_changed = model_->Delete(add_to_kill_buffer); |
1598 break; | 1615 break; |
1599 case ui::TextEditCommand::DELETE_WORD_BACKWARD: | 1616 case ui::TextEditCommand::DELETE_WORD_BACKWARD: |
1600 model_->MoveCursor(gfx::WORD_BREAK, begin, true); | 1617 model_->MoveCursor(gfx::WORD_BREAK, begin, gfx::SELECTION_RETAIN); |
1601 text_changed = cursor_changed = model_->Backspace(add_to_kill_buffer); | 1618 text_changed = cursor_changed = model_->Backspace(add_to_kill_buffer); |
1602 break; | 1619 break; |
1603 case ui::TextEditCommand::DELETE_WORD_FORWARD: | 1620 case ui::TextEditCommand::DELETE_WORD_FORWARD: |
1604 model_->MoveCursor(gfx::WORD_BREAK, end, true); | 1621 model_->MoveCursor(gfx::WORD_BREAK, end, gfx::SELECTION_RETAIN); |
1605 text_changed = cursor_changed = model_->Delete(add_to_kill_buffer); | 1622 text_changed = cursor_changed = model_->Delete(add_to_kill_buffer); |
1606 break; | 1623 break; |
1607 case ui::TextEditCommand::MOVE_BACKWARD: | 1624 case ui::TextEditCommand::MOVE_BACKWARD: |
1608 model_->MoveCursor(gfx::CHARACTER_BREAK, begin, false); | 1625 model_->MoveCursor(gfx::CHARACTER_BREAK, begin, gfx::SELECTION_NONE); |
1609 break; | 1626 break; |
1610 case ui::TextEditCommand::MOVE_BACKWARD_AND_MODIFY_SELECTION: | 1627 case ui::TextEditCommand::MOVE_BACKWARD_AND_MODIFY_SELECTION: |
1611 model_->MoveCursor(gfx::CHARACTER_BREAK, begin, true); | 1628 model_->MoveCursor(gfx::CHARACTER_BREAK, begin, gfx::SELECTION_RETAIN); |
1612 break; | 1629 break; |
1613 case ui::TextEditCommand::MOVE_FORWARD: | 1630 case ui::TextEditCommand::MOVE_FORWARD: |
1614 model_->MoveCursor(gfx::CHARACTER_BREAK, end, false); | 1631 model_->MoveCursor(gfx::CHARACTER_BREAK, end, gfx::SELECTION_NONE); |
1615 break; | 1632 break; |
1616 case ui::TextEditCommand::MOVE_FORWARD_AND_MODIFY_SELECTION: | 1633 case ui::TextEditCommand::MOVE_FORWARD_AND_MODIFY_SELECTION: |
1617 model_->MoveCursor(gfx::CHARACTER_BREAK, end, true); | 1634 model_->MoveCursor(gfx::CHARACTER_BREAK, end, gfx::SELECTION_RETAIN); |
1618 break; | 1635 break; |
1619 case ui::TextEditCommand::MOVE_LEFT: | 1636 case ui::TextEditCommand::MOVE_LEFT: |
1620 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false); | 1637 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, |
1638 gfx::SELECTION_NONE); | |
1621 break; | 1639 break; |
1622 case ui::TextEditCommand::MOVE_LEFT_AND_MODIFY_SELECTION: | 1640 case ui::TextEditCommand::MOVE_LEFT_AND_MODIFY_SELECTION: |
1623 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); | 1641 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, |
1642 gfx::SELECTION_RETAIN); | |
1624 break; | 1643 break; |
1625 case ui::TextEditCommand::MOVE_RIGHT: | 1644 case ui::TextEditCommand::MOVE_RIGHT: |
1626 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); | 1645 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, |
1646 gfx::SELECTION_NONE); | |
1627 break; | 1647 break; |
1628 case ui::TextEditCommand::MOVE_RIGHT_AND_MODIFY_SELECTION: | 1648 case ui::TextEditCommand::MOVE_RIGHT_AND_MODIFY_SELECTION: |
1629 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); | 1649 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, |
1650 gfx::SELECTION_RETAIN); | |
1630 break; | 1651 break; |
1631 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_DOCUMENT: | 1652 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_DOCUMENT: |
1632 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE: | 1653 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE: |
1633 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_PARAGRAPH: | 1654 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_PARAGRAPH: |
1634 model_->MoveCursor(gfx::LINE_BREAK, begin, false); | 1655 case ui::TextEditCommand::MOVE_UP: |
1656 case ui::TextEditCommand::MOVE_PAGE_UP: | |
1657 model_->MoveCursor(gfx::LINE_BREAK, begin, gfx::SELECTION_NONE); | |
1635 break; | 1658 break; |
1636 case ui::TextEditCommand:: | 1659 case ui::TextEditCommand:: |
1637 MOVE_TO_BEGINNING_OF_DOCUMENT_AND_MODIFY_SELECTION: | 1660 MOVE_TO_BEGINNING_OF_DOCUMENT_AND_MODIFY_SELECTION: |
1638 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION: | 1661 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION: |
1639 case ui::TextEditCommand:: | 1662 case ui::TextEditCommand:: |
1640 MOVE_TO_BEGINNING_OF_PARAGRAPH_AND_MODIFY_SELECTION: | 1663 MOVE_TO_BEGINNING_OF_PARAGRAPH_AND_MODIFY_SELECTION: |
1641 model_->MoveCursor(gfx::LINE_BREAK, begin, true); | 1664 model_->MoveCursor(gfx::LINE_BREAK, begin, kLineSelectionBehavior); |
1665 break; | |
1666 case ui::TextEditCommand::MOVE_PAGE_UP_AND_MODIFY_SELECTION: | |
1667 case ui::TextEditCommand::MOVE_UP_AND_MODIFY_SELECTION: | |
1668 model_->MoveCursor(gfx::LINE_BREAK, begin, gfx::SELECTION_RETAIN); | |
1642 break; | 1669 break; |
1643 case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT: | 1670 case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT: |
1644 case ui::TextEditCommand::MOVE_TO_END_OF_LINE: | 1671 case ui::TextEditCommand::MOVE_TO_END_OF_LINE: |
1645 case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH: | 1672 case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH: |
1646 model_->MoveCursor(gfx::LINE_BREAK, end, false); | 1673 case ui::TextEditCommand::MOVE_DOWN: |
1674 case ui::TextEditCommand::MOVE_PAGE_DOWN: | |
1675 model_->MoveCursor(gfx::LINE_BREAK, end, gfx::SELECTION_NONE); | |
1647 break; | 1676 break; |
1648 case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT_AND_MODIFY_SELECTION: | 1677 case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT_AND_MODIFY_SELECTION: |
1649 case ui::TextEditCommand::MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION: | 1678 case ui::TextEditCommand::MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION: |
1650 case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH_AND_MODIFY_SELECTION: | 1679 case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH_AND_MODIFY_SELECTION: |
1651 model_->MoveCursor(gfx::LINE_BREAK, end, true); | 1680 model_->MoveCursor(gfx::LINE_BREAK, end, kLineSelectionBehavior); |
1681 break; | |
1682 case ui::TextEditCommand::MOVE_PAGE_DOWN_AND_MODIFY_SELECTION: | |
1683 case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION: | |
1684 model_->MoveCursor(gfx::LINE_BREAK, end, gfx::SELECTION_RETAIN); | |
1685 break; | |
1686 case ui::TextEditCommand::MOVE_PARAGRAPH_BACKWARD_AND_MODIFY_SELECTION: | |
1687 model_->MoveCursor(gfx::LINE_BREAK, begin, gfx::SELECTION_CARET); | |
msw
2016/08/16 18:37:58
nit: If we ever add Win/Cros/Linux support, this s
karandeepb
2016/08/17 04:37:23
Done.
| |
1688 break; | |
1689 case ui::TextEditCommand::MOVE_PARAGRAPH_FORWARD_AND_MODIFY_SELECTION: | |
1690 model_->MoveCursor(gfx::LINE_BREAK, end, gfx::SELECTION_CARET); | |
1652 break; | 1691 break; |
1653 case ui::TextEditCommand::MOVE_WORD_BACKWARD: | 1692 case ui::TextEditCommand::MOVE_WORD_BACKWARD: |
1654 model_->MoveCursor(gfx::WORD_BREAK, begin, false); | 1693 model_->MoveCursor(gfx::WORD_BREAK, begin, gfx::SELECTION_NONE); |
1655 break; | 1694 break; |
1656 case ui::TextEditCommand::MOVE_WORD_BACKWARD_AND_MODIFY_SELECTION: | 1695 case ui::TextEditCommand::MOVE_WORD_BACKWARD_AND_MODIFY_SELECTION: |
1657 model_->MoveCursor(gfx::WORD_BREAK, begin, true); | 1696 model_->MoveCursor(gfx::WORD_BREAK, begin, kWordSelectionBehavior); |
1658 break; | 1697 break; |
1659 case ui::TextEditCommand::MOVE_WORD_FORWARD: | 1698 case ui::TextEditCommand::MOVE_WORD_FORWARD: |
1660 model_->MoveCursor(gfx::WORD_BREAK, end, false); | 1699 model_->MoveCursor(gfx::WORD_BREAK, end, gfx::SELECTION_NONE); |
1661 break; | 1700 break; |
1662 case ui::TextEditCommand::MOVE_WORD_FORWARD_AND_MODIFY_SELECTION: | 1701 case ui::TextEditCommand::MOVE_WORD_FORWARD_AND_MODIFY_SELECTION: |
1663 model_->MoveCursor(gfx::WORD_BREAK, end, true); | 1702 model_->MoveCursor(gfx::WORD_BREAK, end, kWordSelectionBehavior); |
1664 break; | 1703 break; |
1665 case ui::TextEditCommand::MOVE_WORD_LEFT: | 1704 case ui::TextEditCommand::MOVE_WORD_LEFT: |
1666 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, false); | 1705 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, |
1706 gfx::SELECTION_NONE); | |
1667 break; | 1707 break; |
1668 case ui::TextEditCommand::MOVE_WORD_LEFT_AND_MODIFY_SELECTION: | 1708 case ui::TextEditCommand::MOVE_WORD_LEFT_AND_MODIFY_SELECTION: |
1669 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); | 1709 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, |
1710 kWordSelectionBehavior); | |
1670 break; | 1711 break; |
1671 case ui::TextEditCommand::MOVE_WORD_RIGHT: | 1712 case ui::TextEditCommand::MOVE_WORD_RIGHT: |
1672 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false); | 1713 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, |
1714 gfx::SELECTION_NONE); | |
1673 break; | 1715 break; |
1674 case ui::TextEditCommand::MOVE_WORD_RIGHT_AND_MODIFY_SELECTION: | 1716 case ui::TextEditCommand::MOVE_WORD_RIGHT_AND_MODIFY_SELECTION: |
1675 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); | 1717 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, |
1718 kWordSelectionBehavior); | |
1676 break; | 1719 break; |
1677 case ui::TextEditCommand::UNDO: | 1720 case ui::TextEditCommand::UNDO: |
1678 text_changed = cursor_changed = model_->Undo(); | 1721 text_changed = cursor_changed = model_->Undo(); |
1679 break; | 1722 break; |
1680 case ui::TextEditCommand::REDO: | 1723 case ui::TextEditCommand::REDO: |
1681 text_changed = cursor_changed = model_->Redo(); | 1724 text_changed = cursor_changed = model_->Redo(); |
1682 break; | 1725 break; |
1683 case ui::TextEditCommand::CUT: | 1726 case ui::TextEditCommand::CUT: |
1684 text_changed = cursor_changed = Cut(); | 1727 text_changed = cursor_changed = Cut(); |
1685 break; | 1728 break; |
1686 case ui::TextEditCommand::COPY: | 1729 case ui::TextEditCommand::COPY: |
1687 Copy(); | 1730 Copy(); |
1688 break; | 1731 break; |
1689 case ui::TextEditCommand::PASTE: | 1732 case ui::TextEditCommand::PASTE: |
1690 text_changed = cursor_changed = Paste(); | 1733 text_changed = cursor_changed = Paste(); |
1691 break; | 1734 break; |
1692 case ui::TextEditCommand::SELECT_ALL: | 1735 case ui::TextEditCommand::SELECT_ALL: |
1693 SelectAll(false); | 1736 SelectAll(false); |
1694 break; | 1737 break; |
1695 case ui::TextEditCommand::TRANSPOSE: | 1738 case ui::TextEditCommand::TRANSPOSE: |
1696 text_changed = cursor_changed = model_->Transpose(); | 1739 text_changed = cursor_changed = model_->Transpose(); |
1697 break; | 1740 break; |
1698 case ui::TextEditCommand::YANK: | 1741 case ui::TextEditCommand::YANK: |
1699 text_changed = cursor_changed = model_->Yank(); | 1742 text_changed = cursor_changed = model_->Yank(); |
1700 break; | 1743 break; |
1701 case ui::TextEditCommand::MOVE_DOWN: | |
1702 case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION: | |
1703 case ui::TextEditCommand::MOVE_PAGE_DOWN: | |
1704 case ui::TextEditCommand::MOVE_PAGE_DOWN_AND_MODIFY_SELECTION: | |
1705 case ui::TextEditCommand::MOVE_PAGE_UP: | |
1706 case ui::TextEditCommand::MOVE_PAGE_UP_AND_MODIFY_SELECTION: | |
1707 case ui::TextEditCommand::MOVE_UP: | |
1708 case ui::TextEditCommand::MOVE_UP_AND_MODIFY_SELECTION: | |
1709 case ui::TextEditCommand::INSERT_TEXT: | 1744 case ui::TextEditCommand::INSERT_TEXT: |
1710 case ui::TextEditCommand::SET_MARK: | 1745 case ui::TextEditCommand::SET_MARK: |
1711 case ui::TextEditCommand::UNSELECT: | 1746 case ui::TextEditCommand::UNSELECT: |
1712 case ui::TextEditCommand::INVALID_COMMAND: | 1747 case ui::TextEditCommand::INVALID_COMMAND: |
1713 NOTREACHED(); | 1748 NOTREACHED(); |
1714 break; | 1749 break; |
1715 } | 1750 } |
1716 | 1751 |
1717 cursor_changed |= GetSelectionModel() != selection_model; | 1752 cursor_changed |= GetSelectionModel() != selection_model; |
1718 if (cursor_changed) | 1753 if (cursor_changed) |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1810 if (model_->MoveCursorTo(point, select)) | 1845 if (model_->MoveCursorTo(point, select)) |
1811 UpdateAfterChange(false, true); | 1846 UpdateAfterChange(false, true); |
1812 } | 1847 } |
1813 | 1848 |
1814 void Textfield::SelectThroughLastDragLocation() { | 1849 void Textfield::SelectThroughLastDragLocation() { |
1815 OnBeforeUserAction(); | 1850 OnBeforeUserAction(); |
1816 | 1851 |
1817 const bool drags_to_end = PlatformStyle::kTextfieldDragVerticallyDragsToEnd; | 1852 const bool drags_to_end = PlatformStyle::kTextfieldDragVerticallyDragsToEnd; |
1818 if (drags_to_end && last_drag_location_.y() < 0) { | 1853 if (drags_to_end && last_drag_location_.y() < 0) { |
1819 model_->MoveCursor(gfx::BreakType::LINE_BREAK, | 1854 model_->MoveCursor(gfx::BreakType::LINE_BREAK, |
1820 gfx::VisualCursorDirection::CURSOR_LEFT, true); | 1855 gfx::VisualCursorDirection::CURSOR_LEFT, |
1856 gfx::SELECTION_RETAIN); | |
1821 } else if (drags_to_end && last_drag_location_.y() > height()) { | 1857 } else if (drags_to_end && last_drag_location_.y() > height()) { |
1822 model_->MoveCursor(gfx::BreakType::LINE_BREAK, | 1858 model_->MoveCursor(gfx::BreakType::LINE_BREAK, |
1823 gfx::VisualCursorDirection::CURSOR_RIGHT, true); | 1859 gfx::VisualCursorDirection::CURSOR_RIGHT, |
1860 gfx::SELECTION_RETAIN); | |
1824 } else { | 1861 } else { |
1825 model_->MoveCursorTo(last_drag_location_, true); | 1862 model_->MoveCursorTo(last_drag_location_, true); |
1826 } | 1863 } |
1827 | 1864 |
1828 if (aggregated_clicks_ == 1) { | 1865 if (aggregated_clicks_ == 1) { |
1829 model_->SelectWord(); | 1866 model_->SelectWord(); |
1830 // Expand the selection so the initially selected word remains selected. | 1867 // Expand the selection so the initially selected word remains selected. |
1831 gfx::Range selection = GetRenderText()->selection(); | 1868 gfx::Range selection = GetRenderText()->selection(); |
1832 const size_t min = std::min(selection.GetMin(), | 1869 const size_t min = std::min(selection.GetMin(), |
1833 double_click_word_.GetMin()); | 1870 double_click_word_.GetMin()); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1983 RequestFocus(); | 2020 RequestFocus(); |
1984 model_->MoveCursorTo(mouse); | 2021 model_->MoveCursorTo(mouse); |
1985 if (!selection_clipboard_text.empty()) { | 2022 if (!selection_clipboard_text.empty()) { |
1986 model_->InsertText(selection_clipboard_text); | 2023 model_->InsertText(selection_clipboard_text); |
1987 UpdateAfterChange(true, true); | 2024 UpdateAfterChange(true, true); |
1988 } | 2025 } |
1989 OnAfterUserAction(); | 2026 OnAfterUserAction(); |
1990 } | 2027 } |
1991 | 2028 |
1992 } // namespace views | 2029 } // namespace views |
OLD | NEW |