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/render_view_impl.h" | 5 #include "content/renderer/render_view_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 2341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2352 WebFrame* search_frame = focused_frame; // start searching focused frame. | 2352 WebFrame* search_frame = focused_frame; // start searching focused frame. |
2353 | 2353 |
2354 bool multi_frame = (frame_after_main != main_frame); | 2354 bool multi_frame = (frame_after_main != main_frame); |
2355 | 2355 |
2356 // If we have multiple frames, we don't want to wrap the search within the | 2356 // If we have multiple frames, we don't want to wrap the search within the |
2357 // frame, so we check here if we only have main_frame in the chain. | 2357 // frame, so we check here if we only have main_frame in the chain. |
2358 bool wrap_within_frame = !multi_frame; | 2358 bool wrap_within_frame = !multi_frame; |
2359 | 2359 |
2360 WebRect selection_rect; | 2360 WebRect selection_rect; |
2361 bool result = false; | 2361 bool result = false; |
| 2362 bool new_text_found; |
2362 | 2363 |
2363 // If something is selected when we start searching it means we cannot just | 2364 // If something is selected when we start searching it means we cannot just |
2364 // increment the current match ordinal; we need to re-generate it. | 2365 // increment the current match ordinal; we need to re-generate it. |
2365 WebRange current_selection = focused_frame->selectionRange(); | 2366 WebRange current_selection = focused_frame->selectionRange(); |
2366 | 2367 |
2367 do { | 2368 do { |
2368 result = search_frame->find( | 2369 result = |
2369 request_id, search_text, options, wrap_within_frame, &selection_rect); | 2370 search_frame->find(request_id, search_text, options, wrap_within_frame, |
| 2371 &selection_rect, new_text_found); |
2370 | 2372 |
2371 if (!result) { | 2373 if (!result) { |
2372 // don't leave text selected as you move to the next frame. | 2374 // don't leave text selected as you move to the next frame. |
2373 search_frame->executeCommand(WebString::fromUTF8("Unselect"), | 2375 search_frame->executeCommand(WebString::fromUTF8("Unselect"), |
2374 GetFocusedElement()); | 2376 GetFocusedElement()); |
2375 | 2377 |
2376 // Find the next frame, but skip the invisible ones. | 2378 // Find the next frame, but skip the invisible ones. |
2377 do { | 2379 do { |
2378 // What is the next frame to search? (we might be going backwards). Note | 2380 // What is the next frame to search? (we might be going backwards). Note |
2379 // that we specify wrap=true so that search_frame never becomes NULL. | 2381 // that we specify wrap=true so that search_frame never becomes NULL. |
2380 search_frame = options.forward ? | 2382 search_frame = options.forward ? |
2381 search_frame->traverseNext(true) : | 2383 search_frame->traverseNext(true) : |
2382 search_frame->traversePrevious(true); | 2384 search_frame->traversePrevious(true); |
2383 } while (!search_frame->hasVisibleContent() && | 2385 } while (!search_frame->hasVisibleContent() && |
2384 search_frame != focused_frame); | 2386 search_frame != focused_frame); |
2385 | 2387 |
2386 // Make sure selection doesn't affect the search operation in new frame. | 2388 // Make sure selection doesn't affect the search operation in new frame. |
2387 search_frame->executeCommand(WebString::fromUTF8("Unselect"), | 2389 search_frame->executeCommand(WebString::fromUTF8("Unselect"), |
2388 GetFocusedElement()); | 2390 GetFocusedElement()); |
2389 | 2391 |
2390 // If we have multiple frames and we have wrapped back around to the | 2392 // If we have multiple frames and we have wrapped back around to the |
2391 // focused frame, we need to search it once more allowing wrap within | 2393 // focused frame, we need to search it once more allowing wrap within |
2392 // the frame, otherwise it will report 'no match' if the focused frame has | 2394 // the frame, otherwise it will report 'no match' if the focused frame has |
2393 // reported matches, but no frames after the focused_frame contain a | 2395 // reported matches, but no frames after the focused_frame contain a |
2394 // match for the search word(s). | 2396 // match for the search word(s). |
2395 if (multi_frame && search_frame == focused_frame) { | 2397 if (multi_frame && search_frame == focused_frame) { |
2396 result = search_frame->find( | 2398 result = search_frame->find(request_id, search_text, options, |
2397 request_id, search_text, options, true, // Force wrapping. | 2399 true, // Force wrapping. |
2398 &selection_rect); | 2400 &selection_rect, new_text_found); |
2399 } | 2401 } |
2400 } | 2402 } |
2401 | 2403 |
2402 webview()->setFocusedFrame(search_frame); | 2404 webview()->setFocusedFrame(search_frame); |
2403 } while (!result && search_frame != focused_frame); | 2405 } while (!result && search_frame != focused_frame); |
2404 | 2406 |
2405 if (options.findNext && current_selection.isNull()) { | 2407 if (options.findNext && current_selection.isNull() && !new_text_found) { |
2406 // Force the main_frame to report the actual count. | 2408 // Force the main_frame to report the actual count. |
2407 main_frame->increaseMatchCount(0, request_id); | 2409 main_frame->increaseMatchCount(0, request_id); |
2408 } else { | 2410 } else { |
2409 // If nothing is found, set result to "0 of 0", otherwise, set it to | 2411 // If nothing is found, set result to "0 of 0", otherwise, set it to |
2410 // "-1 of 1" to indicate that we found at least one item, but we don't know | 2412 // "-1 of 1" to indicate that we found at least one item, but we don't know |
2411 // yet what is active. | 2413 // yet what is active. |
2412 int ordinal = result ? -1 : 0; // -1 here means, we might know more later. | 2414 int ordinal = result ? -1 : 0; // -1 here means, we might know more later. |
2413 int match_count = result ? 1 : 0; // 1 here means possibly more coming. | 2415 int match_count = result ? 1 : 0; // 1 here means possibly more coming. |
2414 | 2416 |
2415 // If we find no matches then this will be our last status update. | 2417 // If we find no matches then this will be our last status update. |
(...skipping 1311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3727 if (IsUseZoomForDSFEnabled()) { | 3729 if (IsUseZoomForDSFEnabled()) { |
3728 webview()->setZoomFactorForDeviceScaleFactor(device_scale_factor_); | 3730 webview()->setZoomFactorForDeviceScaleFactor(device_scale_factor_); |
3729 } else { | 3731 } else { |
3730 webview()->setDeviceScaleFactor(device_scale_factor_); | 3732 webview()->setDeviceScaleFactor(device_scale_factor_); |
3731 } | 3733 } |
3732 webview()->settings()->setPreferCompositingToLCDTextEnabled( | 3734 webview()->settings()->setPreferCompositingToLCDTextEnabled( |
3733 PreferCompositingToLCDText(compositor_deps_, device_scale_factor_)); | 3735 PreferCompositingToLCDText(compositor_deps_, device_scale_factor_)); |
3734 } | 3736 } |
3735 | 3737 |
3736 } // namespace content | 3738 } // namespace content |
OLD | NEW |