[go: nahoru, domu]

cros: Add a functional PIN keyboard view.

The view is not visually up to spec, but implements all of the required
functionality and integrates into the password view.

Bug: 719015
Change-Id: Idecf0eb186ef5c027d04646cc2697f9cc8b16b81
Reviewed-on: https://chromium-review.googlesource.com/537673
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Jacob Dufault <jdufault@chromium.org>
Cr-Commit-Position: refs/heads/master@{#480184}
diff --git a/ash/login/ui/login_password_view.cc b/ash/login/ui/login_password_view.cc
index 35326c8..7b37497 100644
--- a/ash/login/ui/login_password_view.cc
+++ b/ash/login/ui/login_password_view.cc
@@ -7,7 +7,10 @@
 #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/string_number_conversions.h"
 #include "base/strings/utf_string_conversions.h"
+#include "ui/events/event_constants.h"
+#include "ui/events/keycodes/dom/dom_code.h"
 #include "ui/gfx/paint_vector_icon.h"
 #include "ui/views/border.h"
 #include "ui/views/controls/image_view.h"
@@ -99,6 +102,24 @@
 
 LoginPasswordView::~LoginPasswordView() = default;
 
+void LoginPasswordView::AppendNumber(int value) {
+  textfield_->SetText(textfield_->text() + base::IntToString16(value));
+}
+
+void LoginPasswordView::Backspace() {
+  // Instead of just adjusting textfield_ text directly, fire a backspace key
+  // event as this handles the various edge cases (ie, selected text).
+
+  // views::Textfield::OnKeyPressed is private, so we call it via views::View.
+  auto* view = static_cast<views::View*>(textfield_);
+  view->OnKeyPressed(ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_BACK,
+                                  ui::DomCode::BACKSPACE, ui::EF_NONE));
+  view->OnKeyPressed(ui::KeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_BACK,
+                                  ui::DomCode::BACKSPACE, ui::EF_NONE));
+}
+
+void LoginPasswordView::Submit() {}
+
 const char* LoginPasswordView::GetClassName() const {
   return kLoginPasswordViewName;
 }