From: Vadim Zeitlin Date: Sat, 31 May 2008 13:25:50 +0000 (+0000) Subject: no real changes, just simplify LoadPage() to make it more readable and less redundant X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/e4e487e2a5d51c93cae3a73745128e3dbd23b168 no real changes, just simplify LoadPage() to make it more readable and less redundant git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53879 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/html/htmlwin.cpp b/src/html/htmlwin.cpp index 11c6e1e44c..6437b543c3 100644 --- a/src/html/htmlwin.cpp +++ b/src/html/htmlwin.cpp @@ -472,7 +472,6 @@ bool wxHtmlWindow::LoadPage(const wxString& location) wxBusyCursor busyCursor; - wxFSFile *f; bool rt_val; bool needs_refresh = false; @@ -485,31 +484,28 @@ bool wxHtmlWindow::LoadPage(const wxString& location) (*m_History)[m_HistoryPos].SetPos(y); } - if (location[0] == wxT('#')) + // first check if we're moving to an anchor in the same page + size_t posLocalAnchor = location.Find('#'); + if ( posLocalAnchor != wxString::npos && posLocalAnchor != 0 ) { - // local anchor: - wxString anch = location.Mid(1) /*1 to end*/; - m_tmpCanDrawLocks--; - rt_val = ScrollToAnchor(anch); - m_tmpCanDrawLocks++; - } - else if (location.Find(wxT('#')) != wxNOT_FOUND && location.BeforeFirst(wxT('#')) == m_OpenedPage) - { - wxString anch = location.AfterFirst(wxT('#')); - m_tmpCanDrawLocks--; - rt_val = ScrollToAnchor(anch); - m_tmpCanDrawLocks++; + // check if the part before the anchor is the same as the (either + // relative or absolute) URI of the current page + const wxString beforeAnchor = location.substr(0, posLocalAnchor); + if ( beforeAnchor != m_OpenedPage && + m_FS->GetPath() + beforeAnchor != m_OpenedPage ) + { + // indicate that we're not moving to a local anchor + posLocalAnchor = wxString::npos; + } } - else if (location.Find(wxT('#')) != wxNOT_FOUND && - (m_FS->GetPath() + location.BeforeFirst(wxT('#'))) == m_OpenedPage) + + if ( posLocalAnchor != wxString::npos ) { - wxString anch = location.AfterFirst(wxT('#')); m_tmpCanDrawLocks--; - rt_val = ScrollToAnchor(anch); + rt_val = ScrollToAnchor(location.substr(posLocalAnchor + 1)); m_tmpCanDrawLocks++; } - - else + else // moving to another page { needs_refresh = true; #if wxUSE_STATUSBAR @@ -521,7 +517,7 @@ bool wxHtmlWindow::LoadPage(const wxString& location) } #endif // wxUSE_STATUSBAR - f = m_Parser->OpenURL(wxHTML_URL_PAGE, location); + wxFSFile *f = m_Parser->OpenURL(wxHTML_URL_PAGE, location); // try to interpret 'location' as filename instead of URL: if (f == NULL)