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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/ViewportControl.js

Issue 1879163003: DevTools: cleanup occurences of selection.getRangeAt to avoid NPE (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@selection-exception
Patch Set: Created 4 years, 8 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
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/ui/TextPrompt.js ('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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 node: node, 271 node: node,
272 offset: offset 272 offset: offset
273 }; 273 };
274 }, 274 },
275 275
276 /** 276 /**
277 * @param {?Selection} selection 277 * @param {?Selection} selection
278 */ 278 */
279 _updateSelectionModel: function(selection) 279 _updateSelectionModel: function(selection)
280 { 280 {
281 if (!selection || !selection.rangeCount || selection.isCollapsed) { 281 var range = selection && selection.rangeCount ? selection.getRangeAt(0) : null;
282 if (!range || selection.isCollapsed) {
282 this._headSelection = null; 283 this._headSelection = null;
283 this._anchorSelection = null; 284 this._anchorSelection = null;
284 return false; 285 return false;
285 } 286 }
286 287
287 var firstSelected = Number.MAX_VALUE; 288 var firstSelected = Number.MAX_VALUE;
288 var lastSelected = -1; 289 var lastSelected = -1;
289 290
290 var range = selection.getRangeAt(0);
291 var hasVisibleSelection = false; 291 var hasVisibleSelection = false;
292 for (var i = 0; i < this._renderedItems.length; ++i) { 292 for (var i = 0; i < this._renderedItems.length; ++i) {
293 if (range.intersectsNode(this._renderedItems[i].element())) { 293 if (range.intersectsNode(this._renderedItems[i].element())) {
294 var index = i + this._firstVisibleIndex; 294 var index = i + this._firstVisibleIndex;
295 firstSelected = Math.min(firstSelected, index); 295 firstSelected = Math.min(firstSelected, index);
296 lastSelected = Math.max(lastSelected, index); 296 lastSelected = Math.max(lastSelected, index);
297 hasVisibleSelection = true; 297 hasVisibleSelection = true;
298 } 298 }
299 } 299 }
300 if (hasVisibleSelection) { 300 if (hasVisibleSelection) {
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 637
638 /** 638 /**
639 * @return {number} 639 * @return {number}
640 */ 640 */
641 _visibleHeight: function() 641 _visibleHeight: function()
642 { 642 {
643 // Use offsetHeight instead of clientHeight to avoid being affected by h orizontal scroll. 643 // Use offsetHeight instead of clientHeight to avoid being affected by h orizontal scroll.
644 return this.element.offsetHeight; 644 return this.element.offsetHeight;
645 } 645 }
646 } 646 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/ui/TextPrompt.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698