Attachment #336532: Patch v1.0 for bug #76053

View | Details | Raw Unified | Return to bug 76053
Collapse All | Expand All

(-)a/content/xul/document/src/nsXULCommandDispatcher.cpp (+32 lines)
Line     Link Here 
 Lines 65-80    Link Here 
65
#include "nsIDOMEventTarget.h"
65
#include "nsIDOMEventTarget.h"
66
#include "nsGUIEvent.h"
66
#include "nsGUIEvent.h"
67
#include "nsContentUtils.h"
67
#include "nsContentUtils.h"
68
#include "nsReadableUtils.h"
68
#include "nsReadableUtils.h"
69
#include "nsCRT.h"
69
#include "nsCRT.h"
70
#include "nsDOMError.h"
70
#include "nsDOMError.h"
71
#include "nsEventDispatcher.h"
71
#include "nsEventDispatcher.h"
72
#include "nsPresShellIterator.h"
72
#include "nsPresShellIterator.h"
73
#include "nsIWidget.h"
74
#include "nsIFrame.h"
73
75
74
#ifdef PR_LOGGING
76
#ifdef PR_LOGGING
75
static PRLogModuleInfo* gLog;
77
static PRLogModuleInfo* gLog;
76
#endif
78
#endif
77
79
78
////////////////////////////////////////////////////////////////////////
80
////////////////////////////////////////////////////////////////////////
79
81
80
nsXULCommandDispatcher::nsXULCommandDispatcher(nsIDocument* aDocument)
82
nsXULCommandDispatcher::nsXULCommandDispatcher(nsIDocument* aDocument)
 Lines 469-476   nsXULCommandDispatcher::SetSuppressFocus Link Here 
469
nsXULCommandDispatcher::SetSuppressFocusScroll(PRBool aSuppressFocusScroll)
471
nsXULCommandDispatcher::SetSuppressFocusScroll(PRBool aSuppressFocusScroll)
470
{
472
{
471
  nsIFocusController* fc = GetFocusController();
473
  nsIFocusController* fc = GetFocusController();
472
  NS_ENSURE_TRUE(fc, NS_ERROR_FAILURE);
474
  NS_ENSURE_TRUE(fc, NS_ERROR_FAILURE);
473
475
474
  return fc->SetSuppressFocusScroll(aSuppressFocusScroll);
476
  return fc->SetSuppressFocusScroll(aSuppressFocusScroll);
475
}
477
}
476
478
479
NS_IMETHODIMP
480
nsXULCommandDispatcher::SnapMouseCursorToButton(nsIDOMElement* aButton)
481
{
482
  if (!aButton)
483
    return NS_OK;
484
485
  nsCOMPtr<nsIContent> content = do_QueryInterface(aButton);
486
  NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
487
488
  nsIFrame *frame = nsnull;
489
  nsPresShellIterator iter(content->GetDocument());
490
  nsCOMPtr<nsIPresShell> shell;
491
  while ((shell = iter.GetNextShell()) && !frame) {
492
    frame = shell->GetPrimaryFrameFor(content);
493
  }
494
  NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
495
496
  nsIWidget *widget = frame->GetWindow();
497
  NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
498
499
  PRBool snap;
500
  nsresult rv = widget->DoesCursorSnapToDefauldButton(&snap);
501
  NS_ENSURE_SUCCESS(rv, rv);
502
  if (!snap)
503
    return NS_OK;
504
505
  nsIntRect r = frame->GetScreenRect();
506
  return widget->MoveMouseCursorTo(nsPoint(r.x + r.width / 2,
507
                                           r.y + r.height / 2));
508
}
(-)a/content/xul/document/src/nsXULDocument.h (-1 / +4 lines)
Line     Link Here 
 Lines 639-655   protected: Link Here 
639
     */
639
     */
640
    nsresult DoneWalking();
640
    nsresult DoneWalking();
641
641
642
    /**
642
    /**
643
     * Report that an overlay failed to load
643
     * Report that an overlay failed to load
644
     * @param aURI the URI of the overlay that failed to load
644
     * @param aURI the URI of the overlay that failed to load
645
     */
645
     */
646
    void ReportMissingOverlay(nsIURI* aURI);
646
    void ReportMissingOverlay(nsIURI* aURI);
647
    
647
648
649
    void DoSnapCursorToDefaultButton();
650
648
#if defined(DEBUG_waterson) || defined(DEBUG_hyatt)
651
#if defined(DEBUG_waterson) || defined(DEBUG_hyatt)
649
    // timing
652
    // timing
