bug 481914 - dialogs shouldn't be larger than available screen space. Send notification and adjust avail screen size for soft keyboard r=dougt, sr=vlad
authorBrad Lassey <blassey@mozilla.com>
Tue, 14 Apr 2009 01:27:39 -0400
changeset 28031 f1e1b8ba74da23613e8b653b1b07e6de4ec8d52c
parent 28030 5b6ce32aeab3e5546ee54833fdfb7cc8489c2929
child 28032 84f6d4fbaf1539b5ebd808be8db718035d775bf7
push id6850
push userblassey@mozilla.com
push dateWed, 06 May 2009 14:59:50 +0000
treeherdermozilla-central@cd77eb6f23bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdougt, vlad
bugs481914
milestone1.9.2a1pre
bug 481914 - dialogs shouldn't be larger than available screen space. Send notification and adjust avail screen size for soft keyboard r=dougt, sr=vlad
widget/src/windows/nsScreenWin.cpp
widget/src/windows/nsWindow.cpp
--- a/widget/src/windows/nsScreenWin.cpp
+++ b/widget/src/windows/nsScreenWin.cpp
@@ -43,16 +43,19 @@
 #undef WINVER
 #define WINVER 0x0500
 #undef _WIN32_WINNT
 #define _WIN32_WINNT 0x0500
 
 #include "nsScreenWin.h"
 
 #ifdef WINCE
+#ifdef WINCE_WINDOWS_MOBILE
+#include "sipapi.h"
+#endif
 #define GetMonitorInfoW GetMonitorInfo
 #endif
 
 
 nsScreenWin :: nsScreenWin ( void* inScreen )
   : mScreen(inScreen)
 {
 #ifdef DEBUG
@@ -109,16 +112,29 @@ nsScreenWin :: GetRect(PRInt32 *outLeft,
 
 } // GetRect
 
 
 NS_IMETHODIMP
 nsScreenWin :: GetAvailRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth, PRInt32 *outHeight)
 {
   BOOL success = FALSE;
+#ifdef WINCE_WINDOWS_MOBILE
+  SIPINFO sipInfo;
+  memset(&sipInfo, 0, sizeof(SIPINFO));
+  sipInfo.cbSize = sizeof(SIPINFO);
+  if (SipGetInfo(&sipInfo) && !(sipInfo.fdwFlags & SIPF_OFF)) {
+    *outLeft = sipInfo.rcVisibleDesktop.left;
+    *outTop = sipInfo.rcVisibleDesktop.top;
+    *outWidth = sipInfo.rcVisibleDesktop.right - sipInfo.rcVisibleDesktop.left;
+    *outHeight = sipInfo.rcVisibleDesktop.bottom - sipInfo.rcVisibleDesktop.top;
+    return NS_OK;
+  }
+#endif
+
 #if _MSC_VER >= 1200
   if ( mScreen ) {
     MONITORINFO info;
     info.cbSize = sizeof(MONITORINFO);
     success = ::GetMonitorInfoW( (HMONITOR)mScreen, &info );
     if ( success ) {
       *outLeft = info.rcWork.left;
       *outTop = info.rcWork.top;
--- a/widget/src/windows/nsWindow.cpp
+++ b/widget/src/windows/nsWindow.cpp
@@ -203,27 +203,47 @@ static gfxIntSize gSharedSurfaceSize;
  * WinCE helpers
  */
 #ifdef WINCE
 
 #ifdef WINCE_HAVE_SOFTKB
 static PRBool gSoftKeyMenuBar = PR_FALSE;
 static PRBool gSoftKeyboardState = PR_FALSE;
 
+static void NotifySoftKbObservers() {
+  nsCOMPtr<nsIObserverService> observerService = do_GetService("@mozilla.org/observer-service;1");
+  if (observerService) {
+    SIPINFO sipInfo;
+    wchar_t rectBuf[256];
+    memset(&sipInfo, 0, sizeof(SIPINFO));
+    sipInfo.cbSize = sizeof(SIPINFO);
+    if (SipGetInfo(&sipInfo)) {
+      _snwprintf(rectBuf, 256, L"{\"left\": %d, \"top\": %d,"
+                 L" \"right\": %d, \"bottom\": %d}", 
+                 sipInfo.rcVisibleDesktop.left, 
+                 sipInfo.rcVisibleDesktop.top, 
+                 sipInfo.rcVisibleDesktop.right, 
+                 sipInfo.rcVisibleDesktop.bottom);
+      observerService->NotifyObservers(nsnull, "softkb-change", rectBuf);
+    }
+  }
+}
+
 static void ToggleSoftKB(PRBool show)
 {
   HWND hWndSIP = FindWindowW(L"SipWndClass", NULL );
   if (hWndSIP)
     ::ShowWindow(hWndSIP, show ? SW_SHOW: SW_HIDE);
 
   hWndSIP = FindWindowW(L"MS_SIPBUTTON", NULL ); 
   if (hWndSIP)
     ShowWindow(hWndSIP, show ? SW_SHOW: SW_HIDE);
 
-  SHSipPreference(NULL, show ? SIP_UP: SIP_DOWN);
+  SipShowIM(show ? SIPF_ON : SIPF_OFF);
+  NotifySoftKbObservers();
 }
 
 static void CreateSoftKeyMenuBar(HWND wnd)
 {
   if (!wnd)
     return;
   
   static HWND gSoftKeyMenuBar = nsnull;
@@ -4824,16 +4844,20 @@ PRBool nsWindow::ProcessMessage(UINT msg
         result = DispatchFocus(NS_ACTIVATE, PR_TRUE);
 #endif
       }
     }
     break;
 
     case WM_SETTINGCHANGE:
         getWheelInfo = PR_TRUE;
+#ifdef WINCE_WINDOWS_MOBILE
+        if (wParam == SPI_SETSIPINFO)
+          NotifySoftKbObservers();
+#endif
       break;
 
     case WM_PALETTECHANGED:
       if ((HWND)wParam == mWnd) {
         // We caused the WM_PALETTECHANGED message so avoid realizing
         // another foreground palette
         result = PR_TRUE;
         break;