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

Side by Side Diff: Source/devtools/front_end/ui/SplitWidget.js

Issue 1156953002: Devtools: Replace split widget rAF animation with web animation (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address review comments Created 5 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 10 *
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 this.dispatchEventToListeners(WebInspector.SplitWidget.Events.Sideba rSizeChanged, this.sidebarSize()); 501 this.dispatchEventToListeners(WebInspector.SplitWidget.Events.Sideba rSizeChanged, this.sidebarSize());
502 } 502 }
503 }, 503 },
504 504
505 /** 505 /**
506 * @param {boolean} reverse 506 * @param {boolean} reverse
507 * @param {function()=} callback 507 * @param {function()=} callback
508 */ 508 */
509 _animate: function(reverse, callback) 509 _animate: function(reverse, callback)
510 { 510 {
511 var animationTime = 50; 511 /**
512 * @param {number} timeStamp
513 * @this {!WebInspector.SplitWidget}
514 */
515 function animationFrame(timeStamp)
516 {
517 this._mainWidget.doResize();
dgozman 2015/06/02 09:36:54 Looks like this call will be duplicated in animati
samli 2015/06/05 03:06:53 Fixed.
samli 2015/06/05 03:06:53 Done.
518 if (player.playState !== "finished")
519 this.contentElement.window().requestAnimationFrame(animationFram e.bind(this));
520 }
521
522 /**
523 * @this {!WebInspector.SplitWidget}
524 */
525 function animationFinished()
526 {
527 this._cancelAnimation();
528 if (this._mainWidget)
529 this._mainWidget.doResize();
530 this.dispatchEventToListeners(WebInspector.SplitWidget.Events.Sideba rSizeChanged, this.sidebarSize());
531 }
532
512 this._animationCallback = callback; 533 this._animationCallback = callback;
513 534
514 var animatedMarginPropertyName; 535 var animatedMarginPropertyName;
515 if (this._isVertical) 536 if (this._isVertical)
516 animatedMarginPropertyName = this._secondIsSidebar ? "margin-right" : "margin-left"; 537 animatedMarginPropertyName = this._secondIsSidebar ? "margin-right" : "margin-left";
517 else 538 else
518 animatedMarginPropertyName = this._secondIsSidebar ? "margin-bottom" : "margin-top"; 539 animatedMarginPropertyName = this._secondIsSidebar ? "margin-bottom" : "margin-top";
519 540
520 var marginFrom = reverse ? "0" : "-" + WebInspector.zoomManager.dipToCSS (this._sidebarSizeDIP) + "px"; 541 var sidebarSize = this._sidebarSizeDIP !== -1 ? this._sidebarSizeDIP : 0
521 var marginTo = reverse ? "-" + WebInspector.zoomManager.dipToCSS(this._s idebarSizeDIP) + "px" : "0"; 542 var marginFrom = reverse ? "0" : "-" + WebInspector.zoomManager.dipToCSS (sidebarSize) + "px";
543 var marginTo = reverse ? "-" + WebInspector.zoomManager.dipToCSS(sidebar Size) + "px" : "0";
522 544
523 // This order of things is important. 545 this.contentElement.style.setProperty(animatedMarginPropertyName, margin To);
524 // 1. Resize main element early and force layout.
525 this.contentElement.style.setProperty(animatedMarginPropertyName, margin From);
526 if (!reverse) {
527 suppressUnused(this._mainElement.offsetWidth);
dgozman 2015/06/02 09:36:54 I wonder why this is not needed anymore?
samli 2015/06/05 03:06:53 I don't know why it was needed in the first place.
samli 2015/06/05 03:06:53 Not sure why it would be.
528 suppressUnused(this._sidebarElement.offsetWidth);
529 }
530
531 // 2. Issue onresize to the sidebar element, its size won't change.
532 if (!reverse) 546 if (!reverse)
533 this._sidebarWidget.doResize(); 547 this._sidebarWidget.doResize();
548 var keyframes = [{}, {}];
549 keyframes[0][animatedMarginPropertyName] = marginFrom;
550 keyframes[1][animatedMarginPropertyName] = marginTo;
551 var player = this.contentElement.animate(keyframes, { duration: 150, eas ing: "cubic-bezier(0, 0, 0.2, 1)" });
552 player.onfinish = animationFinished.bind(this);
534 553
535 // 3. Configure and run animation 554 if (this._mainWidget)
536 this.contentElement.style.setProperty("transition", animatedMarginProper tyName + " " + animationTime + "ms linear"); 555 this.contentElement.window().requestAnimationFrame(animationFrame.bi nd(this));
537
538 var boundAnimationFrame;
539 var startTime;
540 /**
541 * @this {WebInspector.SplitWidget}
542 */
543 function animationFrame()
544 {
545 delete this._animationFrameHandle;
546
547 if (!startTime) {
548 // Kick animation on first frame.
549 this.contentElement.style.setProperty(animatedMarginPropertyName , marginTo);
550 startTime = window.performance.now();
551 } else if (window.performance.now() < startTime + animationTime) {
552 // Process regular animation frame.
553 if (this._mainWidget)
554 this._mainWidget.doResize();
555 } else {
556 // Complete animation.
557 this._cancelAnimation();
558 if (this._mainWidget)
559 this._mainWidget.doResize();
560 this.dispatchEventToListeners(WebInspector.SplitWidget.Events.Si debarSizeChanged, this.sidebarSize());
561 return;
562 }
563 this._animationFrameHandle = this.contentElement.window().requestAni mationFrame(boundAnimationFrame);
564 }
565 boundAnimationFrame = animationFrame.bind(this);
566 this._animationFrameHandle = this.contentElement.window().requestAnimati onFrame(boundAnimationFrame);
567 }, 556 },
568 557
569 _cancelAnimation: function() 558 _cancelAnimation: function()
570 { 559 {
571 this.contentElement.style.removeProperty("margin-top"); 560 this.contentElement.style.removeProperty("margin-top");
572 this.contentElement.style.removeProperty("margin-right"); 561 this.contentElement.style.removeProperty("margin-right");
573 this.contentElement.style.removeProperty("margin-bottom"); 562 this.contentElement.style.removeProperty("margin-bottom");
574 this.contentElement.style.removeProperty("margin-left"); 563 this.contentElement.style.removeProperty("margin-left");
575 this.contentElement.style.removeProperty("transition"); 564 this.contentElement.style.removeProperty("transition");
576 565
577 if (this._animationFrameHandle) {
578 this.contentElement.window().cancelAnimationFrame(this._animationFra meHandle);
579 delete this._animationFrameHandle;
580 }
581 if (this._animationCallback) { 566 if (this._animationCallback) {
582 this._animationCallback(); 567 this._animationCallback();
583 delete this._animationCallback; 568 delete this._animationCallback;
584 } 569 }
585 }, 570 },
586 571
587 /** 572 /**
588 * @param {number} sidebarSize 573 * @param {number} sidebarSize
589 * @param {boolean=} userAction 574 * @param {boolean=} userAction
590 * @return {number} 575 * @return {number}
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 this._showHideSidebarButton.classList.toggle("toggled-hide", !sidebarHid den); 875 this._showHideSidebarButton.classList.toggle("toggled-hide", !sidebarHid den);
891 this._showHideSidebarButton.classList.toggle("top-sidebar-show-hide-butt on", !this.isVertical() && !this.isSidebarSecond()); 876 this._showHideSidebarButton.classList.toggle("top-sidebar-show-hide-butt on", !this.isVertical() && !this.isSidebarSecond());
892 this._showHideSidebarButton.classList.toggle("right-sidebar-show-hide-bu tton", this.isVertical() && this.isSidebarSecond()); 877 this._showHideSidebarButton.classList.toggle("right-sidebar-show-hide-bu tton", this.isVertical() && this.isSidebarSecond());
893 this._showHideSidebarButton.classList.toggle("bottom-sidebar-show-hide-b utton", !this.isVertical() && this.isSidebarSecond()); 878 this._showHideSidebarButton.classList.toggle("bottom-sidebar-show-hide-b utton", !this.isVertical() && this.isSidebarSecond());
894 this._showHideSidebarButton.classList.toggle("left-sidebar-show-hide-but ton", this.isVertical() && !this.isSidebarSecond()); 879 this._showHideSidebarButton.classList.toggle("left-sidebar-show-hide-but ton", this.isVertical() && !this.isSidebarSecond());
895 this._showHideSidebarButton.title = sidebarHidden ? WebInspector.UIStrin g("Show %s", this._showHideSidebarButtonTitle) : WebInspector.UIString("Hide %s" , this._showHideSidebarButtonTitle); 880 this._showHideSidebarButton.title = sidebarHidden ? WebInspector.UIStrin g("Show %s", this._showHideSidebarButtonTitle) : WebInspector.UIString("Hide %s" , this._showHideSidebarButtonTitle);
896 }, 881 },
897 882
898 __proto__: WebInspector.Widget.prototype 883 __proto__: WebInspector.Widget.prototype
899 } 884 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698