650
    nsTime mLoadStart;
653
    nsTime mLoadStart;
651
#endif
654
#endif
652
655
653
    class CachedChromeStreamListener : public nsIStreamListener {
656
    class CachedChromeStreamListener : public nsIStreamListener {
654
    protected:
657
    protected:
655
        nsXULDocument* mDocument;
658
        nsXULDocument* mDocument;
(-)a/dom/public/idl/xul/nsIDOMXULCommandDispatcher.idl (-1 / +3 lines)
Line     Link Here 
 Lines 40-56    Link Here 
40
#include "nsISupports.idl"
40
#include "nsISupports.idl"
41
41
42
interface nsIDOMElement;
42
interface nsIDOMElement;
43
interface nsIController;
43
interface nsIController;
44
interface nsIControllers;
44
interface nsIControllers;
45
interface nsIDOMWindow;
45
interface nsIDOMWindow;
46
46
47
47
48
[scriptable, uuid(f3c50361-14fe-11d3-bf87-00105a1b0627)]
48
[scriptable, uuid(09b86cbd-9784-4fe4-9be6-70b9bbca3a9c)]
49
interface nsIDOMXULCommandDispatcher : nsISupports
49
interface nsIDOMXULCommandDispatcher : nsISupports
50
{
50
{
51
            attribute nsIDOMElement    focusedElement;
51
            attribute nsIDOMElement    focusedElement;
52
            attribute nsIDOMWindow     focusedWindow;
52
            attribute nsIDOMWindow     focusedWindow;
53
53
54
  void                      addCommandUpdater(in nsIDOMElement updater,
54
  void                      addCommandUpdater(in nsIDOMElement updater,
55
                                              in DOMString events,
55
                                              in DOMString events,
56
                                              in DOMString targets);
56
                                              in DOMString targets);
 Lines 60-68   interface nsIDOMXULCommandDispatcher : n Link Here 
60
60
61
  nsIController             getControllerForCommand(in string command);
61
  nsIController             getControllerForCommand(in string command);
62
  nsIControllers            getControllers();
62
  nsIControllers            getControllers();
63
63
64
  void advanceFocus();
64
  void advanceFocus();
65
  void rewindFocus();
65
  void rewindFocus();
66
  void advanceFocusIntoSubtree(in nsIDOMElement elt);
66
  void advanceFocusIntoSubtree(in nsIDOMElement elt);
67
  attribute boolean suppressFocusScroll;
67
  attribute boolean suppressFocusScroll;
68
69
  void snapMouseCursorToButton(in nsIDOMElement button);
68
};
70
};
(-)a/toolkit/content/widgets/dialog.xml (-2 / +8 lines)
Line     Link Here 
 Lines 153-192    Link Here 
153
      ]]>
153
      ]]>
154
      </constructor>
154
      </constructor>
155
155
156
      <method name="postLoadInit">
156
      <method name="postLoadInit">
157
        <parameter name="aEvent"/>
157
        <parameter name="aEvent"/>
158
        <body>
158
        <body>
159
        <![CDATA[
159
        <![CDATA[
160
          function focusInit() {
160
          function focusInit() {
161
            const dialog = document.documentElement;
162
            const defaultButton = dialog.getButton(dialog.defaultButton);
161
            // give focus to the first focusable element in the dialog
163
            // give focus to the first focusable element in the dialog
162
            if (!document.commandDispatcher.focusedElement) {
164
            if (!document.commandDispatcher.focusedElement) {
163
              document.commandDispatcher.advanceFocusIntoSubtree(document.documentElement);
165
              document.commandDispatcher.advanceFocusIntoSubtree(document.documentElement);
164
              var focusedElt = document.commandDispatcher.focusedElement;
166
              var focusedElt = document.commandDispatcher.focusedElement;
165
              if (focusedElt) {
167
              if (focusedElt) {
166
                if (focusedElt.localName == 'tab') {
168
                if (focusedElt.localName == 'tab') {
167
                  // Move focus into the tab
169
                  // Move focus into the tab
168
                  document.commandDispatcher.advanceFocusIntoSubtree(focusedElt);
170
                  document.commandDispatcher.advanceFocusIntoSubtree(focusedElt);
169
                  if (document.commandDispatcher.focusedElement.hasAttribute("dlgtype")) {
171
                  if (document.commandDispatcher.focusedElement.hasAttribute("dlgtype")) {
170
                    // We don't want to focus on anonymous OK, Cancel, etc. buttons,
172
                    // We don't want to focus on anonymous OK, Cancel, etc. buttons,
171
                    // so return focus to the tab itself
173
                    // so return focus to the tab itself
172
                    focusedElt.focus();
174
                    focusedElt.focus();
173
                  }
175
                  }
174
                }
176
                }
175
#ifndef XP_MACOSX
177
#ifndef XP_MACOSX
176
                else {
178
                else {
177
                  const dialog = document.documentElement;
178
                  const defaultButton = dialog.getButton(dialog.defaultButton);
179
                  if (focusedElt.hasAttribute("dlgtype") && focusedElt != defaultButton)
179
                  if (focusedElt.hasAttribute("dlgtype") && focusedElt != defaultButton)
180
                    defaultButton.focus();
180
                    defaultButton.focus();
181
                }
181
                }
182
#endif
182
#endif
183
              }
183
              }
184
            }
184
            }
185
186
            // Snap the mouse cursor to default button if it's needed.
187
            try {
188
              if (defaultButton)
189
                document.commandDispatcher.snapMouseCursorToButton(defaultButton);
190
            } catch (e) { }
185
          }
191
          }
186
192
187
          // Give focus after onload completes, see bug 103197.
193
          // Give focus after onload completes, see bug 103197.
188
          setTimeout(focusInit, 0);
194
          setTimeout(focusInit, 0);
189
        ]]>
195
        ]]>
