Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/xul/tree/nsTreeColFrame.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "nsCOMPtr.h"
8
#include "nsTreeColFrame.h"
9
#include "nsGkAtoms.h"
10
#include "nsIContent.h"
11
#include "mozilla/ComputedStyle.h"
12
#include "nsNameSpaceManager.h"
13
#include "nsIBoxObject.h"
14
#include "mozilla/ErrorResult.h"
15
#include "mozilla/dom/TreeBoxObject.h"
16
#include "nsTreeColumns.h"
17
#include "nsDisplayList.h"
18
#include "nsTreeBodyFrame.h"
19
#include "nsXULElement.h"
20
21
//
22
// NS_NewTreeColFrame
23
//
24
// Creates a new col frame
25
//
26
nsIFrame*
27
NS_NewTreeColFrame(nsIPresShell* aPresShell, ComputedStyle* aStyle)
28
0
{
29
0
  return new (aPresShell) nsTreeColFrame(aStyle);
30
0
}
31
32
NS_IMPL_FRAMEARENA_HELPERS(nsTreeColFrame)
33
34
// Destructor
35
nsTreeColFrame::~nsTreeColFrame()
36
0
{
37
0
}
38
39
void
40
nsTreeColFrame::Init(nsIContent*       aContent,
41
                     nsContainerFrame* aParent,
42
                     nsIFrame*         aPrevInFlow)
43
0
{
44
0
  nsBoxFrame::Init(aContent, aParent, aPrevInFlow);
45
0
  InvalidateColumns();
46
0
}
47
48
void
49
nsTreeColFrame::DestroyFrom(nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData)
50
0
{
51
0
  InvalidateColumns(false);
52
0
  nsBoxFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
53
0
}
54
55
class nsDisplayXULTreeColSplitterTarget final : public nsDisplayItem
56
{
57
public:
58
  nsDisplayXULTreeColSplitterTarget(nsDisplayListBuilder* aBuilder,
59
                                    nsIFrame* aFrame) :
60
0
    nsDisplayItem(aBuilder, aFrame) {
61
0
    MOZ_COUNT_CTOR(nsDisplayXULTreeColSplitterTarget);
62
0
  }
63
#ifdef NS_BUILD_REFCNT_LOGGING
64
  virtual ~nsDisplayXULTreeColSplitterTarget() {
65
    MOZ_COUNT_DTOR(nsDisplayXULTreeColSplitterTarget);
66
  }
67
#endif
68
69
  virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
70
                       HitTestState* aState,
71
                       nsTArray<nsIFrame*> *aOutFrames) override;
72
  NS_DISPLAY_DECL_NAME("XULTreeColSplitterTarget", TYPE_XUL_TREE_COL_SPLITTER_TARGET)
73
};
74
75
void
76
nsDisplayXULTreeColSplitterTarget::HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
77
                                           HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames)
78
0
{
79
0
  nsRect rect = aRect - ToReferenceFrame();
80
0
  // If we are in either in the first 4 pixels or the last 4 pixels, we're going to
81
0
  // do something really strange.  Check for an adjacent splitter.
82
0
  bool left = false;
83
0
  bool right = false;
84
0
  if (mFrame->GetSize().width - nsPresContext::CSSPixelsToAppUnits(4) <= rect.XMost()) {
85
0
    right = true;
86
0
  } else if (nsPresContext::CSSPixelsToAppUnits(4) > rect.x) {
87
0
    left = true;
88
0
  }
89
0
90
0
  // Swap left and right for RTL trees in order to find the correct splitter
91
0
  if (mFrame->StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL) {
92
0
    bool tmp = left;
93
0
    left = right;
94
0
    right = tmp;
95
0
  }
96
0
97
0
  if (left || right) {
98
0
    // We are a header. Look for the correct splitter.
99
0
    nsIFrame* child;
100
0
    if (left)
101
0
      child = mFrame->GetPrevSibling();
102
0
    else
103
0
      child = mFrame->GetNextSibling();
104
0
105
0
    if (child && child->GetContent()->NodeInfo()->Equals(nsGkAtoms::splitter,
106
0
                                                         kNameSpaceID_XUL)) {
107
0
      aOutFrames->AppendElement(child);
108
0
    }
109
0
  }
110
0
111
0
}
112
113
void
114
nsTreeColFrame::BuildDisplayListForChildren(nsDisplayListBuilder*   aBuilder,
115
                                            const nsDisplayListSet& aLists)
