LCOV - code coverage report
Current view: top level - layout/xul/tree - TreeBoxObject.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 374 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 70 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #include "mozilla/dom/TreeBoxObject.h"
       7             : #include "nsCOMPtr.h"
       8             : #include "nsXULElement.h"
       9             : #include "nsIScriptableRegion.h"
      10             : #include "nsIXULTemplateBuilder.h"
      11             : #include "nsTreeContentView.h"
      12             : #include "nsITreeSelection.h"
      13             : #include "ChildIterator.h"
      14             : #include "nsContentUtils.h"
      15             : #include "nsError.h"
      16             : #include "nsTreeBodyFrame.h"
      17             : #include "mozilla/dom/TreeBoxObjectBinding.h"
      18             : #include "nsITreeColumns.h"
      19             : #include "mozilla/dom/DOMRect.h"
      20             : #include "mozilla/dom/BindingUtils.h"
      21             : #include "mozilla/dom/Element.h"
      22             : #include "mozilla/dom/ToJSValue.h"
      23             : 
      24             : namespace mozilla {
      25             : namespace dom {
      26             : 
      27           0 : NS_IMPL_CYCLE_COLLECTION_INHERITED(TreeBoxObject, BoxObject,
      28             :                                    mView)
      29             : 
      30           0 : NS_IMPL_ADDREF_INHERITED(TreeBoxObject, BoxObject)
      31           0 : NS_IMPL_RELEASE_INHERITED(TreeBoxObject, BoxObject)
      32             : 
      33           0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(TreeBoxObject)
      34           0 :   NS_INTERFACE_MAP_ENTRY(nsITreeBoxObject)
      35           0 : NS_INTERFACE_MAP_END_INHERITING(BoxObject)
      36             : 
      37             : void
      38           0 : TreeBoxObject::Clear()
      39             : {
      40           0 :   ClearCachedValues();
      41             : 
      42             :   // Drop the view's ref to us.
      43           0 :   if (mView) {
      44           0 :     nsCOMPtr<nsITreeSelection> sel;
      45           0 :     mView->GetSelection(getter_AddRefs(sel));
      46           0 :     if (sel)
      47           0 :       sel->SetTree(nullptr);
      48           0 :     mView->SetTree(nullptr); // Break the circular ref between the view and us.
      49             :   }
      50           0 :   mView = nullptr;
      51             : 
      52           0 :   BoxObject::Clear();
      53           0 : }
      54             : 
      55             : 
      56           0 : TreeBoxObject::TreeBoxObject()
      57           0 :   : mTreeBody(nullptr)
      58             : {
      59           0 : }
      60             : 
      61           0 : TreeBoxObject::~TreeBoxObject()
      62             : {
      63           0 : }
      64             : 
      65           0 : static nsIContent* FindBodyElement(nsIContent* aParent)
      66             : {
      67           0 :   mozilla::dom::FlattenedChildIterator iter(aParent);
      68           0 :   for (nsIContent* content = iter.GetNextChild(); content; content = iter.GetNextChild()) {
      69           0 :     mozilla::dom::NodeInfo *ni = content->NodeInfo();
      70           0 :     if (ni->Equals(nsGkAtoms::treechildren, kNameSpaceID_XUL)) {
      71           0 :       return content;
      72           0 :     } else if (ni->Equals(nsGkAtoms::tree, kNameSpaceID_XUL)) {
      73             :       // There are nesting tree elements. Only the innermost should
      74             :       // find the treechilren.
      75           0 :       return nullptr;
      76           0 :     } else if (content->IsElement() &&
      77           0 :                !ni->Equals(nsGkAtoms::_template, kNameSpaceID_XUL)) {
      78           0 :       nsIContent* result = FindBodyElement(content);
      79           0 :       if (result)
      80           0 :         return result;
      81             :     }
      82             :   }
      83             : 
      84           0 :   return nullptr;
      85             : }
      86             : 
      87             : nsTreeBodyFrame*
      88           0 : TreeBoxObject::GetTreeBodyFrame(bool aFlushLayout)
      89             : {
      90             :   // Make sure our frames are up to date, and layout as needed.  We
      91             :   // have to do this before checking for our cached mTreeBody, since
      92             :   // it might go away on style flush, and in any case if aFlushLayout
      93             :   // is true we need to make sure to flush no matter what.
      94             :   // XXXbz except that flushing style when we were not asked to flush
      95             :   // layout here breaks things.  See bug 585123.
      96           0 :   nsIFrame* frame = nullptr;
      97           0 :   if (aFlushLayout) {
      98           0 :     frame = GetFrame(aFlushLayout);
      99           0 :     if (!frame)
     100           0 :       return nullptr;
     101             :   }
     102             : 
     103           0 :   if (mTreeBody) {
     104             :     // Have one cached already.
     105           0 :     return mTreeBody;
     106             :   }
     107             : 
     108           0 :   if (!aFlushLayout) {
     109           0 :     frame = GetFrame(aFlushLayout);
     110           0 :     if (!frame)
     111           0 :       return nullptr;
     112             :   }
     113             : 
     114             :   // Iterate over our content model children looking for the body.
     115           0 :   nsCOMPtr<nsIContent> content = FindBodyElement(frame->GetContent());
     116           0 :   if (!content)
     117           0 :     return nullptr;
     118             : 
     119           0 :   frame = content->GetPrimaryFrame();
     120           0 :   if (!frame)
     121           0 :      return nullptr;
     122             : 
     123             :   // Make sure that the treebodyframe has a pointer to |this|.
     124           0 :   nsTreeBodyFrame *treeBody = do_QueryFrame(frame);
     125           0 :   NS_ENSURE_TRUE(treeBody && treeBody->GetTreeBoxObject() == this, nullptr);
     126             : 
     127           0 :   mTreeBody = treeBody;
     128           0 :   return mTreeBody;
     129             : }
     130             : 
     131             : NS_IMETHODIMP
     132           0 : TreeBoxObject::GetView(nsITreeView * *aView)
     133             : {
     134           0 :   if (!mTreeBody) {
     135           0 :     if (!GetTreeBodyFrame()) {
     136             :       // Don't return an uninitialised view
     137           0 :       *aView = nullptr;
     138           0 :       return NS_OK;
     139             :     }
     140             : 
     141           0 :     if (mView)
     142             :       // Our new frame needs to initialise itself
     143           0 :       return mTreeBody->GetView(aView);
     144             :   }
     145           0 :   if (!mView) {
     146           0 :     RefPtr<nsXULElement> xulele = nsXULElement::FromContentOrNull(mContent);
     147           0 :     if (xulele) {
     148             :       // See if there is a XUL tree builder associated with the element
     149           0 :       nsCOMPtr<nsIXULTemplateBuilder> builder = xulele->GetBuilder();
     150           0 :       mView = do_QueryInterface(builder);
     151             : 
     152           0 :       if (!mView) {
     153             :         // No tree builder, create a tree content view.
     154           0 :         nsresult rv = NS_NewTreeContentView(getter_AddRefs(mView));
     155           0 :         NS_ENSURE_SUCCESS(rv, rv);
     156             :       }
     157             : 
     158             :       // Initialise the frame and view
     159           0 :       mTreeBody->SetView(mView);
     160             :     }
     161             :   }
     162           0 :   NS_IF_ADDREF(*aView = mView);
     163           0 :   return NS_OK;
     164             : }
     165             : 
     166             : already_AddRefed<nsITreeView>
     167           0 : TreeBoxObject::GetView() {
     168           0 :   nsCOMPtr<nsITreeView> view;
     169           0 :   GetView(getter_AddRefs(view));
     170           0 :   return view.forget();
     171             : }
     172             : 
     173             : static bool
     174           0 : CanTrustView(nsISupports* aValue)
     175             : {
     176             :   // Untrusted content is only allowed to specify known-good views
     177           0 :   if (nsContentUtils::IsCallerChrome())
     178           0 :     return true;
     179           0 :   nsCOMPtr<nsINativeTreeView> nativeTreeView = do_QueryInterface(aValue);
     180           0 :   if (!nativeTreeView || NS_FAILED(nativeTreeView->EnsureNative())) {
     181             :     // XXX ERRMSG need a good error here for developers
     182           0 :     return false;
     183             :   }
     184           0 :   return true;
     185             : }
     186             : 
     187           0 : NS_IMETHODIMP TreeBoxObject::SetView(nsITreeView * aView)
     188             : {
     189           0 :   if (!CanTrustView(aView))
     190           0 :     return NS_ERROR_DOM_SECURITY_ERR;
     191             : 
     192           0 :   mView = aView;
     193           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     194           0 :   if (body)
     195           0 :     body->SetView(aView);
     196             : 
     197           0 :   return NS_OK;
     198             : }
     199             : 
     200           0 : void TreeBoxObject::SetView(nsITreeView* aView, ErrorResult& aRv)
     201             : {
     202           0 :   aRv = SetView(aView);
     203           0 : }
     204             : 
     205           0 : bool TreeBoxObject::Focused()
     206             : {
     207           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     208           0 :   if (body)
     209           0 :     return body->GetFocused();
     210           0 :   return false;
     211             : }
     212             : 
     213           0 : NS_IMETHODIMP TreeBoxObject::GetFocused(bool* aFocused)
     214             : {
     215           0 :   *aFocused = Focused();
     216           0 :   return NS_OK;
     217             : }
     218             : 
     219           0 : NS_IMETHODIMP TreeBoxObject::SetFocused(bool aFocused)
     220             : {
     221           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     222           0 :   if (body)
     223           0 :     return body->SetFocused(aFocused);
     224           0 :   return NS_OK;
     225             : }
     226             : 
     227           0 : NS_IMETHODIMP TreeBoxObject::GetTreeBody(nsIDOMElement** aElement)
     228             : {
     229           0 :   *aElement = nullptr;
     230           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     231           0 :   if (body)
     232           0 :     return body->GetTreeBody(aElement);
     233           0 :   return NS_OK;
     234             : }
     235             : 
     236             : already_AddRefed<Element>
     237           0 : TreeBoxObject::GetTreeBody()
     238             : {
     239           0 :   nsCOMPtr<nsIDOMElement> el;
     240           0 :   GetTreeBody(getter_AddRefs(el));
     241           0 :   nsCOMPtr<Element> ret(do_QueryInterface(el));
     242           0 :   return ret.forget();
     243             : }
     244             : 
     245             : already_AddRefed<nsTreeColumns>
     246           0 : TreeBoxObject::GetColumns()
     247             : {
     248           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     249           0 :   if (body)
     250           0 :     return body->Columns();
     251           0 :   return nullptr;
     252             : }
     253             : 
     254           0 : NS_IMETHODIMP TreeBoxObject::GetColumns(nsITreeColumns** aColumns)
     255             : {
     256           0 :   *aColumns = GetColumns().take();
     257           0 :   return NS_OK;
     258             : }
     259             : 
     260           0 : int32_t TreeBoxObject::RowHeight()
     261             : {
     262           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     263           0 :   if (body)
     264           0 :     return body->RowHeight();
     265           0 :   return 0;
     266             : }
     267             : 
     268           0 : int32_t TreeBoxObject::RowWidth()
     269             : {
     270           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     271           0 :   if (body)
     272           0 :     return body->RowWidth();
     273           0 :   return 0;
     274             : }
     275             : 
     276           0 : NS_IMETHODIMP TreeBoxObject::GetRowHeight(int32_t* aRowHeight)
     277             : {
     278           0 :   *aRowHeight = RowHeight();
     279           0 :   return NS_OK;
     280             : }
     281             : 
     282           0 : NS_IMETHODIMP TreeBoxObject::GetRowWidth(int32_t *aRowWidth)
     283             : {
     284           0 :   *aRowWidth = RowWidth();
     285           0 :   return NS_OK;
     286             : }
     287             : 
     288           0 : int32_t TreeBoxObject::GetFirstVisibleRow()
     289             : {
     290           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     291           0 :   if (body)
     292           0 :     return body->FirstVisibleRow();
     293           0 :   return 0;
     294             : }
     295             : 
     296           0 : NS_IMETHODIMP TreeBoxObject::GetFirstVisibleRow(int32_t *aFirstVisibleRow)
     297             : {
     298           0 :   *aFirstVisibleRow = GetFirstVisibleRow();
     299           0 :   return NS_OK;
     300             : }
     301             : 
     302           0 : int32_t TreeBoxObject::GetLastVisibleRow()
     303             : {
     304           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     305           0 :   if (body)
     306           0 :     return body->LastVisibleRow();
     307           0 :   return 0;
     308             : }
     309             : 
     310           0 : NS_IMETHODIMP TreeBoxObject::GetLastVisibleRow(int32_t *aLastVisibleRow)
     311             : {
     312           0 :   *aLastVisibleRow = GetLastVisibleRow();
     313           0 :   return NS_OK;
     314             : }
     315             : 
     316           0 : int32_t TreeBoxObject::HorizontalPosition()
     317             : {
     318           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     319           0 :   if (body)
     320           0 :     return body->GetHorizontalPosition();
     321           0 :   return 0;
     322             : }
     323             : 
     324           0 : NS_IMETHODIMP TreeBoxObject::GetHorizontalPosition(int32_t *aHorizontalPosition)
     325             : {
     326           0 :   *aHorizontalPosition = HorizontalPosition();
     327           0 :   return NS_OK;
     328             : }
     329             : 
     330           0 : int32_t TreeBoxObject::GetPageLength()
     331             : {
     332           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     333           0 :   if (body)
     334           0 :     return body->PageLength();
     335           0 :   return 0;
     336             : }
     337             : 
     338           0 : NS_IMETHODIMP TreeBoxObject::GetPageLength(int32_t *aPageLength)
     339             : {
     340           0 :   *aPageLength = GetPageLength();
     341           0 :   return NS_OK;
     342             : }
     343             : 
     344           0 : NS_IMETHODIMP TreeBoxObject::GetSelectionRegion(nsIScriptableRegion **aRegion)
     345             : {
     346           0 :   *aRegion = nullptr;
     347           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     348           0 :   if (body)
     349           0 :     return body->GetSelectionRegion(aRegion);
     350           0 :   return NS_OK;
     351             : }
     352             : 
     353             : already_AddRefed<nsIScriptableRegion>
     354           0 : TreeBoxObject::SelectionRegion()
     355             : {
     356           0 :   nsCOMPtr<nsIScriptableRegion> region;
     357           0 :   GetSelectionRegion(getter_AddRefs(region));
     358           0 :   return region.forget();
     359             : }
     360             : 
     361             : NS_IMETHODIMP
     362           0 : TreeBoxObject::EnsureRowIsVisible(int32_t aRow)
     363             : {
     364           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     365           0 :   if (body)
     366           0 :     return body->EnsureRowIsVisible(aRow);
     367           0 :   return NS_OK;
     368             : }
     369             : 
     370             : NS_IMETHODIMP
     371           0 : TreeBoxObject::EnsureCellIsVisible(int32_t aRow, nsITreeColumn* aCol)
     372             : {
     373           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     374           0 :   if (body)
     375           0 :     return body->EnsureCellIsVisible(aRow, aCol);
     376           0 :   return NS_OK;
     377             : }
     378             : 
     379             : NS_IMETHODIMP
     380           0 : TreeBoxObject::ScrollToRow(int32_t aRow)
     381             : {
     382           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame(true);
     383           0 :   if (body)
     384           0 :     return body->ScrollToRow(aRow);
     385           0 :   return NS_OK;
     386             : }
     387             : 
     388             : NS_IMETHODIMP
     389           0 : TreeBoxObject::ScrollByLines(int32_t aNumLines)
     390             : {
     391           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     392           0 :   if (body)
     393           0 :     return body->ScrollByLines(aNumLines);
     394           0 :   return NS_OK;
     395             : }
     396             : 
     397             : NS_IMETHODIMP
     398           0 : TreeBoxObject::ScrollByPages(int32_t aNumPages)
     399             : {
     400           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     401           0 :   if (body)
     402           0 :     return body->ScrollByPages(aNumPages);
     403           0 :   return NS_OK;
     404             : }
     405             : 
     406             : NS_IMETHODIMP
     407           0 : TreeBoxObject::ScrollToCell(int32_t aRow, nsITreeColumn* aCol)
     408             : {
     409           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     410           0 :   if (body)
     411           0 :     return body->ScrollToCell(aRow, aCol);
     412           0 :   return NS_OK;
     413             : }
     414             : 
     415             : NS_IMETHODIMP
     416           0 : TreeBoxObject::ScrollToColumn(nsITreeColumn* aCol)
     417             : {
     418           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     419           0 :   if (body)
     420           0 :     return body->ScrollToColumn(aCol);
     421           0 :   return NS_OK;
     422             : }
     423             : 
     424             : NS_IMETHODIMP
     425           0 : TreeBoxObject::ScrollToHorizontalPosition(int32_t aHorizontalPosition)
     426             : {
     427           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     428           0 :   if (body)
     429           0 :     return body->ScrollToHorizontalPosition(aHorizontalPosition);
     430           0 :   return NS_OK;
     431             : }
     432             : 
     433           0 : NS_IMETHODIMP TreeBoxObject::Invalidate()
     434             : {
     435           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     436           0 :   if (body)
     437           0 :     return body->Invalidate();
     438           0 :   return NS_OK;
     439             : }
     440             : 
     441             : NS_IMETHODIMP
     442           0 : TreeBoxObject::InvalidateColumn(nsITreeColumn* aCol)
     443             : {
     444           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     445           0 :   if (body)
     446           0 :     return body->InvalidateColumn(aCol);
     447           0 :   return NS_OK;
     448             : }
     449             : 
     450             : NS_IMETHODIMP
     451           0 : TreeBoxObject::InvalidateRow(int32_t aIndex)
     452             : {
     453           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     454           0 :   if (body)
     455           0 :     return body->InvalidateRow(aIndex);
     456           0 :   return NS_OK;
     457             : }
     458             : 
     459             : NS_IMETHODIMP
     460           0 : TreeBoxObject::InvalidateCell(int32_t aRow, nsITreeColumn* aCol)
     461             : {
     462           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     463           0 :   if (body)
     464           0 :     return body->InvalidateCell(aRow, aCol);
     465           0 :   return NS_OK;
     466             : }
     467             : 
     468             : NS_IMETHODIMP
     469           0 : TreeBoxObject::InvalidateRange(int32_t aStart, int32_t aEnd)
     470             : {
     471           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     472           0 :   if (body)
     473           0 :     return body->InvalidateRange(aStart, aEnd);
     474           0 :   return NS_OK;
     475             : }
     476             : 
     477             : NS_IMETHODIMP
     478           0 : TreeBoxObject::InvalidateColumnRange(int32_t aStart, int32_t aEnd, nsITreeColumn* aCol)
     479             : {
     480           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     481           0 :   if (body)
     482           0 :     return body->InvalidateColumnRange(aStart, aEnd, aCol);
     483           0 :   return NS_OK;
     484             : }
     485             : 
     486             : NS_IMETHODIMP
     487           0 : TreeBoxObject::GetRowAt(int32_t x, int32_t y, int32_t *aRow)
     488             : {
     489           0 :   *aRow = 0;
     490           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     491           0 :   if (body)
     492           0 :     return body->GetRowAt(x, y, aRow);
     493           0 :   return NS_OK;
     494             : }
     495             : 
     496             : int32_t
     497           0 : TreeBoxObject::GetRowAt(int32_t x, int32_t y)
     498             : {
     499             :   int32_t row;
     500           0 :   GetRowAt(x, y, &row);
     501           0 :   return row;
     502             : }
     503             : 
     504             : NS_IMETHODIMP
     505           0 : TreeBoxObject::GetCellAt(int32_t aX, int32_t aY, int32_t *aRow,
     506             :                          nsITreeColumn** aCol, nsAString& aChildElt)
     507             : {
     508           0 :   *aRow = 0;
     509           0 :   *aCol = nullptr;
     510           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     511           0 :   if (body) {
     512           0 :     nsAutoCString element;
     513           0 :     nsresult retval = body->GetCellAt(aX, aY, aRow, aCol, element);
     514           0 :     CopyUTF8toUTF16(element, aChildElt);
     515           0 :     return retval;
     516             :   }
     517           0 :   return NS_OK;
     518             : }
     519             : 
     520             : void
     521           0 : TreeBoxObject::GetCellAt(int32_t x, int32_t y, TreeCellInfo& aRetVal, ErrorResult& aRv)
     522             : {
     523           0 :   nsCOMPtr<nsITreeColumn> col;
     524           0 :   GetCellAt(x, y, &aRetVal.mRow, getter_AddRefs(col), aRetVal.mChildElt);
     525           0 :   aRetVal.mCol = col.forget().downcast<nsTreeColumn>();
     526           0 : }
     527             : 
     528             : void
     529           0 : TreeBoxObject::GetCellAt(JSContext* cx,
     530             :                          int32_t x, int32_t y,
     531             :                          JS::Handle<JSObject*> rowOut,
     532             :                          JS::Handle<JSObject*> colOut,
     533             :                          JS::Handle<JSObject*> childEltOut,
     534             :                          ErrorResult& aRv)
     535             : {
     536             :   int32_t row;
     537             :   nsITreeColumn* col;
     538           0 :   nsAutoString childElt;
     539           0 :   GetCellAt(x, y, &row, &col, childElt);
     540             : 
     541           0 :   JS::Rooted<JS::Value> v(cx);
     542             : 
     543           0 :   if (!ToJSValue(cx, row, &v) ||
     544           0 :       !JS_SetProperty(cx, rowOut, "value", v)) {
     545           0 :     aRv.Throw(NS_ERROR_XPC_CANT_SET_OUT_VAL);
     546           0 :     return;
     547             :   }
     548           0 :   if (!dom::WrapObject(cx, col, &v) ||
     549           0 :       !JS_SetProperty(cx, colOut, "value", v)) {
     550           0 :     aRv.Throw(NS_ERROR_XPC_CANT_SET_OUT_VAL);
     551           0 :     return;
     552             :   }
     553           0 :   if (!ToJSValue(cx, childElt, &v) ||
     554           0 :       !JS_SetProperty(cx, childEltOut, "value", v)) {
     555           0 :     aRv.Throw(NS_ERROR_XPC_CANT_SET_OUT_VAL);
     556           0 :     return;
     557             :   }
     558             : }
     559             : 
     560             : NS_IMETHODIMP
     561           0 : TreeBoxObject::GetCoordsForCellItem(int32_t aRow, nsITreeColumn* aCol, const nsAString& aElement,
     562             :                                       int32_t *aX, int32_t *aY, int32_t *aWidth, int32_t *aHeight)
     563             : {
     564           0 :   *aX = *aY = *aWidth = *aHeight = 0;
     565           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     566           0 :   NS_ConvertUTF16toUTF8 element(aElement);
     567           0 :   if (body)
     568           0 :     return body->GetCoordsForCellItem(aRow, aCol, element, aX, aY, aWidth, aHeight);
     569           0 :   return NS_OK;
     570             : }
     571             : 
     572             : already_AddRefed<DOMRect>
     573           0 : TreeBoxObject::GetCoordsForCellItem(int32_t row, nsTreeColumn& col, const nsAString& element, ErrorResult& aRv)
     574             : {
     575             :   int32_t x, y, w, h;
     576           0 :   GetCoordsForCellItem(row, &col, element, &x, &y, &w, &h);
     577           0 :   RefPtr<DOMRect> rect = new DOMRect(mContent, x, y, w, h);
     578           0 :   return rect.forget();
     579             : }
     580             : 
     581             : void
     582           0 : TreeBoxObject::GetCoordsForCellItem(JSContext* cx,
     583             :                                     int32_t row,
     584             :                                     nsTreeColumn& col,
     585             :                                     const nsAString& element,
     586             :                                     JS::Handle<JSObject*> xOut,
     587             :                                     JS::Handle<JSObject*> yOut,
     588             :                                     JS::Handle<JSObject*> widthOut,
     589             :                                     JS::Handle<JSObject*> heightOut,
     590             :                                     ErrorResult& aRv)
     591             : {
     592             :   int32_t x, y, w, h;
     593           0 :   GetCoordsForCellItem(row, &col, element, &x, &y, &w, &h);
     594           0 :   JS::Rooted<JS::Value> v(cx, JS::Int32Value(x));
     595           0 :   if (!JS_SetProperty(cx, xOut, "value", v)) {
     596           0 :     aRv.Throw(NS_ERROR_XPC_CANT_SET_OUT_VAL);
     597           0 :     return;
     598             :   }
     599           0 :   v.setInt32(y);
     600           0 :   if (!JS_SetProperty(cx, yOut, "value", v)) {
     601           0 :     aRv.Throw(NS_ERROR_XPC_CANT_SET_OUT_VAL);
     602           0 :     return;
     603             :   }
     604           0 :   v.setInt32(w);
     605           0 :   if (!JS_SetProperty(cx, widthOut, "value", v)) {
     606           0 :     aRv.Throw(NS_ERROR_XPC_CANT_SET_OUT_VAL);
     607           0 :     return;
     608             :   }
     609           0 :   v.setInt32(h);
     610           0 :   if (!JS_SetProperty(cx, heightOut, "value", v)) {
     611           0 :     aRv.Throw(NS_ERROR_XPC_CANT_SET_OUT_VAL);
     612           0 :     return;
     613             :   }
     614             : }
     615             : 
     616             : NS_IMETHODIMP
     617           0 : TreeBoxObject::IsCellCropped(int32_t aRow, nsITreeColumn* aCol, bool *aIsCropped)
     618             : {
     619           0 :   *aIsCropped = false;
     620           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     621           0 :   if (body)
     622           0 :     return body->IsCellCropped(aRow, aCol, aIsCropped);
     623           0 :   return NS_OK;
     624             : }
     625             : 
     626             : bool
     627           0 : TreeBoxObject::IsCellCropped(int32_t row, nsITreeColumn* col, ErrorResult& aRv)
     628             : {
     629             :   bool ret;
     630           0 :   aRv = IsCellCropped(row, col, &ret);
     631           0 :   return ret;
     632             : }
     633             : 
     634             : NS_IMETHODIMP
     635           0 : TreeBoxObject::RowCountChanged(int32_t aIndex, int32_t aDelta)
     636             : {
     637           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     638           0 :   if (body)
     639           0 :     return body->RowCountChanged(aIndex, aDelta);
     640           0 :   return NS_OK;
     641             : }
     642             : 
     643             : NS_IMETHODIMP
     644           0 : TreeBoxObject::BeginUpdateBatch()
     645             : {
     646           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     647           0 :   if (body)
     648           0 :     return body->BeginUpdateBatch();
     649           0 :   return NS_OK;
     650             : }
     651             : 
     652             : NS_IMETHODIMP
     653           0 : TreeBoxObject::EndUpdateBatch()
     654             : {
     655           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     656           0 :   if (body)
     657           0 :     return body->EndUpdateBatch();
     658           0 :   return NS_OK;
     659             : }
     660             : 
     661             : NS_IMETHODIMP
     662           0 : TreeBoxObject::ClearStyleAndImageCaches()
     663             : {
     664           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     665           0 :   if (body)
     666           0 :     return body->ClearStyleAndImageCaches();
     667           0 :   return NS_OK;
     668             : }
     669             : 
     670             : NS_IMETHODIMP
     671           0 : TreeBoxObject::RemoveImageCacheEntry(int32_t aRowIndex, nsITreeColumn* aCol)
     672             : {
     673           0 :   NS_ENSURE_ARG(aCol);
     674           0 :   NS_ENSURE_TRUE(aRowIndex >= 0, NS_ERROR_INVALID_ARG);
     675           0 :   nsTreeBodyFrame* body = GetTreeBodyFrame();
     676           0 :   if (body) {
     677           0 :     return body->RemoveImageCacheEntry(aRowIndex, aCol);
     678             :   }
     679           0 :   return NS_OK;
     680             : }
     681             : 
     682             : void
     683           0 : TreeBoxObject::RemoveImageCacheEntry(int32_t row, nsITreeColumn& col, ErrorResult& aRv)
     684             : {
     685           0 :   aRv = RemoveImageCacheEntry(row, &col);
     686           0 : }
     687             : 
     688             : void
     689           0 : TreeBoxObject::ClearCachedValues()
     690             : {
     691           0 :   mTreeBody = nullptr;
     692           0 : }
     693             : 
     694             : JSObject*
     695           0 : TreeBoxObject::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
     696             : {
     697           0 :   return TreeBoxObjectBinding::Wrap(aCx, this, aGivenProto);
     698             : }
     699             : 
     700             : } // namespace dom
     701             : } // namespace mozilla
     702             : 
     703             : // Creation Routine ///////////////////////////////////////////////////////////////////////
     704             : 
     705             : using namespace mozilla::dom;
     706             : 
     707             : nsresult
     708           0 : NS_NewTreeBoxObject(nsIBoxObject** aResult)
     709             : {
     710           0 :   NS_ADDREF(*aResult = new TreeBoxObject());
     711           0 :   return NS_OK;
     712             : }

Generated by: LCOV version 1.13