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

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

Issue 2228833002: MacViews: Fix behavior of move and select commands when selection direction changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@use_text_commands
Patch Set: Created 4 years, 4 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 1449 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION: 1460 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION:
1461 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_PARAGRAPH: 1461 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_PARAGRAPH:
1462 case ui::TextEditCommand:: 1462 case ui::TextEditCommand::
1463 MOVE_TO_BEGINNING_OF_PARAGRAPH_AND_MODIFY_SELECTION: 1463 MOVE_TO_BEGINNING_OF_PARAGRAPH_AND_MODIFY_SELECTION:
1464 case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT: 1464 case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT:
1465 case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT_AND_MODIFY_SELECTION: 1465 case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT_AND_MODIFY_SELECTION:
1466 case ui::TextEditCommand::MOVE_TO_END_OF_LINE: 1466 case ui::TextEditCommand::MOVE_TO_END_OF_LINE:
1467 case ui::TextEditCommand::MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION: 1467 case ui::TextEditCommand::MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION:
1468 case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH: 1468 case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH:
1469 case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH_AND_MODIFY_SELECTION: 1469 case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH_AND_MODIFY_SELECTION:
1470 case ui::TextEditCommand::MOVE_PARAGRAPH_FORWARD_AND_MODIFY_SELECTION:
1471 case ui::TextEditCommand::MOVE_PARAGRAPH_BACKWARD_AND_MODIFY_SELECTION:
1470 case ui::TextEditCommand::MOVE_WORD_BACKWARD: 1472 case ui::TextEditCommand::MOVE_WORD_BACKWARD:
1471 case ui::TextEditCommand::MOVE_WORD_BACKWARD_AND_MODIFY_SELECTION: 1473 case ui::TextEditCommand::MOVE_WORD_BACKWARD_AND_MODIFY_SELECTION:
1472 case ui::TextEditCommand::MOVE_WORD_FORWARD: 1474 case ui::TextEditCommand::MOVE_WORD_FORWARD:
1473 case ui::TextEditCommand::MOVE_WORD_FORWARD_AND_MODIFY_SELECTION: 1475 case ui::TextEditCommand::MOVE_WORD_FORWARD_AND_MODIFY_SELECTION:
1474 case ui::TextEditCommand::MOVE_WORD_LEFT: 1476 case ui::TextEditCommand::MOVE_WORD_LEFT:
1475 case ui::TextEditCommand::MOVE_WORD_LEFT_AND_MODIFY_SELECTION: 1477 case ui::TextEditCommand::MOVE_WORD_LEFT_AND_MODIFY_SELECTION:
1476 case ui::TextEditCommand::MOVE_WORD_RIGHT: 1478 case ui::TextEditCommand::MOVE_WORD_RIGHT:
1477 case ui::TextEditCommand::MOVE_WORD_RIGHT_AND_MODIFY_SELECTION: 1479 case ui::TextEditCommand::MOVE_WORD_RIGHT_AND_MODIFY_SELECTION:
1478 return true; 1480 return true;
1479 case ui::TextEditCommand::UNDO: 1481 case ui::TextEditCommand::UNDO:
(...skipping 16 matching lines...) Expand all
1496 case ui::TextEditCommand::YANK: 1498 case ui::TextEditCommand::YANK:
1497 return editable; 1499 return editable;
1498 case ui::TextEditCommand::MOVE_DOWN: 1500 case ui::TextEditCommand::MOVE_DOWN:
1499 case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION: 1501 case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION:
1500 case ui::TextEditCommand::MOVE_PAGE_DOWN: 1502 case ui::TextEditCommand::MOVE_PAGE_DOWN:
1501 case ui::TextEditCommand::MOVE_PAGE_DOWN_AND_MODIFY_SELECTION: 1503 case ui::TextEditCommand::MOVE_PAGE_DOWN_AND_MODIFY_SELECTION:
1502 case ui::TextEditCommand::MOVE_PAGE_UP: 1504 case ui::TextEditCommand::MOVE_PAGE_UP:
1503 case ui::TextEditCommand::MOVE_PAGE_UP_AND_MODIFY_SELECTION: 1505 case ui::TextEditCommand::MOVE_PAGE_UP_AND_MODIFY_SELECTION:
1504 case ui::TextEditCommand::MOVE_UP: 1506 case ui::TextEditCommand::MOVE_UP:
1505 case ui::TextEditCommand::MOVE_UP_AND_MODIFY_SELECTION: 1507 case ui::TextEditCommand::MOVE_UP_AND_MODIFY_SELECTION:
1508 // On Mac, the textfield should respond to Up/Down arrows keys and
1509 // PageUp/PageDown.
1510 #if defined(OS_MACOSX)
1511 return true;
1512 #else
1513 return false;
1514 #endif
1506 case ui::TextEditCommand::INSERT_TEXT: 1515 case ui::TextEditCommand::INSERT_TEXT:
1507 case ui::TextEditCommand::SET_MARK: 1516 case ui::TextEditCommand::SET_MARK:
1508 case ui::TextEditCommand::UNSELECT: 1517 case ui::TextEditCommand::UNSELECT:
1509 case ui::TextEditCommand::INVALID_COMMAND: 1518 case ui::TextEditCommand::INVALID_COMMAND:
1510 return false; 1519 return false;
1511 } 1520 }
1512 NOTREACHED(); 1521 NOTREACHED();
1513 return false; 1522 return false;
1514 } 1523 }
1515 1524
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1623 break; 1632 break;
1624 case ui::TextEditCommand::MOVE_RIGHT: 1633 case ui::TextEditCommand::MOVE_RIGHT:
1625 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 1634 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false);
1626 break; 1635 break;
1627 case ui::TextEditCommand::MOVE_RIGHT_AND_MODIFY_SELECTION: 1636 case ui::TextEditCommand::MOVE_RIGHT_AND_MODIFY_SELECTION:
1628 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 1637 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true);
1629 break; 1638 break;
1630 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_DOCUMENT: 1639 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_DOCUMENT:
1631 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE: 1640 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE:
1632 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_PARAGRAPH: 1641 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_PARAGRAPH:
1642 case ui::TextEditCommand::MOVE_UP:
1643 case ui::TextEditCommand::MOVE_PAGE_UP:
1633 model_->MoveCursor(gfx::LINE_BREAK, begin, false); 1644 model_->MoveCursor(gfx::LINE_BREAK, begin, false);
1634 break; 1645 break;
1635 case ui::TextEditCommand:: 1646 case ui::TextEditCommand::
1636 MOVE_TO_BEGINNING_OF_DOCUMENT_AND_MODIFY_SELECTION: 1647 MOVE_TO_BEGINNING_OF_DOCUMENT_AND_MODIFY_SELECTION:
1637 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION: 1648 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION:
1638 case ui::TextEditCommand:: 1649 case ui::TextEditCommand::
1639 MOVE_TO_BEGINNING_OF_PARAGRAPH_AND_MODIFY_SELECTION: 1650 MOVE_TO_BEGINNING_OF_PARAGRAPH_AND_MODIFY_SELECTION:
1640 model_->MoveCursor(gfx::LINE_BREAK, begin, true); 1651 model_->MoveCursor(gfx::LINE_BREAK, begin, true,
1652 PlatformStyle::kLineSelectionBehavior);
msw 2016/08/11 23:46:37 I'd like to avoid the behavior enum if possible. C
karandeepb 2016/08/12 01:26:31 For CHARACTER_BREAK, the enum is not really releva
1653 break;
1654 case ui::TextEditCommand::MOVE_PAGE_UP_AND_MODIFY_SELECTION:
1655 case ui::TextEditCommand::MOVE_UP_AND_MODIFY_SELECTION:
1656 model_->MoveCursor(gfx::LINE_BREAK, begin, true,
1657 gfx::SelectionReversedBehavior::SELECTION_START_NEW);
tapted 2016/08/11 03:44:08 nit: `::SelectionReversedBehavior` not needed, mor
msw 2016/08/11 23:46:38 Shouldn't these also extend the selection on mac?
karandeepb 2016/08/12 01:26:31 Nope, try yourself with Shift+Up/Down. And the Bli
karandeepb 2016/08/16 10:24:52 Done.
1641 break; 1658 break;
1642 case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT: 1659 case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT:
1643 case ui::TextEditCommand::MOVE_TO_END_OF_LINE: 1660 case ui::TextEditCommand::MOVE_TO_END_OF_LINE:
1644 case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH: 1661 case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH:
1662 case ui::TextEditCommand::MOVE_DOWN:
1663 case ui::TextEditCommand::MOVE_PAGE_DOWN:
1645 model_->MoveCursor(gfx::LINE_BREAK, end, false); 1664 model_->MoveCursor(gfx::LINE_BREAK, end, false);
1646 break; 1665 break;
1647 case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT_AND_MODIFY_SELECTION: 1666 case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT_AND_MODIFY_SELECTION:
1648 case ui::TextEditCommand::MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION: 1667 case ui::TextEditCommand::MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION:
1649 case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH_AND_MODIFY_SELECTION: 1668 case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH_AND_MODIFY_SELECTION:
1650 model_->MoveCursor(gfx::LINE_BREAK, end, true); 1669 model_->MoveCursor(gfx::LINE_BREAK, end, true,
1670 PlatformStyle::kLineSelectionBehavior);
msw 2016/08/11 23:46:38 Can you define the platform-specific constants her
karandeepb 2016/08/12 01:26:31 Will do!
1671 break;
1672 case ui::TextEditCommand::MOVE_PAGE_DOWN_AND_MODIFY_SELECTION:
1673 case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION:
1674 model_->MoveCursor(gfx::LINE_BREAK, end, true,
1675 gfx::SelectionReversedBehavior::SELECTION_START_NEW);
msw 2016/08/11 23:46:38 Shouldn't these also extend the selection on mac?
karandeepb 2016/08/12 01:26:31 Nope, try yourself with Shift+Up/Down.
msw 2016/08/12 21:58:30 Wow, Mac's behavior is so odd; we definitely need
karandeepb 2016/08/16 10:24:52 Done.
1676 break;
1677 case ui::TextEditCommand::MOVE_PARAGRAPH_BACKWARD_AND_MODIFY_SELECTION:
1678 model_->MoveCursor(gfx::LINE_BREAK, begin, true, gfx::SELECTION_CARET);
msw 2016/08/11 23:46:38 ditto: Why don't these (para fwd/back) extend the
karandeepb 2016/08/12 01:26:31 This is how Cocoa does it. Try with Alt+Shift+Up/D
1679 break;
1680 case ui::TextEditCommand::MOVE_PARAGRAPH_FORWARD_AND_MODIFY_SELECTION:
1681 model_->MoveCursor(gfx::LINE_BREAK, end, true, gfx::SELECTION_CARET);
1651 break; 1682 break;
1652 case ui::TextEditCommand::MOVE_WORD_BACKWARD: 1683 case ui::TextEditCommand::MOVE_WORD_BACKWARD:
1653 model_->MoveCursor(gfx::WORD_BREAK, begin, false); 1684 model_->MoveCursor(gfx::WORD_BREAK, begin, false);
1654 break; 1685 break;
1655 case ui::TextEditCommand::MOVE_WORD_BACKWARD_AND_MODIFY_SELECTION: 1686 case ui::TextEditCommand::MOVE_WORD_BACKWARD_AND_MODIFY_SELECTION:
1656 model_->MoveCursor(gfx::WORD_BREAK, begin, true); 1687 model_->MoveCursor(gfx::WORD_BREAK, begin, true,
1688 PlatformStyle::kWordSelectionBehavior);
1657 break; 1689 break;
1658 case ui::TextEditCommand::MOVE_WORD_FORWARD: 1690 case ui::TextEditCommand::MOVE_WORD_FORWARD:
1659 model_->MoveCursor(gfx::WORD_BREAK, end, false); 1691 model_->MoveCursor(gfx::WORD_BREAK, end, false);
1660 break; 1692 break;
1661 case ui::TextEditCommand::MOVE_WORD_FORWARD_AND_MODIFY_SELECTION: 1693 case ui::TextEditCommand::MOVE_WORD_FORWARD_AND_MODIFY_SELECTION:
1662 model_->MoveCursor(gfx::WORD_BREAK, end, true); 1694 model_->MoveCursor(gfx::WORD_BREAK, end, true,
1695 PlatformStyle::kWordSelectionBehavior);
1663 break; 1696 break;
1664 case ui::TextEditCommand::MOVE_WORD_LEFT: 1697 case ui::TextEditCommand::MOVE_WORD_LEFT:
1665 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, false); 1698 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, false);
1666 break; 1699 break;
1667 case ui::TextEditCommand::MOVE_WORD_LEFT_AND_MODIFY_SELECTION: 1700 case ui::TextEditCommand::MOVE_WORD_LEFT_AND_MODIFY_SELECTION:
1668 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 1701 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true,
1702 PlatformStyle::kWordSelectionBehavior);
1669 break; 1703 break;
1670 case ui::TextEditCommand::MOVE_WORD_RIGHT: 1704 case ui::TextEditCommand::MOVE_WORD_RIGHT:
1671 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false); 1705 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false);
1672 break; 1706 break;
1673 case ui::TextEditCommand::MOVE_WORD_RIGHT_AND_MODIFY_SELECTION: 1707 case ui::TextEditCommand::MOVE_WORD_RIGHT_AND_MODIFY_SELECTION:
1674 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); 1708 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true,
1709 PlatformStyle::kWordSelectionBehavior);
1675 break; 1710 break;
1676 case ui::TextEditCommand::UNDO: 1711 case ui::TextEditCommand::UNDO:
1677 text_changed = cursor_changed = model_->Undo(); 1712 text_changed = cursor_changed = model_->Undo();
1678 break; 1713 break;
1679 case ui::TextEditCommand::REDO: 1714 case ui::TextEditCommand::REDO:
1680 text_changed = cursor_changed = model_->Redo(); 1715 text_changed = cursor_changed = model_->Redo();
1681 break; 1716 break;
1682 case ui::TextEditCommand::CUT: 1717 case ui::TextEditCommand::CUT:
1683 text_changed = cursor_changed = Cut(); 1718 text_changed = cursor_changed = Cut();
1684 break; 1719 break;
1685 case ui::TextEditCommand::COPY: 1720 case ui::TextEditCommand::COPY:
1686 Copy(); 1721 Copy();
1687 break; 1722 break;
1688 case ui::TextEditCommand::PASTE: 1723 case ui::TextEditCommand::PASTE:
1689 text_changed = cursor_changed = Paste(); 1724 text_changed = cursor_changed = Paste();
1690 break; 1725 break;
1691 case ui::TextEditCommand::SELECT_ALL: 1726 case ui::TextEditCommand::SELECT_ALL:
1692 SelectAll(false); 1727 SelectAll(false);
1693 break; 1728 break;
1694 case ui::TextEditCommand::TRANSPOSE: 1729 case ui::TextEditCommand::TRANSPOSE:
1695 text_changed = cursor_changed = model_->Transpose(); 1730 text_changed = cursor_changed = model_->Transpose();
1696 break; 1731 break;
1697 case ui::TextEditCommand::YANK: 1732 case ui::TextEditCommand::YANK:
1698 text_changed = cursor_changed = model_->Yank(); 1733 text_changed = cursor_changed = model_->Yank();
1699 break; 1734 break;
1700 case ui::TextEditCommand::MOVE_DOWN:
1701 case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION:
1702 case ui::TextEditCommand::MOVE_PAGE_DOWN:
1703 case ui::TextEditCommand::MOVE_PAGE_DOWN_AND_MODIFY_SELECTION:
1704 case ui::TextEditCommand::MOVE_PAGE_UP:
1705 case ui::TextEditCommand::MOVE_PAGE_UP_AND_MODIFY_SELECTION:
1706 case ui::TextEditCommand::MOVE_UP:
1707 case ui::TextEditCommand::MOVE_UP_AND_MODIFY_SELECTION:
1708 case ui::TextEditCommand::INSERT_TEXT: 1735 case ui::TextEditCommand::INSERT_TEXT:
1709 case ui::TextEditCommand::SET_MARK: 1736 case ui::TextEditCommand::SET_MARK:
1710 case ui::TextEditCommand::UNSELECT: 1737 case ui::TextEditCommand::UNSELECT:
1711 case ui::TextEditCommand::INVALID_COMMAND: 1738 case ui::TextEditCommand::INVALID_COMMAND:
1712 NOTREACHED(); 1739 NOTREACHED();
1713 break; 1740 break;
1714 } 1741 }
1715 1742
1716 cursor_changed |= GetSelectionModel() != selection_model; 1743 cursor_changed |= GetSelectionModel() != selection_model;
1717 if (cursor_changed) 1744 if (cursor_changed)
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1976 RequestFocus(); 2003 RequestFocus();
1977 model_->MoveCursorTo(mouse); 2004 model_->MoveCursorTo(mouse);
1978 if (!selection_clipboard_text.empty()) { 2005 if (!selection_clipboard_text.empty()) {
1979 model_->InsertText(selection_clipboard_text); 2006 model_->InsertText(selection_clipboard_text);
1980 UpdateAfterChange(true, true); 2007 UpdateAfterChange(true, true);
1981 } 2008 }
1982 OnAfterUserAction(); 2009 OnAfterUserAction();
1983 } 2010 }
1984 2011
1985 } // namespace views 2012 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698