116
0
{
117
0
  if (!aBuilder->IsForEventDelivery()) {
118
0
    nsBoxFrame::BuildDisplayListForChildren(aBuilder, aLists);
119
0
    return;
120
0
  }
121
0
122
0
  nsDisplayListCollection set(aBuilder);
123
0
  nsBoxFrame::BuildDisplayListForChildren(aBuilder, set);
124
0
125
0
  WrapListsInRedirector(aBuilder, set, aLists);
126
0
127
0
  aLists.Content()->AppendToTop(
128
0
    MakeDisplayItem<nsDisplayXULTreeColSplitterTarget>(aBuilder, this));
129
0
}
130
131
nsresult
132
nsTreeColFrame::AttributeChanged(int32_t aNameSpaceID,
133
                                 nsAtom* aAttribute,
134
                                 int32_t aModType)
135
0
{
136
0
  nsresult rv = nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute,
137
0
                                             aModType);
138
0
139
0
  if (aAttribute == nsGkAtoms::ordinal || aAttribute == nsGkAtoms::primary) {
140
0
    InvalidateColumns();
141
0
  }
142
0
143
0
  return rv;
144
0
}
145
146
void
147
nsTreeColFrame::SetXULBounds(nsBoxLayoutState& aBoxLayoutState,
148
                             const nsRect& aRect,
149
                             bool aRemoveOverflowArea)
150
0
{
151
0
  nscoord oldWidth = mRect.width;
152
0
153
0
  nsBoxFrame::SetXULBounds(aBoxLayoutState, aRect, aRemoveOverflowArea);
154
0
  if (mRect.width != oldWidth) {
155
0
    nsITreeBoxObject* treeBoxObject = GetTreeBoxObject();
156
0
    if (treeBoxObject) {
157
0
      treeBoxObject->Invalidate();
158
0
    }
159
0
  }
160
0
}
161
162
nsITreeBoxObject*
163
nsTreeColFrame::GetTreeBoxObject()
164
0
{
165
0
  nsITreeBoxObject* result = nullptr;
166
0
167
0
  nsIContent* parent = mContent->GetParent();
168
0
  if (parent) {
169
0
    nsIContent* grandParent = parent->GetParent();
170
0
    RefPtr<nsXULElement> treeElement =
171
0
      nsXULElement::FromNodeOrNull(grandParent);
172
0
    if (treeElement) {
173
0
      nsCOMPtr<nsIBoxObject> boxObject =
174
0
        treeElement->GetBoxObject(IgnoreErrors());
175
0
176
0
      nsCOMPtr<nsITreeBoxObject> treeBoxObject = do_QueryInterface(boxObject);
177
0
      result = treeBoxObject.get();
178
0
    }
179
0
  }
180
0
  return result;
181
0
}
182
183
void
184
nsTreeColFrame::InvalidateColumns(bool aCanWalkFrameTree)
185
0
{
186
0
  nsITreeBoxObject* treeBoxObject = GetTreeBoxObject();
187
0
  if (treeBoxObject) {
188
0
    RefPtr<nsTreeColumns> columns;
189
0
190
0
    if (aCanWalkFrameTree) {
191
0
      treeBoxObject->GetColumns(getter_AddRefs(columns));
192
0
    } else {
193
0
      nsTreeBodyFrame* body = static_cast<mozilla::dom::TreeBoxObject*>
194
0
        (treeBoxObject)->GetCachedTreeBodyFrame();
195
0
      if (body) {
196
0
        columns = body->Columns();
197
0
      }
198
0
    }
199
0
200
0
    if (columns)
201
0
      columns->InvalidateColumns();
202
0
  }
203
0
}