| 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 case ui::VKEY_INSERT: | 162 case ui::VKEY_INSERT: |
| 163 if (control && !shift) | 163 if (control && !shift) |
| 164 return ui::TextEditCommand::COPY; | 164 return ui::TextEditCommand::COPY; |
| 165 return (shift && !control) ? ui::TextEditCommand::PASTE | 165 return (shift && !control) ? ui::TextEditCommand::PASTE |
| 166 : ui::TextEditCommand::INVALID_COMMAND; | 166 : ui::TextEditCommand::INVALID_COMMAND; |
| 167 default: | 167 default: |
| 168 return ui::TextEditCommand::INVALID_COMMAND; | 168 return ui::TextEditCommand::INVALID_COMMAND; |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 | 171 |
| 172 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
| 173 // Convert a custom text edit |command| to the equivalent views command ID. | |
| 174 ui::TextEditCommand GetViewsCommand(const ui::TextEditCommandAuraLinux& command, | |
| 175 bool rtl) { | |
| 176 const bool select = command.extend_selection(); | |
| 177 switch (command.command_id()) { | |
| 178 case ui::TextEditCommandAuraLinux::COPY: | |
| 179 return ui::TextEditCommand::COPY; | |
| 180 case ui::TextEditCommandAuraLinux::CUT: | |
| 181 return ui::TextEditCommand::CUT; | |
| 182 case ui::TextEditCommandAuraLinux::DELETE_BACKWARD: | |
| 183 return ui::TextEditCommand::DELETE_BACKWARD; | |
| 184 case ui::TextEditCommandAuraLinux::DELETE_FORWARD: | |
| 185 return ui::TextEditCommand::DELETE_FORWARD; | |
| 186 case ui::TextEditCommandAuraLinux::DELETE_TO_BEGINNING_OF_LINE: | |
| 187 case ui::TextEditCommandAuraLinux::DELETE_TO_BEGINNING_OF_PARAGRAPH: | |
| 188 return ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE; | |
| 189 case ui::TextEditCommandAuraLinux::DELETE_TO_END_OF_LINE: | |
| 190 case ui::TextEditCommandAuraLinux::DELETE_TO_END_OF_PARAGRAPH: | |
| 191 return ui::TextEditCommand::DELETE_TO_END_OF_LINE; | |
| 192 case ui::TextEditCommandAuraLinux::DELETE_WORD_BACKWARD: | |
| 193 return ui::TextEditCommand::DELETE_WORD_BACKWARD; | |
| 194 case ui::TextEditCommandAuraLinux::DELETE_WORD_FORWARD: | |
| 195 return ui::TextEditCommand::DELETE_WORD_FORWARD; | |
| 196 case ui::TextEditCommandAuraLinux::INSERT_TEXT: | |
| 197 return ui::TextEditCommand::INVALID_COMMAND; | |
| 198 case ui::TextEditCommandAuraLinux::MOVE_BACKWARD: | |
| 199 if (rtl) { | |
| 200 return select ? ui::TextEditCommand::MOVE_RIGHT_AND_MODIFY_SELECTION | |
| 201 : ui::TextEditCommand::MOVE_RIGHT; | |
| 202 } | |
| 203 return select ? ui::TextEditCommand::MOVE_LEFT_AND_MODIFY_SELECTION | |
| 204 : ui::TextEditCommand::MOVE_LEFT; | |
| 205 case ui::TextEditCommandAuraLinux::MOVE_DOWN: | |
| 206 return ui::TextEditCommand::MOVE_DOWN; | |
| 207 case ui::TextEditCommandAuraLinux::MOVE_FORWARD: | |
| 208 if (rtl) { | |
| 209 return select ? ui::TextEditCommand::MOVE_LEFT_AND_MODIFY_SELECTION | |
| 210 : ui::TextEditCommand::MOVE_LEFT; | |
| 211 } | |
| 212 return select ? ui::TextEditCommand::MOVE_RIGHT_AND_MODIFY_SELECTION | |
| 213 : ui::TextEditCommand::MOVE_RIGHT; | |
| 214 case ui::TextEditCommandAuraLinux::MOVE_LEFT: | |
| 215 return select ? ui::TextEditCommand::MOVE_LEFT_AND_MODIFY_SELECTION | |
| 216 : ui::TextEditCommand::MOVE_LEFT; | |
| 217 case ui::TextEditCommandAuraLinux::MOVE_PAGE_DOWN: | |
| 218 case ui::TextEditCommandAuraLinux::MOVE_PAGE_UP: | |
| 219 return ui::TextEditCommand::INVALID_COMMAND; | |
| 220 case ui::TextEditCommandAuraLinux::MOVE_RIGHT: | |
| 221 return select ? ui::TextEditCommand::MOVE_RIGHT_AND_MODIFY_SELECTION | |
| 222 : ui::TextEditCommand::MOVE_RIGHT; | |
| 223 case ui::TextEditCommandAuraLinux::MOVE_TO_BEGINNING_OF_DOCUMENT: | |
| 224 case ui::TextEditCommandAuraLinux::MOVE_TO_BEGINNING_OF_LINE: | |
| 225 case ui::TextEditCommandAuraLinux::MOVE_TO_BEGINNING_OF_PARAGRAPH: | |
| 226 return select ? ui::TextEditCommand:: | |
| 227 MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION | |
| 228 : ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE; | |
| 229 case ui::TextEditCommandAuraLinux::MOVE_TO_END_OF_DOCUMENT: | |
| 230 case ui::TextEditCommandAuraLinux::MOVE_TO_END_OF_LINE: | |
| 231 case ui::TextEditCommandAuraLinux::MOVE_TO_END_OF_PARAGRAPH: | |
| 232 return select | |
| 233 ? ui::TextEditCommand::MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION | |
| 234 : ui::TextEditCommand::MOVE_TO_END_OF_LINE; | |
| 235 case ui::TextEditCommandAuraLinux::MOVE_UP: | |
| 236 return ui::TextEditCommand::MOVE_UP; | |
| 237 case ui::TextEditCommandAuraLinux::MOVE_WORD_BACKWARD: | |
| 238 if (rtl) { | |
| 239 return select | |
| 240 ? ui::TextEditCommand::MOVE_WORD_RIGHT_AND_MODIFY_SELECTION | |
| 241 : ui::TextEditCommand::MOVE_WORD_RIGHT; | |
| 242 } | |
| 243 return select ? ui::TextEditCommand::MOVE_WORD_LEFT_AND_MODIFY_SELECTION | |
| 244 : ui::TextEditCommand::MOVE_WORD_LEFT; | |
| 245 case ui::TextEditCommandAuraLinux::MOVE_WORD_FORWARD: | |
| 246 if (rtl) { | |
| 247 return select ? ui::TextEditCommand::MOVE_WORD_LEFT_AND_MODIFY_SELECTION | |
| 248 : ui::TextEditCommand::MOVE_WORD_LEFT; | |
| 249 } | |
| 250 return select ? ui::TextEditCommand::MOVE_WORD_RIGHT_AND_MODIFY_SELECTION | |
| 251 : ui::TextEditCommand::MOVE_WORD_RIGHT; | |
| 252 case ui::TextEditCommandAuraLinux::MOVE_WORD_LEFT: | |
| 253 return select ? ui::TextEditCommand::MOVE_WORD_LEFT_AND_MODIFY_SELECTION | |
| 254 : ui::TextEditCommand::MOVE_WORD_LEFT; | |
| 255 case ui::TextEditCommandAuraLinux::MOVE_WORD_RIGHT: | |
| 256 return select ? ui::TextEditCommand::MOVE_WORD_RIGHT_AND_MODIFY_SELECTION | |
| 257 : ui::TextEditCommand::MOVE_WORD_RIGHT; | |
| 258 case ui::TextEditCommandAuraLinux::PASTE: | |
| 259 return ui::TextEditCommand::PASTE; | |
| 260 case ui::TextEditCommandAuraLinux::SELECT_ALL: | |
| 261 return ui::TextEditCommand::SELECT_ALL; | |
| 262 case ui::TextEditCommandAuraLinux::SET_MARK: | |
| 263 case ui::TextEditCommandAuraLinux::UNSELECT: | |
| 264 case ui::TextEditCommandAuraLinux::INVALID_COMMAND: | |
| 265 return ui::TextEditCommand::INVALID_COMMAND; | |
| 266 } | |
| 267 NOTREACHED(); | |
| 268 return ui::TextEditCommand::INVALID_COMMAND; | |
| 269 } | |
| 270 #endif | |
| 271 | |
| 272 const gfx::FontList& GetDefaultFontList() { | 172 const gfx::FontList& GetDefaultFontList() { |
| 273 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 173 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 274 return rb.GetFontListWithDelta(ui::kLabelFontSizeDelta); | 174 return rb.GetFontListWithDelta(ui::kLabelFontSizeDelta); |
| 275 } | 175 } |
| 276 | 176 |
| 277 // Returns the ui::TextEditCommand corresponding to the |command_id| menu | 177 // Returns the ui::TextEditCommand corresponding to the |command_id| menu |
| 278 // action. |has_selection| is true if the textfield has an active selection. | 178 // action. |has_selection| is true if the textfield has an active selection. |
| 279 // Keep in sync with UpdateContextMenu. | 179 // Keep in sync with UpdateContextMenu. |
| 280 ui::TextEditCommand GetTextEditCommandFromMenuCommand(int command_id, | 180 ui::TextEditCommand GetTextEditCommandFromMenuCommand(int command_id, |
| 281 bool has_selection) { | 181 bool has_selection) { |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 bool handled = controller_ && controller_->HandleKeyEvent(this, event); | 654 bool handled = controller_ && controller_->HandleKeyEvent(this, event); |
| 755 | 655 |
| 756 if (!textfield) | 656 if (!textfield) |
| 757 return handled; | 657 return handled; |
| 758 | 658 |
| 759 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 659 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 760 ui::TextEditKeyBindingsDelegateAuraLinux* delegate = | 660 ui::TextEditKeyBindingsDelegateAuraLinux* delegate = |
| 761 ui::GetTextEditKeyBindingsDelegate(); | 661 ui::GetTextEditKeyBindingsDelegate(); |
| 762 std::vector<ui::TextEditCommandAuraLinux> commands; | 662 std::vector<ui::TextEditCommandAuraLinux> commands; |
| 763 if (!handled && delegate && delegate->MatchEvent(event, &commands)) { | 663 if (!handled && delegate && delegate->MatchEvent(event, &commands)) { |
| 764 const bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT; | |
| 765 for (size_t i = 0; i < commands.size(); ++i) { | 664 for (size_t i = 0; i < commands.size(); ++i) { |
| 766 const ui::TextEditCommand command = GetViewsCommand(commands[i], rtl); | 665 if (IsTextEditCommandEnabled(commands[i].command())) { |
| 767 if (IsTextEditCommandEnabled(command)) { | 666 ExecuteTextEditCommand(commands[i].command()); |
| 768 ExecuteTextEditCommand(command); | |
| 769 handled = true; | 667 handled = true; |
| 770 } | 668 } |
| 771 } | 669 } |
| 772 return handled; | 670 return handled; |
| 773 } | 671 } |
| 774 #endif | 672 #endif |
| 775 | 673 |
| 776 if (edit_command == ui::TextEditCommand::INVALID_COMMAND) | 674 if (edit_command == ui::TextEditCommand::INVALID_COMMAND) |
| 777 edit_command = GetCommandForKeyEvent(event); | 675 edit_command = GetCommandForKeyEvent(event); |
| 778 | 676 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 SelectAll(false); | 791 SelectAll(false); |
| 894 } | 792 } |
| 895 | 793 |
| 896 bool Textfield::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) { | 794 bool Textfield::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) { |
| 897 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 795 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 898 // Skip any accelerator handling that conflicts with custom keybindings. | 796 // Skip any accelerator handling that conflicts with custom keybindings. |
| 899 ui::TextEditKeyBindingsDelegateAuraLinux* delegate = | 797 ui::TextEditKeyBindingsDelegateAuraLinux* delegate = |
| 900 ui::GetTextEditKeyBindingsDelegate(); | 798 ui::GetTextEditKeyBindingsDelegate(); |
| 901 std::vector<ui::TextEditCommandAuraLinux> commands; | 799 std::vector<ui::TextEditCommandAuraLinux> commands; |
| 902 if (delegate && delegate->MatchEvent(event, &commands)) { | 800 if (delegate && delegate->MatchEvent(event, &commands)) { |
| 903 const bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT; | |
| 904 for (size_t i = 0; i < commands.size(); ++i) | 801 for (size_t i = 0; i < commands.size(); ++i) |
| 905 if (IsTextEditCommandEnabled(GetViewsCommand(commands[i], rtl))) | 802 if (IsTextEditCommandEnabled(commands[i].command())) |
| 906 return true; | 803 return true; |
| 907 } | 804 } |
| 908 #endif | 805 #endif |
| 909 | 806 |
| 910 // Skip backspace accelerator handling; editable textfields handle this key. | 807 // Skip backspace accelerator handling; editable textfields handle this key. |
| 911 // Also skip processing Windows [Alt]+<num-pad digit> Unicode alt-codes. | 808 // Also skip processing Windows [Alt]+<num-pad digit> Unicode alt-codes. |
| 912 const bool is_backspace = event.key_code() == ui::VKEY_BACK; | 809 const bool is_backspace = event.key_code() == ui::VKEY_BACK; |
| 913 return (is_backspace && !read_only()) || event.IsUnicodeKeyCode(); | 810 return (is_backspace && !read_only()) || event.IsUnicodeKeyCode(); |
| 914 } | 811 } |
| 915 | 812 |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1529 DeleteRange(range); | 1426 DeleteRange(range); |
| 1530 } | 1427 } |
| 1531 | 1428 |
| 1532 void Textfield::EnsureCaretInRect(const gfx::Rect& rect) {} | 1429 void Textfield::EnsureCaretInRect(const gfx::Rect& rect) {} |
| 1533 | 1430 |
| 1534 bool Textfield::IsTextEditCommandEnabled(ui::TextEditCommand command) const { | 1431 bool Textfield::IsTextEditCommandEnabled(ui::TextEditCommand command) const { |
| 1535 base::string16 result; | 1432 base::string16 result; |
| 1536 bool editable = !read_only(); | 1433 bool editable = !read_only(); |
| 1537 bool readable = text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD; | 1434 bool readable = text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD; |
| 1538 switch (command) { | 1435 switch (command) { |
| 1539 case ui::TextEditCommand::INVALID_COMMAND: | 1436 case ui::TextEditCommand::DELETE_BACKWARD: |
| 1540 return false; | 1437 case ui::TextEditCommand::DELETE_FORWARD: |
| 1438 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: |
| 1439 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH: |
| 1440 case ui::TextEditCommand::DELETE_TO_END_OF_LINE: |
| 1441 case ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH: |
| 1442 case ui::TextEditCommand::DELETE_WORD_BACKWARD: |
| 1443 case ui::TextEditCommand::DELETE_WORD_FORWARD: |
| 1444 return editable; |
| 1445 case ui::TextEditCommand::MOVE_BACKWARD: |
| 1446 case ui::TextEditCommand::MOVE_BACKWARD_AND_MODIFY_SELECTION: |
| 1447 case ui::TextEditCommand::MOVE_FORWARD: |
| 1448 case ui::TextEditCommand::MOVE_FORWARD_AND_MODIFY_SELECTION: |
| 1449 case ui::TextEditCommand::MOVE_LEFT: |
| 1450 case ui::TextEditCommand::MOVE_LEFT_AND_MODIFY_SELECTION: |
| 1451 case ui::TextEditCommand::MOVE_RIGHT: |
| 1452 case ui::TextEditCommand::MOVE_RIGHT_AND_MODIFY_SELECTION: |
| 1453 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_DOCUMENT: |
| 1454 case ui::TextEditCommand:: |
| 1455 MOVE_TO_BEGINNING_OF_DOCUMENT_AND_MODIFY_SELECTION: |
| 1456 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE: |
| 1457 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION: |
| 1458 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_PARAGRAPH: |
| 1459 case ui::TextEditCommand:: |
| 1460 MOVE_TO_BEGINNING_OF_PARAGRAPH_AND_MODIFY_SELECTION: |
| 1461 case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT: |
| 1462 case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT_AND_MODIFY_SELECTION: |
| 1463 case ui::TextEditCommand::MOVE_TO_END_OF_LINE: |
| 1464 case ui::TextEditCommand::MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION: |
| 1465 case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH: |
| 1466 case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH_AND_MODIFY_SELECTION: |
| 1467 case ui::TextEditCommand::MOVE_WORD_BACKWARD: |
| 1468 case ui::TextEditCommand::MOVE_WORD_BACKWARD_AND_MODIFY_SELECTION: |
| 1469 case ui::TextEditCommand::MOVE_WORD_FORWARD: |
| 1470 case ui::TextEditCommand::MOVE_WORD_FORWARD_AND_MODIFY_SELECTION: |
| 1471 case ui::TextEditCommand::MOVE_WORD_LEFT: |
| 1472 case ui::TextEditCommand::MOVE_WORD_LEFT_AND_MODIFY_SELECTION: |
| 1473 case ui::TextEditCommand::MOVE_WORD_RIGHT: |
| 1474 case ui::TextEditCommand::MOVE_WORD_RIGHT_AND_MODIFY_SELECTION: |
| 1475 return true; |
| 1541 case ui::TextEditCommand::UNDO: | 1476 case ui::TextEditCommand::UNDO: |
| 1542 return editable && model_->CanUndo(); | 1477 return editable && model_->CanUndo(); |
| 1543 case ui::TextEditCommand::REDO: | 1478 case ui::TextEditCommand::REDO: |
| 1544 return editable && model_->CanRedo(); | 1479 return editable && model_->CanRedo(); |
| 1545 case ui::TextEditCommand::CUT: | 1480 case ui::TextEditCommand::CUT: |
| 1546 return editable && readable && model_->HasSelection(); | 1481 return editable && readable && model_->HasSelection(); |
| 1547 case ui::TextEditCommand::COPY: | 1482 case ui::TextEditCommand::COPY: |
| 1548 return readable && model_->HasSelection(); | 1483 return readable && model_->HasSelection(); |
| 1549 case ui::TextEditCommand::PASTE: | 1484 case ui::TextEditCommand::PASTE: |
| 1550 ui::Clipboard::GetForCurrentThread()->ReadText( | 1485 ui::Clipboard::GetForCurrentThread()->ReadText( |
| 1551 ui::CLIPBOARD_TYPE_COPY_PASTE, &result); | 1486 ui::CLIPBOARD_TYPE_COPY_PASTE, &result); |
| 1552 return editable && !result.empty(); | 1487 return editable && !result.empty(); |
| 1553 case ui::TextEditCommand::SELECT_ALL: | 1488 case ui::TextEditCommand::SELECT_ALL: |
| 1554 return !text().empty(); | 1489 return !text().empty(); |
| 1555 case ui::TextEditCommand::DELETE_FORWARD: | 1490 case ui::TextEditCommand::MOVE_DOWN: |
| 1556 case ui::TextEditCommand::DELETE_BACKWARD: | 1491 case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION: |
| 1557 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: | 1492 case ui::TextEditCommand::MOVE_PAGE_DOWN: |
| 1558 case ui::TextEditCommand::DELETE_TO_END_OF_LINE: | 1493 case ui::TextEditCommand::MOVE_PAGE_DOWN_AND_MODIFY_SELECTION: |
| 1559 case ui::TextEditCommand::DELETE_WORD_BACKWARD: | 1494 case ui::TextEditCommand::MOVE_PAGE_UP: |
| 1560 case ui::TextEditCommand::DELETE_WORD_FORWARD: | 1495 case ui::TextEditCommand::MOVE_PAGE_UP_AND_MODIFY_SELECTION: |
| 1561 return editable; | |
| 1562 case ui::TextEditCommand::MOVE_LEFT: | |
| 1563 case ui::TextEditCommand::MOVE_LEFT_AND_MODIFY_SELECTION: | |
| 1564 case ui::TextEditCommand::MOVE_RIGHT: | |
| 1565 case ui::TextEditCommand::MOVE_RIGHT_AND_MODIFY_SELECTION: | |
| 1566 case ui::TextEditCommand::MOVE_WORD_LEFT: | |
| 1567 case ui::TextEditCommand::MOVE_WORD_LEFT_AND_MODIFY_SELECTION: | |
| 1568 case ui::TextEditCommand::MOVE_WORD_RIGHT: | |
| 1569 case ui::TextEditCommand::MOVE_WORD_RIGHT_AND_MODIFY_SELECTION: | |
| 1570 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE: | |
| 1571 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION: | |
| 1572 case ui::TextEditCommand::MOVE_TO_END_OF_LINE: | |
| 1573 case ui::TextEditCommand::MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION: | |
| 1574 return true; | |
| 1575 case ui::TextEditCommand::MOVE_UP: | 1496 case ui::TextEditCommand::MOVE_UP: |
| 1576 case ui::TextEditCommand::MOVE_DOWN: | 1497 case ui::TextEditCommand::MOVE_UP_AND_MODIFY_SELECTION: |
| 1498 case ui::TextEditCommand::INSERT_TEXT: |
| 1499 case ui::TextEditCommand::SET_MARK: |
| 1500 case ui::TextEditCommand::UNSELECT: |
| 1501 case ui::TextEditCommand::INVALID_COMMAND: |
| 1577 return false; | 1502 return false; |
| 1578 } | 1503 } |
| 1579 NOTREACHED(); | 1504 NOTREACHED(); |
| 1580 return false; | 1505 return false; |
| 1581 } | 1506 } |
| 1582 | 1507 |
| 1583 void Textfield::SetTextEditCommandForNextKeyEvent(ui::TextEditCommand command) { | 1508 void Textfield::SetTextEditCommandForNextKeyEvent(ui::TextEditCommand command) { |
| 1584 DCHECK_EQ(ui::TextEditCommand::INVALID_COMMAND, scheduled_text_edit_command_); | 1509 DCHECK_EQ(ui::TextEditCommand::INVALID_COMMAND, scheduled_text_edit_command_); |
| 1585 scheduled_text_edit_command_ = command; | 1510 scheduled_text_edit_command_ = command; |
| 1586 } | 1511 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1612 return selection_clipboard_text; | 1537 return selection_clipboard_text; |
| 1613 } | 1538 } |
| 1614 | 1539 |
| 1615 void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) { | 1540 void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) { |
| 1616 DestroyTouchSelection(); | 1541 DestroyTouchSelection(); |
| 1617 | 1542 |
| 1618 // Some codepaths may bypass GetCommandForKeyEvent, so any selection-dependent | 1543 // Some codepaths may bypass GetCommandForKeyEvent, so any selection-dependent |
| 1619 // modifications of the command should happen here. | 1544 // modifications of the command should happen here. |
| 1620 if (HasSelection()) { | 1545 if (HasSelection()) { |
| 1621 switch (command) { | 1546 switch (command) { |
| 1547 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: |
| 1548 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH: |
| 1549 case ui::TextEditCommand::DELETE_TO_END_OF_LINE: |
| 1550 case ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH: |
| 1622 case ui::TextEditCommand::DELETE_WORD_BACKWARD: | 1551 case ui::TextEditCommand::DELETE_WORD_BACKWARD: |
| 1623 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: | |
| 1624 command = ui::TextEditCommand::DELETE_BACKWARD; | |
| 1625 break; | |
| 1626 case ui::TextEditCommand::DELETE_WORD_FORWARD: | 1552 case ui::TextEditCommand::DELETE_WORD_FORWARD: |
| 1627 case ui::TextEditCommand::DELETE_TO_END_OF_LINE: | |
| 1628 command = ui::TextEditCommand::DELETE_FORWARD; | 1553 command = ui::TextEditCommand::DELETE_FORWARD; |
| 1629 break; | 1554 break; |
| 1630 default: | 1555 default: |
| 1631 break; | 1556 break; |
| 1632 } | 1557 } |
| 1633 } | 1558 } |
| 1634 | 1559 |
| 1635 // We only execute the commands enabled in Textfield::IsTextEditCommandEnabled | 1560 // We only execute the commands enabled in Textfield::IsTextEditCommandEnabled |
| 1636 // below. Hence don't do a virtual IsTextEditCommandEnabled call. | 1561 // below. Hence don't do a virtual IsTextEditCommandEnabled call. |
| 1637 if (!Textfield::IsTextEditCommandEnabled(command)) | 1562 if (!Textfield::IsTextEditCommandEnabled(command)) |
| 1638 return; | 1563 return; |
| 1639 | 1564 |
| 1640 bool text_changed = false; | 1565 bool text_changed = false; |
| 1641 bool cursor_changed = false; | 1566 bool cursor_changed = false; |
| 1642 bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT; | 1567 bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT; |
| 1643 gfx::VisualCursorDirection begin = rtl ? gfx::CURSOR_RIGHT : gfx::CURSOR_LEFT; | 1568 gfx::VisualCursorDirection begin = rtl ? gfx::CURSOR_RIGHT : gfx::CURSOR_LEFT; |
| 1644 gfx::VisualCursorDirection end = rtl ? gfx::CURSOR_LEFT : gfx::CURSOR_RIGHT; | 1569 gfx::VisualCursorDirection end = rtl ? gfx::CURSOR_LEFT : gfx::CURSOR_RIGHT; |
| 1645 gfx::SelectionModel selection_model = GetSelectionModel(); | 1570 gfx::SelectionModel selection_model = GetSelectionModel(); |
| 1646 | 1571 |
| 1647 OnBeforeUserAction(); | 1572 OnBeforeUserAction(); |
| 1648 switch (command) { | 1573 switch (command) { |
| 1649 case ui::TextEditCommand::UNDO: | |
| 1650 text_changed = cursor_changed = model_->Undo(); | |
| 1651 break; | |
| 1652 case ui::TextEditCommand::REDO: | |
| 1653 text_changed = cursor_changed = model_->Redo(); | |
| 1654 break; | |
| 1655 case ui::TextEditCommand::CUT: | |
| 1656 text_changed = cursor_changed = Cut(); | |
| 1657 break; | |
| 1658 case ui::TextEditCommand::COPY: | |
| 1659 Copy(); | |
| 1660 break; | |
| 1661 case ui::TextEditCommand::PASTE: | |
| 1662 text_changed = cursor_changed = Paste(); | |
| 1663 break; | |
| 1664 case ui::TextEditCommand::SELECT_ALL: | |
| 1665 SelectAll(false); | |
| 1666 break; | |
| 1667 case ui::TextEditCommand::DELETE_BACKWARD: | 1574 case ui::TextEditCommand::DELETE_BACKWARD: |
| 1668 text_changed = cursor_changed = model_->Backspace(); | 1575 text_changed = cursor_changed = model_->Backspace(); |
| 1669 break; | 1576 break; |
| 1670 case ui::TextEditCommand::DELETE_FORWARD: | 1577 case ui::TextEditCommand::DELETE_FORWARD: |
| 1671 text_changed = cursor_changed = model_->Delete(); | 1578 text_changed = cursor_changed = model_->Delete(); |
| 1672 break; | 1579 break; |
| 1580 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: |
| 1581 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH: |
| 1582 model_->MoveCursor(gfx::LINE_BREAK, begin, true); |
| 1583 text_changed = cursor_changed = model_->Backspace(); |
| 1584 break; |
| 1673 case ui::TextEditCommand::DELETE_TO_END_OF_LINE: | 1585 case ui::TextEditCommand::DELETE_TO_END_OF_LINE: |
| 1586 case ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH: |
| 1674 model_->MoveCursor(gfx::LINE_BREAK, end, true); | 1587 model_->MoveCursor(gfx::LINE_BREAK, end, true); |
| 1675 text_changed = cursor_changed = model_->Delete(); | 1588 text_changed = cursor_changed = model_->Delete(); |
| 1676 break; | 1589 break; |
| 1677 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: | |
| 1678 model_->MoveCursor(gfx::LINE_BREAK, begin, true); | |
| 1679 text_changed = cursor_changed = model_->Backspace(); | |
| 1680 break; | |
| 1681 case ui::TextEditCommand::DELETE_WORD_BACKWARD: | 1590 case ui::TextEditCommand::DELETE_WORD_BACKWARD: |
| 1682 model_->MoveCursor(gfx::WORD_BREAK, begin, true); | 1591 model_->MoveCursor(gfx::WORD_BREAK, begin, true); |
| 1683 text_changed = cursor_changed = model_->Backspace(); | 1592 text_changed = cursor_changed = model_->Backspace(); |
| 1684 break; | 1593 break; |
| 1685 case ui::TextEditCommand::DELETE_WORD_FORWARD: | 1594 case ui::TextEditCommand::DELETE_WORD_FORWARD: |
| 1686 model_->MoveCursor(gfx::WORD_BREAK, end, true); | 1595 model_->MoveCursor(gfx::WORD_BREAK, end, true); |
| 1687 text_changed = cursor_changed = model_->Delete(); | 1596 text_changed = cursor_changed = model_->Delete(); |
| 1688 break; | 1597 break; |
| 1598 case ui::TextEditCommand::MOVE_BACKWARD: |
| 1599 model_->MoveCursor(gfx::CHARACTER_BREAK, begin, false); |
| 1600 break; |
| 1601 case ui::TextEditCommand::MOVE_BACKWARD_AND_MODIFY_SELECTION: |
| 1602 model_->MoveCursor(gfx::CHARACTER_BREAK, begin, true); |
| 1603 break; |
| 1604 case ui::TextEditCommand::MOVE_FORWARD: |
| 1605 model_->MoveCursor(gfx::CHARACTER_BREAK, end, false); |
| 1606 break; |
| 1607 case ui::TextEditCommand::MOVE_FORWARD_AND_MODIFY_SELECTION: |
| 1608 model_->MoveCursor(gfx::CHARACTER_BREAK, end, true); |
| 1609 break; |
| 1689 case ui::TextEditCommand::MOVE_LEFT: | 1610 case ui::TextEditCommand::MOVE_LEFT: |
| 1690 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false); | 1611 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false); |
| 1691 break; | 1612 break; |
| 1692 case ui::TextEditCommand::MOVE_LEFT_AND_MODIFY_SELECTION: | 1613 case ui::TextEditCommand::MOVE_LEFT_AND_MODIFY_SELECTION: |
| 1693 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); | 1614 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); |
| 1694 break; | 1615 break; |
| 1695 case ui::TextEditCommand::MOVE_RIGHT: | 1616 case ui::TextEditCommand::MOVE_RIGHT: |
| 1696 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); | 1617 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); |
| 1697 break; | 1618 break; |
| 1698 case ui::TextEditCommand::MOVE_RIGHT_AND_MODIFY_SELECTION: | 1619 case ui::TextEditCommand::MOVE_RIGHT_AND_MODIFY_SELECTION: |
| 1699 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); | 1620 model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); |
| 1700 break; | 1621 break; |
| 1622 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_DOCUMENT: |
| 1623 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE: |
| 1624 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_PARAGRAPH: |
| 1625 model_->MoveCursor(gfx::LINE_BREAK, begin, false); |
| 1626 break; |
| 1627 case ui::TextEditCommand:: |
| 1628 MOVE_TO_BEGINNING_OF_DOCUMENT_AND_MODIFY_SELECTION: |
| 1629 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION: |
| 1630 case ui::TextEditCommand:: |
| 1631 MOVE_TO_BEGINNING_OF_PARAGRAPH_AND_MODIFY_SELECTION: |
| 1632 model_->MoveCursor(gfx::LINE_BREAK, begin, true); |
| 1633 break; |
| 1634 case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT: |
| 1635 case ui::TextEditCommand::MOVE_TO_END_OF_LINE: |
| 1636 case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH: |
| 1637 model_->MoveCursor(gfx::LINE_BREAK, end, false); |
| 1638 break; |
| 1639 case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT_AND_MODIFY_SELECTION: |
| 1640 case ui::TextEditCommand::MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION: |
| 1641 case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH_AND_MODIFY_SELECTION: |
| 1642 model_->MoveCursor(gfx::LINE_BREAK, end, true); |
| 1643 break; |
| 1644 case ui::TextEditCommand::MOVE_WORD_BACKWARD: |
| 1645 model_->MoveCursor(gfx::WORD_BREAK, begin, false); |
| 1646 break; |
| 1647 case ui::TextEditCommand::MOVE_WORD_BACKWARD_AND_MODIFY_SELECTION: |
| 1648 model_->MoveCursor(gfx::WORD_BREAK, begin, true); |
| 1649 break; |
| 1650 case ui::TextEditCommand::MOVE_WORD_FORWARD: |
| 1651 model_->MoveCursor(gfx::WORD_BREAK, end, false); |
| 1652 break; |
| 1653 case ui::TextEditCommand::MOVE_WORD_FORWARD_AND_MODIFY_SELECTION: |
| 1654 model_->MoveCursor(gfx::WORD_BREAK, end, true); |
| 1655 break; |
| 1701 case ui::TextEditCommand::MOVE_WORD_LEFT: | 1656 case ui::TextEditCommand::MOVE_WORD_LEFT: |
| 1702 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, false); | 1657 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, false); |
| 1703 break; | 1658 break; |
| 1704 case ui::TextEditCommand::MOVE_WORD_LEFT_AND_MODIFY_SELECTION: | 1659 case ui::TextEditCommand::MOVE_WORD_LEFT_AND_MODIFY_SELECTION: |
| 1705 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); | 1660 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); |
| 1706 break; | 1661 break; |
| 1707 case ui::TextEditCommand::MOVE_WORD_RIGHT: | 1662 case ui::TextEditCommand::MOVE_WORD_RIGHT: |
| 1708 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false); | 1663 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false); |
| 1709 break; | 1664 break; |
| 1710 case ui::TextEditCommand::MOVE_WORD_RIGHT_AND_MODIFY_SELECTION: | 1665 case ui::TextEditCommand::MOVE_WORD_RIGHT_AND_MODIFY_SELECTION: |
| 1711 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); | 1666 model_->MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); |
| 1712 break; | 1667 break; |
| 1713 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE: | 1668 case ui::TextEditCommand::UNDO: |
| 1714 model_->MoveCursor(gfx::LINE_BREAK, begin, false); | 1669 text_changed = cursor_changed = model_->Undo(); |
| 1715 break; | 1670 break; |
| 1716 case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION: | 1671 case ui::TextEditCommand::REDO: |
| 1717 model_->MoveCursor(gfx::LINE_BREAK, begin, true); | 1672 text_changed = cursor_changed = model_->Redo(); |
| 1718 break; | 1673 break; |
| 1719 case ui::TextEditCommand::MOVE_TO_END_OF_LINE: | 1674 case ui::TextEditCommand::CUT: |
| 1720 model_->MoveCursor(gfx::LINE_BREAK, end, false); | 1675 text_changed = cursor_changed = Cut(); |
| 1721 break; | 1676 break; |
| 1722 case ui::TextEditCommand::MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION: | 1677 case ui::TextEditCommand::COPY: |
| 1723 model_->MoveCursor(gfx::LINE_BREAK, end, true); | 1678 Copy(); |
| 1724 break; | 1679 break; |
| 1680 case ui::TextEditCommand::PASTE: |
| 1681 text_changed = cursor_changed = Paste(); |
| 1682 break; |
| 1683 case ui::TextEditCommand::SELECT_ALL: |
| 1684 SelectAll(false); |
| 1685 break; |
| 1686 case ui::TextEditCommand::MOVE_DOWN: |
| 1687 case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION: |
| 1688 case ui::TextEditCommand::MOVE_PAGE_DOWN: |
| 1689 case ui::TextEditCommand::MOVE_PAGE_DOWN_AND_MODIFY_SELECTION: |
| 1690 case ui::TextEditCommand::MOVE_PAGE_UP: |
| 1691 case ui::TextEditCommand::MOVE_PAGE_UP_AND_MODIFY_SELECTION: |
| 1725 case ui::TextEditCommand::MOVE_UP: | 1692 case ui::TextEditCommand::MOVE_UP: |
| 1726 case ui::TextEditCommand::MOVE_DOWN: | 1693 case ui::TextEditCommand::MOVE_UP_AND_MODIFY_SELECTION: |
| 1694 case ui::TextEditCommand::INSERT_TEXT: |
| 1695 case ui::TextEditCommand::SET_MARK: |
| 1696 case ui::TextEditCommand::UNSELECT: |
| 1727 case ui::TextEditCommand::INVALID_COMMAND: | 1697 case ui::TextEditCommand::INVALID_COMMAND: |
| 1728 NOTREACHED(); | 1698 NOTREACHED(); |
| 1729 break; | 1699 break; |
| 1730 } | 1700 } |
| 1731 | 1701 |
| 1732 cursor_changed |= GetSelectionModel() != selection_model; | 1702 cursor_changed |= GetSelectionModel() != selection_model; |
| 1733 if (cursor_changed) | 1703 if (cursor_changed) |
| 1734 UpdateSelectionClipboard(); | 1704 UpdateSelectionClipboard(); |
| 1735 UpdateAfterChange(text_changed, cursor_changed); | 1705 UpdateAfterChange(text_changed, cursor_changed); |
| 1736 OnAfterUserAction(); | 1706 OnAfterUserAction(); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1991 RequestFocus(); | 1961 RequestFocus(); |
| 1992 model_->MoveCursorTo(mouse); | 1962 model_->MoveCursorTo(mouse); |
| 1993 if (!selection_clipboard_text.empty()) { | 1963 if (!selection_clipboard_text.empty()) { |
| 1994 model_->InsertText(selection_clipboard_text); | 1964 model_->InsertText(selection_clipboard_text); |
| 1995 UpdateAfterChange(true, true); | 1965 UpdateAfterChange(true, true); |
| 1996 } | 1966 } |
| 1997 OnAfterUserAction(); | 1967 OnAfterUserAction(); |
| 1998 } | 1968 } |
| 1999 | 1969 |
| 2000 } // namespace views | 1970 } // namespace views |
| OLD | NEW |