| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // starts at the document's start and ends at the selection start and will | 86 // starts at the document's start and ends at the selection start and will |
| 87 // be updated. | 87 // be updated. |
| 88 BackwardsCharacterIterator backwards_iterator( | 88 BackwardsCharacterIterator backwards_iterator( |
| 89 Position::FirstPositionInNode(document->documentElement()) | 89 Position::FirstPositionInNode(document->documentElement()) |
| 90 .ParentAnchoredEquivalent(), | 90 .ParentAnchoredEquivalent(), |
| 91 start_position, | 91 start_position, |
| 92 TextIteratorBehavior::Builder().SetStopsOnFormControls(true).Build()); | 92 TextIteratorBehavior::Builder().SetStopsOnFormControls(true).Build()); |
| 93 if (!backwards_iterator.AtEnd()) | 93 if (!backwards_iterator.AtEnd()) |
| 94 backwards_iterator.Advance(half_max_length); | 94 backwards_iterator.Advance(half_max_length); |
| 95 | 95 |
| 96 start_offset_in_content_ = | 96 const TextIteratorBehavior behavior = |
| 97 Range::Create(*document, backwards_iterator.EndPosition(), start_position) | 97 TextIteratorBehavior::NoTrailingSpaceRangeLengthBehavior(); |
| 98 ->GetText() | 98 start_offset_in_content_ = TextIterator::RangeLength( |
| 99 .length(); | 99 backwards_iterator.EndPosition(), start_position, behavior); |
| 100 end_offset_in_content_ = | 100 end_offset_in_content_ = TextIterator::RangeLength( |
| 101 Range::Create(*document, backwards_iterator.EndPosition(), end_position) | 101 backwards_iterator.EndPosition(), end_position, behavior); |
| 102 ->GetText() | |
| 103 .length(); | |
| 104 content_range_ = Range::Create(*document, backwards_iterator.EndPosition(), | 102 content_range_ = Range::Create(*document, backwards_iterator.EndPosition(), |
| 105 forward_range.StartPosition()); | 103 forward_range.StartPosition()); |
| 106 DCHECK(content_range_); | 104 DCHECK(content_range_); |
| 107 } | 105 } |
| 108 | 106 |
| 109 String SurroundingText::Content() const { | 107 String SurroundingText::Content() const { |
| 110 if (content_range_) { | 108 if (content_range_) { |
| 111 // SurroundingText is created with clean layout and must not be stored | 109 // SurroundingText is created with clean layout and must not be stored |
| 112 // through DOM or style changes, so layout must still be clean here. | 110 // through DOM or style changes, so layout must still be clean here. |
| 113 DCHECK(!content_range_->OwnerDocument().NeedsLayoutTreeUpdate()); | 111 DCHECK(!content_range_->OwnerDocument().NeedsLayoutTreeUpdate()); |
| 114 return content_range_->GetText(); | 112 return content_range_->GetText(); |
| 115 } | 113 } |
| 116 return String(); | 114 return String(); |
| 117 } | 115 } |
| 118 | 116 |
| 119 unsigned SurroundingText::StartOffsetInContent() const { | 117 unsigned SurroundingText::StartOffsetInContent() const { |
| 120 return start_offset_in_content_; | 118 return start_offset_in_content_; |
| 121 } | 119 } |
| 122 | 120 |
| 123 unsigned SurroundingText::EndOffsetInContent() const { | 121 unsigned SurroundingText::EndOffsetInContent() const { |
| 124 return end_offset_in_content_; | 122 return end_offset_in_content_; |
| 125 } | 123 } |
| 126 | 124 |
| 127 } // namespace blink | 125 } // namespace blink |
| OLD | NEW |