1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/tables/nsTableColFrame.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,210 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 +#include "nsCOMPtr.h" 1.9 +#include "nsTableColFrame.h" 1.10 +#include "nsTableFrame.h" 1.11 +#include "nsContainerFrame.h" 1.12 +#include "nsStyleContext.h" 1.13 +#include "nsStyleConsts.h" 1.14 +#include "nsPresContext.h" 1.15 +#include "nsGkAtoms.h" 1.16 +#include "nsCSSRendering.h" 1.17 +#include "nsIContent.h" 1.18 + 1.19 +#define COL_TYPE_BITS (NS_FRAME_STATE_BIT(28) | \ 1.20 + NS_FRAME_STATE_BIT(29) | \ 1.21 + NS_FRAME_STATE_BIT(30) | \ 1.22 + NS_FRAME_STATE_BIT(31)) 1.23 +#define COL_TYPE_OFFSET 28 1.24 + 1.25 +nsTableColFrame::nsTableColFrame(nsStyleContext* aContext) : 1.26 + nsSplittableFrame(aContext) 1.27 +{ 1.28 + SetColType(eColContent); 1.29 + ResetIntrinsics(); 1.30 + ResetSpanIntrinsics(); 1.31 + ResetFinalWidth(); 1.32 +} 1.33 + 1.34 +nsTableColFrame::~nsTableColFrame() 1.35 +{ 1.36 +} 1.37 + 1.38 +nsTableColType 1.39 +nsTableColFrame::GetColType() const 1.40 +{ 1.41 + return (nsTableColType)((mState & COL_TYPE_BITS) >> COL_TYPE_OFFSET); 1.42 +} 1.43 + 1.44 +void 1.45 +nsTableColFrame::SetColType(nsTableColType aType) 1.46 +{ 1.47 + NS_ASSERTION(aType != eColAnonymousCol || 1.48 + (GetPrevContinuation() && 1.49 + GetPrevContinuation()->GetNextContinuation() == this && 1.50 + GetPrevContinuation()->GetNextSibling() == this), 1.51 + "spanned content cols must be continuations"); 1.52 + uint32_t type = aType - eColContent; 1.53 + RemoveStateBits(COL_TYPE_BITS); 1.54 + AddStateBits(nsFrameState(type << COL_TYPE_OFFSET)); 1.55 +} 1.56 + 1.57 +/* virtual */ void 1.58 +nsTableColFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext) 1.59 +{ 1.60 + nsSplittableFrame::DidSetStyleContext(aOldStyleContext); 1.61 + 1.62 + if (!aOldStyleContext) //avoid this on init 1.63 + return; 1.64 + 1.65 + nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this); 1.66 + if (tableFrame->IsBorderCollapse() && 1.67 + tableFrame->BCRecalcNeeded(aOldStyleContext, StyleContext())) { 1.68 + nsIntRect damageArea(GetColIndex(), 0, 1, tableFrame->GetRowCount()); 1.69 + tableFrame->AddBCDamageArea(damageArea); 1.70 + } 1.71 +} 1.72 + 1.73 +void nsTableColFrame::SetContinuousBCBorderWidth(uint8_t aForSide, 1.74 + BCPixelSize aPixelValue) 1.75 +{ 1.76 + switch (aForSide) { 1.77 + case NS_SIDE_TOP: 1.78 + mTopContBorderWidth = aPixelValue; 1.79 + return; 1.80 + case NS_SIDE_RIGHT: 1.81 + mRightContBorderWidth = aPixelValue; 1.82 + return; 1.83 + case NS_SIDE_BOTTOM: 1.84 + mBottomContBorderWidth = aPixelValue; 1.85 + return; 1.86 + default: 1.87 + NS_ERROR("invalid side arg"); 1.88 + } 1.89 +} 1.90 + 1.91 +nsresult nsTableColFrame::Reflow(nsPresContext* aPresContext, 1.92 + nsHTMLReflowMetrics& aDesiredSize, 1.93 + const nsHTMLReflowState& aReflowState, 1.94 + nsReflowStatus& aStatus) 1.95 +{ 1.96 + DO_GLOBAL_REFLOW_COUNT("nsTableColFrame"); 1.97 + DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus); 1.98 + aDesiredSize.Width() = 0; 1.99 + aDesiredSize.Height() = 0; 1.100 + const nsStyleVisibility* colVis = StyleVisibility(); 1.101 + bool collapseCol = (NS_STYLE_VISIBILITY_COLLAPSE == colVis->mVisible); 1.102 + if (collapseCol) { 1.103 + nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this); 1.104 + tableFrame->SetNeedToCollapse(true); 1.105 + } 1.106 + aStatus = NS_FRAME_COMPLETE; 1.107 + NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize); 1.108 + return NS_OK; 1.109 +} 1.110 + 1.111 +int32_t nsTableColFrame::GetSpan() 1.112 +{ 1.113 + return StyleTable()->mSpan; 1.114 +} 1.115 + 1.116 +#ifdef DEBUG 1.117 +void nsTableColFrame::Dump(int32_t aIndent) 1.118 +{ 1.119 + char* indent = new char[aIndent + 1]; 1.120 + if (!indent) return; 1.121 + for (int32_t i = 0; i < aIndent + 1; i++) { 1.122 + indent[i] = ' '; 1.123 + } 1.124 + indent[aIndent] = 0; 1.125 + 1.126 + printf("%s**START COL DUMP**\n%s colIndex=%d coltype=", 1.127 + indent, indent, mColIndex); 1.128 + nsTableColType colType = GetColType(); 1.129 + switch (colType) { 1.130 + case eColContent: 1.131 + printf(" content "); 1.132 + break; 1.133 + case eColAnonymousCol: 1.134 + printf(" anonymous-column "); 1.135 + break; 1.136 + case eColAnonymousColGroup: 1.137 + printf(" anonymous-colgroup "); 1.138 + break; 1.139 + case eColAnonymousCell: 1.140 + printf(" anonymous-cell "); 1.141 + break; 1.142 + } 1.143 + printf("\nm:%d c:%d(%c) p:%f sm:%d sc:%d sp:%f f:%d", 1.144 + int32_t(mMinCoord), int32_t(mPrefCoord), 1.145 + mHasSpecifiedCoord ? 's' : 'u', mPrefPercent, 1.146 + int32_t(mSpanMinCoord), int32_t(mSpanPrefCoord), 1.147 + mSpanPrefPercent, 1.148 + int32_t(GetFinalWidth())); 1.149 + printf("\n%s**END COL DUMP** ", indent); 1.150 + delete [] indent; 1.151 +} 1.152 +#endif 1.153 +/* ----- global methods ----- */ 1.154 + 1.155 +nsTableColFrame* 1.156 +NS_NewTableColFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) 1.157 +{ 1.158 + return new (aPresShell) nsTableColFrame(aContext); 1.159 +} 1.160 + 1.161 +NS_IMPL_FRAMEARENA_HELPERS(nsTableColFrame) 1.162 + 1.163 +nsTableColFrame* 1.164 +nsTableColFrame::GetNextCol() const 1.165 +{ 1.166 + nsIFrame* childFrame = GetNextSibling(); 1.167 + while (childFrame) { 1.168 + if (nsGkAtoms::tableColFrame == childFrame->GetType()) { 1.169 + return (nsTableColFrame*)childFrame; 1.170 + } 1.171 + childFrame = childFrame->GetNextSibling(); 1.172 + } 1.173 + return nullptr; 1.174 +} 1.175 + 1.176 +nsIAtom* 1.177 +nsTableColFrame::GetType() const 1.178 +{ 1.179 + return nsGkAtoms::tableColFrame; 1.180 +} 1.181 + 1.182 +#ifdef DEBUG_FRAME_DUMP 1.183 +nsresult 1.184 +nsTableColFrame::GetFrameName(nsAString& aResult) const 1.185 +{ 1.186 + return MakeFrameName(NS_LITERAL_STRING("TableCol"), aResult); 1.187 +} 1.188 +#endif 1.189 + 1.190 +nsSplittableType 1.191 +nsTableColFrame::GetSplittableType() const 1.192 +{ 1.193 + return NS_FRAME_NOT_SPLITTABLE; 1.194 +} 1.195 + 1.196 +void 1.197 +nsTableColFrame::InvalidateFrame(uint32_t aDisplayItemKey) 1.198 +{ 1.199 + nsIFrame::InvalidateFrame(aDisplayItemKey); 1.200 + GetParent()->InvalidateFrameWithRect(GetVisualOverflowRect() + GetPosition(), aDisplayItemKey); 1.201 +} 1.202 + 1.203 +void 1.204 +nsTableColFrame::InvalidateFrameWithRect(const nsRect& aRect, uint32_t aDisplayItemKey) 1.205 +{ 1.206 + nsIFrame::InvalidateFrameWithRect(aRect, aDisplayItemKey); 1.207 + 1.208 + // If we have filters applied that would affects our bounds, then 1.209 + // we get an inactive layer created and this is computed 1.210 + // within FrameLayerBuilder 1.211 + GetParent()->InvalidateFrameWithRect(aRect + GetPosition(), aDisplayItemKey); 1.212 +} 1.213 +