| OLD | NEW |
| 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 25 matching lines...) Expand all Loading... |
| 36 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 36 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 37 #include "core/dom/Document.h" | 37 #include "core/dom/Document.h" |
| 38 #include "core/dom/ExceptionCode.h" | 38 #include "core/dom/ExceptionCode.h" |
| 39 #include "core/dom/Node.h" | 39 #include "core/dom/Node.h" |
| 40 #include "core/dom/Range.h" | 40 #include "core/dom/Range.h" |
| 41 #include "core/dom/TreeScope.h" | 41 #include "core/dom/TreeScope.h" |
| 42 #include "core/editing/EditingUtilities.h" | 42 #include "core/editing/EditingUtilities.h" |
| 43 #include "core/editing/FrameSelection.h" | 43 #include "core/editing/FrameSelection.h" |
| 44 #include "core/editing/iterators/TextIterator.h" | 44 #include "core/editing/iterators/TextIterator.h" |
| 45 #include "core/frame/LocalFrame.h" | 45 #include "core/frame/LocalFrame.h" |
| 46 #include "core/frame/UseCounter.h" |
| 46 #include "core/inspector/ConsoleMessage.h" | 47 #include "core/inspector/ConsoleMessage.h" |
| 47 #include "wtf/text/WTFString.h" | 48 #include "wtf/text/WTFString.h" |
| 48 | 49 |
| 49 namespace blink { | 50 namespace blink { |
| 50 | 51 |
| 51 static Position createPosition(Node* node, int offset) | 52 static Position createPosition(Node* node, int offset) |
| 52 { | 53 { |
| 53 ASSERT(offset >= 0); | 54 ASSERT(offset >= 0); |
| 54 if (!node) | 55 if (!node) |
| 55 return Position(); | 56 return Position(); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 return 0; | 202 return 0; |
| 202 return m_frame->selection().isNone() ? 0 : 1; | 203 return m_frame->selection().isNone() ? 0 : 1; |
| 203 } | 204 } |
| 204 | 205 |
| 205 void DOMSelection::collapse(Node* node, int offset, ExceptionState& exceptionSta
te) | 206 void DOMSelection::collapse(Node* node, int offset, ExceptionState& exceptionSta
te) |
| 206 { | 207 { |
| 207 if (!m_frame) | 208 if (!m_frame) |
| 208 return; | 209 return; |
| 209 | 210 |
| 210 if (!node) { | 211 if (!node) { |
| 212 UseCounter::count(m_frame, UseCounter::SelectionCollapseNull); |
| 211 m_frame->selection().clear(); | 213 m_frame->selection().clear(); |
| 212 return; | 214 return; |
| 213 } | 215 } |
| 214 | 216 |
| 215 if (offset < 0) { | 217 if (offset < 0) { |
| 216 exceptionState.throwDOMException(IndexSizeError, String::number(offset)
+ " is not a valid offset."); | 218 exceptionState.throwDOMException(IndexSizeError, String::number(offset)
+ " is not a valid offset."); |
| 217 return; | 219 return; |
| 218 } | 220 } |
| 219 | 221 |
| 220 if (!isValidForPosition(node)) | 222 if (!isValidForPosition(node)) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 if (baseOffset < 0) { | 276 if (baseOffset < 0) { |
| 275 exceptionState.throwDOMException(IndexSizeError, String::number(baseOffs
et) + " is not a valid base offset."); | 277 exceptionState.throwDOMException(IndexSizeError, String::number(baseOffs
et) + " is not a valid base offset."); |
| 276 return; | 278 return; |
| 277 } | 279 } |
| 278 | 280 |
| 279 if (extentOffset < 0) { | 281 if (extentOffset < 0) { |
| 280 exceptionState.throwDOMException(IndexSizeError, String::number(extentOf
fset) + " is not a valid extent offset."); | 282 exceptionState.throwDOMException(IndexSizeError, String::number(extentOf
fset) + " is not a valid extent offset."); |
| 281 return; | 283 return; |
| 282 } | 284 } |
| 283 | 285 |
| 286 if (!baseNode || !extentNode) |
| 287 UseCounter::count(m_frame, UseCounter::SelectionSetBaseAndExtentNull); |
| 288 |
| 284 if (!isValidForPosition(baseNode) || !isValidForPosition(extentNode)) | 289 if (!isValidForPosition(baseNode) || !isValidForPosition(extentNode)) |
| 285 return; | 290 return; |
| 286 | 291 |
| 287 VisiblePosition visibleBase = createVisiblePosition(createPosition(baseNode,
baseOffset)); | 292 VisiblePosition visibleBase = createVisiblePosition(createPosition(baseNode,
baseOffset)); |
| 288 VisiblePosition visibleExtent = createVisiblePosition(createPosition(extentN
ode, extentOffset)); | 293 VisiblePosition visibleExtent = createVisiblePosition(createPosition(extentN
ode, extentOffset)); |
| 289 | 294 |
| 290 m_frame->selection().moveTo(visibleBase, visibleExtent); | 295 m_frame->selection().moveTo(visibleBase, visibleExtent); |
| 291 } | 296 } |
| 292 | 297 |
| 293 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) |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 m_treeScope->document().addConsoleMessage(ConsoleMessage::create(JSMessa
geSource, ErrorMessageLevel, message)); | 567 m_treeScope->document().addConsoleMessage(ConsoleMessage::create(JSMessa
geSource, ErrorMessageLevel, message)); |
| 563 } | 568 } |
| 564 | 569 |
| 565 DEFINE_TRACE(DOMSelection) | 570 DEFINE_TRACE(DOMSelection) |
| 566 { | 571 { |
| 567 visitor->trace(m_treeScope); | 572 visitor->trace(m_treeScope); |
| 568 DOMWindowProperty::trace(visitor); | 573 DOMWindowProperty::trace(visitor); |
| 569 } | 574 } |
| 570 | 575 |
| 571 } // namespace blink | 576 } // namespace blink |
| OLD | NEW |