1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsTableFrame.h"
#include "nsTableColFrame.h"
#include "nsTableCellFrame.h"
#include "nsTableFrame.h"
#include "nsTableRowGroupFrame.h"
#include "nsTablePainter.h"
#include "nsReflowPath.h"
#include "nsStyleContext.h"
#include "nsStyleConsts.h"
#include "nsPresContext.h"
#include "nsIRenderingContext.h"
#include "nsCSSRendering.h"
#include "nsIContent.h"
#include "nsGenericHTMLElement.h"
#include "nsHTMLParts.h"
#include "nsHTMLAtoms.h"
#include "nsVoidArray.h"
#include "nsIView.h"
#include "nsLayoutAtoms.h"
#include "nsIPresShell.h"
#include "nsCOMPtr.h"
#include "nsIDOMHTMLTableCellElement.h"
#ifdef ACCESSIBILITY
#include "nsIAccessibilityService.h"
#endif
#include "nsIServiceManager.h"
#include "nsIDOMNode.h"
#include "nsINameSpaceManager.h"
//TABLECELL SELECTION
#include "nsIFrameSelection.h"
#include "nsILookAndFeel.h"
nsTableCellFrame::nsTableCellFrame()
{
mBits.mColIndex = 0;
mPriorAvailWidth = 0;
SetContentEmpty(PR_FALSE);
SetNeedSpecialReflow(PR_FALSE);
SetHadSpecialReflow(PR_FALSE);
SetHasPctOverHeight(PR_FALSE);
SetNeedPass2Reflow(PR_TRUE);
#ifdef DEBUG_TABLE_REFLOW_TIMING
mTimer = new nsReflowTimer(this);
mBlockTimer = new nsReflowTimer(this);
#endif
}
nsTableCellFrame::~nsTableCellFrame()
{
#ifdef DEBUG_TABLE_REFLOW_TIMING
nsTableFrame::DebugReflowDone(this);
#endif
}
nsTableCellFrame*
nsTableCellFrame::GetNextCell() const
{
nsIFrame* childFrame = GetNextSibling();
while (childFrame) {
if (IS_TABLE_CELL(childFrame->GetType())) {
return (nsTableCellFrame*)childFrame;
}
childFrame = childFrame->GetNextSibling();
}
return nsnull;
}
NS_IMETHODIMP
nsTableCellFrame::Init(nsPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
nsresult rv;
// Let the base class do its initialization
rv = nsHTMLContainerFrame::Init(aPresContext, aContent, aParent, aContext,
aPrevInFlow);
if (aPrevInFlow) {
// Set the column index
nsTableCellFrame* cellFrame = (nsTableCellFrame*)aPrevInFlow;
PRInt32 colIndex;
cellFrame->GetColIndex(colIndex);
SetColIndex(colIndex);
}
return rv;
}
// nsIPercentHeightObserver methods
void
nsTableCellFrame::NotifyPercentHeight(const nsHTMLReflowState& aReflowState)
{
if (!NeedSpecialReflow()) {
// Only initiate a special reflow if we will be able to construct a computed height
// on the cell that will result in the frame getting a computed height. This can only
// happen (but not sufficient) if there is no computed height already set between the
// initiating frame and the cell.
for (const nsHTMLReflowState* rs = aReflowState.parentReflowState; rs; rs = rs->parentReflowState) {
if ((NS_UNCONSTRAINEDSIZE != rs->mComputedHeight) && (0 != rs->mComputedHeight)) {
return;
}
// stop when we reach the cell frame
if (rs->frame == this) {
nsTableFrame::RequestSpecialHeightReflow(*rs);
return;
}
}
NS_ASSERTION(PR_FALSE, "program error in NotifyPercentHeight");
}
}
// The cell needs to observe its block and things inside its block but nothing below that
PRBool
nsTableCellFrame::NeedsToObserve(const nsHTMLReflowState& aReflowState)
{
PRBool result = PR_FALSE;
const nsHTMLReflowState* parentRS = aReflowState.parentReflowState;
if (parentRS && (parentRS->mPercentHeightObserver == this)) { // cell observes the parent
result = PR_TRUE;
parentRS = parentRS->parentReflowState;
if (parentRS && (parentRS->mPercentHeightObserver == this)) { // cell observers the grand parent
parentRS = parentRS->parentReflowState;
if (parentRS && (parentRS->mPercentHeightObserver == this)) {
// cell observes the great grand parent, so we have gone too deep
result = PR_FALSE;
}
}
}
return result;
}
nsresult
nsTableCellFrame::GetRowIndex(PRInt32 &aRowIndex) const
{
nsresult result;
nsTableRowFrame* row = NS_STATIC_CAST(nsTableRowFrame*, GetParent());
if (row) {
aRowIndex = row->GetRowIndex();
result = NS_OK;
}
else {
aRowIndex = 0;
result = NS_ERROR_NOT_INITIALIZED;
}
return result;
}
nsresult
nsTableCellFrame::GetColIndex(PRInt32 &aColIndex) const
{
if (mPrevInFlow) {
return ((nsTableCellFrame*)GetFirstInFlow())->GetColIndex(aColIndex);
}
else {
aColIndex = mBits.mColIndex;
return NS_OK;
}
}
NS_IMETHODIMP
nsTableCellFrame::AttributeChanged(nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aModType)
{
// let the table frame decide what to do
nsTableFrame* tableFrame = nsnull;
nsresult rv = nsTableFrame::GetTableFrame(this, tableFrame);
if ((NS_SUCCEEDED(rv)) && (tableFrame)) {
tableFrame->AttributeChangedFor(this, aChild, aAttribute);
}
return NS_OK;
}
void nsTableCellFrame::SetPass1MaxElementWidth(nscoord aMaxWidth,
nscoord aMaxElementWidth)
{
nscoord maxElemWidth = aMaxElementWidth;
if (eCompatibility_NavQuirks == GetPresContext()->CompatibilityMode()) {
// check for fixed width and not nowrap and not pre
const nsStylePosition* stylePosition = GetStylePosition();
if (stylePosition->mWidth.GetUnit() == eStyleUnit_Coord) {
if (GetContent()->HasAttr(kNameSpaceID_None, nsHTMLAtoms::nowrap)) {
// set the max element size to the value of the fixed width (NAV/IE quirk)
maxElemWidth = NS_MAX(maxElemWidth, stylePosition->mWidth.GetCoordValue());
}
}
}
mPass1MaxElementWidth = maxElemWidth;
}
NS_IMETHODIMP
nsTableCellFrame::AppendFrames(nsIAtom* aListName,
nsIFrame* aFrameList)
{
NS_PRECONDITION(PR_FALSE, "unsupported operation");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsTableCellFrame::InsertFrames(nsIAtom* aListName,
nsIFrame* aPrevFrame,
nsIFrame* aFrameList)
{
NS_PRECONDITION(PR_FALSE, "unsupported operation");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsTableCellFrame::RemoveFrame(nsIAtom* aListName,
nsIFrame* aOldFrame)
{
NS_PRECONDITION(PR_FALSE, "unsupported operation");
return NS_ERROR_NOT_IMPLEMENTED;
}
void nsTableCellFrame::SetColIndex(PRInt32 aColIndex)
{
mBits.mColIndex = aColIndex;
}
//ASSURE DIFFERENT COLORS for selection
inline nscolor EnsureDifferentColors(nscolor colorA, nscolor colorB)
{
if (colorA == colorB)
{
nscolor res;
res = NS_RGB(NS_GET_R(colorA) ^ 0xff,
NS_GET_G(colorA) ^ 0xff,
NS_GET_B(colorA) ^ 0xff);
return res;
}
return colorA;
}
nsresult
nsTableCellFrame::DecorateForSelection(nsPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsStyleBackground *aStyleColor)
{
PRInt16 displaySelection;
displaySelection = DisplaySelection(aPresContext);
if (displaySelection) {
PRBool isSelected =
(GetStateBits() & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT;
if (isSelected) {
nsIFrameSelection *frameSelection =
aPresContext->PresShell()->FrameSelection();
PRBool tableCellSelectionMode;
nsresult result =
frameSelection->GetTableCellSelection(&tableCellSelectionMode);
if (NS_SUCCEEDED(result) && tableCellSelectionMode) {
nscolor bordercolor;
if (displaySelection == nsISelectionController::SELECTION_DISABLED) {
bordercolor = NS_RGB(176,176,176);// disabled color
}
else {
aPresContext->LookAndFeel()->
GetColor(nsILookAndFeel::eColor_TextSelectBackground,
bordercolor);
}
PRInt16 t2p = (PRInt16) aPresContext->PixelsToTwips();
if ((mRect.width >(3*t2p)) && (mRect.height > (3*t2p)))
{
//compare bordercolor to ((nsStyleColor *)myColor)->mBackgroundColor)
bordercolor = EnsureDifferentColors(bordercolor, aStyleColor->mBackgroundColor);
//outerrounded
aRenderingContext.SetColor(bordercolor);
aRenderingContext.DrawLine(t2p, 0, mRect.width, 0);
aRenderingContext.DrawLine(0, t2p, 0, mRect.height);
aRenderingContext.DrawLine(t2p, mRect.height, mRect.width, mRect.height);
aRenderingContext.DrawLine(mRect.width, t2p, mRect.width, mRect.height);
//middle
aRenderingContext.DrawRect(t2p, t2p, mRect.width-t2p, mRect.height-t2p);
//shading
aRenderingContext.DrawLine(2*t2p, mRect.height-2*t2p, mRect.width-t2p, mRect.height- (2*t2p));
aRenderingContext.DrawLine(mRect.width - (2*t2p), 2*t2p, mRect.width - (2*t2p), mRect.height-t2p);
}
}
}
}
return NS_OK;
}
void
nsTableCellFrame::PaintUnderlay(nsPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
PRUint32& aFlags,
const nsStyleBorder& aStyleBorder,
const nsStylePadding& aStylePadding,
const nsStyleTableBorder& aCellTableStyle)
{
nsRect rect(0, 0, mRect.width, mRect.height);
nsCSSRendering::PaintBackground(&aPresContext, aRenderingContext, this,
aDirtyRect, rect, aStyleBorder, aStylePadding,
PR_TRUE);
PRIntn skipSides = GetSkipSides();
if (NS_STYLE_TABLE_EMPTY_CELLS_SHOW == aCellTableStyle.mEmptyCells ||
!GetContentEmpty()) {
nsCSSRendering::PaintBorder(&aPresContext, aRenderingContext, this,
aDirtyRect, rect, aStyleBorder, mStyleContext, skipSides);
}
}
NS_IMETHODIMP
nsTableCellFrame::Paint(nsPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
nsFramePaintLayer aWhichLayer,
PRUint32 aFlags)
{
NS_ENSURE_TRUE(aPresContext, NS_ERROR_NULL_POINTER);
PRBool isVisible;
if (NS_SUCCEEDED(IsVisibleForPainting(aPresContext, aRenderingContext, PR_FALSE, &isVisible)) && !isVisible) {
return NS_OK;
}
PRBool paintChildren = PR_TRUE;
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {
const nsStyleBorder* myBorder = nsnull;
const nsStylePadding* myPadding = nsnull;
const nsStyleTableBorder* cellTableStyle = nsnull;
const nsStyleVisibility* vis = GetStyleVisibility();
if (vis->IsVisible()) {
myBorder = GetStyleBorder();
myPadding = GetStylePadding();
cellTableStyle = GetStyleTableBorder();
// draw the border & background only when there is content or showing empty cells
if (NS_STYLE_TABLE_EMPTY_CELLS_HIDE != cellTableStyle->mEmptyCells ||
!GetContentEmpty()) {
PaintUnderlay(*aPresContext, aRenderingContext, aDirtyRect, aFlags,
*myBorder, *myPadding, *cellTableStyle);
}
// Paint outline
nsRect rect(0, 0, mRect.width, mRect.height);
const nsStyleOutline* myOutline = GetStyleOutline();
nsCSSRendering::PaintOutline(aPresContext, aRenderingContext, this,
aDirtyRect, rect, *myBorder, *myOutline,
mStyleContext, 0);
const nsStyleBackground* myColor = GetStyleBackground();
DecorateForSelection(aPresContext, aRenderingContext,myColor); //ignore return value
}
paintChildren = !(aFlags & NS_PAINT_FLAG_TABLE_CELL_BG_PASS);
//flags were for us; remove them for our children
aFlags &= ~ (NS_PAINT_FLAG_TABLE_CELL_BG_PASS | NS_PAINT_FLAG_TABLE_BG_PAINT);
}
#ifdef DEBUG
// for debug...
if ((NS_FRAME_PAINT_LAYER_DEBUG == aWhichLayer) && GetShowFrameBorders()) {
aRenderingContext.SetColor(NS_RGB(0, 0, 128));
aRenderingContext.DrawRect(0, 0, mRect.width, mRect.height);
}
#endif
// paint the children unless we've been told not to
if (paintChildren) {
const nsStyleDisplay* disp = GetStyleDisplay();
// if the cell originates in a row and/or col that is collapsed, the
// bottom and/or right portion of the cell is painted by translating
// the rendering context.
nsPoint offset;
GetCollapseOffset(offset);
PRBool pushed = PR_FALSE;
if ((0 != offset.x) || (0 != offset.y)) {
aRenderingContext.PushState();
pushed = PR_TRUE;
aRenderingContext.Translate(offset.x, offset.y);
aRenderingContext.SetClipRect(nsRect(-offset.x, -offset.y, mRect.width, mRect.height),
nsClipCombine_kIntersect);
}
else {
// XXXldb HIDDEN should really create a scrollframe,
// but use |IsTableClip| here since it doesn't.
if (disp->IsTableClip() ||
(HasPctOverHeight() && eCompatibility_NavQuirks == aPresContext->CompatibilityMode())) {
aRenderingContext.PushState();
pushed = PR_TRUE;
SetOverflowClipRect(aRenderingContext);
}
}
PaintChildren(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, aFlags);
if (pushed) {
aRenderingContext.PopState();
}
}
DO_GLOBAL_REFLOW_COUNT_DSP_J("nsTableCellFrame", &aRenderingContext, 0);
return NS_OK;
/*nsFrame::Paint(aPresContext,
aRenderingContext,
aDirtyRect,
aWhichLayer);*/
}
NS_IMETHODIMP
nsTableCellFrame::GetFrameForPoint(const nsPoint& aPoint,
nsFramePaintLayer aWhichLayer,
nsIFrame** aFrame)
{
// this should act like a block, so we need to override
return GetFrameForPointUsing(aPoint, nsnull, aWhichLayer, (aWhichLayer == NS_FRAME_PAINT_LAYER_BACKGROUND), aFrame);
}
//null range means the whole thing
NS_IMETHODIMP
nsTableCellFrame::SetSelected(nsPresContext* aPresContext,
nsIDOMRange* aRange,
PRBool aSelected,
nsSpread aSpread)
{
//traverse through children unselect tables
#if 0
if ((aSpread == eSpreadDown)){
nsIFrame* kid = GetFirstChild(nsnull);
while (nsnull != kid) {
kid->SetSelected(nsnull, aSelected, eSpreadDown);
kid = kid->GetNextSibling();
}
}
//return nsFrame::SetSelected(aRange,aSelected,eSpreadNone);
#endif
// Must call base class to set mSelected state and trigger repaint of frame
// Note that in current version, aRange and aSpread are ignored,
// only this frame is considered
nsFrame::SetSelected(aPresContext, aRange, aSelected, aSpread);
PRBool tableCellSelectionMode;
nsresult result = aPresContext->PresShell()->FrameSelection()->GetTableCellSelection(&tableCellSelectionMode);
if (NS_SUCCEEDED(result) && tableCellSelectionMode) {
// Selection can affect content, border and outline
Invalidate(GetOverflowRect(), PR_FALSE);
}
return NS_OK;
}
PRIntn
nsTableCellFrame::GetSkipSides() const
{
PRIntn skip = 0;
if (nsnull != mPrevInFlow) {
skip |= 1 << NS_SIDE_TOP;
}
if (nsnull != mNextInFlow) {
skip |= 1 << NS_SIDE_BOTTOM;
}
return skip;
}
PRBool nsTableCellFrame::ParentDisablesSelection() const //override default behavior
{
PRBool returnval;
if (NS_FAILED(GetSelected(&returnval)))
return PR_FALSE;
if (returnval)
return PR_TRUE;
return nsFrame::ParentDisablesSelection();
}
/* virtual */ void
nsTableCellFrame::GetSelfOverflow(nsRect& aOverflowArea)
{
aOverflowArea = nsRect(nsPoint(0,0), GetSize());
}
// Align the cell's child frame within the cell
void nsTableCellFrame::VerticallyAlignChild(const nsHTMLReflowState& aReflowState,
nscoord aMaxAscent)
{
const nsStyleTextReset* textStyle = GetStyleTextReset();
/* XXX: remove tableFrame when border-collapse inherits */
nsPresContext* presContext = GetPresContext();
GET_PIXELS_TO_TWIPS(presContext, p2t);
nsMargin borderPadding = nsTableFrame::GetBorderPadding(aReflowState, p2t, this);
nscoord topInset = borderPadding.top;
nscoord bottomInset = borderPadding.bottom;
// As per bug 10207, we map 'sub', 'super', 'text-top', 'text-bottom',
// length and percentage values to 'baseline'
// XXX It seems that we don't get to see length and percentage values here
// because the Style System has already fixed the error and mapped them
// to whatever is inherited from the parent, i.e, 'middle' in most cases.
PRUint8 verticalAlignFlags = NS_STYLE_VERTICAL_ALIGN_BASELINE;
if (textStyle->mVerticalAlign.GetUnit() == eStyleUnit_Enumerated) {
verticalAlignFlags = textStyle->mVerticalAlign.GetIntValue();
if (verticalAlignFlags != NS_STYLE_VERTICAL_ALIGN_TOP &&
verticalAlignFlags != NS_STYLE_VERTICAL_ALIGN_MIDDLE &&
verticalAlignFlags != NS_STYLE_VERTICAL_ALIGN_BOTTOM)
{
verticalAlignFlags = NS_STYLE_VERTICAL_ALIGN_BASELINE;
}
}
nscoord height = mRect.height;
nsIFrame* firstKid = mFrames.FirstChild();
NS_ASSERTION(firstKid, "Frame construction error, a table cell always has an inner cell frame");
nsRect kidRect = firstKid->GetRect();
nscoord childHeight = kidRect.height;
// Vertically align the child
nscoord kidYTop = 0;
switch (verticalAlignFlags)
{
case NS_STYLE_VERTICAL_ALIGN_BASELINE:
// Align the baselines of the child frame with the baselines of
// other children in the same row which have 'vertical-align: baseline'
kidYTop = topInset + aMaxAscent - GetDesiredAscent();
break;
case NS_STYLE_VERTICAL_ALIGN_TOP:
// Align the top of the child frame with the top of the content area,
kidYTop = topInset;
break;
case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
// Align the bottom of the child frame with the bottom of the content area,
kidYTop = height - childHeight - bottomInset;
break;
default:
case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
// Align the middle of the child frame with the middle of the content area,
kidYTop = (height - childHeight - bottomInset + topInset) / 2;
kidYTop = nsTableFrame::RoundToPixel(kidYTop,
presContext->ScaledPixelsToTwips(),
eAlwaysRoundDown);
}
// if the content is larger than the cell height align from top
kidYTop = PR_MAX(0, kidYTop);
firstKid->SetPosition(nsPoint(kidRect.x, kidYTop));
nsHTMLReflowMetrics desiredSize(PR_FALSE);
desiredSize.width = mRect.width;
desiredSize.height = mRect.height;
GetSelfOverflow(desiredSize.mOverflowArea);
ConsiderChildOverflow(desiredSize.mOverflowArea, firstKid);
FinishAndStoreOverflow(&desiredSize);
if (kidYTop != kidRect.y) {
// Make sure any child views are correctly positioned. We know the inner table
// cell won't have a view
nsContainerFrame::PositionChildViews(firstKid);
}
if (HasView()) {
nsContainerFrame::SyncFrameViewAfterReflow(presContext, this,
GetView(),
&desiredSize.mOverflowArea, 0);
}
}
// As per bug 10207, we map 'sub', 'super', 'text-top', 'text-bottom',
// length and percentage values to 'baseline'
// XXX It seems that we don't get to see length and percentage values here
// because the Style System has already fixed the error and mapped them
// to whatever is inherited from the parent, i.e, 'middle' in most cases.
PRBool
nsTableCellFrame::HasVerticalAlignBaseline()
{
const nsStyleTextReset* textStyle = GetStyleTextReset();
if (textStyle->mVerticalAlign.GetUnit() == eStyleUnit_Enumerated) {
PRUint8 verticalAlignFlags = textStyle->mVerticalAlign.GetIntValue();
if (verticalAlignFlags == NS_STYLE_VERTICAL_ALIGN_TOP ||
verticalAlignFlags == NS_STYLE_VERTICAL_ALIGN_MIDDLE ||
verticalAlignFlags == NS_STYLE_VERTICAL_ALIGN_BOTTOM)
{
return PR_FALSE;
}
}
return PR_TRUE;
}
PRInt32 nsTableCellFrame::GetRowSpan()
{
PRInt32 rowSpan=1;
nsGenericHTMLElement *hc = nsGenericHTMLElement::FromContent(mContent);
if (hc) {
const nsAttrValue* attr = hc->GetParsedAttr(nsHTMLAtoms::rowspan);
if (attr && attr->Type() == nsAttrValue::eInteger) {
rowSpan = attr->GetIntegerValue();
}
}
return rowSpan;
}
PRInt32 nsTableCellFrame::GetColSpan()
{
PRInt32 colSpan=1;
nsGenericHTMLElement *hc = nsGenericHTMLElement::FromContent(mContent);
if (hc) {
const nsAttrValue* attr = hc->GetParsedAttr(nsHTMLAtoms::colspan);
if (attr && attr->Type() == nsAttrValue::eInteger) {
colSpan = attr->GetIntegerValue();
}
}
return colSpan;
}
#ifdef DEBUG
#define PROBABLY_TOO_LARGE 1000000
static
void DebugCheckChildSize(nsIFrame* aChild,
nsHTMLReflowMetrics& aMet,
nsSize& aAvailSize,
PRBool aIsPass2Reflow)
{
if (aIsPass2Reflow) {
if ((aMet.width < 0) || (aMet.width > PROBABLY_TOO_LARGE)) {
printf("WARNING: cell content %p has large width %d \n", aChild, aMet.width);
}
}
if (aMet.mComputeMEW) {
nscoord tmp = aMet.mMaxElementWidth;
if ((tmp < 0) || (tmp > PROBABLY_TOO_LARGE)) {
printf("WARNING: cell content %p has large max element width %d \n", aChild, tmp);
}
}
}
#endif
// the computed height for the cell, which descendents use for percent height calculations
// it is the height (minus border, padding) of the cell's first in flow during its final
// reflow without an unconstrained height.
static nscoord
CalcUnpaginagedHeight(nsPresContext* aPresContext,
nsTableCellFrame& aCellFrame,
nsTableFrame& aTableFrame,
nscoord aVerticalBorderPadding)
{
const nsTableCellFrame* firstCellInFlow = (nsTableCellFrame*)aCellFrame.GetFirstInFlow();
nsTableFrame* firstTableInFlow = (nsTableFrame*)aTableFrame.GetFirstInFlow();
nsTableRowFrame* row
= NS_STATIC_CAST(nsTableRowFrame*, firstCellInFlow->GetParent());
nsTableRowGroupFrame* firstRGInFlow
= NS_STATIC_CAST(nsTableRowGroupFrame*, row->GetParent());
PRInt32 rowIndex;
firstCellInFlow->GetRowIndex(rowIndex);
PRInt32 rowSpan = aTableFrame.GetEffectiveRowSpan(*firstCellInFlow);
nscoord cellSpacing = firstTableInFlow->GetCellSpacingX();
nscoord computedHeight = ((rowSpan - 1) * cellSpacing) - aVerticalBorderPadding;
PRInt32 rowX;
for (row = firstRGInFlow->GetFirstRow(), rowX = 0; row; row = row->GetNextRow(), rowX++) {
if (rowX > rowIndex + rowSpan - 1) {
break;
}
else if (rowX >= rowIndex) {
computedHeight += row->GetUnpaginatedHeight(aPresContext);
}
}
return computedHeight;
}
NS_METHOD nsTableCellFrame::Reflow(nsPresContext* aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus)
{
DO_GLOBAL_REFLOW_COUNT("nsTableCellFrame", aReflowState.reason);
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
#if defined DEBUG_TABLE_REFLOW_TIMING
nsTableFrame::DebugReflow(this, (nsHTMLReflowState&)aReflowState);
#endif
float p2t = aPresContext->ScaledPixelsToTwips();
// work around pixel rounding errors, round down to ensure we don't exceed the avail height in
nscoord availHeight = aReflowState.availableHeight;
if (NS_UNCONSTRAINEDSIZE != availHeight) {
availHeight = nsTableFrame::RoundToPixel(availHeight, p2t, eAlwaysRoundDown);
}
nsresult rv = NS_OK;
// see if a special height reflow needs to occur due to having a pct height
if (!NeedSpecialReflow())
nsTableFrame::CheckRequestSpecialHeightReflow(aReflowState);
// this should probably be cached somewhere
nsCompatibility compatMode = aPresContext->CompatibilityMode();
// Initialize out parameter
if (aDesiredSize.mComputeMEW) {
aDesiredSize.mMaxElementWidth = 0;
}
aStatus = NS_FRAME_COMPLETE;
nsSize availSize(aReflowState.availableWidth, availHeight);
PRBool noBorderBeforeReflow = GetContentEmpty() &&
GetStyleTableBorder()->mEmptyCells != NS_STYLE_TABLE_EMPTY_CELLS_SHOW;
/* XXX: remove tableFrame when border-collapse inherits */
nsTableFrame* tableFrame = nsnull;
rv = nsTableFrame::GetTableFrame(this, tableFrame); if (!tableFrame) ABORT1(NS_ERROR_NULL_POINTER);
nsMargin borderPadding = aReflowState.mComputedPadding;
nsMargin border;
GetBorderWidth(p2t, border);
if ((NS_UNCONSTRAINEDSIZE == availSize.width) || !noBorderBeforeReflow) {
borderPadding += border;
}
nscoord topInset = borderPadding.top;
nscoord rightInset = borderPadding.right;
nscoord bottomInset = borderPadding.bottom;
nscoord leftInset = borderPadding.left;
// reduce available space by insets, if we're in a constrained situation
if (NS_UNCONSTRAINEDSIZE!=availSize.width)
availSize.width -= leftInset+rightInset;
if (NS_UNCONSTRAINEDSIZE!=availSize.height)
availSize.height -= topInset+bottomInset;
PRBool isStyleChanged = PR_FALSE;
if (eReflowReason_Incremental == aReflowState.reason) {
// if the path has a reflow command then the cell must be the target of a style change
nsHTMLReflowCommand* command = aReflowState.path->mReflowCommand;
if (command) {
// if there are other reflow commands targeted at the cell's block, these will
// be subsumed by the style change reflow
nsReflowType type;
command->GetType(type);
if (eReflowType_StyleChanged == type) {
isStyleChanged = PR_TRUE;
}
else NS_ASSERTION(PR_FALSE, "table cell target of illegal incremental reflow type");
}
// else the reflow command will be passed down to the child
}
// Try to reflow the child into the available space. It might not
// fit or might need continuing.
if (availSize.height < 0)
availSize.height = 1;
nsHTMLReflowMetrics kidSize(NS_UNCONSTRAINEDSIZE == aReflowState.availableWidth ||
aDesiredSize.mComputeMEW,
aDesiredSize.mFlags);
kidSize.width=kidSize.height=kidSize.ascent=kidSize.descent=0;
SetPriorAvailWidth(aReflowState.availableWidth);
nsIFrame* firstKid = mFrames.FirstChild();
NS_ASSERTION(firstKid, "Frame construction error, a table cell always has an inner cell frame");
nscoord computedPaginatedHeight = 0;
if (aReflowState.mFlags.mSpecialHeightReflow ||
(HadSpecialReflow() && (eReflowReason_Incremental == aReflowState.reason))) {
((nsHTMLReflowState&)aReflowState).mComputedHeight = mRect.height - topInset - bottomInset;
DISPLAY_REFLOW_CHANGE();
}
else if (aPresContext->IsPaginated()) {
computedPaginatedHeight = CalcUnpaginagedHeight(aPresContext, (nsTableCellFrame&)*this, *tableFrame, topInset + bottomInset);
if (computedPaginatedHeight > 0) {
((nsHTMLReflowState&)aReflowState).mComputedHeight = computedPaginatedHeight;
DISPLAY_REFLOW_CHANGE();
}
}
else {
SetHasPctOverHeight(PR_FALSE);
}
// If it was a style change targeted at us, then reflow the child with a style change reason
nsReflowReason reason = aReflowState.reason;
if (isStyleChanged) {
reason = eReflowReason_StyleChange;
// the following could be optimized with a fair amount of effort
tableFrame->SetNeedStrategyInit(PR_TRUE);
}
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, firstKid, availSize, reason);
// mIPercentHeightObserver is for non table related frames inside cells in quirks mode
kidReflowState.mPercentHeightObserver = (eCompatibility_NavQuirks == compatMode) ? (nsIPercentHeightObserver *)this : nsnull;
// Assume the inner child will stay positioned exactly where it is. Later in
// VerticallyAlignChild() we'll move it if it turns out to be wrong. This
// avoids excessive movement and is more stable
nsPoint kidOrigin;
if (isStyleChanged ||
(eReflowReason_Initial == aReflowState.reason) ||
(eReflowReason_StyleChange == aReflowState.reason)) {
kidOrigin.MoveTo(leftInset, topInset);
} else {
// handle percent padding-left which was 0 during initial reflow
if (eStyleUnit_Percent == aReflowState.mStylePadding->mPadding.GetLeftUnit()) {
nsRect kidRect = firstKid->GetRect();
// only move in the x direction for the same reason as above
kidOrigin.MoveTo(leftInset, kidRect.y);
firstKid->SetPosition(nsPoint(leftInset, kidRect.y));
}
kidOrigin = firstKid->GetPosition();
}
#if defined DEBUG_TABLE_REFLOW_TIMING
nsTableFrame::DebugReflow(firstKid, (nsHTMLReflowState&)kidReflowState);
#endif
nscoord priorBlockHeight = GetLastBlockHeight();
ReflowChild(firstKid, aPresContext, kidSize, kidReflowState,
kidOrigin.x, kidOrigin.y, 0, aStatus);
SetLastBlockHeight(kidSize.height);
if (isStyleChanged) {
Invalidate(GetOverflowRect(), PR_FALSE);
}
#if defined DEBUG_TABLE_REFLOW_TIMING
nsTableFrame::DebugReflow(firstKid, (nsHTMLReflowState&)kidReflowState, &kidSize, aStatus);
#endif
#ifdef NS_DEBUG
DebugCheckChildSize(firstKid, kidSize, availSize, (NS_UNCONSTRAINEDSIZE != aReflowState.availableWidth));
#endif
// 0 dimensioned cells need to be treated specially in Standard/NavQuirks mode
// see testcase "emptyCells.html"
if ((0 == kidSize.width) || (0 == kidSize.height)) { // XXX why was this &&
SetContentEmpty(PR_TRUE);
if (NS_UNCONSTRAINEDSIZE == kidReflowState.availableWidth &&
GetStyleTableBorder()->mEmptyCells != NS_STYLE_TABLE_EMPTY_CELLS_SHOW) {
// need to reduce the insets by border if the cell is empty
leftInset -= border.left;
rightInset -= border.right;
topInset -= border.top;
bottomInset -= border.bottom;
}
}
else {
SetContentEmpty(PR_FALSE);
if ((eReflowReason_Incremental == aReflowState.reason) && noBorderBeforeReflow) {
// need to consider borders, since they were factored out above
leftInset += border.left;
rightInset += border.right;
topInset += border.top;
bottomInset += border.bottom;
kidOrigin.MoveTo(leftInset, topInset);
}
}
const nsStylePosition* pos = GetStylePosition();
// calculate the min cell width
nscoord onePixel = NSIntPixelsToTwips(1, p2t);
nscoord smallestMinWidth = 0;
if (eCompatibility_NavQuirks == compatMode) {
if ((pos->mWidth.GetUnit() != eStyleUnit_Coord) &&
(pos->mWidth.GetUnit() != eStyleUnit_Percent)) {
if (PR_TRUE == GetContentEmpty()) {
if (border.left > 0)
smallestMinWidth += onePixel;
if (border.right > 0)
smallestMinWidth += onePixel;
}
}
}
PRInt32 colspan = tableFrame->GetEffectiveColSpan(*this);
if (colspan > 1) {
smallestMinWidth = PR_MAX(smallestMinWidth, colspan * onePixel);
nscoord spacingX = tableFrame->GetCellSpacingX();
nscoord spacingExtra = spacingX * (colspan - 1);
smallestMinWidth += spacingExtra;
if (aReflowState.mComputedPadding.left > 0) {
smallestMinWidth -= onePixel;
}
}
if ((0 == kidSize.width) && (NS_UNCONSTRAINEDSIZE != kidReflowState.availableWidth)) {
// empty content has to be forced to the assigned width for resize or incremental reflow
kidSize.width = kidReflowState.availableWidth;
}
if (0 == kidSize.height) {
if ((pos->mHeight.GetUnit() != eStyleUnit_Coord) &&
(pos->mHeight.GetUnit() != eStyleUnit_Percent)) {
PRInt32 pixHeight = (eCompatibility_NavQuirks == compatMode) ? 1 : 0;
kidSize.height = NSIntPixelsToTwips(pixHeight, p2t);
}
}
// end 0 dimensioned cells
kidSize.width = PR_MAX(kidSize.width, smallestMinWidth);
if (!tableFrame->IsAutoLayout()) {
// a cell in a fixed layout table is constrained to the avail width
// if we need to shorten the cell the previous non overflowing block
// will get some overflow area
if (kidSize.width > availSize.width) {
kidSize.width = availSize.width;
firstKid->FinishAndStoreOverflow(&kidSize);
}
}
//if (eReflowReason_Resize == aReflowState.reason) {
// NS_ASSERTION(kidSize.width <= availSize.width, "child needed more space during resize reflow");
//}
// Place the child
FinishReflowChild(firstKid, aPresContext, &kidReflowState, kidSize,
kidOrigin.x, kidOrigin.y, 0);
// first, compute the height which can be set w/o being restricted by aMaxSize.height
nscoord cellHeight = kidSize.height;
if (NS_UNCONSTRAINEDSIZE != cellHeight) {
cellHeight += topInset + bottomInset;
// work around block rounding errors, round down to ensure we don't exceed the avail height in
nsPixelRound roundMethod = (NS_UNCONSTRAINEDSIZE == availHeight) ? eAlwaysRoundUp : eAlwaysRoundDown;
cellHeight = nsTableFrame::RoundToPixel(cellHeight, p2t, roundMethod);
}
// next determine the cell's width
nscoord cellWidth = kidSize.width; // at this point, we've factored in the cell's style attributes
// factor in border and padding
if (NS_UNCONSTRAINEDSIZE != cellWidth) {
cellWidth += leftInset + rightInset;
}
cellWidth = nsTableFrame::RoundToPixel(cellWidth, p2t); // work around block rounding errors
// set the cell's desired size and max element size
aDesiredSize.width = cellWidth;
aDesiredSize.height = cellHeight;
aDesiredSize.ascent = topInset;
aDesiredSize.descent = bottomInset;
aDesiredSize.ascent += kidSize.ascent;
aDesiredSize.descent += kidSize.descent;
// the overflow area will be computed when the child will be vertically aligned
if (aDesiredSize.mComputeMEW) {
aDesiredSize.mMaxElementWidth =
PR_MAX(smallestMinWidth, kidSize.mMaxElementWidth);
if (NS_UNCONSTRAINEDSIZE != aDesiredSize.mMaxElementWidth) {
aDesiredSize.mMaxElementWidth = nsTableFrame::RoundToPixel(
aDesiredSize.mMaxElementWidth + leftInset + rightInset, p2t);
}
}
if (aDesiredSize.mFlags & NS_REFLOW_CALC_MAX_WIDTH) {
aDesiredSize.mMaximumWidth = kidSize.mMaximumWidth;
if (NS_UNCONSTRAINEDSIZE != aDesiredSize.mMaximumWidth) {
aDesiredSize.mMaximumWidth += leftInset + rightInset;
aDesiredSize.mMaximumWidth = nsTableFrame::RoundToPixel(aDesiredSize.mMaximumWidth, p2t);
}
// make sure the preferred width is at least as big as the max element width
if (aDesiredSize.mComputeMEW) {
aDesiredSize.mMaximumWidth = PR_MAX(aDesiredSize.mMaximumWidth, aDesiredSize.mMaxElementWidth);
}
}
if (aReflowState.mFlags.mSpecialHeightReflow) {
if (aDesiredSize.height > mRect.height) {
// set a bit indicating that the pct height contents exceeded
// the height that they could honor in the pass 2 reflow
SetHasPctOverHeight(PR_TRUE);
}
if (NS_UNCONSTRAINEDSIZE == aReflowState.availableHeight) {
aDesiredSize.height = mRect.height;
}
SetNeedSpecialReflow(PR_FALSE);
SetHadSpecialReflow(PR_TRUE);
}
else if (HadSpecialReflow()) {
if (eReflowReason_Incremental == aReflowState.reason) {
// with an unconstrained height, if the block height value hasn't changed,
// use the last height of the cell.
if ((NS_UNCONSTRAINEDSIZE == aReflowState.availableHeight) &&
(GetLastBlockHeight() == priorBlockHeight)) {
aDesiredSize.height = mRect.height;
}
}
// XXX should probably call SetHadSpecialReflow(PR_FALSE) when things change so that
// nothing inside the cell has a percent height, but it is not easy determining this
}
// remember the desired size for this reflow
SetDesiredSize(aDesiredSize);
#if defined DEBUG_TABLE_REFLOW_TIMING
nsTableFrame::DebugReflow(this, (nsHTMLReflowState&)aReflowState, &aDesiredSize, aStatus);
#endif
if (NS_UNCONSTRAINEDSIZE == aReflowState.availableWidth) {
SetNeedPass2Reflow(PR_TRUE);
}
else if ((eReflowReason_Initial == aReflowState.reason) ||
(eReflowReason_Resize == aReflowState.reason)) {
SetNeedPass2Reflow(PR_FALSE);
}
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
return NS_OK;
}
/* ----- global methods ----- */
NS_IMPL_ADDREF_INHERITED(nsTableCellFrame, nsHTMLContainerFrame)
NS_IMPL_RELEASE_INHERITED(nsTableCellFrame, nsHTMLContainerFrame)
nsresult nsTableCellFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(NS_GET_IID(nsITableCellLayout))) {
*aInstancePtr = (void*) (nsITableCellLayout *)this;
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsIPercentHeightObserver))) {
*aInstancePtr = (void*) (nsIPercentHeightObserver *)this;
return NS_OK;
}
return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr);
}
#ifdef ACCESSIBILITY
NS_IMETHODIMP nsTableCellFrame::GetAccessible(nsIAccessible** aAccessible)
{
nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
if (accService) {
return accService->CreateHTMLTableCellAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
}
return NS_ERROR_FAILURE;
}
#endif
/* This is primarily for editor access via nsITableLayout */
NS_IMETHODIMP
nsTableCellFrame::GetCellIndexes(PRInt32 &aRowIndex, PRInt32 &aColIndex)
{
nsresult res = GetRowIndex(aRowIndex);
if (NS_FAILED(res))
{
aColIndex = 0;
return res;
}
aColIndex = mBits.mColIndex;
return NS_OK;
}
NS_IMETHODIMP
nsTableCellFrame::GetPreviousCellInColumn(nsITableCellLayout **aCellLayout)
{
if (!aCellLayout) return NS_ERROR_NULL_POINTER;
*aCellLayout = nsnull;
nsTableFrame* tableFrame = nsnull;
nsresult rv = nsTableFrame::GetTableFrame(this, tableFrame);
if (NS_FAILED(rv)) return rv;
if (!tableFrame) return NS_ERROR_FAILURE;
// Get current cell location
PRInt32 rowIndex, colIndex;
GetCellIndexes(rowIndex, colIndex);
if (colIndex > 0)
{
// Get the cellframe at previous colIndex
nsTableCellFrame *cellFrame = tableFrame->GetCellFrameAt(rowIndex, colIndex-1);
if (!cellFrame) return NS_ERROR_FAILURE;
return CallQueryInterface(cellFrame, aCellLayout);
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsTableCellFrame::GetNextCellInColumn(nsITableCellLayout **aCellLayout)
{
if (!aCellLayout) return NS_ERROR_NULL_POINTER;
*aCellLayout = nsnull;
nsTableFrame* tableFrame = nsnull;
nsresult rv = nsTableFrame::GetTableFrame(this, tableFrame);
if (NS_FAILED(rv)) return rv;
if (!tableFrame) return NS_ERROR_FAILURE;
// Get current cell location
PRInt32 rowIndex, colIndex;
GetCellIndexes(rowIndex, colIndex);
// Get the cellframe at next colIndex
nsTableCellFrame *cellFrame = tableFrame->GetCellFrameAt(rowIndex, colIndex+1);
if (!cellFrame) return NS_ERROR_FAILURE;
return CallQueryInterface(cellFrame, aCellLayout);
}
nsresult
NS_NewTableCellFrame(nsIPresShell* aPresShell,
PRBool aIsBorderCollapse,
nsIFrame** aNewFrame)
{
NS_PRECONDITION(aNewFrame, "null OUT ptr");
if (nsnull == aNewFrame) {
return NS_ERROR_NULL_POINTER;
}
nsTableCellFrame* it = (aIsBorderCollapse) ? new (aPresShell) nsBCTableCellFrame
: new (aPresShell) nsTableCellFrame;
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
*aNewFrame = it;
return NS_OK;
}
nsMargin*
nsTableCellFrame::GetBorderWidth(float aPixelsToTwips,
nsMargin& aBorder) const
{
aBorder = GetStyleBorder()->GetBorder();
return &aBorder;
}
nsIAtom*
nsTableCellFrame::GetType() const
{
return nsLayoutAtoms::tableCellFrame;
}
#ifdef DEBUG
NS_IMETHODIMP
nsTableCellFrame::GetFrameName(nsAString& aResult) const
{
return MakeFrameName(NS_LITERAL_STRING("TableCell"), aResult);
}
#endif
void nsTableCellFrame::SetCollapseOffsetX(nscoord aXOffset)
{
// Get the frame property (creating a point struct if necessary)
nsPoint* offset = (nsPoint*)nsTableFrame::GetProperty(this, nsLayoutAtoms::collapseOffsetProperty, aXOffset != 0);
if (offset) {
offset->x = aXOffset;
}
}
void nsTableCellFrame::SetCollapseOffsetY(nscoord aYOffset)
{
// Get the property (creating a point struct if necessary)
nsPoint* offset = (nsPoint*)nsTableFrame::GetProperty(this, nsLayoutAtoms::collapseOffsetProperty, aYOffset != 0);
if (offset) {
offset->y = aYOffset;
}
}
void nsTableCellFrame::GetCollapseOffset(nsPoint& aOffset)
{
// See if the property is set
nsPoint* offset = (nsPoint*)nsTableFrame::GetProperty(this, nsLayoutAtoms::collapseOffsetProperty);
if (offset) {
aOffset = *offset;
} else {
aOffset.MoveTo(0, 0);
}
}
// nsBCTableCellFrame
nsBCTableCellFrame::nsBCTableCellFrame()
:nsTableCellFrame()
{
mTopBorder = mRightBorder = mBottomBorder = mLeftBorder = 0;
}
nsBCTableCellFrame::~nsBCTableCellFrame()
{
}
nsIAtom*
nsBCTableCellFrame::GetType() const
{
return nsLayoutAtoms::bcTableCellFrame;
}
#ifdef DEBUG
NS_IMETHODIMP
nsBCTableCellFrame::GetFrameName(nsAString& aResult) const
{
return MakeFrameName(NS_LITERAL_STRING("BCTableCell"), aResult);
}
#endif
nsMargin*
nsBCTableCellFrame::GetBorderWidth(float aPixelsToTwips,
nsMargin& aBorder) const
{
aBorder.top = BC_BORDER_BOTTOM_HALF_COORD(aPixelsToTwips, mTopBorder);
aBorder.right = BC_BORDER_LEFT_HALF_COORD(aPixelsToTwips, mRightBorder);
aBorder.bottom = BC_BORDER_TOP_HALF_COORD(aPixelsToTwips, mBottomBorder);
aBorder.left = BC_BORDER_RIGHT_HALF_COORD(aPixelsToTwips, mLeftBorder);
return &aBorder;
}
BCPixelSize
nsBCTableCellFrame::GetBorderWidth(PRUint8 aSide) const
{
switch(aSide) {
case NS_SIDE_TOP:
return BC_BORDER_BOTTOM_HALF(mTopBorder);
case NS_SIDE_RIGHT:
return BC_BORDER_LEFT_HALF(mRightBorder);
case NS_SIDE_BOTTOM:
return BC_BORDER_TOP_HALF(mBottomBorder);
default:
return BC_BORDER_RIGHT_HALF(mLeftBorder);
}
}
void
nsBCTableCellFrame::SetBorderWidth(PRUint8 aSide,
BCPixelSize aValue)
{
switch(aSide) {
case NS_SIDE_TOP:
mTopBorder = aValue;
break;
case NS_SIDE_RIGHT:
mRightBorder = aValue;
break;
case NS_SIDE_BOTTOM:
mBottomBorder = aValue;
break;
default:
mLeftBorder = aValue;
}
}
/* virtual */ void
nsBCTableCellFrame::GetSelfOverflow(nsRect& aOverflowArea)
{
nsMargin halfBorder;
float p2t = GetPresContext()->PixelsToTwips();
halfBorder.top = BC_BORDER_TOP_HALF_COORD(p2t, mTopBorder);
halfBorder.right = BC_BORDER_RIGHT_HALF_COORD(p2t, mRightBorder);
halfBorder.bottom = BC_BORDER_BOTTOM_HALF_COORD(p2t, mBottomBorder);
halfBorder.left = BC_BORDER_LEFT_HALF_COORD(p2t, mLeftBorder);
nsRect overflow(nsPoint(0,0), GetSize());
overflow.Inflate(halfBorder);
aOverflowArea = overflow;
}
void
nsBCTableCellFrame::PaintUnderlay(nsPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect,
PRUint32& aFlags,
const nsStyleBorder& aStyleBorder,
const nsStylePadding& aStylePadding,
const nsStyleTableBorder& aCellTableStyle)
{
if (!(aFlags & NS_PAINT_FLAG_TABLE_BG_PAINT)
/*direct call; not table-based paint*/ ||
(aFlags & NS_PAINT_FLAG_TABLE_CELL_BG_PASS)
/*table cell background only pass*/) {
// make border-width reflect the half of the border-collapse
// assigned border that's inside the cell
GET_PIXELS_TO_TWIPS(&aPresContext, p2t);
nsMargin borderWidth;
GetBorderWidth(p2t, borderWidth);
nsStyleBorder myBorder(aStyleBorder);
NS_FOR_CSS_SIDES(side) {
myBorder.SetBorderWidth(side, borderWidth.side(side));
}
nsRect rect(0, 0, mRect.width, mRect.height);
nsCSSRendering::PaintBackground(&aPresContext, aRenderingContext, this,
aDirtyRect, rect, myBorder, aStylePadding,
PR_TRUE);
// borders are painted by nsTableFrame
}
}
|