190
        </body>
196
        </body>
191
      </method>                
197
      </method>                
192
198
(-)a/toolkit/content/widgets/wizard.xml (+14 lines)
Line     Link Here 
 Lines 319-334    Link Here 
319
        <body>
319
        <body>
320
        <![CDATA[
320
        <![CDATA[
321
          document.documentElement._hasLoaded = true;
321
          document.documentElement._hasLoaded = true;
322
          var focusInit = 
322
          var focusInit = 
323
            function() {
323
            function() {
324
              // give focus to the first focusable element in the dialog
324
              // give focus to the first focusable element in the dialog
325
              if (!document.commandDispatcher.focusedElement)
325
              if (!document.commandDispatcher.focusedElement)
326
                document.commandDispatcher.advanceFocusIntoSubtree(document.documentElement);
326
                document.commandDispatcher.advanceFocusIntoSubtree(document.documentElement);
327
328
              // Snap the mouse cursor to default button if it's needed.
329
              try {
330
                var button = document.documentElement._getDefaultButton();
331
                if (button)
332
                  document.commandDispatcher.snapMouseCursorToButton(button);
333
              } catch (e) { }
327
            };
334
            };
328
335
329
          // Give focus after onload completes, see bug 103197.
336
          // Give focus after onload completes, see bug 103197.
330
          setTimeout(focusInit, 0);
337
          setTimeout(focusInit, 0);
331
        ]]>
338
        ]]>
332
        </body>
339
        </body>
333
      </method>                
340
      </method>                
334
341
 Lines 424-439    Link Here 
424
            var returned = fn.apply(aTarget, [event]);
431
            var returned = fn.apply(aTarget, [event]);
425
            if (returned == false)
432
            if (returned == false)
426
              noCancel = false;
433
              noCancel = false;
427
          }
434
          }
428
435
429
          return noCancel;
436
          return noCancel;
430
        ]]>
437
        ]]>
431
        </body>
438
        </body>
439
      </method>
440
441
      <method name="_getDefaultButton">
442
        <body><![CDATA[
443
          // XXX this is not strict, we should find a default button.
444
          return this.getButton(this.pageIndex < this.pageCount - 1 ? "next" : "finish");
445
        ]]></body>
432
      </method>
446
      </method>
433
447
434
    </implementation>
448
    </implementation>
435
449
436
    <handlers>
450
    <handlers>
437
      <handler event="keypress" keycode="VK_ENTER"
451
      <handler event="keypress" keycode="VK_ENTER"
438
               group="system" action="this._hitEnter(event)"/>
452
               group="system" action="this._hitEnter(event)"/>
439
      <handler event="keypress" keycode="VK_RETURN"
453
      <handler event="keypress" keycode="VK_RETURN"
