Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
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 | |
michael@0 | 6 | #include "nsCOMPtr.h" |
michael@0 | 7 | #include "nsTreeColFrame.h" |
michael@0 | 8 | #include "nsGkAtoms.h" |
michael@0 | 9 | #include "nsIContent.h" |
michael@0 | 10 | #include "nsStyleContext.h" |
michael@0 | 11 | #include "nsNameSpaceManager.h" |
michael@0 | 12 | #include "nsIBoxObject.h" |
michael@0 | 13 | #include "nsTreeBoxObject.h" |
michael@0 | 14 | #include "nsIDOMElement.h" |
michael@0 | 15 | #include "nsITreeBoxObject.h" |
michael@0 | 16 | #include "nsITreeColumns.h" |
michael@0 | 17 | #include "nsIDOMXULTreeElement.h" |
michael@0 | 18 | #include "nsDisplayList.h" |
michael@0 | 19 | #include "nsTreeBodyFrame.h" |
michael@0 | 20 | |
michael@0 | 21 | // |
michael@0 | 22 | // NS_NewTreeColFrame |
michael@0 | 23 | // |
michael@0 | 24 | // Creates a new col frame |
michael@0 | 25 | // |
michael@0 | 26 | nsIFrame* |
michael@0 | 27 | NS_NewTreeColFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) |
michael@0 | 28 | { |
michael@0 | 29 | return new (aPresShell) nsTreeColFrame(aPresShell, aContext); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | NS_IMPL_FRAMEARENA_HELPERS(nsTreeColFrame) |
michael@0 | 33 | |
michael@0 | 34 | // Destructor |
michael@0 | 35 | nsTreeColFrame::~nsTreeColFrame() |
michael@0 | 36 | { |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | void |
michael@0 | 40 | nsTreeColFrame::Init(nsIContent* aContent, |
michael@0 | 41 | nsIFrame* aParent, |
michael@0 | 42 | nsIFrame* aPrevInFlow) |
michael@0 | 43 | { |
michael@0 | 44 | nsBoxFrame::Init(aContent, aParent, aPrevInFlow); |
michael@0 | 45 | InvalidateColumns(); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | void |
michael@0 | 49 | nsTreeColFrame::DestroyFrom(nsIFrame* aDestructRoot) |
michael@0 | 50 | { |
michael@0 | 51 | InvalidateColumns(false); |
michael@0 | 52 | nsBoxFrame::DestroyFrom(aDestructRoot); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | class nsDisplayXULTreeColSplitterTarget : public nsDisplayItem { |
michael@0 | 56 | public: |
michael@0 | 57 | nsDisplayXULTreeColSplitterTarget(nsDisplayListBuilder* aBuilder, |
michael@0 | 58 | nsIFrame* aFrame) : |
michael@0 | 59 | nsDisplayItem(aBuilder, aFrame) { |
michael@0 | 60 | MOZ_COUNT_CTOR(nsDisplayXULTreeColSplitterTarget); |
michael@0 | 61 | } |
michael@0 | 62 | #ifdef NS_BUILD_REFCNT_LOGGING |
michael@0 | 63 | virtual ~nsDisplayXULTreeColSplitterTarget() { |
michael@0 | 64 | MOZ_COUNT_DTOR(nsDisplayXULTreeColSplitterTarget); |
michael@0 | 65 | } |
michael@0 | 66 | #endif |
michael@0 | 67 | |
michael@0 | 68 | virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect, |
michael@0 | 69 | HitTestState* aState, |
michael@0 | 70 | nsTArray<nsIFrame*> *aOutFrames) MOZ_OVERRIDE; |
michael@0 | 71 | NS_DISPLAY_DECL_NAME("XULTreeColSplitterTarget", TYPE_XUL_TREE_COL_SPLITTER_TARGET) |
michael@0 | 72 | }; |
michael@0 | 73 | |
michael@0 | 74 | void |
michael@0 | 75 | nsDisplayXULTreeColSplitterTarget::HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect, |
michael@0 | 76 | HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames) |
michael@0 | 77 | { |
michael@0 | 78 | nsRect rect = aRect - ToReferenceFrame(); |
michael@0 | 79 | // If we are in either in the first 4 pixels or the last 4 pixels, we're going to |
michael@0 | 80 | // do something really strange. Check for an adjacent splitter. |
michael@0 | 81 | bool left = false; |
michael@0 | 82 | bool right = false; |
michael@0 | 83 | if (mFrame->GetSize().width - nsPresContext::CSSPixelsToAppUnits(4) <= rect.XMost()) { |
michael@0 | 84 | right = true; |
michael@0 | 85 | } else if (nsPresContext::CSSPixelsToAppUnits(4) > rect.x) { |
michael@0 | 86 | left = true; |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | // Swap left and right for RTL trees in order to find the correct splitter |
michael@0 | 90 | if (mFrame->StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL) { |
michael@0 | 91 | bool tmp = left; |
michael@0 | 92 | left = right; |
michael@0 | 93 | right = tmp; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | if (left || right) { |
michael@0 | 97 | // We are a header. Look for the correct splitter. |
michael@0 | 98 | nsIFrame* child; |
michael@0 | 99 | if (left) |
michael@0 | 100 | child = mFrame->GetPrevSibling(); |
michael@0 | 101 | else |
michael@0 | 102 | child = mFrame->GetNextSibling(); |
michael@0 | 103 | |
michael@0 | 104 | if (child && child->GetContent()->NodeInfo()->Equals(nsGkAtoms::splitter, |
michael@0 | 105 | kNameSpaceID_XUL)) { |
michael@0 | 106 | aOutFrames->AppendElement(child); |
michael@0 | 107 | } |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | void |
michael@0 | 113 | nsTreeColFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder, |
michael@0 | 114 | const nsRect& aDirtyRect, |
michael@0 | 115 | const nsDisplayListSet& aLists) |
michael@0 | 116 | { |
michael@0 | 117 | if (!aBuilder->IsForEventDelivery()) { |
michael@0 | 118 | nsBoxFrame::BuildDisplayListForChildren(aBuilder, aDirtyRect, aLists); |
michael@0 | 119 | return; |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | nsDisplayListCollection set; |
michael@0 | 123 | nsBoxFrame::BuildDisplayListForChildren(aBuilder, aDirtyRect, set); |
michael@0 | 124 | |
michael@0 | 125 | WrapListsInRedirector(aBuilder, set, aLists); |
michael@0 | 126 | |
michael@0 | 127 | aLists.Content()->AppendNewToTop(new (aBuilder) |
michael@0 | 128 | nsDisplayXULTreeColSplitterTarget(aBuilder, this)); |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | nsresult |
michael@0 | 132 | nsTreeColFrame::AttributeChanged(int32_t aNameSpaceID, |
michael@0 | 133 | nsIAtom* aAttribute, |
michael@0 | 134 | int32_t aModType) |
michael@0 | 135 | { |
michael@0 | 136 | nsresult rv = nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute, |
michael@0 | 137 | aModType); |
michael@0 | 138 | |
michael@0 | 139 | if (aAttribute == nsGkAtoms::ordinal || aAttribute == nsGkAtoms::primary) { |
michael@0 | 140 | InvalidateColumns(); |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | return rv; |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | void |
michael@0 | 147 | nsTreeColFrame::SetBounds(nsBoxLayoutState& aBoxLayoutState, |
michael@0 | 148 | const nsRect& aRect, |
michael@0 | 149 | bool aRemoveOverflowArea) { |
michael@0 | 150 | nscoord oldWidth = mRect.width; |
michael@0 | 151 | |
michael@0 | 152 | nsBoxFrame::SetBounds(aBoxLayoutState, aRect, aRemoveOverflowArea); |
michael@0 | 153 | if (mRect.width != oldWidth) { |
michael@0 | 154 | nsITreeBoxObject* treeBoxObject = GetTreeBoxObject(); |
michael@0 | 155 | if (treeBoxObject) { |
michael@0 | 156 | treeBoxObject->Invalidate(); |
michael@0 | 157 | } |
michael@0 | 158 | } |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | nsITreeBoxObject* |
michael@0 | 162 | nsTreeColFrame::GetTreeBoxObject() |
michael@0 | 163 | { |
michael@0 | 164 | nsITreeBoxObject* result = nullptr; |
michael@0 | 165 | |
michael@0 | 166 | nsIContent* parent = mContent->GetParent(); |
michael@0 | 167 | if (parent) { |
michael@0 | 168 | nsIContent* grandParent = parent->GetParent(); |
michael@0 | 169 | nsCOMPtr<nsIDOMXULElement> treeElement = do_QueryInterface(grandParent); |
michael@0 | 170 | if (treeElement) { |
michael@0 | 171 | nsCOMPtr<nsIBoxObject> boxObject; |
michael@0 | 172 | treeElement->GetBoxObject(getter_AddRefs(boxObject)); |
michael@0 | 173 | |
michael@0 | 174 | nsCOMPtr<nsITreeBoxObject> treeBoxObject = do_QueryInterface(boxObject); |
michael@0 | 175 | result = treeBoxObject.get(); |
michael@0 | 176 | } |
michael@0 | 177 | } |
michael@0 | 178 | return result; |
michael@0 | 179 | } |
michael@0 | 180 | |
michael@0 | 181 | void |
michael@0 | 182 | nsTreeColFrame::InvalidateColumns(bool aCanWalkFrameTree) |
michael@0 | 183 | { |
michael@0 | 184 | nsITreeBoxObject* treeBoxObject = GetTreeBoxObject(); |
michael@0 | 185 | if (treeBoxObject) { |
michael@0 | 186 | nsCOMPtr<nsITreeColumns> columns; |
michael@0 | 187 | |
michael@0 | 188 | if (aCanWalkFrameTree) { |
michael@0 | 189 | treeBoxObject->GetColumns(getter_AddRefs(columns)); |
michael@0 | 190 | } else { |
michael@0 | 191 | nsTreeBodyFrame* body = static_cast<nsTreeBoxObject*>(treeBoxObject)->GetCachedTreeBody(); |
michael@0 | 192 | if (body) { |
michael@0 | 193 | columns = body->Columns(); |
michael@0 | 194 | } |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | if (columns) |
michael@0 | 198 | columns->InvalidateColumns(); |
michael@0 | 199 | } |
michael@0 | 200 | } |