| Index: chrome/browser/ui/views/autofill/decorated_textfield.cc
|
| diff --git a/chrome/browser/ui/views/autofill/decorated_textfield.cc b/chrome/browser/ui/views/autofill/decorated_textfield.cc
|
| index fa3e816f95fbd7497dd65912d21bc21fb2063b31..94e8202c7655ffbb8edc403a80d7b34dd58294a8 100644
|
| --- a/chrome/browser/ui/views/autofill/decorated_textfield.cc
|
| +++ b/chrome/browser/ui/views/autofill/decorated_textfield.cc
|
| @@ -10,7 +10,6 @@
|
| #include "ui/views/background.h"
|
| #include "ui/views/controls/button/label_button.h"
|
| #include "ui/views/controls/focusable_border.h"
|
| -#include "ui/views/controls/textfield/native_textfield_views.h"
|
| #include "ui/views/controls/textfield/textfield_controller.h"
|
|
|
| namespace {
|
| @@ -25,38 +24,28 @@ namespace autofill {
|
| // static
|
| const char DecoratedTextfield::kViewClassName[] = "autofill/DecoratedTextfield";
|
|
|
| -const int DecoratedTextfield::kMagicInsetNumber = 6;
|
| -
|
| DecoratedTextfield::DecoratedTextfield(
|
| const base::string16& default_value,
|
| const base::string16& placeholder,
|
| views::TextfieldController* controller)
|
| - : border_(new views::FocusableBorder()),
|
| - invalid_(false),
|
| + : invalid_(false),
|
| editable_(true) {
|
| UpdateBackground();
|
| -
|
| - set_border(border_);
|
| - // Removes the border from |native_wrapper_|.
|
| - RemoveBorder();
|
| + UpdateBorder();
|
|
|
| set_placeholder_text(placeholder);
|
| SetText(default_value);
|
| SetController(controller);
|
| - SetHorizontalMargins(0, 0);
|
| }
|
|
|
| DecoratedTextfield::~DecoratedTextfield() {}
|
|
|
| void DecoratedTextfield::SetInvalid(bool invalid) {
|
| - invalid_ = invalid;
|
| - if (!editable_)
|
| + if (invalid_ == invalid)
|
| return;
|
|
|
| - if (invalid)
|
| - border_->SetColor(kWarningColor);
|
| - else
|
| - border_->UseDefaultColor();
|
| + invalid_ = invalid;
|
| + UpdateBorder();
|
| SchedulePaint();
|
| }
|
|
|
| @@ -65,14 +54,7 @@ void DecoratedTextfield::SetEditable(bool editable) {
|
| return;
|
|
|
| editable_ = editable;
|
| - if (editable) {
|
| - SetInvalid(invalid_);
|
| - UseDefaultBackgroundColor();
|
| - } else {
|
| - border_->SetColor(SK_ColorTRANSPARENT);
|
| - SetBackgroundColor(SK_ColorTRANSPARENT);
|
| - }
|
| -
|
| + UpdateBorder();
|
| UpdateBackground();
|
| SetEnabled(editable);
|
| IconChanged();
|
| @@ -111,10 +93,7 @@ void DecoratedTextfield::SetTooltipIcon(const base::string16& text) {
|
| }
|
|
|
| base::string16 DecoratedTextfield::GetPlaceholderText() const {
|
| - if (!editable_)
|
| - return base::string16();
|
| -
|
| - return views::Textfield::GetPlaceholderText();
|
| + return editable_ ? views::Textfield::GetPlaceholderText() : base::string16();
|
| }
|
|
|
| const char* DecoratedTextfield::GetClassName() const {
|
| @@ -125,25 +104,14 @@ views::View* DecoratedTextfield::GetEventHandlerForRect(const gfx::Rect& rect) {
|
| views::View* handler = views::Textfield::GetEventHandlerForRect(rect);
|
| if (handler->GetClassName() == TooltipIcon::kViewClassName)
|
| return handler;
|
| - return textfield_view_;
|
| -}
|
| -
|
| -void DecoratedTextfield::OnFocus() {
|
| - views::Textfield::OnFocus();
|
| - SchedulePaint();
|
| -}
|
| -
|
| -void DecoratedTextfield::OnBlur() {
|
| - views::Textfield::OnBlur();
|
| - SchedulePaint();
|
| + return this;
|
| }
|
|
|
| gfx::Size DecoratedTextfield::GetPreferredSize() {
|
| - int w = views::Textfield::GetPreferredSize().width();
|
| - views::LabelButton button(NULL, base::string16());
|
| - button.SetStyle(views::Button::STYLE_BUTTON);
|
| - int h = button.GetPreferredSize().height();
|
| - return gfx::Size(w, h - kMagicInsetNumber);
|
| + static const int height =
|
| + views::LabelButton(NULL, base::string16()).GetPreferredSize().height();
|
| + const gfx::Size size = views::Textfield::GetPreferredSize();
|
| + return gfx::Size(size.width(), std::max(size.height(), height));
|
| }
|
|
|
| void DecoratedTextfield::Layout() {
|
| @@ -157,29 +125,45 @@ void DecoratedTextfield::Layout() {
|
| bounds.right() - icon_size.width() - kTextfieldIconPadding;
|
| // Vertically centered.
|
| int y = bounds.y() + (bounds.height() - icon_size.height()) / 2;
|
| - icon_view_->SetBounds(x,
|
| - y,
|
| - icon_size.width(),
|
| - icon_size.height());
|
| + icon_view_->SetBounds(x, y, icon_size.width(), icon_size.height());
|
| }
|
| }
|
|
|
| void DecoratedTextfield::UpdateBackground() {
|
| + if (editable_)
|
| + UseDefaultBackgroundColor();
|
| + else
|
| + SetBackgroundColor(SK_ColorTRANSPARENT);
|
| set_background(
|
| views::Background::CreateSolidBackground(GetBackgroundColor()));
|
| }
|
|
|
| -void DecoratedTextfield::IconChanged() {
|
| - // Don't show the icon if nothing else is showing.
|
| - icon_view_->SetVisible(editable_ || !text().empty());
|
| +void DecoratedTextfield::UpdateBorder() {
|
| + views::FocusableBorder* border = new views::FocusableBorder();
|
| + if (invalid_)
|
| + border->SetColor(kWarningColor);
|
| + else if (!editable_)
|
| + border->SetColor(SK_ColorTRANSPARENT);
|
|
|
| - int icon_space = icon_view_ ?
|
| + const gfx::Insets insets = GetInsets();
|
| + int left = icon_view_ ?
|
| icon_view_->GetPreferredSize().width() + 2 * kTextfieldIconPadding : 0;
|
| + int right = 0;
|
| + if (base::i18n::IsRTL())
|
| + std::swap(left, right);
|
| + border->SetInsets(insets.top(), insets.left() + left, insets.bottom(),
|
| + insets.right() + right);
|
| + set_border(border);
|
| +}
|
|
|
| - bool is_rtl = base::i18n::IsRTL();
|
| - SetHorizontalMargins(is_rtl ? icon_space : 0, is_rtl ? 0 : icon_space);
|
| +void DecoratedTextfield::IconChanged() {
|
| + // Don't show the icon if nothing else is showing.
|
| + const bool visible = editable_ || !text().empty();
|
| + if (icon_view_->visible() == visible)
|
| + return;
|
|
|
| - Layout();
|
| + icon_view_->SetVisible(visible);
|
| + UpdateBorder();
|
| SchedulePaint();
|
| }
|
|
|
|
|