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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/Popover.js

Issue 2157533003: DevTools: Source color picker experiment. Make color swatches clickable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 clearTimeout(this._hidePopoverTimer); 413 clearTimeout(this._hidePopoverTimer);
414 delete this._hidePopoverTimer; 414 delete this._hidePopoverTimer;
415 415
416 // We know that we reached the popup, but we might have moved over o ther elements. 416 // We know that we reached the popup, but we might have moved over o ther elements.
417 // Discard pending command. 417 // Discard pending command.
418 this._resetHoverTimer(); 418 this._resetHoverTimer();
419 } 419 }
420 } 420 }
421 } 421 }
422 422
423 /**
424 * @constructor
425 * @extends {WebInspector.Object}
426 */
427 WebInspector.IconPopoverHelper = function()
428 {
429 this._popover = new WebInspector.Popover();
430 this._popover.setCanShrink(false);
431 this._popover.setNoMargins(true);
432 this._popover.element.addEventListener("mousedown", consumeEvent, false);
433
434 this._hideProxy = this.hide.bind(this, true);
435 this._boundOnKeyDown = this._onKeyDown.bind(this);
436 this._repositionBound = this.reposition.bind(this);
437 this._boundFocusOut = this._onFocusOut.bind(this);
438 }
439
440 WebInspector.IconPopoverHelper.prototype = {
441 /**
442 * @param {!Event} event
443 */
444 _onFocusOut: function(event)
445 {
446 if (!event.relatedTarget || event.relatedTarget.isSelfOrDescendant(this. _view.contentElement))
447 return;
448 this._hideProxy();
449 },
450
451 /**
452 * @return {boolean}
453 */
454 isShowing: function()
455 {
456 return this._popover.isShowing();
457 },
458
459 /**
460 * @param {!WebInspector.Widget} view
461 * @param {!Element} anchorElement
462 * @param {?Element=} scrollerElement
463 * @param {function(boolean)=} hiddenCallback
464 */
465 show: function(view, anchorElement, scrollerElement, hiddenCallback)
466 {
467 if (this._popover.isShowing()) {
468 if (this._anchorElement === anchorElement)
469 return;
470
471 // Reopen the picker for another anchor element.
472 this.hide(true);
473 }
474
475 delete this._isHidden;
476 this._anchorElement = anchorElement;
477 this._view = view;
478 this._hiddenCallback = hiddenCallback;
479 this.reposition();
480
481 var document = this._popover.element.ownerDocument;
482 document.addEventListener("mousedown", this._hideProxy, false);
483 document.defaultView.addEventListener("resize", this._hideProxy, false);
484 this._view.contentElement.addEventListener("keydown", this._boundOnKeyDo wn, false);
485
486 this._scrollerElement = scrollerElement;
487 if (this._scrollerElement)
488 this._scrollerElement.addEventListener("scroll", this._repositionBou nd, false);
489 },
490
491 /**
492 * @param {!Event=} event
493 */
494 reposition: function(event)
495 {
496 if (!this._previousFocusElement)
497 this._previousFocusElement = WebInspector.currentFocusElement();
498 // Unbind "blur" listener to avoid reenterability: |popover.showView| wi ll hide the popover and trigger it synchronously.
499 this._view.contentElement.removeEventListener("focusout", this._boundFoc usOut, false);
500 this._popover.showView(this._view, this._anchorElement);
501 this._view.contentElement.addEventListener("focusout", this._boundFocusO ut, false);
502 WebInspector.setCurrentFocusElement(this._view.contentElement);
503 },
504
505 /**
506 * @param {boolean=} commitEdit
507 */
508 hide: function(commitEdit)
509 {
510 if (this._isHidden)
511 return;
512 var document = this._popover.element.ownerDocument;
513 this._isHidden = true;
514 this._popover.hide();
515
516 if (this._scrollerElement)
517 this._scrollerElement.removeEventListener("scroll", this._reposition Bound, false);
518
519 document.removeEventListener("mousedown", this._hideProxy, false);
520 document.defaultView.removeEventListener("resize", this._hideProxy, fals e);
521
522 if (this._hiddenCallback)
523 this._hiddenCallback.call(null, !!commitEdit);
524
525 WebInspector.setCurrentFocusElement(this._previousFocusElement);
526 delete this._previousFocusElement;
527 delete this._anchorElement;
528 if (this._view) {
529 this._view.detach();
530 this._view.contentElement.removeEventListener("keydown", this._bound OnKeyDown, false);
531 this._view.contentElement.removeEventListener("focusout", this._boun dFocusOut, false);
532 delete this._view;
533 }
534 },
535
536 /**
537 * @param {!Event} event
538 */
539 _onKeyDown: function(event)
540 {
541 if (event.key === "Enter") {
542 this.hide(true);
543 event.consume(true);
544 return;
545 }
546 if (event.key === "Escape") {
547 this.hide(false);
548 event.consume(true);
549 }
550 },
551
552 __proto__: WebInspector.Object.prototype
553 }
554
423 /** @enum {string} */ 555 /** @enum {string} */
424 WebInspector.Popover.Orientation = { 556 WebInspector.Popover.Orientation = {
425 Top: "top", 557 Top: "top",
426 Bottom: "bottom" 558 Bottom: "bottom"
427 } 559 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698