Changeset 116715 in webkit


Ignore:
Timestamp:
May 10, 2012 6:45:47 PM (12 years ago)
Author:
shinyak@chromium.org
Message:

[Refactoring] Move Selection from DOMWindow to TreeScope.
https://bugs.webkit.org/show_bug.cgi?id=82699

Reviewed by Ryosuke Niwa.

Since ShadowRoot will also manage its own version of DOMSelection, we would like to
share the code among Document and DOMSelection. This patch moves DOMSelection from DOMWindow to TreeScope
so that ShadowRoot can also use it.

No new tests, should covered by existing tests.

  • dom/Document.cpp:

(WebCore::Document::updateFocusAppearanceTimerFired):

  • dom/Document.h:

(Document):

  • dom/ShadowRoot.cpp:

(WebCore::ShadowRoot::selection):

  • do/mTreeScope.cpp:

(WebCore::TreeScope::~TreeScope):
(WebCore::TreeScope::getSelection):
(WebCore):

  • dom/TreeScope.h:

(WebCore):
(TreeScope):

  • page/DOMSelection.cpp:

(WebCore::DOMSelection::DOMSelection):
(WebCore::DOMSelection::clearTreeScope):
(WebCore):

  • page/DOMSelection.h:

(WebCore):
(WebCore::DOMSelection::create):
(DOMSelection):
(WebCore::DOMSelection::frame):

  • page/DOMWindow.cpp:

(WebCore::DOMWindow::~DOMWindow):
(WebCore::DOMWindow::clearDOMWindowProperties):
(WebCore::DOMWindow::getSelection):

  • page/DOMWindow.h:

(DOMWindow):

