| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
| 3 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. | 3 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 // We can't load a javascript: URL if there is no Document! | 346 // We can't load a javascript: URL if there is no Document! |
| 347 if (!frame_->document()) | 347 if (!frame_->document()) |
| 348 return; | 348 return; |
| 349 | 349 |
| 350 // TODO(darin): Is this the best API to use here? It works and seems good, | 350 // TODO(darin): Is this the best API to use here? It works and seems good, |
| 351 // but will it change out from under us? | 351 // but will it change out from under us? |
| 352 String script = | 352 String script = |
| 353 decodeURLEscapeSequences(kurl.string().substring(sizeof("javascript:")-1
)); | 353 decodeURLEscapeSequences(kurl.string().substring(sizeof("javascript:")-1
)); |
| 354 WebCore::ScriptValue result = frame_->loader()->executeScript(script, true); | 354 WebCore::ScriptValue result = frame_->loader()->executeScript(script, true); |
| 355 String scriptResult; | 355 String scriptResult; |
| 356 if (result.getString(scriptResult) && | 356 if (result.getString(scriptResult) && |
| 357 !frame_->loader()->isScheduledLocationChangePending()) { | 357 !frame_->loader()->isScheduledLocationChangePending()) { |
| 358 // TODO(darin): We need to figure out how to represent this in session | 358 // TODO(darin): We need to figure out how to represent this in session |
| 359 // history. Hint: don't re-eval script when the user or script navigates | 359 // history. Hint: don't re-eval script when the user or script navigates |
| 360 // back-n-forth (instead store the script result somewhere). | 360 // back-n-forth (instead store the script result somewhere). |
| 361 LoadDocumentData(kurl, scriptResult, String("text/html"), String()); | 361 LoadDocumentData(kurl, scriptResult, String("text/html"), String()); |
| 362 } | 362 } |
| 363 return; | 363 return; |
| 364 } | 364 } |
| 365 | 365 |
| 366 StopLoading(); // make sure existing activity stops | 366 StopLoading(); // make sure existing activity stops |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 view->x() + view->visibleWidth(), view->y(), | 757 view->x() + view->visibleWidth(), view->y(), |
| 758 WebCore::ScrollbarTheme::nativeTheme()->scrollbarThickness(), | 758 WebCore::ScrollbarTheme::nativeTheme()->scrollbarThickness(), |
| 759 view->visibleHeight()); | 759 view->visibleHeight()); |
| 760 view->invalidateRect(scroll_bar_vert); | 760 view->invalidateRect(scroll_bar_vert); |
| 761 } | 761 } |
| 762 } | 762 } |
| 763 #endif | 763 #endif |
| 764 } | 764 } |
| 765 | 765 |
| 766 void WebFrameImpl::IncreaseMatchCount(int count, int request_id) { | 766 void WebFrameImpl::IncreaseMatchCount(int count, int request_id) { |
| 767 // This function should only be called on the mainframe. |
| 768 DCHECK(this == static_cast<WebFrameImpl*>(GetView()->GetMainFrame())); |
| 769 |
| 767 total_matchcount_ += count; | 770 total_matchcount_ += count; |
| 768 | 771 |
| 769 // Update the UI with the latest findings. | 772 // Update the UI with the latest findings. |
| 770 WebViewDelegate* webview_delegate = GetView()->GetDelegate(); | 773 WebViewDelegate* webview_delegate = GetView()->GetDelegate(); |
| 771 DCHECK(webview_delegate); | 774 DCHECK(webview_delegate); |
| 772 if (webview_delegate) | 775 if (webview_delegate) |
| 773 webview_delegate->ReportFindInPageMatchCount(total_matchcount_, request_id, | 776 webview_delegate->ReportFindInPageMatchCount(total_matchcount_, request_id, |
| 774 frames_scoping_count_ == 0); | 777 frames_scoping_count_ == 0); |
| 775 } | 778 } |
| 776 | 779 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 bool start_in_selection = true; | 812 bool start_in_selection = true; |
| 810 | 813 |
| 811 DCHECK(frame() && frame()->view()); | 814 DCHECK(frame() && frame()->view()); |
| 812 bool found = frame()->findString(webcore_string, request.forward, | 815 bool found = frame()->findString(webcore_string, request.forward, |
| 813 request.match_case, wrap_within_frame, | 816 request.match_case, wrap_within_frame, |
| 814 start_in_selection); | 817 start_in_selection); |
| 815 if (found) { | 818 if (found) { |
| 816 #if defined(OS_WIN) | 819 #if defined(OS_WIN) |
| 817 WebCore::RenderThemeWin::setFindInPageMode(true); | 820 WebCore::RenderThemeWin::setFindInPageMode(true); |
| 818 #endif | 821 #endif |
| 822 // Store which frame was active. This will come in handy later when we |
| 823 // change the active match ordinal below. |
| 824 WebFrameImpl* old_active_frame = main_frame_impl->active_match_frame_; |
| 819 // Set this frame as the active frame (the one with the active highlight). | 825 // Set this frame as the active frame (the one with the active highlight). |
| 820 main_frame_impl->active_match_frame_ = this; | 826 main_frame_impl->active_match_frame_ = this; |
| 821 | 827 |
| 822 // We found something, so we can now query the selection for its position. | 828 // We found something, so we can now query the selection for its position. |
| 823 Selection new_selection(frame()->selection()->selection()); | 829 Selection new_selection(frame()->selection()->selection()); |
| 824 IntRect curr_selection_rect; | 830 IntRect curr_selection_rect; |
| 825 | 831 |
| 826 // If we thought we found something, but it couldn't be selected (perhaps | 832 // If we thought we found something, but it couldn't be selected (perhaps |
| 827 // because it was marked -webkit-user-select: none), we can't set it to | 833 // because it was marked -webkit-user-select: none), we can't set it to |
| 828 // be active but we still continue searching. This matches Safari's | 834 // be active but we still continue searching. This matches Safari's |
| 829 // behavior, including some oddities when selectable and un-selectable text | 835 // behavior, including some oddities when selectable and un-selectable text |
| 830 // are mixed on a page: see https://bugs.webkit.org/show_bug.cgi?id=19127. | 836 // are mixed on a page: see https://bugs.webkit.org/show_bug.cgi?id=19127. |
| 831 if (new_selection.isNone() || | 837 if (new_selection.isNone() || |
| 832 (new_selection.start() == new_selection.end())) { | 838 (new_selection.start() == new_selection.end())) { |
| 833 active_match_ = NULL; | 839 active_match_ = NULL; |
| 834 } else { | 840 } else { |
| 835 active_match_ = new_selection.toRange(); | 841 active_match_ = new_selection.toRange(); |
| 836 curr_selection_rect = active_match_->boundingBox(); | 842 curr_selection_rect = active_match_->boundingBox(); |
| 837 } | 843 } |
| 838 | 844 |
| 839 if (!request.find_next) { | 845 if (!request.find_next) { |
| 840 // This is a Find operation, so we set the flag to ask the scoping effort | 846 // This is a Find operation, so we set the flag to ask the scoping effort |
| 841 // to find the active rect for us so we can update the ordinal (n of m). | 847 // to find the active rect for us so we can update the ordinal (n of m). |
| 842 locating_active_rect_ = true; | 848 locating_active_rect_ = true; |
| 843 } else { | 849 } else { |
| 844 // This is FindNext so we need to increment (or decrement) the count and | 850 if (old_active_frame != this) { |
| 845 // wrap if needed. | 851 // If the active frame has changed it means that we have a multi-frame |
| 846 request.forward ? ++active_match_index_ : --active_match_index_; | 852 // page and we just switch to searching in a new frame. Then we just |
| 847 if (active_match_index_ + 1 > last_match_count_) | 853 // want to reset the index. |
| 848 active_match_index_ = 0; | 854 if (request.forward) |
| 849 if (active_match_index_ + 1 == 0) | 855 active_match_index_ = 0; |
| 850 active_match_index_ = last_match_count_ - 1; | 856 else |
| 857 active_match_index_ = last_match_count_ - 1; |
| 858 } else { |
| 859 // We are still the active frame, so increment (or decrement) the |
| 860 // |active_match_index|, wrapping if needed (on single frame pages). |
| 861 request.forward ? ++active_match_index_ : --active_match_index_; |
| 862 if (active_match_index_ + 1 > last_match_count_) |
| 863 active_match_index_ = 0; |
| 864 if (active_match_index_ + 1 == 0) |
| 865 active_match_index_ = last_match_count_ - 1; |
| 866 } |
| 851 } | 867 } |
| 852 | 868 |
| 853 #if defined(OS_WIN) | 869 #if defined(OS_WIN) |
| 854 // TODO(pinkerton): Fix Mac scrolling to be more like Win ScrollView | 870 // TODO(pinkerton): Fix Mac scrolling to be more like Win ScrollView |
| 855 if (selection_rect) { | 871 if (selection_rect) { |
| 856 gfx::Rect rect = webkit_glue::FromIntRect( | 872 gfx::Rect rect = webkit_glue::FromIntRect( |
| 857 frame()->view()->convertToContainingWindow(curr_selection_rect)); | 873 frame()->view()->convertToContainingWindow(curr_selection_rect)); |
| 858 rect.Offset(-frameview()->scrollOffset().width(), | 874 rect.Offset(-frameview()->scrollOffset().width(), |
| 859 -frameview()->scrollOffset().height()); | 875 -frameview()->scrollOffset().height()); |
| 860 *selection_rect = rect; | 876 *selection_rect = rect; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 878 int WebFrameImpl::OrdinalOfFirstMatchForFrame(WebFrameImpl* frame) const { | 894 int WebFrameImpl::OrdinalOfFirstMatchForFrame(WebFrameImpl* frame) const { |
| 879 int ordinal = 0; | 895 int ordinal = 0; |
| 880 WebFrameImpl* const main_frame_impl = | 896 WebFrameImpl* const main_frame_impl = |
| 881 static_cast<WebFrameImpl*>(GetView()->GetMainFrame()); | 897 static_cast<WebFrameImpl*>(GetView()->GetMainFrame()); |
| 882 // Iterate from the main frame up to (but not including) |frame| and | 898 // Iterate from the main frame up to (but not including) |frame| and |
| 883 // add up the number of matches found so far. | 899 // add up the number of matches found so far. |
| 884 for (WebFrameImpl* it = main_frame_impl; | 900 for (WebFrameImpl* it = main_frame_impl; |
| 885 it != frame; | 901 it != frame; |
| 886 it = static_cast<WebFrameImpl*>( | 902 it = static_cast<WebFrameImpl*>( |
| 887 webview_impl_->GetNextFrameAfter(it, true))) { | 903 webview_impl_->GetNextFrameAfter(it, true))) { |
| 888 ordinal += it->last_match_count_; | 904 if (it->last_match_count_ > 0) |
| 905 ordinal += it->last_match_count_; |
| 889 } | 906 } |
| 890 | 907 |
| 891 return ordinal; | 908 return ordinal; |
| 892 } | 909 } |
| 893 | 910 |
| 894 bool WebFrameImpl::ShouldScopeMatches(FindInPageRequest request) { | 911 bool WebFrameImpl::ShouldScopeMatches(FindInPageRequest request) { |
| 895 // Don't scope if we can't find a frame or if the frame is not visible. | 912 // Don't scope if we can't find a frame or if the frame is not visible. |
| 896 // The user may have closed the tab/application, so abort. | 913 // The user may have closed the tab/application, so abort. |
| 897 if (!frame() || !Visible()) | 914 if (!frame() || !Visible()) |
| 898 return false; | 915 return false; |
| (...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1532 WebErrorImpl weberror_impl(error); | 1549 WebErrorImpl weberror_impl(error); |
| 1533 alt_error_page_fetcher_.reset( | 1550 alt_error_page_fetcher_.reset( |
| 1534 new AltErrorPageResourceFetcher(webview_impl_, weberror_impl, this, | 1551 new AltErrorPageResourceFetcher(webview_impl_, weberror_impl, this, |
| 1535 error_page_url)); | 1552 error_page_url)); |
| 1536 } | 1553 } |
| 1537 | 1554 |
| 1538 void WebFrameImpl::ExecuteJavaScript(const std::string& js_code, | 1555 void WebFrameImpl::ExecuteJavaScript(const std::string& js_code, |
| 1539 const GURL& script_url) { | 1556 const GURL& script_url) { |
| 1540 WebCore::ScriptSourceCode source_code( | 1557 WebCore::ScriptSourceCode source_code( |
| 1541 webkit_glue::StdStringToString(js_code), | 1558 webkit_glue::StdStringToString(js_code), |
| 1542 webkit_glue::GURLToKURL(script_url), | 1559 webkit_glue::GURLToKURL(script_url), |
| 1543 1); // base line number (for errors) | 1560 1); // base line number (for errors) |
| 1544 frame_->loader()->executeScript(source_code); | 1561 frame_->loader()->executeScript(source_code); |
| 1545 } | 1562 } |
| 1546 | 1563 |
| 1547 std::wstring WebFrameImpl::GetName() { | 1564 std::wstring WebFrameImpl::GetName() { |
| 1548 return webkit_glue::StringToStdWString(frame_->tree()->name()); | 1565 return webkit_glue::StringToStdWString(frame_->tree()->name()); |
| 1549 } | 1566 } |
| 1550 | 1567 |
| 1551 WebTextInput* WebFrameImpl::GetTextInput() { | 1568 WebTextInput* WebFrameImpl::GetTextInput() { |
| 1552 if (!webtextinput_impl_.get()) { | 1569 if (!webtextinput_impl_.get()) { |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1821 return password_listeners_.get(input_element); | 1838 return password_listeners_.get(input_element); |
| 1822 } | 1839 } |
| 1823 | 1840 |
| 1824 void WebFrameImpl::ClearPasswordListeners() { | 1841 void WebFrameImpl::ClearPasswordListeners() { |
| 1825 for (PasswordListenerMap::iterator iter = password_listeners_.begin(); | 1842 for (PasswordListenerMap::iterator iter = password_listeners_.begin(); |
| 1826 iter != password_listeners_.end(); ++iter) { | 1843 iter != password_listeners_.end(); ++iter) { |
| 1827 delete iter->second; | 1844 delete iter->second; |
| 1828 } | 1845 } |
| 1829 password_listeners_.clear(); | 1846 password_listeners_.clear(); |
| 1830 } | 1847 } |
| 1831 | |
| OLD | NEW |