Title: [166937] trunk/Source/WebCore
Revision
166937
Author
d...@apple.com
Date
2014-04-08 11:06:11 -0700 (Tue, 08 Apr 2014)

Log Message

Allow elements to register for changes in page scale
https://bugs.webkit.org/show_bug.cgi?id=131319

Reviewed by Eric Carlson.

Some parts of WebCore need to react to changes in the page
scale factor, such as resizing when the user zooms. A followup
patch will enable this for media controls - this simply lays
the groundwork.

At the moment we only allow HTMLMediaElements to register, but if
necessary this could be expanded in the future.

* dom/Document.cpp: New methods to keep a list of HTMLMediaElements that
are interested in updates.
(WebCore::Document::registerForPageScaleFactorChangedCallbacks):
(WebCore::Document::unregisterForPageScaleFactorChangedCallbacks):
(WebCore::Document::pageScaleFactorChanged):
* dom/Document.h:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::HTMLMediaElement):
(WebCore::HTMLMediaElement::registerWithDocument): Add ourselves to the
the document's pageScale callback.
(WebCore::HTMLMediaElement::unregisterWithDocument): Remove ourselves from the
the document's pageScale callback.
(WebCore::HTMLMediaElement::setMediaControlsDependOnPageScaleFactor): Add/remove ourselves to/from
the callback if necessary.
(WebCore::HTMLMediaElement::pageScaleFactorChanged): The callback function. Empty for now.
* html/HTMLMediaElement.h:
(WebCore::HTMLMediaElement::mediaControlsDependOnPageScaleFactor): Accessor.
* page/Page.cpp:
(WebCore::Page::setPageScaleFactor): Tell all documents that the user has zoomed.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (166936 => 166937)


--- trunk/Source/WebCore/ChangeLog	2014-04-08 18:04:59 UTC (rev 166936)
+++ trunk/Source/WebCore/ChangeLog	2014-04-08 18:06:11 UTC (rev 166937)
@@ -1,3 +1,38 @@
+2014-04-07  Dean Jackson  <d...@apple.com>
+
+        Allow elements to register for changes in page scale
+        https://bugs.webkit.org/show_bug.cgi?id=131319
+
+        Reviewed by Eric Carlson.
+
+        Some parts of WebCore need to react to changes in the page
+        scale factor, such as resizing when the user zooms. A followup
+        patch will enable this for media controls - this simply lays
+        the groundwork.
+
+        At the moment we only allow HTMLMediaElements to register, but if
+        necessary this could be expanded in the future.
+
+        * dom/Document.cpp: New methods to keep a list of HTMLMediaElements that
+        are interested in updates.
+        (WebCore::Document::registerForPageScaleFactorChangedCallbacks):
+        (WebCore::Document::unregisterForPageScaleFactorChangedCallbacks):
+        (WebCore::Document::pageScaleFactorChanged):
+        * dom/Document.h:
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::HTMLMediaElement):
+        (WebCore::HTMLMediaElement::registerWithDocument): Add ourselves to the
+        the document's pageScale callback.
+        (WebCore::HTMLMediaElement::unregisterWithDocument): Remove ourselves from the
+        the document's pageScale callback.
+        (WebCore::HTMLMediaElement::setMediaControlsDependOnPageScaleFactor): Add/remove ourselves to/from
+        the callback if necessary.
+        (WebCore::HTMLMediaElement::pageScaleFactorChanged): The callback function. Empty for now.
+        * html/HTMLMediaElement.h:
+        (WebCore::HTMLMediaElement::mediaControlsDependOnPageScaleFactor): Accessor.
+        * page/Page.cpp:
+        (WebCore::Page::setPageScaleFactor): Tell all documents that the user has zoomed.
+
 2014-04-08  pe...@outlook.com  <pe...@outlook.com>
 
         [WinCairo] Compile error in TextureMapper.h

Modified: trunk/Source/WebCore/dom/Document.cpp (166936 => 166937)


