layout/xul/nsListBoxObject.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 "nsPIListBoxObject.h"
michael@0 8 #include "nsBoxObject.h"
michael@0 9 #include "nsIFrame.h"
michael@0 10 #include "nsBindingManager.h"
michael@0 11 #include "nsIDOMElement.h"
michael@0 12 #include "nsIDOMNodeList.h"
michael@0 13 #include "nsGkAtoms.h"
michael@0 14 #include "nsIScrollableFrame.h"
michael@0 15 #include "nsListBoxBodyFrame.h"
michael@0 16 #include "ChildIterator.h"
michael@0 17
michael@0 18 class nsListBoxObject : public nsPIListBoxObject, public nsBoxObject
michael@0 19 {
michael@0 20 public:
michael@0 21 NS_DECL_ISUPPORTS_INHERITED
michael@0 22 NS_DECL_NSILISTBOXOBJECT
michael@0 23
michael@0 24 // nsPIListBoxObject
michael@0 25 virtual nsListBoxBodyFrame* GetListBoxBody(bool aFlush) MOZ_OVERRIDE;
michael@0 26
michael@0 27 nsListBoxObject();
michael@0 28
michael@0 29 // nsPIBoxObject
michael@0 30 virtual void Clear() MOZ_OVERRIDE;
michael@0 31 virtual void ClearCachedValues() MOZ_OVERRIDE;
michael@0 32
michael@0 33 protected:
michael@0 34 nsListBoxBodyFrame *mListBoxBody;
michael@0 35 };
michael@0 36
michael@0 37 NS_IMPL_ISUPPORTS_INHERITED(nsListBoxObject, nsBoxObject, nsIListBoxObject,
michael@0 38 nsPIListBoxObject)
michael@0 39
michael@0 40 nsListBoxObject::nsListBoxObject()
michael@0 41 : mListBoxBody(nullptr)
michael@0 42 {
michael@0 43 }
michael@0 44
michael@0 45 //////////////////////////////////////////////////////////////////////////
michael@0 46 //// nsIListBoxObject
michael@0 47
michael@0 48 NS_IMETHODIMP
michael@0 49 nsListBoxObject::GetRowCount(int32_t *aResult)
michael@0 50 {
michael@0 51 nsListBoxBodyFrame* body = GetListBoxBody(true);
michael@0 52 if (body)
michael@0 53 return body->GetRowCount(aResult);
michael@0 54 return NS_OK;
michael@0 55 }
michael@0 56
michael@0 57 NS_IMETHODIMP
michael@0 58 nsListBoxObject::GetNumberOfVisibleRows(int32_t *aResult)
michael@0 59 {
michael@0 60 nsListBoxBodyFrame* body = GetListBoxBody(true);
michael@0 61 if (body)
michael@0 62 return body->GetNumberOfVisibleRows(aResult);
michael@0 63 return NS_OK;
michael@0 64 }
michael@0 65
michael@0 66 NS_IMETHODIMP
michael@0 67 nsListBoxObject::GetIndexOfFirstVisibleRow(int32_t *aResult)
michael@0 68 {
michael@0 69 nsListBoxBodyFrame* body = GetListBoxBody(true);
michael@0 70 if (body)
michael@0 71 return body->GetIndexOfFirstVisibleRow(aResult);
michael@0 72 return NS_OK;
michael@0 73 }
michael@0 74
michael@0 75 NS_IMETHODIMP nsListBoxObject::EnsureIndexIsVisible(int32_t aRowIndex)
michael@0 76 {
michael@0 77 nsListBoxBodyFrame* body = GetListBoxBody(true);
michael@0 78 if (body)
michael@0 79 return body->EnsureIndexIsVisible(aRowIndex);
michael@0 80 return NS_OK;
michael@0 81 }
michael@0 82
michael@0 83 NS_IMETHODIMP
michael@0 84 nsListBoxObject::ScrollToIndex(int32_t aRowIndex)
michael@0 85 {
michael@0 86 nsListBoxBodyFrame* body = GetListBoxBody(true);
michael@0 87 if (body)
michael@0 88 return body->ScrollToIndex(aRowIndex);
michael@0 89 return NS_OK;
michael@0 90 }
michael@0 91
michael@0 92 NS_IMETHODIMP
michael@0 93 nsListBoxObject::ScrollByLines(int32_t aNumLines)
michael@0 94 {
michael@0 95 nsListBoxBodyFrame* body = GetListBoxBody(true);
michael@0 96 if (body)
michael@0 97 return body->ScrollByLines(aNumLines);
michael@0 98 return NS_OK;
michael@0 99 }
michael@0 100
michael@0 101 NS_IMETHODIMP
michael@0 102 nsListBoxObject::GetItemAtIndex(int32_t index, nsIDOMElement **_retval)
michael@0 103 {
michael@0 104 nsListBoxBodyFrame* body = GetListBoxBody(true);
michael@0 105 if (body)
michael@0 106 return body->GetItemAtIndex(index, _retval);
michael@0 107 return NS_OK;
michael@0 108 }
michael@0 109
michael@0 110 NS_IMETHODIMP
michael@0 111 nsListBoxObject::GetIndexOfItem(nsIDOMElement* aElement, int32_t *aResult)
michael@0 112 {
michael@0 113 *aResult = 0;
michael@0 114
michael@0 115 nsListBoxBodyFrame* body = GetListBoxBody(true);
michael@0 116 if (body)
michael@0 117 return body->GetIndexOfItem(aElement, aResult);
michael@0 118 return NS_OK;
michael@0 119 }
michael@0 120
michael@0 121 //////////////////////
michael@0 122
michael@0 123 static nsIContent*
michael@0 124 FindBodyContent(nsIContent* aParent)
michael@0 125 {
michael@0 126 if (aParent->Tag() == nsGkAtoms::listboxbody) {
michael@0 127 return aParent;
michael@0 128 }
michael@0 129
michael@0 130 mozilla::dom::FlattenedChildIterator iter(aParent);
michael@0 131 for (nsIContent* child = iter.GetNextChild(); child; child = iter.GetNextChild()) {
michael@0 132 nsIContent* result = FindBodyContent(child);
michael@0 133 if (result) {
michael@0 134 return result;
michael@0 135 }
michael@0 136 }
michael@0 137
michael@0 138 return nullptr;
michael@0 139 }
michael@0 140
michael@0 141 nsListBoxBodyFrame*
michael@0 142 nsListBoxObject::GetListBoxBody(bool aFlush)
michael@0 143 {
michael@0 144 if (mListBoxBody) {
michael@0 145 return mListBoxBody;
michael@0 146 }
michael@0 147
michael@0 148 nsIPresShell* shell = GetPresShell(false);
michael@0 149 if (!shell) {
michael@0 150 return nullptr;
michael@0 151 }
michael@0 152
michael@0 153 nsIFrame* frame = aFlush ?
michael@0 154 GetFrame(false) /* does Flush_Frames */ :
michael@0 155 mContent->GetPrimaryFrame();
michael@0 156 if (!frame)
michael@0 157 return nullptr;
michael@0 158
michael@0 159 // Iterate over our content model children looking for the body.
michael@0 160 nsCOMPtr<nsIContent> content = FindBodyContent(frame->GetContent());
michael@0 161
michael@0 162 if (!content)
michael@0 163 return nullptr;
michael@0 164
michael@0 165 // this frame will be a nsGFXScrollFrame
michael@0 166 frame = content->GetPrimaryFrame();
michael@0 167 if (!frame)
michael@0 168 return nullptr;
michael@0 169 nsIScrollableFrame* scrollFrame = do_QueryFrame(frame);
michael@0 170 if (!scrollFrame)
michael@0 171 return nullptr;
michael@0 172
michael@0 173 // this frame will be the one we want
michael@0 174 nsIFrame* yeahBaby = scrollFrame->GetScrolledFrame();
michael@0 175 if (!yeahBaby)
michael@0 176 return nullptr;
michael@0 177
michael@0 178 // It's a frame. Refcounts are irrelevant.
michael@0 179 nsListBoxBodyFrame* listBoxBody = do_QueryFrame(yeahBaby);
michael@0 180 NS_ENSURE_TRUE(listBoxBody &&
michael@0 181 listBoxBody->SetBoxObject(this),
michael@0 182 nullptr);
michael@0 183 mListBoxBody = listBoxBody;
michael@0 184 return mListBoxBody;
michael@0 185 }
michael@0 186
michael@0 187 void
michael@0 188 nsListBoxObject::Clear()
michael@0 189 {
michael@0 190 ClearCachedValues();
michael@0 191
michael@0 192 nsBoxObject::Clear();
michael@0 193 }
michael@0 194
michael@0 195 void
michael@0 196 nsListBoxObject::ClearCachedValues()
michael@0 197 {
michael@0 198 mListBoxBody = nullptr;
michael@0 199 }
michael@0 200
michael@0 201 // Creation Routine ///////////////////////////////////////////////////////////////////////
michael@0 202
michael@0 203 nsresult
michael@0 204 NS_NewListBoxObject(nsIBoxObject** aResult)
michael@0 205 {
michael@0 206 *aResult = new nsListBoxObject;
michael@0 207 if (!*aResult)
michael@0 208 return NS_ERROR_OUT_OF_MEMORY;
michael@0 209 NS_ADDREF(*aResult);
michael@0 210 return NS_OK;
michael@0 211 }

mercurial