Chromium Code Reviews| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 } | 100 } |
| 101 | 101 |
| 102 Node* DOMSelection::anchorNode() const | 102 Node* DOMSelection::anchorNode() const |
| 103 { | 103 { |
| 104 if (!m_frame) | 104 if (!m_frame) |
| 105 return 0; | 105 return 0; |
| 106 | 106 |
| 107 return shadowAdjustedNode(anchorPosition(visibleSelection())); | 107 return shadowAdjustedNode(anchorPosition(visibleSelection())); |
| 108 } | 108 } |
| 109 | 109 |
| 110 int DOMSelection::anchorOffset() const | 110 unsigned DOMSelection::anchorOffset() const |
| 111 { | 111 { |
| 112 if (!m_frame) | 112 if (!m_frame) |
| 113 return 0; | 113 return 0; |
| 114 | 114 |
| 115 return shadowAdjustedOffset(anchorPosition(visibleSelection())); | 115 return shadowAdjustedOffset(anchorPosition(visibleSelection())); |
| 116 } | 116 } |
| 117 | 117 |
| 118 Node* DOMSelection::focusNode() const | 118 Node* DOMSelection::focusNode() const |
| 119 { | 119 { |
| 120 if (!m_frame) | 120 if (!m_frame) |
| 121 return 0; | 121 return 0; |
| 122 | 122 |
| 123 return shadowAdjustedNode(focusPosition(visibleSelection())); | 123 return shadowAdjustedNode(focusPosition(visibleSelection())); |
| 124 } | 124 } |
| 125 | 125 |
| 126 int DOMSelection::focusOffset() const | 126 unsigned DOMSelection::focusOffset() const |
| 127 { | 127 { |
| 128 if (!m_frame) | 128 if (!m_frame) |
| 129 return 0; | 129 return 0; |
| 130 | 130 |
| 131 return shadowAdjustedOffset(focusPosition(visibleSelection())); | 131 return shadowAdjustedOffset(focusPosition(visibleSelection())); |
| 132 } | 132 } |
| 133 | 133 |
| 134 Node* DOMSelection::baseNode() const | 134 Node* DOMSelection::baseNode() const |
| 135 { | 135 { |
| 136 if (!m_frame) | 136 if (!m_frame) |
| 137 return 0; | 137 return 0; |
| 138 | 138 |
| 139 return shadowAdjustedNode(basePosition(visibleSelection())); | 139 return shadowAdjustedNode(basePosition(visibleSelection())); |
| 140 } | 140 } |
| 141 | 141 |
| 142 int DOMSelection::baseOffset() const | 142 unsigned DOMSelection::baseOffset() const |
| 143 { | 143 { |
| 144 if (!m_frame) | 144 if (!m_frame) |
| 145 return 0; | 145 return 0; |
| 146 | 146 |
| 147 return shadowAdjustedOffset(basePosition(visibleSelection())); | 147 return shadowAdjustedOffset(basePosition(visibleSelection())); |
| 148 } | 148 } |
| 149 | 149 |
| 150 Node* DOMSelection::extentNode() const | 150 Node* DOMSelection::extentNode() const |
| 151 { | 151 { |
| 152 if (!m_frame) | 152 if (!m_frame) |
| 153 return 0; | 153 return 0; |
| 154 | 154 |
| 155 return shadowAdjustedNode(extentPosition(visibleSelection())); | 155 return shadowAdjustedNode(extentPosition(visibleSelection())); |
| 156 } | 156 } |
| 157 | 157 |
| 158 int DOMSelection::extentOffset() const | 158 unsigned DOMSelection::extentOffset() const |
| 159 { | 159 { |
| 160 if (!m_frame) | 160 if (!m_frame) |
| 161 return 0; | 161 return 0; |
| 162 | 162 |
| 163 return shadowAdjustedOffset(extentPosition(visibleSelection())); | 163 return shadowAdjustedOffset(extentPosition(visibleSelection())); |
| 164 } | 164 } |
| 165 | 165 |
| 166 bool DOMSelection::isCollapsed() const | 166 bool DOMSelection::isCollapsed() const |
| 167 { | 167 { |
| 168 if (!m_frame || selectionShadowAncestor(m_frame)) | 168 if (!m_frame || selectionShadowAncestor(m_frame)) |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 180 // This is a WebKit DOM extension, incompatible with an IE extension | 180 // This is a WebKit DOM extension, incompatible with an IE extension |
| 181 // IE has this same attribute, but returns "none", "text" and "control" | 181 // IE has this same attribute, but returns "none", "text" and "control" |
| 182 // http://msdn.microsoft.com/en-us/library/ms534692(VS.85).aspx | 182 // http://msdn.microsoft.com/en-us/library/ms534692(VS.85).aspx |
| 183 if (selection.isNone()) | 183 if (selection.isNone()) |
| 184 return "None"; | 184 return "None"; |
| 185 if (selection.isCaret()) | 185 if (selection.isCaret()) |
| 186 return "Caret"; | 186 return "Caret"; |
| 187 return "Range"; | 187 return "Range"; |
| 188 } | 188 } |
| 189 | 189 |
| 190 int DOMSelection::rangeCount() const | 190 unsigned DOMSelection::rangeCount() const |
| 191 { | 191 { |
| 192 if (!m_frame) | 192 if (!m_frame) |
| 193 return 0; | 193 return 0; |
| 194 return m_frame->selection().isNone() ? 0 : 1; | 194 return m_frame->selection().isNone() ? 0 : 1; |
| 195 } | 195 } |
| 196 | 196 |
| 197 void DOMSelection::collapse(Node* node, int offset, ExceptionState& exceptionSta te) | 197 void DOMSelection::collapse(Node* node, unsigned offset, ExceptionState& excepti onState) |
| 198 { | 198 { |
| 199 if (!m_frame) | 199 if (!m_frame) |
| 200 return; | 200 return; |
| 201 | 201 |
| 202 if (!node) { | 202 if (!node) { |
| 203 m_frame->selection().clear(); | 203 m_frame->selection().clear(); |
| 204 return; | 204 return; |
| 205 } | 205 } |
| 206 | 206 |
| 207 if (offset < 0) { | 207 if (static_cast<int>(offset) < 0) { |
|
philipj_slow
2015/08/10 13:46:40
This is really quite strange, and is strange in th
| |
| 208 exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is not a valid offset."); | 208 exceptionState.throwDOMException(IndexSizeError, String::number(static_c ast<int>(offset)) + " is not a valid offset."); |
| 209 return; | 209 return; |
| 210 } | 210 } |
| 211 | 211 |
| 212 if (!isValidForPosition(node)) | 212 if (!isValidForPosition(node)) |
| 213 return; | 213 return; |
| 214 RefPtrWillBeRawPtr<Range> range = Range::create(node->document()); | 214 RefPtrWillBeRawPtr<Range> range = Range::create(node->document()); |
| 215 range->setStart(node, offset, exceptionState); | 215 range->setStart(node, offset, exceptionState); |
| 216 if (exceptionState.hadException()) | 216 if (exceptionState.hadException()) |
| 217 return; | 217 return; |
| 218 range->setEnd(node, offset, exceptionState); | 218 range->setEnd(node, offset, exceptionState); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 m_frame->selection().moveTo(VisiblePosition(selection.start(), DOWNSTREAM)); | 251 m_frame->selection().moveTo(VisiblePosition(selection.start(), DOWNSTREAM)); |
| 252 } | 252 } |
| 253 | 253 |
| 254 void DOMSelection::empty() | 254 void DOMSelection::empty() |
| 255 { | 255 { |
| 256 if (!m_frame) | 256 if (!m_frame) |
| 257 return; | 257 return; |
| 258 m_frame->selection().clear(); | 258 m_frame->selection().clear(); |
| 259 } | 259 } |
| 260 | 260 |
| 261 void DOMSelection::setBaseAndExtent(Node* baseNode, int baseOffset, Node* extent Node, int extentOffset, ExceptionState& exceptionState) | 261 void DOMSelection::setBaseAndExtent(Node* baseNode, unsigned baseOffset, Node* e xtentNode, unsigned extentOffset, ExceptionState& exceptionState) |
| 262 { | 262 { |
| 263 if (!m_frame) | 263 if (!m_frame) |
| 264 return; | 264 return; |
| 265 | 265 |
| 266 if (baseOffset < 0) { | 266 if (static_cast<int>(baseOffset) < 0) { |
| 267 exceptionState.throwDOMException(IndexSizeError, String::number(baseOffs et) + " is not a valid base offset."); | 267 exceptionState.throwDOMException(IndexSizeError, String::number(static_c ast<int>(baseOffset)) + " is not a valid base offset."); |
| 268 return; | 268 return; |
| 269 } | 269 } |
| 270 | 270 |
| 271 if (extentOffset < 0) { | 271 if (static_cast<int>(extentOffset) < 0) { |
| 272 exceptionState.throwDOMException(IndexSizeError, String::number(extentOf fset) + " is not a valid extent offset."); | 272 exceptionState.throwDOMException(IndexSizeError, String::number(static_c ast<int>(extentOffset)) + " is not a valid extent offset."); |
| 273 return; | 273 return; |
| 274 } | 274 } |
| 275 | 275 |
| 276 if (!isValidForPosition(baseNode) || !isValidForPosition(extentNode)) | 276 if (!isValidForPosition(baseNode) || !isValidForPosition(extentNode)) |
| 277 return; | 277 return; |
| 278 | 278 |
| 279 VisiblePosition visibleBase = VisiblePosition(Position(baseNode, baseOffset) , DOWNSTREAM); | 279 VisiblePosition visibleBase = VisiblePosition(Position(baseNode, baseOffset) , DOWNSTREAM); |
| 280 VisiblePosition visibleExtent = VisiblePosition(Position(extentNode, extentO ffset), DOWNSTREAM); | 280 VisiblePosition visibleExtent = VisiblePosition(Position(extentNode, extentO ffset), DOWNSTREAM); |
| 281 | 281 |
| 282 m_frame->selection().moveTo(visibleBase, visibleExtent); | 282 m_frame->selection().moveTo(visibleBase, visibleExtent); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 else if (equalIgnoringCase(granularityString, "paragraphboundary")) | 325 else if (equalIgnoringCase(granularityString, "paragraphboundary")) |
| 326 granularity = ParagraphBoundary; | 326 granularity = ParagraphBoundary; |
| 327 else if (equalIgnoringCase(granularityString, "documentboundary")) | 327 else if (equalIgnoringCase(granularityString, "documentboundary")) |
| 328 granularity = DocumentBoundary; | 328 granularity = DocumentBoundary; |
| 329 else | 329 else |
| 330 return; | 330 return; |
| 331 | 331 |
| 332 m_frame->selection().modify(alter, direction, granularity); | 332 m_frame->selection().modify(alter, direction, granularity); |
| 333 } | 333 } |
| 334 | 334 |
| 335 void DOMSelection::extend(Node* node, int offset, ExceptionState& exceptionState ) | 335 void DOMSelection::extend(Node* node, unsigned offset, ExceptionState& exception State) |
| 336 { | 336 { |
| 337 ASSERT(node); | 337 ASSERT(node); |
| 338 | 338 |
| 339 if (!m_frame) | 339 if (!m_frame) |
| 340 return; | 340 return; |
| 341 | 341 |
| 342 if (offset < 0) { | 342 if (static_cast<int>(offset) < 0) { |
| 343 exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is not a valid offset."); | 343 exceptionState.throwDOMException(IndexSizeError, String::number(static_c ast<int>(offset)) + " is not a valid offset."); |
| 344 return; | 344 return; |
| 345 } | 345 } |
| 346 if (static_cast<unsigned>(offset) > node->lengthOfContents()) { | 346 if (offset > node->lengthOfContents()) { |
| 347 exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is larger than the given node's length."); | 347 exceptionState.throwDOMException(IndexSizeError, String::number(offset) + " is larger than the given node's length."); |
| 348 return; | 348 return; |
| 349 } | 349 } |
| 350 | 350 |
| 351 if (!isValidForPosition(node)) | 351 if (!isValidForPosition(node)) |
| 352 return; | 352 return; |
| 353 | 353 |
| 354 m_frame->selection().setExtent(VisiblePosition(Position(node, offset), DOWNS TREAM)); | 354 m_frame->selection().setExtent(VisiblePosition(Position(node, offset), DOWNS TREAM)); |
| 355 } | 355 } |
| 356 | 356 |
| 357 PassRefPtrWillBeRawPtr<Range> DOMSelection::getRangeAt(int index, ExceptionState & exceptionState) | 357 PassRefPtrWillBeRawPtr<Range> DOMSelection::getRangeAt(unsigned index, Exception State& exceptionState) |
| 358 { | 358 { |
| 359 if (!m_frame) | 359 if (!m_frame) |
| 360 return nullptr; | 360 return nullptr; |
| 361 | 361 |
| 362 if (index < 0 || index >= rangeCount()) { | 362 if (static_cast<int>(index) < 0 || index >= rangeCount()) { |
| 363 exceptionState.throwDOMException(IndexSizeError, String::number(index) + " is not a valid index."); | 363 exceptionState.throwDOMException(IndexSizeError, String::number(static_c ast<int>(index)) + " is not a valid index."); |
| 364 return nullptr; | 364 return nullptr; |
| 365 } | 365 } |
| 366 | 366 |
| 367 // If you're hitting this, you've added broken multi-range selection support | 367 // If you're hitting this, you've added broken multi-range selection support |
| 368 ASSERT(rangeCount() == 1); | 368 ASSERT(rangeCount() == 1); |
| 369 | 369 |
| 370 Position anchor = anchorPosition(visibleSelection()); | 370 Position anchor = anchorPosition(visibleSelection()); |
| 371 if (!anchor.anchorNode()->isInShadowTree()) | 371 if (!anchor.anchorNode()->isInShadowTree()) |
| 372 return m_frame->selection().firstRange(); | 372 return m_frame->selection().firstRange(); |
| 373 | 373 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 if (!adjustedNode) | 518 if (!adjustedNode) |
| 519 return 0; | 519 return 0; |
| 520 | 520 |
| 521 if (containerNode == adjustedNode) | 521 if (containerNode == adjustedNode) |
| 522 return containerNode; | 522 return containerNode; |
| 523 | 523 |
| 524 ASSERT(!adjustedNode->isShadowRoot()); | 524 ASSERT(!adjustedNode->isShadowRoot()); |
| 525 return adjustedNode->parentOrShadowHostNode(); | 525 return adjustedNode->parentOrShadowHostNode(); |
| 526 } | 526 } |
| 527 | 527 |
| 528 int DOMSelection::shadowAdjustedOffset(const Position& position) const | 528 unsigned DOMSelection::shadowAdjustedOffset(const Position& position) const |
| 529 { | 529 { |
| 530 if (position.isNull()) | 530 if (position.isNull()) |
| 531 return 0; | 531 return 0; |
| 532 | 532 |
| 533 Node* containerNode = position.computeContainerNode(); | 533 Node* containerNode = position.computeContainerNode(); |
| 534 Node* adjustedNode = m_treeScope->ancestorInThisScope(containerNode); | 534 Node* adjustedNode = m_treeScope->ancestorInThisScope(containerNode); |
| 535 | 535 |
| 536 if (!adjustedNode) | 536 if (!adjustedNode) |
| 537 return 0; | 537 return 0; |
| 538 | 538 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 556 m_treeScope->document().addConsoleMessage(ConsoleMessage::create(JSMessa geSource, ErrorMessageLevel, message)); | 556 m_treeScope->document().addConsoleMessage(ConsoleMessage::create(JSMessa geSource, ErrorMessageLevel, message)); |
| 557 } | 557 } |
| 558 | 558 |
| 559 DEFINE_TRACE(DOMSelection) | 559 DEFINE_TRACE(DOMSelection) |
| 560 { | 560 { |
| 561 visitor->trace(m_treeScope); | 561 visitor->trace(m_treeScope); |
| 562 DOMWindowProperty::trace(visitor); | 562 DOMWindowProperty::trace(visitor); |
| 563 } | 563 } |
| 564 | 564 |
| 565 } // namespace blink | 565 } // namespace blink |
| OLD | NEW |