OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/autofill/password_generation_popup_controller_impl.h
" | 5 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h
" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversion_utils.h" | 13 #include "base/strings/utf_string_conversion_utils.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/sync/profile_sync_service_factory.h" | 16 #include "chrome/browser/sync/profile_sync_service_factory.h" |
17 #include "chrome/browser/ui/autofill/password_generation_popup_observer.h" | 17 #include "chrome/browser/ui/autofill/password_generation_popup_observer.h" |
18 #include "chrome/browser/ui/autofill/password_generation_popup_view.h" | 18 #include "chrome/browser/ui/autofill/password_generation_popup_view.h" |
19 #include "chrome/browser/ui/autofill/popup_constants.h" | 19 #include "chrome/browser/ui/autofill/popup_constants.h" |
20 #include "chrome/browser/ui/browser_finder.h" | 20 #include "chrome/browser/ui/browser_finder.h" |
21 #include "chrome/browser/ui/chrome_pages.h" | 21 #include "chrome/browser/ui/chrome_pages.h" |
22 #include "chrome/common/features.h" | 22 #include "chrome/common/features.h" |
23 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
24 #include "chrome/grit/chromium_strings.h" | 24 #include "chrome/grit/chromium_strings.h" |
25 #include "chrome/grit/generated_resources.h" | 25 #include "chrome/grit/generated_resources.h" |
26 #include "components/autofill/content/common/autofill_messages.h" | 26 #include "components/autofill/content/common/autofill_messages.h" |
27 #include "components/autofill/core/browser/password_generator.h" | 27 #include "components/autofill/core/browser/password_generator.h" |
| 28 #include "components/autofill/core/browser/suggestion.h" |
28 #include "components/browser_sync/browser/profile_sync_service.h" | 29 #include "components/browser_sync/browser/profile_sync_service.h" |
29 #include "components/password_manager/core/browser/password_bubble_experiment.h" | 30 #include "components/password_manager/core/browser/password_bubble_experiment.h" |
30 #include "components/password_manager/core/browser/password_manager.h" | 31 #include "components/password_manager/core/browser/password_manager.h" |
31 #include "content/public/browser/native_web_keyboard_event.h" | 32 #include "content/public/browser/native_web_keyboard_event.h" |
32 #include "content/public/browser/render_view_host.h" | 33 #include "content/public/browser/render_view_host.h" |
33 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
34 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
35 #include "ui/events/keycodes/keyboard_codes.h" | 36 #include "ui/events/keycodes/keyboard_codes.h" |
36 #include "ui/gfx/geometry/rect_conversions.h" | 37 #include "ui/gfx/geometry/rect_conversions.h" |
37 #include "ui/gfx/text_utils.h" | 38 #include "ui/gfx/text_utils.h" |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 password_manager_->SetHasGeneratedPasswordForForm(driver_, form_, true); | 168 password_manager_->SetHasGeneratedPasswordForForm(driver_, form_, true); |
168 Hide(); | 169 Hide(); |
169 } | 170 } |
170 | 171 |
171 int PasswordGenerationPopupControllerImpl::GetMinimumWidth() { | 172 int PasswordGenerationPopupControllerImpl::GetMinimumWidth() { |
172 // Minimum width in pixels. | 173 // Minimum width in pixels. |
173 const int minimum_width = 350; | 174 const int minimum_width = 350; |
174 | 175 |
175 // If the width of the field is longer than the minimum, use that instead. | 176 // If the width of the field is longer than the minimum, use that instead. |
176 return std::max(minimum_width, | 177 return std::max(minimum_width, |
177 controller_common_.RoundedElementBounds().width()); | 178 gfx::ToEnclosingRect(element_bounds()).width()); |
178 } | 179 } |
179 | 180 |
180 void PasswordGenerationPopupControllerImpl::CalculateBounds() { | 181 void PasswordGenerationPopupControllerImpl::CalculateBounds() { |
181 gfx::Size bounds = view_->GetPreferredSizeOfPasswordView(); | 182 gfx::Size bounds = view_->GetPreferredSizeOfPasswordView(); |
182 | 183 |
183 popup_bounds_ = controller_common_.GetPopupBounds(bounds.width(), | 184 popup_bounds_ = view_utils_.CalculatePopupBounds( |
184 bounds.height()); | 185 bounds.width(), bounds.height(), gfx::ToEnclosingRect(element_bounds()), |
| 186 container_view(), IsRTL()); |
185 } | 187 } |
186 | 188 |
187 void PasswordGenerationPopupControllerImpl::Show(bool display_password) { | 189 void PasswordGenerationPopupControllerImpl::Show(bool display_password) { |
188 display_password_ = display_password; | 190 display_password_ = display_password; |
189 if (display_password_ && current_password_.empty()) | 191 if (display_password_ && current_password_.empty()) |
190 current_password_ = base::ASCIIToUTF16(generator_->Generate()); | 192 current_password_ = base::ASCIIToUTF16(generator_->Generate()); |
191 | 193 |
192 if (!view_) { | 194 if (!view_) { |
193 view_ = PasswordGenerationPopupView::Create(this); | 195 view_ = PasswordGenerationPopupView::Create(this); |
194 | 196 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 } | 259 } |
258 | 260 |
259 void PasswordGenerationPopupControllerImpl::SelectionCleared() { | 261 void PasswordGenerationPopupControllerImpl::SelectionCleared() { |
260 PasswordSelected(false); | 262 PasswordSelected(false); |
261 } | 263 } |
262 | 264 |
263 gfx::NativeView PasswordGenerationPopupControllerImpl::container_view() { | 265 gfx::NativeView PasswordGenerationPopupControllerImpl::container_view() { |
264 return controller_common_.container_view(); | 266 return controller_common_.container_view(); |
265 } | 267 } |
266 | 268 |
267 const gfx::Rect& PasswordGenerationPopupControllerImpl::popup_bounds() const { | 269 gfx::Rect PasswordGenerationPopupControllerImpl::popup_bounds() const { |
268 return popup_bounds_; | 270 return popup_bounds_; |
269 } | 271 } |
270 | 272 |
271 const gfx::RectF& PasswordGenerationPopupControllerImpl::element_bounds() | 273 const gfx::RectF& PasswordGenerationPopupControllerImpl::element_bounds() |
272 const { | 274 const { |
273 return controller_common_.element_bounds(); | 275 return controller_common_.element_bounds(); |
274 } | 276 } |
275 | 277 |
276 bool PasswordGenerationPopupControllerImpl::IsRTL() const { | 278 bool PasswordGenerationPopupControllerImpl::IsRTL() const { |
277 return base::i18n::IsRTL(); | 279 return base::i18n::IsRTL(); |
278 } | 280 } |
279 | 281 |
| 282 // Autofill-specific method returns nothing. |
| 283 const std::vector<autofill::Suggestion> |
| 284 PasswordGenerationPopupControllerImpl::GetSuggestions() { |
| 285 return std::vector<autofill::Suggestion>(); |
| 286 } |
| 287 |
| 288 #if !defined(OS_ANDROID) |
| 289 // Autofill-specific method returns nothing. |
| 290 int PasswordGenerationPopupControllerImpl::GetElidedValueWidthForRow( |
| 291 size_t row) { |
| 292 return 0; |
| 293 } |
| 294 |
| 295 // Autofill-specific method returns nothing. |
| 296 int PasswordGenerationPopupControllerImpl::GetElidedLabelWidthForRow( |
| 297 size_t row) { |
| 298 return 0; |
| 299 } |
| 300 #endif |
| 301 |
280 bool PasswordGenerationPopupControllerImpl::display_password() const { | 302 bool PasswordGenerationPopupControllerImpl::display_password() const { |
281 return display_password_; | 303 return display_password_; |
282 } | 304 } |
283 | 305 |
284 bool PasswordGenerationPopupControllerImpl::password_selected() const { | 306 bool PasswordGenerationPopupControllerImpl::password_selected() const { |
285 return password_selected_; | 307 return password_selected_; |
286 } | 308 } |
287 | 309 |
288 base::string16 PasswordGenerationPopupControllerImpl::password() const { | 310 base::string16 PasswordGenerationPopupControllerImpl::password() const { |
289 return current_password_; | 311 return current_password_; |
290 } | 312 } |
291 | 313 |
292 base::string16 PasswordGenerationPopupControllerImpl::SuggestedText() { | 314 base::string16 PasswordGenerationPopupControllerImpl::SuggestedText() { |
293 return l10n_util::GetStringUTF16(IDS_PASSWORD_GENERATION_SUGGESTION); | 315 return l10n_util::GetStringUTF16(IDS_PASSWORD_GENERATION_SUGGESTION); |
294 } | 316 } |
295 | 317 |
296 const base::string16& PasswordGenerationPopupControllerImpl::HelpText() { | 318 const base::string16& PasswordGenerationPopupControllerImpl::HelpText() { |
297 return help_text_; | 319 return help_text_; |
298 } | 320 } |
299 | 321 |
300 const gfx::Range& PasswordGenerationPopupControllerImpl::HelpTextLinkRange() { | 322 const gfx::Range& PasswordGenerationPopupControllerImpl::HelpTextLinkRange() { |
301 return link_range_; | 323 return link_range_; |
302 } | 324 } |
303 | 325 |
304 } // namespace autofill | 326 } // namespace autofill |
OLD | NEW |