Chromium Code Reviews| 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 use_default_selection_background_color_(true), | 261 use_default_selection_background_color_(true), |
| 262 text_color_(SK_ColorBLACK), | 262 text_color_(SK_ColorBLACK), |
| 263 background_color_(SK_ColorWHITE), | 263 background_color_(SK_ColorWHITE), |
| 264 selection_text_color_(SK_ColorWHITE), | 264 selection_text_color_(SK_ColorWHITE), |
| 265 selection_background_color_(SK_ColorBLUE), | 265 selection_background_color_(SK_ColorBLUE), |
| 266 placeholder_text_color_(kDefaultPlaceholderTextColor), | 266 placeholder_text_color_(kDefaultPlaceholderTextColor), |
| 267 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT), | 267 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT), |
| 268 performing_user_action_(false), | 268 performing_user_action_(false), |
| 269 skip_input_method_cancel_composition_(false), | 269 skip_input_method_cancel_composition_(false), |
| 270 cursor_visible_(false), | 270 cursor_visible_(false), |
| 271 has_shadow_(false), | |
| 271 drop_cursor_visible_(false), | 272 drop_cursor_visible_(false), |
| 272 initiating_drag_(false), | 273 initiating_drag_(false), |
| 273 aggregated_clicks_(0), | 274 aggregated_clicks_(0), |
| 274 weak_ptr_factory_(this) { | 275 weak_ptr_factory_(this) { |
| 275 set_context_menu_controller(this); | 276 set_context_menu_controller(this); |
| 276 set_drag_controller(this); | 277 set_drag_controller(this); |
| 277 SetBorder(scoped_ptr<Border>(new FocusableBorder())); | 278 SetBorder(scoped_ptr<Border>(new FocusableBorder())); |
| 278 SetFocusable(true); | 279 SetFocusable(true); |
| 279 | 280 |
| 280 if (ViewsDelegate::views_delegate) { | 281 if (ViewsDelegate::views_delegate) { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 424 SchedulePaint(); | 425 SchedulePaint(); |
| 425 } | 426 } |
| 426 | 427 |
| 427 void Textfield::UseDefaultSelectionBackgroundColor() { | 428 void Textfield::UseDefaultSelectionBackgroundColor() { |
| 428 use_default_selection_background_color_ = true; | 429 use_default_selection_background_color_ = true; |
| 429 GetRenderText()->set_selection_background_focused_color( | 430 GetRenderText()->set_selection_background_focused_color( |
| 430 GetSelectionBackgroundColor()); | 431 GetSelectionBackgroundColor()); |
| 431 SchedulePaint(); | 432 SchedulePaint(); |
| 432 } | 433 } |
| 433 | 434 |
| 435 void Textfield::SetHasShadow(bool has_shadow) { | |
| 436 has_shadow_ = has_shadow; | |
| 437 SchedulePaint(); | |
| 438 } | |
| 439 | |
| 434 bool Textfield::GetCursorEnabled() const { | 440 bool Textfield::GetCursorEnabled() const { |
| 435 return GetRenderText()->cursor_enabled(); | 441 return GetRenderText()->cursor_enabled(); |
| 436 } | 442 } |
| 437 | 443 |
| 438 void Textfield::SetCursorEnabled(bool enabled) { | 444 void Textfield::SetCursorEnabled(bool enabled) { |
| 439 GetRenderText()->SetCursorEnabled(enabled); | 445 GetRenderText()->SetCursorEnabled(enabled); |
| 440 } | 446 } |
| 441 | 447 |
| 442 const gfx::FontList& Textfield::GetFontList() const { | 448 const gfx::FontList& Textfield::GetFontList() const { |
| 443 return GetRenderText()->font_list(); | 449 return GetRenderText()->font_list(); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 640 drag_selection_timer_.Stop(); | 646 drag_selection_timer_.Stop(); |
| 641 // Cancel suspected drag initiations, the user was clicking in the selection. | 647 // Cancel suspected drag initiations, the user was clicking in the selection. |
| 642 if (initiating_drag_) | 648 if (initiating_drag_) |
| 643 MoveCursorTo(event.location(), false); | 649 MoveCursorTo(event.location(), false); |
| 644 initiating_drag_ = false; | 650 initiating_drag_ = false; |
| 645 UpdateSelectionClipboard(); | 651 UpdateSelectionClipboard(); |
| 646 OnAfterUserAction(); | 652 OnAfterUserAction(); |
| 647 } | 653 } |
| 648 | 654 |
| 649 bool Textfield::OnKeyPressed(const ui::KeyEvent& event) { | 655 bool Textfield::OnKeyPressed(const ui::KeyEvent& event) { |
| 656 base::WeakPtr<Textfield> textfield(weak_ptr_factory_.GetWeakPtr()); | |
|
flackr
2014/06/26 17:33:08
nit: Might be worth a comment that HandleKeyEvent
Nina
2014/06/27 15:20:39
Done.
| |
| 650 bool handled = controller_ && controller_->HandleKeyEvent(this, event); | 657 bool handled = controller_ && controller_->HandleKeyEvent(this, event); |
| 651 | 658 |
| 659 if (!textfield) | |
| 660 return handled; | |
| 661 | |
| 652 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 662 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 653 ui::TextEditKeyBindingsDelegateAuraLinux* delegate = | 663 ui::TextEditKeyBindingsDelegateAuraLinux* delegate = |
| 654 ui::GetTextEditKeyBindingsDelegate(); | 664 ui::GetTextEditKeyBindingsDelegate(); |
| 655 std::vector<ui::TextEditCommandAuraLinux> commands; | 665 std::vector<ui::TextEditCommandAuraLinux> commands; |
| 656 if (!handled && delegate && delegate->MatchEvent(event, &commands)) { | 666 if (!handled && delegate && delegate->MatchEvent(event, &commands)) { |
| 657 const bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT; | 667 const bool rtl = GetTextDirection() == base::i18n::RIGHT_TO_LEFT; |
| 658 for (size_t i = 0; i < commands.size(); ++i) { | 668 for (size_t i = 0; i < commands.size(); ++i) { |
| 659 const int command = GetViewsCommand(commands[i], rtl); | 669 const int command = GetViewsCommand(commands[i], rtl); |
| 660 if (IsCommandIdEnabled(command)) { | 670 if (IsCommandIdEnabled(command)) { |
| 661 ExecuteCommand(command); | 671 ExecuteCommand(command); |
| (...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1581 // Draw placeholder text if needed. | 1591 // Draw placeholder text if needed. |
| 1582 gfx::RenderText* render_text = GetRenderText(); | 1592 gfx::RenderText* render_text = GetRenderText(); |
| 1583 if (text().empty() && !GetPlaceholderText().empty()) { | 1593 if (text().empty() && !GetPlaceholderText().empty()) { |
| 1584 canvas->DrawStringRect(GetPlaceholderText(), GetFontList(), | 1594 canvas->DrawStringRect(GetPlaceholderText(), GetFontList(), |
| 1585 placeholder_text_color(), render_text->display_rect()); | 1595 placeholder_text_color(), render_text->display_rect()); |
| 1586 } | 1596 } |
| 1587 | 1597 |
| 1588 // Draw the text, cursor, and selection. | 1598 // Draw the text, cursor, and selection. |
| 1589 render_text->set_cursor_visible(cursor_visible_ && !drop_cursor_visible_ && | 1599 render_text->set_cursor_visible(cursor_visible_ && !drop_cursor_visible_ && |
| 1590 !HasSelection()); | 1600 !HasSelection()); |
| 1601 | |
| 1602 if (has_shadow_) { | |
| 1603 // Draw a basic shadow underneath the text. | |
| 1604 gfx::ShadowValues shadows; | |
| 1605 shadows.push_back(gfx::ShadowValue(gfx::Point(0, 1), 10, SK_ColorBLACK)); | |
|
flackr
2014/06/26 17:33:08
Maybe we should pass the ShadowValues in when sett
| |
| 1606 render_text->set_shadows(shadows); | |
| 1607 } | |
| 1608 | |
| 1591 render_text->Draw(canvas); | 1609 render_text->Draw(canvas); |
| 1592 | 1610 |
| 1593 // Draw the detached drop cursor that marks where the text will be dropped. | 1611 // Draw the detached drop cursor that marks where the text will be dropped. |
| 1594 if (drop_cursor_visible_) | 1612 if (drop_cursor_visible_) |
| 1595 render_text->DrawCursor(canvas, drop_cursor_position_); | 1613 render_text->DrawCursor(canvas, drop_cursor_position_); |
| 1596 | 1614 |
| 1597 canvas->Restore(); | 1615 canvas->Restore(); |
| 1598 } | 1616 } |
| 1599 | 1617 |
| 1600 void Textfield::MoveCursorTo(const gfx::Point& point, bool select) { | 1618 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(); | 1779 const size_t length = selection_clipboard_text.length(); |
| 1762 range = gfx::Range(range.start() + length, range.end() + length); | 1780 range = gfx::Range(range.start() + length, range.end() + length); |
| 1763 } | 1781 } |
| 1764 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); | 1782 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); |
| 1765 UpdateAfterChange(true, true); | 1783 UpdateAfterChange(true, true); |
| 1766 OnAfterUserAction(); | 1784 OnAfterUserAction(); |
| 1767 } | 1785 } |
| 1768 } | 1786 } |
| 1769 | 1787 |
| 1770 } // namespace views | 1788 } // namespace views |
| OLD | NEW |