Bug 613076 - Fix GetDPI in the content process. r=cjones a=blocking-fennec
authorAlon Zakai <azakai@mozilla.com>
Thu, 02 Dec 2010 17:24:04 -0800
changeset 58528 15cdaa1d538bdfe393320f4d06b5c29010e625e6
parent 58527 bcf68bd9321dcf7012b1d36a6a3bc3914c7ecc4b
child 58529 2afc36a5499c1bfb03fcd5982b8fe0f2d491e3f5
push id17335
push usermwu@mozilla.com
push dateFri, 03 Dec 2010 01:30:35 +0000
treeherdermozilla-central@15cdaa1d538b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscjones, blocking-fennec
bugs613076
milestone2.0b8pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 613076 - Fix GetDPI in the content process. r=cjones a=blocking-fennec
dom/ipc/PBrowser.ipdl
dom/ipc/TabParent.cpp
dom/ipc/TabParent.h
widget/src/xpwidgets/PuppetWidget.cpp
widget/src/xpwidgets/PuppetWidget.h
--- a/dom/ipc/PBrowser.ipdl
+++ b/dom/ipc/PBrowser.ipdl
@@ -170,16 +170,21 @@ parent:
     sync GetIMEEnabled() returns (PRUint32 value);
 
     SetInputMode(PRUint32 value, nsString type, nsString actionHint);
 
     sync GetIMEOpenState() returns (PRBool value);
 
     SetIMEOpenState(PRBool value);
 
