Title: [116746] trunk/Source/WebCore
Revision
116746
Author
shin...@chromium.org
Date
2012-05-11 03:36:31 -0700 (Fri, 11 May 2012)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (116745 => 116746)


--- trunk/Source/WebCore/ChangeLog	2012-05-11 10:26:21 UTC (rev 116745)
+++ trunk/Source/WebCore/ChangeLog	2012-05-11 10:36:31 UTC (rev 116746)
@@ -1,3 +1,44 @@
+2012-05-11  Shinya Kawanaka  <shin...@chromium.org>
+
+        [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):
+
 2012-05-04  Yury Semikhatsky  <yu...@chromium.org>
 
         Web Inspector: console should allow JS execution in the context of an isolated world

Modified: trunk/Source/WebCore/dom/Document.cpp (116745 => 116746)


--- trunk/Source/WebCore/dom/Document.cpp	2012-05-11 10:26:21 UTC (rev 116745)
+++ trunk/Source/WebCore/dom/Document.cpp	2012-05-11 10:36:31 UTC (rev 116746)
@@ -46,6 +46,7 @@
 #include "ContentSecurityPolicy.h"
 #include "CookieJar.h"
 #include "DOMImplementation.h"
+#include "DOMSelection.h"
 #include "DOMWindow.h"
 #include "DateComponents.h"
 #include "DeviceMotionController.h"
@@ -5092,12 +5093,6 @@
         element->updateFocusAppearance(m_updateFocusAppearanceRestoresSelection);
 }
 
-// FF method for accessing the selection added for compatibility.
-DOMSelection* Document::getSelection() const
-{
-    return frame() ? frame()->domWindow()->getSelection() : 0;
-}
-
 void Document::attachRange(Range* range)
 {
     ASSERT(!m_ranges.contains(range));

Modified: trunk/Source/WebCore/dom/Document.h (116745 => 116746)


--- trunk/Source/WebCore/dom/Document.h	2012-05-11 10:26:21 UTC (rev 116745)
+++ trunk/Source/WebCore/dom/Document.h	2012-05-11 10:36:31 UTC (rev 116746)
@@ -969,9 +969,6 @@
     void updateFocusAppearanceSoon(bool restorePreviousSelection);
     void cancelFocusAppearanceUpdate();
         
-    // FF method for accessing the selection added for compatibility.
-    DOMSelection* getSelection() const;
-    
     // Extension for manipulating canvas drawing contexts for use in CSS
     CanvasRenderingContext* getCSSCanvasContext(const String& type, const String& name, int width, int height);
     HTMLCanvasElement* getCSSCanvasElement(const String& name);

Modified: trunk/Source/WebCore/dom/ShadowRoot.cpp (116745 => 116746)


--- trunk/Source/WebCore/dom/ShadowRoot.cpp	2012-05-11 10:26:21 UTC (rev 116745)
+++ trunk/Source/WebCore/dom/ShadowRoot.cpp	2012-05-11 10:36:31 UTC (rev 116746)
@@ -151,8 +151,8 @@
 
 DOMSelection* ShadowRoot::selection()
 {
-    if (document() && document()->domWindow())
-        return document()->domWindow()->getSelection();
+    if (document())
+        return document()->getSelection();
     return 0;
 }
 

Modified: trunk/Source/WebCore/dom/TreeScope.cpp (116745 => 116746)


--- trunk/Source/WebCore/dom/TreeScope.cpp	2012-05-11 10:26:21 UTC (rev 116745)
+++ trunk/Source/WebCore/dom/TreeScope.cpp	2012-05-11 10:36:31 UTC (rev 116746)
@@ -27,6 +27,8 @@
 #include "TreeScope.h"
 
 #include "ContainerNode.h"
+#include "DOMSelection.h"
+#include "DOMWindow.h"
 #include "Document.h"
 #include "Element.h"
 #include "FocusController.h"
@@ -36,6 +38,7 @@
 #include "HTMLMapElement.h"
 #include "HTMLNames.h"
 #include "Page.h"
+#include "RuntimeEnabledFeatures.h"
 #include "TreeScopeAdopter.h"
 #include <wtf/text/AtomicString.h>
 #include <wtf/text/CString.h>
@@ -54,6 +57,10 @@
 
 TreeScope::~TreeScope()
 {
+    if (m_selection) {
+        m_selection->clearTreeScope();
+        m_selection = 0;
+    }
 }
 
 void TreeScope::destroyTreeScopeData()
@@ -116,6 +123,18 @@
     return static_cast<HTMLMapElement*>(m_imageMapsByName.getElementByMapName(AtomicString(name).impl(), this));
 }
 