--- trunk/Source/WebCore/dom/Document.cpp	2014-04-08 18:04:59 UTC (rev 166936)
+++ trunk/Source/WebCore/dom/Document.cpp	2014-04-08 18:06:11 UTC (rev 166937)
@@ -4195,6 +4195,24 @@
 }
 #endif
 
+#if ENABLE(MEDIA_CONTROLS_SCRIPT)
+void Document::registerForPageScaleFactorChangedCallbacks(HTMLMediaElement* element)
+{
+    m_pageScaleFactorChangedElements.add(element);
+}
+
+void Document::unregisterForPageScaleFactorChangedCallbacks(HTMLMediaElement* element)
+{
+    m_pageScaleFactorChangedElements.remove(element);
+}
+
+void Document::pageScaleFactorChanged()
+{
+    for (HTMLMediaElement* mediaElement : m_pageScaleFactorChangedElements)
+        mediaElement->pageScaleFactorChanged();
+}
+#endif
+
 void Document::setShouldCreateRenderers(bool f)
 {
     m_createRenderers = f;

Modified: trunk/Source/WebCore/dom/Document.h (166936 => 166937)


--- trunk/Source/WebCore/dom/Document.h	2014-04-08 18:04:59 UTC (rev 166936)
+++ trunk/Source/WebCore/dom/Document.h	2014-04-08 18:06:11 UTC (rev 166937)
@@ -109,6 +109,7 @@
 class HTMLIFrameElement;
 class HTMLImageElement;
 class HTMLMapElement;
+class HTMLMediaElement;
 class HTMLNameCollection;
 class HTMLScriptElement;
 class HitTestRequest;
@@ -1040,6 +1041,12 @@
     void captionPreferencesChanged();
 #endif
 
+#if ENABLE(MEDIA_CONTROLS_SCRIPT)
+    void registerForPageScaleFactorChangedCallbacks(HTMLMediaElement*);
+    void unregisterForPageScaleFactorChangedCallbacks(HTMLMediaElement*);
+    void pageScaleFactorChanged();
+#endif
+
 #if ENABLE(PAGE_VISIBILITY_API)
     void registerForVisibilityStateChangedCallbacks(Element*);
     void unregisterForVisibilityStateChangedCallbacks(Element*);
@@ -1531,6 +1538,10 @@
     HashSet<Element*> m_captionPreferencesChangedElements;
 #endif
 
+#if ENABLE(MEDIA_CONTROLS_SCRIPT)
+    HashSet<HTMLMediaElement*> m_pageScaleFactorChangedElements;
+#endif
+
 #if ENABLE(PAGE_VISIBILITY_API)
     HashSet<Element*> m_visibilityStateCallbackElements;
 #endif

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (166936 => 166937)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2014-04-08 18:04:59 UTC (rev 166936)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2014-04-08 18:06:11 UTC (rev 166937)
@@ -330,6 +330,9 @@
 #if PLATFORM(IOS)
     , m_requestingPlay(false)
 #endif
+#if ENABLE(MEDIA_CONTROLS_SCRIPT)
+    , m_mediaControlsDependOnPageScaleFactor(false)
+#endif
 #if ENABLE(VIDEO_TRACK)
     , m_tracksAreReady(true)
     , m_haveVisibleTextTrack(false)
@@ -451,6 +454,11 @@
     document.registerForCaptionPreferencesChangedCallbacks(this);
 #endif
 
+#if ENABLE(MEDIA_CONTROLS_SCRIPT)
+    if (m_mediaControlsDependOnPageScaleFactor)
+        document.registerForPageScaleFactorChangedCallbacks(this);
+#endif
+
     addElementToDocumentMap(*this, document);
 }
 
@@ -471,6 +479,11 @@
     document.unregisterForCaptionPreferencesChangedCallbacks(this);
 #endif
 
