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

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: smorgan fix 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
« no previous file with comments | « chrome/browser/resources/options/options_page.css ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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',
327 this.bodyMouseEventHandler_.bind(this),
328 true);
329 // We also need to cancel mousedowns on non-subpage content.
330 document.body.addEventListener('mousedown',
331 this.bodyMouseEventHandler_.bind(this),
332 true);
333
322 // Hook up the close buttons. 334 // Hook up the close buttons.
323 var self = this;
324 subpageCloseButtons = document.querySelectorAll('.close-subpage'); 335 subpageCloseButtons = document.querySelectorAll('.close-subpage');
325 for (var i = 0; i < subpageCloseButtons.length; i++) { 336 for (var i = 0; i < subpageCloseButtons.length; i++) {
326 subpageCloseButtons[i].onclick = function() { 337 subpageCloseButtons[i].onclick = function() {
327 self.closeTopSubPage(); 338 self.closeTopSubPage();
328 }; 339 };
329 } 340 };
330 341
331 // Close the top overlay or sub-page on esc. 342 // Close the top overlay or sub-page on esc.
332 document.addEventListener('keydown', function(e) { 343 document.addEventListener('keydown', function(e) {
333 if (e.keyCode == 27) { // Esc 344 if (e.keyCode == 27) { // Esc
334 if (self.isOverlayVisible_()) 345 if (self.isOverlayVisible_())
335 self.clearOverlays(); 346 self.clearOverlays();
336 else 347 else
337 self.closeTopSubPage(); 348 self.closeTopSubPage();
338 } 349 }
339 }); 350 });
340 }; 351 };
341 352
342 /** 353 /**
343 * Returns a function to handle clicks behind a subpage at level |level| by 354 * Returns a function to handle clicks behind a subpage at level |level| by
344 * closing all subpages down to |level| - 1. 355 * closing all subpages down to |level| - 1.
345 * @param {number} level The level of the subpage being handled. 356 * @param {number} level The level of the subpage being handled.
346 * @return {function} a function to handle clicks outside the given subpage. 357 * @return {Function} a function to handle clicks outside the given subpage.
347 * @private 358 * @private
348 */ 359 */
349 OptionsPage.subPageClosingClickHandler_ = function(level) { 360 OptionsPage.subPageClosingClickHandler_ = function(level) {
350 var self = this; 361 var self = this;
351 return function(event) { 362 return function(event) {
352 // Clicks on the visible part of the parent page should close the overlay, 363 // Clicks on the narrow strip between the left of the subpage sheet and
364 // that shows part of the parent page should close the overlay, but
353 // not fall through to the parent page. 365 // not fall through to the parent page.
354 if (!$('subpage-sheet-' + level).contains(event.target)) 366 if (!$('subpage-sheet-' + level).contains(event.target))
355 self.closeSubPagesToLevel(level - 1); 367 self.closeSubPagesToLevel(level - 1);
356 event.stopPropagation(); 368 event.stopPropagation();
369 event.preventDefault();
357 }; 370 };
358 }; 371 };
359 372
360 /** 373 /**
374 * A function to handle mouse events (mousedown or click) on the html body by
375 * closing subpages and/or stopping event propagation.
376 * @return {Event} a mousedown or click event.
377 * @private
378 */
379 OptionsPage.bodyMouseEventHandler_ = function(event) {
380 // Do nothing if a subpage isn't showing.
381 var topPage = this.getTopmostVisiblePage();
382 if (!(topPage && topPage.parentPage))
383 return;
384
385 // If the click was within a subpage, do nothing.
386 for (var level = 1; level <= 2; level++) {
387 if ($('subpage-sheet-container-' + level).contains(event.target))
388 return;
389 }
390
391 // Close all subpages on click.
392 if (event.type == 'click')
393 this.closeSubPagesToLevel(0);
394
395 // Events should not fall through to the main view,
396 // but they can fall through for the sidebar.
397 if ($('mainview-content').contains(event.target)) {
398 event.stopPropagation();
399 event.preventDefault();
400 }
401 };
402
403 /**
361 * Re-initializes the C++ handlers if necessary. This is called if the 404 * 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 405 * 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 406 * 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 407 * called, this does nothing (since it will be later, once the DOM has
365 * finished loading). 408 * finished loading).
366 */ 409 */
367 OptionsPage.reinitializeCore = function() { 410 OptionsPage.reinitializeCore = function() {
368 if (this.initialized_) 411 if (this.initialized_)
369 chrome.send('coreOptionsInitialize'); 412 chrome.send('coreOptionsInitialize');
370 } 413 }
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 OptionsPage.showOverlay(hash); 570 OptionsPage.showOverlay(hash);
528 }, 571 },
529 }; 572 };
530 573
531 // Export 574 // Export
532 return { 575 return {
533 OptionsPage: OptionsPage 576 OptionsPage: OptionsPage
534 }; 577 };
535 578
536 }); 579 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/options_page.css ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698