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

Unified Diff: chrome/browser/resources/local_ntp/local_ntp.js

Issue 20501002: Adds paste function to searchbox api and handles paste event on fakebox (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 7 years, 4 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 | « chrome/browser/resources/local_ntp/local_ntp.css ('k') | chrome/browser/ui/browser_instant_controller.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/local_ntp/local_ntp.js
diff --git a/chrome/browser/resources/local_ntp/local_ntp.js b/chrome/browser/resources/local_ntp/local_ntp.js
index ab514dfeb1f0c07205ffa45495031cf3daead90c..b3878197c66dcabec64badb24a37872b48b6a969 100644
--- a/chrome/browser/resources/local_ntp/local_ntp.js
+++ b/chrome/browser/resources/local_ntp/local_ntp.js
@@ -28,6 +28,8 @@ var CLASSES = {
DELAYED_HIDE_NOTIFICATION: 'mv-notice-delayed-hide',
FAKEBOX_DISABLE: 'fakebox-disable', // Makes fakebox non-interactive
FAKEBOX_FOCUS: 'fakebox-focused', // Applies focus styles to the fakebox
+ // Applies drag focus style to the fakebox
+ FAKEBOX_DRAG_FOCUS: 'fakebox-drag-focused',
FAVICON: 'mv-favicon',
HIDE_BLACKLIST_BUTTON: 'mv-x-hide', // hides blacklist button during animation
HIDE_FAKEBOX_AND_LOGO: 'hide-fakebox-logo',
@@ -55,6 +57,7 @@ var IDS = {
ATTRIBUTION_TEXT: 'attribution-text',
CUSTOM_THEME_STYLE: 'ct-style',
FAKEBOX: 'fakebox',
+ FAKEBOX_INPUT: 'fakebox-input',
LOGO: 'logo',
NOTIFICATION: 'mv-notice',
NOTIFICATION_CLOSE_BUTTON: 'mv-notice-x',
@@ -770,6 +773,7 @@ function getTileByRid(rid) {
function onInputStart() {
if (fakebox && isFakeboxFocused()) {
setFakeboxFocus(false);
+ setFakeboxDragFocus(false);
disposeNtp(true);
} else if (!isFakeboxFocused()) {
disposeNtp(false);
@@ -806,12 +810,19 @@ function setFakeboxFocus(focus) {
document.body.classList.toggle(CLASSES.FAKEBOX_FOCUS, focus);
}
+/**
+ * @param {boolean} focus True to show a dragging focus to the fakebox.
+ */
+function setFakeboxDragFocus(focus) {
+ document.body.classList.toggle(CLASSES.FAKEBOX_DRAG_FOCUS, focus);
+}
/**
* @return {boolean} True if the fakebox has focus.
*/
function isFakeboxFocused() {
- return document.body.classList.contains(CLASSES.FAKEBOX_FOCUS);
+ return document.body.classList.contains(CLASSES.FAKEBOX_FOCUS) ||
+ document.body.classList.contains(CLASSES.FAKEBOX_DRAG_FOCUS);
}
@@ -947,7 +958,8 @@ function init() {
fakebox = document.createElement('div');
fakebox.id = IDS.FAKEBOX;
fakebox.innerHTML =
- '<input autocomplete="off" tabindex="-1" aria-hidden="true">' +
+ '<input id="' + IDS.FAKEBOX_INPUT +
+ '" autocomplete="off" tabindex="-1" aria-hidden="true">' +
'<div id=cursor></div>';
ntpContents.insertBefore(fakebox, ntpContents.firstChild);
@@ -1011,7 +1023,7 @@ function init() {
if (fakebox) {
// Listener for updating the key capture state.
- document.body.onclick = function(event) {
+ document.body.onmousedown = function(event) {
if (isFakeboxClick(event))
searchboxApiHandle.startCapturingKeyStrokes();
else if (isFakeboxFocused())
@@ -1020,6 +1032,26 @@ function init() {
searchboxApiHandle.onkeycapturechange = function() {
setFakeboxFocus(searchboxApiHandle.isKeyCaptureEnabled);
};
+ var inputbox = $(IDS.FAKEBOX_INPUT);
+ if (inputbox) {
+ inputbox.onpaste = function(event) {
+ event.preventDefault();
+ searchboxApiHandle.paste();
+ };
+ inputbox.ondrop = function(event) {
+ event.preventDefault();
+ var text = event.dataTransfer.getData('text/plain');
+ if (text) {
+ searchboxApiHandle.paste(text);
+ }
+ };
+ inputbox.ondragenter = function() {
+ setFakeboxDragFocus(true);
+ };
+ inputbox.ondragleave = function() {
+ setFakeboxDragFocus(false);
+ };
+ }
}
if (searchboxApiHandle.rtl) {
« no previous file with comments | « chrome/browser/resources/local_ntp/local_ntp.css ('k') | chrome/browser/ui/browser_instant_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698