gecko-dev/layout/xul/nsBoxFrame.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

1224 строки
40 KiB
C++
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
2012-05-21 15:12:37 +04:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
1999-03-27 04:35:55 +03:00
//
// Eric Vaughan
// Netscape Communications
//
// See documentation in associated header file
//
// How boxes layout
// ----------------
// Boxes layout a bit differently than html. html does a bottom up layout. Where
// boxes do a top down.
//
// 1) First thing a box does it goes out and askes each child for its min, max,
// and preferred sizes.
//
// 2) It then adds them up to determine its size.
//
// 3) If the box was asked to layout it self intrinically it will layout its
// children at their preferred size otherwise it will layout the child at
// the size it was told to. It will squeeze or stretch its children if
// Necessary.
//
// However there is a catch. Some html components like block frames can not
// determine their preferred size. this is their size if they were laid out
// intrinsically. So the box will flow the child to determine this can cache the
// value.
// Boxes and Incremental Reflow
// ----------------------------
// Boxes layout out top down by adding up their children's min, max, and
// preferred sizes. Only problem is if a incremental reflow occurs. The
// preferred size of a child deep in the hierarchy could change. And this could
// change any number of syblings around the box. Basically any children in the
// reflow chain must have their caches cleared so when asked for there current
// size they can relayout themselves.
1999-03-27 04:35:55 +03:00
#include "nsBoxFrame.h"
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj This was done by: This was done by applying: ``` diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py index 789affde7bbf..fe33c4c7d4d1 100644 --- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py +++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py @@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase): from subprocess import Popen, PIPE, check_output, CalledProcessError diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE) - args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format] + args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes'] if not output_file: args.append("-i") ``` Then running `./mach clang-format -c <commit-hash>` Then undoing that patch. Then running check_spidermonkey_style.py --fixup Then running `./mach clang-format` I had to fix four things: * I needed to move <utility> back down in GuardObjects.h because I was hitting obscure problems with our system include wrappers like this: 0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration 0:03.94 extern void *realloc (void *__ptr, size_t __size) 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here 0:03.94 MALLOC_DECL(realloc, void*, void*, size_t) 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL' 0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__); 0:03.94 ^ 0:03.94 <scratch space>:178:1: note: expanded from here 0:03.94 realloc_impl 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl' 0:03.94 #define realloc_impl mozmem_malloc_impl(realloc) Which I really didn't feel like digging into. * I had to restore the order of TrustOverrideUtils.h and related files in nss because the .inc files depend on TrustOverrideUtils.h being included earlier. * I had to add a missing include to RollingNumber.h * Also had to partially restore include order in JsepSessionImpl.cpp to avoid some -WError issues due to some static inline functions being defined in a header but not used in the rest of the compilation unit. Differential Revision: https://phabricator.services.mozilla.com/D60327 --HG-- extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
#include <algorithm>
#include <utility>
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj This was done by: This was done by applying: ``` diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py index 789affde7bbf..fe33c4c7d4d1 100644 --- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py +++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py @@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase): from subprocess import Popen, PIPE, check_output, CalledProcessError diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE) - args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format] + args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes'] if not output_file: args.append("-i") ``` Then running `./mach clang-format -c <commit-hash>` Then undoing that patch. Then running check_spidermonkey_style.py --fixup Then running `./mach clang-format` I had to fix four things: * I needed to move <utility> back down in GuardObjects.h because I was hitting obscure problems with our system include wrappers like this: 0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration 0:03.94 extern void *realloc (void *__ptr, size_t __size) 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here 0:03.94 MALLOC_DECL(realloc, void*, void*, size_t) 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL' 0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__); 0:03.94 ^ 0:03.94 <scratch space>:178:1: note: expanded from here 0:03.94 realloc_impl 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl' 0:03.94 #define realloc_impl mozmem_malloc_impl(realloc) Which I really didn't feel like digging into. * I had to restore the order of TrustOverrideUtils.h and related files in nss because the .inc files depend on TrustOverrideUtils.h being included earlier. * I had to add a missing include to RollingNumber.h * Also had to partially restore include order in JsepSessionImpl.cpp to avoid some -WError issues due to some static inline functions being defined in a header but not used in the rest of the compilation unit. Differential Revision: https://phabricator.services.mozilla.com/D60327 --HG-- extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
#include "gfxUtils.h"
#include "mozilla/ComputedStyle.h"
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj This was done by: This was done by applying: ``` diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py index 789affde7bbf..fe33c4c7d4d1 100644 --- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py +++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py @@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase): from subprocess import Popen, PIPE, check_output, CalledProcessError diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE) - args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format] + args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes'] if not output_file: args.append("-i") ``` Then running `./mach clang-format -c <commit-hash>` Then undoing that patch. Then running check_spidermonkey_style.py --fixup Then running `./mach clang-format` I had to fix four things: * I needed to move <utility> back down in GuardObjects.h because I was hitting obscure problems with our system include wrappers like this: 0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration 0:03.94 extern void *realloc (void *__ptr, size_t __size) 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here 0:03.94 MALLOC_DECL(realloc, void*, void*, size_t) 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL' 0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__); 0:03.94 ^ 0:03.94 <scratch space>:178:1: note: expanded from here 0:03.94 realloc_impl 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl' 0:03.94 #define realloc_impl mozmem_malloc_impl(realloc) Which I really didn't feel like digging into. * I had to restore the order of TrustOverrideUtils.h and related files in nss because the .inc files depend on TrustOverrideUtils.h being included earlier. * I had to add a missing include to RollingNumber.h * Also had to partially restore include order in JsepSessionImpl.cpp to avoid some -WError issues due to some static inline functions being defined in a header but not used in the rest of the compilation unit. Differential Revision: https://phabricator.services.mozilla.com/D60327 --HG-- extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
#include "mozilla/EventStateManager.h"
#include "mozilla/Preferences.h"
#include "mozilla/PresShell.h"
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj This was done by: This was done by applying: ``` diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py index 789affde7bbf..fe33c4c7d4d1 100644 --- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py +++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py @@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase): from subprocess import Popen, PIPE, check_output, CalledProcessError diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE) - args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format] + args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes'] if not output_file: args.append("-i") ``` Then running `./mach clang-format -c <commit-hash>` Then undoing that patch. Then running check_spidermonkey_style.py --fixup Then running `./mach clang-format` I had to fix four things: * I needed to move <utility> back down in GuardObjects.h because I was hitting obscure problems with our system include wrappers like this: 0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration 0:03.94 extern void *realloc (void *__ptr, size_t __size) 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here 0:03.94 MALLOC_DECL(realloc, void*, void*, size_t) 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL' 0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__); 0:03.94 ^ 0:03.94 <scratch space>:178:1: note: expanded from here 0:03.94 realloc_impl 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl' 0:03.94 #define realloc_impl mozmem_malloc_impl(realloc) Which I really didn't feel like digging into. * I had to restore the order of TrustOverrideUtils.h and related files in nss because the .inc files depend on TrustOverrideUtils.h being included earlier. * I had to add a missing include to RollingNumber.h * Also had to partially restore include order in JsepSessionImpl.cpp to avoid some -WError issues due to some static inline functions being defined in a header but not used in the rest of the compilation unit. Differential Revision: https://phabricator.services.mozilla.com/D60327 --HG-- extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
#include "mozilla/dom/Touch.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/gfxVars.h"
#include "nsBoxLayout.h"
#include "nsBoxLayoutState.h"
1999-03-27 04:35:55 +03:00
#include "nsCOMPtr.h"
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj This was done by: This was done by applying: ``` diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py index 789affde7bbf..fe33c4c7d4d1 100644 --- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py +++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py @@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase): from subprocess import Popen, PIPE, check_output, CalledProcessError diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE) - args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format] + args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes'] if not output_file: args.append("-i") ``` Then running `./mach clang-format -c <commit-hash>` Then undoing that patch. Then running check_spidermonkey_style.py --fixup Then running `./mach clang-format` I had to fix four things: * I needed to move <utility> back down in GuardObjects.h because I was hitting obscure problems with our system include wrappers like this: 0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration 0:03.94 extern void *realloc (void *__ptr, size_t __size) 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here 0:03.94 MALLOC_DECL(realloc, void*, void*, size_t) 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL' 0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__); 0:03.94 ^ 0:03.94 <scratch space>:178:1: note: expanded from here 0:03.94 realloc_impl 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl' 0:03.94 #define realloc_impl mozmem_malloc_impl(realloc) Which I really didn't feel like digging into. * I had to restore the order of TrustOverrideUtils.h and related files in nss because the .inc files depend on TrustOverrideUtils.h being included earlier. * I had to add a missing include to RollingNumber.h * Also had to partially restore include order in JsepSessionImpl.cpp to avoid some -WError issues due to some static inline functions being defined in a header but not used in the rest of the compilation unit. Differential Revision: https://phabricator.services.mozilla.com/D60327 --HG-- extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
#include "nsCSSAnonBoxes.h"
#include "nsCSSRendering.h"
#include "nsContainerFrame.h"
#include "nsDisplayList.h"
#include "nsGkAtoms.h"
#include "nsHTMLParts.h"
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj This was done by: This was done by applying: ``` diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py index 789affde7bbf..fe33c4c7d4d1 100644 --- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py +++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py @@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase): from subprocess import Popen, PIPE, check_output, CalledProcessError diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE) - args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format] + args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes'] if not output_file: args.append("-i") ``` Then running `./mach clang-format -c <commit-hash>` Then undoing that patch. Then running check_spidermonkey_style.py --fixup Then running `./mach clang-format` I had to fix four things: * I needed to move <utility> back down in GuardObjects.h because I was hitting obscure problems with our system include wrappers like this: 0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration 0:03.94 extern void *realloc (void *__ptr, size_t __size) 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here 0:03.94 MALLOC_DECL(realloc, void*, void*, size_t) 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL' 0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__); 0:03.94 ^ 0:03.94 <scratch space>:178:1: note: expanded from here 0:03.94 realloc_impl 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl' 0:03.94 #define realloc_impl mozmem_malloc_impl(realloc) Which I really didn't feel like digging into. * I had to restore the order of TrustOverrideUtils.h and related files in nss because the .inc files depend on TrustOverrideUtils.h being included earlier. * I had to add a missing include to RollingNumber.h * Also had to partially restore include order in JsepSessionImpl.cpp to avoid some -WError issues due to some static inline functions being defined in a header but not used in the rest of the compilation unit. Differential Revision: https://phabricator.services.mozilla.com/D60327 --HG-- extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
#include "nsIContent.h"
#include "nsIScrollableFrame.h"
#include "nsITheme.h"
#include "nsLayoutUtils.h"
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj This was done by: This was done by applying: ``` diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py index 789affde7bbf..fe33c4c7d4d1 100644 --- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py +++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py @@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase): from subprocess import Popen, PIPE, check_output, CalledProcessError diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE) - args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format] + args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes'] if not output_file: args.append("-i") ``` Then running `./mach clang-format -c <commit-hash>` Then undoing that patch. Then running check_spidermonkey_style.py --fixup Then running `./mach clang-format` I had to fix four things: * I needed to move <utility> back down in GuardObjects.h because I was hitting obscure problems with our system include wrappers like this: 0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration 0:03.94 extern void *realloc (void *__ptr, size_t __size) 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here 0:03.94 MALLOC_DECL(realloc, void*, void*, size_t) 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL' 0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__); 0:03.94 ^ 0:03.94 <scratch space>:178:1: note: expanded from here 0:03.94 realloc_impl 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl' 0:03.94 #define realloc_impl mozmem_malloc_impl(realloc) Which I really didn't feel like digging into. * I had to restore the order of TrustOverrideUtils.h and related files in nss because the .inc files depend on TrustOverrideUtils.h being included earlier. * I had to add a missing include to RollingNumber.h * Also had to partially restore include order in JsepSessionImpl.cpp to avoid some -WError issues due to some static inline functions being defined in a header but not used in the rest of the compilation unit. Differential Revision: https://phabricator.services.mozilla.com/D60327 --HG-- extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
#include "nsNameSpaceManager.h"
#include "nsPlaceholderFrame.h"
#include "nsPresContext.h"
#include "nsSliderFrame.h"
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj This was done by: This was done by applying: ``` diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py index 789affde7bbf..fe33c4c7d4d1 100644 --- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py +++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py @@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase): from subprocess import Popen, PIPE, check_output, CalledProcessError diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE) - args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format] + args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes'] if not output_file: args.append("-i") ``` Then running `./mach clang-format -c <commit-hash>` Then undoing that patch. Then running check_spidermonkey_style.py --fixup Then running `./mach clang-format` I had to fix four things: * I needed to move <utility> back down in GuardObjects.h because I was hitting obscure problems with our system include wrappers like this: 0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration 0:03.94 extern void *realloc (void *__ptr, size_t __size) 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here 0:03.94 MALLOC_DECL(realloc, void*, void*, size_t) 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL' 0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__); 0:03.94 ^ 0:03.94 <scratch space>:178:1: note: expanded from here 0:03.94 realloc_impl 0:03.94 ^ 0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl' 0:03.94 #define realloc_impl mozmem_malloc_impl(realloc) Which I really didn't feel like digging into. * I had to restore the order of TrustOverrideUtils.h and related files in nss because the .inc files depend on TrustOverrideUtils.h being included earlier. * I had to add a missing include to RollingNumber.h * Also had to partially restore include order in JsepSessionImpl.cpp to avoid some -WError issues due to some static inline functions being defined in a header but not used in the rest of the compilation unit. Differential Revision: https://phabricator.services.mozilla.com/D60327 --HG-- extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
#include "nsSprocketLayout.h"
#include "nsStyleConsts.h"
#include "nsTransform2D.h"
#include "nsView.h"
#include "nsViewManager.h"
#include "nsWidgetsCID.h"
2000-06-22 04:48:49 +04:00
// Needed for Print Preview
#include "mozilla/TouchEvents.h"
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::gfx;
nsIFrame* NS_NewBoxFrame(PresShell* aPresShell, ComputedStyle* aStyle,
bool aIsRoot, nsBoxLayout* aLayoutManager) {
return new (aPresShell)
nsBoxFrame(aStyle, aPresShell->GetPresContext(), nsBoxFrame::kClassID,
aIsRoot, aLayoutManager);
}
1999-03-27 04:35:55 +03:00
nsIFrame* NS_NewBoxFrame(PresShell* aPresShell, ComputedStyle* aStyle) {
return new (aPresShell) nsBoxFrame(aStyle, aPresShell->GetPresContext());
}
NS_IMPL_FRAMEARENA_HELPERS(nsBoxFrame)
#ifdef DEBUG
NS_QUERYFRAME_HEAD(nsBoxFrame)
NS_QUERYFRAME_ENTRY(nsBoxFrame)
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
#endif
nsBoxFrame::nsBoxFrame(ComputedStyle* aStyle, nsPresContext* aPresContext,
ClassID aID, bool aIsRoot, nsBoxLayout* aLayoutManager)
: nsContainerFrame(aStyle, aPresContext, aID), mFlex(0), mAscent(0) {
AddStateBits(NS_STATE_IS_HORIZONTAL | NS_STATE_AUTO_STRETCH);
2000-02-17 02:00:52 +03:00
if (aIsRoot) AddStateBits(NS_STATE_IS_ROOT);
mValign = vAlign_Top;
mHalign = hAlign_Left;
// if no layout manager specified us the static sprocket layout
2011-07-11 18:05:10 +04:00
nsCOMPtr<nsBoxLayout> layout = aLayoutManager;
if (layout == nullptr) {
NS_NewSprocketLayout(layout);
}
SetXULLayoutManager(layout);
}
nsBoxFrame::~nsBoxFrame() = default;
1999-03-27 04:35:55 +03:00
void nsBoxFrame::SetInitialChildList(ChildListID aListID,
nsFrameList& aChildList) {
nsContainerFrame::SetInitialChildList(aListID, aChildList);
if (aListID == kPrincipalList) {
// initialize our list of infos.
nsBoxLayoutState state(PresContext());
CheckBoxOrder();
if (mLayoutManager)
mLayoutManager->ChildrenSet(this, state, mFrames.FirstChild());
}
}
/* virtual */
void nsBoxFrame::DidSetComputedStyle(ComputedStyle* aOldComputedStyle) {
nsContainerFrame::DidSetComputedStyle(aOldComputedStyle);
// The values that CacheAttributes() computes depend on our style,
// so we need to recompute them here...
CacheAttributes();
}
/**
* Initialize us. This is a good time to get the alignment of the box
*/
void nsBoxFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
nsIFrame* aPrevInFlow) {
nsContainerFrame::Init(aContent, aParent, aPrevInFlow);
2000-01-08 05:18:14 +03:00
if (GetStateBits() & NS_FRAME_FONT_INFLATION_CONTAINER) {
AddStateBits(NS_FRAME_FONT_INFLATION_FLOW_ROOT);
}
MarkIntrinsicISizesDirty();
CacheAttributes();
// register access key
RegUnregAccessKey(true);
}
void nsBoxFrame::CacheAttributes() {
/*
printf("Caching: ");
XULDumpBox(stdout);
printf("\n");
*/
mValign = vAlign_Top;
mHalign = hAlign_Left;
bool orient = false;
GetInitialOrientation(orient);
if (orient)
AddStateBits(NS_STATE_IS_HORIZONTAL);
2001-08-02 04:09:27 +04:00
else
RemoveStateBits(NS_STATE_IS_HORIZONTAL);
bool normal = true;
GetInitialDirection(normal);
2001-08-15 08:09:41 +04:00
if (normal)
AddStateBits(NS_STATE_IS_DIRECTION_NORMAL);
2001-08-15 08:09:41 +04:00
else
RemoveStateBits(NS_STATE_IS_DIRECTION_NORMAL);
2001-08-15 08:09:41 +04:00
GetInitialVAlignment(mValign);
GetInitialHAlignment(mHalign);
bool equalSize = false;
GetInitialEqualSize(equalSize);
if (equalSize)
AddStateBits(NS_STATE_EQUAL_SIZE);
else
RemoveStateBits(NS_STATE_EQUAL_SIZE);
bool autostretch = !!(mState & NS_STATE_AUTO_STRETCH);
GetInitialAutoStretch(autostretch);
if (autostretch)
AddStateBits(NS_STATE_AUTO_STRETCH);
else
RemoveStateBits(NS_STATE_AUTO_STRETCH);
}
2000-02-14 04:42:09 +03:00
bool nsBoxFrame::GetInitialHAlignment(nsBoxFrame::Halignment& aHalign) {
if (!GetContent()) return false;
2000-02-14 04:42:09 +03:00
// For horizontal boxes we're checking PACK. For vertical boxes we are
// checking ALIGN.
const nsStyleXUL* boxInfo = StyleXUL();
if (IsXULHorizontal()) {
2001-08-02 04:09:27 +04:00
switch (boxInfo->mBoxPack) {
case StyleBoxPack::Start:
2001-08-02 04:09:27 +04:00
aHalign = nsBoxFrame::hAlign_Left;
return true;
case StyleBoxPack::Center:
2001-08-02 04:09:27 +04:00
aHalign = nsBoxFrame::hAlign_Center;
return true;
case StyleBoxPack::End:
2001-08-02 04:09:27 +04:00
aHalign = nsBoxFrame::hAlign_Right;
return true;
2001-08-02 04:09:27 +04:00
default: // Nonsensical value. Just bail.
return false;
2001-08-02 04:09:27 +04:00
}
} else {
switch (boxInfo->mBoxAlign) {
case StyleBoxAlign::Start:
2001-08-02 04:09:27 +04:00
aHalign = nsBoxFrame::hAlign_Left;
return true;
case StyleBoxAlign::Center:
2001-08-02 04:09:27 +04:00
aHalign = nsBoxFrame::hAlign_Center;
return true;
case StyleBoxAlign::End:
2001-08-02 04:09:27 +04:00
aHalign = nsBoxFrame::hAlign_Right;
return true;
2001-08-02 04:09:27 +04:00
default: // Nonsensical value. Just bail.
return false;
2001-08-02 04:09:27 +04:00
}
}
2000-02-14 04:42:09 +03:00
return false;
2000-02-14 04:42:09 +03:00
}
bool nsBoxFrame::GetInitialVAlignment(nsBoxFrame::Valignment& aValign) {
if (!GetContent()) return false;
// For horizontal boxes we're checking ALIGN. For vertical boxes we are
// checking PACK.
const nsStyleXUL* boxInfo = StyleXUL();
if (IsXULHorizontal()) {
2001-08-02 04:09:27 +04:00
switch (boxInfo->mBoxAlign) {
case StyleBoxAlign::Start:
2001-08-02 04:09:27 +04:00
aValign = nsBoxFrame::vAlign_Top;
return true;
case StyleBoxAlign::Center:
2001-08-02 04:09:27 +04:00
aValign = nsBoxFrame::vAlign_Middle;
return true;
case StyleBoxAlign::Baseline:
2001-08-02 04:09:27 +04:00
aValign = nsBoxFrame::vAlign_BaseLine;
return true;
case StyleBoxAlign::End:
2001-08-02 04:09:27 +04:00
aValign = nsBoxFrame::vAlign_Bottom;
return true;
2001-08-02 04:09:27 +04:00
default: // Nonsensical value. Just bail.
return false;
2001-08-02 04:09:27 +04:00
}
} else {
switch (boxInfo->mBoxPack) {
case StyleBoxPack::Start:
2001-08-02 04:09:27 +04:00
aValign = nsBoxFrame::vAlign_Top;
return true;
case StyleBoxPack::Center:
2001-08-02 04:09:27 +04:00
aValign = nsBoxFrame::vAlign_Middle;
return true;
case StyleBoxPack::End:
2001-08-02 04:09:27 +04:00
aValign = nsBoxFrame::vAlign_Bottom;
return true;
2001-08-02 04:09:27 +04:00
default: // Nonsensical value. Just bail.
return false;
2001-08-02 04:09:27 +04:00
}
}
2000-02-14 04:42:09 +03:00
return false;
}
void nsBoxFrame::GetInitialOrientation(bool& aIsHorizontal) {
// see if we are a vertical or horizontal box.
if (!GetContent()) return;
const nsStyleXUL* boxInfo = StyleXUL();
if (boxInfo->mBoxOrient == StyleBoxOrient::Horizontal) {
aIsHorizontal = true;
} else {
aIsHorizontal = false;
}
2000-02-14 04:42:09 +03:00
}
void nsBoxFrame::GetInitialDirection(bool& aIsNormal) {
if (!GetContent()) return;
2001-08-15 08:09:41 +04:00
if (IsXULHorizontal()) {
2001-08-15 08:09:41 +04:00
// For horizontal boxes only, we initialize our value based off the CSS
// 'direction' property. This means that BiDI users will end up with
// horizontally inverted chrome.
//
// If text runs RTL then so do we.
aIsNormal = StyleVisibility()->mDirection == StyleDirection::Ltr;
if (GetContent()->IsElement()) {
Element* element = GetContent()->AsElement();
// Now see if we have an attribute. The attribute overrides
// the style system 'direction' property.
static Element::AttrValuesArray strings[] = {nsGkAtoms::ltr,
nsGkAtoms::rtl, nullptr};
int32_t index = element->FindAttrValueIn(
kNameSpaceID_None, nsGkAtoms::dir, strings, eCaseMatters);
if (index >= 0) {
bool values[] = {true, false};
aIsNormal = values[index];
}
}
} else {
aIsNormal = true; // Assume a normal direction in the vertical case.
}
2001-08-15 08:09:41 +04:00
// Now check the style system to see if we should invert aIsNormal.
const nsStyleXUL* boxInfo = StyleXUL();
if (boxInfo->mBoxDirection == StyleBoxDirection::Reverse) {
2001-08-15 08:09:41 +04:00
aIsNormal = !aIsNormal; // Invert our direction.
}
2001-08-15 08:09:41 +04:00
}
/* Returns true if it was set.
*/
bool nsBoxFrame::GetInitialEqualSize(bool& aEqualSize) {
// see if we are a vertical or horizontal box.
if (!GetContent() || !GetContent()->IsElement()) return false;
if (GetContent()->AsElement()->AttrValueIs(kNameSpaceID_None,
nsGkAtoms::equalsize,
nsGkAtoms::always, eCaseMatters)) {
aEqualSize = true;
return true;
}
return false;
}
2000-02-14 04:42:09 +03:00
/* Returns true if it was set.
*/
bool nsBoxFrame::GetInitialAutoStretch(bool& aStretch) {
if (!GetContent()) return false;
// Check the CSS box-align property.
const nsStyleXUL* boxInfo = StyleXUL();
aStretch = (boxInfo->mBoxAlign == StyleBoxAlign::Stretch);
2001-08-02 04:09:27 +04:00
return true;
}
void nsBoxFrame::DidReflow(nsPresContext* aPresContext,
const ReflowInput* aReflowInput) {
2003-06-02 00:03:13 +04:00
nsFrameState preserveBits =
mState & (NS_FRAME_IS_DIRTY | NS_FRAME_HAS_DIRTY_CHILDREN);
nsFrame::DidReflow(aPresContext, aReflowInput);
AddStateBits(preserveBits);
if (preserveBits & NS_FRAME_IS_DIRTY) {
this->MarkSubtreeDirty();
}
}
2007-10-12 22:37:51 +04:00
bool nsBoxFrame::HonorPrintBackgroundSettings() {
return !mContent->IsInNativeAnonymousSubtree() &&
2007-10-12 22:37:51 +04:00
nsContainerFrame::HonorPrintBackgroundSettings();
}
#ifdef DO_NOISY_REFLOW
static int myCounter = 0;
static void printSize(char* aDesc, nscoord aSize) {
printf(" %s: ", aDesc);
if (aSize == NS_UNCONSTRAINEDSIZE) {
printf("UC");
} else {
printf("%d", aSize);
}
}
#endif
/* virtual */
nscoord nsBoxFrame::GetMinISize(gfxContext* aRenderingContext) {
nscoord result;
DISPLAY_MIN_INLINE_SIZE(this, result);
nsBoxLayoutState state(PresContext(), aRenderingContext);
nsSize minSize = GetXULMinSize(state);
// GetXULMinSize returns border-box width, and we want to return content
// width. Since Reflow uses the reflow input's border and padding, we
// actually just want to subtract what GetXULMinSize added, which is the
// result of GetXULBorderAndPadding.
nsMargin bp;
GetXULBorderAndPadding(bp);
result = minSize.width - bp.LeftRight();
result = std::max(result, 0);
return result;
}
/* virtual */
nscoord nsBoxFrame::GetPrefISize(gfxContext* aRenderingContext) {
nscoord result;
DISPLAY_PREF_INLINE_SIZE(this, result);
nsBoxLayoutState state(PresContext(), aRenderingContext);
nsSize prefSize = GetXULPrefSize(state);
// GetXULPrefSize returns border-box width, and we want to return content
// width. Since Reflow uses the reflow input's border and padding, we
// actually just want to subtract what GetXULPrefSize added, which is the
// result of GetXULBorderAndPadding.
nsMargin bp;
GetXULBorderAndPadding(bp);
result = prefSize.width - bp.LeftRight();
result = std::max(result, 0);
return result;
}
void nsBoxFrame::Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
const ReflowInput& aReflowInput,
nsReflowStatus& aStatus) {
MarkInReflow();
// If you make changes to this method, please keep nsLeafBoxFrame::Reflow
// in sync, if the changes are applicable there.
DO_GLOBAL_REFLOW_COUNT("nsBoxFrame");
DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus);
MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!");
1999-03-27 04:35:55 +03:00
NS_ASSERTION(
aReflowInput.ComputedWidth() >= 0 && aReflowInput.ComputedHeight() >= 0,
"Computed Size < 0");
#ifdef DO_NOISY_REFLOW
printf(
"\n-------------Starting BoxFrame Reflow ----------------------------\n");
printf("%p ** nsBF::Reflow %d ", this, myCounter++);
printSize("AW", aReflowInput.AvailableWidth());
printSize("AH", aReflowInput.AvailableHeight());
printSize("CW", aReflowInput.ComputedWidth());
printSize("CH", aReflowInput.ComputedHeight());
printf(" *\n");
#endif
2000-03-31 11:02:06 +04:00
// create the layout state
nsBoxLayoutState state(aPresContext, aReflowInput.mRenderingContext,
&aReflowInput, aReflowInput.mReflowDepth);
WritingMode wm = aReflowInput.GetWritingMode();
LogicalSize computedSize = aReflowInput.ComputedSize();
1999-09-14 00:24:20 +04:00
LogicalMargin m = aReflowInput.ComputedLogicalBorderPadding();
// GetXULBorderAndPadding(m);
1999-08-31 02:32:25 +04:00
LogicalSize prefSize(wm);
1999-09-14 00:24:20 +04:00
// if we are told to layout intrinsic then get our preferred size.
NS_ASSERTION(computedSize.ISize(wm) != NS_UNCONSTRAINEDSIZE,
"computed inline size should always be computed");
if (computedSize.BSize(wm) == NS_UNCONSTRAINEDSIZE) {
nsSize physicalPrefSize = GetXULPrefSize(state);
nsSize minSize = GetXULMinSize(state);
nsSize maxSize = GetXULMaxSize(state);
// XXXbz isn't GetXULPrefSize supposed to bounds-check for us?
physicalPrefSize = XULBoundsCheck(minSize, physicalPrefSize, maxSize);
prefSize = LogicalSize(wm, physicalPrefSize);
2000-03-31 11:02:06 +04:00
}
2000-03-31 11:02:06 +04:00
// get our desiredSize
computedSize.ISize(wm) += m.IStart(wm) + m.IEnd(wm);
if (aReflowInput.ComputedBSize() == NS_UNCONSTRAINEDSIZE) {
computedSize.BSize(wm) = prefSize.BSize(wm);
// prefSize is border-box but min/max constraints are content-box.
nscoord blockDirBorderPadding =
aReflowInput.ComputedLogicalBorderPadding().BStartEnd(wm);
nscoord contentBSize = computedSize.BSize(wm) - blockDirBorderPadding;
// Note: contentHeight might be negative, but that's OK because min-height
// is never negative.
computedSize.BSize(wm) =
aReflowInput.ApplyMinMaxHeight(contentBSize) + blockDirBorderPadding;
} else {
computedSize.BSize(wm) += m.BStart(wm) + m.BEnd(wm);
}
nsSize physicalSize = computedSize.GetPhysicalSize(wm);
nsRect r(mRect.x, mRect.y, physicalSize.width, physicalSize.height);
SetXULBounds(state, r);
2000-03-31 11:02:06 +04:00
// layout our children
XULLayout(state);
2000-03-31 11:02:06 +04:00
// ok our child could have gotten bigger. So lets get its bounds
2000-03-31 11:02:06 +04:00
// get the ascent
LogicalSize boxSize = GetLogicalSize(wm);
nscoord ascent = boxSize.BSize(wm);
2000-03-31 11:02:06 +04:00
// getting the ascent could be a lot of work. Don't get it if
// we are the root. The viewport doesn't care about it.
if (!(mState & NS_STATE_IS_ROOT)) {
ascent = GetXULBoxAscent(state);
}
aDesiredSize.SetSize(wm, boxSize);
aDesiredSize.SetBlockStartAscent(ascent);
aDesiredSize.mOverflowAreas = GetOverflowAreas();
#ifdef DO_NOISY_REFLOW
{
printf("%p ** nsBF(done) W:%d H:%d ", this, aDesiredSize.Width(),
aDesiredSize.Height());
if (maxElementSize) {
printf("MW:%d\n", *maxElementWidth);
} else {
printf("MW:?\n");
}
}
#endif
ReflowAbsoluteFrames(aPresContext, aDesiredSize, aReflowInput, aStatus);
NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize);
}
nsSize nsBoxFrame::GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) {
NS_ASSERTION(aBoxLayoutState.GetRenderingContext(),
"must have rendering context");
nsSize size(0, 0);
DISPLAY_PREF_SIZE(this, size);
if (!XULNeedsRecalc(mPrefSize)) {
size = mPrefSize;
return size;
}
if (IsXULCollapsed()) return size;
// if the size was not completely redefined in CSS then ask our children
bool widthSet, heightSet;
if (!nsIFrame::AddXULPrefSize(this, size, widthSet, heightSet)) {
if (mLayoutManager) {
nsSize layoutSize = mLayoutManager->GetXULPrefSize(this, aBoxLayoutState);
if (!widthSet) size.width = layoutSize.width;
if (!heightSet) size.height = layoutSize.height;
} else {
size = nsIFrame::GetXULPrefSize(aBoxLayoutState);
}
}
nsSize minSize = GetXULMinSize(aBoxLayoutState);
nsSize maxSize = GetXULMaxSize(aBoxLayoutState);
mPrefSize = XULBoundsCheck(minSize, size, maxSize);
return mPrefSize;
2000-03-31 11:02:06 +04:00
}
1999-10-22 00:17:51 +04:00
nscoord nsBoxFrame::GetXULBoxAscent(nsBoxLayoutState& aBoxLayoutState) {
if (!XULNeedsRecalc(mAscent)) {
return mAscent;
}
1999-07-24 03:30:17 +04:00
if (IsXULCollapsed()) {
return 0;
}
if (mLayoutManager) {
mAscent = mLayoutManager->GetAscent(this, aBoxLayoutState);
} else {
mAscent = nsIFrame::GetXULBoxAscent(aBoxLayoutState);
}
return mAscent;
2000-03-31 11:02:06 +04:00
}
1999-07-24 03:30:17 +04:00
nsSize nsBoxFrame::GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) {
NS_ASSERTION(aBoxLayoutState.GetRenderingContext(),
"must have rendering context");
nsSize size(0, 0);
DISPLAY_MIN_SIZE(this, size);
if (!XULNeedsRecalc(mMinSize)) {
size = mMinSize;
return size;
2000-03-31 11:02:06 +04:00
}
1999-07-24 03:30:17 +04:00
if (IsXULCollapsed()) return size;
// if the size was not completely redefined in CSS then ask our children
bool widthSet, heightSet;
if (!nsIFrame::AddXULMinSize(this, size, widthSet, heightSet)) {
if (mLayoutManager) {
nsSize layoutSize = mLayoutManager->GetXULMinSize(this, aBoxLayoutState);
if (!widthSet) size.width = layoutSize.width;
if (!heightSet) size.height = layoutSize.height;
} else {
size = nsIFrame::GetXULMinSize(aBoxLayoutState);
}
}
mMinSize = size;
return size;
2000-03-31 11:02:06 +04:00
}
1999-07-24 03:30:17 +04:00
nsSize nsBoxFrame::GetXULMaxSize(nsBoxLayoutState& aBoxLayoutState) {
NS_ASSERTION(aBoxLayoutState.GetRenderingContext(),
"must have rendering context");
nsSize size(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
DISPLAY_MAX_SIZE(this, size);
if (!XULNeedsRecalc(mMaxSize)) {
size = mMaxSize;
return size;
2000-03-31 11:02:06 +04:00
}
1999-07-24 03:30:17 +04:00
if (IsXULCollapsed()) return size;
// if the size was not completely redefined in CSS then ask our children
bool widthSet, heightSet;
if (!nsIFrame::AddXULMaxSize(this, size, widthSet, heightSet)) {
if (mLayoutManager) {
nsSize layoutSize = mLayoutManager->GetXULMaxSize(this, aBoxLayoutState);
if (!widthSet) size.width = layoutSize.width;
if (!heightSet) size.height = layoutSize.height;
} else {
size = nsIFrame::GetXULMaxSize(aBoxLayoutState);
}
}
mMaxSize = size;
return size;
1999-03-27 04:35:55 +03:00
}
nscoord nsBoxFrame::GetXULFlex() {
if (!XULNeedsRecalc(mFlex)) {
return mFlex;
}
mFlex = nsIFrame::GetXULFlex();
return mFlex;
2000-03-31 11:02:06 +04:00
}
/**
* If subclassing please subclass this method not layout.
* layout will call this method.
*/
NS_IMETHODIMP
nsBoxFrame::DoXULLayout(nsBoxLayoutState& aState) {
ReflowChildFlags oldFlags = aState.LayoutFlags();
aState.SetLayoutFlags(ReflowChildFlags::Default);
nsresult rv = NS_OK;
if (mLayoutManager) {
XULCoordNeedsRecalc(mAscent);
rv = mLayoutManager->XULLayout(this, aState);
}
aState.SetLayoutFlags(oldFlags);
if (HasAbsolutelyPositionedChildren()) {
// Set up a |reflowInput| to pass into ReflowAbsoluteFrames
WritingMode wm = GetWritingMode();
ReflowInput reflowInput(
aState.PresContext(), this, aState.GetRenderingContext(),
LogicalSize(wm, GetLogicalSize().ISize(wm), NS_UNCONSTRAINEDSIZE));
// Set up a |desiredSize| to pass into ReflowAbsoluteFrames
ReflowOutput desiredSize(reflowInput);
desiredSize.Width() = mRect.width;
desiredSize.Height() = mRect.height;
// get the ascent (cribbed from ::Reflow)
nscoord ascent = mRect.height;
// getting the ascent could be a lot of work. Don't get it if
// we are the root. The viewport doesn't care about it.
if (!(mState & NS_STATE_IS_ROOT)) {
ascent = GetXULBoxAscent(aState);
}
desiredSize.SetBlockStartAscent(ascent);
desiredSize.mOverflowAreas = GetOverflowAreas();
AddStateBits(NS_FRAME_IN_REFLOW);
// Set up a |reflowStatus| to pass into ReflowAbsoluteFrames
// (just a dummy value; hopefully that's OK)
nsReflowStatus reflowStatus;
ReflowAbsoluteFrames(aState.PresContext(), desiredSize, reflowInput,
reflowStatus);
RemoveStateBits(NS_FRAME_IN_REFLOW);
}
return rv;
}
void nsBoxFrame::DestroyFrom(nsIFrame* aDestructRoot,
PostDestroyData& aPostDestroyData) {
// unregister access key
RegUnregAccessKey(false);
// clean up the container box's layout manager and child boxes
SetXULLayoutManager(nullptr);
nsContainerFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
}
/* virtual */
void nsBoxFrame::MarkIntrinsicISizesDirty() {
XULSizeNeedsRecalc(mPrefSize);
XULSizeNeedsRecalc(mMinSize);
XULSizeNeedsRecalc(mMaxSize);
XULCoordNeedsRecalc(mFlex);
XULCoordNeedsRecalc(mAscent);
if (mLayoutManager) {
nsBoxLayoutState state(PresContext());
mLayoutManager->IntrinsicISizesDirty(this, state);
}
nsContainerFrame::MarkIntrinsicISizesDirty();
2000-03-31 11:02:06 +04:00
}
void nsBoxFrame::RemoveFrame(ChildListID aListID, nsIFrame* aOldFrame) {
MOZ_ASSERT(aListID == kPrincipalList, "We don't support out-of-flow kids");
nsPresContext* presContext = PresContext();
nsBoxLayoutState state(presContext);
2000-03-31 11:02:06 +04:00
// remove the child frame
mFrames.RemoveFrame(aOldFrame);
// notify the layout manager
if (mLayoutManager) mLayoutManager->ChildrenRemoved(this, state, aOldFrame);
2000-03-31 11:02:06 +04:00
// destroy the child frame
aOldFrame->Destroy();
2000-03-31 11:02:06 +04:00
// mark us dirty and generate a reflow command
PresShell()->FrameNeedsReflow(this, IntrinsicDirty::TreeChange,
NS_FRAME_HAS_DIRTY_CHILDREN);
}
void nsBoxFrame::InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
const nsLineList::iterator* aPrevFrameLine,
nsFrameList& aFrameList) {
NS_ASSERTION(!aPrevFrame || aPrevFrame->GetParent() == this,
"inserting after sibling frame with different parent");
NS_ASSERTION(!aPrevFrame || mFrames.ContainsFrame(aPrevFrame),
"inserting after sibling frame not in our child list");
MOZ_ASSERT(aListID == kPrincipalList, "We don't support out-of-flow kids");
nsBoxLayoutState state(PresContext());
// insert the child frames
const nsFrameList::Slice& newFrames =
mFrames.InsertFrames(this, aPrevFrame, aFrameList);
// notify the layout manager
if (mLayoutManager)
mLayoutManager->ChildrenInserted(this, state, aPrevFrame, newFrames);
// Make sure to check box order _after_ notifying the layout
// manager; otherwise the slice we give the layout manager will
// just be bogus. If the layout manager cares about the order, we
// just lose.
CheckBoxOrder();
PresShell()->FrameNeedsReflow(this, IntrinsicDirty::TreeChange,
NS_FRAME_HAS_DIRTY_CHILDREN);
}
1999-05-18 08:06:52 +04:00
void nsBoxFrame::AppendFrames(ChildListID aListID, nsFrameList& aFrameList) {
MOZ_ASSERT(aListID == kPrincipalList, "We don't support out-of-flow kids");
nsBoxLayoutState state(PresContext());
2000-03-31 11:02:06 +04:00
// append the new frames
const nsFrameList::Slice& newFrames = mFrames.AppendFrames(this, aFrameList);
// notify the layout manager
if (mLayoutManager) mLayoutManager->ChildrenAppended(this, state, newFrames);
// Make sure to check box order _after_ notifying the layout
// manager; otherwise the slice we give the layout manager will
// just be bogus. If the layout manager cares about the order, we
// just lose.
CheckBoxOrder();
// XXXbz why is this NS_FRAME_FIRST_REFLOW check here?
if (!(GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
PresShell()->FrameNeedsReflow(this, IntrinsicDirty::TreeChange,
NS_FRAME_HAS_DIRTY_CHILDREN);
}
}
/* virtual */
nsContainerFrame* nsBoxFrame::GetContentInsertionFrame() {
if (GetStateBits() & NS_STATE_BOX_WRAPS_KIDS_IN_BLOCK)
return PrincipalChildList().FirstChild()->GetContentInsertionFrame();
return nsContainerFrame::GetContentInsertionFrame();
}
1999-03-27 04:35:55 +03:00
nsresult nsBoxFrame::AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
int32_t aModType) {
nsresult rv =
nsContainerFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
// Ignore 'width', 'height', 'screenX', 'screenY' and 'sizemode' on a
// <window>.
if (mContent->IsXULElement(nsGkAtoms::window) &&
(nsGkAtoms::width == aAttribute || nsGkAtoms::height == aAttribute ||
nsGkAtoms::screenX == aAttribute || nsGkAtoms::screenY == aAttribute ||
nsGkAtoms::sizemode == aAttribute)) {
return rv;
}
if (aAttribute == nsGkAtoms::width || aAttribute == nsGkAtoms::height ||
aAttribute == nsGkAtoms::align || aAttribute == nsGkAtoms::valign ||
aAttribute == nsGkAtoms::left || aAttribute == nsGkAtoms::top ||
aAttribute == nsGkAtoms::right || aAttribute == nsGkAtoms::bottom ||
aAttribute == nsGkAtoms::start || aAttribute == nsGkAtoms::end ||
aAttribute == nsGkAtoms::minwidth || aAttribute == nsGkAtoms::maxwidth ||
aAttribute == nsGkAtoms::minheight ||
aAttribute == nsGkAtoms::maxheight || aAttribute == nsGkAtoms::flex ||
aAttribute == nsGkAtoms::orient || aAttribute == nsGkAtoms::pack ||
aAttribute == nsGkAtoms::dir || aAttribute == nsGkAtoms::equalsize) {
if (aAttribute == nsGkAtoms::align || aAttribute == nsGkAtoms::valign ||
aAttribute == nsGkAtoms::orient || aAttribute == nsGkAtoms::pack ||
aAttribute == nsGkAtoms::dir) {
mValign = nsBoxFrame::vAlign_Top;
mHalign = nsBoxFrame::hAlign_Left;
bool orient = true;
GetInitialOrientation(orient);
if (orient)
AddStateBits(NS_STATE_IS_HORIZONTAL);
else
RemoveStateBits(NS_STATE_IS_HORIZONTAL);
bool normal = true;
GetInitialDirection(normal);
if (normal)
AddStateBits(NS_STATE_IS_DIRECTION_NORMAL);
else
RemoveStateBits(NS_STATE_IS_DIRECTION_NORMAL);
GetInitialVAlignment(mValign);
GetInitialHAlignment(mHalign);
bool equalSize = false;
GetInitialEqualSize(equalSize);
if (equalSize)
AddStateBits(NS_STATE_EQUAL_SIZE);
else
RemoveStateBits(NS_STATE_EQUAL_SIZE);
bool autostretch = !!(mState & NS_STATE_AUTO_STRETCH);
GetInitialAutoStretch(autostretch);
if (autostretch)
AddStateBits(NS_STATE_AUTO_STRETCH);
else
RemoveStateBits(NS_STATE_AUTO_STRETCH);
} else if (aAttribute == nsGkAtoms::left || aAttribute == nsGkAtoms::top ||
aAttribute == nsGkAtoms::right ||
aAttribute == nsGkAtoms::bottom ||
aAttribute == nsGkAtoms::start || aAttribute == nsGkAtoms::end) {
RemoveStateBits(NS_STATE_STACK_NOT_POSITIONED);
}
PresShell()->FrameNeedsReflow(this, IntrinsicDirty::StyleChange,
NS_FRAME_IS_DIRTY);
}
// If the accesskey changed, register for the new value
// The old value has been unregistered in nsXULElement::SetAttr
else if (aAttribute == nsGkAtoms::accesskey) {
RegUnregAccessKey(true);
} else if (aAttribute == nsGkAtoms::rows &&
mContent->IsXULElement(nsGkAtoms::tree)) {
// Reflow ourselves and all our children if "rows" changes, since
// nsTreeBodyFrame's layout reads this from its parent (this frame).
PresShell()->FrameNeedsReflow(this, IntrinsicDirty::StyleChange,
NS_FRAME_IS_DIRTY);
}
1999-03-27 04:35:55 +03:00
return rv;
}
void nsBoxFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsDisplayListSet& aLists) {
bool forceLayer = false;
if (GetContent()->IsXULElement()) {
// forcelayer is only supported on XUL elements with box layout
if (GetContent()->AsElement()->HasAttr(kNameSpaceID_None,
nsGkAtoms::layer)) {
forceLayer = true;
}
// Check for frames that are marked as a part of the region used
// in calculating glass margins on Windows.
const nsStyleDisplay* styles = StyleDisplay();
if (styles && styles->mAppearance == StyleAppearance::MozWinExcludeGlass) {
aBuilder->AddWindowExcludeGlassRegion(
this, nsRect(aBuilder->ToReferenceFrame(this), GetSize()));
}
}
nsDisplayListCollection tempLists(aBuilder);
const nsDisplayListSet& destination = (forceLayer) ? tempLists : aLists;
DisplayBorderBackgroundOutline(aBuilder, destination);
Maybe<nsDisplayListBuilder::AutoContainerASRTracker> contASRTracker;
if (forceLayer) {
contASRTracker.emplace(aBuilder);
}
BuildDisplayListForChildren(aBuilder, destination);
2000-09-01 04:59:09 +04:00
// see if we have to draw a selection frame around this container
DisplaySelectionOverlay(aBuilder, destination.Content());
if (forceLayer) {
// This is a bit of a hack. Collect up all descendant display items
// and merge them into a single Content() list. This can cause us
// to violate CSS stacking order, but forceLayer is a magic
// XUL-only extension anyway.
2017-11-16 06:09:28 +03:00
nsDisplayList masterList;
masterList.AppendToTop(tempLists.BorderBackground());
masterList.AppendToTop(tempLists.BlockBorderBackgrounds());
masterList.AppendToTop(tempLists.Floats());
masterList.AppendToTop(tempLists.Content());
masterList.AppendToTop(tempLists.PositionedDescendants());
masterList.AppendToTop(tempLists.Outlines());
const ActiveScrolledRoot* ownLayerASR = contASRTracker->GetContainerASR();
DisplayListClipState::AutoSaveRestore ownLayerClipState(aBuilder);
if (forceLayer) {
// Wrap the list to make it its own layer
aLists.Content()->AppendNewToTop<nsDisplayOwnLayer>(
aBuilder, this, &masterList, ownLayerASR,
nsDisplayOwnLayerFlags::None, mozilla::layers::ScrollbarData{}, true,
true, nsDisplayOwnLayer::OwnLayerForBoxFrame);
}
}
2000-09-01 04:59:09 +04:00
}
void nsBoxFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
const nsDisplayListSet& aLists) {
nsIFrame* kid = mFrames.FirstChild();
// Put each child's background onto the BlockBorderBackgrounds list
// to emulate the existing two-layer XUL painting scheme.
nsDisplayListSet set(aLists, aLists.BlockBorderBackgrounds());
// The children should be in the right order
while (kid) {
BuildDisplayListForChild(aBuilder, kid, set);
kid = kid->GetNextSibling();
2000-09-01 04:59:09 +04:00
}
}
#ifdef DEBUG_FRAME_DUMP
nsresult nsBoxFrame::GetFrameName(nsAString& aResult) const {
return MakeFrameName(NS_LITERAL_STRING("Box"), aResult);
2000-03-31 11:02:06 +04:00
}
#endif
// If you make changes to this function, check its counterparts
// in nsTextBoxFrame and nsXULLabelFrame
void nsBoxFrame::RegUnregAccessKey(bool aDoReg) {
MOZ_ASSERT(mContent);
// only support accesskeys for the following elements
if (!mContent->IsAnyOfXULElements(nsGkAtoms::button, nsGkAtoms::toolbarbutton,
nsGkAtoms::checkbox, nsGkAtoms::tab,
nsGkAtoms::radio)) {
return;
}
nsAutoString accessKey;
mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey,
accessKey);
if (accessKey.IsEmpty()) return;
// With a valid PresContext we can get the ESM
// and register the access key
EventStateManager* esm = PresContext()->EventStateManager();
uint32_t key = accessKey.First();
if (aDoReg)
esm->RegisterAccessKey(mContent->AsElement(), key);
else
esm->UnregisterAccessKey(mContent->AsElement(), key);
}
void nsBoxFrame::AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) {
if (GetStateBits() & NS_STATE_BOX_WRAPS_KIDS_IN_BLOCK) {
aResult.AppendElement(OwnedAnonBox(PrincipalChildList().FirstChild()));
}
}
// Helper less-than-or-equal function, used in CheckBoxOrder() as a
// template-parameter for the sorting functions.
static bool IsBoxOrdinalLEQ(nsIFrame* aFrame1, nsIFrame* aFrame2) {
// If we've got a placeholder frame, use its out-of-flow frame's ordinal val.
nsIFrame* aRealFrame1 = nsPlaceholderFrame::GetRealFrameFor(aFrame1);
nsIFrame* aRealFrame2 = nsPlaceholderFrame::GetRealFrameFor(aFrame2);
return aRealFrame1->StyleXUL()->mBoxOrdinal <=
aRealFrame2->StyleXUL()->mBoxOrdinal;
}
void nsBoxFrame::CheckBoxOrder() {
if (!nsIFrame::IsFrameListSorted<IsBoxOrdinalLEQ>(mFrames)) {
nsIFrame::SortFrameList<IsBoxOrdinalLEQ>(mFrames);
}
}
nsresult nsBoxFrame::LayoutChildAt(nsBoxLayoutState& aState, nsIFrame* aBox,
const nsRect& aRect) {
// get the current rect
nsRect oldRect(aBox->GetRect());
aBox->SetXULBounds(aState, aRect);
bool layout = NS_SUBTREE_DIRTY(aBox);
if (layout ||
(oldRect.width != aRect.width || oldRect.height != aRect.height)) {
return aBox->XULLayout(aState);
}
return NS_OK;
}
nsresult nsBoxFrame::XULRelayoutChildAtOrdinal(nsIFrame* aChild) {
int32_t ord = aChild->StyleXUL()->mBoxOrdinal;
nsIFrame* child = mFrames.FirstChild();
nsIFrame* newPrevSib = nullptr;
while (child) {
if (ord < child->StyleXUL()->mBoxOrdinal) {
break;
}
if (child != aChild) {
newPrevSib = child;
}
child = GetNextXULBox(child);
}
if (aChild->GetPrevSibling() == newPrevSib) {
// This box is not moving.
return NS_OK;
}
// Take |aChild| out of its old position in the child list.
mFrames.RemoveFrame(aChild);
// Insert it after |newPrevSib| or at the start if it's null.
mFrames.InsertFrame(nullptr, newPrevSib, aChild);
return NS_OK;
}
/**
* This wrapper class lets us redirect mouse hits from descendant frames
* of a menu to the menu itself, if they didn't specify 'allowevents'.
*
* The wrapper simply turns a hit on a descendant element
* into a hit on the menu itself, unless there is an element between the target
* and the menu with the "allowevents" attribute.
*
* This is used by nsMenuFrame and nsTreeColFrame.
*
* Note that turning a hit on a descendant element into nullptr, so events
* could fall through to the menu background, might be an appealing
* simplification but it would mean slightly strange behaviour in some cases,
* because grabber wrappers can be created for many individual lists and items,
* so the exact fallthrough behaviour would be complex. E.g. an element with
* "allowevents" on top of the Content() list could receive the event even if it
* was covered by a PositionedDescenants() element without "allowevents". It is
* best to never convert a non-null hit into null.
*/
// REVIEW: This is roughly of what nsMenuFrame::GetFrameForPoint used to do.
// I've made 'allowevents' affect child elements because that seems the only
// reasonable thing to do.
class nsDisplayXULEventRedirector final : public nsDisplayWrapList {
public:
nsDisplayXULEventRedirector(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
nsDisplayItem* aItem, nsIFrame* aTargetFrame)
: nsDisplayWrapList(aBuilder, aFrame, aItem),
mTargetFrame(aTargetFrame) {}
nsDisplayXULEventRedirector(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
nsDisplayList* aList, nsIFrame* aTargetFrame)
: nsDisplayWrapList(aBuilder, aFrame, aList),
mTargetFrame(aTargetFrame) {}
virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
HitTestState* aState,
nsTArray<nsIFrame*>* aOutFrames) override;
virtual bool ShouldFlattenAway(nsDisplayListBuilder* aBuilder) override {
return false;
}
NS_DISPLAY_DECL_NAME("XULEventRedirector", TYPE_XUL_EVENT_REDIRECTOR)
private:
nsIFrame* mTargetFrame;
};
void nsDisplayXULEventRedirector::HitTest(nsDisplayListBuilder* aBuilder,
const nsRect& aRect,
HitTestState* aState,
nsTArray<nsIFrame*>* aOutFrames) {
nsTArray<nsIFrame*> outFrames;
mList.HitTest(aBuilder, aRect, aState, &outFrames);
bool topMostAdded = false;
uint32_t localLength = outFrames.Length();
for (uint32_t i = 0; i < localLength; i++) {
for (nsIContent* content = outFrames.ElementAt(i)->GetContent();
content && content != mTargetFrame->GetContent();
content = content->GetParent()) {
if (!content->IsElement() ||
!content->AsElement()->AttrValueIs(kNameSpaceID_None,
nsGkAtoms::allowevents,
nsGkAtoms::_true, eCaseMatters)) {
continue;
}
// Events are allowed on 'frame', so let it go.
aOutFrames->AppendElement(outFrames.ElementAt(i));
topMostAdded = true;
}
// If there was no hit on the topmost frame or its ancestors,
// add the target frame itself as the first candidate (see bug 562554).
if (!topMostAdded) {
topMostAdded = true;
aOutFrames->AppendElement(mTargetFrame);
}
}
}
class nsXULEventRedirectorWrapper final : public nsDisplayWrapper {
public:
explicit nsXULEventRedirectorWrapper(nsIFrame* aTargetFrame)
: mTargetFrame(aTargetFrame) {}
virtual nsDisplayItem* WrapList(nsDisplayListBuilder* aBuilder,
nsIFrame* aFrame,
nsDisplayList* aList) override {
return MakeDisplayItem<nsDisplayXULEventRedirector>(aBuilder, aFrame, aList,
mTargetFrame);
}
virtual nsDisplayItem* WrapItem(nsDisplayListBuilder* aBuilder,
nsDisplayItem* aItem) override {
return MakeDisplayItem<nsDisplayXULEventRedirector>(
aBuilder, aItem->Frame(), aItem, mTargetFrame);
}
private:
nsIFrame* mTargetFrame;
};
void nsBoxFrame::WrapListsInRedirector(nsDisplayListBuilder* aBuilder,
const nsDisplayListSet& aIn,
const nsDisplayListSet& aOut) {
nsXULEventRedirectorWrapper wrapper(this);
wrapper.WrapLists(aBuilder, this, aIn, aOut);
}
bool nsBoxFrame::GetEventPoint(WidgetGUIEvent* aEvent, nsPoint& aPoint) {
LayoutDeviceIntPoint refPoint;
bool res = GetEventPoint(aEvent, refPoint);
aPoint = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, refPoint, this);
return res;
}
bool nsBoxFrame::GetEventPoint(WidgetGUIEvent* aEvent,
LayoutDeviceIntPoint& aPoint) {
NS_ENSURE_TRUE(aEvent, false);
WidgetTouchEvent* touchEvent = aEvent->AsTouchEvent();
if (touchEvent) {
// return false if there is more than one touch on the page, or if
// we can't find a touch point
if (touchEvent->mTouches.Length() != 1) {
return false;
}
dom::Touch* touch = touchEvent->mTouches.SafeElementAt(0);
if (!touch) {
return false;
}
aPoint = touch->mRefPoint;
} else {
aPoint = aEvent->mRefPoint;
}
return true;
}