1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef LayoutLogging_h
8 #define LayoutLogging_h
9 
10 #include "mozilla/Logging.h"
11 
12 /**
13  * Retrieves the log module to use for layout logging.
14  */
15 static mozilla::LazyLogModule sLayoutLog("layout");
16 
17 /**
18  * Use the layout log to warn if a given condition is false.
19  *
20  * This is only enabled in debug builds and the logging is only displayed if
21  * the environmental variable MOZ_LOG includes "layout:2" (or higher).
22  */
23 #ifdef DEBUG
24 #define LAYOUT_WARN_IF_FALSE(_cond, _msg)                                 \
25   PR_BEGIN_MACRO                                                          \
26   if (MOZ_LOG_TEST(sLayoutLog, mozilla::LogLevel::Warning) && !(_cond)) { \
27     mozilla::detail::LayoutLogWarning(_msg, #_cond, __FILE__, __LINE__);  \
28   }                                                                       \
29   PR_END_MACRO
30 #else
31 #define LAYOUT_WARN_IF_FALSE(_cond, _msg) \
32   PR_BEGIN_MACRO                          \
33   PR_END_MACRO
34 #endif
35 
36 /**
37  * Use the layout log to emit a warning with the same format as NS_WARNING.
38  *
39  * This is only enabled in debug builds and the logging is only displayed if
40  * the environmental variable MOZ_LOG includes "layout:2" (or higher).
41  */
42 #ifdef DEBUG
43 #define LAYOUT_WARNING(_msg)                                              \
44   PR_BEGIN_MACRO                                                          \
45   if (MOZ_LOG_TEST(sLayoutLog, mozilla::LogLevel::Warning)) {             \
46     mozilla::detail::LayoutLogWarning(_msg, nullptr, __FILE__, __LINE__); \
47   }                                                                       \
48   PR_END_MACRO
49 #else
50 #define LAYOUT_WARNING(_msg) \
51   PR_BEGIN_MACRO             \
52   PR_END_MACRO
53 #endif
54 
55 namespace mozilla {
56 namespace detail {
57 
58 void LayoutLogWarning(const char* aStr, const char* aExpr, const char* aFile,
59                       int32_t aLine);
60 
61 }  // namespace detail
62 }  // namespace mozilla
63 
64 #endif  // LayoutLogging_h
65