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 "ui/accessibility/ax_view_state.h" | 10 #include "ui/accessibility/ax_view_state.h" |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 return kNoCommand; | 231 return kNoCommand; |
232 } | 232 } |
233 return kNoCommand; | 233 return kNoCommand; |
234 } | 234 } |
235 #endif | 235 #endif |
236 | 236 |
237 } // namespace | 237 } // namespace |
238 | 238 |
239 // static | 239 // static |
240 const char Textfield::kViewClassName[] = "Textfield"; | 240 const char Textfield::kViewClassName[] = "Textfield"; |
241 const int Textfield::kTextPadding = 3; | |
241 | 242 |
242 // static | 243 // static |
243 size_t Textfield::GetCaretBlinkMs() { | 244 size_t Textfield::GetCaretBlinkMs() { |
244 static const size_t default_value = 500; | 245 static const size_t default_value = 500; |
245 #if defined(OS_WIN) | 246 #if defined(OS_WIN) |
246 static const size_t system_value = ::GetCaretBlinkTime(); | 247 static const size_t system_value = ::GetCaretBlinkTime(); |
247 if (system_value != 0) | 248 if (system_value != 0) |
248 return (system_value == INFINITE) ? 0 : system_value; | 249 return (system_value == INFINITE) ? 0 : system_value; |
249 #endif | 250 #endif |
250 return default_value; | 251 return default_value; |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
548 } | 549 } |
549 | 550 |
550 //////////////////////////////////////////////////////////////////////////////// | 551 //////////////////////////////////////////////////////////////////////////////// |
551 // Textfield, View overrides: | 552 // Textfield, View overrides: |
552 | 553 |
553 int Textfield::GetBaseline() const { | 554 int Textfield::GetBaseline() const { |
554 return GetInsets().top() + GetRenderText()->GetBaseline(); | 555 return GetInsets().top() + GetRenderText()->GetBaseline(); |
555 } | 556 } |
556 | 557 |
557 gfx::Size Textfield::GetPreferredSize() const { | 558 gfx::Size Textfield::GetPreferredSize() const { |
558 const gfx::Insets& insets = GetInsets(); | 559 gfx::Insets insets = GetInsets(); |
560 insets += gfx::Insets(kTextPadding, kTextPadding, kTextPadding, kTextPadding); | |
559 return gfx::Size(GetFontList().GetExpectedTextWidth(default_width_in_chars_) + | 561 return gfx::Size(GetFontList().GetExpectedTextWidth(default_width_in_chars_) + |
560 insets.width(), GetFontList().GetHeight() + insets.height()); | 562 insets.width(), GetFontList().GetHeight() + insets.height()); |
561 } | 563 } |
562 | 564 |
563 const char* Textfield::GetClassName() const { | 565 const char* Textfield::GetClassName() const { |
564 return kViewClassName; | 566 return kViewClassName; |
565 } | 567 } |
566 | 568 |
567 gfx::NativeCursor Textfield::GetCursor(const ui::MouseEvent& event) { | 569 gfx::NativeCursor Textfield::GetCursor(const ui::MouseEvent& event) { |
568 bool in_selection = GetRenderText()->IsPointInSelection(event.location()); | 570 bool in_selection = GetRenderText()->IsPointInSelection(event.location()); |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
912 state->selection_end = range.end(); | 914 state->selection_end = range.end(); |
913 | 915 |
914 if (!read_only()) { | 916 if (!read_only()) { |
915 state->set_value_callback = | 917 state->set_value_callback = |
916 base::Bind(&Textfield::AccessibilitySetValue, | 918 base::Bind(&Textfield::AccessibilitySetValue, |
917 weak_ptr_factory_.GetWeakPtr()); | 919 weak_ptr_factory_.GetWeakPtr()); |
918 } | 920 } |
919 } | 921 } |
920 | 922 |
921 void Textfield::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 923 void Textfield::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
922 GetRenderText()->SetDisplayRect(GetContentsBounds()); | 924 // Allow the text to paint over vertical padding, but not horizontal padding. |
925 // kTextPadding was previously unused FocusableBorder inset padding, now that | |
926 // space is reserved for excessively tall text from unforseen fallback fonts. | |
927 // This is better than clipping text, shrinking text or painting over borders. | |
Peter Kasting
2014/08/30 00:46:43
Hmm, I'd really rather not talk about "previously"
msw
2014/09/04 01:25:51
I revised the comment.
| |
928 gfx::Rect bounds = GetContentsBounds(); | |
929 bounds.Inset(kTextPadding, 0); | |
930 GetRenderText()->SetDisplayRect(bounds); | |
923 OnCaretBoundsChanged(); | 931 OnCaretBoundsChanged(); |
924 } | 932 } |
925 | 933 |
926 void Textfield::OnEnabledChanged() { | 934 void Textfield::OnEnabledChanged() { |
927 View::OnEnabledChanged(); | 935 View::OnEnabledChanged(); |
928 if (GetInputMethod()) | 936 if (GetInputMethod()) |
929 GetInputMethod()->OnTextInputTypeChanged(this); | 937 GetInputMethod()->OnTextInputTypeChanged(this); |
930 SchedulePaint(); | 938 SchedulePaint(); |
931 } | 939 } |
932 | 940 |
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1792 const size_t length = selection_clipboard_text.length(); | 1800 const size_t length = selection_clipboard_text.length(); |
1793 range = gfx::Range(range.start() + length, range.end() + length); | 1801 range = gfx::Range(range.start() + length, range.end() + length); |
1794 } | 1802 } |
1795 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); | 1803 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); |
1796 UpdateAfterChange(true, true); | 1804 UpdateAfterChange(true, true); |
1797 OnAfterUserAction(); | 1805 OnAfterUserAction(); |
1798 } | 1806 } |
1799 } | 1807 } |
1800 | 1808 |
1801 } // namespace views | 1809 } // namespace views |
OLD | NEW |