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

Side by Side Diff: third_party/WebKit/Source/core/editing/DOMSelection.cpp

Issue 1756763002: 2016-03-02T18:53:01 LayoutPosition Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-04-25T19:02:18 Created 4 years, 7 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) 2007, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 exceptionState.throwDOMException(IndexSizeError, String::number(extentOf fset) + " is not a valid extent offset."); 281 exceptionState.throwDOMException(IndexSizeError, String::number(extentOf fset) + " is not a valid extent offset.");
282 return; 282 return;
283 } 283 }
284 284
285 if (!baseNode || !extentNode) 285 if (!baseNode || !extentNode)
286 UseCounter::count(m_frame, UseCounter::SelectionSetBaseAndExtentNull); 286 UseCounter::count(m_frame, UseCounter::SelectionSetBaseAndExtentNull);
287 287
288 if (!isValidForPosition(baseNode) || !isValidForPosition(extentNode)) 288 if (!isValidForPosition(baseNode) || !isValidForPosition(extentNode))
289 return; 289 return;
290 290
291 // We check |DocumentTypeNode| here instead of |isValidForPosition()|,
292 // since, |collapse()| throws error for |DocumentTypeNode|, but
293 // |setBaseAndExtent()| doesn't.
294 if (baseNode && baseNode->isDocumentTypeNode())
295 return;
296 if (extentNode && extentNode->isDocumentTypeNode())
297 return;
298
291 VisiblePosition visibleBase = createVisiblePosition(createPosition(baseNode, baseOffset)); 299 VisiblePosition visibleBase = createVisiblePosition(createPosition(baseNode, baseOffset));
292 VisiblePosition visibleExtent = createVisiblePosition(createPosition(extentN ode, extentOffset)); 300 VisiblePosition visibleExtent = createVisiblePosition(createPosition(extentN ode, extentOffset));
293 301
294 m_frame->selection().moveTo(visibleBase, visibleExtent); 302 m_frame->selection().moveTo(visibleBase, visibleExtent);
295 } 303 }
296 304
297 void DOMSelection::modify(const String& alterString, const String& directionStri ng, const String& granularityString) 305 void DOMSelection::modify(const String& alterString, const String& directionStri ng, const String& granularityString)
298 { 306 {
299 if (!m_frame) 307 if (!m_frame)
300 return; 308 return;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 return; 364 return;
357 } 365 }
358 if (static_cast<unsigned>(offset) > node->lengthOfContents()) { 366 if (static_cast<unsigned>(offset) > node->lengthOfContents()) {
359 exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is larger than the given node's length."); 367 exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is larger than the given node's length.");
360 return; 368 return;
361 } 369 }
362 370
363 if (!isValidForPosition(node)) 371 if (!isValidForPosition(node))
364 return; 372 return;
365 373
374 // We check |DocumentTypeNode| here instead of |isValidForPosition()|,
375 // since, |collapse()| throws error for |DocumentTypeNode|, but
376 // |setBaseAndExtent()| doesn't.
377 if (node && node->isDocumentTypeNode())
378 return;
379
366 m_frame->selection().setExtent(createVisiblePosition(createPosition(node, of fset))); 380 m_frame->selection().setExtent(createVisiblePosition(createPosition(node, of fset)));
367 } 381 }
368 382
369 Range* DOMSelection::getRangeAt(int index, ExceptionState& exceptionState) 383 Range* DOMSelection::getRangeAt(int index, ExceptionState& exceptionState)
370 { 384 {
371 if (!m_frame) 385 if (!m_frame)
372 return nullptr; 386 return nullptr;
373 387
374 if (index < 0 || index >= rangeCount()) { 388 if (index < 0 || index >= rangeCount()) {
375 exceptionState.throwDOMException(IndexSizeError, String::number(index) + " is not a valid index."); 389 exceptionState.throwDOMException(IndexSizeError, String::number(index) + " is not a valid index.");
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 m_treeScope->document().addConsoleMessage(ConsoleMessage::create(JSMessa geSource, ErrorMessageLevel, message)); 583 m_treeScope->document().addConsoleMessage(ConsoleMessage::create(JSMessa geSource, ErrorMessageLevel, message));
570 } 584 }
571 585
572 DEFINE_TRACE(DOMSelection) 586 DEFINE_TRACE(DOMSelection)
573 { 587 {
574 visitor->trace(m_treeScope); 588 visitor->trace(m_treeScope);
575 DOMWindowProperty::trace(visitor); 589 DOMWindowProperty::trace(visitor);
576 } 590 }
577 591
578 } // namespace blink 592 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/Node.cpp ('k') | third_party/WebKit/Source/core/editing/Editor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698