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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 479 return model_->HasCompositionText(); | 479 return model_->HasCompositionText(); |
| 480 } | 480 } |
| 481 | 481 |
| 482 const gfx::Range& Textfield::GetSelectedRange() const { | 482 const gfx::Range& Textfield::GetSelectedRange() const { |
| 483 return GetRenderText()->selection(); | 483 return GetRenderText()->selection(); |
| 484 } | 484 } |
| 485 | 485 |
| 486 void Textfield::SelectRange(const gfx::Range& range) { | 486 void Textfield::SelectRange(const gfx::Range& range) { |
| 487 model_->SelectRange(range); | 487 model_->SelectRange(range); |
| 488 UpdateAfterChange(false, true); | 488 UpdateAfterChange(false, true); |
| 489 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_SELECTION_CHANGED, true); | |
| 489 } | 490 } |
| 490 | 491 |
| 491 const gfx::SelectionModel& Textfield::GetSelectionModel() const { | 492 const gfx::SelectionModel& Textfield::GetSelectionModel() const { |
| 492 return GetRenderText()->selection_model(); | 493 return GetRenderText()->selection_model(); |
| 493 } | 494 } |
| 494 | 495 |
| 495 void Textfield::SelectSelectionModel(const gfx::SelectionModel& sel) { | 496 void Textfield::SelectSelectionModel(const gfx::SelectionModel& sel) { |
| 496 model_->SelectSelectionModel(sel); | 497 model_->SelectSelectionModel(sel); |
| 497 UpdateAfterChange(false, true); | 498 UpdateAfterChange(false, true); |
| 498 } | 499 } |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 930 state->placeholder = GetPlaceholderText(); | 931 state->placeholder = GetPlaceholderText(); |
| 931 | 932 |
| 932 const gfx::Range range = GetSelectedRange(); | 933 const gfx::Range range = GetSelectedRange(); |
| 933 state->selection_start = range.start(); | 934 state->selection_start = range.start(); |
| 934 state->selection_end = range.end(); | 935 state->selection_end = range.end(); |
| 935 | 936 |
| 936 if (!read_only()) { | 937 if (!read_only()) { |
| 937 state->set_value_callback = | 938 state->set_value_callback = |
| 938 base::Bind(&Textfield::AccessibilitySetValue, | 939 base::Bind(&Textfield::AccessibilitySetValue, |
| 939 weak_ptr_factory_.GetWeakPtr()); | 940 weak_ptr_factory_.GetWeakPtr()); |
| 941 state->replace_selection_callback = | |
| 942 base::Bind(&Textfield::AccessibilityReplaceSelection, | |
| 943 weak_ptr_factory_.GetWeakPtr()); | |
| 940 } | 944 } |
| 941 } | 945 } |
| 942 | 946 |
| 943 void Textfield::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 947 void Textfield::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 944 // Textfield insets include a reasonable amount of whitespace on all sides of | 948 // Textfield insets include a reasonable amount of whitespace on all sides of |
| 945 // the default font list. Fallback fonts with larger heights may paint over | 949 // the default font list. Fallback fonts with larger heights may paint over |
| 946 // the vertical whitespace as needed. Alternate solutions involve undesirable | 950 // the vertical whitespace as needed. Alternate solutions involve undesirable |
| 947 // behavior like changing the default font size, shrinking some fallback fonts | 951 // behavior like changing the default font size, shrinking some fallback fonts |
| 948 // beyond their legibility, or enlarging controls dynamically with content. | 952 // beyond their legibility, or enlarging controls dynamically with content. |
| 949 gfx::Rect bounds = GetContentsBounds(); | 953 gfx::Rect bounds = GetContentsBounds(); |
| (...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1770 //////////////////////////////////////////////////////////////////////////////// | 1774 //////////////////////////////////////////////////////////////////////////////// |
| 1771 // Textfield, private: | 1775 // Textfield, private: |
| 1772 | 1776 |
| 1773 void Textfield::AccessibilitySetValue(const base::string16& new_value) { | 1777 void Textfield::AccessibilitySetValue(const base::string16& new_value) { |
| 1774 if (!read_only()) { | 1778 if (!read_only()) { |
| 1775 SetText(new_value); | 1779 SetText(new_value); |
| 1776 ClearSelection(); | 1780 ClearSelection(); |
| 1777 } | 1781 } |
| 1778 } | 1782 } |
| 1779 | 1783 |
| 1784 void Textfield::AccessibilityReplaceSelection(const base::string16& new_value) { | |
| 1785 if (!read_only()) { | |
| 1786 InsertOrReplaceText(new_value); | |
| 1787 ClearSelection(); | |
|
tapted
2016/09/27 07:16:30
do we want to extend the selection here too?
Patti Lor
2016/10/20 04:19:34
No - Cocoa doesn't, so I was following that behavi
| |
| 1788 } | |
| 1789 } | |
| 1790 | |
| 1780 void Textfield::UpdateBackgroundColor() { | 1791 void Textfield::UpdateBackgroundColor() { |
| 1781 const SkColor color = GetBackgroundColor(); | 1792 const SkColor color = GetBackgroundColor(); |
| 1782 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { | 1793 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
| 1783 set_background(Background::CreateBackgroundPainter( | 1794 set_background(Background::CreateBackgroundPainter( |
| 1784 true, Painter::CreateSolidRoundRectPainter( | 1795 true, Painter::CreateSolidRoundRectPainter( |
| 1785 color, FocusableBorder::kCornerRadiusDp))); | 1796 color, FocusableBorder::kCornerRadiusDp))); |
| 1786 } else { | 1797 } else { |
| 1787 set_background(Background::CreateSolidBackground(color)); | 1798 set_background(Background::CreateSolidBackground(color)); |
| 1788 } | 1799 } |
| 1789 // Disable subpixel rendering when the background color is transparent | 1800 // Disable subpixel rendering when the background color is transparent |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2039 UpdateAfterChange(true, true); | 2050 UpdateAfterChange(true, true); |
| 2040 } | 2051 } |
| 2041 OnAfterUserAction(); | 2052 OnAfterUserAction(); |
| 2042 } | 2053 } |
| 2043 | 2054 |
| 2044 void Textfield::OnKeypressUnhandled() { | 2055 void Textfield::OnKeypressUnhandled() { |
| 2045 PlatformStyle::OnTextfieldKeypressUnhandled(); | 2056 PlatformStyle::OnTextfieldKeypressUnhandled(); |
| 2046 } | 2057 } |
| 2047 | 2058 |
| 2048 } // namespace views | 2059 } // namespace views |
| OLD | NEW |