From e21dde09498cc6a9341892b2e5a10a66f88f754c Mon Sep 17 00:00:00 2001 From: Mike Conley Date: Wed, 22 Apr 2015 10:58:33 -0400 Subject: [PATCH] Bug 1096093 - Send ThemeRefresh message from parent down to content process. r=smaug. --HG-- extra : rebase_source : 2103f47a75612dc4f1b719f5913d6cc14be5fbf7 --- dom/ipc/PBrowser.ipdl | 7 +++++++ dom/ipc/TabChild.cpp | 23 +++++++++++++++++++++-- dom/ipc/TabChild.h | 2 ++ dom/ipc/TabParent.cpp | 14 ++++++++++++++ dom/ipc/TabParent.h | 1 + layout/base/nsPresContext.cpp | 11 +++++++++++ 6 files changed, 56 insertions(+), 2 deletions(-) diff --git a/dom/ipc/PBrowser.ipdl b/dom/ipc/PBrowser.ipdl index df74b1eea1cf..36c8ff79ceda 100644 --- a/dom/ipc/PBrowser.ipdl +++ b/dom/ipc/PBrowser.ipdl @@ -58,6 +58,7 @@ using mozilla::layers::GeckoContentController::APZStateChange from "mozilla/laye using mozilla::WritingMode from "mozilla/WritingModes.h"; using mozilla::layers::TouchBehaviorFlags from "mozilla/layers/APZUtils.h"; using nsIWidget::TouchPointerState from "nsIWidget.h"; +using struct LookAndFeelInt from "mozilla/widget/WidgetMessageUtils.h"; namespace mozilla { namespace dom { @@ -673,6 +674,12 @@ child: */ UIResolutionChanged(); + /** + * Tell the child that the system theme has changed, and that a repaint + * is necessary. + */ + ThemeChanged(LookAndFeelInt[] lookAndFeelIntCache); + /** * Tell the child of an app's offline status */ diff --git a/dom/ipc/TabChild.cpp b/dom/ipc/TabChild.cpp index 5bb4f164d9b7..fa2ba3836a58 100644 --- a/dom/ipc/TabChild.cpp +++ b/dom/ipc/TabChild.cpp @@ -3140,8 +3140,27 @@ TabChild::RecvUIResolutionChanged() static_cast(mWidget.get())->ClearBackingScaleCache(); nsCOMPtr document(GetDocument()); nsCOMPtr presShell = document->GetShell(); - nsRefPtr presContext = presShell->GetPresContext(); - presContext->UIResolutionChanged(); + if (presShell) { + nsRefPtr presContext = presShell->GetPresContext(); + if (presContext) { + presContext->UIResolutionChanged(); + } + } + return true; +} + +bool +TabChild::RecvThemeChanged(nsTArray&& aLookAndFeelIntCache) +{ + LookAndFeel::SetIntCache(aLookAndFeelIntCache); + nsCOMPtr document(GetDocument()); + nsCOMPtr presShell = document->GetShell(); + if (presShell) { + nsRefPtr presContext = presShell->GetPresContext(); + if (presContext) { + presContext->ThemeChanged(); + } + } return true; } diff --git a/dom/ipc/TabChild.h b/dom/ipc/TabChild.h index e9da68c1112b..fabefb4674dc 100644 --- a/dom/ipc/TabChild.h +++ b/dom/ipc/TabChild.h @@ -480,6 +480,8 @@ public: virtual bool RecvUIResolutionChanged() override; + virtual bool RecvThemeChanged(nsTArray&& aLookAndFeelIntCache) override; + /** * Native widget remoting protocol for use with windowed plugins with e10s. */ diff --git a/dom/ipc/TabParent.cpp b/dom/ipc/TabParent.cpp index d927bb2a7462..0eba65a491e7 100644 --- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -24,6 +24,7 @@ #include "mozilla/layers/CompositorParent.h" #include "mozilla/layers/InputAPZContext.h" #include "mozilla/layout/RenderFrameParent.h" +#include "mozilla/LookAndFeel.h" #include "mozilla/MouseEvents.h" #include "mozilla/net/NeckoChild.h" #include "mozilla/Preferences.h" @@ -992,6 +993,19 @@ TabParent::UIResolutionChanged() } } +void +TabParent::ThemeChanged() +{ + if (!mIsDestroyed) { + // The theme has changed, and any cached values we had sent down + // to the child have been invalidated. When this method is called, + // LookAndFeel should have the up-to-date values, which we now + // send down to the child. We do this for every remote tab for now, + // but bug 1156934 has been filed to do it once per content process. + unused << SendThemeChanged(LookAndFeel::GetIntCache()); + } +} + void TabParent::RequestFlingSnap(const FrameMetrics::ViewID& aScrollId, const mozilla::CSSPoint& aDestination) diff --git a/dom/ipc/TabParent.h b/dom/ipc/TabParent.h index 145738ab53b6..e3af125599a4 100644 --- a/dom/ipc/TabParent.h +++ b/dom/ipc/TabParent.h @@ -246,6 +246,7 @@ public: void UpdateDimensions(const nsIntRect& rect, const ScreenIntSize& size); void UpdateFrame(const layers::FrameMetrics& aFrameMetrics); void UIResolutionChanged(); + void ThemeChanged(); void RequestFlingSnap(const FrameMetrics::ViewID& aScrollId, const mozilla::CSSPoint& aDestination); void AcknowledgeScrollUpdate(const ViewID& aScrollId, const uint32_t& aScrollGeneration); diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 12cc002abba7..f807b476a1a5 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -1702,6 +1702,12 @@ nsPresContext::ThemeChanged() } } +static void +NotifyThemeChanged(TabParent* aTabParent, void* aArg) +{ + aTabParent->ThemeChanged(); +} + void nsPresContext::ThemeChangedInternal() { @@ -1735,6 +1741,11 @@ nsPresContext::ThemeChangedInternal() // changes are not), and -moz-appearance (whose changes likewise are // not), so we need to reflow. MediaFeatureValuesChanged(eRestyle_Subtree, NS_STYLE_HINT_REFLOW); + + // Recursively notify all remote leaf descendants that the + // system theme has changed. + nsContentUtils::CallOnAllRemoteChildren(mDocument->GetWindow(), + NotifyThemeChanged, nullptr); } void