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"
12 nsresult
DimensionRequest::SupplementFrom(nsIBaseWindow
* aSource
) {
13 NS_ENSURE_ARG_POINTER(aSource
);
14 int32_t x
= 0, y
= 0, width
= 0, height
= 0;
16 bool needsPosition
= mX
.isSome() != mY
.isSome();
17 bool needsSize
= mWidth
.isSome() != mHeight
.isSome();
19 if (!needsPosition
&& !needsSize
) {
23 MOZ_TRY(aSource
->GetDimensions(mDimensionKind
, needsPosition
? &x
: nullptr,
24 needsPosition
? &y
: nullptr,
25 needsSize
? &width
: nullptr,
26 needsSize
? &height
: nullptr));
37 if (mWidth
.isNothing()) {
38 mWidth
.emplace(width
);
40 if (mHeight
.isNothing()) {
41 mHeight
.emplace(height
);
45 MOZ_ASSERT(mX
.isSome() == mY
.isSome());
46 MOZ_ASSERT(mWidth
.isSome() == mHeight
.isSome());
50 nsresult
DimensionRequest::ApplyOuterTo(nsIBaseWindow
* aTarget
) {
51 NS_ENSURE_ARG_POINTER(aTarget
);
52 MOZ_ASSERT(mX
.isSome() == mY
.isSome(),
53 "Missing dimensions should have been completed.");
54 MOZ_ASSERT(mWidth
.isSome() == mHeight
.isSome(),
55 "Missing dimensions should have been completed.");
56 if (mDimensionKind
!= DimensionKind::Outer
) {
57 MOZ_ASSERT_UNREACHABLE("Expected outer dimensions.");
58 return NS_ERROR_UNEXPECTED
;
61 bool havePosition
= mX
.isSome() && mY
.isSome();
62 bool haveSize
= mWidth
.isSome() && mHeight
.isSome();
64 if (!havePosition
&& !haveSize
) {
68 if (havePosition
&& haveSize
) {
69 return aTarget
->SetPositionAndSize(*mX
, *mY
, *mWidth
, *mHeight
, true);
73 return aTarget
->SetPosition(*mX
, *mY
);
77 return aTarget
->SetSize(*mWidth
, *mHeight
, true);
80 MOZ_ASSERT_UNREACHABLE();
81 return NS_ERROR_UNEXPECTED
;
84 nsresult
DimensionRequest::ApplyInnerTo(nsIDocShellTreeOwner
* aTarget
,
86 NS_ENSURE_ARG_POINTER(aTarget
);
87 MOZ_ASSERT(mX
.isSome() == mY
.isSome(),
88 "Missing dimensions should have been completed.");
89 MOZ_ASSERT(mWidth
.isSome() == mHeight
.isSome(),
90 "Missing dimensions should have been completed.");
91 if (mDimensionKind
!= DimensionKind::Inner
) {
92 MOZ_ASSERT_UNREACHABLE("Expected inner dimensions.");
93 return NS_ERROR_UNEXPECTED
;
96 bool havePosition
= mX
.isSome() && mY
.isSome();
97 bool haveSize
= mWidth
.isSome() && mHeight
.isSome();
99 if (!havePosition
&& !haveSize
) {
104 MOZ_ASSERT_UNREACHABLE("Inner position is not implemented.");
105 return NS_ERROR_NOT_IMPLEMENTED
;
110 return aTarget
->SetRootShellSize(*mWidth
, *mHeight
);
112 return aTarget
->SetPrimaryContentSize(*mWidth
, *mHeight
);
115 MOZ_ASSERT_UNREACHABLE();
116 return NS_ERROR_UNEXPECTED
;
119 } // namespace mozilla