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

Side by Side Diff: chrome/browser/resources/options/options_page.js

Issue 6277005: Fix subsheet RTL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: click handling Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('options', function() { 5 cr.define('options', function() {
6 ///////////////////////////////////////////////////////////////////////////// 6 /////////////////////////////////////////////////////////////////////////////
7 // OptionsPage class: 7 // OptionsPage class:
8 8
9 /** 9 /**
10 * Base class for options page. 10 * Base class for options page.
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 OptionsPage.initialize = function() { 312 OptionsPage.initialize = function() {
313 chrome.send('coreOptionsInitialize'); 313 chrome.send('coreOptionsInitialize');
314 this.initialized_ = true; 314 this.initialized_ = true;
315 315
316 // Set up the overlay sheets: 316 // Set up the overlay sheets:
317 // Close nested sub-pages when clicking the visible part of an earlier page. 317 // Close nested sub-pages when clicking the visible part of an earlier page.
318 for (var level = 1; level <= 2; level++) { 318 for (var level = 1; level <= 2; level++) {
319 var containerId = 'subpage-sheet-container-' + level; 319 var containerId = 'subpage-sheet-container-' + level;
320 $(containerId).onclick = this.subPageClosingClickHandler_(level); 320 $(containerId).onclick = this.subPageClosingClickHandler_(level);
321 } 321 }
322
323 var self = this;
324 // Close subpages if the user clicks on the html body. Listen in the
325 // capturing phase so that we can stop the click from doing anything.
326 document.body.addEventListener('click', this.bodyMouseEventHandler_(),
arv (Not doing code reviews) 2011/01/18 19:06:07 Use bind instead?
Evan Stade 2011/01/18 22:37:09 Done.
327 true);
328 // We also need to cancel mousedowns on non-subpage content.
329 document.body.addEventListener('mousedown', this.bodyMouseEventHandler_(),
330 true);
331
322 // Hook up the close buttons. 332 // Hook up the close buttons.
323 var self = this;
324 subpageCloseButtons = document.querySelectorAll('.close-subpage'); 333 subpageCloseButtons = document.querySelectorAll('.close-subpage');
325 for (var i = 0; i < subpageCloseButtons.length; i++) { 334 for (var i = 0; i < subpageCloseButtons.length; i++) {
326 subpageCloseButtons[i].onclick = function() { 335 subpageCloseButtons[i].onclick = function() {
327 self.closeTopSubPage(); 336 self.closeTopSubPage();
328 }; 337 };
329 } 338 };
330 339
331 // Close the top overlay or sub-page on esc. 340 // Close the top overlay or sub-page on esc.
332 document.addEventListener('keydown', function(e) { 341 document.addEventListener('keydown', function(e) {
333 if (e.keyCode == 27) { // Esc 342 if (e.keyCode == 27) { // Esc
334 if (self.isOverlayVisible_()) 343 if (self.isOverlayVisible_())
335 self.clearOverlays(); 344 self.clearOverlays();
336 else 345 else
337 self.closeTopSubPage(); 346 self.closeTopSubPage();
338 } 347 }
339 }); 348 });
340 }; 349 };
341 350
342 /** 351 /**
343 * Returns a function to handle clicks behind a subpage at level |level| by 352 * Returns a function to handle clicks behind a subpage at level |level| by
344 * closing all subpages down to |level| - 1. 353 * closing all subpages down to |level| - 1.
345 * @param {number} level The level of the subpage being handled. 354 * @param {number} level The level of the subpage being handled.
346 * @return {function} a function to handle clicks outside the given subpage. 355 * @return {function} a function to handle clicks outside the given subpage.
347 * @private 356 * @private
348 */ 357 */
349 OptionsPage.subPageClosingClickHandler_ = function(level) { 358 OptionsPage.subPageClosingClickHandler_ = function(level) {
350 var self = this; 359 var self = this;
351 return function(event) { 360 return function(event) {
352 // Clicks on the visible part of the parent page should close the overlay, 361 // Clicks on the narrow strip between the left of the subpage sheet and
362 // that shows part of the parent page should close the overlay, but
353 // not fall through to the parent page. 363 // not fall through to the parent page.
354 if (!$('subpage-sheet-' + level).contains(event.target)) 364 if (!$('subpage-sheet-' + level).contains(event.target))
355 self.closeSubPagesToLevel(level - 1); 365 self.closeSubPagesToLevel(level - 1);
356 event.stopPropagation(); 366 event.stopPropagation();
367 event.preventDefault();
357 }; 368 };
358 }; 369 };
359 370
371 /**
372 * Returns a function to handle mouse events (mousedown or click) on the html
373 * body by closing subpages and/or stopping event propagation.
374 * @return {function} a function to handle mouse events while a subpage is
arv (Not doing code reviews) 2011/01/18 19:06:07 {Function} only value types are lower case
Evan Stade 2011/01/18 22:37:09 Done.
375 * showing.
376 * @private
377 */
378 OptionsPage.bodyMouseEventHandler_ = function() {
379 var self = this;
380 return function(event) {
381 // Do nothing if a subpage isn't showing.
382 var topPage = self.getTopmostVisiblePage();
383 if (!(topPage && topPage.parentPage))
384 return;
385
386 // If the click was within a subpage, do nothing.
387 for (var level = 1; level <= 2; level++) {
388 if ($('subpage-sheet-container-' + level).contains(event.target))
389 return;
390 }
391
392 // Close all subpages on click.
393 if (event.type == 'click')
394 self.closeSubPagesToLevel(0);
395
396 // Events should not fall through to the main view,
397 // but they can fall through for the sidebar.
398 if ($('mainview-content').contains(event.target)) {
399 event.stopPropagation();
400 event.preventDefault();
401 }
402 };
403 };
404
360 /** 405 /**
361 * Re-initializes the C++ handlers if necessary. This is called if the 406 * Re-initializes the C++ handlers if necessary. This is called if the
362 * handlers are torn down and recreated but the DOM may not have been (in 407 * handlers are torn down and recreated but the DOM may not have been (in
363 * which case |initialize| won't be called again). If |initialize| hasn't been 408 * which case |initialize| won't be called again). If |initialize| hasn't been
364 * called, this does nothing (since it will be later, once the DOM has 409 * called, this does nothing (since it will be later, once the DOM has
365 * finished loading). 410 * finished loading).
366 */ 411 */
367 OptionsPage.reinitializeCore = function() { 412 OptionsPage.reinitializeCore = function() {
368 if (this.initialized_) 413 if (this.initialized_)
369 chrome.send('coreOptionsInitialize'); 414 chrome.send('coreOptionsInitialize');
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 OptionsPage.showOverlay(hash); 572 OptionsPage.showOverlay(hash);
528 }, 573 },
529 }; 574 };
530 575
531 // Export 576 // Export
532 return { 577 return {
533 OptionsPage: OptionsPage 578 OptionsPage: OptionsPage
534 }; 579 };
535 580
536 }); 581 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698