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 5030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5041 WebFrame* search_frame = focused_frame; // start searching focused frame. | 5041 WebFrame* search_frame = focused_frame; // start searching focused frame. |
5042 | 5042 |
5043 bool multi_frame = (frame_after_main != main_frame); | 5043 bool multi_frame = (frame_after_main != main_frame); |
5044 | 5044 |
5045 // If we have multiple frames, we don't want to wrap the search within the | 5045 // If we have multiple frames, we don't want to wrap the search within the |
5046 // frame, so we check here if we only have main_frame in the chain. | 5046 // frame, so we check here if we only have main_frame in the chain. |
5047 bool wrap_within_frame = !multi_frame; | 5047 bool wrap_within_frame = !multi_frame; |
5048 | 5048 |
5049 WebRect selection_rect; | 5049 WebRect selection_rect; |
5050 bool result = false; | 5050 bool result = false; |
| 5051 bool active_now; |
5051 | 5052 |
5052 // If something is selected when we start searching it means we cannot just | 5053 // If something is selected when we start searching it means we cannot just |
5053 // increment the current match ordinal; we need to re-generate it. | 5054 // increment the current match ordinal; we need to re-generate it. |
5054 WebRange current_selection = focused_frame->selectionRange(); | 5055 WebRange current_selection = focused_frame->selectionRange(); |
5055 | 5056 |
5056 do { | 5057 do { |
5057 result = search_frame->find(request_id, search_text, options, | 5058 result = |
5058 wrap_within_frame, &selection_rect); | 5059 search_frame->find(request_id, search_text, options, wrap_within_frame, |
| 5060 &selection_rect, &active_now); |
5059 | 5061 |
5060 if (!result) { | 5062 if (!result) { |
5061 // Don't leave text selected as you move to the next frame. | 5063 // Don't leave text selected as you move to the next frame. |
5062 search_frame->executeCommand(WebString::fromUTF8("Unselect"), | 5064 search_frame->executeCommand(WebString::fromUTF8("Unselect"), |
5063 GetFocusedElement()); | 5065 GetFocusedElement()); |
5064 | 5066 |
5065 // Find the next frame, but skip the invisible ones. | 5067 // Find the next frame, but skip the invisible ones. |
5066 do { | 5068 do { |
5067 // What is the next frame to search (we might be going backwards)? Note | 5069 // What is the next frame to search (we might be going backwards)? Note |
5068 // that we specify wrap=true so that search_frame never becomes NULL. | 5070 // that we specify wrap=true so that search_frame never becomes NULL. |
5069 search_frame = options.forward ? search_frame->traverseNext(true) | 5071 search_frame = options.forward ? search_frame->traverseNext(true) |
5070 : search_frame->traversePrevious(true); | 5072 : search_frame->traversePrevious(true); |
5071 } while (!search_frame->hasVisibleContent() && | 5073 } while (!search_frame->hasVisibleContent() && |
5072 search_frame != focused_frame); | 5074 search_frame != focused_frame); |
5073 | 5075 |
5074 // Make sure selection doesn't affect the search operation in new frame. | 5076 // Make sure selection doesn't affect the search operation in new frame. |
5075 search_frame->executeCommand(WebString::fromUTF8("Unselect"), | 5077 search_frame->executeCommand(WebString::fromUTF8("Unselect"), |
5076 GetFocusedElement()); | 5078 GetFocusedElement()); |
5077 | 5079 |
5078 // If we have multiple frames and we have wrapped back around to the | 5080 // If we have multiple frames and we have wrapped back around to the |
5079 // focused frame, we need to search it once more allowing wrap within | 5081 // focused frame, we need to search it once more allowing wrap within |
5080 // the frame, otherwise it will report 'no match' if the focused frame has | 5082 // the frame, otherwise it will report 'no match' if the focused frame has |
5081 // reported matches, but no frames after the focused_frame contain a | 5083 // reported matches, but no frames after the focused_frame contain a |
5082 // match for the search word(s). | 5084 // match for the search word(s). |
5083 if (multi_frame && search_frame == focused_frame) { | 5085 if (multi_frame && search_frame == focused_frame) { |
5084 result = search_frame->find(request_id, search_text, options, | 5086 result = search_frame->find(request_id, search_text, options, |
5085 true, // Force wrapping. | 5087 true, // Force wrapping. |
5086 &selection_rect); | 5088 &selection_rect, &active_now); |
5087 } | 5089 } |
5088 } | 5090 } |
5089 | 5091 |
5090 render_view_->webview()->setFocusedFrame(search_frame); | 5092 render_view_->webview()->setFocusedFrame(search_frame); |
5091 } while (!result && search_frame != focused_frame); | 5093 } while (!result && search_frame != focused_frame); |
5092 | 5094 |
5093 if (options.findNext && current_selection.isNull()) { | 5095 if (options.findNext && current_selection.isNull() && active_now) { |
5094 // Force the main_frame to report the actual count. | 5096 // Force the main_frame to report the actual count. |
5095 main_frame->increaseMatchCount(0, request_id); | 5097 main_frame->increaseMatchCount(0, request_id); |
5096 } else { | 5098 } else { |
5097 // If nothing is found, set result to "0 of 0", otherwise, set it to | 5099 // If nothing is found, set result to "0 of 0", otherwise, set it to |
5098 // "-1 of 1" to indicate that we found at least one item, but we don't know | 5100 // "-1 of 1" to indicate that we found at least one item, but we don't know |
5099 // yet what is active. | 5101 // yet what is active. |
5100 int ordinal = result ? -1 : 0; // -1 here means we might know more later. | 5102 int ordinal = result ? -1 : 0; // -1 here means we might know more later. |
5101 int match_count = result ? 1 : 0; // 1 here means possibly more coming. | 5103 int match_count = result ? 1 : 0; // 1 here means possibly more coming. |
5102 | 5104 |
5103 // If we find no matches then this will be our last status update. | 5105 // If we find no matches then this will be our last status update. |
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6077 int match_count, | 6079 int match_count, |
6078 int ordinal, | 6080 int ordinal, |
6079 const WebRect& selection_rect, | 6081 const WebRect& selection_rect, |
6080 bool final_status_update) { | 6082 bool final_status_update) { |
6081 Send(new FrameHostMsg_Find_Reply(routing_id_, request_id, match_count, | 6083 Send(new FrameHostMsg_Find_Reply(routing_id_, request_id, match_count, |
6082 selection_rect, ordinal, | 6084 selection_rect, ordinal, |
6083 final_status_update)); | 6085 final_status_update)); |
6084 } | 6086 } |
6085 | 6087 |
6086 } // namespace content | 6088 } // namespace content |
OLD | NEW |