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