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

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

Issue 2374183004: Make non-null VisibleSelections creatable only by createVisibleSelection[Deprecated] (Closed)
Patch Set: Fix mac compile error Created 4 years, 2 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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 if (offset < 0) { 221 if (offset < 0) {
222 exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is not a valid offset."); 222 exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is not a valid offset.");
223 return; 223 return;
224 } 224 }
225 225
226 if (!isValidForPosition(node)) 226 if (!isValidForPosition(node))
227 return; 227 return;
228 Range::checkNodeWOffset(node, offset, exceptionState); 228 Range::checkNodeWOffset(node, offset, exceptionState);
229 if (exceptionState.hadException()) 229 if (exceptionState.hadException())
230 return; 230 return;
231 frame()->selection().setSelection(VisibleSelection(Position(node, offset), f rame()->selection().isDirectional())); 231 frame()->selection().setSelection(createVisibleSelectionDeprecated(Position( node, offset), frame()->selection().isDirectional()));
232 } 232 }
233 233
234 void DOMSelection::collapseToEnd(ExceptionState& exceptionState) 234 void DOMSelection::collapseToEnd(ExceptionState& exceptionState)
235 { 235 {
236 if (!isAvailable()) 236 if (!isAvailable())
237 return; 237 return;
238 238
239 const VisibleSelection& selection = frame()->selection().selection(); 239 const VisibleSelection& selection = frame()->selection().selection();
240 240
241 if (selection.isNone()) { 241 if (selection.isNone()) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 285
286 if (!baseNode || !extentNode) 286 if (!baseNode || !extentNode)
287 UseCounter::count(frame(), UseCounter::SelectionSetBaseAndExtentNull); 287 UseCounter::count(frame(), UseCounter::SelectionSetBaseAndExtentNull);
288 288
289 if (!isValidForPosition(baseNode) || !isValidForPosition(extentNode)) 289 if (!isValidForPosition(baseNode) || !isValidForPosition(extentNode))
290 return; 290 return;
291 291
292 Position base = createPosition(baseNode, baseOffset); 292 Position base = createPosition(baseNode, baseOffset);
293 Position extent = createPosition(extentNode, extentOffset); 293 Position extent = createPosition(extentNode, extentOffset);
294 const bool selectionHasDirection = true; 294 const bool selectionHasDirection = true;
295 frame()->selection().setSelection(VisibleSelection(base, extent, SelDefaultA ffinity, selectionHasDirection)); 295 frame()->selection().setSelection(createVisibleSelectionDeprecated(base, ext ent, SelDefaultAffinity, selectionHasDirection));
296 } 296 }
297 297
298 void DOMSelection::modify(const String& alterString, const String& directionStri ng, const String& granularityString) 298 void DOMSelection::modify(const String& alterString, const String& directionStri ng, const String& granularityString)
299 { 299 {
300 if (!isAvailable()) 300 if (!isAvailable())
301 return; 301 return;
302 302
303 FrameSelection::EAlteration alter; 303 FrameSelection::EAlteration alter;
304 if (equalIgnoringCase(alterString, "extend")) 304 if (equalIgnoringCase(alterString, "extend"))
305 alter = FrameSelection::AlterationExtend; 305 alter = FrameSelection::AlterationExtend;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is larger than the given node's length."); 360 exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is larger than the given node's length.");
361 return; 361 return;
362 } 362 }
363 363
364 if (!isValidForPosition(node)) 364 if (!isValidForPosition(node))
365 return; 365 return;
366 366
367 const Position& base = frame()->selection().base(); 367 const Position& base = frame()->selection().base();
368 const Position& extent = createPosition(node, offset); 368 const Position& extent = createPosition(node, offset);
369 const bool selectionHasDirection = true; 369 const bool selectionHasDirection = true;
370 const VisibleSelection newSelection(base, extent, TextAffinity::Downstream, selectionHasDirection); 370 const VisibleSelection newSelection = createVisibleSelectionDeprecated(base, extent, TextAffinity::Downstream, selectionHasDirection);
371 frame()->selection().setSelection(newSelection); 371 frame()->selection().setSelection(newSelection);
372 } 372 }
373 373
374 Range* DOMSelection::getRangeAt(int index, ExceptionState& exceptionState) 374 Range* DOMSelection::getRangeAt(int index, ExceptionState& exceptionState)
375 { 375 {
376 if (!isAvailable()) 376 if (!isAvailable())
377 return nullptr; 377 return nullptr;
378 378
379 if (index < 0 || index >= rangeCount()) { 379 if (index < 0 || index >= rangeCount()) {
380 exceptionState.throwDOMException(IndexSizeError, String::number(index) + " is not a valid index."); 380 exceptionState.throwDOMException(IndexSizeError, String::number(index) + " is not a valid index.");
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 m_treeScope->document().addConsoleMessage(ConsoleMessage::create(JSMessa geSource, ErrorMessageLevel, message)); 588 m_treeScope->document().addConsoleMessage(ConsoleMessage::create(JSMessa geSource, ErrorMessageLevel, message));
589 } 589 }
590 590
591 DEFINE_TRACE(DOMSelection) 591 DEFINE_TRACE(DOMSelection)
592 { 592 {
593 visitor->trace(m_treeScope); 593 visitor->trace(m_treeScope);
594 DOMWindowProperty::trace(visitor); 594 DOMWindowProperty::trace(visitor);
595 } 595 }
596 596
597 } // namespace blink 597 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698