OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/render_frame_impl.h" | 5 #include "content/renderer/render_frame_impl.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 5074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5085 | 5085 |
5086 // Check for multiple searchable frames. | 5086 // Check for multiple searchable frames. |
5087 bool multi_frame = (main_frame->traverseNextLocal(true) != main_frame); | 5087 bool multi_frame = (main_frame->traverseNextLocal(true) != main_frame); |
5088 | 5088 |
5089 // If we have multiple frames, we don't want to wrap the search within the | 5089 // If we have multiple frames, we don't want to wrap the search within the |
5090 // frame, so we check here if we only have |main_frame| in the chain. | 5090 // frame, so we check here if we only have |main_frame| in the chain. |
5091 bool wrap_within_frame = !multi_frame; | 5091 bool wrap_within_frame = !multi_frame; |
5092 | 5092 |
5093 WebRect selection_rect; | 5093 WebRect selection_rect; |
5094 bool result = false; | 5094 bool result = false; |
| 5095 bool active_now; |
5095 | 5096 |
5096 // If something is selected when we start searching it means we cannot just | 5097 // If something is selected when we start searching it means we cannot just |
5097 // increment the current match ordinal; we need to re-generate it. | 5098 // increment the current match ordinal; we need to re-generate it. |
5098 WebRange current_selection = focused_frame->selectionRange(); | 5099 WebRange current_selection = focused_frame->selectionRange(); |
5099 | 5100 |
5100 do { | 5101 do { |
5101 result = search_frame->find(request_id, search_text, options, | 5102 result = |
5102 wrap_within_frame, &selection_rect); | 5103 search_frame->find(request_id, search_text, options, wrap_within_frame, |
| 5104 &selection_rect, &active_now); |
5103 | 5105 |
5104 if (!result) { | 5106 if (!result) { |
5105 // Don't leave text selected as you move to the next frame. | 5107 // Don't leave text selected as you move to the next frame. |
5106 search_frame->executeCommand(WebString::fromUTF8("Unselect"), | 5108 search_frame->executeCommand(WebString::fromUTF8("Unselect"), |
5107 GetFocusedElement()); | 5109 GetFocusedElement()); |
5108 | 5110 |
5109 // Find the next frame, but skip the invisible ones. | 5111 // Find the next frame, but skip the invisible ones. |
5110 do { | 5112 do { |
5111 // What is the next frame to search (we might be going backwards)? Note | 5113 // What is the next frame to search (we might be going backwards)? Note |
5112 // that we specify wrap=true so that search_frame never becomes NULL. | 5114 // that we specify wrap=true so that search_frame never becomes NULL. |
5113 search_frame = options.forward | 5115 search_frame = options.forward |
5114 ? search_frame->traverseNextLocal(true) | 5116 ? search_frame->traverseNextLocal(true) |
5115 : search_frame->traversePreviousLocal(true); | 5117 : search_frame->traversePreviousLocal(true); |
5116 } while (!search_frame->hasVisibleContent() && | 5118 } while (!search_frame->hasVisibleContent() && |
5117 search_frame != focused_frame); | 5119 search_frame != focused_frame); |
5118 | 5120 |
5119 // Make sure selection doesn't affect the search operation in new frame. | 5121 // Make sure selection doesn't affect the search operation in new frame. |
5120 search_frame->executeCommand(WebString::fromUTF8("Unselect"), | 5122 search_frame->executeCommand(WebString::fromUTF8("Unselect"), |
5121 GetFocusedElement()); | 5123 GetFocusedElement()); |
5122 | 5124 |
5123 // If we have multiple frames and we have wrapped back around to the | 5125 // If we have multiple frames and we have wrapped back around to the |
5124 // focused frame, we need to search it once more allowing wrap within | 5126 // focused frame, we need to search it once more allowing wrap within |
5125 // the frame, otherwise it will report 'no match' if the focused frame has | 5127 // the frame, otherwise it will report 'no match' if the focused frame has |
5126 // reported matches, but no frames after the focused_frame contain a | 5128 // reported matches, but no frames after the focused_frame contain a |
5127 // match for the search word(s). | 5129 // match for the search word(s). |
5128 if (multi_frame && search_frame == focused_frame) { | 5130 if (multi_frame && search_frame == focused_frame) { |
5129 result = search_frame->find(request_id, search_text, options, | 5131 result = search_frame->find(request_id, search_text, options, |
5130 true, // Force wrapping. | 5132 true, // Force wrapping. |
5131 &selection_rect); | 5133 &selection_rect, &active_now); |
5132 } | 5134 } |
5133 } | 5135 } |
5134 | 5136 |
5135 render_view_->webview()->setFocusedFrame(search_frame); | 5137 render_view_->webview()->setFocusedFrame(search_frame); |
5136 } while (!result && search_frame != focused_frame); | 5138 } while (!result && search_frame != focused_frame); |
5137 | 5139 |
5138 if (options.findNext && current_selection.isNull()) { | 5140 if (options.findNext && current_selection.isNull() && active_now) { |
5139 // Force the main_frame to report the actual count. | 5141 // Force the main_frame to report the actual count. |
5140 main_frame->increaseMatchCount(0, request_id); | 5142 main_frame->increaseMatchCount(0, request_id); |
5141 } else { | 5143 } else { |
5142 // If nothing is found, set result to "0 of 0", otherwise, set it to | 5144 // If nothing is found, set result to "0 of 0", otherwise, set it to |
5143 // "-1 of 1" to indicate that we found at least one item, but we don't know | 5145 // "-1 of 1" to indicate that we found at least one item, but we don't know |
5144 // yet what is active. | 5146 // yet what is active. |
5145 int ordinal = result ? -1 : 0; // -1 here means we might know more later. | 5147 int ordinal = result ? -1 : 0; // -1 here means we might know more later. |
5146 int match_count = result ? 1 : 0; // 1 here means possibly more coming. | 5148 int match_count = result ? 1 : 0; // 1 here means possibly more coming. |
5147 | 5149 |
5148 // If we find no matches then this will be our last status update. | 5150 // If we find no matches then this will be our last status update. |
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6139 int match_count, | 6141 int match_count, |
6140 int ordinal, | 6142 int ordinal, |
6141 const WebRect& selection_rect, | 6143 const WebRect& selection_rect, |
6142 bool final_status_update) { | 6144 bool final_status_update) { |
6143 Send(new FrameHostMsg_Find_Reply(routing_id_, request_id, match_count, | 6145 Send(new FrameHostMsg_Find_Reply(routing_id_, request_id, match_count, |
6144 selection_rect, ordinal, | 6146 selection_rect, ordinal, |
6145 final_status_update)); | 6147 final_status_update)); |
6146 } | 6148 } |
6147 | 6149 |
6148 } // namespace content | 6150 } // namespace content |
OLD | NEW |