Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
1 /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /*
7 * Inline methods that belong in nsStyleStruct.h, except that they
8 * require more headers.
9 */
11 #ifndef nsStyleStructInlines_h_
12 #define nsStyleStructInlines_h_
14 #include "nsIFrame.h"
15 #include "nsStyleStruct.h"
16 #include "imgIRequest.h"
17 #include "imgIContainer.h"
18 #include "nsIContent.h"
20 inline void
21 nsStyleImage::SetSubImage(uint8_t aIndex, imgIContainer* aSubImage) const
22 {
23 const_cast<nsStyleImage*>(this)->mSubImages.ReplaceObjectAt(aSubImage, aIndex);
24 }
26 inline imgIContainer*
27 nsStyleImage::GetSubImage(uint8_t aIndex) const
28 {
29 imgIContainer* subImage = nullptr;
30 if (aIndex < mSubImages.Count())
31 subImage = mSubImages[aIndex];
32 return subImage;
33 }
35 bool
36 nsStyleText::HasTextShadow() const
37 {
38 return mTextShadow;
39 }
41 nsCSSShadowArray*
42 nsStyleText::GetTextShadow() const
43 {
44 return mTextShadow;
45 }
47 bool
48 nsStyleText::WhiteSpaceCanWrap(const nsIFrame* aContextFrame) const
49 {
50 NS_ASSERTION(aContextFrame->StyleText() == this, "unexpected aContextFrame");
51 return WhiteSpaceCanWrapStyle() && !aContextFrame->IsSVGText();
52 }
54 bool
55 nsStyleText::WordCanWrap(const nsIFrame* aContextFrame) const
56 {
57 NS_ASSERTION(aContextFrame->StyleText() == this, "unexpected aContextFrame");
58 return WordCanWrapStyle() && !aContextFrame->IsSVGText();
59 }
61 bool
62 nsStyleDisplay::IsBlockInside(const nsIFrame* aContextFrame) const
63 {
64 NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
65 if (aContextFrame->IsSVGText()) {
66 return aContextFrame->GetType() == nsGkAtoms::blockFrame;
67 }
68 return IsBlockInsideStyle();
69 }
71 bool
72 nsStyleDisplay::IsBlockOutside(const nsIFrame* aContextFrame) const
73 {
74 NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
75 if (aContextFrame->IsSVGText()) {
76 return aContextFrame->GetType() == nsGkAtoms::blockFrame;
77 }
78 return IsBlockOutsideStyle();
79 }
81 bool
82 nsStyleDisplay::IsInlineOutside(const nsIFrame* aContextFrame) const
83 {
84 NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
85 if (aContextFrame->IsSVGText()) {
86 return aContextFrame->GetType() != nsGkAtoms::blockFrame;
87 }
88 return IsInlineOutsideStyle();
89 }
91 bool
92 nsStyleDisplay::IsOriginalDisplayInlineOutside(const nsIFrame* aContextFrame) const
93 {
94 NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
95 if (aContextFrame->IsSVGText()) {
96 return aContextFrame->GetType() != nsGkAtoms::blockFrame;
97 }
98 return IsOriginalDisplayInlineOutsideStyle();
99 }
101 uint8_t
102 nsStyleDisplay::GetDisplay(const nsIFrame* aContextFrame) const
103 {
104 NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
105 if (aContextFrame->IsSVGText() &&
106 mDisplay != NS_STYLE_DISPLAY_NONE) {
107 return aContextFrame->GetType() == nsGkAtoms::blockFrame ?
108 NS_STYLE_DISPLAY_BLOCK :
109 NS_STYLE_DISPLAY_INLINE;
110 }
111 return mDisplay;
112 }
114 bool
115 nsStyleDisplay::IsFloating(const nsIFrame* aContextFrame) const
116 {
117 NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
118 return IsFloatingStyle() && !aContextFrame->IsSVGText();
119 }
121 bool
122 nsStyleDisplay::HasTransform(const nsIFrame* aContextFrame) const
123 {
124 NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
125 return HasTransformStyle() && aContextFrame->IsFrameOfType(nsIFrame::eSupportsCSSTransforms);
126 }
128 bool
129 nsStyleDisplay::IsPositioned(const nsIFrame* aContextFrame) const
130 {
131 NS_ASSERTION(aContextFrame->StyleDisplay() == this,
132 "unexpected aContextFrame");
133 return (IsAbsolutelyPositionedStyle() ||
134 IsRelativelyPositionedStyle() ||
135 HasTransform(aContextFrame) ||
136 HasPerspectiveStyle()) &&
137 !aContextFrame->IsSVGText();
138 }
140 bool
141 nsStyleDisplay::IsRelativelyPositioned(const nsIFrame* aContextFrame) const
142 {
143 NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
144 return IsRelativelyPositionedStyle() && !aContextFrame->IsSVGText();
145 }
147 bool
148 nsStyleDisplay::IsAbsolutelyPositioned(const nsIFrame* aContextFrame) const
149 {
150 NS_ASSERTION(aContextFrame->StyleDisplay() == this, "unexpected aContextFrame");
151 return IsAbsolutelyPositionedStyle() && !aContextFrame->IsSVGText();
152 }
154 uint8_t
155 nsStyleVisibility::GetEffectivePointerEvents(nsIFrame* aFrame) const
156 {
157 if (aFrame->GetContent() && !aFrame->GetContent()->GetParent()) {
158 // The root element has a cluster of frames associated with it
159 // (root scroll frame, canvas frame, the actual primary frame). Make
160 // those take their pointer-events value from the root element's primary
161 // frame.
162 nsIFrame* f = aFrame->GetContent()->GetPrimaryFrame();
163 if (f) {
164 return f->StyleVisibility()->mPointerEvents;
165 }
166 }
167 return mPointerEvents;
168 }
170 #endif /* !defined(nsStyleStructInlines_h_) */