Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(573)

Unified Diff: ios/web/web_state/js/resources/form.js

Issue 2807213003: Move stringify, form, navigation and scroll methods out of core.js. (Closed)
Patch Set: Re-upload patch after rebase-update in local branch Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/web/web_state/js/resources/core.js ('k') | ios/web/web_state/js/resources/navigation.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/web_state/js/resources/form.js
diff --git a/ios/web/web_state/js/resources/form.js b/ios/web/web_state/js/resources/form.js
new file mode 100644
index 0000000000000000000000000000000000000000..c18d3da91d6ad28a9ac4f1a87251cf393f9a876c
--- /dev/null
+++ b/ios/web/web_state/js/resources/form.js
@@ -0,0 +1,89 @@
+// 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.
+
+/**
+ * @fileoverview Adds listeners that are used to handle forms, enabling autofill
+ * and the replacement method to dismiss the keyboard needed because of the
+ * Autofill keyboard accessory.
+ */
+
+goog.provide('__crWeb.form');
+
+goog.require('__crWeb.message');
+
+/** Beginning of anonymous object */
+(function() {
+
+ /**
+ * Focus and input events for form elements are messaged to the main
+ * application for broadcast to CRWWebControllerObservers.
+ * This is done with a single event handler for each type being added to the
+ * main document element which checks the source element of the event; this
+ * is much easier to manage than adding handlers to individual elements.
+ * @private
+ */
+ var formActivity_ = function(evt) {
+ var srcElement = evt.srcElement;
+ var fieldName = srcElement.name || '';
+ var value = srcElement.value || '';
+
+ var msg = {
+ 'command': 'form.activity',
+ 'formName': __gCrWeb.common.getFormIdentifier(evt.srcElement.form),
+ 'fieldName': fieldName,
+ 'type': evt.type,
+ 'value': value
+ };
+ __gCrWeb.message.invokeOnHost(msg);
+ };
+
+ /**
+ * Focus events performed on the 'capture' phase otherwise they are often
+ * not received.
+ */
+ document.addEventListener('focus', formActivity_, true);
+ document.addEventListener('blur', formActivity_, true);
+ document.addEventListener('change', formActivity_, true);
+
+ /**
+ * Text input is watched at the bubbling phase as this seems adequate in
+ * practice and it is less obtrusive to page scripts than capture phase.
+ */
+ document.addEventListener('input', formActivity_, false);
+ document.addEventListener('keyup', formActivity_, false);
+
+ /**
+ * Capture form submit actions.
+ */
+ document.addEventListener('submit', function(evt) {
+ var action;
+ if (evt['defaultPrevented'])
+ return;
+ action = evt.target.getAttribute('action');
+ // Default action is to re-submit to same page.
+ if (!action) {
+ action = document.location.href;
+ }
+ __gCrWeb.message.invokeOnHost({
+ 'command': 'document.submit',
+ 'formName': __gCrWeb.common.getFormIdentifier(evt.srcElement),
+ 'href': getFullyQualifiedUrl_(action)
+ });
+ }, false);
+
+ /** @private */
+ var getFullyQualifiedUrl_ = function(originalURL) {
+ // A dummy anchor (never added to the document) is used to obtain the
+ // fully-qualified URL of |originalURL|.
+ var anchor = document.createElement('a');
+ anchor.href = originalURL;
+ return anchor.href;
+ };
+
+ /** Flush the message queue. */
+ if (__gCrWeb.message) {
+ __gCrWeb.message.invokeQueues();
+ }
+
+}()); // End of anonymous object
« no previous file with comments | « ios/web/web_state/js/resources/core.js ('k') | ios/web/web_state/js/resources/navigation.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698