summaryrefslogtreecommitdiffstats
path: root/o3d
diff options
context:
space:
mode:
authorpetersont@google.com <petersont@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-22 20:57:29 +0000
committerpetersont@google.com <petersont@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-22 20:57:29 +0000
commitaa01094677c08f3dd7461357a08d66d9622ad8dc (patch)
tree0abb81a4b064dd9e8e5bd38dd3e5c36e0288f526 /o3d
parent7e966d5a580bdb141b6cde1a6cba24b545966b42 (diff)
downloadchromium_src-aa01094677c08f3dd7461357a08d66d9622ad8dc.zip
chromium_src-aa01094677c08f3dd7461357a08d66d9622ad8dc.tar.gz
chromium_src-aa01094677c08f3dd7461357a08d66d9622ad8dc.tar.bz2
Changed code to eliminate ibeam cursor to only affect the canvas itself (not the whole document) and made option to leave ibeam cursor alone part of a new options argument to o3djs.webgl.makeClients / o3djs.webgl.createClients which replaces opt_features (which wasn't doing anything in o3d-webgl anway) and contains options on the client itself.
Review URL: http://codereview.chromium.org/3358002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60219 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r--o3d/samples/o3djs/webgl.js95
1 files changed, 70 insertions, 25 deletions
diff --git a/o3d/samples/o3djs/webgl.js b/o3d/samples/o3djs/webgl.js
index 9494759..b7c4111 100644
--- a/o3d/samples/o3djs/webgl.js
+++ b/o3d/samples/o3djs/webgl.js
@@ -50,35 +50,68 @@ o3djs.webgl = o3djs.webgl || {};
/**
+ * Takes a javascript object containing name-value pairs of options to
+ * makeClients or createClient and adds options to the default value if they
+ * aren't already there setting them to the default value.
+ * @param {Object} The obejct containing options.
+ */
+o3djs.webgl.setUndefinedOptionsToDefaults_ = function(options) {
+ /**
+ * Whether to install debugging functions, and selectable
+ * @type {boolean}
+ */
+ options.debug = options.debug || false;
+
+ /**
+ * Whether to allow the canvas object created to remain selectable.
+ * @type {boolean}
+ */
+ options.selectable = options.selectable || false;
+};
+
+
+/**
* Finds all divs with an id that starts with "o3d" and inits a canvas
* under them with o3d client object and the o3d namespace.
+ * @param {!function(Array.<!Element>): void} callback Function to call when
+ * client objects have been created.
+ * @param {Object} opt_options An object mapping various options to their values
+ * See comment for o3djs.webgl.setUndefinedOptionsToDefaults_ to see what
+ * options there are.
+ * @param {string} opt_requiredVersion Ignored in o3d-webgl.
+ * @param {!function(!o3d.Renderer.InitStatus, string, (string|undefined),
+ * (string|undefined)): void} opt_failureCallback Called with an error
+ * string if the client fails to create.
+ * @param {string} opt_id The id to look for. This can be a regular
+ * expression. The default is "^o3d".
+ * @param {string} opt_tag The type of tag to look for. The default is "div".
+ * @see o3djs.util.informPluginFailure
*/
o3djs.webgl.makeClients = function(callback,
- opt_features,
+ opt_options,
opt_requiredVersion,
opt_failureCallback,
opt_id,
- opt_tag,
- opt_debug) {
- opt_failureCallback = opt_failureCallback || o3djs.webgl.informPluginFailure;
+ opt_tag) {
+ opt_failureCallback = opt_failureCallback || o3djs.util.informPluginFailure;
+ var options = opt_options;
+
+ // If opt_options is a string, we assume it's coming from formerly plugin
+ // code and ignore it. If it's an object, we assume it's the name-value-pair
+ // object describing the optional arguments to this function.
+ if (options == undefined || typeof options == 'string') {
+ options = {};
+ }
+ o3djs.webgl.setUndefinedOptionsToDefaults_(options);
var clientElements = [];
var elements = o3djs.util.getO3DContainerElements(opt_id, opt_tag);
for (var ee = 0; ee < elements.length; ++ee) {
var element = elements[ee];
- var features = opt_features;
- if (!features) {
- var o3d_features = element.getAttribute('o3d_features');
- if (o3d_features) {
- features = o3d_features;
- } else {
- features = '';
- }
- }
- var objElem = o3djs.webgl.createClient(element, features, opt_debug);
+ var objElem = o3djs.webgl.createClient(element, options, options.debug);
if (!objElem) {
- // If we couldn't create the client then we don't call the callback.
+ opt_failureCallback('Failed to create o3d-webgl client object.');
return;
}
clientElements.push(objElem);
@@ -169,13 +202,23 @@ o3djs.webgl.webGlCanvasError = function(parentNode, unavailableElement) {
* under that.
*
* @param {!Element} element The element under which to insert the client.
- * @param {string} opt_features Features to turn on.
+ * @param {Object} opt_options A javascript object containing
* @param {boolean} opt_debug Whether gl debugging features should be
* enabled.
* @return {HTMLCanvas} The canvas element, or null if initializaton failed.
*/
-o3djs.webgl.createClient = function(element, opt_features, opt_debug) {
- opt_features = opt_features || '';
+o3djs.webgl.createClient = function(element, opt_options, opt_debug) {
+ var options = opt_options;
+
+ // If opt_options is a string, we assume it's coming from formerly plugin
+ // code and ignore it. If it's an object, we assume it's the name-value-pair
+ // object describing the optional arguments to this function.
+ if (opt_options == undefined || typeof opt_options == 'string') {
+ options = {};
+ options.debug = opt_debug;
+ }
+ o3djs.webgl.setUndefinedOptionsToDefaults_(options);
+
opt_debug = opt_debug || false;
// If we're creating a webgl client, the assumption is we're using webgl,
@@ -216,18 +259,20 @@ o3djs.webgl.createClient = function(element, opt_features, opt_debug) {
return null;
}
- // This keeps the cursor from changing to an I-beam when the user clicks and
- // drags. It's easier on the eyes.
- function returnFalse() {
- return false;
+ if (!options.selectable) {
+ // This keeps the cursor from changing to an I-beam when the user clicks
+ // and drags. It's easier on the eyes.
+ function returnFalse() {
+ return false;
+ }
+ canvas.onselectstart = returnFalse;
+ canvas.onmousedown = returnFalse;
}
- document.onselectstart = returnFalse;
- document.onmousedown = returnFalse;
canvas.client = client;
canvas.o3d = o3d;
- if (opt_debug) {
+ if (options.debug) {
client.gl = o3djs.webgl.addDebuggingWrapper(client.gl);
}