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

Unified Diff: ui/views/controls/textfield/textfield.cc

Issue 19666006: Supports FontList in Textfield. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updates ui_unittests_disabled for Android. Created 7 years, 5 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
Index: ui/views/controls/textfield/textfield.cc
diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc
index 258e90b6acb8f276dd872c5d21b27209974c6dd1..a23f66b10f39535d0b229a647ba5f7c29171e539 100644
--- a/ui/views/controls/textfield/textfield.cc
+++ b/ui/views/controls/textfield/textfield.cc
@@ -14,6 +14,7 @@
#include "ui/base/ime/text_input_type.h"
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/base/range/range.h"
+#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_switches.h"
#include "ui/base/ui_base_switches_util.h"
#include "ui/gfx/insets.h"
@@ -79,6 +80,7 @@ Textfield::Textfield()
: native_wrapper_(NULL),
controller_(NULL),
style_(STYLE_DEFAULT),
+ font_list_(GetDefaultFontList()),
read_only_(false),
default_width_in_chars_(0),
draw_border_(true),
@@ -103,6 +105,7 @@ Textfield::Textfield(StyleFlags style)
: native_wrapper_(NULL),
controller_(NULL),
style_(style),
+ font_list_(GetDefaultFontList()),
read_only_(false),
default_width_in_chars_(0),
draw_border_(true),
@@ -270,13 +273,21 @@ void Textfield::SetCursorEnabled(bool enabled) {
native_wrapper_->SetCursorEnabled(enabled);
}
-void Textfield::SetFont(const gfx::Font& font) {
- font_ = font;
+void Textfield::SetFontList(const gfx::FontList& font_list) {
+ font_list_ = font_list;
if (native_wrapper_)
native_wrapper_->UpdateFont();
PreferredSizeChanged();
}
+const gfx::Font& Textfield::GetPrimaryFont() const {
+ return font_list_.GetPrimaryFont();
+}
+
+void Textfield::SetFont(const gfx::Font& font) {
+ SetFontList(gfx::FontList(font));
+}
+
void Textfield::SetHorizontalMargins(int left, int right) {
margins_.Set(margins_.top(), left, margins_.bottom(), right);
horizontal_margins_were_set_ = true;
@@ -424,22 +435,19 @@ void Textfield::Layout() {
int Textfield::GetBaseline() const {
gfx::Insets insets = GetTextInsets();
const int baseline = native_wrapper_ ?
- native_wrapper_->GetTextfieldBaseline() : font_.GetBaseline();
+ native_wrapper_->GetTextfieldBaseline() : font_list_.GetBaseline();
return insets.top() + baseline;
}
gfx::Size Textfield::GetPreferredSize() {
gfx::Insets insets = GetTextInsets();
- // For NativeTextfieldViews, we might use a pre-defined font list (defined in
- // IDS_UI_FONT_FAMILY_CROS) as the fonts to render text. The fonts in the
- // list might be different (in name or in size) from |font_|, so we need to
- // use GetFontHeight() to get the height of the first font in the list to
- // guide textfield's height.
const int font_height = native_wrapper_ ? native_wrapper_->GetFontHeight() :
- font_.GetHeight();
- return gfx::Size(font_.GetExpectedTextWidth(default_width_in_chars_) +
- insets.width(), font_height + insets.height());
+ font_list_.GetHeight();
+ return gfx::Size(
+ GetPrimaryFont().GetExpectedTextWidth(default_width_in_chars_)
+ + insets.width(),
+ font_height + insets.height());
}
void Textfield::AboutToRequestFocusFromTabTraversal(bool reverse) {
@@ -542,6 +550,12 @@ const char* Textfield::GetClassName() const {
return kViewClassName;
}
+// static
+gfx::FontList Textfield::GetDefaultFontList() {
msw 2013/07/30 21:32:27 This is only used by the Textfield ctors above. In
Yuki 2013/07/31 05:38:43 Done.
+ return ResourceBundle::GetSharedInstance().GetFontList(
+ ResourceBundle::BaseFont);
+}
+
gfx::Insets Textfield::GetTextInsets() const {
gfx::Insets insets = GetInsets();
if (draw_border_ && native_wrapper_)

Powered by Google App Engine
This is Rietveld 408576698