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 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "grit/ui_strings.h" | 10 #include "grit/ui_strings.h" |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
402 GetRenderText()->set_selection_color(GetSelectionTextColor()); | 402 GetRenderText()->set_selection_color(GetSelectionTextColor()); |
403 SchedulePaint(); | 403 SchedulePaint(); |
404 } | 404 } |
405 | 405 |
406 void Textfield::UseDefaultSelectionTextColor() { | 406 void Textfield::UseDefaultSelectionTextColor() { |
407 use_default_selection_text_color_ = true; | 407 use_default_selection_text_color_ = true; |
408 GetRenderText()->set_selection_color(GetSelectionTextColor()); | 408 GetRenderText()->set_selection_color(GetSelectionTextColor()); |
409 SchedulePaint(); | 409 SchedulePaint(); |
410 } | 410 } |
411 | 411 |
412 void Textfield::SetShadows(const gfx::ShadowValues& shadows) { | |
413 shadows_ = shadows; | |
414 SchedulePaint(); | |
415 } | |
416 | |
412 SkColor Textfield::GetSelectionBackgroundColor() const { | 417 SkColor Textfield::GetSelectionBackgroundColor() const { |
413 return use_default_selection_background_color_ ? | 418 return use_default_selection_background_color_ ? |
414 GetNativeTheme()->GetSystemColor( | 419 GetNativeTheme()->GetSystemColor( |
415 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused) : | 420 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused) : |
416 selection_background_color_; | 421 selection_background_color_; |
417 } | 422 } |
418 | 423 |
419 void Textfield::SetSelectionBackgroundColor(SkColor color) { | 424 void Textfield::SetSelectionBackgroundColor(SkColor color) { |
420 selection_background_color_ = color; | 425 selection_background_color_ = color; |
421 use_default_selection_background_color_ = false; | 426 use_default_selection_background_color_ = false; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
594 | 599 |
595 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 600 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
596 if (event.IsOnlyMiddleMouseButton()) { | 601 if (event.IsOnlyMiddleMouseButton()) { |
597 if (GetRenderText()->IsPointInSelection(event.location())) { | 602 if (GetRenderText()->IsPointInSelection(event.location())) { |
598 OnBeforeUserAction(); | 603 OnBeforeUserAction(); |
599 ClearSelection(); | 604 ClearSelection(); |
600 ui::ScopedClipboardWriter( | 605 ui::ScopedClipboardWriter( |
601 ui::Clipboard::GetForCurrentThread(), | 606 ui::Clipboard::GetForCurrentThread(), |
602 ui::CLIPBOARD_TYPE_SELECTION).WriteText(base::string16()); | 607 ui::CLIPBOARD_TYPE_SELECTION).WriteText(base::string16()); |
603 OnAfterUserAction(); | 608 OnAfterUserAction(); |
604 } else if(!read_only()) { | 609 } else if (!read_only()) { |
605 PasteSelectionClipboard(event); | 610 PasteSelectionClipboard(event); |
606 } | 611 } |
607 } | 612 } |
608 #endif | 613 #endif |
609 } | 614 } |
610 | 615 |
611 return true; | 616 return true; |
612 } | 617 } |
613 | 618 |
614 bool Textfield::OnMouseDragged(const ui::MouseEvent& event) { | 619 bool Textfield::OnMouseDragged(const ui::MouseEvent& event) { |
(...skipping 25 matching lines...) Expand all Loading... | |
640 drag_selection_timer_.Stop(); | 645 drag_selection_timer_.Stop(); |
641 // Cancel suspected drag initiations, the user was clicking in the selection. | 646 // Cancel suspected drag initiations, the user was clicking in the selection. |
642 if (initiating_drag_) | 647 if (initiating_drag_) |
643 MoveCursorTo(event.location(), false); | 648 MoveCursorTo(event.location(), false); |
644 initiating_drag_ = false; | 649 initiating_drag_ = false; |
645 UpdateSelectionClipboard(); | 650 UpdateSelectionClipboard(); |
646 OnAfterUserAction(); | 651 OnAfterUserAction(); |
647 } | 652 } |
648 | 653 |
649 bool Textfield::OnKeyPressed(const ui::KeyEvent& event) { | 654 bool Textfield::OnKeyPressed(const ui::KeyEvent& event) { |
655 // Since HandleKeyEvent() might destroy |this|, get a weak pointer and verify | |
656 // it isn't null before proceeding. | |
sadrul
2014/07/02 17:44:04
This change should be in a separate CL, with a cor
| |
657 base::WeakPtr<Textfield> textfield(weak_ptr_factory_.GetWeakPtr()); | |
650 bool handled = controller_ && controller_->HandleKeyEvent(this, event); | 658 bool handled = controller_ && controller_->HandleKeyEvent(this, event); |
651 | 659 |
660 if (!textfield) | |
661 return handled; | |
662 | |
652 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 663 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
653 ui::TextEditKeyBindingsDelegateAuraLinux* delegate = | 664 ui::TextEditKeyBindingsDelegateAuraLinux* delegate = |
654 ui::GetTextEditKeyBindingsDelegate(); | 665 ui::GetTextEditKeyBindingsDelegate(); |
655 std::vector<ui::TextEditCommandAuraLinux> commands; | 666 std::vector<ui::TextEditCommandAuraLinux> commands; |
656 if (!handled && delegate && delegate->MatchEvent(event, &commands)) { | 667 if (!handled && delegate && delegate->MatchEvent(event, &commands)) { |
657 const bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT; | 668 const bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT; |
658 for (size_t i = 0; i < commands.size(); ++i) { | 669 for (size_t i = 0; i < commands.size(); ++i) { |
659 const int command = GetViewsCommand(commands[i], rtl); | 670 const int command = GetViewsCommand(commands[i], rtl); |
660 if (IsCommandIdEnabled(command)) { | 671 if (IsCommandIdEnabled(command)) { |
661 ExecuteCommand(command); | 672 ExecuteCommand(command); |
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1581 // Draw placeholder text if needed. | 1592 // Draw placeholder text if needed. |
1582 gfx::RenderText* render_text = GetRenderText(); | 1593 gfx::RenderText* render_text = GetRenderText(); |
1583 if (text().empty() && !GetPlaceholderText().empty()) { | 1594 if (text().empty() && !GetPlaceholderText().empty()) { |
1584 canvas->DrawStringRect(GetPlaceholderText(), GetFontList(), | 1595 canvas->DrawStringRect(GetPlaceholderText(), GetFontList(), |
1585 placeholder_text_color(), render_text->display_rect()); | 1596 placeholder_text_color(), render_text->display_rect()); |
1586 } | 1597 } |
1587 | 1598 |
1588 // Draw the text, cursor, and selection. | 1599 // Draw the text, cursor, and selection. |
1589 render_text->set_cursor_visible(cursor_visible_ && !drop_cursor_visible_ && | 1600 render_text->set_cursor_visible(cursor_visible_ && !drop_cursor_visible_ && |
1590 !HasSelection()); | 1601 !HasSelection()); |
1602 render_text->set_shadows(shadows_); | |
1603 | |
1591 render_text->Draw(canvas); | 1604 render_text->Draw(canvas); |
1592 | 1605 |
1593 // Draw the detached drop cursor that marks where the text will be dropped. | 1606 // Draw the detached drop cursor that marks where the text will be dropped. |
1594 if (drop_cursor_visible_) | 1607 if (drop_cursor_visible_) |
1595 render_text->DrawCursor(canvas, drop_cursor_position_); | 1608 render_text->DrawCursor(canvas, drop_cursor_position_); |
1596 | 1609 |
1597 canvas->Restore(); | 1610 canvas->Restore(); |
1598 } | 1611 } |
1599 | 1612 |
1600 void Textfield::MoveCursorTo(const gfx::Point& point, bool select) { | 1613 void Textfield::MoveCursorTo(const gfx::Point& point, bool select) { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1761 const size_t length = selection_clipboard_text.length(); | 1774 const size_t length = selection_clipboard_text.length(); |
1762 range = gfx::Range(range.start() + length, range.end() + length); | 1775 range = gfx::Range(range.start() + length, range.end() + length); |
1763 } | 1776 } |
1764 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); | 1777 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); |
1765 UpdateAfterChange(true, true); | 1778 UpdateAfterChange(true, true); |
1766 OnAfterUserAction(); | 1779 OnAfterUserAction(); |
1767 } | 1780 } |
1768 } | 1781 } |
1769 | 1782 |
1770 } // namespace views | 1783 } // namespace views |
OLD | NEW |