(-)a/widget/public/nsIWidget.h (+11 lines)
Line     Link Here 
 Lines 1202-1217   class nsIWidget : public nsISupports { Link Here 
1202
    /**
1202
    /**
1203
     * This is used for native menu system testing. Calling this forces a full
1203
     * This is used for native menu system testing. Calling this forces a full
1204
     * reload of the menu system, reloading all native menus and their items.
1204
     * reload of the menu system, reloading all native menus and their items.
1205
     * This is important for testing because changes to the DOM can affect the
1205
     * This is important for testing because changes to the DOM can affect the
1206
     * native menu system lazily.
1206
     * native menu system lazily.
1207
     */
1207
     */
1208
    virtual nsresult ForceNativeMenuReload() = 0;
1208
    virtual nsresult ForceNativeMenuReload() = 0;
1209
1209
1210
    /**
1211
     * Whether we should snap the mouse cursor to default button of a dialog.
1212
     * aResult is true when we should do. Otherwise, false.
1213
     */
1214
    NS_IMETHOD DoesCursorSnapToDefauldButton(PRBool* aResult) = 0;
1215
1216
    /**
1217
     * Move the mouse cursor to the point in screen.
1218
     */
1219
    NS_IMETHOD MoveMouseCursorTo(nsPoint &aPoint) = 0;
1220
1210
protected:
1221
protected:
1211
    // keep the list of children.  We also keep track of our siblings.
1222
    // keep the list of children.  We also keep track of our siblings.
1212
    // The ownership model is as follows: parent holds a strong ref to
1223
    // The ownership model is as follows: parent holds a strong ref to
1213
    // the first element of the list, and each element holds a strong
1224
    // the first element of the list, and each element holds a strong
1214
    // ref to the next element in the list.  The prevsibling and
1225
    // ref to the next element in the list.  The prevsibling and
1215
    // lastchild pointers are weak, which is fine as long as they are
1226
    // lastchild pointers are weak, which is fine as long as they are
1216
    // maintained properly.
1227
    // maintained properly.
1217
    nsCOMPtr<nsIWidget> mFirstChild;
1228
    nsCOMPtr<nsIWidget> mFirstChild;
(-)a/widget/src/windows/nsWindow.cpp (+24 lines)
Line     Link Here 
 Lines 8095-8102   nsresult nsWindow::UpdateTranslucentWind Link Here 
8095
  // perform the alpha blend
8095
  // perform the alpha blend
8096
  if (!::UpdateLayeredWindow(hWnd, NULL, (POINT*)&winRect, &winSize, mMemoryDC, &srcPos, 0, &bf, ULW_ALPHA))
8096
  if (!::UpdateLayeredWindow(hWnd, NULL, (POINT*)&winRect, &winSize, mMemoryDC, &srcPos, 0, &bf, ULW_ALPHA))
8097
    return NS_ERROR_FAILURE;
8097
    return NS_ERROR_FAILURE;
8098
8098
8099
  return NS_OK;
8099
  return NS_OK;
8100
}
8100
}
8101
8101
8102
#endif
8102
#endif
8103
8104
NS_IMETHODIMP
8105
nsWindow::DoesCursorSnapToDefauldButton(PRBool* aResult)
8106
{
8107
  NS_PRECONDITION(aResult, "aEnabled is null");
8108
  *aResult = PR_FALSE;
8109
  // Don't snap when we are not active.
8110
  if (::GetActiveWindow() != ::GetForegroundWindow())
8111
    return NS_OK;
8112
8113
  BOOL snapDefaultButton;
8114
  if (!::SystemParametersInfo(SPI_GETSNAPTODEFBUTTON, 0,
8115
                              &snapDefaultButton, 0) || !snapDefaultButton)
8116
    return NS_OK;
8117
8118
  *aResult = PR_TRUE;
8119
  return NS_OK;
8120
}
8121
8122
NS_IMETHODIMP
8123
nsWindow::MoveMouseCursorTo(nsPoint& aPoint)
8124
{
8125
  return ::SetCursorPos(aPoint.x, aPoint.y) ? NS_OK : NS_ERROR_FAILURE;
8126
}
(-)a/widget/src/windows/nsWindow.h (+3 lines)
Line     Link Here 
 Lines 259-274   public: Link Here 
259
259
260
  PRInt32                 GetNewCmdMenuId() { mMenuCmdId++; return mMenuCmdId; }
260
  PRInt32                 GetNewCmdMenuId() { mMenuCmdId++; return mMenuCmdId; }
261
261
262
  void                    InitEvent(nsGUIEvent& event, nsPoint* aPoint = nsnull);
262
  void                    InitEvent(nsGUIEvent& event, nsPoint* aPoint = nsnull);
263
263
264
  void                    SuppressBlurEvents(PRBool aSuppress);
264
  void                    SuppressBlurEvents(PRBool aSuppress);
265
  PRBool                  BlurEventsSuppressed();
265
  PRBool                  BlurEventsSuppressed();
