| 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 // Textfield preferred sizing includes a reasonable amount of whitespace on |
| 925 // all sides of the default font list. Fallback fonts with larger heights may |
| 926 // paint over the vertical whitespace as needed. Alternate solutions involve |
| 927 // undesirable behavior like changing the default font size, shrinking some |
| 928 // fallback fonts beyond their legibility, or enlarging controls dynamically. |
| 929 gfx::Rect bounds = GetContentsBounds(); |
| 930 bounds.Inset(kTextPadding, 0); |
| 931 GetRenderText()->SetDisplayRect(bounds); |
| 923 OnCaretBoundsChanged(); | 932 OnCaretBoundsChanged(); |
| 924 } | 933 } |
| 925 | 934 |
| 926 void Textfield::OnEnabledChanged() { | 935 void Textfield::OnEnabledChanged() { |
| 927 View::OnEnabledChanged(); | 936 View::OnEnabledChanged(); |
| 928 if (GetInputMethod()) | 937 if (GetInputMethod()) |
| 929 GetInputMethod()->OnTextInputTypeChanged(this); | 938 GetInputMethod()->OnTextInputTypeChanged(this); |
| 930 SchedulePaint(); | 939 SchedulePaint(); |
| 931 } | 940 } |
| 932 | 941 |
| (...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1792 const size_t length = selection_clipboard_text.length(); | 1801 const size_t length = selection_clipboard_text.length(); |
| 1793 range = gfx::Range(range.start() + length, range.end() + length); | 1802 range = gfx::Range(range.start() + length, range.end() + length); |
| 1794 } | 1803 } |
| 1795 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); | 1804 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); |
| 1796 UpdateAfterChange(true, true); | 1805 UpdateAfterChange(true, true); |
| 1797 OnAfterUserAction(); | 1806 OnAfterUserAction(); |
| 1798 } | 1807 } |
| 1799 } | 1808 } |
| 1800 | 1809 |
| 1801 } // namespace views | 1810 } // namespace views |
| OLD | NEW |