Index: ash/login/ui/login_password_view.cc |
diff --git a/ash/login/ui/login_password_view.cc b/ash/login/ui/login_password_view.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..af22458c64a9d9a19bb61c8265b7a50984147cd3 |
--- /dev/null |
+++ b/ash/login/ui/login_password_view.cc |
@@ -0,0 +1,137 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ash/login/ui/login_password_view.h" |
+ |
+#include "ash/resources/vector_icons/vector_icons.h" |
+#include "ash/system/tray/size_range_layout.h" |
+#include "ash/system/user/button_from_view.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "ui/gfx/paint_vector_icon.h" |
+#include "ui/views/border.h" |
+#include "ui/views/controls/button/button.h" |
+#include "ui/views/controls/image_view.h" |
+#include "ui/views/controls/separator.h" |
+#include "ui/views/controls/textfield/textfield.h" |
+#include "ui/views/layout/box_layout.h" |
+#include "ui/views/layout/fill_layout.h" |
+ |
+namespace ash { |
+namespace { |
+ |
+// Width/height of the submit button. |
+const int kSubmitButtonWidthDp = 20; |
xiyuan
2017/05/24 20:11:02
nit: const -> constexpr ?
jdufault
2017/06/07 18:09:13
Done.
|
+const int kSubmitButtonHeightDp = 20; |
+ |
+// Width/height of the password inputfield. |
+const int kPasswordInputWidthDp = 184; |
+const int kPasswordInputHeightDp = 40; |
+ |
+// Total width of the password view. |
+const int kPasswordTotalWidthDp = 204; |
+ |
+// Distance between the last password dot and the submit arrow/button. |
+const int kDistanceBetweenPasswordAndSubmitDp = 0; |
+ |
+const char* kLoginPasswordViewName = "LoginPasswordView"; |
+ |
+} // namespace |
+ |
+LoginPasswordView::TestApi::TestApi(LoginPasswordView* view) : view_(view) {} |
+ |
+LoginPasswordView::TestApi::~TestApi() = default; |
+ |
+views::View* LoginPasswordView::TestApi::textfield() const { |
+ return view_->textfield_; |
+} |
+ |
+views::View* LoginPasswordView::TestApi::submit_button() const { |
+ return view_->submit_button_; |
+} |
+ |
+LoginPasswordView::LoginPasswordView(const OnPasswordSubmit& on_submit) |
+ : on_submit_(on_submit) { |
+ auto* root_layout = |
+ new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); |
+ root_layout->set_main_axis_alignment( |
+ views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); |
+ SetLayoutManager(root_layout); |
+ |
+ { |
+ auto* row = new views::View(); |
+ AddChildView(row); |
+ auto* layout = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, |
+ kDistanceBetweenPasswordAndSubmitDp); |
+ layout->set_main_axis_alignment( |
+ views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); |
+ row->SetLayoutManager(layout); |
+ |
+ // Password textfield. We place the actual textfield inside of an empty |
+ // fixed-size view so we can precisely control the textfield sizing. |
+ auto* textfield_sizer = new views::View(); |
+ textfield_sizer->SetLayoutManager(new SizeRangeLayout( |
+ gfx::Size(kPasswordInputWidthDp, kPasswordInputHeightDp))); |
+ textfield_ = new views::Textfield(); |
+ textfield_->SetLayoutManager(new views::FillLayout()); |
xiyuan
2017/05/24 20:11:02
Should this be set to |textfield_sizer | instead?
jdufault
2017/06/07 18:09:13
textfield_sizer has a SizeRangeLayout set on it al
xiyuan
2017/06/07 18:19:59
Can you elaboarate why |textfield_| needs a layout
jdufault
2017/06/08 00:11:34
Looks like the |textfield_| layout manager is not
|
+ textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
+ // TODO(jdufault): Real placeholder text. |
+ textfield_->set_placeholder_text(base::ASCIIToUTF16("Password (FIXME)")); |
+ textfield_->SetBorder(nullptr); |
+ |
+ textfield_sizer->AddChildView(textfield_); |
+ row->AddChildView(textfield_sizer); |
+ |
+ // Submit button. |
+ auto* submit_icon = new views::ImageView(); |
+ submit_icon->set_preferred_size( |
+ gfx::Size(kSubmitButtonWidthDp, kSubmitButtonHeightDp)); |
+ // TODO(jdufuault): Use the real icon. |
+ submit_icon->SetImage( |
+ gfx::CreateVectorIcon(kSystemMenuArrowRightIcon, SK_ColorBLUE)); |
+ submit_button_ = new ash::tray::ButtonFromView( |
+ submit_icon, this, TrayPopupInkDropStyle::HOST_CENTERED); |
+ row->AddChildView(submit_button_); |
+ } |
+ |
+ // Separator on bottom. |
+ AddChildView(new views::Separator()); |
+ |
+ // Make sure the textfield always starts with focus. |
+ textfield_->RequestFocus(); |
+} |
+ |
+LoginPasswordView::~LoginPasswordView() = default; |
+ |
+const char* LoginPasswordView::GetClassName() const { |
+ return kLoginPasswordViewName; |
+} |
+ |
+gfx::Size LoginPasswordView::GetPreferredSize() const { |
+ gfx::Size size = views::View::GetPreferredSize(); |
+ size.set_width(kPasswordTotalWidthDp); |
+ return size; |
+} |
+ |
+bool LoginPasswordView::OnKeyPressed(const ui::KeyEvent& event) { |
+ if (event.key_code() == ui::KeyboardCode::VKEY_RETURN) { |
+ SubmitPassword(); |
+ return true; |
+ } |
+ |
+ return false; |
+} |
+ |
+void LoginPasswordView::ButtonPressed(views::Button* sender, |
+ const ui::Event& event) { |
+ SubmitPassword(); |
xiyuan
2017/05/24 20:11:02
nit: DCHCKE_EQ(sender, submit_button_)
jdufault
2017/06/07 18:09:13
Done.
|
+} |
+ |
+void LoginPasswordView::SubmitPassword() { |
+ if (on_submit_) |
+ on_submit_.Run(textfield_->text()); |
+ textfield_->SetText(base::string16()); |
+ textfield_->SchedulePaint(); |
xiyuan
2017/05/24 20:11:02
SchedulePaint() is probably not needed since SetTe
jdufault
2017/06/07 18:09:13
Done.
|
+} |
+ |
+} // namespace ash |