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"
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
) {
24 MOZ_TRY(aSource
->GetDimensions(mDimensionKind
, needsPosition
? &x
: nullptr,
25 needsPosition
? &y
: nullptr,
26 needsSize
? &width
: nullptr,
27 needsSize
? &height
: nullptr));
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());
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
) {
69 if (havePosition
&& haveSize
) {
70 return aTarget
->SetPositionAndSize(*mX
, *mY
, *mWidth
, *mHeight
, true);
74 return aTarget
->SetPosition(*mX
, *mY
);
78 return aTarget
->SetSize(*mWidth
, *mHeight
, true);
81 MOZ_ASSERT_UNREACHABLE();
82 return NS_ERROR_UNEXPECTED
;
85 nsresult
DimensionRequest::ApplyInnerTo(nsIDocShellTreeOwner
* aTarget
,
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
) {
105 MOZ_ASSERT_UNREACHABLE("Inner position is not implemented.");
106 return NS_ERROR_NOT_IMPLEMENTED
;
111 return aTarget
->SetRootShellSize(*mWidth
, *mHeight
);
113 return aTarget
->SetPrimaryContentSize(*mWidth
, *mHeight
);
116 MOZ_ASSERT_UNREACHABLE();
117 return NS_ERROR_UNEXPECTED
;
120 } // namespace mozilla