Bug 1839316: part 5) Guard the "fetchpriority" attribute behind a pref. r=kershaw...
[gecko.git] / widget / DimensionRequest.cpp
blob61d4ae5cf79a3ed5e653d39e53e1205aec7e3b82
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"
10 namespace mozilla {
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) {
20 return NS_OK;
23 MOZ_TRY(aSource->GetDimensions(mDimensionKind, needsPosition ? &x : nullptr,
24 needsPosition ? &y : nullptr,
25 needsSize ? &width : nullptr,
26 needsSize ? &height : nullptr));
28 if (needsPosition) {
29 if (mX.isNothing()) {
30 mX.emplace(x);
32 if (mY.isNothing()) {
33 mY.emplace(y);
36 if (needsSize) {
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());
47 return NS_OK;
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) {
65 return NS_OK;
68 if (havePosition && haveSize) {
69 return aTarget->SetPositionAndSize(*mX, *mY, *mWidth, *mHeight, true);
72 if (havePosition) {
73 return aTarget->SetPosition(*mX, *mY);
76 if (haveSize) {
77 return aTarget->SetSize(*mWidth, *mHeight, true);
80 MOZ_ASSERT_UNREACHABLE();
81 return NS_ERROR_UNEXPECTED;
84 nsresult DimensionRequest::ApplyInnerTo(nsIDocShellTreeOwner* aTarget,
85 bool aAsRootShell) {
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) {
100 return NS_OK;
103 if (havePosition) {
104 MOZ_ASSERT_UNREACHABLE("Inner position is not implemented.");
105 return NS_ERROR_NOT_IMPLEMENTED;
108 if (haveSize) {
109 if (aAsRootShell) {
110 return aTarget->SetRootShellSize(*mWidth, *mHeight);
112 return aTarget->SetPrimaryContentSize(*mWidth, *mHeight);
115 MOZ_ASSERT_UNREACHABLE();
116 return NS_ERROR_UNEXPECTED;
119 } // namespace mozilla