Changeset 49608 in webkit


Ignore:
Timestamp:
Oct 14, 2009 10:15:54 PM (15 years ago)
Author:
eric@webkit.org
Message:

2009-10-14 Adam Barth <abarth@webkit.org>

Reviewed by Sam Weinig.

Move scrolling code from FrameLoader to FrameView
https://bugs.webkit.org/show_bug.cgi?id=30370

This code is about controlling the Frame's view, not about loading
stuff into the frame.

  • loader/FrameLoader.cpp: (WebCore::FrameLoader::finishedParsing): (WebCore::FrameLoader::scrollToAnchor):
  • page/FrameView.cpp: (WebCore::FrameView::scrollToFragment): (WebCore::FrameView::scrollToAnchor):
  • page/FrameView.h:
Location:
trunk/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r49607 r49608  
     12009-10-14  Adam Barth  <abarth@webkit.org>
     2
     3        Reviewed by Sam Weinig.
     4
     5        Move scrolling code from FrameLoader to FrameView
     6        https://bugs.webkit.org/show_bug.cgi?id=30370
     7
     8        This code is about controlling the Frame's view, not about loading
     9        stuff into the frame.
     10
     11        * loader/FrameLoader.cpp:
     12        (WebCore::FrameLoader::finishedParsing):
     13        (WebCore::FrameLoader::scrollToAnchor):
     14        * page/FrameView.cpp:
     15        (WebCore::FrameView::scrollToFragment):
     16        (WebCore::FrameView::scrollToAnchor):
     17        * page/FrameView.h:
     18
    1192009-10-14  Oliver Hunt  <oliver@apple.com>
    220
  • trunk/WebCore/dom/Document.cpp

    r49507 r49608  
    23552355        m_tokenizer->executeScriptsWaitingForStylesheets();
    23562356
    2357     if (!m_pendingStylesheets && m_gotoAnchorNeededAfterStylesheetsLoad && m_frame)
    2358         m_frame->loader()->gotoAnchor();
     2357    if (!m_pendingStylesheets && m_gotoAnchorNeededAfterStylesheetsLoad && view())
     2358        view()->scrollToFragment(m_frame->loader()->url());
    23592359}
    23602360
  • trunk/WebCore/loader/FrameLoader.cpp

    r49507 r49608  
    10201020}
    10211021
    1022 void FrameLoader::gotoAnchor()
    1023 {
    1024     // If our URL has no ref, then we have no place we need to jump to.
    1025     // OTOH If CSS target was set previously, we want to set it to 0, recalc
    1026     // and possibly repaint because :target pseudo class may have been
    1027     // set (see bug 11321).
    1028     if (!m_URL.hasFragmentIdentifier() && !m_frame->document()->cssTarget())
    1029         return;
    1030 
    1031     String fragmentIdentifier = m_URL.fragmentIdentifier();
    1032     if (gotoAnchor(fragmentIdentifier))
    1033         return;
    1034 
    1035     // Try again after decoding the ref, based on the document's encoding.
    1036     if (m_decoder)
    1037         gotoAnchor(decodeURLEscapeSequences(fragmentIdentifier, m_decoder->encoding()));
    1038 }
    1039 
    10401022void FrameLoader::finishedParsing()
    10411023{
     
    10601042    // If not, remove them, relayout, and repaint.
    10611043    m_frame->view()->restoreScrollbar();
    1062 
    1063     gotoAnchor();
     1044    m_frame->view()->scrollToFragment(m_URL);
    10641045}
    10651046
     
    12421223    Settings* settings = m_frame->settings();
    12431224    return settings ? settings->defaultTextEncodingName() : String();
    1244 }
    1245 
    1246 bool FrameLoader::gotoAnchor(const String& name)
    1247 {
    1248     ASSERT(m_frame->document());
    1249 
    1250     if (!m_frame->document()->haveStylesheetsLoaded()) {
    1251         m_frame->document()->setGotoAnchorNeededAfterStylesheetsLoad(true);
    1252         return false;
    1253     }
    1254 
    1255     m_frame->document()->setGotoAnchorNeededAfterStylesheetsLoad(false);
    1256 
    1257     Element* anchorNode = m_frame->document()->findAnchor(name);
    1258 
    1259 #if ENABLE(SVG)
    1260     if (m_frame->document()->isSVGDocument()) {
    1261         if (name.startsWith("xpointer(")) {
    1262             // We need to parse the xpointer reference here
    1263         } else if (name.startsWith("svgView(")) {
    1264             RefPtr<SVGSVGElement> svg = static_cast<SVGDocument*>(m_frame->document())->rootElement();
    1265             if (!svg->currentView()->parseViewSpec(name))
    1266                 return false;
    1267             svg->setUseCurrentView(true);
    1268         } else {
    1269             if (anchorNode && anchorNode->hasTagName(SVGNames::viewTag)) {
    1270                 RefPtr<SVGViewElement> viewElement = anchorNode->hasTagName(SVGNames::viewTag) ? static_cast<SVGViewElement*>(anchorNode) : 0;
    1271                 if (viewElement.get()) {
    1272                     RefPtr<SVGSVGElement> svg = static_cast<SVGSVGElement*>(SVGLocatable::nearestViewportElement(viewElement.get()));
    1273                     svg->inheritViewAttributes(viewElement.get());
    1274                 }
    1275             }
    1276         }
    1277         // FIXME: need to decide which <svg> to focus on, and zoom to that one
    1278         // FIXME: need to actually "highlight" the viewTarget(s)
    1279     }
    1280 #endif
    1281 
    1282     m_frame->document()->setCSSTarget(anchorNode); // Setting to null will clear the current target.
    1283  
    1284     // Implement the rule that "" and "top" both mean top of page as in other browsers.
    1285     if (!anchorNode && !(name.isEmpty() || equalIgnoringCase(name, "top")))
    1286         return false;
    1287 
    1288     if (FrameView* view = m_frame->view())
    1289         view->maintainScrollPositionAtAnchor(anchorNode ? static_cast<Node*>(anchorNode) : m_frame->document());
    1290 
    1291     return true;
    12921225}
    12931226
     
    17671700    m_frame->eventHandler()->stopAutoscrollTimer();
    17681701    started();
    1769     gotoAnchor();
     1702    if (FrameView* view = m_frame->view())
     1703        view->scrollToFragment(m_URL);
    17701704
    17711705    // It's important to model this as a load that starts and immediately finishes.
  • trunk/WebCore/loader/FrameLoader.h

    r49415 r49608  
    247247        String encoding() const;
    248248
    249         void gotoAnchor();
    250 
    251249        void tokenizerProcessedData();
    252250
     
    429427        Frame* loadSubframe(HTMLFrameOwnerElement*, const KURL&, const String& name, const String& referrer);
    430428
    431         bool gotoAnchor(const String& name); // returns true if the anchor was found
    432429        void scrollToAnchor(const KURL&);
    433430
  • trunk/WebCore/page/FrameView.cpp

    r48533 r49608  
    5353#include "RenderView.h"
    5454#include "Settings.h"
     55#include "TextResourceDecoder.h"
    5556#include <wtf/CurrentTime.h>
    5657
     
    5859#include "RenderLayerCompositor.h"
    5960#endif
     61
     62#if ENABLE(SVG)
     63#include "SVGDocument.h"
     64#include "SVGLocatable.h"
     65#include "SVGNames.h"
     66#include "SVGPreserveAspectRatio.h"
     67#include "SVGSVGElement.h"
     68#include "SVGViewElement.h"
     69#include "SVGViewSpec.h"
     70#endif
     71
    6072
    6173namespace WebCore {
     
    770782}
    771783
     784bool FrameView::scrollToFragment(const KURL& url)
     785{
     786    // If our URL has no ref, then we have no place we need to jump to.
     787    // OTOH If CSS target was set previously, we want to set it to 0, recalc
     788    // and possibly repaint because :target pseudo class may have been
     789    // set (see bug 11321).
     790    if (!url.hasFragmentIdentifier() && !m_frame->document()->cssTarget())
     791        return false;
     792
     793    String fragmentIdentifier = url.fragmentIdentifier();
     794    if (scrollToAnchor(fragmentIdentifier))
     795        return true;
     796
     797    // Try again after decoding the ref, based on the document's encoding.
     798    if (TextResourceDecoder* decoder = m_frame->document()->decoder())
     799        return scrollToAnchor(decodeURLEscapeSequences(fragmentIdentifier, decoder->encoding()));
     800
     801    return false;
     802}
     803
     804bool FrameView::scrollToAnchor(const String& name)
     805{
     806    ASSERT(m_frame->document());
     807
     808    if (!m_frame->document()->haveStylesheetsLoaded()) {
     809        m_frame->document()->setGotoAnchorNeededAfterStylesheetsLoad(true);
     810        return false;
     811    }
     812
     813    m_frame->document()->setGotoAnchorNeededAfterStylesheetsLoad(false);
     814
     815    Element* anchorNode = m_frame->document()->findAnchor(name);
     816
     817#if ENABLE(SVG)
     818    if (m_frame->document()->isSVGDocument()) {
     819        if (name.startsWith("xpointer(")) {
     820            // We need to parse the xpointer reference here
     821        } else if (name.startsWith("svgView(")) {
     822            RefPtr<SVGSVGElement> svg = static_cast<SVGDocument*>(m_frame->document())->rootElement();
     823            if (!svg->currentView()->parseViewSpec(name))
     824                return false;
     825            svg->setUseCurrentView(true);
     826        } else {
     827            if (anchorNode && anchorNode->hasTagName(SVGNames::viewTag)) {
     828                RefPtr<SVGViewElement> viewElement = anchorNode->hasTagName(SVGNames::viewTag) ? static_cast<SVGViewElement*>(anchorNode) : 0;
     829                if (viewElement.get()) {
     830                    RefPtr<SVGSVGElement> svg = static_cast<SVGSVGElement*>(SVGLocatable::nearestViewportElement(viewElement.get()));
     831                    svg->inheritViewAttributes(viewElement.get());
     832                }
     833            }
     834        }
     835        // FIXME: need to decide which <svg> to focus on, and zoom to that one
     836        // FIXME: need to actually "highlight" the viewTarget(s)
     837    }
     838#endif
     839
     840    m_frame->document()->setCSSTarget(anchorNode); // Setting to null will clear the current target.
     841 
     842    // Implement the rule that "" and "top" both mean top of page as in other browsers.
     843    if (!anchorNode && !(name.isEmpty() || equalIgnoringCase(name, "top")))
     844        return false;
     845
     846    maintainScrollPositionAtAnchor(anchorNode ? static_cast<Node*>(anchorNode) : m_frame->document());
     847    return true;
     848}
     849
    772850void FrameView::maintainScrollPositionAtAnchor(Node* anchorNode)
    773851{
  • trunk/WebCore/page/FrameView.h

    r48526 r49608  
    184184    void adjustPageHeight(float* newBottom, float oldTop, float oldBottom, float bottomLimit);
    185185
     186    bool scrollToFragment(const KURL&);
     187    bool scrollToAnchor(const String&);
    186188    void maintainScrollPositionAtAnchor(Node*);
    187189
Note: See TracChangeset for help on using the changeset viewer.