Location:
trunk/Source/WebCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r116714 r116715  
     12012-05-10  Shinya Kawanaka  <shinyak@chromium.org>
     2
     3        [Refactoring] Move Selection from DOMWindow to TreeScope.
     4        https://bugs.webkit.org/show_bug.cgi?id=82699
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Since ShadowRoot will also manage its own version of DOMSelection, we would like to
     9        share the code among Document and DOMSelection. This patch moves DOMSelection from DOMWindow to TreeScope
     10        so that ShadowRoot can also use it.
     11
     12        No new tests, should covered by existing tests.
     13
     14        * dom/Document.cpp:
     15        (WebCore::Document::updateFocusAppearanceTimerFired):
     16        * dom/Document.h:
     17        (Document):
     18        * dom/ShadowRoot.cpp:
     19        (WebCore::ShadowRoot::selection):
     20        * do/mTreeScope.cpp:
     21        (WebCore::TreeScope::~TreeScope):
     22        (WebCore::TreeScope::getSelection):
     23        (WebCore):
     24        * dom/TreeScope.h:
     25        (WebCore):
     26        (TreeScope):
     27        * page/DOMSelection.cpp:
     28        (WebCore::DOMSelection::DOMSelection):
     29        (WebCore::DOMSelection::clearTreeScope):
     30        (WebCore):
     31        * page/DOMSelection.h:
     32        (WebCore):
     33        (WebCore::DOMSelection::create):
     34        (DOMSelection):
     35        (WebCore::DOMSelection::frame):
     36        * page/DOMWindow.cpp:
     37        (WebCore::DOMWindow::~DOMWindow):
     38        (WebCore::DOMWindow::clearDOMWindowProperties):
     39        (WebCore::DOMWindow::getSelection):
     40        * page/DOMWindow.h:
     41        (DOMWindow):
     42
    1432012-05-10  Kent Tamura  <tkent@chromium.org>
    244
  • trunk/Source/WebCore/dom/Document.cpp

    r116694 r116715  
    4747#include "CookieJar.h"
    4848#include "DOMImplementation.h"
     49#include "DOMSelection.h"
    4950#include "DOMWindow.h"
    5051#include "DateComponents.h"
     
    50935094}
    50945095
    5095 // FF method for accessing the selection added for compatibility.
    5096 DOMSelection* Document::getSelection() const
    5097 {
    5098     return frame() ? frame()->domWindow()->getSelection() : 0;
    5099 }
    5100 
    51015096void Document::attachRange(Range* range)
    51025097{
  • trunk/Source/WebCore/dom/Document.h

    r116595 r116715  
    970970    void cancelFocusAppearanceUpdate();
    971971       
    972     // FF method for accessing the selection added for compatibility.
    973     DOMSelection* getSelection() const;
    974    
    975972    // Extension for manipulating canvas drawing contexts for use in CSS
    976973    CanvasRenderingContext* getCSSCanvasContext(const String& type, const String& name, int width, int height);
  • trunk/Source/WebCore/dom/ShadowRoot.cpp

    r116521 r116715  
    152152DOMSelection* ShadowRoot::selection()
    153153{
    154     if (document() && document()->domWindow())
    155         return document()->domWindow()->getSelection();
     154    if (document())
     155        return document()->getSelection();
    156156    return 0;
    157157}
  • trunk/Source/WebCore/dom/TreeScope.cpp

    r116521 r116715  
    2828
    2929#include "ContainerNode.h"
     30#include "DOMSelection.h"
    3031#include "Document.h"
    3132#include "Element.h"
     
    3738#include "HTMLNames.h"
    3839#include "Page.h"
     40#include "RuntimeEnabledFeatures.h"
    3941#include "TreeScopeAdopter.h"
    4042#include <wtf/text/AtomicString.h>
     
    5557TreeScope::~TreeScope()
    5658{
     59    if (m_selection) {
     60        m_selection->clearTreeScope();
     61        m_selection = 0;
     62    }
    5763}
    5864
     
    115121        return static_cast<HTMLMapElement*>(m_imageMapsByName.getElementByLowercasedMapName(AtomicString(name.lower()).impl(), this));
    116122    return static_cast<HTMLMapElement*>(m_imageMapsByName.getElementByMapName(AtomicString(name).impl(), this));
     123}
     124
     125DOMSelection* TreeScope::getSelection() const
     126{
     127    if (!rootNode()->document()->frame())
     128        return 0;
     129
     130    if (m_selection)
     131        return m_selection.get();
     132
     133    m_selection = DOMSelection::create(rootNode()->document());
     134    return m_selection.get();
    117135}
    118136
  • trunk/Source/WebCore/dom/TreeScope.h

    r116521 r116715  
    3434
    3535class ContainerNode;
     36class DOMSelection;
    3637class Element;
    3738class HTMLMapElement;
     
    6364    bool hasNodeListCaches() const { return m_numNodeListCaches; }
    6465
     66    DOMSelection* getSelection() const;
     67
    6568    // Find first anchor with the given name.
    6669    // First searches for an element with the given ID, but if that fails, then looks
     
    9194
    9295    unsigned m_numNodeListCaches;
     96
     97    mutable RefPtr<DOMSelection> m_selection;
    9398};
    9499
  • trunk/Source/WebCore/page/DOMSelection.cpp

    r113276 r116715  
    5959}
    6060
    61 DOMSelection::DOMSelection(Frame* frame)
    62     : DOMWindowProperty(frame)
    63 {
     61DOMSelection::DOMSelection(const TreeScope* treeScope)
     62    : m_treeScope(treeScope)
     63    , m_frame(treeScope->rootNode()->document()->frame())
     64{
     65}
     66
     67void DOMSelection::clearTreeScope()
     68{
     69    m_frame = 0;
     70    m_treeScope = 0;
    6471}
    6572
  • trunk/Source/WebCore/page/DOMSelection.h

    r104380 r116715  
    11/*
    22 * Copyright (C) 2007 Apple Inc.  All rights reserved.
     3 * Copyright (C) 2012 Google Inc.  All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3940
    4041    class Frame;
     42    class Node;
    4143    class Range;
    42     class Node;
     44    class TreeScope;
    4345    class VisibleSelection;
    4446
    4547    typedef int ExceptionCode;
    4648
    47     class DOMSelection : public RefCounted<DOMSelection>, public DOMWindowProperty {
     49    class DOMSelection : public RefCounted<DOMSelection> {
    4850    public:
    49         static PassRefPtr<DOMSelection> create(Frame* frame) { return adoptRef(new DOMSelection(frame)); }
     51        static PassRefPtr<DOMSelection> create(const TreeScope* treeScope) { return adoptRef(new DOMSelection(treeScope)); }
     52
     53        void clearTreeScope();
    5054
    5155        // Safari Selection Object API
     
    8589        String toString();
    8690
     91        Frame* frame() const { return m_frame; }
     92
    8793        // Microsoft Selection Object API
    8894        void empty();
    8995
    9096    private:
    91         explicit DOMSelection(Frame*);
     97        const TreeScope* m_treeScope;
     98        Frame* m_frame;
     99
     100        explicit DOMSelection(const TreeScope*);
    92101
    93102        // Convenience method for accessors, does not NULL check m_frame.
  • trunk/Source/WebCore/page/DOMWindow.cpp

    r116608 r116715  
    400400    if (!m_suspendedForPageCache) {
    401401        ASSERT(!m_screen);
    402         ASSERT(!m_selection);
    403402        ASSERT(!m_history);
    404403        ASSERT(!m_crypto);
     
    573572
    574573    m_screen = 0;
    575     m_selection = 0;
    576574    m_history = 0;
    577575    m_crypto = 0;
     
    887885DOMSelection* DOMWindow::getSelection()
    888886{
    889     if (!isCurrentlyDisplayedInFrame())
    890         return 0;
    891     if (!m_selection)
    892         m_selection = DOMSelection::create(m_frame);
    893     return m_selection.get();
     887    if (!isCurrentlyDisplayedInFrame() || !m_frame)
     888        return 0;
     889
     890    return m_frame->document()->getSelection();
    894891}
    895892
  • trunk/Source/WebCore/page/DOMWindow.h

    r116608 r116715  
    429429
    430430        mutable RefPtr<Screen> m_screen;
    431         mutable RefPtr<DOMSelection> m_selection;
    432431        mutable RefPtr<History> m_history;
    433432        mutable RefPtr<Crypto>  m_crypto;
Note: See TracChangeset for help on using the changeset viewer.