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

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: 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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 skip_input_method_cancel_composition_(false), 269 skip_input_method_cancel_composition_(false),
270 cursor_visible_(false), 270 cursor_visible_(false),
271 drop_cursor_visible_(false), 271 drop_cursor_visible_(false),
272 initiating_drag_(false), 272 initiating_drag_(false),
273 aggregated_clicks_(0), 273 aggregated_clicks_(0),
274 drag_start_display_offset_(0), 274 drag_start_display_offset_(0),
275 touch_handles_hidden_due_to_scroll_(false), 275 touch_handles_hidden_due_to_scroll_(false),
276 weak_ptr_factory_(this) { 276 weak_ptr_factory_(this) {
277 set_context_menu_controller(this); 277 set_context_menu_controller(this);
278 set_drag_controller(this); 278 set_drag_controller(this);
279 SetBorder(scoped_ptr<Border>(new FocusableBorder()));
280 SetFocusable(true); 279 SetFocusable(true);
281 280
281 // 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
282 scoped_ptr<FocusableBorder> border(new FocusableBorder());
283 const int kVerticalInset = border->GetMinimumSize().height() / 2;
284 const gfx::Insets insets(border->GetInsets());
285 border->SetInsets(kVerticalInset, insets.left(),
286 kVerticalInset, insets.right());
287 SetBorder(border.PassAs<Border>());
288 internal_padding_ = gfx::Insets(insets.top() - kVerticalInset, 0,
289 insets.bottom() - kVerticalInset, 0);
290
282 if (ViewsDelegate::views_delegate) { 291 if (ViewsDelegate::views_delegate) {
283 password_reveal_duration_ = ViewsDelegate::views_delegate-> 292 password_reveal_duration_ = ViewsDelegate::views_delegate->
284 GetDefaultTextfieldObscuredRevealDuration(); 293 GetDefaultTextfieldObscuredRevealDuration();
285 } 294 }
286 } 295 }
287 296
288 Textfield::~Textfield() {} 297 Textfield::~Textfield() {}
289 298
290 void Textfield::SetReadOnly(bool read_only) { 299 void Textfield::SetReadOnly(bool read_only) {
291 // Update read-only without changing the focusable state (or active, etc.). 300 // Update read-only without changing the focusable state (or active, etc.).
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 } 557 }
549 558
550 //////////////////////////////////////////////////////////////////////////////// 559 ////////////////////////////////////////////////////////////////////////////////
551 // Textfield, View overrides: 560 // Textfield, View overrides:
552 561
553 int Textfield::GetBaseline() const { 562 int Textfield::GetBaseline() const {
554 return GetInsets().top() + GetRenderText()->GetBaseline(); 563 return GetInsets().top() + GetRenderText()->GetBaseline();
555 } 564 }
556 565
557 gfx::Size Textfield::GetPreferredSize() const { 566 gfx::Size Textfield::GetPreferredSize() const {
558 const gfx::Insets& insets = GetInsets(); 567 gfx::Insets insets = GetInsets();
568 insets += internal_padding_;
559 return gfx::Size(GetFontList().GetExpectedTextWidth(default_width_in_chars_) + 569 return gfx::Size(GetFontList().GetExpectedTextWidth(default_width_in_chars_) +
560 insets.width(), GetFontList().GetHeight() + insets.height()); 570 insets.width(), GetFontList().GetHeight() + insets.height());
561 } 571 }
562 572
573 void Textfield::SetBorder(scoped_ptr<Border> b) {
574 // Clear the default internal padding if a custom border is used.
575 internal_padding_ = gfx::Insets();
576 View::SetBorder(b.Pass());
577 }
578
563 const char* Textfield::GetClassName() const { 579 const char* Textfield::GetClassName() const {
564 return kViewClassName; 580 return kViewClassName;
565 } 581 }
566 582
567 gfx::NativeCursor Textfield::GetCursor(const ui::MouseEvent& event) { 583 gfx::NativeCursor Textfield::GetCursor(const ui::MouseEvent& event) {
568 bool in_selection = GetRenderText()->IsPointInSelection(event.location()); 584 bool in_selection = GetRenderText()->IsPointInSelection(event.location());
569 bool drag_event = event.type() == ui::ET_MOUSE_DRAGGED; 585 bool drag_event = event.type() == ui::ET_MOUSE_DRAGGED;
570 bool text_cursor = !initiating_drag_ && (drag_event || !in_selection); 586 bool text_cursor = !initiating_drag_ && (drag_event || !in_selection);
571 return text_cursor ? GetNativeIBeamCursor() : gfx::kNullCursor; 587 return text_cursor ? GetNativeIBeamCursor() : gfx::kNullCursor;
572 } 588 }
(...skipping 1219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1792 const size_t length = selection_clipboard_text.length(); 1808 const size_t length = selection_clipboard_text.length();
1793 range = gfx::Range(range.start() + length, range.end() + length); 1809 range = gfx::Range(range.start() + length, range.end() + length);
1794 } 1810 }
1795 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); 1811 model_->MoveCursorTo(gfx::SelectionModel(range, affinity));
1796 UpdateAfterChange(true, true); 1812 UpdateAfterChange(true, true);
1797 OnAfterUserAction(); 1813 OnAfterUserAction();
1798 } 1814 }
1799 } 1815 }
1800 1816
1801 } // namespace views 1817 } // 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