OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/android/content_detector.h" | 5 #include "content/renderer/android/content_detector.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "third_party/WebKit/public/platform/WebPoint.h" | 8 #include "third_party/WebKit/public/platform/WebPoint.h" |
9 #include "third_party/WebKit/public/web/WebHitTestResult.h" | 9 #include "third_party/WebKit/public/web/WebHitTestResult.h" |
10 #include "third_party/WebKit/public/web/WebSurroundingText.h" | 10 #include "third_party/WebKit/public/web/WebSurroundingText.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 const blink::WebHitTestResult& hit_test, | 45 const blink::WebHitTestResult& hit_test, |
46 std::string* content_text) { | 46 std::string* content_text) { |
47 // As the surrounding text extractor looks at maxLength/2 characters on | 47 // As the surrounding text extractor looks at maxLength/2 characters on |
48 // either side of the hit point, we need to double max content length here. | 48 // either side of the hit point, we need to double max content length here. |
49 WebSurroundingText surrounding_text; | 49 WebSurroundingText surrounding_text; |
50 surrounding_text.initialize(hit_test.node(), hit_test.localPoint(), | 50 surrounding_text.initialize(hit_test.node(), hit_test.localPoint(), |
51 GetMaximumContentLength() * 2); | 51 GetMaximumContentLength() * 2); |
52 if (surrounding_text.isNull()) | 52 if (surrounding_text.isNull()) |
53 return WebRange(); | 53 return WebRange(); |
54 | 54 |
55 string16 content = surrounding_text.textContent(); | 55 base::string16 content = surrounding_text.textContent(); |
56 if (content.empty()) | 56 if (content.empty()) |
57 return WebRange(); | 57 return WebRange(); |
58 | 58 |
59 size_t selected_offset = surrounding_text.hitOffsetInTextContent(); | 59 size_t selected_offset = surrounding_text.hitOffsetInTextContent(); |
60 for (size_t start_offset = 0; start_offset < content.length();) { | 60 for (size_t start_offset = 0; start_offset < content.length();) { |
61 size_t relative_start, relative_end; | 61 size_t relative_start, relative_end; |
62 if (!FindContent(content.begin() + start_offset, | 62 if (!FindContent(content.begin() + start_offset, |
63 content.end(), &relative_start, &relative_end, content_text)) { | 63 content.end(), &relative_start, &relative_end, content_text)) { |
64 break; | 64 break; |
65 } else { | 65 } else { |
66 size_t content_start = start_offset + relative_start; | 66 size_t content_start = start_offset + relative_start; |
67 size_t content_end = start_offset + relative_end; | 67 size_t content_end = start_offset + relative_end; |
68 DCHECK(content_end <= content.length()); | 68 DCHECK(content_end <= content.length()); |
69 | 69 |
70 if (selected_offset >= content_start && selected_offset < content_end) { | 70 if (selected_offset >= content_start && selected_offset < content_end) { |
71 WebRange range = surrounding_text.rangeFromContentOffsets( | 71 WebRange range = surrounding_text.rangeFromContentOffsets( |
72 content_start, content_end); | 72 content_start, content_end); |
73 DCHECK(!range.isNull()); | 73 DCHECK(!range.isNull()); |
74 return range; | 74 return range; |
75 } else { | 75 } else { |
76 start_offset += relative_end; | 76 start_offset += relative_end; |
77 } | 77 } |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 return WebRange(); | 81 return WebRange(); |
82 } | 82 } |
83 | 83 |
84 } // namespace content | 84 } // namespace content |
OLD | NEW |