Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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(); | |
| 518 if (player.playState !== "finished") | |
| 519 this.contentElement.window().requestAnimationFrame(animationFram e.bind(this)); | |
| 520 } | |
| 521 | |
| 512 this._animationCallback = callback; | 522 this._animationCallback = callback; |
| 513 | 523 |
| 514 var animatedMarginPropertyName; | 524 var animatedMarginPropertyName; |
| 515 if (this._isVertical) | 525 if (this._isVertical) |
| 516 animatedMarginPropertyName = this._secondIsSidebar ? "margin-right" : "margin-left"; | 526 animatedMarginPropertyName = this._secondIsSidebar ? "margin-right" : "margin-left"; |
| 517 else | 527 else |
| 518 animatedMarginPropertyName = this._secondIsSidebar ? "margin-bottom" : "margin-top"; | 528 animatedMarginPropertyName = this._secondIsSidebar ? "margin-bottom" : "margin-top"; |
| 519 | 529 |
| 520 var marginFrom = reverse ? "0" : "-" + WebInspector.zoomManager.dipToCSS (this._sidebarSizeDIP) + "px"; | 530 var sidebarSize = this._sidebarSizeDIP !== -1 ? this._sidebarSizeDIP : 0 |
| 521 var marginTo = reverse ? "-" + WebInspector.zoomManager.dipToCSS(this._s idebarSizeDIP) + "px" : "0"; | 531 var marginFrom = reverse ? "0" : "-" + WebInspector.zoomManager.dipToCSS (sidebarSize) + "px"; |
| 532 var marginTo = reverse ? "-" + WebInspector.zoomManager.dipToCSS(sidebar Size) + "px" : "0"; | |
| 522 | 533 |
| 523 // This order of things is important. | 534 this.contentElement.style.setProperty(animatedMarginPropertyName, margin To); |
| 524 // 1. Resize main element early and force layout. | 535 var keyframes = [{}, {}]; |
| 525 this.contentElement.style.setProperty(animatedMarginPropertyName, margin From); | 536 keyframes[0][animatedMarginPropertyName] = marginFrom; |
| 526 if (!reverse) { | 537 keyframes[1][animatedMarginPropertyName] = marginTo; |
| 527 suppressUnused(this._mainElement.offsetWidth); | 538 var player = this.contentElement.animate(keyframes, { duration: 150, eas ing: "cubic-bezier(0, 0, 0.2, 1)" }); |
| 528 suppressUnused(this._sidebarElement.offsetWidth); | 539 player.onfinish = this._cancelAnimation.bind(this); |
| 529 } | |
| 530 | 540 |
| 531 // 2. Issue onresize to the sidebar element, its size won't change. | 541 if (this._mainWidget) |
| 532 if (!reverse) | 542 this.contentElement.window().requestAnimationFrame(animationFrame.bi nd(this)); |
| 533 this._sidebarWidget.doResize(); | |
|
dgozman
2015/05/28 11:43:53
This seems valuable.
| |
| 534 | |
| 535 // 3. Configure and run animation | |
| 536 this.contentElement.style.setProperty("transition", animatedMarginProper tyName + " " + animationTime + "ms linear"); | |
| 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 }, | 543 }, |
| 568 | 544 |
| 569 _cancelAnimation: function() | 545 _cancelAnimation: function() |
| 570 { | 546 { |
| 571 this.contentElement.style.removeProperty("margin-top"); | 547 this.contentElement.style.removeProperty("margin-top"); |
| 572 this.contentElement.style.removeProperty("margin-right"); | 548 this.contentElement.style.removeProperty("margin-right"); |
| 573 this.contentElement.style.removeProperty("margin-bottom"); | 549 this.contentElement.style.removeProperty("margin-bottom"); |
| 574 this.contentElement.style.removeProperty("margin-left"); | 550 this.contentElement.style.removeProperty("margin-left"); |
| 575 this.contentElement.style.removeProperty("transition"); | 551 this.contentElement.style.removeProperty("transition"); |
| 576 | 552 |
| 577 if (this._animationFrameHandle) { | |
| 578 this.contentElement.window().cancelAnimationFrame(this._animationFra meHandle); | |
| 579 delete this._animationFrameHandle; | |
| 580 } | |
| 581 if (this._animationCallback) { | 553 if (this._animationCallback) { |
| 582 this._animationCallback(); | 554 this._animationCallback(); |
| 583 delete this._animationCallback; | 555 delete this._animationCallback; |
| 584 } | 556 } |
| 557 | |
| 558 if (this._mainWidget) | |
| 559 this._mainWidget.doResize(); | |
|
dgozman
2015/05/28 11:43:53
This causes a lot of extra resizes, since |_cancel
| |
| 560 | |
| 561 this.dispatchEventToListeners(WebInspector.SplitWidget.Events.SidebarSiz eChanged, this.sidebarSize()); | |
| 585 }, | 562 }, |
| 586 | 563 |
| 587 /** | 564 /** |
| 588 * @param {number} sidebarSize | 565 * @param {number} sidebarSize |
| 589 * @param {boolean=} userAction | 566 * @param {boolean=} userAction |
| 590 * @return {number} | 567 * @return {number} |
| 591 */ | 568 */ |
| 592 _applyConstraints: function(sidebarSize, userAction) | 569 _applyConstraints: function(sidebarSize, userAction) |
| 593 { | 570 { |
| 594 var totalSize = this._totalSizeDIP(); | 571 var totalSize = this._totalSizeDIP(); |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 890 this._showHideSidebarButton.classList.toggle("toggled-hide", !sidebarHid den); | 867 this._showHideSidebarButton.classList.toggle("toggled-hide", !sidebarHid den); |
| 891 this._showHideSidebarButton.classList.toggle("top-sidebar-show-hide-butt on", !this.isVertical() && !this.isSidebarSecond()); | 868 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()); | 869 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()); | 870 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()); | 871 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); | 872 this._showHideSidebarButton.title = sidebarHidden ? WebInspector.UIStrin g("Show %s", this._showHideSidebarButtonTitle) : WebInspector.UIString("Hide %s" , this._showHideSidebarButtonTitle); |
| 896 }, | 873 }, |
| 897 | 874 |
| 898 __proto__: WebInspector.Widget.prototype | 875 __proto__: WebInspector.Widget.prototype |
| 899 } | 876 } |
| OLD | NEW |