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

Unified Diff: tools/cc-frame-viewer/src/ui/drag_handle.js

Issue 12225131: [cc] Initial checkin of cc-frame-viewer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 10 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 | « tools/cc-frame-viewer/src/ui/drag_handle.css ('k') | tools/cc-frame-viewer/src/ui/event_target.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/cc-frame-viewer/src/ui/drag_handle.js
diff --git a/tools/cc-frame-viewer/src/ui/drag_handle.js b/tools/cc-frame-viewer/src/ui/drag_handle.js
new file mode 100644
index 0000000000000000000000000000000000000000..e0146b4677a5cfe373bd965e7e74cad19241a7fe
--- /dev/null
+++ b/tools/cc-frame-viewer/src/ui/drag_handle.js
@@ -0,0 +1,65 @@
+/* Copyright (c) 2012 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.
+ */
+'use strict';
+
+base.require('ui');
+base.requireStylesheet('ui.drag_handle');
+
+base.exportTo('ui', function() {
+
+ /**
+ * Detects when user clicks handle determines new height of container based
+ * on user's vertical mouse move and resizes the target.
+ * @constructor
+ * @extends {HTMLDivElement}
+ * You will need to set target to be the draggable element
+ */
+ var DragHandle = ui.define('x-drag-handle');
+
+ DragHandle.prototype = {
+ __proto__: HTMLDivElement.prototype,
+
+ decorate: function() {
+ this.lastMousePosY = 0;
+ this.onMouseMove_ = this.onMouseMove_.bind(this);
+ this.onMouseUp_ = this.onMouseUp_.bind(this);
+ this.addEventListener('mousedown', this.onMouseDown_);
+ this.target = undefined;
+ },
+
+ onMouseMove_: function(e) {
+ // Compute the difference in height position.
+ var dy = this.lastMousePosY - e.clientY;
+ // If style is not set, start off with computed height.
+ if (!this.target.style.height)
+ this.target.style.height = window.getComputedStyle(this.target).height;
+ // Apply new height to the container.
+ this.target.style.height = parseInt(this.target.style.height) + dy + 'px';
+ this.lastMousePosY = e.clientY;
+ e.preventDefault();
+ return true;
+ },
+
+ onMouseDown_: function(e) {
+ if (!this.target)
+ return;
+ this.lastMousePosY = e.clientY;
+ document.addEventListener('mousemove', this.onMouseMove_);
+ document.addEventListener('mouseup', this.onMouseUp_);
+ e.preventDefault();
+ return true;
+ },
+
+ onMouseUp_: function(e) {
+ document.removeEventListener('mousemove', this.onMouseMove_);
+ document.removeEventListener('mouseup', this.onMouseUp_);
+ e.preventDefault();
+ }
+ };
+
+ return {
+ DragHandle: DragHandle
+ };
+});
« no previous file with comments | « tools/cc-frame-viewer/src/ui/drag_handle.css ('k') | tools/cc-frame-viewer/src/ui/event_target.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698