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

Unified 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: Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/controls/textfield/textfield.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/textfield/textfield.cc
diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc
index bedee3a1c0c8cabcece0a1f5d192c79e9f5d5191..e5e2500e8102360f0fb88e390e9d3515498b3608 100644
--- a/ui/views/controls/textfield/textfield.cc
+++ b/ui/views/controls/textfield/textfield.cc
@@ -276,9 +276,18 @@ Textfield::Textfield()
weak_ptr_factory_(this) {
set_context_menu_controller(this);
set_drag_controller(this);
- SetBorder(scoped_ptr<Border>(new FocusableBorder()));
SetFocusable(true);
+ // Use most of the FocusableBorder's internal padding for text rendering.
Peter Kasting 2014/08/28 21:15:37 Why not just make FocusableBorder thinner?
msw 2014/08/28 21:29:14 That would be a good next step to give Combobox an
+ scoped_ptr<FocusableBorder> border(new FocusableBorder());
+ const int kVerticalInset = border->GetMinimumSize().height() / 2;
+ const gfx::Insets insets(border->GetInsets());
+ border->SetInsets(kVerticalInset, insets.left(),
+ kVerticalInset, insets.right());
+ SetBorder(border.PassAs<Border>());
+ internal_padding_ = gfx::Insets(insets.top() - kVerticalInset, 0,
+ insets.bottom() - kVerticalInset, 0);
+
if (ViewsDelegate::views_delegate) {
password_reveal_duration_ = ViewsDelegate::views_delegate->
GetDefaultTextfieldObscuredRevealDuration();
@@ -555,11 +564,18 @@ int Textfield::GetBaseline() const {
}
gfx::Size Textfield::GetPreferredSize() const {
- const gfx::Insets& insets = GetInsets();
+ gfx::Insets insets = GetInsets();
+ insets += internal_padding_;
return gfx::Size(GetFontList().GetExpectedTextWidth(default_width_in_chars_) +
insets.width(), GetFontList().GetHeight() + insets.height());
}
+void Textfield::SetBorder(scoped_ptr<Border> b) {
+ // Clear the default internal padding if a custom border is used.
+ internal_padding_ = gfx::Insets();
+ View::SetBorder(b.Pass());
+}
+
const char* Textfield::GetClassName() const {
return kViewClassName;
}
« 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