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 5041 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5052 | 5052 |
5053 // Check for multiple searchable frames. | 5053 // Check for multiple searchable frames. |
5054 bool multi_frame = (main_frame->traverseNextLocal(true) != main_frame); | 5054 bool multi_frame = (main_frame->traverseNextLocal(true) != main_frame); |
5055 | 5055 |
5056 // If we have multiple frames, we don't want to wrap the search within the | 5056 // If we have multiple frames, we don't want to wrap the search within the |
5057 // frame, so we check here if we only have |main_frame| in the chain. | 5057 // frame, so we check here if we only have |main_frame| in the chain. |
5058 bool wrap_within_frame = !multi_frame; | 5058 bool wrap_within_frame = !multi_frame; |
5059 | 5059 |
5060 WebRect selection_rect; | 5060 WebRect selection_rect; |
5061 bool result = false; | 5061 bool result = false; |
5062 bool active_now; | |
jochen (gone - plz use gerrit)
2016/02/23 14:34:26
please add a default value
dvadym
2016/02/23 14:39:36
Done.
| |
5062 | 5063 |
5063 // If something is selected when we start searching it means we cannot just | 5064 // If something is selected when we start searching it means we cannot just |
5064 // increment the current match ordinal; we need to re-generate it. | 5065 // increment the current match ordinal; we need to re-generate it. |
5065 WebRange current_selection = focused_frame->selectionRange(); | 5066 WebRange current_selection = focused_frame->selectionRange(); |
5066 | 5067 |
5067 do { | 5068 do { |
5068 result = search_frame->find(request_id, search_text, options, | 5069 result = |
5069 wrap_within_frame, &selection_rect); | 5070 search_frame->find(request_id, search_text, options, wrap_within_frame, |
5071 &selection_rect, &active_now); | |
5070 | 5072 |
5071 if (!result) { | 5073 if (!result) { |
5072 // Don't leave text selected as you move to the next frame. | 5074 // Don't leave text selected as you move to the next frame. |
5073 search_frame->executeCommand(WebString::fromUTF8("Unselect"), | 5075 search_frame->executeCommand(WebString::fromUTF8("Unselect"), |
5074 GetFocusedElement()); | 5076 GetFocusedElement()); |
5075 | 5077 |
5076 // Find the next frame, but skip the invisible ones. | 5078 // Find the next frame, but skip the invisible ones. |
5077 do { | 5079 do { |
5078 // What is the next frame to search (we might be going backwards)? Note | 5080 // What is the next frame to search (we might be going backwards)? Note |
5079 // that we specify wrap=true so that search_frame never becomes NULL. | 5081 // that we specify wrap=true so that search_frame never becomes NULL. |
5080 search_frame = options.forward | 5082 search_frame = options.forward |
5081 ? search_frame->traverseNextLocal(true) | 5083 ? search_frame->traverseNextLocal(true) |
5082 : search_frame->traversePreviousLocal(true); | 5084 : search_frame->traversePreviousLocal(true); |
5083 } while (!search_frame->hasVisibleContent() && | 5085 } while (!search_frame->hasVisibleContent() && |
5084 search_frame != focused_frame); | 5086 search_frame != focused_frame); |
5085 | 5087 |
5086 // Make sure selection doesn't affect the search operation in new frame. | 5088 // Make sure selection doesn't affect the search operation in new frame. |
5087 search_frame->executeCommand(WebString::fromUTF8("Unselect"), | 5089 search_frame->executeCommand(WebString::fromUTF8("Unselect"), |
5088 GetFocusedElement()); | 5090 GetFocusedElement()); |
5089 | 5091 |
5090 // If we have multiple frames and we have wrapped back around to the | 5092 // If we have multiple frames and we have wrapped back around to the |
5091 // focused frame, we need to search it once more allowing wrap within | 5093 // focused frame, we need to search it once more allowing wrap within |
5092 // the frame, otherwise it will report 'no match' if the focused frame has | 5094 // the frame, otherwise it will report 'no match' if the focused frame has |
5093 // reported matches, but no frames after the focused_frame contain a | 5095 // reported matches, but no frames after the focused_frame contain a |
5094 // match for the search word(s). | 5096 // match for the search word(s). |
5095 if (multi_frame && search_frame == focused_frame) { | 5097 if (multi_frame && search_frame == focused_frame) { |
5096 result = search_frame->find(request_id, search_text, options, | 5098 result = search_frame->find(request_id, search_text, options, |
5097 true, // Force wrapping. | 5099 true, // Force wrapping. |
5098 &selection_rect); | 5100 &selection_rect, &active_now); |
5099 } | 5101 } |
5100 } | 5102 } |
5101 | 5103 |
5102 render_view_->webview()->setFocusedFrame(search_frame); | 5104 render_view_->webview()->setFocusedFrame(search_frame); |
5103 } while (!result && search_frame != focused_frame); | 5105 } while (!result && search_frame != focused_frame); |
5104 | 5106 |
5105 if (options.findNext && current_selection.isNull()) { | 5107 if (options.findNext && current_selection.isNull() && active_now) { |
5106 // Force the main_frame to report the actual count. | 5108 // Force the main_frame to report the actual count. |
5107 main_frame->increaseMatchCount(0, request_id); | 5109 main_frame->increaseMatchCount(0, request_id); |
5108 } else { | 5110 } else { |
5109 // If nothing is found, set result to "0 of 0", otherwise, set it to | 5111 // If nothing is found, set result to "0 of 0", otherwise, set it to |
5110 // "-1 of 1" to indicate that we found at least one item, but we don't know | 5112 // "-1 of 1" to indicate that we found at least one item, but we don't know |
5111 // yet what is active. | 5113 // yet what is active. |
5112 int ordinal = result ? -1 : 0; // -1 here means we might know more later. | 5114 int ordinal = result ? -1 : 0; // -1 here means we might know more later. |
5113 int match_count = result ? 1 : 0; // 1 here means possibly more coming. | 5115 int match_count = result ? 1 : 0; // 1 here means possibly more coming. |
5114 | 5116 |
5115 // If we find no matches then this will be our last status update. | 5117 // If we find no matches then this will be our last status update. |
(...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6114 int match_count, | 6116 int match_count, |
6115 int ordinal, | 6117 int ordinal, |
6116 const WebRect& selection_rect, | 6118 const WebRect& selection_rect, |
6117 bool final_status_update) { | 6119 bool final_status_update) { |
6118 Send(new FrameHostMsg_Find_Reply(routing_id_, request_id, match_count, | 6120 Send(new FrameHostMsg_Find_Reply(routing_id_, request_id, match_count, |
6119 selection_rect, ordinal, | 6121 selection_rect, ordinal, |
6120 final_status_update)); | 6122 final_status_update)); |
6121 } | 6123 } |
6122 | 6124 |
6123 } // namespace content | 6125 } // namespace content |
OLD | NEW |