| 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/views/autofill/password_generation_popup_view_views.
h" | 5 #include "chrome/browser/ui/views/autofill/password_generation_popup_view_views.
h" |
| 6 | 6 |
| 7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
| 8 #include "chrome/browser/ui/autofill/password_generation_popup_controller.h" | 8 #include "chrome/browser/ui/autofill/password_generation_popup_controller.h" |
| 9 #include "chrome/browser/ui/autofill/popup_constants.h" | 9 #include "chrome/browser/ui/autofill/popup_constants.h" |
| 10 #include "grit/theme_resources.h" | 10 #include "grit/theme_resources.h" |
| 11 #include "ui/accessibility/ax_view_state.h" |
| 11 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
| 12 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
| 13 #include "ui/views/background.h" | 14 #include "ui/views/background.h" |
| 14 #include "ui/views/border.h" | 15 #include "ui/views/border.h" |
| 15 #include "ui/views/controls/image_view.h" | 16 #include "ui/views/controls/image_view.h" |
| 16 #include "ui/views/controls/label.h" | 17 #include "ui/views/controls/label.h" |
| 17 #include "ui/views/controls/styled_label.h" | 18 #include "ui/views/controls/styled_label.h" |
| 18 #include "ui/views/layout/box_layout.h" | 19 #include "ui/views/layout/box_layout.h" |
| 19 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 20 | 21 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 class PasswordGenerationPopupViewViews::PasswordBox : public views::View { | 78 class PasswordGenerationPopupViewViews::PasswordBox : public views::View { |
| 78 public: | 79 public: |
| 79 PasswordBox() {} | 80 PasswordBox() {} |
| 80 virtual ~PasswordBox() {} | 81 virtual ~PasswordBox() {} |
| 81 | 82 |
| 82 // |password| is the generated password, |suggestion| is the text prompting | 83 // |password| is the generated password, |suggestion| is the text prompting |
| 83 // the user to select the password, and |font_list| is the font used for all | 84 // the user to select the password, and |font_list| is the font used for all |
| 84 // the text. | 85 // the text. |
| 85 void Init(const base::string16& password, | 86 void Init(const base::string16& password, |
| 86 const base::string16& suggestion, | 87 const base::string16& suggestion, |
| 88 const base::string16& accessibility_name, |
| 87 const gfx::FontList& font_list) { | 89 const gfx::FontList& font_list) { |
| 90 accessibility_name_ = accessibility_name; |
| 91 |
| 88 views::BoxLayout* box_layout = new views::BoxLayout( | 92 views::BoxLayout* box_layout = new views::BoxLayout( |
| 89 views::BoxLayout::kHorizontal, | 93 views::BoxLayout::kHorizontal, |
| 90 PasswordGenerationPopupController::kHorizontalPadding, | 94 PasswordGenerationPopupController::kHorizontalPadding, |
| 91 0, | 95 0, |
| 92 15); | 96 15); |
| 93 box_layout->set_main_axis_alignment( | 97 box_layout->set_main_axis_alignment( |
| 94 views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); | 98 views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); |
| 95 SetLayoutManager(box_layout); | 99 SetLayoutManager(box_layout); |
| 96 | 100 |
| 97 views::ImageView* key_image = new views::ImageView(); | 101 views::ImageView* key_image = new views::ImageView(); |
| 98 key_image->SetImage( | 102 key_image->SetImage( |
| 99 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 103 ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 100 IDR_GENERATE_PASSWORD_KEY).ToImageSkia()); | 104 IDR_GENERATE_PASSWORD_KEY).ToImageSkia()); |
| 101 AddChildView(key_image); | 105 AddChildView(key_image); |
| 102 | 106 |
| 103 PasswordTextBox* password_text_box = new PasswordTextBox(); | 107 PasswordTextBox* password_text_box = new PasswordTextBox(); |
| 104 password_text_box->Init(suggestion, password, font_list); | 108 password_text_box->Init(suggestion, password, font_list); |
| 105 AddChildView(password_text_box); | 109 AddChildView(password_text_box); |
| 110 |
| 111 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
| 106 } | 112 } |
| 107 | 113 |
| 108 // views::View: | 114 // views::View: |
| 109 virtual bool CanProcessEventsWithinSubtree() const override { | 115 virtual bool CanProcessEventsWithinSubtree() const override { |
| 110 // Send events to the parent view for handling. | 116 // Send events to the parent view for handling. |
| 111 return false; | 117 return false; |
| 112 } | 118 } |
| 113 | 119 |
| 120 virtual void GetAccessibleState(ui::AXViewState* state) override { |
| 121 state->role = ui::AX_ROLE_ALERT; |
| 122 state->name = accessibility_name_; |
| 123 } |
| 124 |
| 114 private: | 125 private: |
| 126 base::string16 accessibility_name_; |
| 127 |
| 115 DISALLOW_COPY_AND_ASSIGN(PasswordBox); | 128 DISALLOW_COPY_AND_ASSIGN(PasswordBox); |
| 116 }; | 129 }; |
| 117 | 130 |
| 118 PasswordGenerationPopupViewViews::PasswordGenerationPopupViewViews( | 131 PasswordGenerationPopupViewViews::PasswordGenerationPopupViewViews( |
| 119 PasswordGenerationPopupController* controller, | 132 PasswordGenerationPopupController* controller, |
| 120 views::Widget* observing_widget) | 133 views::Widget* observing_widget) |
| 121 : AutofillPopupBaseView(controller, observing_widget), | 134 : AutofillPopupBaseView(controller, observing_widget), |
| 122 password_view_(NULL), | 135 password_view_(NULL), |
| 123 font_list_(ResourceBundle::GetSharedInstance().GetFontList( | 136 font_list_(ResourceBundle::GetSharedInstance().GetFontList( |
| 124 ResourceBundle::SmallFont)), | 137 ResourceBundle::SmallFont)), |
| (...skipping 30 matching lines...) Expand all Loading... |
| 155 | 168 |
| 156 PasswordGenerationPopupViewViews::~PasswordGenerationPopupViewViews() {} | 169 PasswordGenerationPopupViewViews::~PasswordGenerationPopupViewViews() {} |
| 157 | 170 |
| 158 void PasswordGenerationPopupViewViews::CreatePasswordView() { | 171 void PasswordGenerationPopupViewViews::CreatePasswordView() { |
| 159 if (password_view_) | 172 if (password_view_) |
| 160 return; | 173 return; |
| 161 | 174 |
| 162 password_view_ = new PasswordBox(); | 175 password_view_ = new PasswordBox(); |
| 163 password_view_->Init(controller_->password(), | 176 password_view_->Init(controller_->password(), |
| 164 controller_->SuggestedText(), | 177 controller_->SuggestedText(), |
| 178 controller_->AccessibilityName(), |
| 165 font_list_); | 179 font_list_); |
| 166 password_view_->SetPosition(gfx::Point(kPopupBorderThickness, | 180 password_view_->SetPosition(gfx::Point(kPopupBorderThickness, |
| 167 kPopupBorderThickness)); | 181 kPopupBorderThickness)); |
| 168 password_view_->SizeToPreferredSize(); | 182 password_view_->SizeToPreferredSize(); |
| 169 AddChildView(password_view_); | 183 AddChildView(password_view_); |
| 170 } | 184 } |
| 171 | 185 |
| 172 gfx::Size PasswordGenerationPopupViewViews::GetPreferredSizeOfPasswordView() { | 186 gfx::Size PasswordGenerationPopupViewViews::GetPreferredSizeOfPasswordView() { |
| 173 int height = kPopupBorderThickness; | 187 int height = kPopupBorderThickness; |
| 174 if (controller_->display_password()) { | 188 if (controller_->display_password()) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 279 |
| 266 // If the top level widget can't be found, cancel the popup since we can't | 280 // If the top level widget can't be found, cancel the popup since we can't |
| 267 // fully set it up. | 281 // fully set it up. |
| 268 if (!observing_widget) | 282 if (!observing_widget) |
| 269 return NULL; | 283 return NULL; |
| 270 | 284 |
| 271 return new PasswordGenerationPopupViewViews(controller, observing_widget); | 285 return new PasswordGenerationPopupViewViews(controller, observing_widget); |
| 272 } | 286 } |
| 273 | 287 |
| 274 } // namespace autofill | 288 } // namespace autofill |
| OLD | NEW |