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

Unified Diff: chrome/browser/resources/net_internals/util.js

Issue 1088007: Add an initial implementation of net-internals inspector in javascript.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: more build file Created 10 years, 9 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/net_internals/timelineviewpainter.js ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/net_internals/util.js
===================================================================
--- chrome/browser/resources/net_internals/util.js (revision 0)
+++ chrome/browser/resources/net_internals/util.js (revision 0)
@@ -0,0 +1,88 @@
+// Copyright (c) 2010 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.
+
+/**
+ * Helper that binds the |this| object to a method to create a callback.
+ */
+Function.prototype.bind = function(thisObj) {
+ var func = this;
+ var args = Array.prototype.slice.call(arguments, 1);
+ return function() {
+ return func.apply(thisObj,
+ args.concat(Array.prototype.slice.call(arguments, 0)))
+ };
+};
+
+/**
+ * Sets the width (in pixels) on a DOM node.
+ */
+function setNodeWidth(node, widthPx) {
+ node.style.width = widthPx.toFixed(0) + "px";
+}
+
+/**
+ * Sets the height (in pixels) on a DOM node.
+ */
+function setNodeHeight(node, heightPx) {
+ node.style.height = heightPx.toFixed(0) + "px";
+}
+
+/**
+ * Sets the position and size of a DOM node (in pixels).
+ */
+function setNodePosition(node, leftPx, topPx, widthPx, heightPx) {
+ node.style.left = leftPx.toFixed(0) + "px";
+ node.style.top = topPx.toFixed(0) + "px";
+ setNodeWidth(node, widthPx);
+ setNodeHeight(node, heightPx);
+}
+
+/**
+ * Adds a node to |parentNode|, of type |tagName|.
+ */
+function addNode(parentNode, tagName) {
+ var elem = parentNode.ownerDocument.createElement(tagName);
+ parentNode.appendChild(elem);
+ return elem;
+}
+
+/**
+ * Adds text to node |parentNode|.
+ */
+function addTextNode(parentNode, text) {
+ var textNode = parentNode.ownerDocument.createTextNode(text);
+ parentNode.appendChild(textNode);
+ return textNode;
+}
+
+/**
+ * Adds or removes a CSS class to |node|.
+ */
+function changeClassName(node, classNameToAddOrRemove, isAdd) {
+ // Multiple classes can be separated by spaces.
+ var currentNames = node.className.split(" ");
+
+ if (isAdd) {
+ if (!(classNameToAddOrRemove in currentNames)) {
+ currentNames.push(classNameToAddOrRemove);
+ }
+ } else {
+ for (var i = 0; i < currentNames.length; ++i) {
+ if (currentNames[i] == classNameToAddOrRemove) {
+ currentNames.splice(i, 1);
+ break;
+ }
+ }
+ }
+
+ node.className = currentNames.join(" ");
+}
+
+function getKeyWithValue(map, value) {
+ for (key in map) {
+ if (map[key] == value)
+ return key;
+ }
+ return '?';
+}
Property changes on: chrome\browser\resources\net_internals\util.js
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « chrome/browser/resources/net_internals/timelineviewpainter.js ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698