Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | #include "nsCOMPtr.h" |
michael@0 | 6 | #include "nsTableColFrame.h" |
michael@0 | 7 | #include "nsTableFrame.h" |
michael@0 | 8 | #include "nsContainerFrame.h" |
michael@0 | 9 | #include "nsStyleContext.h" |
michael@0 | 10 | #include "nsStyleConsts.h" |
michael@0 | 11 | #include "nsPresContext.h" |
michael@0 | 12 | #include "nsGkAtoms.h" |
michael@0 | 13 | #include "nsCSSRendering.h" |
michael@0 | 14 | #include "nsIContent.h" |
michael@0 | 15 | |
michael@0 | 16 | #define COL_TYPE_BITS (NS_FRAME_STATE_BIT(28) | \ |
michael@0 | 17 | NS_FRAME_STATE_BIT(29) | \ |
michael@0 | 18 | NS_FRAME_STATE_BIT(30) | \ |
michael@0 | 19 | NS_FRAME_STATE_BIT(31)) |
michael@0 | 20 | #define COL_TYPE_OFFSET 28 |
michael@0 | 21 | |
michael@0 | 22 | nsTableColFrame::nsTableColFrame(nsStyleContext* aContext) : |
michael@0 | 23 | nsSplittableFrame(aContext) |
michael@0 | 24 | { |
michael@0 | 25 | SetColType(eColContent); |
michael@0 | 26 | ResetIntrinsics(); |
michael@0 | 27 | ResetSpanIntrinsics(); |
michael@0 | 28 | ResetFinalWidth(); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | nsTableColFrame::~nsTableColFrame() |
michael@0 | 32 | { |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | nsTableColType |
michael@0 | 36 | nsTableColFrame::GetColType() const |
michael@0 | 37 | { |
michael@0 | 38 | return (nsTableColType)((mState & COL_TYPE_BITS) >> COL_TYPE_OFFSET); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | void |
michael@0 | 42 | nsTableColFrame::SetColType(nsTableColType aType) |
michael@0 | 43 | { |
michael@0 | 44 | NS_ASSERTION(aType != eColAnonymousCol || |
michael@0 | 45 | (GetPrevContinuation() && |
michael@0 | 46 | GetPrevContinuation()->GetNextContinuation() == this && |
michael@0 | 47 | GetPrevContinuation()->GetNextSibling() == this), |
michael@0 | 48 | "spanned content cols must be continuations"); |
michael@0 | 49 | uint32_t type = aType - eColContent; |
michael@0 | 50 | RemoveStateBits(COL_TYPE_BITS); |
michael@0 | 51 | AddStateBits(nsFrameState(type << COL_TYPE_OFFSET)); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | /* virtual */ void |
michael@0 | 55 | nsTableColFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext) |
michael@0 | 56 | { |
michael@0 | 57 | nsSplittableFrame::DidSetStyleContext(aOldStyleContext); |
michael@0 | 58 | |
michael@0 | 59 | if (!aOldStyleContext) //avoid this on init |
michael@0 | 60 | return; |
michael@0 | 61 | |
michael@0 | 62 | nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this); |
michael@0 | 63 | if (tableFrame->IsBorderCollapse() && |
michael@0 | 64 | tableFrame->BCRecalcNeeded(aOldStyleContext, StyleContext())) { |
michael@0 | 65 | nsIntRect damageArea(GetColIndex(), 0, 1, tableFrame->GetRowCount()); |
michael@0 | 66 | tableFrame->AddBCDamageArea(damageArea); |
michael@0 | 67 | } |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | void nsTableColFrame::SetContinuousBCBorderWidth(uint8_t aForSide, |
michael@0 | 71 | BCPixelSize aPixelValue) |
michael@0 | 72 | { |
michael@0 | 73 | switch (aForSide) { |
michael@0 | 74 | case NS_SIDE_TOP: |
michael@0 | 75 | mTopContBorderWidth = aPixelValue; |
michael@0 | 76 | return; |
michael@0 | 77 | case NS_SIDE_RIGHT: |
michael@0 | 78 | mRightContBorderWidth = aPixelValue; |
michael@0 | 79 | return; |
michael@0 | 80 | case NS_SIDE_BOTTOM: |
michael@0 | 81 | mBottomContBorderWidth = aPixelValue; |
michael@0 | 82 | return; |
michael@0 | 83 | default: |
michael@0 | 84 | NS_ERROR("invalid side arg"); |
michael@0 | 85 | } |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | nsresult nsTableColFrame::Reflow(nsPresContext* aPresContext, |
michael@0 | 89 | nsHTMLReflowMetrics& aDesiredSize, |
michael@0 | 90 | const nsHTMLReflowState& aReflowState, |
michael@0 | 91 | nsReflowStatus& aStatus) |
michael@0 | 92 | { |
michael@0 | 93 | DO_GLOBAL_REFLOW_COUNT("nsTableColFrame"); |
michael@0 | 94 | DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus); |
michael@0 | 95 | aDesiredSize.Width() = 0; |
michael@0 | 96 | aDesiredSize.Height() = 0; |
michael@0 | 97 | const nsStyleVisibility* colVis = StyleVisibility(); |
michael@0 | 98 | bool collapseCol = (NS_STYLE_VISIBILITY_COLLAPSE == colVis->mVisible); |
michael@0 | 99 | if (collapseCol) { |
michael@0 | 100 | nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this); |
michael@0 | 101 | tableFrame->SetNeedToCollapse(true); |
michael@0 | 102 | } |
michael@0 | 103 | aStatus = NS_FRAME_COMPLETE; |
michael@0 | 104 | NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize); |
michael@0 | 105 | return NS_OK; |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | int32_t nsTableColFrame::GetSpan() |
michael@0 | 109 | { |
michael@0 | 110 | return StyleTable()->mSpan; |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | #ifdef DEBUG |
michael@0 | 114 | void nsTableColFrame::Dump(int32_t aIndent) |
michael@0 | 115 | { |
michael@0 | 116 | char* indent = new char[aIndent + 1]; |
michael@0 | 117 | if (!indent) return; |
michael@0 | 118 | for (int32_t i = 0; i < aIndent + 1; i++) { |
michael@0 | 119 | indent[i] = ' '; |
michael@0 | 120 | } |
michael@0 | 121 | indent[aIndent] = 0; |
michael@0 | 122 | |
michael@0 | 123 | printf("%s**START COL DUMP**\n%s colIndex=%d coltype=", |
michael@0 | 124 | indent, indent, mColIndex); |
michael@0 | 125 | nsTableColType colType = GetColType(); |
michael@0 | 126 | switch (colType) { |
michael@0 | 127 | case eColContent: |
michael@0 | 128 | printf(" content "); |
michael@0 | 129 | break; |
michael@0 | 130 | case eColAnonymousCol: |
michael@0 | 131 | printf(" anonymous-column "); |
michael@0 | 132 | break; |
michael@0 | 133 | case eColAnonymousColGroup: |
michael@0 | 134 | printf(" anonymous-colgroup "); |
michael@0 | 135 | break; |
michael@0 | 136 | case eColAnonymousCell: |
michael@0 | 137 | printf(" anonymous-cell "); |
michael@0 | 138 | break; |
michael@0 | 139 | } |
michael@0 | 140 | printf("\nm:%d c:%d(%c) p:%f sm:%d sc:%d sp:%f f:%d", |
michael@0 | 141 | int32_t(mMinCoord), int32_t(mPrefCoord), |
michael@0 | 142 | mHasSpecifiedCoord ? 's' : 'u', mPrefPercent, |
michael@0 | 143 | int32_t(mSpanMinCoord), int32_t(mSpanPrefCoord), |
michael@0 | 144 | mSpanPrefPercent, |
michael@0 | 145 | int32_t(GetFinalWidth())); |
michael@0 | 146 | printf("\n%s**END COL DUMP** ", indent); |
michael@0 | 147 | delete [] indent; |
michael@0 | 148 | } |
michael@0 | 149 | #endif |
michael@0 | 150 | /* ----- global methods ----- */ |
michael@0 | 151 | |
michael@0 | 152 | nsTableColFrame* |
michael@0 | 153 | NS_NewTableColFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) |
michael@0 | 154 | { |
michael@0 | 155 | return new (aPresShell) nsTableColFrame(aContext); |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | NS_IMPL_FRAMEARENA_HELPERS(nsTableColFrame) |
michael@0 | 159 | |
michael@0 | 160 | nsTableColFrame* |
michael@0 | 161 | nsTableColFrame::GetNextCol() const |
michael@0 | 162 | { |
michael@0 | 163 | nsIFrame* childFrame = GetNextSibling(); |
michael@0 | 164 | while (childFrame) { |
michael@0 | 165 | if (nsGkAtoms::tableColFrame == childFrame->GetType()) { |
michael@0 | 166 | return (nsTableColFrame*)childFrame; |
michael@0 | 167 | } |
michael@0 | 168 | childFrame = childFrame->GetNextSibling(); |
michael@0 | 169 | } |
michael@0 | 170 | return nullptr; |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | nsIAtom* |
michael@0 | 174 | nsTableColFrame::GetType() const |
michael@0 | 175 | { |
michael@0 | 176 | return nsGkAtoms::tableColFrame; |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | #ifdef DEBUG_FRAME_DUMP |
michael@0 | 180 | nsresult |
michael@0 | 181 | nsTableColFrame::GetFrameName(nsAString& aResult) const |
michael@0 | 182 | { |
michael@0 | 183 | return MakeFrameName(NS_LITERAL_STRING("TableCol"), aResult); |
michael@0 | 184 | } |
michael@0 | 185 | #endif |
michael@0 | 186 | |
michael@0 | 187 | nsSplittableType |
michael@0 | 188 | nsTableColFrame::GetSplittableType() const |
michael@0 | 189 | { |
michael@0 | 190 | return NS_FRAME_NOT_SPLITTABLE; |
michael@0 | 191 | } |
michael@0 | 192 | |
michael@0 | 193 | void |
michael@0 | 194 | nsTableColFrame::InvalidateFrame(uint32_t aDisplayItemKey) |
michael@0 | 195 | { |
michael@0 | 196 | nsIFrame::InvalidateFrame(aDisplayItemKey); |
michael@0 | 197 | GetParent()->InvalidateFrameWithRect(GetVisualOverflowRect() + GetPosition(), aDisplayItemKey); |
michael@0 | 198 | } |
michael@0 | 199 | |
michael@0 | 200 | void |
michael@0 | 201 | nsTableColFrame::InvalidateFrameWithRect(const nsRect& aRect, uint32_t aDisplayItemKey) |
michael@0 | 202 | { |
michael@0 | 203 | nsIFrame::InvalidateFrameWithRect(aRect, aDisplayItemKey); |
michael@0 | 204 | |
michael@0 | 205 | // If we have filters applied that would affects our bounds, then |
michael@0 | 206 | // we get an inactive layer created and this is computed |
michael@0 | 207 | // within FrameLayerBuilder |
michael@0 | 208 | GetParent()->InvalidateFrameWithRect(aRect + GetPosition(), aDisplayItemKey); |
michael@0 | 209 | } |
michael@0 | 210 |