| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "views/controls/textfield/native_textfield_views.h" | 5 #include "views/controls/textfield/native_textfield_views.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 cursor_bounds_.x(), | 420 cursor_bounds_.x(), |
| 421 cursor_bounds_.y(), | 421 cursor_bounds_.y(), |
| 422 insert_ ? 0 : cursor_bounds_.width(), | 422 insert_ ? 0 : cursor_bounds_.width(), |
| 423 cursor_bounds_.height()); | 423 cursor_bounds_.height()); |
| 424 } | 424 } |
| 425 } | 425 } |
| 426 | 426 |
| 427 bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) { | 427 bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) { |
| 428 // TODO(oshima): handle IME. | 428 // TODO(oshima): handle IME. |
| 429 if (key_event.GetType() == views::Event::ET_KEY_PRESSED) { | 429 if (key_event.GetType() == views::Event::ET_KEY_PRESSED) { |
| 430 app::KeyboardCode key_code = key_event.GetKeyCode(); | 430 ui::KeyboardCode key_code = key_event.GetKeyCode(); |
| 431 // TODO(oshima): shift-tab does not work. Figure out why and fix. | 431 // TODO(oshima): shift-tab does not work. Figure out why and fix. |
| 432 if (key_code == app::VKEY_TAB) | 432 if (key_code == ui::VKEY_TAB) |
| 433 return false; | 433 return false; |
| 434 bool selection = key_event.IsShiftDown(); | 434 bool selection = key_event.IsShiftDown(); |
| 435 bool control = key_event.IsControlDown(); | 435 bool control = key_event.IsControlDown(); |
| 436 bool text_changed = false; | 436 bool text_changed = false; |
| 437 bool cursor_changed = false; | 437 bool cursor_changed = false; |
| 438 switch (key_code) { | 438 switch (key_code) { |
| 439 case app::VKEY_A: | 439 case ui::VKEY_A: |
| 440 if (control) { | 440 if (control) { |
| 441 model_->SelectAll(); | 441 model_->SelectAll(); |
| 442 cursor_changed = true; | 442 cursor_changed = true; |
| 443 } | 443 } |
| 444 break; | 444 break; |
| 445 case app::VKEY_X: | 445 case ui::VKEY_X: |
| 446 if (control) | 446 if (control) |
| 447 text_changed = model_->Cut(); | 447 text_changed = model_->Cut(); |
| 448 break; | 448 break; |
| 449 case app::VKEY_C: | 449 case ui::VKEY_C: |
| 450 if (control) | 450 if (control) |
| 451 model_->Copy(); | 451 model_->Copy(); |
| 452 break; | 452 break; |
| 453 case app::VKEY_V: | 453 case ui::VKEY_V: |
| 454 if (control) | 454 if (control) |
| 455 text_changed = model_->Paste(); | 455 text_changed = model_->Paste(); |
| 456 break; | 456 break; |
| 457 case app::VKEY_RIGHT: | 457 case ui::VKEY_RIGHT: |
| 458 control ? model_->MoveCursorToNextWord(selection) | 458 control ? model_->MoveCursorToNextWord(selection) |
| 459 : model_->MoveCursorRight(selection); | 459 : model_->MoveCursorRight(selection); |
| 460 cursor_changed = true; | 460 cursor_changed = true; |
| 461 break; | 461 break; |
| 462 case app::VKEY_LEFT: | 462 case ui::VKEY_LEFT: |
| 463 control ? model_->MoveCursorToPreviousWord(selection) | 463 control ? model_->MoveCursorToPreviousWord(selection) |
| 464 : model_->MoveCursorLeft(selection); | 464 : model_->MoveCursorLeft(selection); |
| 465 cursor_changed = true; | 465 cursor_changed = true; |
| 466 break; | 466 break; |
| 467 case app::VKEY_END: | 467 case ui::VKEY_END: |
| 468 model_->MoveCursorToEnd(selection); | 468 model_->MoveCursorToEnd(selection); |
| 469 cursor_changed = true; | 469 cursor_changed = true; |
| 470 break; | 470 break; |
| 471 case app::VKEY_HOME: | 471 case ui::VKEY_HOME: |
| 472 model_->MoveCursorToStart(selection); | 472 model_->MoveCursorToStart(selection); |
| 473 cursor_changed = true; | 473 cursor_changed = true; |
| 474 break; | 474 break; |
| 475 case app::VKEY_BACK: | 475 case ui::VKEY_BACK: |
| 476 if (!model_->HasSelection()) { | 476 if (!model_->HasSelection()) { |
| 477 if (selection && control) { | 477 if (selection && control) { |
| 478 // If both shift and control are pressed, then erase upto the | 478 // If both shift and control are pressed, then erase upto the |
| 479 // beginning of the buffer in ChromeOS. In windows, do nothing. | 479 // beginning of the buffer in ChromeOS. In windows, do nothing. |
| 480 #if defined(OS_WIN) | 480 #if defined(OS_WIN) |
| 481 break; | 481 break; |
| 482 #else | 482 #else |
| 483 model_->MoveCursorToStart(true); | 483 model_->MoveCursorToStart(true); |
| 484 #endif | 484 #endif |
| 485 } else if (control) { | 485 } else if (control) { |
| 486 // If only control is pressed, then erase the previous word. | 486 // If only control is pressed, then erase the previous word. |
| 487 model_->MoveCursorToPreviousWord(true); | 487 model_->MoveCursorToPreviousWord(true); |
| 488 } | 488 } |
| 489 } | 489 } |
| 490 text_changed = model_->Backspace(); | 490 text_changed = model_->Backspace(); |
| 491 cursor_changed = true; | 491 cursor_changed = true; |
| 492 break; | 492 break; |
| 493 case app::VKEY_DELETE: | 493 case ui::VKEY_DELETE: |
| 494 if (!model_->HasSelection()) { | 494 if (!model_->HasSelection()) { |
| 495 if (selection && control) { | 495 if (selection && control) { |
| 496 // If both shift and control are pressed, then erase upto the | 496 // If both shift and control are pressed, then erase upto the |
| 497 // end of the buffer in ChromeOS. In windows, do nothing. | 497 // end of the buffer in ChromeOS. In windows, do nothing. |
| 498 #if defined(OS_WIN) | 498 #if defined(OS_WIN) |
| 499 break; | 499 break; |
| 500 #else | 500 #else |
| 501 model_->MoveCursorToEnd(true); | 501 model_->MoveCursorToEnd(true); |
| 502 #endif | 502 #endif |
| 503 } else if (control) { | 503 } else if (control) { |
| 504 // If only control is pressed, then erase the next word. | 504 // If only control is pressed, then erase the next word. |
| 505 model_->MoveCursorToNextWord(true); | 505 model_->MoveCursorToNextWord(true); |
| 506 } | 506 } |
| 507 } | 507 } |
| 508 text_changed = model_->Delete(); | 508 text_changed = model_->Delete(); |
| 509 break; | 509 break; |
| 510 case app::VKEY_INSERT: | 510 case ui::VKEY_INSERT: |
| 511 insert_ = !insert_; | 511 insert_ = !insert_; |
| 512 cursor_changed = true; | 512 cursor_changed = true; |
| 513 break; | 513 break; |
| 514 default: | 514 default: |
| 515 break; | 515 break; |
| 516 } | 516 } |
| 517 char16 print_char = GetPrintableChar(key_event); | 517 char16 print_char = GetPrintableChar(key_event); |
| 518 if (!control && print_char) { | 518 if (!control && print_char) { |
| 519 if (insert_) | 519 if (insert_) |
| 520 model_->Insert(print_char); | 520 model_->Insert(print_char); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 537 SchedulePaint(); | 537 SchedulePaint(); |
| 538 return true; | 538 return true; |
| 539 } | 539 } |
| 540 } | 540 } |
| 541 return false; | 541 return false; |
| 542 } | 542 } |
| 543 | 543 |
| 544 char16 NativeTextfieldViews::GetPrintableChar(const KeyEvent& key_event) { | 544 char16 NativeTextfieldViews::GetPrintableChar(const KeyEvent& key_event) { |
| 545 // TODO(oshima): IME, i18n support. | 545 // TODO(oshima): IME, i18n support. |
| 546 // This only works for UCS-2 characters. | 546 // This only works for UCS-2 characters. |
| 547 app::KeyboardCode key_code = key_event.GetKeyCode(); | 547 ui::KeyboardCode key_code = key_event.GetKeyCode(); |
| 548 bool shift = key_event.IsShiftDown(); | 548 bool shift = key_event.IsShiftDown(); |
| 549 bool upper = shift ^ key_event.IsCapsLockDown(); | 549 bool upper = shift ^ key_event.IsCapsLockDown(); |
| 550 // TODO(oshima): We should have a utility function | 550 // TODO(oshima): We should have a utility function |
| 551 // under app to convert a KeyboardCode to a printable character, | 551 // under app to convert a KeyboardCode to a printable character, |
| 552 // probably in keyboard_code_conversion{.h, _x | 552 // probably in keyboard_code_conversion{.h, _x |
| 553 switch (key_code) { | 553 switch (key_code) { |
| 554 case app::VKEY_NUMPAD0: | 554 case ui::VKEY_NUMPAD0: |
| 555 return '0'; | 555 return '0'; |
| 556 case app::VKEY_NUMPAD1: | 556 case ui::VKEY_NUMPAD1: |
| 557 return '1'; | 557 return '1'; |
| 558 case app::VKEY_NUMPAD2: | 558 case ui::VKEY_NUMPAD2: |
| 559 return '2'; | 559 return '2'; |
| 560 case app::VKEY_NUMPAD3: | 560 case ui::VKEY_NUMPAD3: |
| 561 return '3'; | 561 return '3'; |
| 562 case app::VKEY_NUMPAD4: | 562 case ui::VKEY_NUMPAD4: |
| 563 return '4'; | 563 return '4'; |
| 564 case app::VKEY_NUMPAD5: | 564 case ui::VKEY_NUMPAD5: |
| 565 return '5'; | 565 return '5'; |
| 566 case app::VKEY_NUMPAD6: | 566 case ui::VKEY_NUMPAD6: |
| 567 return '6'; | 567 return '6'; |
| 568 case app::VKEY_NUMPAD7: | 568 case ui::VKEY_NUMPAD7: |
| 569 return '7'; | 569 return '7'; |
| 570 case app::VKEY_NUMPAD8: | 570 case ui::VKEY_NUMPAD8: |
| 571 return '8'; | 571 return '8'; |
| 572 case app::VKEY_NUMPAD9: | 572 case ui::VKEY_NUMPAD9: |
| 573 return '9'; | 573 return '9'; |
| 574 case app::VKEY_MULTIPLY: | 574 case ui::VKEY_MULTIPLY: |
| 575 return '*'; | 575 return '*'; |
| 576 case app::VKEY_ADD: | 576 case ui::VKEY_ADD: |
| 577 return '+'; | 577 return '+'; |
| 578 case app::VKEY_SUBTRACT: | 578 case ui::VKEY_SUBTRACT: |
| 579 return '-'; | 579 return '-'; |
| 580 case app::VKEY_DECIMAL: | 580 case ui::VKEY_DECIMAL: |
| 581 return '.'; | 581 return '.'; |
| 582 case app::VKEY_DIVIDE: | 582 case ui::VKEY_DIVIDE: |
| 583 return '/'; | 583 return '/'; |
| 584 case app::VKEY_SPACE: | 584 case ui::VKEY_SPACE: |
| 585 return ' '; | 585 return ' '; |
| 586 case app::VKEY_0: | 586 case ui::VKEY_0: |
| 587 return shift ? ')' : '0'; | 587 return shift ? ')' : '0'; |
| 588 case app::VKEY_1: | 588 case ui::VKEY_1: |
| 589 return shift ? '!' : '1'; | 589 return shift ? '!' : '1'; |
| 590 case app::VKEY_2: | 590 case ui::VKEY_2: |
| 591 return shift ? '@' : '2'; | 591 return shift ? '@' : '2'; |
| 592 case app::VKEY_3: | 592 case ui::VKEY_3: |
| 593 return shift ? '#' : '3'; | 593 return shift ? '#' : '3'; |
| 594 case app::VKEY_4: | 594 case ui::VKEY_4: |
| 595 return shift ? '$' : '4'; | 595 return shift ? '$' : '4'; |
| 596 case app::VKEY_5: | 596 case ui::VKEY_5: |
| 597 return shift ? '%' : '5'; | 597 return shift ? '%' : '5'; |
| 598 case app::VKEY_6: | 598 case ui::VKEY_6: |
| 599 return shift ? '^' : '6'; | 599 return shift ? '^' : '6'; |
| 600 case app::VKEY_7: | 600 case ui::VKEY_7: |
| 601 return shift ? '&' : '7'; | 601 return shift ? '&' : '7'; |
| 602 case app::VKEY_8: | 602 case ui::VKEY_8: |
| 603 return shift ? '*' : '8'; | 603 return shift ? '*' : '8'; |
| 604 case app::VKEY_9: | 604 case ui::VKEY_9: |
| 605 return shift ? '(' : '9'; | 605 return shift ? '(' : '9'; |
| 606 | 606 |
| 607 case app::VKEY_A: | 607 case ui::VKEY_A: |
| 608 case app::VKEY_B: | 608 case ui::VKEY_B: |
| 609 case app::VKEY_C: | 609 case ui::VKEY_C: |
| 610 case app::VKEY_D: | 610 case ui::VKEY_D: |
| 611 case app::VKEY_E: | 611 case ui::VKEY_E: |
| 612 case app::VKEY_F: | 612 case ui::VKEY_F: |
| 613 case app::VKEY_G: | 613 case ui::VKEY_G: |
| 614 case app::VKEY_H: | 614 case ui::VKEY_H: |
| 615 case app::VKEY_I: | 615 case ui::VKEY_I: |
| 616 case app::VKEY_J: | 616 case ui::VKEY_J: |
| 617 case app::VKEY_K: | 617 case ui::VKEY_K: |
| 618 case app::VKEY_L: | 618 case ui::VKEY_L: |
| 619 case app::VKEY_M: | 619 case ui::VKEY_M: |
| 620 case app::VKEY_N: | 620 case ui::VKEY_N: |
| 621 case app::VKEY_O: | 621 case ui::VKEY_O: |
| 622 case app::VKEY_P: | 622 case ui::VKEY_P: |
| 623 case app::VKEY_Q: | 623 case ui::VKEY_Q: |
| 624 case app::VKEY_R: | 624 case ui::VKEY_R: |
| 625 case app::VKEY_S: | 625 case ui::VKEY_S: |
| 626 case app::VKEY_T: | 626 case ui::VKEY_T: |
| 627 case app::VKEY_U: | 627 case ui::VKEY_U: |
| 628 case app::VKEY_V: | 628 case ui::VKEY_V: |
| 629 case app::VKEY_W: | 629 case ui::VKEY_W: |
| 630 case app::VKEY_X: | 630 case ui::VKEY_X: |
| 631 case app::VKEY_Y: | 631 case ui::VKEY_Y: |
| 632 case app::VKEY_Z: | 632 case ui::VKEY_Z: |
| 633 return (upper ? 'A' : 'a') + (key_code - app::VKEY_A); | 633 return (upper ? 'A' : 'a') + (key_code - ui::VKEY_A); |
| 634 case app::VKEY_OEM_1: | 634 case ui::VKEY_OEM_1: |
| 635 return shift ? ':' : ';'; | 635 return shift ? ':' : ';'; |
| 636 case app::VKEY_OEM_PLUS: | 636 case ui::VKEY_OEM_PLUS: |
| 637 return shift ? '+' : '='; | 637 return shift ? '+' : '='; |
| 638 case app::VKEY_OEM_COMMA: | 638 case ui::VKEY_OEM_COMMA: |
| 639 return shift ? '<' : ','; | 639 return shift ? '<' : ','; |
| 640 case app::VKEY_OEM_MINUS: | 640 case ui::VKEY_OEM_MINUS: |
| 641 return shift ? '_' : '-'; | 641 return shift ? '_' : '-'; |
| 642 case app::VKEY_OEM_PERIOD: | 642 case ui::VKEY_OEM_PERIOD: |
| 643 return shift ? '>' : '.'; | 643 return shift ? '>' : '.'; |
| 644 case app::VKEY_OEM_2: | 644 case ui::VKEY_OEM_2: |
| 645 return shift ? '?' : '/'; | 645 return shift ? '?' : '/'; |
| 646 case app::VKEY_OEM_3: | 646 case ui::VKEY_OEM_3: |
| 647 return shift ? '~' : '`'; | 647 return shift ? '~' : '`'; |
| 648 case app::VKEY_OEM_4: | 648 case ui::VKEY_OEM_4: |
| 649 return shift ? '}' : ']'; | 649 return shift ? '}' : ']'; |
| 650 case app::VKEY_OEM_5: | 650 case ui::VKEY_OEM_5: |
| 651 return shift ? '|' : '\\'; | 651 return shift ? '|' : '\\'; |
| 652 case app::VKEY_OEM_6: | 652 case ui::VKEY_OEM_6: |
| 653 return shift ? '{' : '['; | 653 return shift ? '{' : '['; |
| 654 case app::VKEY_OEM_7: | 654 case ui::VKEY_OEM_7: |
| 655 return shift ? '"' : '\''; | 655 return shift ? '"' : '\''; |
| 656 default: | 656 default: |
| 657 return 0; | 657 return 0; |
| 658 } | 658 } |
| 659 } | 659 } |
| 660 | 660 |
| 661 size_t NativeTextfieldViews::FindCursorPosition(const gfx::Point& point) const { | 661 size_t NativeTextfieldViews::FindCursorPosition(const gfx::Point& point) const { |
| 662 // TODO(oshima): BIDI/i18n support. | 662 // TODO(oshima): BIDI/i18n support. |
| 663 gfx::Font font = GetFont(); | 663 gfx::Font font = GetFont(); |
| 664 gfx::Insets insets = GetInsets(); | 664 gfx::Insets insets = GetInsets(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 } | 738 } |
| 739 | 739 |
| 740 void NativeTextfieldViews::TextfieldBorder::SetInsets(int top, | 740 void NativeTextfieldViews::TextfieldBorder::SetInsets(int top, |
| 741 int left, | 741 int left, |
| 742 int bottom, | 742 int bottom, |
| 743 int right) { | 743 int right) { |
| 744 insets_.Set(top, left, bottom, right); | 744 insets_.Set(top, left, bottom, right); |
| 745 } | 745 } |
| 746 | 746 |
| 747 } // namespace views | 747 } // namespace views |
| OLD | NEW |