diff --git a/accessible/base/nsCoreUtils.cpp b/accessible/base/nsCoreUtils.cpp index 095fb6597bd1..8d9782f4f36e 100644 --- a/accessible/base/nsCoreUtils.cpp +++ b/accessible/base/nsCoreUtils.cpp @@ -66,8 +66,7 @@ bool nsCoreUtils::HasClickListener(nsIContent *aContent) { void nsCoreUtils::DispatchClickEvent(XULTreeElement *aTree, int32_t aRowIndex, nsTreeColumn *aColumn, const nsAString &aPseudoElt) { - RefPtr tcElm; - aTree->GetTreeBody(getter_AddRefs(tcElm)); + RefPtr tcElm = aTree->GetTreeBody(); if (!tcElm) return; Document *document = tcElm->GetUncomposedDoc(); @@ -80,10 +79,12 @@ void nsCoreUtils::DispatchClickEvent(XULTreeElement *aTree, aTree->EnsureRowIsVisible(aRowIndex); // Calculate x and y coordinates. - int32_t x = 0, y = 0, width = 0, height = 0; - nsresult rv = aTree->GetCoordsForCellItem(aRowIndex, aColumn, aPseudoElt, &x, - &y, &width, &height); - if (NS_FAILED(rv)) return; + nsresult rv; + nsIntRect rect = + aTree->GetCoordsForCellItem(aRowIndex, aColumn, aPseudoElt, rv); + if (NS_FAILED(rv)) { + return; + } nsCOMPtr tcBoxObj = nsXULElement::FromNode(tcElm)->GetBoxObject(IgnoreErrors()); @@ -103,9 +104,9 @@ void nsCoreUtils::DispatchClickEvent(XULTreeElement *aTree, RefPtr presContext = presShell->GetPresContext(); - int32_t cnvdX = presContext->CSSPixelsToDevPixels(tcX + x + 1) + + int32_t cnvdX = presContext->CSSPixelsToDevPixels(tcX + int32_t(rect.x) + 1) + presContext->AppUnitsToDevPixels(offset.x); - int32_t cnvdY = presContext->CSSPixelsToDevPixels(tcY + y + 1) + + int32_t cnvdY = presContext->CSSPixelsToDevPixels(tcY + int32_t(rect.y) + 1) + presContext->AppUnitsToDevPixels(offset.y); // XUL is just desktop, so there is no real reason for senfing touch events. @@ -426,8 +427,7 @@ void nsCoreUtils::GetLanguageFor(nsIContent *aContent, nsIContent *aRootContent, already_AddRefed nsCoreUtils::GetTreeBodyBoxObject( XULTreeElement *aTree) { - RefPtr tcElm; - aTree->GetTreeBody(getter_AddRefs(tcElm)); + RefPtr tcElm = aTree->GetTreeBody(); RefPtr tcXULElm = nsXULElement::FromNodeOrNull(tcElm); if (!tcXULElm) return nullptr; @@ -449,8 +449,7 @@ XULTreeElement *nsCoreUtils::GetTree(nsIContent *aContent) { already_AddRefed nsCoreUtils::GetFirstSensibleColumn( XULTreeElement *aTree) { - RefPtr cols; - aTree->GetColumns(getter_AddRefs(cols)); + RefPtr cols = aTree->GetColumns(); if (!cols) return nullptr; RefPtr column = cols->GetFirstColumn(); @@ -462,8 +461,7 @@ already_AddRefed nsCoreUtils::GetFirstSensibleColumn( uint32_t nsCoreUtils::GetSensibleColumnCount(XULTreeElement *aTree) { uint32_t count = 0; - RefPtr cols; - aTree->GetColumns(getter_AddRefs(cols)); + RefPtr cols = aTree->GetColumns(); if (!cols) return count; nsTreeColumn *column = cols->GetFirstColumn(); diff --git a/accessible/xul/XULTreeAccessible.cpp b/accessible/xul/XULTreeAccessible.cpp index 0409a84baf70..b7770a46c853 100644 --- a/accessible/xul/XULTreeAccessible.cpp +++ b/accessible/xul/XULTreeAccessible.cpp @@ -31,6 +31,7 @@ #include "nsTreeBodyFrame.h" #include "nsTreeColumns.h" #include "nsTreeUtils.h" +#include "mozilla/dom/XULTreeElementBinding.h" using namespace mozilla::a11y; @@ -113,8 +114,7 @@ void XULTreeAccessible::Value(nsString& aValue) const { if (currentIndex >= 0) { RefPtr keyCol; - RefPtr cols; - mTree->GetColumns(getter_AddRefs(cols)); + RefPtr cols = mTree->GetColumns(); if (cols) keyCol = cols->GetKeyColumn(); mTreeView->GetCellText(currentIndex, keyCol, aValue); @@ -171,23 +171,21 @@ Accessible* XULTreeAccessible::ChildAtPoint(int32_t aX, int32_t aY, int32_t clientX = presContext->DevPixelsToIntCSSPixels(aX) - rootRect.X(); int32_t clientY = presContext->DevPixelsToIntCSSPixels(aY) - rootRect.Y(); - int32_t row = -1; - RefPtr column; - nsAutoString childEltUnused; - mTree->GetCellAt(clientX, clientY, &row, getter_AddRefs(column), - childEltUnused); + ErrorResult rv; + dom::TreeCellInfo cellInfo; + mTree->GetCellAt(clientX, clientY, cellInfo, rv); // If we failed to find tree cell for the given point then it might be // tree columns. - if (row == -1 || !column) + if (cellInfo.mRow == -1 || !cellInfo.mCol) return AccessibleWrap::ChildAtPoint(aX, aY, aWhichChild); - Accessible* child = GetTreeItemAccessible(row); + Accessible* child = GetTreeItemAccessible(cellInfo.mRow); if (aWhichChild == eDeepestChild && child) { // Look for accessible cell for the found item accessible. RefPtr treeitem = do_QueryObject(child); - Accessible* cell = treeitem->GetCellAccessible(column); + Accessible* cell = treeitem->GetCellAccessible(cellInfo.mCol); if (cell) child = cell; } @@ -524,8 +522,7 @@ void XULTreeAccessible::TreeViewInvalidated(int32_t aStartRow, int32_t aEndRow, endRow = rowCount - 1; } - RefPtr treeColumns; - mTree->GetColumns(getter_AddRefs(treeColumns)); + RefPtr treeColumns = mTree->GetColumns(); if (!treeColumns) return; int32_t endCol = aEndCol; @@ -625,23 +622,19 @@ nsIntRect XULTreeItemAccessibleBase::BoundsInCSSPixels() const { RefPtr column = nsCoreUtils::GetFirstSensibleColumn(mTree); - int32_t x = 0, y = 0, width = 0, height = 0; - nsresult rv = mTree->GetCoordsForCellItem(mRow, column, EmptyString(), &x, &y, - &width, &height); + nsresult rv; + nsIntRect rect = + mTree->GetCoordsForCellItem(mRow, column, NS_LITERAL_STRING("cell"), rv); if (NS_FAILED(rv)) { return nsIntRect(); } - boxObj->GetWidth(&width); + boxObj->GetWidth(&rect.width); int32_t tcX = 0, tcY = 0; boxObj->GetScreenX(&tcX); boxObj->GetScreenY(&tcY); - - x = tcX; - y += tcY; - - return nsIntRect(x, y, width, height); + return nsIntRect(tcX, rect.y + tcY, rect.width, rect.height); } nsRect XULTreeItemAccessibleBase::BoundsInAppUnits() const { @@ -806,9 +799,8 @@ uint64_t XULTreeItemAccessibleBase::NativeState() const { if (FocusMgr()->IsFocused(this)) state |= states::FOCUSED; // invisible state - int32_t firstVisibleRow, lastVisibleRow; - mTree->GetFirstVisibleRow(&firstVisibleRow); - mTree->GetLastVisibleRow(&lastVisibleRow); + int32_t firstVisibleRow = mTree->GetFirstVisibleRow(); + int32_t lastVisibleRow = mTree->GetLastVisibleRow(); if (mRow < firstVisibleRow || mRow > lastVisibleRow) state |= states::INVISIBLE; @@ -837,8 +829,7 @@ void XULTreeItemAccessibleBase::DispatchClickEvent( nsIContent* aContent, uint32_t aActionIndex) const { if (IsDefunct()) return; - RefPtr columns; - mTree->GetColumns(getter_AddRefs(columns)); + RefPtr columns = mTree->GetColumns(); if (!columns) return; // Get column and pseudo element. @@ -874,8 +865,7 @@ bool XULTreeItemAccessibleBase::IsExpandable() const { bool isEmpty = false; mTreeView->IsContainerEmpty(mRow, &isEmpty); if (!isEmpty) { - RefPtr columns; - mTree->GetColumns(getter_AddRefs(columns)); + RefPtr columns = mTree->GetColumns(); if (columns) { nsTreeColumn* primaryColumn = columns->GetPrimaryColumn(); if (primaryColumn && !nsCoreUtils::IsColumnHidden(primaryColumn)) @@ -946,8 +936,7 @@ void XULTreeItemAccessible::Shutdown() { } role XULTreeItemAccessible::NativeRole() const { - RefPtr columns; - mTree->GetColumns(getter_AddRefs(columns)); + RefPtr columns = mTree->GetColumns(); if (!columns) { NS_ERROR("No tree columns object in the tree!"); return roles::NOTHING; @@ -989,8 +978,7 @@ Accessible* XULTreeColumAccessible::GetSiblingAtOffset(int32_t aOffset, RefPtr tree = nsCoreUtils::GetTree(mContent); if (tree) { - nsCOMPtr treeView; - tree->GetView(getter_AddRefs(treeView)); + nsCOMPtr treeView = tree->GetView(); if (treeView) { int32_t rowCount = 0; treeView->GetRowCount(&rowCount); diff --git a/accessible/xul/XULTreeGridAccessible.cpp b/accessible/xul/XULTreeGridAccessible.cpp index e6e63e6e2152..0e0b8a45136c 100644 --- a/accessible/xul/XULTreeGridAccessible.cpp +++ b/accessible/xul/XULTreeGridAccessible.cpp @@ -23,6 +23,7 @@ #include "nsComponentManagerUtils.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/TreeColumnBinding.h" +#include "mozilla/dom/XULTreeElementBinding.h" using namespace mozilla::a11y; using namespace mozilla; @@ -169,8 +170,7 @@ void XULTreeGridAccessible::UnselectRow(uint32_t aRowIdx) { // XULTreeGridAccessible: Accessible implementation role XULTreeGridAccessible::NativeRole() const { - RefPtr treeColumns; - mTree->GetColumns(getter_AddRefs(treeColumns)); + RefPtr treeColumns = mTree->GetColumns(); if (!treeColumns) { NS_ERROR("No treecolumns object for tree!"); return roles::NOTHING; @@ -268,16 +268,14 @@ Accessible* XULTreeGridRowAccessible::ChildAtPoint( int32_t clientX = presContext->DevPixelsToIntCSSPixels(aX) - rootRect.X(); int32_t clientY = presContext->DevPixelsToIntCSSPixels(aY) - rootRect.Y(); - int32_t row = -1; - RefPtr column; - nsAutoString childEltUnused; - mTree->GetCellAt(clientX, clientY, &row, getter_AddRefs(column), - childEltUnused); + ErrorResult rv; + dom::TreeCellInfo cellInfo; + mTree->GetCellAt(clientX, clientY, cellInfo, rv); // Return if we failed to find tree cell in the row for the given point. - if (row != mRow || !column) return nullptr; + if (cellInfo.mRow != mRow || !cellInfo.mCol) return nullptr; - return GetCellAccessible(column); + return GetCellAccessible(cellInfo.mCol); } Accessible* XULTreeGridRowAccessible::GetChildAt(uint32_t aIndex) const { @@ -314,8 +312,7 @@ XULTreeGridCellAccessible* XULTreeGridRowAccessible::GetCellAccessible( void XULTreeGridRowAccessible::RowInvalidated(int32_t aStartColIdx, int32_t aEndColIdx) { - RefPtr treeColumns; - mTree->GetColumns(getter_AddRefs(treeColumns)); + RefPtr treeColumns = mTree->GetColumns(); if (!treeColumns) return; bool nameChanged = false; @@ -410,9 +407,9 @@ nsIntRect XULTreeGridCellAccessible::BoundsInCSSPixels() const { return nsIntRect(); } - int32_t x = 0, y = 0, width = 0, height = 0; - nsresult rv = mTree->GetCoordsForCellItem( - mRow, mColumn, NS_LITERAL_STRING("cell"), &x, &y, &width, &height); + nsresult rv; + nsIntRect rect = + mTree->GetCoordsForCellItem(mRow, mColumn, NS_LITERAL_STRING("cell"), rv); if (NS_FAILED(rv)) { return nsIntRect(); } @@ -420,10 +417,7 @@ nsIntRect XULTreeGridCellAccessible::BoundsInCSSPixels() const { int32_t tcX = 0, tcY = 0; boxObj->GetScreenX(&tcX); boxObj->GetScreenY(&tcY); - x += tcX; - y += tcY; - - return nsIntRect(x, y, width, height); + return nsIntRect(rect.x + tcX, rect.y + tcY, rect.width, rect.height); } nsRect XULTreeGridCellAccessible::BoundsInAppUnits() const { diff --git a/dom/xul/XULTreeElement.cpp b/dom/xul/XULTreeElement.cpp index 4b13020d2dc1..659887d3f47d 100644 --- a/dom/xul/XULTreeElement.cpp +++ b/dom/xul/XULTreeElement.cpp @@ -110,41 +110,30 @@ nsTreeBodyFrame* XULTreeElement::GetTreeBodyFrame(bool aFlushLayout) { return mTreeBody; } -nsresult XULTreeElement::GetView(nsITreeView** aView) { +already_AddRefed XULTreeElement::GetView() { if (!mTreeBody) { if (!GetTreeBodyFrame()) { - // Don't return an uninitialised view - *aView = nullptr; - return NS_OK; + return nullptr; } if (mView) { + nsCOMPtr view; // Our new frame needs to initialise itself - return mTreeBody->GetView(aView); + mTreeBody->GetView(getter_AddRefs(view)); + return view.forget(); } } if (!mView) { // No tree builder, create a tree content view. - nsresult rv = NS_NewTreeContentView(getter_AddRefs(mView)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(NS_NewTreeContentView(getter_AddRefs(mView)))) { + return nullptr; + } // Initialise the frame and view mTreeBody->SetView(mView); } - NS_IF_ADDREF(*aView = mView); - return NS_OK; -} -already_AddRefed XULTreeElement::GetView(CallerType /* unused */) { - nsCOMPtr view; - GetView(getter_AddRefs(view)); - return view.forget(); -} - -nsresult XULTreeElement::SetView(nsITreeView* aView) { - ErrorResult rv; - SetView(aView, CallerType::System, rv); - return rv.StealNSResult(); + return do_AddRef(mView); } void XULTreeElement::SetView(nsITreeView* aView, CallerType aCallerType, @@ -157,108 +146,98 @@ void XULTreeElement::SetView(nsITreeView* aView, CallerType aCallerType, mView = aView; nsTreeBodyFrame* body = GetTreeBodyFrame(); - if (body) body->SetView(aView); + if (body) { + body->SetView(aView); + } } bool XULTreeElement::Focused() { nsTreeBodyFrame* body = GetTreeBodyFrame(); - if (body) return body->GetFocused(); + if (body) { + return body->GetFocused(); + } return false; } -nsresult XULTreeElement::GetFocused(bool* aFocused) { - *aFocused = Focused(); - return NS_OK; -} - void XULTreeElement::SetFocused(bool aFocused) { nsTreeBodyFrame* body = GetTreeBodyFrame(); - if (body) body->SetFocused(aFocused); -} - -nsresult XULTreeElement::GetTreeBody(Element** aElement) { - *aElement = nullptr; - nsTreeBodyFrame* body = GetTreeBodyFrame(); - if (body) return body->GetTreeBody(aElement); - return NS_OK; + if (body) { + body->SetFocused(aFocused); + } } already_AddRefed XULTreeElement::GetTreeBody() { - RefPtr el; - GetTreeBody(getter_AddRefs(el)); - return el.forget(); + nsTreeBodyFrame* body = GetTreeBodyFrame(); + if (body) { + nsCOMPtr element; + body->GetTreeBody(getter_AddRefs(element)); + return element.forget(); + } + + return nullptr; } already_AddRefed XULTreeElement::GetColumns() { nsTreeBodyFrame* body = GetTreeBodyFrame(); - if (body) return body->Columns(); + if (body) { + return body->Columns(); + } return nullptr; } -nsresult XULTreeElement::GetColumns(nsTreeColumns** aColumns) { - *aColumns = GetColumns().take(); - return NS_OK; -} - int32_t XULTreeElement::RowHeight() { nsTreeBodyFrame* body = GetTreeBodyFrame(); - if (body) return body->RowHeight(); + if (body) { + return body->RowHeight(); + } return 0; } int32_t XULTreeElement::RowWidth() { nsTreeBodyFrame* body = GetTreeBodyFrame(); - if (body) return body->RowWidth(); + if (body) { + return body->RowWidth(); + } return 0; } -nsresult XULTreeElement::GetRowHeight(int32_t* aRowHeight) { - *aRowHeight = RowHeight(); - return NS_OK; -} - -nsresult XULTreeElement::GetRowWidth(int32_t* aRowWidth) { - *aRowWidth = RowWidth(); - return NS_OK; -} - int32_t XULTreeElement::GetFirstVisibleRow() { nsTreeBodyFrame* body = GetTreeBodyFrame(); - if (body) return body->FirstVisibleRow(); + if (body) { + return body->FirstVisibleRow(); + } return 0; } -nsresult XULTreeElement::GetFirstVisibleRow(int32_t* aFirstVisibleRow) { - *aFirstVisibleRow = GetFirstVisibleRow(); - return NS_OK; -} - int32_t XULTreeElement::GetLastVisibleRow() { nsTreeBodyFrame* body = GetTreeBodyFrame(); - if (body) return body->LastVisibleRow(); + if (body) { + return body->LastVisibleRow(); + } return 0; } -nsresult XULTreeElement::GetLastVisibleRow(int32_t* aLastVisibleRow) { - *aLastVisibleRow = GetLastVisibleRow(); - return NS_OK; -} - int32_t XULTreeElement::HorizontalPosition() { nsTreeBodyFrame* body = GetTreeBodyFrame(); - if (body) return body->GetHorizontalPosition(); + if (body) { + return body->GetHorizontalPosition(); + } return 0; } int32_t XULTreeElement::GetPageLength() { nsTreeBodyFrame* body = GetTreeBodyFrame(); - if (body) return body->PageLength(); + if (body) { + return body->PageLength(); + } return 0; } void XULTreeElement::EnsureRowIsVisible(int32_t aRow) { nsTreeBodyFrame* body = GetTreeBodyFrame(); - if (body) body->EnsureRowIsVisible(aRow); + if (body) { + body->EnsureRowIsVisible(aRow); + } } void XULTreeElement::EnsureCellIsVisible(int32_t aRow, nsTreeColumn* aCol, @@ -291,32 +270,44 @@ void XULTreeElement::ScrollByLines(int32_t aNumLines) { void XULTreeElement::ScrollByPages(int32_t aNumPages) { nsTreeBodyFrame* body = GetTreeBodyFrame(); - if (body) body->ScrollByPages(aNumPages); + if (body) { + body->ScrollByPages(aNumPages); + } } void XULTreeElement::Invalidate() { nsTreeBodyFrame* body = GetTreeBodyFrame(); - if (body) body->Invalidate(); + if (body) { + body->Invalidate(); + } } void XULTreeElement::InvalidateColumn(nsTreeColumn* aCol) { nsTreeBodyFrame* body = GetTreeBodyFrame(); - if (body) body->InvalidateColumn(aCol); + if (body) { + body->InvalidateColumn(aCol); + } } void XULTreeElement::InvalidateRow(int32_t aIndex) { nsTreeBodyFrame* body = GetTreeBodyFrame(); - if (body) body->InvalidateRow(aIndex); + if (body) { + body->InvalidateRow(aIndex); + } } void XULTreeElement::InvalidateCell(int32_t aRow, nsTreeColumn* aCol) { nsTreeBodyFrame* body = GetTreeBodyFrame(); - if (body) body->InvalidateCell(aRow, aCol); + if (body) { + body->InvalidateCell(aRow, aCol); + } } void XULTreeElement::InvalidateRange(int32_t aStart, int32_t aEnd) { nsTreeBodyFrame* body = GetTreeBodyFrame(); - if (body) body->InvalidateRange(aStart, aEnd); + if (body) { + body->InvalidateRange(aStart, aEnd); + } } int32_t XULTreeElement::GetRowAt(int32_t x, int32_t y) { @@ -327,82 +318,86 @@ int32_t XULTreeElement::GetRowAt(int32_t x, int32_t y) { return body->GetRowAt(x, y); } -nsresult XULTreeElement::GetCellAt(int32_t aX, int32_t aY, int32_t* aRow, - nsTreeColumn** aCol, nsAString& aChildElt) { - *aRow = 0; - *aCol = nullptr; +void XULTreeElement::GetCellAt(int32_t aX, int32_t aY, TreeCellInfo& aRetVal, + ErrorResult& aRv) { + aRetVal.mRow = 0; + aRetVal.mCol = nullptr; + nsTreeBodyFrame* body = GetTreeBodyFrame(); if (body) { nsAutoCString element; - nsresult retval = body->GetCellAt(aX, aY, aRow, aCol, element); - CopyUTF8toUTF16(element, aChildElt); - return retval; + body->GetCellAt(aX, aY, &aRetVal.mRow, getter_AddRefs(aRetVal.mCol), + element); + CopyUTF8toUTF16(element, aRetVal.mChildElt); } - return NS_OK; } -void XULTreeElement::GetCellAt(int32_t x, int32_t y, TreeCellInfo& aRetVal, - ErrorResult& aRv) { - GetCellAt(x, y, &aRetVal.mRow, getter_AddRefs(aRetVal.mCol), - aRetVal.mChildElt); -} +nsIntRect XULTreeElement::GetCoordsForCellItem(int32_t aRow, nsTreeColumn* aCol, + const nsAString& aElement, + nsresult& rv) { + rv = NS_OK; + nsIntRect rect; -nsresult XULTreeElement::GetCoordsForCellItem(int32_t aRow, nsTreeColumn* aCol, - const nsAString& aElement, - int32_t* aX, int32_t* aY, - int32_t* aWidth, - int32_t* aHeight) { - *aX = *aY = *aWidth = *aHeight = 0; nsTreeBodyFrame* body = GetTreeBodyFrame(); NS_ConvertUTF16toUTF8 element(aElement); - if (body) - return body->GetCoordsForCellItem(aRow, aCol, element, aX, aY, aWidth, - aHeight); - return NS_OK; + if (body) { + rv = body->GetCoordsForCellItem(aRow, aCol, element, &rect.x, &rect.y, + &rect.width, &rect.height); + } + + return rect; } already_AddRefed XULTreeElement::GetCoordsForCellItem( - int32_t row, nsTreeColumn& col, const nsAString& element, + int32_t aRow, nsTreeColumn& aCol, const nsAString& aElement, ErrorResult& aRv) { - int32_t x, y, w, h; - GetCoordsForCellItem(row, &col, element, &x, &y, &w, &h); - RefPtr rect = new DOMRect(this, x, y, w, h); - return rect.forget(); + nsresult rv; + nsIntRect rect = GetCoordsForCellItem(aRow, &aCol, aElement, rv); + aRv = rv; + + RefPtr domRect = + new DOMRect(this, rect.x, rect.y, rect.width, rect.height); + return domRect.forget(); } -nsresult XULTreeElement::IsCellCropped(int32_t aRow, nsTreeColumn* aCol, - bool* aIsCropped) { - *aIsCropped = false; - nsTreeBodyFrame* body = GetTreeBodyFrame(); - if (body) return body->IsCellCropped(aRow, aCol, aIsCropped); - return NS_OK; -} - -bool XULTreeElement::IsCellCropped(int32_t row, nsTreeColumn* col, +bool XULTreeElement::IsCellCropped(int32_t aRow, nsTreeColumn* aCol, ErrorResult& aRv) { - bool ret; - aRv = IsCellCropped(row, col, &ret); - return ret; + bool cropped = false; + + nsTreeBodyFrame* body = GetTreeBodyFrame(); + if (body) { + aRv = body->IsCellCropped(aRow, aCol, &cropped); + } + + return cropped; } void XULTreeElement::RowCountChanged(int32_t aIndex, int32_t aDelta) { nsTreeBodyFrame* body = GetTreeBodyFrame(); - if (body) body->RowCountChanged(aIndex, aDelta); + if (body) { + body->RowCountChanged(aIndex, aDelta); + } } void XULTreeElement::BeginUpdateBatch() { nsTreeBodyFrame* body = GetTreeBodyFrame(); - if (body) body->BeginUpdateBatch(); + if (body) { + body->BeginUpdateBatch(); + } } void XULTreeElement::EndUpdateBatch() { nsTreeBodyFrame* body = GetTreeBodyFrame(); - if (body) body->EndUpdateBatch(); + if (body) { + body->EndUpdateBatch(); + } } void XULTreeElement::ClearStyleAndImageCaches() { nsTreeBodyFrame* body = GetTreeBodyFrame(); - if (body) body->ClearStyleAndImageCaches(); + if (body) { + body->ClearStyleAndImageCaches(); + } } void XULTreeElement::RemoveImageCacheEntry(int32_t aRowIndex, diff --git a/dom/xul/XULTreeElement.h b/dom/xul/XULTreeElement.h index 991fbc8ade2d..a556d01716c4 100644 --- a/dom/xul/XULTreeElement.h +++ b/dom/xul/XULTreeElement.h @@ -38,12 +38,15 @@ class XULTreeElement final : public nsXULElement { NS_DECL_ISUPPORTS_INHERITED NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULTreeElement, nsXULElement) - nsTreeBodyFrame *GetTreeBodyFrame(bool aFlushLayout = false); - nsTreeBodyFrame *GetCachedTreeBodyFrame() { return mTreeBody; } + nsTreeBodyFrame* GetTreeBodyFrame(bool aFlushLayout = false); + nsTreeBodyFrame* GetCachedTreeBodyFrame() { return mTreeBody; } already_AddRefed GetColumns(); - already_AddRefed GetView(CallerType /* unused */); + already_AddRefed GetView(CallerType /* unused */) { + return GetView(); + } + already_AddRefed GetView(); void SetView(nsITreeView* arg, CallerType aCallerType, ErrorResult& aRv); @@ -57,7 +60,7 @@ class XULTreeElement final : public nsXULElement { int32_t HorizontalPosition(); - void EnsureCellIsVisible(int32_t row, nsTreeColumn *col, ErrorResult &aRv); + void EnsureCellIsVisible(int32_t row, nsTreeColumn* col, ErrorResult& aRv); void ScrollToRow(int32_t aRow); @@ -73,42 +76,29 @@ class XULTreeElement final : public nsXULElement { int32_t GetRowAt(int32_t x, int32_t y); - void GetCellAt(int32_t x, int32_t y, TreeCellInfo &aRetVal, ErrorResult &aRv); + void GetCellAt(int32_t x, int32_t y, TreeCellInfo& aRetVal, ErrorResult& aRv); - already_AddRefed GetCoordsForCellItem(int32_t row, nsTreeColumn &col, - const nsAString &element, - ErrorResult &aRv); + nsIntRect GetCoordsForCellItem(int32_t aRow, nsTreeColumn* aCol, + const nsAString& aElement, nsresult& rv); + already_AddRefed GetCoordsForCellItem(int32_t row, nsTreeColumn& col, + const nsAString& element, + ErrorResult& aRv); - bool IsCellCropped(int32_t row, nsTreeColumn *col, ErrorResult &aRv); + bool IsCellCropped(int32_t row, nsTreeColumn* col, ErrorResult& aRv); - void RemoveImageCacheEntry(int32_t row, nsTreeColumn &col, ErrorResult &aRv); + void RemoveImageCacheEntry(int32_t row, nsTreeColumn& col, ErrorResult& aRv); void SetFocused(bool aFocused); void EnsureRowIsVisible(int32_t index); void Invalidate(void); - void InvalidateColumn(nsTreeColumn *col); + void InvalidateColumn(nsTreeColumn* col); void InvalidateRow(int32_t index); - void InvalidateCell(int32_t row, nsTreeColumn *col); + void InvalidateCell(int32_t row, nsTreeColumn* col); void InvalidateRange(int32_t startIndex, int32_t endIndex); void RowCountChanged(int32_t index, int32_t count); void BeginUpdateBatch(void); void EndUpdateBatch(void); void ClearStyleAndImageCaches(void); - nsresult GetColumns(nsTreeColumns **aColumns); - nsresult GetView(nsITreeView **aView); - nsresult SetView(nsITreeView *aView); - nsresult GetFocused(bool *aFocused); - nsresult GetTreeBody(mozilla::dom::Element **aTreeBody); - nsresult GetRowHeight(int32_t *aRowHeight); - nsresult GetRowWidth(int32_t *aRowWidth); - nsresult GetFirstVisibleRow(int32_t *_retval); - nsresult GetLastVisibleRow(int32_t *_retval); - nsresult GetCellAt(int32_t x, int32_t y, int32_t *row, nsTreeColumn **col, - nsAString &childElt); - nsresult GetCoordsForCellItem(int32_t row, nsTreeColumn *col, - const nsAString &element, int32_t *x, - int32_t *y, int32_t *width, int32_t *height); - nsresult IsCellCropped(int32_t row, nsTreeColumn *col, bool *_retval); virtual void UnbindFromTree(bool aDeep, bool aNullParent) override; virtual void DestroyContent() override; @@ -123,7 +113,7 @@ class XULTreeElement final : public nsXULElement { protected: int32_t mCachedFirstVisibleRow; - nsTreeBodyFrame *mTreeBody; + nsTreeBodyFrame* mTreeBody; nsCOMPtr mView; virtual ~XULTreeElement() {} diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp index 0a0b7b64fd4d..888d3826d352 100644 --- a/layout/base/PresShell.cpp +++ b/layout/base/PresShell.cpp @@ -7984,16 +7984,14 @@ void PresShell::GetCurrentItemAndPositionForElement( // which could provide the current focus coordinates? if (tree) { tree->EnsureRowIsVisible(currentIndex); - int32_t firstVisibleRow, rowHeight; - tree->GetFirstVisibleRow(&firstVisibleRow); - tree->GetRowHeight(&rowHeight); + int32_t firstVisibleRow = tree->GetFirstVisibleRow(); + int32_t rowHeight = tree->RowHeight(); extraTreeY += nsPresContext::CSSPixelsToAppUnits( (currentIndex - firstVisibleRow + 1) * rowHeight); istree = true; - RefPtr cols; - tree->GetColumns(getter_AddRefs(cols)); + RefPtr cols = tree->GetColumns(); if (cols) { nsTreeColumn* col = cols->GetFirstColumn(); if (col) { diff --git a/layout/xul/nsXULTooltipListener.cpp b/layout/xul/nsXULTooltipListener.cpp index c31e085c2dfa..620d09cfdaf2 100644 --- a/layout/xul/nsXULTooltipListener.cpp +++ b/layout/xul/nsXULTooltipListener.cpp @@ -33,6 +33,7 @@ #include "mozilla/dom/BoxObject.h" #include "mozilla/dom/MouseEvent.h" #include "mozilla/dom/TreeColumnBinding.h" +#include "mozilla/dom/XULTreeElementBinding.h" #include "mozilla/TextEvents.h" using namespace mozilla; @@ -337,10 +338,6 @@ void nsXULTooltipListener::CheckTreeBodyMove(MouseEvent* aMouseEvent) { int32_t x = aMouseEvent->ScreenX(CallerType::System); int32_t y = aMouseEvent->ScreenY(CallerType::System); - int32_t row; - RefPtr col; - nsAutoString obj; - // subtract off the documentElement's boxObject int32_t boxX, boxY; bx->GetScreenX(&boxX); @@ -348,7 +345,12 @@ void nsXULTooltipListener::CheckTreeBodyMove(MouseEvent* aMouseEvent) { x -= boxX; y -= boxY; - tree->GetCellAt(x, y, &row, getter_AddRefs(col), obj); + ErrorResult rv; + TreeCellInfo cellInfo; + tree->GetCellAt(x, y, cellInfo, rv); + + int32_t row = cellInfo.mRow; + RefPtr col = cellInfo.mCol; // determine if we are going to need a titletip // XXX check the disabletitletips attribute on the tree content @@ -357,9 +359,9 @@ void nsXULTooltipListener::CheckTreeBodyMove(MouseEvent* aMouseEvent) { if (col) { colType = col->Type(); } - if (row >= 0 && obj.EqualsLiteral("text") && + if (row >= 0 && cellInfo.mChildElt.EqualsLiteral("text") && colType != TreeColumn_Binding::TYPE_PASSWORD) { - tree->IsCellCropped(row, col, &mNeedTitletip); + mNeedTitletip = tree->IsCellCropped(row, col, rv); } nsCOMPtr currentTooltip = do_QueryReferent(mCurrentTooltip); @@ -435,8 +437,7 @@ nsresult nsXULTooltipListener::ShowTooltip() { #ifdef MOZ_XUL static void SetTitletipLabel(XULTreeElement* aTree, Element* aTooltip, int32_t aRow, nsTreeColumn* aCol) { - nsCOMPtr view; - aTree->GetView(getter_AddRefs(view)); + nsCOMPtr view = aTree->GetView(); if (view) { nsAutoString label; #ifdef DEBUG diff --git a/layout/xul/tree/nsTreeBodyFrame.cpp b/layout/xul/tree/nsTreeBodyFrame.cpp index 871696822283..e8ab01272f17 100644 --- a/layout/xul/tree/nsTreeBodyFrame.cpp +++ b/layout/xul/tree/nsTreeBodyFrame.cpp @@ -277,8 +277,7 @@ void nsTreeBodyFrame::EnsureView() { RefPtr tree = GetBaseElement(); if (tree) { - nsCOMPtr treeView; - tree->GetView(getter_AddRefs(treeView)); + nsCOMPtr treeView = tree->GetView(); if (treeView && weakFrame.IsAlive()) { int32_t rowIndex = tree->GetCachedTopVisibleRow(); diff --git a/layout/xul/tree/nsTreeColFrame.cpp b/layout/xul/tree/nsTreeColFrame.cpp index 9a56a96c6055..7c5d5c187180 100644 --- a/layout/xul/tree/nsTreeColFrame.cpp +++ b/layout/xul/tree/nsTreeColFrame.cpp @@ -155,7 +155,7 @@ void nsTreeColFrame::InvalidateColumns(bool aCanWalkFrameTree) { RefPtr columns; if (aCanWalkFrameTree) { - tree->GetColumns(getter_AddRefs(columns)); + columns = tree->GetColumns(); } else { nsTreeBodyFrame* body = tree->GetCachedTreeBodyFrame(); if (body) { diff --git a/layout/xul/tree/nsTreeContentView.cpp b/layout/xul/tree/nsTreeContentView.cpp index 1f029f25a13a..245b329ef9d9 100644 --- a/layout/xul/tree/nsTreeContentView.cpp +++ b/layout/xul/tree/nsTreeContentView.cpp @@ -518,8 +518,7 @@ nsTreeContentView::SetTree(XULTreeElement* aTree) { mDocument = document; } - RefPtr bodyElement; - mTree->GetTreeBody(getter_AddRefs(bodyElement)); + RefPtr bodyElement = mTree->GetTreeBody(); if (bodyElement) { mBody = bodyElement.forget(); int32_t index = 0; @@ -779,8 +778,7 @@ void nsTreeContentView::AttributeChanged(dom::Element* aElement, if (aElement->IsXULElement(nsGkAtoms::treecol)) { if (aAttribute == nsGkAtoms::properties) { if (mTree) { - RefPtr cols; - mTree->GetColumns(getter_AddRefs(cols)); + RefPtr cols = mTree->GetColumns(); if (cols) { RefPtr col = cols->GetColumnFor(aElement); mTree->InvalidateColumn(col); diff --git a/layout/xul/tree/nsTreeSelection.cpp b/layout/xul/tree/nsTreeSelection.cpp index 167222d9425c..25382d46db42 100644 --- a/layout/xul/tree/nsTreeSelection.cpp +++ b/layout/xul/tree/nsTreeSelection.cpp @@ -466,8 +466,7 @@ NS_IMETHODIMP nsTreeSelection::InvertSelection() { NS_IMETHODIMP nsTreeSelection::SelectAll() { if (!mTree) return NS_OK; - nsCOMPtr view; - mTree->GetView(getter_AddRefs(view)); + nsCOMPtr view = mTree->GetView(); if (!view) return NS_OK; int32_t rowCount;