From 8dd7086160c2b7ea739997d0b31a7efed38bf8f6 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Wed, 27 Jun 2012 21:47:50 +0900 Subject: [PATCH] Bug 733630 Use native window border size if there is no content under mouse cursor r=jimm --- widget/windows/nsWindow.cpp | 81 ++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 36 deletions(-) diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index 9bc266fbfb46..f2702214230c 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -5406,37 +5406,61 @@ nsWindow::ClientMarginHitTestPoint(PRInt32 mx, PRInt32 my) if (mSizeMode == nsSizeMode_Maximized) isResizable = false; + // Ensure being accessible to borders of window. Even if contents are in + // this area, the area must behave as border. + nsIntMargin nonClientSize(NS_MAX(mHorResizeMargin - mNonClientOffset.left, + kResizableBorderMinSize), + NS_MAX(mCaptionHeight - mNonClientOffset.top, + kResizableBorderMinSize), + NS_MAX(mHorResizeMargin - mNonClientOffset.right, + kResizableBorderMinSize), + NS_MAX(mVertResizeMargin - mNonClientOffset.bottom, + kResizableBorderMinSize)); + + bool allowContentOverride = mSizeMode == nsSizeMode_Maximized || + (mx >= winRect.left + nonClientSize.left && + mx <= winRect.right - nonClientSize.right && + my >= winRect.top + nonClientSize.top && + my <= winRect.bottom - nonClientSize.bottom); + + // The border size. If there is no content under mouse cursor, the border + // size should be larger than the values in system settings. Otherwise, + // contents under the mouse cursor should be able to override the behavior. + // E.g., user must expect that Firefox button always opens the popup menu + // even when the user clicks on the above edge of it. + nsIntMargin borderSize(NS_MAX(nonClientSize.left, mHorResizeMargin), + NS_MAX(nonClientSize.top, mVertResizeMargin), + NS_MAX(nonClientSize.right, mHorResizeMargin), + NS_MAX(nonClientSize.bottom, mVertResizeMargin)); + + bool contentMayOverlap = false; + bool top = false; bool bottom = false; bool left = false; bool right = false; - int topOffset = NS_MAX(mCaptionHeight - mNonClientOffset.top, - kResizableBorderMinSize); - int bottomOffset = NS_MAX(mVertResizeMargin - mNonClientOffset.bottom, - kResizableBorderMinSize); - int topBounds = winRect.top + topOffset; - int bottomBounds = winRect.bottom - bottomOffset; - - if (my >= winRect.top && my < topBounds) + if (my >= winRect.top && my < winRect.top + borderSize.top) { top = true; - else if (my <= winRect.bottom && my > bottomBounds) + contentMayOverlap = (my >= winRect.top + nonClientSize.top); + } else if (my <= winRect.bottom && my > winRect.bottom - borderSize.bottom) { bottom = true; + contentMayOverlap = (my <= winRect.bottom - nonClientSize.bottom); + } - int leftOffset = NS_MAX(mHorResizeMargin - mNonClientOffset.left, - kResizableBorderMinSize); - int rightOffset = NS_MAX(mHorResizeMargin - mNonClientOffset.right, - kResizableBorderMinSize); // (the 2x case here doubles the resize area for corners) - int leftBounds = winRect.left + - (bottom ? (2*leftOffset) : leftOffset); - int rightBounds = winRect.right - - (bottom ? (2*rightOffset) : rightOffset); - - if (mx >= winRect.left && mx < leftBounds) + int multiplier = (top || bottom) ? 2 : 1; + if (mx >= winRect.left && + mx < winRect.left + (multiplier * borderSize.left)) { left = true; - else if (mx <= winRect.right && mx > rightBounds) + contentMayOverlap = + contentMayOverlap || (mx >= winRect.left + nonClientSize.left); + } else if (mx <= winRect.right && + mx > winRect.right - (multiplier * borderSize.right)) { right = true; + contentMayOverlap = + contentMayOverlap || (mx <= winRect.right - nonClientSize.right); + } if (isResizable) { if (top) { @@ -5464,22 +5488,7 @@ nsWindow::ClientMarginHitTestPoint(PRInt32 mx, PRInt32 my) testResult = HTBORDER; } - bool contentOverlap = true; - - if (mSizeMode != nsSizeMode_Maximized) { - contentOverlap = mx >= winRect.left + leftOffset && - mx <= winRect.right - rightOffset && - my >= winRect.top + topOffset && - my <= winRect.bottom - bottomOffset; - } - - if (!sIsInMouseCapture && - contentOverlap && - (testResult == HTCLIENT || - testResult == HTTOP || - testResult == HTBORDER || - testResult == HTTOPLEFT || - testResult == HTCAPTION)) { + if (!sIsInMouseCapture && allowContentOverride && contentMayOverlap) { LPARAM lParam = MAKELPARAM(mx, my); LPARAM lParamClient = lParamToClient(lParam); bool result = DispatchMouseEvent(NS_MOUSE_MOZHITTEST, 0, lParamClient,