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

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

Issue 800633004: ShadowRoot's getSelection().getRangeAt(0) returns an incorrect Range object (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « LayoutTests/editing/shadow/getRangeAt-end-of-text-node.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 return nullptr; 362 return nullptr;
363 363
364 if (index < 0 || index >= rangeCount()) { 364 if (index < 0 || index >= rangeCount()) {
365 exceptionState.throwDOMException(IndexSizeError, String::number(index) + " is not a valid index."); 365 exceptionState.throwDOMException(IndexSizeError, String::number(index) + " is not a valid index.");
366 return nullptr; 366 return nullptr;
367 } 367 }
368 368
369 // If you're hitting this, you've added broken multi-range selection support 369 // If you're hitting this, you've added broken multi-range selection support
370 ASSERT(rangeCount() == 1); 370 ASSERT(rangeCount() == 1);
371 371
372 if (Node* shadowAncestor = selectionShadowAncestor(m_frame)) { 372 if (!m_treeScope->rootNode().isShadowRoot())
373 ASSERT(!shadowAncestor->isShadowRoot()); 373 return m_frame->selection().firstRange();
374 ContainerNode* container = shadowAncestor->parentOrShadowHostNode();
375 int offset = shadowAncestor->nodeIndex();
376 return Range::create(shadowAncestor->document(), container, offset, cont ainer, offset);
377 }
378 374
379 return m_frame->selection().firstRange(); 375 Node* anchor = anchorNode();
376 ASSERT(anchor);
yosin_UTC9 2015/01/07 01:06:29 I think we don't need to |ASSERT(anchor)| here. We
kojii 2015/01/07 06:53:52 Done.
377 return Range::create(anchor->document(), anchor, anchorOffset(), focusNode() , focusOffset());
380 } 378 }
381 379
382 void DOMSelection::removeAllRanges() 380 void DOMSelection::removeAllRanges()
383 { 381 {
384 if (!m_frame) 382 if (!m_frame)
385 return; 383 return;
386 m_frame->selection().clear(); 384 m_frame->selection().clear();
387 } 385 }
388 386
389 void DOMSelection::addRange(Range* newRange) 387 void DOMSelection::addRange(Range* newRange)
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 m_treeScope->document().addConsoleMessage(ConsoleMessage::create(JSMessa geSource, ErrorMessageLevel, message)); 557 m_treeScope->document().addConsoleMessage(ConsoleMessage::create(JSMessa geSource, ErrorMessageLevel, message));
560 } 558 }
561 559
562 void DOMSelection::trace(Visitor* visitor) 560 void DOMSelection::trace(Visitor* visitor)
563 { 561 {
564 visitor->trace(m_treeScope); 562 visitor->trace(m_treeScope);
565 DOMWindowProperty::trace(visitor); 563 DOMWindowProperty::trace(visitor);
566 } 564 }
567 565
568 } // namespace blink 566 } // namespace blink
OLDNEW
« no previous file with comments | « LayoutTests/editing/shadow/getRangeAt-end-of-text-node.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698