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/Source/WebKit/chromium/public/platform/WebPoint.h" |
8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHitTestResult.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHitTestResult.h" |
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSurroundingText.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSurroundingText.h" |
10 | 11 |
11 using WebKit::WebRange; | 12 using WebKit::WebRange; |
12 using WebKit::WebSurroundingText; | 13 using WebKit::WebSurroundingText; |
13 | 14 |
14 namespace content { | 15 namespace content { |
15 | 16 |
16 ContentDetector::Result ContentDetector::FindTappedContent( | 17 ContentDetector::Result ContentDetector::FindTappedContent( |
17 const WebKit::WebHitTestResult& hit_test) { | 18 const WebKit::WebHitTestResult& hit_test) { |
18 if (hit_test.isNull()) | 19 if (hit_test.isNull()) |
19 return Result(); | 20 return Result(); |
20 | 21 |
21 std::string content_text; | 22 std::string content_text; |
22 WebKit::WebRange range = FindContentRange(hit_test, &content_text); | 23 WebKit::WebRange range = FindContentRange(hit_test, &content_text); |
23 if (range.isNull()) | 24 if (range.isNull()) |
24 return Result(); | 25 return Result(); |
25 | 26 |
26 GURL intent_url = GetIntentURL(content_text); | 27 GURL intent_url = GetIntentURL(content_text); |
27 return Result(range, content_text, intent_url); | 28 return Result(range, content_text, intent_url); |
28 } | 29 } |
29 | 30 |
30 WebRange ContentDetector::FindContentRange( | 31 WebRange ContentDetector::FindContentRange( |
31 const WebKit::WebHitTestResult& hit_test, | 32 const WebKit::WebHitTestResult& hit_test, |
32 std::string* content_text) { | 33 std::string* content_text) { |
33 // As the surrounding text extractor looks at maxLength/2 characters on | 34 // As the surrounding text extractor looks at maxLength/2 characters on |
34 // either side of the hit point, we need to double max content length here. | 35 // either side of the hit point, we need to double max content length here. |
35 WebSurroundingText surrounding_text; | 36 WebSurroundingText surrounding_text; |
36 surrounding_text.initialize(hit_test, GetMaximumContentLength() * 2); | 37 surrounding_text.initialize(hit_test.node(), hit_test.localPoint(), |
| 38 GetMaximumContentLength() * 2); |
37 if (surrounding_text.isNull()) | 39 if (surrounding_text.isNull()) |
38 return WebRange(); | 40 return WebRange(); |
39 | 41 |
40 string16 content = surrounding_text.textContent(); | 42 string16 content = surrounding_text.textContent(); |
41 if (content.empty()) | 43 if (content.empty()) |
42 return WebRange(); | 44 return WebRange(); |
43 | 45 |
44 size_t selected_offset = surrounding_text.hitOffsetInTextContent(); | 46 size_t selected_offset = surrounding_text.hitOffsetInTextContent(); |
45 for (size_t start_offset = 0; start_offset < content.length();) { | 47 for (size_t start_offset = 0; start_offset < content.length();) { |
46 size_t relative_start, relative_end; | 48 size_t relative_start, relative_end; |
(...skipping 13 matching lines...) Expand all Loading... |
60 } else { | 62 } else { |
61 start_offset += relative_end; | 63 start_offset += relative_end; |
62 } | 64 } |
63 } | 65 } |
64 } | 66 } |
65 | 67 |
66 return WebRange(); | 68 return WebRange(); |
67 } | 69 } |
68 | 70 |
69 } // namespace content | 71 } // namespace content |
OLD | NEW |