1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is Mozilla Communicator client code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : //
39 : // Eric Vaughan
40 : // Netscape Communications
41 : //
42 : // See documentation in associated header file
43 : //
44 :
45 : #include "nsScrollbarFrame.h"
46 : #include "nsScrollbarButtonFrame.h"
47 : #include "nsGkAtoms.h"
48 : #include "nsIScrollableFrame.h"
49 : #include "nsIScrollbarMediator.h"
50 :
51 : //
52 : // NS_NewToolbarFrame
53 : //
54 : // Creates a new Toolbar frame and returns it
55 : //
56 : nsIFrame*
57 0 : NS_NewScrollbarFrame (nsIPresShell* aPresShell, nsStyleContext* aContext)
58 : {
59 0 : return new (aPresShell) nsScrollbarFrame (aPresShell, aContext);
60 : }
61 :
62 0 : NS_IMPL_FRAMEARENA_HELPERS(nsScrollbarFrame)
63 :
64 0 : NS_QUERYFRAME_HEAD(nsScrollbarFrame)
65 0 : NS_QUERYFRAME_ENTRY(nsScrollbarFrame)
66 0 : NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
67 :
68 : NS_IMETHODIMP
69 0 : nsScrollbarFrame::Init(nsIContent* aContent,
70 : nsIFrame* aParent,
71 : nsIFrame* aPrevInFlow)
72 : {
73 0 : nsresult rv = nsBoxFrame::Init(aContent, aParent, aPrevInFlow);
74 :
75 : // We want to be a reflow root since we use reflows to move the
76 : // slider. Any reflow inside the scrollbar frame will be a reflow to
77 : // move the slider and will thus not change anything outside of the
78 : // scrollbar or change the size of the scrollbar frame.
79 0 : mState |= NS_FRAME_REFLOW_ROOT;
80 :
81 0 : return rv;
82 : }
83 :
84 : NS_IMETHODIMP
85 0 : nsScrollbarFrame::Reflow(nsPresContext* aPresContext,
86 : nsHTMLReflowMetrics& aDesiredSize,
87 : const nsHTMLReflowState& aReflowState,
88 : nsReflowStatus& aStatus)
89 : {
90 0 : nsresult rv = nsBoxFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
91 0 : NS_ENSURE_SUCCESS(rv, rv);
92 :
93 : // nsGfxScrollFrame may have told us to shrink to nothing. If so, make sure our
94 : // desired size agrees.
95 0 : if (aReflowState.availableWidth == 0) {
96 0 : aDesiredSize.width = 0;
97 : }
98 0 : if (aReflowState.availableHeight == 0) {
99 0 : aDesiredSize.height = 0;
100 : }
101 :
102 0 : return NS_OK;
103 : }
104 :
105 : nsIAtom*
106 0 : nsScrollbarFrame::GetType() const
107 : {
108 0 : return nsGkAtoms::scrollbarFrame;
109 : }
110 :
111 : NS_IMETHODIMP
112 0 : nsScrollbarFrame::AttributeChanged(PRInt32 aNameSpaceID,
113 : nsIAtom* aAttribute,
114 : PRInt32 aModType)
115 : {
116 : nsresult rv = nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute,
117 0 : aModType);
118 :
119 : // if the current position changes, notify any nsGfxScrollFrame
120 : // parent we may have
121 0 : if (aAttribute != nsGkAtoms::curpos)
122 0 : return rv;
123 :
124 0 : nsIScrollableFrame* scrollable = do_QueryFrame(GetParent());
125 0 : if (!scrollable)
126 0 : return rv;
127 :
128 0 : scrollable->CurPosAttributeChanged(mContent);
129 0 : return rv;
130 : }
131 :
132 : NS_IMETHODIMP
133 0 : nsScrollbarFrame::HandlePress(nsPresContext* aPresContext,
134 : nsGUIEvent* aEvent,
135 : nsEventStatus* aEventStatus)
136 : {
137 0 : return NS_OK;
138 : }
139 :
140 : NS_IMETHODIMP
141 0 : nsScrollbarFrame::HandleMultiplePress(nsPresContext* aPresContext,
142 : nsGUIEvent* aEvent,
143 : nsEventStatus* aEventStatus,
144 : bool aControlHeld)
145 : {
146 0 : return NS_OK;
147 : }
148 :
149 : NS_IMETHODIMP
150 0 : nsScrollbarFrame::HandleDrag(nsPresContext* aPresContext,
151 : nsGUIEvent* aEvent,
152 : nsEventStatus* aEventStatus)
153 : {
154 0 : return NS_OK;
155 : }
156 :
157 : NS_IMETHODIMP
158 0 : nsScrollbarFrame::HandleRelease(nsPresContext* aPresContext,
159 : nsGUIEvent* aEvent,
160 : nsEventStatus* aEventStatus)
161 : {
162 0 : return NS_OK;
163 : }
164 :
165 : void
166 0 : nsScrollbarFrame::SetScrollbarMediatorContent(nsIContent* aMediator)
167 : {
168 0 : mScrollbarMediator = aMediator;
169 0 : }
170 :
171 : nsIScrollbarMediator*
172 0 : nsScrollbarFrame::GetScrollbarMediator()
173 : {
174 0 : if (!mScrollbarMediator)
175 0 : return nsnull;
176 0 : nsIFrame* f = mScrollbarMediator->GetPrimaryFrame();
177 :
178 : // check if the frame is a scroll frame. If so, get the scrollable frame
179 : // inside it.
180 0 : nsIScrollableFrame* scrollFrame = do_QueryFrame(f);
181 0 : if (scrollFrame) {
182 0 : f = scrollFrame->GetScrolledFrame();
183 : }
184 :
185 0 : nsIScrollbarMediator* sbm = do_QueryFrame(f);
186 0 : return sbm;
187 : }
|