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

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

Issue 546703003: Editing: Let Selection.collapse with null clears selection. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: add tests Created 6 years, 3 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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 190
191 int DOMSelection::rangeCount() const 191 int DOMSelection::rangeCount() const
192 { 192 {
193 if (!m_frame) 193 if (!m_frame)
194 return 0; 194 return 0;
195 return m_frame->selection().isNone() ? 0 : 1; 195 return m_frame->selection().isNone() ? 0 : 1;
196 } 196 }
197 197
198 void DOMSelection::collapse(Node* node, int offset, ExceptionState& exceptionSta te) 198 void DOMSelection::collapse(Node* node, int offset, ExceptionState& exceptionSta te)
199 { 199 {
200 ASSERT(node);
201 if (!m_frame) 200 if (!m_frame)
202 return; 201 return;
203 202
203 if (!node) {
204 m_frame->selection().clear();
205 return;
206 }
207
204 if (offset < 0) { 208 if (offset < 0) {
205 exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is not a valid offset."); 209 exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is not a valid offset.");
206 return; 210 return;
207 } 211 }
208 212
209 if (!isValidForPosition(node)) 213 if (!isValidForPosition(node))
210 return; 214 return;
211 RefPtrWillBeRawPtr<Range> range = Range::create(node->document()); 215 RefPtrWillBeRawPtr<Range> range = Range::create(node->document());
212 range->setStart(node, offset, exceptionState); 216 range->setStart(node, offset, exceptionState);
213 if (exceptionState.hadException()) 217 if (exceptionState.hadException())
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 return node->document() == m_frame->document(); 552 return node->document() == m_frame->document();
549 } 553 }
550 554
551 void DOMSelection::addConsoleError(const String& message) 555 void DOMSelection::addConsoleError(const String& message)
552 { 556 {
553 if (m_treeScope) 557 if (m_treeScope)
554 m_treeScope->document().addConsoleMessage(ConsoleMessage::create(JSMessa geSource, ErrorMessageLevel, message)); 558 m_treeScope->document().addConsoleMessage(ConsoleMessage::create(JSMessa geSource, ErrorMessageLevel, message));
555 } 559 }
556 560
557 } // namespace blink 561 } // namespace blink
OLDNEW
« no previous file with comments | « LayoutTests/editing/selection/collapse-null-expected.txt ('k') | Source/core/editing/Selection.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698