266
266
267
  NS_IMETHOD DoesCursorSnapToDefauldButton(PRBool* aResult);
268
  NS_IMETHOD MoveMouseCursorTo(nsPoint &aPoint);
269
267
protected:
270
protected:
268
271
269
#ifndef WINCE
272
#ifndef WINCE
270
273
271
  // special callback hook methods for pop ups
274
  // special callback hook methods for pop ups
272
  static LRESULT CALLBACK MozSpecialMsgFilter(int code, WPARAM wParam, LPARAM lParam);
275
  static LRESULT CALLBACK MozSpecialMsgFilter(int code, WPARAM wParam, LPARAM lParam);
273
  static LRESULT CALLBACK MozSpecialWndProc(int code, WPARAM wParam, LPARAM lParam);
276
  static LRESULT CALLBACK MozSpecialWndProc(int code, WPARAM wParam, LPARAM lParam);
274
  static LRESULT CALLBACK MozSpecialMouseProc(int code, WPARAM wParam, LPARAM lParam);
277
  static LRESULT CALLBACK MozSpecialMouseProc(int code, WPARAM wParam, LPARAM lParam);
(-)a/widget/src/xpwidgets/nsBaseWidget.h (-1 / +2 lines)
Line     Link Here 
 Lines 139-155   public: Link Here 
139
  virtual nsresult        ForceNativeMenuReload() { return NS_ERROR_NOT_IMPLEMENTED; }
139
  virtual nsresult        ForceNativeMenuReload() { return NS_ERROR_NOT_IMPLEMENTED; }
140
  NS_IMETHOD              ResetInputState() { return NS_ERROR_NOT_IMPLEMENTED; }
140
  NS_IMETHOD              ResetInputState() { return NS_ERROR_NOT_IMPLEMENTED; }
141
  NS_IMETHOD              SetIMEOpenState(PRBool aState) { return NS_ERROR_NOT_IMPLEMENTED; }
141
  NS_IMETHOD              SetIMEOpenState(PRBool aState) { return NS_ERROR_NOT_IMPLEMENTED; }
142
  NS_IMETHOD              GetIMEOpenState(PRBool* aState) { return NS_ERROR_NOT_IMPLEMENTED; }
142
  NS_IMETHOD              GetIMEOpenState(PRBool* aState) { return NS_ERROR_NOT_IMPLEMENTED; }
143
  NS_IMETHOD              SetIMEEnabled(PRUint32 aState) { return NS_ERROR_NOT_IMPLEMENTED; }
143
  NS_IMETHOD              SetIMEEnabled(PRUint32 aState) { return NS_ERROR_NOT_IMPLEMENTED; }
144
  NS_IMETHOD              GetIMEEnabled(PRUint32* aState) { return NS_ERROR_NOT_IMPLEMENTED; }
144
  NS_IMETHOD              GetIMEEnabled(PRUint32* aState) { return NS_ERROR_NOT_IMPLEMENTED; }
145
  NS_IMETHOD              CancelIMEComposition() { return NS_ERROR_NOT_IMPLEMENTED; }
145
  NS_IMETHOD              CancelIMEComposition() { return NS_ERROR_NOT_IMPLEMENTED; }
146
  NS_IMETHOD              GetToggledKeyState(PRUint32 aKeyCode, PRBool* aLEDState) { return NS_ERROR_NOT_IMPLEMENTED; }
146
  NS_IMETHOD              GetToggledKeyState(PRUint32 aKeyCode, PRBool* aLEDState) { return NS_ERROR_NOT_IMPLEMENTED; }
147
147
  NS_IMETHOD              GetCursorSnapToDefauldButtonEnabled(PRBool* aResult) { return NS_ERROR_NOT_IMPLEMENTED; }
148
  NS_IMETHOD              MoveMouseCursorTo(nsPoint &aPoint) { return NS_ERROR_NOT_IMPLEMENTED; }
148
protected:
149
protected:
149
150
150
  virtual void            ResolveIconName(const nsAString &aIconName,
151
  virtual void            ResolveIconName(const nsAString &aIconName,
151
                                          const nsAString &aIconSuffix,
152
                                          const nsAString &aIconSuffix,
152
                                          nsILocalFile **aResult);
153
                                          nsILocalFile **aResult);
153
  virtual void            OnDestroy();
154
  virtual void            OnDestroy();
154
  virtual void            BaseCreate(nsIWidget *aParent,
155
  virtual void            BaseCreate(nsIWidget *aParent,
155
                                     const nsRect &aRect,
156
                                     const nsRect &aRect,

Return to bug 76053