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