layout/xul/nsScrollbarFrame.cpp

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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 //
michael@0 7 // Eric Vaughan
michael@0 8 // Netscape Communications
michael@0 9 //
michael@0 10 // See documentation in associated header file
michael@0 11 //
michael@0 12
michael@0 13 #include "nsScrollbarFrame.h"
michael@0 14 #include "nsScrollbarButtonFrame.h"
michael@0 15 #include "nsGkAtoms.h"
michael@0 16 #include "nsIScrollableFrame.h"
michael@0 17 #include "nsIScrollbarMediator.h"
michael@0 18 #include "mozilla/LookAndFeel.h"
michael@0 19 #include "nsThemeConstants.h"
michael@0 20 #include "nsRenderingContext.h"
michael@0 21 #include "nsIContent.h"
michael@0 22
michael@0 23 using namespace mozilla;
michael@0 24
michael@0 25 //
michael@0 26 // NS_NewScrollbarFrame
michael@0 27 //
michael@0 28 // Creates a new scrollbar frame and returns it
michael@0 29 //
michael@0 30 nsIFrame*
michael@0 31 NS_NewScrollbarFrame (nsIPresShell* aPresShell, nsStyleContext* aContext)
michael@0 32 {
michael@0 33 return new (aPresShell) nsScrollbarFrame (aPresShell, aContext);
michael@0 34 }
michael@0 35
michael@0 36 NS_IMPL_FRAMEARENA_HELPERS(nsScrollbarFrame)
michael@0 37
michael@0 38 NS_QUERYFRAME_HEAD(nsScrollbarFrame)
michael@0 39 NS_QUERYFRAME_ENTRY(nsScrollbarFrame)
michael@0 40 NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
michael@0 41
michael@0 42 void
michael@0 43 nsScrollbarFrame::Init(nsIContent* aContent,
michael@0 44 nsIFrame* aParent,
michael@0 45 nsIFrame* aPrevInFlow)
michael@0 46 {
michael@0 47 nsBoxFrame::Init(aContent, aParent, aPrevInFlow);
michael@0 48
michael@0 49 // We want to be a reflow root since we use reflows to move the
michael@0 50 // slider. Any reflow inside the scrollbar frame will be a reflow to
michael@0 51 // move the slider and will thus not change anything outside of the
michael@0 52 // scrollbar or change the size of the scrollbar frame.
michael@0 53 mState |= NS_FRAME_REFLOW_ROOT;
michael@0 54 }
michael@0 55
michael@0 56 nsresult
michael@0 57 nsScrollbarFrame::Reflow(nsPresContext* aPresContext,
michael@0 58 nsHTMLReflowMetrics& aDesiredSize,
michael@0 59 const nsHTMLReflowState& aReflowState,
michael@0 60 nsReflowStatus& aStatus)
michael@0 61 {
michael@0 62 nsresult rv = nsBoxFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
michael@0 63 NS_ENSURE_SUCCESS(rv, rv);
michael@0 64
michael@0 65 // nsGfxScrollFrame may have told us to shrink to nothing. If so, make sure our
michael@0 66 // desired size agrees.
michael@0 67 if (aReflowState.AvailableWidth() == 0) {
michael@0 68 aDesiredSize.Width() = 0;
michael@0 69 }
michael@0 70 if (aReflowState.AvailableHeight() == 0) {
michael@0 71 aDesiredSize.Height() = 0;
michael@0 72 }
michael@0 73
michael@0 74 return NS_OK;
michael@0 75 }
michael@0 76
michael@0 77 nsIAtom*
michael@0 78 nsScrollbarFrame::GetType() const
michael@0 79 {
michael@0 80 return nsGkAtoms::scrollbarFrame;
michael@0 81 }
michael@0 82
michael@0 83 nsresult
michael@0 84 nsScrollbarFrame::AttributeChanged(int32_t aNameSpaceID,
michael@0 85 nsIAtom* aAttribute,
michael@0 86 int32_t aModType)
michael@0 87 {
michael@0 88 nsresult rv = nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute,
michael@0 89 aModType);
michael@0 90
michael@0 91 // if the current position changes, notify any nsGfxScrollFrame
michael@0 92 // parent we may have
michael@0 93 if (aAttribute != nsGkAtoms::curpos)
michael@0 94 return rv;
michael@0 95
michael@0 96 nsIScrollableFrame* scrollable = do_QueryFrame(GetParent());
michael@0 97 if (!scrollable)
michael@0 98 return rv;
michael@0 99
michael@0 100 nsCOMPtr<nsIContent> kungFuDeathGrip(mContent);
michael@0 101 scrollable->CurPosAttributeChanged(mContent);
michael@0 102 return rv;
michael@0 103 }
michael@0 104
michael@0 105 NS_IMETHODIMP
michael@0 106 nsScrollbarFrame::HandlePress(nsPresContext* aPresContext,
michael@0 107 WidgetGUIEvent* aEvent,
michael@0 108 nsEventStatus* aEventStatus)
michael@0 109 {
michael@0 110 return NS_OK;
michael@0 111 }
michael@0 112
michael@0 113 NS_IMETHODIMP
michael@0 114 nsScrollbarFrame::HandleMultiplePress(nsPresContext* aPresContext,
michael@0 115 WidgetGUIEvent* aEvent,
michael@0 116 nsEventStatus* aEventStatus,
michael@0 117 bool aControlHeld)
michael@0 118 {
michael@0 119 return NS_OK;
michael@0 120 }
michael@0 121
michael@0 122 NS_IMETHODIMP
michael@0 123 nsScrollbarFrame::HandleDrag(nsPresContext* aPresContext,
michael@0 124 WidgetGUIEvent* aEvent,
michael@0 125 nsEventStatus* aEventStatus)
michael@0 126 {
michael@0 127 return NS_OK;
michael@0 128 }
michael@0 129
michael@0 130 NS_IMETHODIMP
michael@0 131 nsScrollbarFrame::HandleRelease(nsPresContext* aPresContext,
michael@0 132 WidgetGUIEvent* aEvent,
michael@0 133 nsEventStatus* aEventStatus)
michael@0 134 {
michael@0 135 return NS_OK;
michael@0 136 }
michael@0 137
michael@0 138 void
michael@0 139 nsScrollbarFrame::SetScrollbarMediatorContent(nsIContent* aMediator)
michael@0 140 {
michael@0 141 mScrollbarMediator = aMediator;
michael@0 142 }
michael@0 143
michael@0 144 nsIScrollbarMediator*
michael@0 145 nsScrollbarFrame::GetScrollbarMediator()
michael@0 146 {
michael@0 147 if (!mScrollbarMediator)
michael@0 148 return nullptr;
michael@0 149 nsIFrame* f = mScrollbarMediator->GetPrimaryFrame();
michael@0 150
michael@0 151 // check if the frame is a scroll frame. If so, get the scrollable frame
michael@0 152 // inside it.
michael@0 153 nsIScrollableFrame* scrollFrame = do_QueryFrame(f);
michael@0 154 if (scrollFrame) {
michael@0 155 f = scrollFrame->GetScrolledFrame();
michael@0 156 }
michael@0 157
michael@0 158 nsIScrollbarMediator* sbm = do_QueryFrame(f);
michael@0 159 return sbm;
michael@0 160 }
michael@0 161
michael@0 162 nsresult
michael@0 163 nsScrollbarFrame::GetMargin(nsMargin& aMargin)
michael@0 164 {
michael@0 165 aMargin.SizeTo(0,0,0,0);
michael@0 166
michael@0 167 if (LookAndFeel::GetInt(LookAndFeel::eIntID_UseOverlayScrollbars) != 0) {
michael@0 168 nsPresContext* presContext = PresContext();
michael@0 169 nsITheme* theme = presContext->GetTheme();
michael@0 170 if (theme) {
michael@0 171 nsIntSize size;
michael@0 172 bool isOverridable;
michael@0 173 nsRefPtr<nsRenderingContext> rc =
michael@0 174 presContext->PresShell()->CreateReferenceRenderingContext();
michael@0 175 theme->GetMinimumWidgetSize(rc, this, NS_THEME_SCROLLBAR, &size,
michael@0 176 &isOverridable);
michael@0 177 if (IsHorizontal()) {
michael@0 178 aMargin.top = -presContext->DevPixelsToAppUnits(size.height);
michael@0 179 }
michael@0 180 else {
michael@0 181 if (StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL) {
michael@0 182 aMargin.right = -presContext->DevPixelsToAppUnits(size.width);
michael@0 183 }
michael@0 184 else {
michael@0 185 aMargin.left = -presContext->DevPixelsToAppUnits(size.width);
michael@0 186 }
michael@0 187 }
michael@0 188 return NS_OK;
michael@0 189 }
michael@0 190 }
michael@0 191
michael@0 192 return nsBox::GetMargin(aMargin);
michael@0 193 }

mercurial