Skip to content

Commit

Permalink
Bug 1710533 - Apply the widget size constraints to newBounds r=mstang…
Browse files Browse the repository at this point in the history
…e,gfx-reviewers

When nsView::CalcWidgetBounds() size might be applied to widget with modification. And next widget->GetClientBounds() could be different than nsView::CalcWidgetBounds() again with several reasons. But it seems OK to apply widget->ConstrainSize() in nsView::DoResetWidgetBounds(). It could remove repaint because of widget->ConstrainSize() call in the Resize().

Differential Revision: https://phabricator.services.mozilla.com/D114814
  • Loading branch information
sotaro committed May 13, 2021
1 parent ba27236 commit c94f215
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion toolkit/content/tests/chrome/window_panel.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ var tests = [
is(screenRect.top, 210, testname + " screen top");
}
ok(screenRect.width >= 120 && screenRect.width <= 140, testname + " screen width");
ok(screenRect.height >= 40 && screenRect.height <= 80, testname + " screen height");
ok(screenRect.height >= 40 && screenRect.height <= 118, testname + " screen height");

var gotMouseEvent = false;
function mouseMoved(event)
Expand Down
3 changes: 3 additions & 0 deletions view/nsView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ void nsView::DoResetWidgetBounds(bool aMoveOnly, bool aInvalidateChangedSize) {
return;
}

// Apply the widget size constraints to newBounds.
widget->ConstrainSize(&newBounds.width, &newBounds.height);

bool changedPos = curBounds.TopLeft() != newBounds.TopLeft();
bool changedSize = curBounds.Size() != newBounds.Size();

Expand Down
2 changes: 1 addition & 1 deletion widget/nsBaseWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ class nsBaseWidget : public nsIWidget, public nsSupportsWeakReference {
* @param aWidth width to constrain
* @param aHeight height to constrain
*/
void ConstrainSize(int32_t* aWidth, int32_t* aHeight) {
void ConstrainSize(int32_t* aWidth, int32_t* aHeight) override {
SizeConstraints c = GetSizeConstraints();
*aWidth = std::max(c.mMinSize.width, std::min(c.mMaxSize.width, *aWidth));
*aHeight =
Expand Down
8 changes: 8 additions & 0 deletions widget/nsIWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -2079,6 +2079,14 @@ class nsIWidget : public nsISupports {
*/
virtual const SizeConstraints GetSizeConstraints() = 0;

/**
* Apply the current size constraints to the given size.
*
* @param aWidth width to constrain
* @param aHeight height to constrain
*/
virtual void ConstrainSize(int32_t* aWidth, int32_t* aHeight) = 0;

/**
* If this is owned by a BrowserChild, return that. Otherwise return
* null.
Expand Down

0 comments on commit c94f215

Please sign in to comment.