Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: ui/views/controls/textfield/textfield.cc

Issue 516943003: Add textfield internal padding from FocusableBorder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Shrink FocusableBorder; add Textfield and Combobox padding. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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.
Peter Kasting 2014/08/29 21:09:11 Nit: Maybe fill this comment out more? Something
msw 2014/08/30 00:17:48 Done.
925 gfx::Rect bounds = GetContentsBounds();
926 bounds.Inset(kTextPadding, 0);
927 GetRenderText()->SetDisplayRect(bounds);
923 OnCaretBoundsChanged(); 928 OnCaretBoundsChanged();
924 } 929 }
925 930
926 void Textfield::OnEnabledChanged() { 931 void Textfield::OnEnabledChanged() {
927 View::OnEnabledChanged(); 932 View::OnEnabledChanged();
928 if (GetInputMethod()) 933 if (GetInputMethod())
929 GetInputMethod()->OnTextInputTypeChanged(this); 934 GetInputMethod()->OnTextInputTypeChanged(this);
930 SchedulePaint(); 935 SchedulePaint();
931 } 936 }
932 937
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after
1792 const size_t length = selection_clipboard_text.length(); 1797 const size_t length = selection_clipboard_text.length();
1793 range = gfx::Range(range.start() + length, range.end() + length); 1798 range = gfx::Range(range.start() + length, range.end() + length);
1794 } 1799 }
1795 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); 1800 model_->MoveCursorTo(gfx::SelectionModel(range, affinity));
1796 UpdateAfterChange(true, true); 1801 UpdateAfterChange(true, true);
1797 OnAfterUserAction(); 1802 OnAfterUserAction();
1798 } 1803 }
1799 } 1804 }
1800 1805
1801 } // namespace views 1806 } // namespace views
OLDNEW
« ui/views/controls/focusable_border.cc ('K') | « ui/views/controls/textfield/textfield.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698