+#if ENABLE(MEDIA_CONTROLS_SCRIPT)
+    if (m_mediaControlsDependOnPageScaleFactor)
+        document.unregisterForPageScaleFactorChangedCallbacks(this);
+#endif
+
     removeElementFromDocumentMap(*this, document);
 }
 
@@ -5979,6 +5992,24 @@
     if (exec->hadException())
         exec->clearException();
 }
+
+void HTMLMediaElement::setMediaControlsDependOnPageScaleFactor(bool dependsOnPageScale)
+{
+    LOG(Media, "MediaElement::setMediaControlsDependPageScaleFactor = %s", boolString(dependsOnPageScale));
+    if (m_mediaControlsDependOnPageScaleFactor == dependsOnPageScale)
+        return;
+
+    m_mediaControlsDependOnPageScaleFactor = dependsOnPageScale;
+
+    if (m_mediaControlsDependOnPageScaleFactor)
+        document().registerForPageScaleFactorChangedCallbacks(this);
+    else
+        document().unregisterForPageScaleFactorChangedCallbacks(this);
+}
+
+void HTMLMediaElement::pageScaleFactorChanged()
+{
+}
 #endif // ENABLE(MEDIA_CONTROLS_SCRIPT)
 
 unsigned long long HTMLMediaElement::fileSize() const

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (166936 => 166937)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2014-04-08 18:04:59 UTC (rev 166936)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2014-04-08 18:06:11 UTC (rev 166937)
@@ -456,6 +456,10 @@
     MediaPlayer::Preload preloadValue() const { return m_preload; }
     HTMLMediaSession& mediaSession() const { return *m_mediaSession; }
 
+#if ENABLE(MEDIA_CONTROLS_SCRIPT)
+    void pageScaleFactorChanged();
+#endif
+
 protected:
     HTMLMediaElement(const QualifiedName&, Document&, bool);
     virtual ~HTMLMediaElement();
@@ -482,6 +486,11 @@
 
     virtual RenderPtr<RenderElement> createElementRenderer(PassRef<RenderStyle>) override;
 
+#if ENABLE(MEDIA_CONTROLS_SCRIPT)
+    bool mediaControlsDependOnPageScaleFactor() const { return m_mediaControlsDependOnPageScaleFactor; }
+    void setMediaControlsDependOnPageScaleFactor(bool);
+#endif
+
 private:
     void createMediaPlayer();
 
@@ -828,6 +837,10 @@
     bool m_requestingPlay : 1;
 #endif
 
+#if ENABLE(MEDIA_CONTROLS_SCRIPT)
+    bool m_mediaControlsDependOnPageScaleFactor : 1;
+#endif
+
 #if ENABLE(VIDEO_TRACK)
     bool m_tracksAreReady : 1;
     bool m_haveVisibleTextTrack : 1;
@@ -877,6 +890,7 @@
     size_t m_reportedExtraMemoryCost;
 
 #if ENABLE(MEDIA_CONTROLS_SCRIPT)
+    friend class MediaControlsHost;
     RefPtr<MediaControlsHost> m_mediaControlsHost;
     RefPtr<DOMWrapperWorld> m_isolatedWorld;
 #endif

Modified: trunk/Source/WebCore/page/Page.cpp (166936 => 166937)


--- trunk/Source/WebCore/page/Page.cpp	2014-04-08 18:04:59 UTC (rev 166936)
+++ trunk/Source/WebCore/page/Page.cpp	2014-04-08 18:06:11 UTC (rev 166937)
@@ -730,6 +730,11 @@
         if (!view->delegatesScrolling())
             view->setScrollPosition(origin);
     }
+
+#if ENABLE(MEDIA_CONTROLS_SCRIPT)
+    for (Frame* frame = &mainFrame(); frame; frame = frame->tree().traverseNext())
+        frame->document()->pageScaleFactorChanged();
+#endif
 }
 
 void Page::setDeviceScaleFactor(float scaleFactor)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to