Changeset 116746 in webkit


Ignore:
Timestamp:
May 11, 2012 3:36:31 AM (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):

  • dom/TreeScope.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):

  • 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

    r116744 r116746  
     12012-05-11  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        * dom/TreeScope.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        * page/DOMWindow.cpp:
     36        (WebCore::DOMWindow::~DOMWindow):
     37        (WebCore::DOMWindow::clearDOMWindowProperties):
     38        (WebCore::DOMWindow::getSelection):
     39        * page/DOMWindow.h:
     40        (DOMWindow):
     41
    1422012-05-04  Yury Semikhatsky  <yurys@chromium.org>
    243
  • trunk/Source/WebCore/dom/Document.cpp

    r116730 r116746  
    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

    r116724 r116746  
    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

    r116730 r116746  
    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

    r116724 r116746  
    2828
    2929#include "ContainerNode.h"
     30#include "DOMSelection.h"
     31#include "DOMWindow.h"
    3032#include "Document.h"
    3133#include "Element.h"
     
    3739#include "HTMLNames.h"
    3840#include "Page.h"
     41#include "RuntimeEnabledFeatures.h"
    3942#include "TreeScopeAdopter.h"
    4043#include <wtf/text/AtomicString.h>
     
    5558TreeScope::~TreeScope()
    5659{
     60    if (m_selection) {
     61        m_selection->clearTreeScope();
     62        m_selection = 0;
     63    }
    5764}
    5865
     
    115122        return static_cast<HTMLMapElement*>(m_imageMapsByName.getElementByLowercasedMapName(AtomicString(name.lower()).impl(), this));
    116123    return static_cast<HTMLMapElement*>(m_imageMapsByName.getElementByMapName(AtomicString(name).impl(), this));
     124}
     125
     126DOMSelection* TreeScope::getSelection() const
     127{
     128    if (!rootNode()->document()->frame())
     129        return 0;
     130
     131    if (m_selection)
     132        return m_selection.get();
     133
     134    m_selection = DOMSelection::create(rootNode()->document());
     135    return m_selection.get();
    117136}
    118137
  • trunk/Source/WebCore/dom/TreeScope.h

    r116724 r116746  
    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

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

    r116724 r116746  
    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
     
    4749    class DOMSelection : public RefCounted<DOMSelection>, public DOMWindowProperty {
    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
     
    8993
    9094    private:
    91         explicit DOMSelection(Frame*);
     95        const TreeScope* m_treeScope;
     96
     97        explicit DOMSelection(const TreeScope*);
    9298
    9399        // Convenience method for accessors, does not NULL check m_frame.
  • trunk/Source/WebCore/page/DOMWindow.cpp

    r116724 r116746  
    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

    r116724 r116746  
    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.