Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 | 263 |
| 264 bool Textfield::GetCursorEnabled() const { | 264 bool Textfield::GetCursorEnabled() const { |
| 265 return native_wrapper_ && native_wrapper_->GetCursorEnabled(); | 265 return native_wrapper_ && native_wrapper_->GetCursorEnabled(); |
| 266 } | 266 } |
| 267 | 267 |
| 268 void Textfield::SetCursorEnabled(bool enabled) { | 268 void Textfield::SetCursorEnabled(bool enabled) { |
| 269 if (native_wrapper_) | 269 if (native_wrapper_) |
| 270 native_wrapper_->SetCursorEnabled(enabled); | 270 native_wrapper_->SetCursorEnabled(enabled); |
| 271 } | 271 } |
| 272 | 272 |
| 273 void Textfield::SetFont(const gfx::Font& font) { | 273 void Textfield::SetFontList(const gfx::FontList& font_list) { |
| 274 font_ = font; | 274 font_list_ = font_list; |
| 275 if (native_wrapper_) | 275 if (native_wrapper_) |
| 276 native_wrapper_->UpdateFont(); | 276 native_wrapper_->UpdateFont(); |
| 277 PreferredSizeChanged(); | 277 PreferredSizeChanged(); |
| 278 } | 278 } |
| 279 | 279 |
| 280 const gfx::Font& Textfield::GetPrimaryFont() const { | |
| 281 return font_list_.GetPrimaryFont(); | |
| 282 } | |
| 283 | |
| 284 void Textfield::SetFont(const gfx::Font& font) { | |
| 285 SetFontList(gfx::FontList(font)); | |
| 286 } | |
| 287 | |
| 280 void Textfield::SetHorizontalMargins(int left, int right) { | 288 void Textfield::SetHorizontalMargins(int left, int right) { |
| 281 margins_.Set(margins_.top(), left, margins_.bottom(), right); | 289 margins_.Set(margins_.top(), left, margins_.bottom(), right); |
| 282 horizontal_margins_were_set_ = true; | 290 horizontal_margins_were_set_ = true; |
| 283 if (native_wrapper_) | 291 if (native_wrapper_) |
| 284 native_wrapper_->UpdateHorizontalMargins(); | 292 native_wrapper_->UpdateHorizontalMargins(); |
| 285 PreferredSizeChanged(); | 293 PreferredSizeChanged(); |
| 286 } | 294 } |
| 287 | 295 |
| 288 void Textfield::SetVerticalMargins(int top, int bottom) { | 296 void Textfield::SetVerticalMargins(int top, int bottom) { |
| 289 margins_.Set(top, margins_.left(), bottom, margins_.right()); | 297 margins_.Set(top, margins_.left(), bottom, margins_.right()); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 void Textfield::Layout() { | 425 void Textfield::Layout() { |
| 418 if (native_wrapper_) { | 426 if (native_wrapper_) { |
| 419 native_wrapper_->GetView()->SetBoundsRect(GetContentsBounds()); | 427 native_wrapper_->GetView()->SetBoundsRect(GetContentsBounds()); |
| 420 native_wrapper_->GetView()->Layout(); | 428 native_wrapper_->GetView()->Layout(); |
| 421 } | 429 } |
| 422 } | 430 } |
| 423 | 431 |
| 424 int Textfield::GetBaseline() const { | 432 int Textfield::GetBaseline() const { |
| 425 gfx::Insets insets = GetTextInsets(); | 433 gfx::Insets insets = GetTextInsets(); |
| 426 const int baseline = native_wrapper_ ? | 434 const int baseline = native_wrapper_ ? |
| 427 native_wrapper_->GetTextfieldBaseline() : font_.GetBaseline(); | 435 native_wrapper_->GetTextfieldBaseline() : font_list_.GetBaseline(); |
| 428 return insets.top() + baseline; | 436 return insets.top() + baseline; |
| 429 } | 437 } |
| 430 | 438 |
| 431 gfx::Size Textfield::GetPreferredSize() { | 439 gfx::Size Textfield::GetPreferredSize() { |
| 432 gfx::Insets insets = GetTextInsets(); | 440 gfx::Insets insets = GetTextInsets(); |
| 433 | 441 |
| 434 // For NativeTextfieldViews, we might use a pre-defined font list (defined in | 442 // For NativeTextfieldViews, we might use a pre-defined font list (defined in |
|
msw
2013/07/23 19:51:54
Does this comment need updating?
Yuki
2013/07/24 09:17:05
I simply deleted the comment. We no longer need i
| |
| 435 // IDS_UI_FONT_FAMILY_CROS) as the fonts to render text. The fonts in the | 443 // IDS_UI_FONT_FAMILY_CROS) as the fonts to render text. The fonts in the |
| 436 // list might be different (in name or in size) from |font_|, so we need to | 444 // list might be different (in name or in size) from |font_|, so we need to |
| 437 // use GetFontHeight() to get the height of the first font in the list to | 445 // use GetFontHeight() to get the height of the first font in the list to |
| 438 // guide textfield's height. | 446 // guide textfield's height. |
| 439 const int font_height = native_wrapper_ ? native_wrapper_->GetFontHeight() : | 447 const int font_height = native_wrapper_ ? native_wrapper_->GetFontHeight() : |
| 440 font_.GetHeight(); | 448 font_list_.GetHeight(); |
| 441 return gfx::Size(font_.GetExpectedTextWidth(default_width_in_chars_) + | 449 return gfx::Size( |
| 442 insets.width(), font_height + insets.height()); | 450 GetPrimaryFont().GetExpectedTextWidth(default_width_in_chars_) |
| 451 + insets.width(), | |
| 452 font_height + insets.height()); | |
| 443 } | 453 } |
| 444 | 454 |
| 445 void Textfield::AboutToRequestFocusFromTabTraversal(bool reverse) { | 455 void Textfield::AboutToRequestFocusFromTabTraversal(bool reverse) { |
| 446 SelectAll(false); | 456 SelectAll(false); |
| 447 } | 457 } |
| 448 | 458 |
| 449 bool Textfield::SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) { | 459 bool Textfield::SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) { |
| 450 // Skip any accelerator handling of backspace; textfields handle this key. | 460 // Skip any accelerator handling of backspace; textfields handle this key. |
| 451 // Also skip processing of [Alt]+<num-pad digit> Unicode alt key codes. | 461 // Also skip processing of [Alt]+<num-pad digit> Unicode alt key codes. |
| 452 return e.key_code() == ui::VKEY_BACK || e.IsUnicodeKeyCode(); | 462 return e.key_code() == ui::VKEY_BACK || e.IsUnicodeKeyCode(); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 566 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
| 557 Textfield* field) { | 567 Textfield* field) { |
| 558 #if defined(OS_WIN) && !defined(USE_AURA) | 568 #if defined(OS_WIN) && !defined(USE_AURA) |
| 559 if (!Textfield::IsViewsTextfieldEnabled()) | 569 if (!Textfield::IsViewsTextfieldEnabled()) |
| 560 return new NativeTextfieldWin(field); | 570 return new NativeTextfieldWin(field); |
| 561 #endif | 571 #endif |
| 562 return new NativeTextfieldViews(field); | 572 return new NativeTextfieldViews(field); |
| 563 } | 573 } |
| 564 | 574 |
| 565 } // namespace views | 575 } // namespace views |
| OLD | NEW |