Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/views/autofill/decorated_textfield.h" | 5 #include "chrome/browser/ui/views/autofill/decorated_textfield.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/autofill/autofill_dialog_types.h" | 7 #include "chrome/browser/ui/autofill/autofill_dialog_types.h" |
| 8 #include "chrome/browser/ui/views/autofill/tooltip_icon.h" | 8 #include "chrome/browser/ui/views/autofill/learn_more_icon.h" |
| 9 #include "ui/gfx/canvas.h" | 9 #include "ui/gfx/canvas.h" |
| 10 #include "ui/views/background.h" | 10 #include "ui/views/background.h" |
| 11 #include "ui/views/controls/button/label_button.h" | 11 #include "ui/views/controls/button/label_button.h" |
| 12 #include "ui/views/controls/focusable_border.h" | 12 #include "ui/views/controls/focusable_border.h" |
| 13 #include "ui/views/controls/textfield/textfield_controller.h" | 13 #include "ui/views/controls/textfield/textfield_controller.h" |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 // Padding around icons inside DecoratedTextfields. | 17 // Padding around icons inside DecoratedTextfields. |
| 18 const int kTextfieldIconPadding = 3; | 18 const int kTextfieldIconPadding = 3; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 if (!icon.IsEmpty()) { | 87 if (!icon.IsEmpty()) { |
| 88 icon_view_.reset(new views::ImageView()); | 88 icon_view_.reset(new views::ImageView()); |
| 89 icon_view_->set_owned_by_client(); | 89 icon_view_->set_owned_by_client(); |
| 90 icon_view_->SetImage(icon.ToImageSkia()); | 90 icon_view_->SetImage(icon.ToImageSkia()); |
| 91 AddChildView(icon_view_.get()); | 91 AddChildView(icon_view_.get()); |
| 92 } | 92 } |
| 93 | 93 |
| 94 IconChanged(); | 94 IconChanged(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void DecoratedTextfield::SetTooltipIcon(const base::string16& text) { | 97 void DecoratedTextfield::SetLearnMoreIcon( |
| 98 const base::string16& text, | |
| 99 const base::WeakPtr<LearnMoreIconDelegate>& delegate) { | |
| 98 if (!icon_view_ && text.empty()) | 100 if (!icon_view_ && text.empty()) |
| 99 return; | 101 return; |
| 100 | 102 |
| 101 if (icon_view_) | 103 if (icon_view_) |
| 102 RemoveChildView(icon_view_.get()); | 104 RemoveChildView(icon_view_.get()); |
| 103 | 105 |
| 104 if (!text.empty()) { | 106 if (!text.empty()) { |
| 105 icon_view_.reset(new TooltipIcon(text)); | 107 icon_view_.reset(new LearnMoreIcon(text, delegate)); |
| 106 AddChildView(icon_view_.get()); | 108 AddChildView(icon_view_.get()); |
| 107 } | 109 } |
| 108 | 110 |
| 109 IconChanged(); | 111 IconChanged(); |
| 110 } | 112 } |
| 111 | 113 |
| 112 base::string16 DecoratedTextfield::GetPlaceholderText() const { | 114 base::string16 DecoratedTextfield::GetPlaceholderText() const { |
| 113 if (!editable_) | 115 if (!editable_) |
| 114 return base::string16(); | 116 return base::string16(); |
| 115 | 117 |
| 116 return views::Textfield::GetPlaceholderText(); | 118 return views::Textfield::GetPlaceholderText(); |
| 117 } | 119 } |
| 118 | 120 |
| 119 const char* DecoratedTextfield::GetClassName() const { | 121 const char* DecoratedTextfield::GetClassName() const { |
| 120 return kViewClassName; | 122 return kViewClassName; |
| 121 } | 123 } |
| 122 | 124 |
| 123 views::View* DecoratedTextfield::GetEventHandlerForPoint( | 125 views::View* DecoratedTextfield::GetEventHandlerForPoint( |
| 124 const gfx::Point& point) { | 126 const gfx::Point& point) { |
| 125 return native_wrapper_->GetView(); | 127 if (icon_view_ && icon_view_->GetClassName() != LearnMoreIcon::kViewClassName) |
| 128 return native_wrapper_->GetView(); | |
| 129 return views::Textfield::GetEventHandlerForPoint(point); | |
|
Evan Stade
2013/11/05 02:01:40
I'd write this as:
views::View* handler = views::
Dan Beam
2013/11/05 07:00:55
Done.
| |
| 126 } | 130 } |
| 127 | 131 |
| 128 void DecoratedTextfield::OnFocus() { | 132 void DecoratedTextfield::OnFocus() { |
| 129 border_->set_has_focus(true); | 133 border_->set_has_focus(true); |
| 130 views::Textfield::OnFocus(); | 134 views::Textfield::OnFocus(); |
| 131 } | 135 } |
| 132 | 136 |
| 133 void DecoratedTextfield::OnBlur() { | 137 void DecoratedTextfield::OnBlur() { |
| 134 border_->set_has_focus(false); | 138 border_->set_has_focus(false); |
| 135 views::Textfield::OnBlur(); | 139 views::Textfield::OnBlur(); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 163 | 167 |
| 164 void DecoratedTextfield::UpdateBackground() { | 168 void DecoratedTextfield::UpdateBackground() { |
| 165 set_background( | 169 set_background( |
| 166 views::Background::CreateSolidBackground(GetBackgroundColor())); | 170 views::Background::CreateSolidBackground(GetBackgroundColor())); |
| 167 } | 171 } |
| 168 | 172 |
| 169 void DecoratedTextfield::IconChanged() { | 173 void DecoratedTextfield::IconChanged() { |
| 170 // Don't show the icon if nothing else is showing. | 174 // Don't show the icon if nothing else is showing. |
| 171 icon_view_->SetVisible(editable_ || !text().empty()); | 175 icon_view_->SetVisible(editable_ || !text().empty()); |
| 172 | 176 |
| 177 if (!icon_view_->visible()) | |
| 178 icon_view_->SetSize(gfx::Size()); | |
|
Evan Stade
2013/11/05 02:01:40
why necessary?
Dan Beam
2013/11/05 07:00:55
not
| |
| 179 | |
| 173 int icon_space = icon_view_ ? | 180 int icon_space = icon_view_ ? |
| 174 icon_view_->GetPreferredSize().width() + 2 * kTextfieldIconPadding : 0; | 181 icon_view_->GetPreferredSize().width() + 2 * kTextfieldIconPadding : 0; |
| 175 | 182 |
| 176 bool is_rtl = base::i18n::IsRTL(); | 183 bool is_rtl = base::i18n::IsRTL(); |
| 177 SetHorizontalMargins(is_rtl ? icon_space : 0, is_rtl ? 0 : icon_space); | 184 SetHorizontalMargins(is_rtl ? icon_space : 0, is_rtl ? 0 : icon_space); |
| 178 | 185 |
| 179 Layout(); | 186 Layout(); |
| 180 SchedulePaint(); | 187 SchedulePaint(); |
| 181 } | 188 } |
| 182 | 189 |
| 183 } // namespace autofill | 190 } // namespace autofill |
| OLD | NEW |