+    /**
+     * Gets the DPI of the screen corresponding to this browser.
+     */
+    sync GetDPI() returns (float value);
+
     PContentPermissionRequest(nsCString aType, URI uri);
 
     PContentDialog(PRUint32 aType, nsCString aName, nsCString aFeatures,
                    PRInt32[] aIntParams, nsString[] aStringParams);
 
     /**
      * Create a layout frame (encapsulating a remote layer tree) for
      * the page that is currently loaded in the <browser>.
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -64,16 +64,17 @@
 #include "nsContentPermissionHelper.h"
 #include "nsIDOMNSHTMLFrameElement.h"
 #include "nsIDialogCreator.h"
 #include "nsThreadUtils.h"
 #include "nsSerializationHelper.h"
 #include "nsIPromptFactory.h"
 #include "nsIContent.h"
 #include "mozilla/unused.h"
+#include "nsDebug.h"
 
 using namespace mozilla::dom;
 using namespace mozilla::ipc;
 using namespace mozilla::layout;
 
 // The flags passed by the webProgress notifications are 16 bits shifted
 // from the ones registered by webProgressListeners.
 #define NOTIFY_FLAG_SHIFT 16
@@ -534,16 +535,25 @@ TabParent::RecvSetIMEOpenState(const PRB
 {
   nsCOMPtr<nsIWidget> widget = GetWidget();
   if (widget && AllowContentIME())
     widget->SetIMEOpenState(aValue);
   return true;
 }
 
 bool
+TabParent::RecvGetDPI(float* aValue)
+{
+  nsCOMPtr<nsIWidget> widget = GetWidget();
+  NS_ABORT_IF_FALSE(widget, "Must have a widget to find the DPI!");
+  *aValue = widget->GetDPI();
+  return true;
+}
+
+bool
 TabParent::ReceiveMessage(const nsString& aMessage,
                           PRBool aSync,
                           const nsString& aJSON,
                           InfallibleTArray<nsString>* aJSONRetVal)
 {
   nsRefPtr<nsFrameLoader> frameLoader = GetFrameLoader();
   if (frameLoader && frameLoader->GetFrameMessageManager()) {
     nsFrameMessageManager* manager = frameLoader->GetFrameMessageManager();
--- a/dom/ipc/TabParent.h
+++ b/dom/ipc/TabParent.h
@@ -100,27 +100,29 @@ public:
                                         const PRUint32& aFocus);
     virtual bool RecvNotifyIMETextHint(const nsString& aText);
     virtual bool RecvEndIMEComposition(const PRBool& aCancel,
                                        nsString* aComposition);
     virtual bool RecvGetIMEEnabled(PRUint32* aValue);
     virtual bool RecvSetInputMode(const PRUint32& aValue, const nsString& aType, const nsString& aAction);
     virtual bool RecvGetIMEOpenState(PRBool* aValue);
     virtual bool RecvSetIMEOpenState(const PRBool& aValue);
+    virtual bool RecvGetDPI(float* aValue);
     virtual PContentDialogParent* AllocPContentDialog(const PRUint32& aType,
                                                       const nsCString& aName,
                                                       const nsCString& aFeatures,
                                                       const InfallibleTArray<int>& aIntParams,
                                                       const InfallibleTArray<nsString>& aStringParams);
     virtual bool DeallocPContentDialog(PContentDialogParent* aDialog)
     {
       delete aDialog;
       return true;
     }
 
+
     void LoadURL(nsIURI* aURI);
     // XXX/cjones: it's not clear what we gain by hiding these
     // message-sending functions under a layer of indirection and
     // eating the return values
     void Show(const nsIntSize& size);
     void Move(const nsIntSize& size);
     void Activate();
     void SendMouseEvent(const nsAString& aType, float aX, float aY,
--- a/widget/src/xpwidgets/PuppetWidget.cpp
+++ b/widget/src/xpwidgets/PuppetWidget.cpp
@@ -73,16 +73,17 @@ namespace widget {
 // Arbitrary, fungible.
 const size_t PuppetWidget::kMaxDimension = 4000;
 
 NS_IMPL_ISUPPORTS_INHERITED1(PuppetWidget, nsBaseWidget,
                              nsISupportsWeakReference)
 
 PuppetWidget::PuppetWidget(PBrowserChild *aTabChild)
   : mTabChild(aTabChild)
+  , mDPI(-1)
 {
   MOZ_COUNT_CTOR(PuppetWidget);
 }
 
 PuppetWidget::~PuppetWidget()
 {
   MOZ_COUNT_DTOR(PuppetWidget);
 }
@@ -545,10 +546,21 @@ NS_IMETHODIMP
 PuppetWidget::PaintTask::Run()
 {
   if (mWidget) {
     mWidget->DispatchPaintEvent();
   }
   return NS_OK;
 }
 
+float
+PuppetWidget::GetDPI()
+{
+  if (mDPI < 0) {
+    NS_ABORT_IF_FALSE(mTabChild, "Need TabChild to get the DPI from!");
+    mTabChild->SendGetDPI(&mDPI);
+  }
+
+  return mDPI;
+}
+
 }  // namespace widget
 }  // namespace mozilla
--- a/widget/src/xpwidgets/PuppetWidget.h
+++ b/widget/src/xpwidgets/PuppetWidget.h
@@ -174,16 +174,22 @@ public:
   NS_IMETHOD SetInputMode(const IMEContext& aContext);
   NS_IMETHOD GetInputMode(IMEContext& aContext);
   NS_IMETHOD CancelComposition();
   NS_IMETHOD OnIMEFocusChange(PRBool aFocus);
   NS_IMETHOD OnIMETextChange(PRUint32 aOffset, PRUint32 aEnd,
                              PRUint32 aNewEnd);
   NS_IMETHOD OnIMESelectionChange(void);
 
+  // Gets the DPI of the screen corresponding to this widget.
+  // Contacts the parent process which gets the DPI from the
+  // proper widget there. TODO: Handle DPI changes that happen
+  // later on.
+  virtual float GetDPI();
+
 private:
   nsresult DispatchPaintEvent();
   nsresult DispatchResizeEvent();
 
   void SetChild(PuppetWidget* aChild);
 
   nsresult IMEEndComposition(PRBool aCancel);
 
@@ -218,14 +224,17 @@ private:
   PRPackedBool mIMEComposing;
   // Latest seqno received through events
   PRUint32 mIMELastReceivedSeqno;
   // Chrome's seqno value when last blur occurred
   // arriving events with seqno up to this should be discarded
   // Note that if seqno overflows (~50 days at 1 ms increment rate),
   // events will be discarded until new focus/blur occurs
   PRUint32 mIMELastBlurSeqno;
+
+  // The DPI of the screen corresponding to this widget
+  float mDPI;
 };
 
 }  // namespace widget
 }  // namespace mozilla
 
 #endif  // mozilla_widget_PuppetWidget_h__