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

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: Restore Insets const ref. 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
« no previous file with comments | « ui/views/controls/textfield/textfield.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 focus_painter_ = focus_painter.Pass(); 544 focus_painter_ = focus_painter.Pass();
544 } 545 }
545 546
546 bool Textfield::HasTextBeingDragged() { 547 bool Textfield::HasTextBeingDragged() {
547 return initiating_drag_; 548 return initiating_drag_;
548 } 549 }
549 550
550 //////////////////////////////////////////////////////////////////////////////// 551 ////////////////////////////////////////////////////////////////////////////////
551 // Textfield, View overrides: 552 // Textfield, View overrides:
552 553
554 gfx::Insets Textfield::GetInsets() const {
555 gfx::Insets insets = View::GetInsets();
556 insets += gfx::Insets(kTextPadding, kTextPadding, kTextPadding, kTextPadding);
557 return insets;
558 }
559
553 int Textfield::GetBaseline() const { 560 int Textfield::GetBaseline() const {
554 return GetInsets().top() + GetRenderText()->GetBaseline(); 561 return GetInsets().top() + GetRenderText()->GetBaseline();
555 } 562 }
556 563
557 gfx::Size Textfield::GetPreferredSize() const { 564 gfx::Size Textfield::GetPreferredSize() const {
558 const gfx::Insets& insets = GetInsets(); 565 const gfx::Insets& insets = GetInsets();
559 return gfx::Size(GetFontList().GetExpectedTextWidth(default_width_in_chars_) + 566 return gfx::Size(GetFontList().GetExpectedTextWidth(default_width_in_chars_) +
560 insets.width(), GetFontList().GetHeight() + insets.height()); 567 insets.width(), GetFontList().GetHeight() + insets.height());
561 } 568 }
562 569
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 state->selection_end = range.end(); 919 state->selection_end = range.end();
913 920
914 if (!read_only()) { 921 if (!read_only()) {
915 state->set_value_callback = 922 state->set_value_callback =
916 base::Bind(&Textfield::AccessibilitySetValue, 923 base::Bind(&Textfield::AccessibilitySetValue,
917 weak_ptr_factory_.GetWeakPtr()); 924 weak_ptr_factory_.GetWeakPtr());
918 } 925 }
919 } 926 }
920 927
921 void Textfield::OnBoundsChanged(const gfx::Rect& previous_bounds) { 928 void Textfield::OnBoundsChanged(const gfx::Rect& previous_bounds) {
922 GetRenderText()->SetDisplayRect(GetContentsBounds()); 929 // Textfield insets include a reasonable amount of whitespace on all sides of
930 // the default font list. Fallback fonts with larger heights may paint over
931 // the vertical whitespace as needed. Alternate solutions involve undesirable
932 // behavior like changing the default font size, shrinking some fallback fonts
933 // beyond their legibility, or enlarging controls dynamically with content.
934 gfx::Rect bounds = GetContentsBounds();
935 // GetContentsBounds() does not actually use the local GetInsets() override.
936 bounds.Inset(gfx::Insets(0, kTextPadding, 0, kTextPadding));
937 GetRenderText()->SetDisplayRect(bounds);
923 OnCaretBoundsChanged(); 938 OnCaretBoundsChanged();
924 } 939 }
925 940
926 void Textfield::OnEnabledChanged() { 941 void Textfield::OnEnabledChanged() {
927 View::OnEnabledChanged(); 942 View::OnEnabledChanged();
928 if (GetInputMethod()) 943 if (GetInputMethod())
929 GetInputMethod()->OnTextInputTypeChanged(this); 944 GetInputMethod()->OnTextInputTypeChanged(this);
930 SchedulePaint(); 945 SchedulePaint();
931 } 946 }
932 947
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after
1792 const size_t length = selection_clipboard_text.length(); 1807 const size_t length = selection_clipboard_text.length();
1793 range = gfx::Range(range.start() + length, range.end() + length); 1808 range = gfx::Range(range.start() + length, range.end() + length);
1794 } 1809 }
1795 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); 1810 model_->MoveCursorTo(gfx::SelectionModel(range, affinity));
1796 UpdateAfterChange(true, true); 1811 UpdateAfterChange(true, true);
1797 OnAfterUserAction(); 1812 OnAfterUserAction();
1798 } 1813 }
1799 } 1814 }
1800 1815
1801 } // namespace views 1816 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698