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

Side by Side Diff: Source/devtools/front_end/ui/StatusBarButton.js

Issue 529553002: DevTools: [SSP] implement "add rule to end" of arbitrary style sheet. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: add long-click glyph Created 6 years, 3 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 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 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 * @extends {WebInspector.StatusBarItem} 234 * @extends {WebInspector.StatusBarItem}
235 * @param {string} title 235 * @param {string} title
236 * @param {string} className 236 * @param {string} className
237 * @param {number=} states 237 * @param {number=} states
238 */ 238 */
239 WebInspector.StatusBarButton = function(title, className, states) 239 WebInspector.StatusBarButton = function(title, className, states)
240 { 240 {
241 WebInspector.StatusBarItem.call(this, "button"); 241 WebInspector.StatusBarItem.call(this, "button");
242 this.element.className = className + " status-bar-item"; 242 this.element.className = className + " status-bar-item";
243 this.element.addEventListener("click", this._clicked.bind(this), false); 243 this.element.addEventListener("click", this._clicked.bind(this), false);
244 this._longClickController = new WebInspector.LongClickController(this.elemen t);
245 this._longClickController.addEventListener(WebInspector.LongClickController. Events.LongClick, this._onLongClick.bind(this));
246 this._longClickController.addEventListener(WebInspector.LongClickController. Events.LongPress, this._onLongPress.bind(this));
244 247
245 this.glyph = this.element.createChild("div", "glyph"); 248 this.glyph = this.element.createChild("div", "glyph");
246 this.glyphShadow = this.element.createChild("div", "glyph shadow"); 249 this.glyphShadow = this.element.createChild("div", "glyph shadow");
247 250
248 this.states = states; 251 this.states = states;
249 if (!states) 252 if (!states)
250 this.states = 2; 253 this.states = 2;
251 254
252 if (states == 2) 255 if (states == 2)
253 this._state = false; 256 this._state = false;
254 else 257 else
255 this._state = 0; 258 this._state = 0;
256 259
257 this.title = title; 260 this.title = title;
258 this.className = className; 261 this.className = className;
259 } 262 }
260 263
261 WebInspector.StatusBarButton.prototype = { 264 WebInspector.StatusBarButton.prototype = {
265 /**
266 * @param {!WebInspector.Event} event
267 */
268 _onLongClick: function(event)
269 {
270 this.dispatchEventToListeners("longClickDown");
271 },
272
273 /**
274 * @param {!WebInspector.Event} event
275 */
276 _onLongPress: function(event)
277 {
278 this.dispatchEventToListeners("longPressDown");
279 },
280
262 _clicked: function() 281 _clicked: function()
263 { 282 {
264 this.dispatchEventToListeners("click"); 283 this.dispatchEventToListeners("click");
265 if (this._longClickInterval) { 284 this._longClickController.reset();
266 clearInterval(this._longClickInterval);
267 delete this._longClickInterval;
268 }
269 }, 285 },
270 286
271 /** 287 /**
272 * @override 288 * @override
273 */ 289 */
274 applyEnabledState: function() 290 applyEnabledState: function()
275 { 291 {
276 this.element.disabled = !this._enabled; 292 this.element.disabled = !this._enabled;
277 if (this._longClickInterval) { 293 this._longClickController.reset();
278 clearInterval(this._longClickInterval);
279 delete this._longClickInterval;
280 }
281 }, 294 },
282 295
283 /** 296 /**
284 * @return {boolean} 297 * @return {boolean}
285 */ 298 */
286 enabled: function() 299 enabled: function()
287 { 300 {
288 return this._enabled; 301 return this._enabled;
289 }, 302 },
290 303
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 343
331 set toggled(x) 344 set toggled(x)
332 { 345 {
333 if (this.states !== 2) 346 if (this.states !== 2)
334 throw("Only used toggled when there are 2 states, otherwise, use sta te"); 347 throw("Only used toggled when there are 2 states, otherwise, use sta te");
335 this.state = x; 348 this.state = x;
336 }, 349 },
337 350
338 makeLongClickEnabled: function() 351 makeLongClickEnabled: function()
339 { 352 {
340 var boundMouseDown = mouseDown.bind(this); 353 this._longClickController.enable();
341 var boundMouseUp = mouseUp.bind(this);
342
343 this.element.addEventListener("mousedown", boundMouseDown, false);
344 this.element.addEventListener("mouseout", boundMouseUp, false);
345 this.element.addEventListener("mouseup", boundMouseUp, false);
346
347 var longClicks = 0;
348
349 this._longClickData = { mouseUp: boundMouseUp, mouseDown: boundMouseDown };
350
351 /**
352 * @param {!Event} e
353 * @this {WebInspector.StatusBarButton}
354 */
355 function mouseDown(e)
356 {
357 if (e.which !== 1)
358 return;
359 longClicks = 0;
360 this._longClickInterval = setInterval(longClicked.bind(this), 200);
361 }
362
363 /**
364 * @param {!Event} e
365 * @this {WebInspector.StatusBarButton}
366 */
367 function mouseUp(e)
368 {
369 if (e.which !== 1)
370 return;
371 if (this._longClickInterval) {
372 clearInterval(this._longClickInterval);
373 delete this._longClickInterval;
374 }
375 }
376
377 /**
378 * @this {WebInspector.StatusBarButton}
379 */
380 function longClicked()
381 {
382 ++longClicks;
383 this.dispatchEventToListeners(longClicks === 1 ? "longClickDown" : " longClickPress");
384 }
385 }, 354 },
386 355
387 unmakeLongClickEnabled: function() 356 unmakeLongClickEnabled: function()
388 { 357 {
389 if (!this._longClickData) 358 this._longClickController.disable();
390 return;
391 this.element.removeEventListener("mousedown", this._longClickData.mouseD own, false);
392 this.element.removeEventListener("mouseout", this._longClickData.mouseUp , false);
393 this.element.removeEventListener("mouseup", this._longClickData.mouseUp, false);
394 delete this._longClickData;
395 }, 359 },
396 360
397 /** 361 /**
398 * @param {?function():!Array.<!WebInspector.StatusBarButton>} buttonsProvid er 362 * @param {?function():!Array.<!WebInspector.StatusBarButton>} buttonsProvid er
399 */ 363 */
400 setLongClickOptionsEnabled: function(buttonsProvider) 364 setLongClickOptionsEnabled: function(buttonsProvider)
401 { 365 {
402 if (buttonsProvider) { 366 if (buttonsProvider) {
403 if (!this._longClickOptionsData) { 367 if (!this._longClickOptionsData) {
404 this.makeLongClickEnabled(); 368 this.makeLongClickEnabled();
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 var options = []; 711 var options = [];
748 for (var index = 0; index < this._states.length; index++) { 712 for (var index = 0; index < this._states.length; index++) {
749 if (this._states[index] !== this.state && this._states[index] !== th is._currentState) 713 if (this._states[index] !== this.state && this._states[index] !== th is._currentState)
750 options.push(this._buttons[index]); 714 options.push(this._buttons[index]);
751 } 715 }
752 return options; 716 return options;
753 }, 717 },
754 718
755 __proto__: WebInspector.StatusBarButton.prototype 719 __proto__: WebInspector.StatusBarButton.prototype
756 } 720 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698