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

Side by Side Diff: Source/wtf/text/TextPosition.cpp

Issue 172593003: DevTools: [CSS] Add CSS.editRangeInStyleSheetText() to the protocol (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fix glitch Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013, Google Inc. All rights reserved. 2 * Copyright (C) 2013, 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 30 matching lines...) Expand all
41 break; 41 break;
42 42
43 result->append(static_cast<unsigned>(lineEnd)); 43 result->append(static_cast<unsigned>(lineEnd));
44 start = lineEnd + 1; 44 start = lineEnd + 1;
45 } 45 }
46 result->append(text.length()); 46 result->append(text.length());
47 47
48 return result.release(); 48 return result.release();
49 } 49 }
50 50
51 OrdinalNumber TextPosition::toOffsetPosition(const Vector<unsigned>& lineEndings )
52 {
53 unsigned lineStartOffset = m_line != OrdinalNumber::first() ? lineEndings.at (m_line.zeroBasedInt() - 1) + 1 : 0;
54 return OrdinalNumber::fromZeroBasedInt(lineStartOffset + m_column.zeroBasedI nt());
55 }
56
51 TextPosition TextPosition::fromOffsetAndLineEndings(unsigned offset, const Vecto r<unsigned>& lineEndings) 57 TextPosition TextPosition::fromOffsetAndLineEndings(unsigned offset, const Vecto r<unsigned>& lineEndings)
52 { 58 {
53 const unsigned* foundLineEnding = std::lower_bound(lineEndings.begin(), line Endings.end(), offset); 59 const unsigned* foundLineEnding = std::lower_bound(lineEndings.begin(), line Endings.end(), offset);
54 int lineIndex = foundLineEnding - &lineEndings.at(0); 60 int lineIndex = foundLineEnding - &lineEndings.at(0);
55 unsigned lineStartOffset = lineIndex > 0 ? lineEndings.at(lineIndex - 1) + 1 : 0; 61 unsigned lineStartOffset = lineIndex > 0 ? lineEndings.at(lineIndex - 1) + 1 : 0;
56 int column = offset - lineStartOffset; 62 int column = offset - lineStartOffset;
57 return TextPosition(OrdinalNumber::fromZeroBasedInt(lineIndex), OrdinalNumbe r::fromZeroBasedInt(column)); 63 return TextPosition(OrdinalNumber::fromZeroBasedInt(lineIndex), OrdinalNumbe r::fromZeroBasedInt(column));
58 } 64 }
59 65
60 } // namespace WTF 66 } // namespace WTF
OLDNEW
« Source/core/inspector/InspectorStyleSheet.cpp ('K') | « Source/wtf/text/TextPosition.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698