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 "chrome/browser/ui/views/password_generation_bubble_view.h" | 5 #include "chrome/browser/ui/views/password_generation_bubble_view.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/browser_list.h" | 9 #include "chrome/browser/ui/browser_list.h" |
10 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // are part of one logical textfield with the button on the right side of the | 47 // are part of one logical textfield with the button on the right side of the |
48 // field. It also assumes that the textfield is already sized appropriately | 48 // field. It also assumes that the textfield is already sized appropriately |
49 // and will alter the image size to fit. | 49 // and will alter the image size to fit. |
50 class TextfieldWrapper : public views::View { | 50 class TextfieldWrapper : public views::View { |
51 public: | 51 public: |
52 TextfieldWrapper(views::Textfield* textfield, | 52 TextfieldWrapper(views::Textfield* textfield, |
53 views::ImageButton* image_button); | 53 views::ImageButton* image_button); |
54 virtual ~TextfieldWrapper(); | 54 virtual ~TextfieldWrapper(); |
55 | 55 |
56 virtual void Layout() OVERRIDE; | 56 virtual void Layout() OVERRIDE; |
57 virtual gfx::Size GetPreferredSize() OVERRIDE; | 57 virtual gfx::Size GetPreferredSize() const OVERRIDE; |
58 | 58 |
59 private: | 59 private: |
60 gfx::Size GetImageSize() const; | 60 gfx::Size GetImageSize() const; |
61 | 61 |
62 views::Textfield* textfield_; | 62 views::Textfield* textfield_; |
63 views::ImageButton* image_button_; | 63 views::ImageButton* image_button_; |
64 }; | 64 }; |
65 | 65 |
66 TextfieldWrapper::TextfieldWrapper(views::Textfield* textfield, | 66 TextfieldWrapper::TextfieldWrapper(views::Textfield* textfield, |
67 views::ImageButton* image_button) | 67 views::ImageButton* image_button) |
(...skipping 21 matching lines...) Expand all Loading... |
89 image_button_->SetPosition(gfx::Point(button_x, | 89 image_button_->SetPosition(gfx::Point(button_x, |
90 kWrapperBorderSize)); | 90 kWrapperBorderSize)); |
91 | 91 |
92 // Make sure that the image is centered after cropping. | 92 // Make sure that the image is centered after cropping. |
93 image_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 93 image_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, |
94 views::ImageButton::ALIGN_MIDDLE); | 94 views::ImageButton::ALIGN_MIDDLE); |
95 | 95 |
96 image_button_->SetSize(GetImageSize()); | 96 image_button_->SetSize(GetImageSize()); |
97 } | 97 } |
98 | 98 |
99 gfx::Size TextfieldWrapper::GetPreferredSize() { | 99 gfx::Size TextfieldWrapper::GetPreferredSize() const { |
100 int width = (textfield_->GetPreferredSize().width() + | 100 int width = (textfield_->GetPreferredSize().width() + |
101 GetImageSize().width() + | 101 GetImageSize().width() + |
102 kTextfieldHorizontalPadding * 3); | 102 kTextfieldHorizontalPadding * 3); |
103 int height = (textfield_->GetPreferredSize().height() + | 103 int height = (textfield_->GetPreferredSize().height() + |
104 kTextfieldVerticalPadding * 2); | 104 kTextfieldVerticalPadding * 2); |
105 | 105 |
106 return gfx::Size(width, height); | 106 return gfx::Size(width, height); |
107 } | 107 } |
108 | 108 |
109 gfx::Size TextfieldWrapper::GetImageSize() const { | 109 gfx::Size TextfieldWrapper::GetImageSize() const { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 189 |
190 int button_x = (textfield_wrapper_->GetPreferredSize().width() + | 190 int button_x = (textfield_wrapper_->GetPreferredSize().width() + |
191 kButtonHorizontalSpacing); | 191 kButtonHorizontalSpacing); |
192 accept_button_->SetBounds( | 192 accept_button_->SetBounds( |
193 button_x, | 193 button_x, |
194 y - kWrapperBorderSize, | 194 y - kWrapperBorderSize, |
195 kButtonWidth, | 195 kButtonWidth, |
196 textfield_wrapper_->GetPreferredSize().height() + kWrapperBorderSize * 2); | 196 textfield_wrapper_->GetPreferredSize().height() + kWrapperBorderSize * 2); |
197 } | 197 } |
198 | 198 |
199 gfx::Size PasswordGenerationBubbleView::GetPreferredSize() { | 199 gfx::Size PasswordGenerationBubbleView::GetPreferredSize() const { |
200 int width = (textfield_wrapper_->GetPreferredSize().width() + | 200 int width = (textfield_wrapper_->GetPreferredSize().width() + |
201 kButtonHorizontalSpacing + | 201 kButtonHorizontalSpacing + |
202 kButtonWidth - 1); | 202 kButtonWidth - 1); |
203 int height = (title_label_->GetPreferredSize().height() + | 203 int height = (title_label_->GetPreferredSize().height() + |
204 textfield_wrapper_->GetPreferredSize().height() + | 204 textfield_wrapper_->GetPreferredSize().height() + |
205 kVerticalPadding); | 205 kVerticalPadding); |
206 return gfx::Size(width, height); | 206 return gfx::Size(width, height); |
207 } | 207 } |
208 | 208 |
209 gfx::Rect PasswordGenerationBubbleView::GetAnchorRect() { | 209 gfx::Rect PasswordGenerationBubbleView::GetAnchorRect() const { |
210 return anchor_rect_; | 210 return anchor_rect_; |
211 } | 211 } |
212 | 212 |
213 void PasswordGenerationBubbleView::ButtonPressed(views::Button* sender, | 213 void PasswordGenerationBubbleView::ButtonPressed(views::Button* sender, |
214 const ui::Event& event) { | 214 const ui::Event& event) { |
215 if (sender == accept_button_) { | 215 if (sender == accept_button_) { |
216 render_view_host_->Send(new AutofillMsg_GeneratedPasswordAccepted( | 216 render_view_host_->Send(new AutofillMsg_GeneratedPasswordAccepted( |
217 render_view_host_->GetRoutingID(), textfield_->text())); | 217 render_view_host_->GetRoutingID(), textfield_->text())); |
218 password_manager_->SetFormHasGeneratedPassword(form_); | 218 password_manager_->SetFormHasGeneratedPassword(form_); |
219 actions_.password_accepted = true; | 219 actions_.password_accepted = true; |
(...skipping 18 matching lines...) Expand all Loading... |
238 return false; | 238 return false; |
239 } | 239 } |
240 | 240 |
241 views::View* PasswordGenerationBubbleView::GetInitiallyFocusedView() { | 241 views::View* PasswordGenerationBubbleView::GetInitiallyFocusedView() { |
242 return textfield_; | 242 return textfield_; |
243 } | 243 } |
244 | 244 |
245 void PasswordGenerationBubbleView::WindowClosing() { | 245 void PasswordGenerationBubbleView::WindowClosing() { |
246 autofill::password_generation::LogUserActions(actions_); | 246 autofill::password_generation::LogUserActions(actions_); |
247 } | 247 } |
OLD | NEW |