+DOMSelection* TreeScope::getSelection() const
+{
+    if (!rootNode()->document()->frame())
+        return 0;
+
+    if (m_selection)
+        return m_selection.get();
+
+    m_selection = DOMSelection::create(rootNode()->document());
+    return m_selection.get();
+}
+
 Element* TreeScope::findAnchor(const String& name)
 {
     if (name.isEmpty())

Modified: trunk/Source/WebCore/dom/TreeScope.h (116745 => 116746)


--- trunk/Source/WebCore/dom/TreeScope.h	2012-05-11 10:26:21 UTC (rev 116745)
+++ trunk/Source/WebCore/dom/TreeScope.h	2012-05-11 10:36:31 UTC (rev 116746)
@@ -33,6 +33,7 @@
 namespace WebCore {
 
 class ContainerNode;
+class DOMSelection;
 class Element;
 class HTMLMapElement;
 class Node;
@@ -62,6 +63,8 @@
     void removeNodeListCache() { ASSERT(m_numNodeListCaches > 0); --m_numNodeListCaches; }
     bool hasNodeListCaches() const { return m_numNodeListCaches; }
 
+    DOMSelection* getSelection() const;
+
     // Find first anchor with the given name.
     // First searches for an element with the given ID, but if that fails, then looks
     // for an anchor with the given name. ID matching is always case sensitive, but
@@ -90,6 +93,8 @@
     DocumentOrderedMap m_imageMapsByName;
 
     unsigned m_numNodeListCaches;
+
+    mutable RefPtr<DOMSelection> m_selection;
 };
 
 inline bool TreeScope::hasElementWithId(AtomicStringImpl* id) const

Modified: trunk/Source/WebCore/page/DOMSelection.cpp (116745 => 116746)


--- trunk/Source/WebCore/page/DOMSelection.cpp	2012-05-11 10:26:21 UTC (rev 116745)
+++ trunk/Source/WebCore/page/DOMSelection.cpp	2012-05-11 10:36:31 UTC (rev 116746)
@@ -58,11 +58,17 @@
     return shadowAncestor;
 }
 
-DOMSelection::DOMSelection(Frame* frame)
-    : DOMWindowProperty(frame)
+DOMSelection::DOMSelection(const TreeScope* treeScope)
+    : DOMWindowProperty(treeScope->rootNode()->document()->frame())
+    , m_treeScope(treeScope)
 {
 }
 
+void DOMSelection::clearTreeScope()
+{
+    m_treeScope = 0;
+}
+
 const VisibleSelection& DOMSelection::visibleSelection() const
 {
     ASSERT(m_frame);

Modified: trunk/Source/WebCore/page/DOMSelection.h (116745 => 116746)


--- trunk/Source/WebCore/page/DOMSelection.h	2012-05-11 10:26:21 UTC (rev 116745)
+++ trunk/Source/WebCore/page/DOMSelection.h	2012-05-11 10:36:31 UTC (rev 116746)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2007 Apple Inc.  All rights reserved.
+ * Copyright (C) 2012 Google Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -38,16 +39,19 @@
 namespace WebCore {
 
     class Frame;
+    class Node;
     class Range;
-    class Node;
+    class TreeScope;
     class VisibleSelection;
 
     typedef int ExceptionCode;
 
     class DOMSelection : public RefCounted<DOMSelection>, public DOMWindowProperty {
     public:
-        static PassRefPtr<DOMSelection> create(Frame* frame) { return adoptRef(new DOMSelection(frame)); }
+        static PassRefPtr<DOMSelection> create(const TreeScope* treeScope) { return adoptRef(new DOMSelection(treeScope)); }
 
+        void clearTreeScope();
+
         // Safari Selection Object API
         // These methods return the valid equivalents of internal editing positions.
         Node* baseNode() const;
@@ -88,8 +92,10 @@
         void empty();
 
     private:
-        explicit DOMSelection(Frame*);
+        const TreeScope* m_treeScope;
 
+        explicit DOMSelection(const TreeScope*);
+
         // Convenience method for accessors, does not NULL check m_frame.
         const VisibleSelection& visibleSelection() const;
 

Modified: trunk/Source/WebCore/page/DOMWindow.cpp (116745 => 116746)


--- trunk/Source/WebCore/page/DOMWindow.cpp	2012-05-11 10:26:21 UTC (rev 116745)
+++ trunk/Source/WebCore/page/DOMWindow.cpp	2012-05-11 10:36:31 UTC (rev 116746)
@@ -399,7 +399,6 @@
 #ifndef NDEBUG
     if (!m_suspendedForPageCache) {
         ASSERT(!m_screen);
-        ASSERT(!m_selection);
         ASSERT(!m_history);
         ASSERT(!m_crypto);
         ASSERT(!m_locationbar);
@@ -572,7 +571,6 @@
     m_properties.clear();
 
     m_screen = 0;
-    m_selection = 0;
     m_history = 0;
     m_crypto = 0;
     m_locationbar = 0;
@@ -886,11 +884,10 @@
 
 DOMSelection* DOMWindow::getSelection()
 {
-    if (!isCurrentlyDisplayedInFrame())
+    if (!isCurrentlyDisplayedInFrame() || !m_frame)
         return 0;
-    if (!m_selection)
-        m_selection = DOMSelection::create(m_frame);
-    return m_selection.get();
+
+    return m_frame->document()->getSelection();
 }
 
 Element* DOMWindow::frameElement() const

Modified: trunk/Source/WebCore/page/DOMWindow.h (116745 => 116746)


--- trunk/Source/WebCore/page/DOMWindow.h	2012-05-11 10:26:21 UTC (rev 116745)
+++ trunk/Source/WebCore/page/DOMWindow.h	2012-05-11 10:36:31 UTC (rev 116746)
@@ -428,7 +428,6 @@
         HashSet<DOMWindowProperty*> m_properties;
 
         mutable RefPtr<Screen> m_screen;
-        mutable RefPtr<DOMSelection> m_selection;
         mutable RefPtr<History> m_history;
         mutable RefPtr<Crypto>  m_crypto;
         mutable RefPtr<BarInfo> m_locationbar;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to