1 /*
  2  * ***** BEGIN LICENSE BLOCK *****
  3  * Zimbra Collaboration Suite Web Client
  4  * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013, 2014, 2016 Synacor, Inc.
  5  *
  6  * The contents of this file are subject to the Common Public Attribution License Version 1.0 (the "License");
  7  * you may not use this file except in compliance with the License.
  8  * You may obtain a copy of the License at: https://www.zimbra.com/license
  9  * The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15
 10  * have been added to cover use of software over a computer network and provide for limited attribution
 11  * for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B.
 12  *
 13  * Software distributed under the License is distributed on an "AS IS" basis,
 14  * WITHOUT WARRANTY OF ANY KIND, either express or implied.
 15  * See the License for the specific language governing rights and limitations under the License.
 16  * The Original Code is Zimbra Open Source Web Client.
 17  * The Initial Developer of the Original Code is Zimbra, Inc.  All rights to the Original Code were
 18  * transferred by Zimbra, Inc. to Synacor, Inc. on September 14, 2015.
 19  *
 20  * All portions of the code are Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved.
 21  * ***** END LICENSE BLOCK *****
 22  */
 23 
 24 
 25 /**
 26  * 
 27  * @private
 28  */
 29 DwtMouseEvent = function() {
 30 	DwtUiEvent.call(this, true);
 31 	this.reset(true);
 32 };
 33 
 34 DwtMouseEvent.prototype = new DwtUiEvent;
 35 DwtMouseEvent.prototype.constructor = DwtMouseEvent;
 36 
 37 DwtMouseEvent.prototype.toString = 
 38 function() {
 39 	return "DwtMouseEvent";
 40 };
 41 
 42 DwtMouseEvent.NONE		= 0;
 43 DwtMouseEvent.LEFT 		= 1;
 44 DwtMouseEvent.MIDDLE	= 2;
 45 DwtMouseEvent.RIGHT		= 3;
 46 
 47 DwtMouseEvent.prototype.reset =
 48 function(dontCallParent) {
 49 	if (!dontCallParent) {
 50 		DwtUiEvent.prototype.reset.call(this);
 51 	}
 52 	this.button = 0;
 53 };
 54 
 55 DwtMouseEvent.prototype.setFromDhtmlEvent =
 56 function(ev, obj) {
 57 	ev = DwtUiEvent.prototype.setFromDhtmlEvent.apply(this, arguments);
 58 	if (!ev) { return; }
 59 
 60 	if (ev.which) { // Mozilla or Safari3
 61 		switch (ev.which) {
 62 			case 1:  this.button = DwtMouseEvent.LEFT; break;
 63 			case 2:  this.button = DwtMouseEvent.MIDDLE; break;
 64 			case 3:  this.button = DwtMouseEvent.RIGHT; break;
 65 			default: this.button = DwtMouseEvent.NONE;
 66 		}
 67 	} else if (ev.button) { // IE
 68 		if ((ev.button & 1) != 0) {
 69 			this.button = DwtMouseEvent.LEFT;
 70 		} else if ((ev.button & 2) != 0) {
 71 			this.button = DwtMouseEvent.RIGHT;
 72 		} else if ((ev.button & 4) != 0) {
 73 			this.button = DwtMouseEvent.MIDDLE;
 74 		} else {
 75 			this.button = DwtMouseEvent.NONE;
 76 		}
 77 	}
 78 
 79 	if (AjxEnv.isMac && this.button) {
 80 		// Mac only comes with one button, but can take a USB multibutton mouse. Single-button will translate
 81 		// CTRL-LEFT into RIGHT, but leave ctrlKey set to true. Convert that into vanilla RIGHT click. That
 82 		// means we can't distinguish a CTRL-RIGHT, but oh well.
 83 		if (this.ctrlKey && (this.button == DwtMouseEvent.LEFT || this.button == DwtMouseEvent.RIGHT)) {
 84 			this.button = DwtMouseEvent.RIGHT;
 85 			this.ctrlKey = false;
 86 		}
 87 		// allow alt-key to be used for ctrl-select
 88 		if (this.altKey) {
 89 			this.ctrlKey = true;
 90 			this.altKey = false;
 91 		}
 92 	}
 93 };
 94