Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / widget / DimensionRequest.cpp
blob4f2f667643e09d5ddd5a9a9958f96e12510371be
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "DimensionRequest.h"
7 #include "nsIBaseWindow.h"
8 #include "nsIDocShellTreeOwner.h"
9 #include "mozilla/Try.h"
11 namespace mozilla {
13 nsresult DimensionRequest::SupplementFrom(nsIBaseWindow* aSource) {
14 NS_ENSURE_ARG_POINTER(aSource);
15 int32_t x = 0, y = 0, width = 0, height = 0;
17 bool needsPosition = mX.isSome() != mY.isSome();
18 bool needsSize = mWidth.isSome() != mHeight.isSome();
20 if (!needsPosition && !needsSize) {
21 return NS_OK;
24 MOZ_TRY(aSource->GetDimensions(mDimensionKind, needsPosition ? &x : nullptr,
25 needsPosition ? &y : nullptr,
26 needsSize ? &width : nullptr,
27 needsSize ? &height : nullptr));
29 if (needsPosition) {
30 if (mX.isNothing()) {
31 mX.emplace(x);
33 if (mY.isNothing()) {
34 mY.emplace(y);
37 if (needsSize) {
38 if (mWidth.isNothing()) {
39 mWidth.emplace(width);
41 if (mHeight.isNothing()) {
42 mHeight.emplace(height);
46 MOZ_ASSERT(mX.isSome() == mY.isSome());
47 MOZ_ASSERT(mWidth.isSome() == mHeight.isSome());
48 return NS_OK;
51 nsresult DimensionRequest::ApplyOuterTo(nsIBaseWindow* aTarget) {
52 NS_ENSURE_ARG_POINTER(aTarget);
53 MOZ_ASSERT(mX.isSome() == mY.isSome(),
54 "Missing dimensions should have been completed.");
55 MOZ_ASSERT(mWidth.isSome() == mHeight.isSome(),
56 "Missing dimensions should have been completed.");
57 if (mDimensionKind != DimensionKind::Outer) {
58 MOZ_ASSERT_UNREACHABLE("Expected outer dimensions.");
59 return NS_ERROR_UNEXPECTED;
62 bool havePosition = mX.isSome() && mY.isSome();
63 bool haveSize = mWidth.isSome() && mHeight.isSome();
65 if (!havePosition && !haveSize) {
66 return NS_OK;
69 if (havePosition && haveSize) {
70 return aTarget->SetPositionAndSize(*mX, *mY, *mWidth, *mHeight, true);
73 if (havePosition) {
74 return aTarget->SetPosition(*mX, *mY);
77 if (haveSize) {
78 return aTarget->SetSize(*mWidth, *mHeight, true);
81 MOZ_ASSERT_UNREACHABLE();
82 return NS_ERROR_UNEXPECTED;
85 nsresult DimensionRequest::ApplyInnerTo(nsIDocShellTreeOwner* aTarget,
86 bool aAsRootShell) {
87 NS_ENSURE_ARG_POINTER(aTarget);
88 MOZ_ASSERT(mX.isSome() == mY.isSome(),
89 "Missing dimensions should have been completed.");
90 MOZ_ASSERT(mWidth.isSome() == mHeight.isSome(),
91 "Missing dimensions should have been completed.");
92 if (mDimensionKind != DimensionKind::Inner) {
93 MOZ_ASSERT_UNREACHABLE("Expected inner dimensions.");
94 return NS_ERROR_UNEXPECTED;
97 bool havePosition = mX.isSome() && mY.isSome();
98 bool haveSize = mWidth.isSome() && mHeight.isSome();
100 if (!havePosition && !haveSize) {
101 return NS_OK;
104 if (havePosition) {
105 MOZ_ASSERT_UNREACHABLE("Inner position is not implemented.");
106 return NS_ERROR_NOT_IMPLEMENTED;
109 if (haveSize) {
110 if (aAsRootShell) {
111 return aTarget->SetRootShellSize(*mWidth, *mHeight);
113 return aTarget->SetPrimaryContentSize(*mWidth, *mHeight);
116 MOZ_ASSERT_UNREACHABLE();
117 return NS_ERROR_UNEXPECTED;
120 } // namespace mozilla